KDDockWidgets API Documentation 2.0
Loading...
Searching...
No Matches
ClassicDropIndicatorOverlay.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2019 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 Author: Sérgio Martins <sergio.martins@kdab.com>
6
7 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
8
9 Contact KDAB at <info@kdab.com> for commercial licensing options.
10*/
11
13#include "Config.h"
14#include "core/ViewFactory.h"
16
17#include "core/DropArea.h"
18#include "core/DockRegistry.h"
19#include "core/Group.h"
20
21#include "core/DragController_p.h"
22#include "core/Logging_p.h"
23#include "core/Utils_p.h"
24
25
26using namespace KDDockWidgets;
27using namespace KDDockWidgets::Core;
28
31{
32 auto window = Config::self().viewFactory()->createClassicIndicatorWindow(classicIndicators, parent);
33 window->setObjectName(QStringLiteral("_docks_IndicatorWindow_Overlay"));
34
35 return window;
36}
37
39 : DropIndicatorOverlay(dropArea) // Is parented on the drop-area, not a toplevel.
40 , m_rubberBand(Config::self().viewFactory()->createRubberBand(
41 rubberBandIsTopLevel() ? nullptr : dropArea->view())) // rubber band is parented on the drop area
42 , m_indicatorWindow(createIndicatorWindow(this, dropArea->view())) // a real top-level, transparent window, to hold our indicators
43{
44 if (rubberBandIsTopLevel())
45 m_rubberBand->setWindowOpacity(0.5);
46 m_rubberBand->setVisible(false);
47}
48
50{
51 delete m_indicatorWindow;
52}
53
55{
56 return m_indicatorWindow->hover(globalPos);
57}
58
60{
61 return m_indicatorWindow->posForIndicator(loc);
62}
63
65{
66 m_indicatorWindow->resize(window()->size());
67 return false;
68}
69
71{
72 if (isHovered()) {
73 m_indicatorWindow->updatePositions();
74 m_indicatorWindow->setVisible(true);
75 updateWindowPosition();
76 raiseIndicators();
77 } else {
78 m_rubberBand->setVisible(false);
79 m_indicatorWindow->setVisible(false);
80 }
81
82 m_indicatorWindow->updateIndicatorVisibility();
83}
84
89
90void ClassicDropIndicatorOverlay::raiseIndicators()
91{
92 m_indicatorWindow->raise();
93}
94
118
120{
122
123 if (location == DropLocation_None) {
124 m_rubberBand->setVisible(false);
125 return;
126 }
127
128 m_rubberBand->raise();
129
130 if (location == DropLocation_Center) {
131 m_rubberBand->setGeometry(
132 geometryForRubberband(m_hoveredGroup ? m_hoveredGroup->view()->geometry() : rect()));
133 m_rubberBand->setVisible(true);
134 if (rubberBandIsTopLevel())
135 raiseIndicators();
136
137 return;
138 }
139
140 KDDockWidgets::Location multisplitterLocation = locationToMultisplitterLocation(location);
141 Core::Group *relativeToFrame = nullptr;
142
143 switch (location) {
145 case DropLocation_Top:
148 if (!m_hoveredGroup) {
149 KDDW_ERROR("ClassicIndicators::setCurrentDropLocation: group is null. location={}, isHovered={}, dropArea->widgets={}", location, isHovered(), m_dropArea->items().size());
150 assert(false);
151 return;
152 }
153 relativeToFrame = m_hoveredGroup;
154 break;
159 break;
160 default:
161 break;
162 }
163
164 auto windowBeingDragged = DragController::instance()->windowBeingDragged();
165
166 Rect rect = m_dropArea->rectForDrop(windowBeingDragged, multisplitterLocation,
167 m_dropArea->itemForGroup(relativeToFrame));
168
169 m_rubberBand->setGeometry(geometryForRubberband(rect));
170 m_rubberBand->setVisible(true);
171 if (rubberBandIsTopLevel()) {
172 m_rubberBand->raise();
173 raiseIndicators();
174 }
175}
176
177void ClassicDropIndicatorOverlay::updateWindowPosition()
178{
179 Rect rect = this->rect();
180 if (m_indicatorWindow->isWindow()) {
181 // On all non-wayland platforms it's a top-level.
182
183 const Point pos = m_dropArea->mapToGlobal(Point(0, 0));
184 rect.moveTo(pos);
185 }
186 m_indicatorWindow->setGeometry(rect);
187}
188
189bool ClassicDropIndicatorOverlay::rubberBandIsTopLevel() const
190{
192}
193
194Rect ClassicDropIndicatorOverlay::geometryForRubberband(Rect localRect) const
195{
196 if (!rubberBandIsTopLevel())
197 return localRect;
198
199 Point topLeftLocal = localRect.topLeft();
200 Point topLeftGlobal = m_dropArea->mapToGlobal(topLeftLocal);
201
202 localRect.moveTopLeft(topLeftGlobal);
203
204 return localRect;
205}
206
208{
209 return m_rubberBand;
210}
KDDockWidgets::Location locationToMultisplitterLocation(DropLocation location)
static Core::ClassicIndicatorWindowViewInterface * createIndicatorWindow(ClassicDropIndicatorOverlay *classicIndicators, Core::View *parent)
Application-wide config to tune certain behaviours of the framework.
Singleton to allow to choose certain behaviours of the framework.
Definition Config.h:64
InternalFlags internalFlags() const
Definition Config.cpp:312
Core::ViewFactory * viewFactory() const
getter for the framework view factory
Definition Config.cpp:182
@ InternalFlag_TopLevelIndicatorRubberBand
with more exotic setups. This flag can be used to override.
Definition Config.h:171
static Config & self()
returns the singleton Config instance
Definition Config.cpp:88
Point posForIndicator(DropLocation) const override
returns the position of the specified drop location The return is in global coordinates
Core::ClassicIndicatorWindowViewInterface * indicatorWindow() const
The window that will hold the classic indicators This is a window so it can be over the window that i...
virtual Point posForIndicator(DropLocation) const =0
View * view() const
Returns the view associated with this controller, if any.
Point mapToGlobal(Point) const
std::shared_ptr< View > window() const
Rect rectForDrop(const WindowBeingDragged *wbd, KDDockWidgets::Location location, const Core::Item *relativeTo) const
Core::Item * itemForGroup(const Core::Group *group) const
returns the Item that holds group in this layout
Definition Layout.cpp:224
Vector< Core::Item * > items() const
The list of items in this layout.
Definition Layout.cpp:194
virtual Core::ClassicIndicatorWindowViewInterface * createClassicIndicatorWindow(Core::ClassicDropIndicatorOverlay *, Core::View *parent=nullptr) const =0
Creates the window that will show the actual drop indicators. They need a higher z-order,...
virtual Rect geometry() const =0
virtual void raise()=0
virtual void setWindowOpacity(double)=0
virtual void setVisible(bool)=0
virtual void setGeometry(Rect)=0
A MultiSplitter with support for drop indicators when hovering over.
Class to abstract QAction, so code still works with QtQuick and Flutter.
@ Location_OnTop
‍Left docking location
@ Location_OnRight
‍Top docking location
@ Location_OnBottom
‍Right docking location
DropLocation
Enum describing the different drop indicator types.

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDDockWidgets
Advanced Dock Widget Framework for Qt
https://www.kdab.com/development-resources/qt-tools/kddockwidgets/
Generated by doxygen 1.9.8