KDDockWidgets API Documentation  1.6
DropIndicatorOverlayInterface.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 "DropIndicatorOverlayInterface_p.h"
13 
14 #include "Frame_p.h"
15 #include "DropArea_p.h"
16 #include "DockRegistry_p.h"
17 #include "DragController_p.h"
18 #include "Config.h"
19 
20 using namespace KDDockWidgets;
21 
22 DropIndicatorOverlayInterface::DropIndicatorOverlayInterface(DropArea *dropArea)
23  : QWidgetAdapter(dropArea)
24  , m_dropArea(dropArea)
25 {
26  setVisible(false);
27  setObjectName(QStringLiteral("DropIndicatorOverlayInterface"));
28 
29  // Set transparent for mouse events so that topLevel->childAt() never returns the drop indicator overlay
31 
32  connect(DockRegistry::self(), &DockRegistry::dropIndicatorsInhibitedChanged, this,
33  [this](bool inhibited) {
34  if (inhibited)
35  removeHover();
36 
37  // if false then simply moving the mouse will make the drop indicators appear again
38  });
39 }
40 
41 void DropIndicatorOverlayInterface::setWindowBeingDragged(bool is)
42 {
43  if (is == m_draggedWindowIsHovering)
44  return;
45 
46  m_draggedWindowIsHovering = is;
47  if (is) {
48  setGeometry(m_dropArea->QWidgetAdapter::rect());
49  raise();
50  } else {
51  setHoveredFrame(nullptr);
52  }
53 
54  setVisible(is);
55  updateVisibility();
56 }
57 
58 QRect DropIndicatorOverlayInterface::hoveredFrameRect() const
59 {
60  return m_hoveredFrameRect;
61 }
62 
63 void DropIndicatorOverlayInterface::setHoveredFrame(Frame *frame)
64 {
65  if (frame == m_hoveredFrame)
66  return;
67 
68  if (m_hoveredFrame)
69  disconnect(m_hoveredFrame, &QObject::destroyed, this, &DropIndicatorOverlayInterface::onFrameDestroyed);
70 
71  m_hoveredFrame = frame;
72  if (m_hoveredFrame) {
73  connect(frame, &QObject::destroyed, this, &DropIndicatorOverlayInterface::onFrameDestroyed);
74  setHoveredFrameRect(m_hoveredFrame->QWidgetAdapter::geometry());
75  } else {
76  setHoveredFrameRect(QRect());
77  }
78 
79  updateVisibility();
80  Q_EMIT hoveredFrameChanged(m_hoveredFrame);
81  onHoveredFrameChanged(m_hoveredFrame);
82 }
83 
84 bool DropIndicatorOverlayInterface::isHovered() const
85 {
86  return m_draggedWindowIsHovering;
87 }
88 
89 DropLocation DropIndicatorOverlayInterface::currentDropLocation() const
90 {
91  return m_currentDropLocation;
92 }
93 
94 KDDockWidgets::Location DropIndicatorOverlayInterface::multisplitterLocationFor(DropLocation dropLoc)
95 {
96  switch (dropLoc) {
97  case DropLocation_None:
99  case DropLocation_Left:
103  case DropLocation_Top:
106  case DropLocation_Right:
109  case DropLocation_Bottom:
111  case DropLocation_Center:
113  case DropLocation_Inner:
114  case DropLocation_Outter:
117  qWarning() << Q_FUNC_INFO << "Unexpected drop location" << dropLoc;
118  break;
119  }
120 
122 }
123 
124 bool DropIndicatorOverlayInterface::dropIndicatorVisible(DropLocation dropLoc) const
125 {
126  if (dropLoc == DropLocation_None)
127  return false;
128 
129  WindowBeingDragged *windowBeingDragged = DragController::instance()->windowBeingDragged();
130  if (!windowBeingDragged)
131  return false;
132 
133  const DockWidgetBase::List source = windowBeingDragged->dockWidgets();
134  const DockWidgetBase::List target = m_hoveredFrame ? m_hoveredFrame->dockWidgets()
136 
137  const bool isInner = dropLoc & DropLocation_Inner;
138  const bool isOutter = dropLoc & DropLocation_Outter;
139  if (isInner) {
140  if (!m_hoveredFrame)
141  return false;
142  } else if (isOutter) {
143  // If there's only 1 frame in the layout, the outer indicators are redundant, as they do the same thing as the internal ones.
144  // But there might be another window obscuring our target, so it's useful to show the outer indicators in this case
145  const bool isTheOnlyFrame = m_hoveredFrame && m_hoveredFrame->isTheOnlyFrame();
146  if (isTheOnlyFrame && !DockRegistry::self()->isProbablyObscured(m_hoveredFrame->window()->windowHandle(), windowBeingDragged))
147  return false;
148  } else if (dropLoc == DropLocation_Center) {
149  if (!m_hoveredFrame || !m_hoveredFrame->isDockable())
150  return false;
151 
152  if (auto tabbingAllowedFunc = Config::self().tabbingAllowedFunc()) {
153  if (!tabbingAllowedFunc(source, target))
154  return false;
155  }
156 
157  // Only allow to dock to center if the affinities match
158  if (!DockRegistry::self()->affinitiesMatch(m_hoveredFrame->affinities(), windowBeingDragged->affinities()))
159  return false;
160  } else {
161  qWarning() << Q_FUNC_INFO << "Unknown drop indicator location" << dropLoc;
162  return false;
163  }
164 
165  if (auto dropIndicatorAllowedFunc = Config::self().dropIndicatorAllowedFunc()) {
166  DropArea *dropArea = DragController::instance()->dropAreaUnderCursor();
167  if (!dropIndicatorAllowedFunc(dropLoc, source, target, dropArea))
168  return false;
169  }
170 
171  return true;
172 }
173 
174 void DropIndicatorOverlayInterface::onFrameDestroyed()
175 {
176  setHoveredFrame(nullptr);
177 }
178 
179 void DropIndicatorOverlayInterface::onHoveredFrameChanged(Frame *)
180 {
181 }
182 
183 void DropIndicatorOverlayInterface::setCurrentDropLocation(DropLocation location)
184 {
185  if (m_currentDropLocation != location) {
186  m_currentDropLocation = location;
187  Q_EMIT currentDropLocationChanged();
188  }
189 }
190 
191 DropLocation DropIndicatorOverlayInterface::hover(QPoint globalPos)
192 {
193  return hover_impl(globalPos);
194 }
195 
196 void DropIndicatorOverlayInterface::setHoveredFrameRect(QRect rect)
197 {
198  if (m_hoveredFrameRect != rect) {
199  m_hoveredFrameRect = rect;
200  Q_EMIT hoveredFrameRectChanged();
201  }
202 }
203 
204 void DropIndicatorOverlayInterface::removeHover()
205 {
206  setWindowBeingDragged(false);
207  setCurrentDropLocation(DropLocation_None);
208 }
KDDockWidgets::DropLocation_Top
@ DropLocation_Top
Definition: KDDockWidgets.h:232
QRect
KDDockWidgets::DropLocation_Vertical
@ DropLocation_Vertical
Definition: KDDockWidgets.h:243
KDDockWidgets::DropLocation_Center
@ DropLocation_Center
Definition: KDDockWidgets.h:235
KDDockWidgets::DropLocation_Inner
@ DropLocation_Inner
Definition: KDDockWidgets.h:240
KDDockWidgets::Location_OnTop
@ Location_OnTop
Left docking location
Definition: KDDockWidgets.h:47
KDDockWidgets::Location
Location
Definition: KDDockWidgets.h:44
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
QObject::destroyed
void destroyed(QObject *obj)
KDDockWidgets::Location_OnLeft
@ Location_OnLeft
Definition: KDDockWidgets.h:46
KDDockWidgets::DropLocation_OutterTop
@ DropLocation_OutterTop
Definition: KDDockWidgets.h:237
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
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
KDDockWidgets::DropLocation_Horizontal
@ DropLocation_Horizontal
Definition: KDDockWidgets.h:242
KDDockWidgets::DropLocation
DropLocation
Enum describing the different drop indicator types.
Definition: KDDockWidgets.h:229
QVector
KDDockWidgets::DropLocation_None
@ DropLocation_None
Definition: KDDockWidgets.h:230
Qt::WA_TransparentForMouseEvents
WA_TransparentForMouseEvents
QPoint
KDDockWidgets::DropLocation_Outter
@ DropLocation_Outter
Definition: KDDockWidgets.h:241
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:28 for KDDockWidgets API Documentation by doxygen 1.8.20