KDDockWidgets API Documentation 1.7
Loading...
Searching...
No Matches
ClassicIndicators.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2019-2023 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
12#include "ClassicIndicators_p.h"
13#include "Config.h"
15#include "ClassicIndicatorsWindow_p.h"
16
17#include "private/DropArea_p.h"
18#include "private/DragController_p.h"
19#include "private/Frame_p.h"
20#include "private/Logging_p.h"
21#include "private/DockRegistry_p.h"
22#include "private/Utils_p.h"
23
24using namespace KDDockWidgets;
25
26static IndicatorWindow *createIndicatorWindow(ClassicIndicators *classicIndicators)
27{
28 auto window = new IndicatorWindow(classicIndicators);
29 window->setObjectName(QStringLiteral("_docks_IndicatorWindow_Overlay"));
30
31 return window;
32}
33
34ClassicIndicators::ClassicIndicators(DropArea *dropArea)
35 : DropIndicatorOverlayInterface(dropArea) // Is parented on the drop-area, not a toplevel.
36 , m_rubberBand(Config::self().frameworkWidgetFactory()->createRubberBand(rubberBandIsTopLevel() ? nullptr : dropArea))
37 , m_indicatorWindow(createIndicatorWindow(this))
38{
39 if (rubberBandIsTopLevel())
40 m_rubberBand->setWindowOpacity(0.5);
41}
42
43ClassicIndicators::~ClassicIndicators()
44{
45 delete m_indicatorWindow;
46}
47
48DropLocation ClassicIndicators::hover_impl(QPoint globalPos)
49{
50 return m_indicatorWindow->hover(globalPos);
51}
52
53QPoint ClassicIndicators::posForIndicator(DropLocation loc) const
54{
55 return m_indicatorWindow->posForIndicator(loc);
56}
57
58bool ClassicIndicators::innerLeftIndicatorVisible() const
59{
60 return dropIndicatorVisible(DropLocation_Left);
61}
62
63bool ClassicIndicators::innerRightIndicatorVisible() const
64{
65 return dropIndicatorVisible(DropLocation_Right);
66}
67
68bool ClassicIndicators::innerTopIndicatorVisible() const
69{
70 return dropIndicatorVisible(DropLocation_Top);
71}
72
73bool ClassicIndicators::innerBottomIndicatorVisible() const
74{
75 return dropIndicatorVisible(DropLocation_Bottom);
76}
77
78bool ClassicIndicators::outterLeftIndicatorVisible() const
79{
80 return dropIndicatorVisible(DropLocation_OutterLeft);
81}
82
83bool ClassicIndicators::outterRightIndicatorVisible() const
84{
85 return dropIndicatorVisible(DropLocation_OutterRight);
86}
87
88bool ClassicIndicators::outterTopIndicatorVisible() const
89{
90 return dropIndicatorVisible(DropLocation_OutterTop);
91}
92
93bool ClassicIndicators::outterBottomIndicatorVisible() const
94{
95 return dropIndicatorVisible(DropLocation_OutterBottom);
96}
97
98bool ClassicIndicators::tabIndicatorVisible() const
99{
100 return dropIndicatorVisible(DropLocation_Center);
101}
102
103bool ClassicIndicators::onResize(QSize)
104{
105 m_indicatorWindow->resize(window()->size());
106 return false;
107}
108
109void ClassicIndicators::updateVisibility()
110{
111 if (isHovered()) {
112 m_indicatorWindow->updatePositions();
113 m_indicatorWindow->setVisible(true);
114 updateWindowPosition();
115 raiseIndicators();
116 } else {
117 m_rubberBand->setVisible(false);
118 m_indicatorWindow->setVisible(false);
119 }
120
121 Q_EMIT indicatorsVisibleChanged();
122}
123
124void ClassicIndicators::raiseIndicators()
125{
126 m_indicatorWindow->raise();
127}
128
152
153void ClassicIndicators::setDropLocation(DropLocation location)
154{
155 setCurrentDropLocation(location);
156
157 if (location == DropLocation_None) {
158 m_rubberBand->setVisible(false);
159 return;
160 }
161
162 if (location == DropLocation_Center) {
163 m_rubberBand->setGeometry(geometryForRubberband(m_hoveredFrame ? m_hoveredFrame->QWidgetAdapter::geometry() : rect()));
164 m_rubberBand->setVisible(true);
165 if (rubberBandIsTopLevel()) {
166 m_rubberBand->raise();
167 raiseIndicators();
168 }
169
170 return;
171 }
172
173 KDDockWidgets::Location multisplitterLocation = locationToMultisplitterLocation(location);
174 Frame *relativeToFrame = nullptr;
175
176 switch (location) {
178 case DropLocation_Top:
181 if (!m_hoveredFrame) {
182 qWarning() << "ClassicIndicators::setCurrentDropLocation: frame is null. location=" << location
183 << "; isHovered=" << isHovered()
184 << "; dropArea->widgets=" << m_dropArea->items();
185 Q_ASSERT(false);
186 return;
187 }
188 relativeToFrame = m_hoveredFrame;
189 break;
194 break;
195 default:
196 break;
197 }
198
199 auto windowBeingDragged = DragController::instance()->windowBeingDragged();
200
201 QRect rect = m_dropArea->rectForDrop(windowBeingDragged, multisplitterLocation,
202 m_dropArea->itemForFrame(relativeToFrame));
203
204 m_rubberBand->setGeometry(geometryForRubberband(rect));
205 m_rubberBand->setVisible(true);
206 if (rubberBandIsTopLevel()) {
207 m_rubberBand->raise();
208 raiseIndicators();
209 }
210}
211
212void ClassicIndicators::updateWindowPosition()
213{
214 QRect rect = this->rect();
215 if (KDDockWidgets::isWindow(m_indicatorWindow)) {
216 // On all non-wayland platforms it's a top-level.
217 QPoint pos = mapToGlobal(QPoint(0, 0));
218 rect.moveTo(pos);
219 }
220 m_indicatorWindow->setGeometry(rect);
221}
222
223bool ClassicIndicators::rubberBandIsTopLevel() const
224{
226}
227
228QRect ClassicIndicators::geometryForRubberband(QRect localRect) const
229{
230 if (!rubberBandIsTopLevel())
231 return localRect;
232
233 QPoint topLeftLocal = localRect.topLeft();
234 QPoint topLeftGlobal = m_dropArea->QWidgetAdapter::mapToGlobal(topLeftLocal);
235
236 localRect.moveTopLeft(topLeftGlobal);
237
238 return localRect;
239}
static IndicatorWindow * createIndicatorWindow(ClassicIndicators *classicIndicators)
KDDockWidgets::Location locationToMultisplitterLocation(DropLocation location)
Application-wide config to tune certain behaviours of the framework.
A factory class for allowing the user to customize some internal widgets.
Singleton to allow to choose certain behaviours of the framework.
Definition Config.h:75
InternalFlags internalFlags() const
Definition Config.cpp:225
@ InternalFlag_TopLevelIndicatorRubberBand
with more exotic setups. This flag can be used to override.
Definition Config.h:139
static Config & self()
returns the singleton Config instance
Definition Config.cpp:84
@ Location_OnTop
‍Left docking location
@ Location_OnRight
‍Top docking location
@ Location_OnBottom
‍Right docking location
DropLocation
Enum describing the different drop indicator types.
void moveTo(int x, int y)
void moveTopLeft(const QPoint &position)
QPoint topLeft() const const

© 2019-2023 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 on Wed Nov 1 2023 00:02:31 for KDDockWidgets API Documentation by doxygen 1.9.8