KDDockWidgets API Documentation  1.6
ClassicIndicators.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KDDockWidgets.
3 
4  SPDX-FileCopyrightText: 2019-2022 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"
14 #include "FrameworkWidgetFactory.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 
24 using namespace KDDockWidgets;
25 
26 static IndicatorWindow *createIndicatorWindow(ClassicIndicators *classicIndicators)
27 {
28  auto window = new IndicatorWindow(classicIndicators);
29  window->setObjectName(QStringLiteral("_docks_IndicatorWindow_Overlay"));
30 
31  return window;
32 }
33 
34 ClassicIndicators::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 
43 ClassicIndicators::~ClassicIndicators()
44 {
45  delete m_indicatorWindow;
46 }
47 
48 DropLocation ClassicIndicators::hover_impl(QPoint globalPos)
49 {
50  return m_indicatorWindow->hover(globalPos);
51 }
52 
53 QPoint ClassicIndicators::posForIndicator(DropLocation loc) const
54 {
55  return m_indicatorWindow->posForIndicator(loc);
56 }
57 
58 bool ClassicIndicators::innerLeftIndicatorVisible() const
59 {
60  return dropIndicatorVisible(DropLocation_Left);
61 }
62 
63 bool ClassicIndicators::innerRightIndicatorVisible() const
64 {
65  return dropIndicatorVisible(DropLocation_Right);
66 }
67 
68 bool ClassicIndicators::innerTopIndicatorVisible() const
69 {
70  return dropIndicatorVisible(DropLocation_Top);
71 }
72 
73 bool ClassicIndicators::innerBottomIndicatorVisible() const
74 {
75  return dropIndicatorVisible(DropLocation_Bottom);
76 }
77 
78 bool ClassicIndicators::outterLeftIndicatorVisible() const
79 {
80  return dropIndicatorVisible(DropLocation_OutterLeft);
81 }
82 
83 bool ClassicIndicators::outterRightIndicatorVisible() const
84 {
85  return dropIndicatorVisible(DropLocation_OutterRight);
86 }
87 
88 bool ClassicIndicators::outterTopIndicatorVisible() const
89 {
90  return dropIndicatorVisible(DropLocation_OutterTop);
91 }
92 
93 bool ClassicIndicators::outterBottomIndicatorVisible() const
94 {
95  return dropIndicatorVisible(DropLocation_OutterBottom);
96 }
97 
98 bool ClassicIndicators::tabIndicatorVisible() const
99 {
100  return dropIndicatorVisible(DropLocation_Center);
101 }
102 
103 bool ClassicIndicators::onResize(QSize)
104 {
105  m_indicatorWindow->resize(window()->size());
106  return false;
107 }
108 
109 void 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 
124 void ClassicIndicators::raiseIndicators()
125 {
126  m_indicatorWindow->raise();
127 }
128 
130 {
131  switch (location) {
132  case DropLocation_Left:
134  case DropLocation_Top:
136  case DropLocation_Right:
138  case DropLocation_Bottom:
148  default:
150  }
151 }
152 
153 void 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) {
177  case DropLocation_Left:
178  case DropLocation_Top:
179  case DropLocation_Right:
180  case DropLocation_Bottom:
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 
212 void 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 
223 bool ClassicIndicators::rubberBandIsTopLevel() const
224 {
225  return Config::self().internalFlags() & Config::InternalFlag_TopLevelIndicatorRubberBand;
226 }
227 
228 QRect 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 }
QRect::moveTopLeft
void moveTopLeft(const QPoint &position)
KDDockWidgets::DropLocation_Top
@ DropLocation_Top
Definition: KDDockWidgets.h:232
QRect::topLeft
QPoint topLeft() const const
QRect
KDDockWidgets::DropLocation_Center
@ DropLocation_Center
Definition: KDDockWidgets.h:235
locationToMultisplitterLocation
KDDockWidgets::Location locationToMultisplitterLocation(DropLocation location)
Definition: ClassicIndicators.cpp:129
KDDockWidgets::Location_OnTop
@ Location_OnTop
Left docking location
Definition: KDDockWidgets.h:47
KDDockWidgets::Location
Location
Definition: KDDockWidgets.h:44
QSize
KDDockWidgets::DropLocation_Right
@ DropLocation_Right
Definition: KDDockWidgets.h:233
KDDockWidgets::Location_OnBottom
@ Location_OnBottom
Right docking location
Definition: KDDockWidgets.h:49
KDDockWidgets::DropLocation_Bottom
@ DropLocation_Bottom
Definition: KDDockWidgets.h:234
KDDockWidgets::Location_OnLeft
@ Location_OnLeft
Definition: KDDockWidgets.h:46
KDDockWidgets::DropLocation_OutterTop
@ DropLocation_OutterTop
Definition: KDDockWidgets.h:237
KDDockWidgets::Config
Singleton to allow to choose certain behaviours of the framework.
Definition: Config.h:75
KDDockWidgets::Location_OnRight
@ Location_OnRight
Top docking location
Definition: KDDockWidgets.h:48
Config.h
Application-wide config to tune certain behaviours of the framework.
KDDockWidgets::DropLocation_Left
@ DropLocation_Left
Definition: KDDockWidgets.h:231
createIndicatorWindow
static IndicatorWindow * createIndicatorWindow(ClassicIndicators *classicIndicators)
Definition: ClassicIndicators.cpp:26
KDDockWidgets::DropLocation_OutterLeft
@ DropLocation_OutterLeft
Definition: KDDockWidgets.h:236
KDDockWidgets
Definition: Config.cpp:37
KDDockWidgets::DropLocation_OutterRight
@ DropLocation_OutterRight
Definition: KDDockWidgets.h:238
KDDockWidgets::Location_None
@ Location_None
Definition: KDDockWidgets.h:45
QRect::moveTo
void moveTo(int x, int y)
KDDockWidgets::DropLocation
DropLocation
Enum describing the different drop indicator types.
Definition: KDDockWidgets.h:229
KDDockWidgets::DropLocation_None
@ DropLocation_None
Definition: KDDockWidgets.h:230
QPoint
FrameworkWidgetFactory.h
A factory class for allowing the user to customize some internal widgets.
KDDockWidgets::DropLocation_OutterBottom
@ DropLocation_OutterBottom
Definition: KDDockWidgets.h:239

© 2019-2022 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 Thu Sep 15 2022 00:16:27 for KDDockWidgets API Documentation by doxygen 1.8.20