KDDockWidgets API Documentation  1.5
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 
18 using namespace KDDockWidgets;
19 
20 DropIndicatorOverlayInterface::DropIndicatorOverlayInterface(DropArea *dropArea)
21  : QWidgetAdapter(dropArea)
22  , m_dropArea(dropArea)
23 {
24  setVisible(false);
25  setObjectName(QStringLiteral("DropIndicatorOverlayInterface"));
26 
27  connect(DockRegistry::self(), &DockRegistry::dropIndicatorsInhibitedChanged, this,
28  [this](bool inhibited) {
29  if (inhibited)
30  removeHover();
31 
32  // if false then simply moving the mouse will make the drop indicators appear again
33  });
34 }
35 
36 void DropIndicatorOverlayInterface::setWindowBeingDragged(bool is)
37 {
38  if (is == m_draggedWindowIsHovering)
39  return;
40 
41  m_draggedWindowIsHovering = is;
42  if (is) {
43  setGeometry(m_dropArea->QWidgetAdapter::rect());
44  raise();
45  } else {
46  setHoveredFrame(nullptr);
47  }
48 
49  setVisible(is);
50  updateVisibility();
51 }
52 
53 QRect DropIndicatorOverlayInterface::hoveredFrameRect() const
54 {
55  return m_hoveredFrameRect;
56 }
57 
58 void DropIndicatorOverlayInterface::setHoveredFrame(Frame *frame)
59 {
60  if (frame == m_hoveredFrame)
61  return;
62 
63  if (m_hoveredFrame)
64  disconnect(m_hoveredFrame, &QObject::destroyed, this, &DropIndicatorOverlayInterface::onFrameDestroyed);
65 
66  m_hoveredFrame = frame;
67  if (m_hoveredFrame) {
68  connect(frame, &QObject::destroyed, this, &DropIndicatorOverlayInterface::onFrameDestroyed);
69  setHoveredFrameRect(m_hoveredFrame->QWidgetAdapter::geometry());
70  } else {
71  setHoveredFrameRect(QRect());
72  }
73 
74  updateVisibility();
75  Q_EMIT hoveredFrameChanged(m_hoveredFrame);
76  onHoveredFrameChanged(m_hoveredFrame);
77 }
78 
79 bool DropIndicatorOverlayInterface::isHovered() const
80 {
81  return m_draggedWindowIsHovering;
82 }
83 
84 DropIndicatorOverlayInterface::DropLocation DropIndicatorOverlayInterface::currentDropLocation() const
85 {
86  return m_currentDropLocation;
87 }
88 
89 KDDockWidgets::Location DropIndicatorOverlayInterface::multisplitterLocationFor(DropIndicatorOverlayInterface::DropLocation dropLoc)
90 {
91  switch (dropLoc) {
92  case KDDockWidgets::DropIndicatorOverlayInterface::DropLocation_None:
94  case KDDockWidgets::DropIndicatorOverlayInterface::DropLocation_Left:
95  case KDDockWidgets::DropIndicatorOverlayInterface::DropLocation_OutterLeft:
97  case KDDockWidgets::DropIndicatorOverlayInterface::DropLocation_OutterTop:
98  case KDDockWidgets::DropIndicatorOverlayInterface::DropLocation_Top:
100  case KDDockWidgets::DropIndicatorOverlayInterface::DropLocation_OutterRight:
101  case KDDockWidgets::DropIndicatorOverlayInterface::DropLocation_Right:
103  case KDDockWidgets::DropIndicatorOverlayInterface::DropLocation_OutterBottom:
104  case KDDockWidgets::DropIndicatorOverlayInterface::DropLocation_Bottom:
106  case KDDockWidgets::DropIndicatorOverlayInterface::DropLocation_Center:
108  }
109 
111 }
112 
113 void DropIndicatorOverlayInterface::onFrameDestroyed()
114 {
115  setHoveredFrame(nullptr);
116 }
117 
118 void DropIndicatorOverlayInterface::onHoveredFrameChanged(Frame *)
119 {
120 }
121 
122 void DropIndicatorOverlayInterface::setCurrentDropLocation(DropIndicatorOverlayInterface::DropLocation location)
123 {
124  if (m_currentDropLocation != location) {
125  m_currentDropLocation = location;
126  Q_EMIT currentDropLocationChanged();
127  }
128 }
129 
130 DropIndicatorOverlayInterface::DropLocation DropIndicatorOverlayInterface::hover(QPoint globalPos)
131 {
132  return hover_impl(globalPos);
133 }
134 
135 void DropIndicatorOverlayInterface::setHoveredFrameRect(QRect rect)
136 {
137  if (m_hoveredFrameRect != rect) {
138  m_hoveredFrameRect = rect;
139  Q_EMIT hoveredFrameRectChanged();
140  }
141 }
142 
143 void DropIndicatorOverlayInterface::removeHover()
144 {
145  setWindowBeingDragged(false);
146  setCurrentDropLocation(DropIndicatorOverlayInterface::DropLocation_None);
147 }
QRect
KDDockWidgets::Location_OnTop
@ Location_OnTop
Left docking location
Definition: KDDockWidgets.h:48
KDDockWidgets::Location
Location
Definition: KDDockWidgets.h:45
KDDockWidgets::Location_OnBottom
@ Location_OnBottom
Right docking location
Definition: KDDockWidgets.h:50
QObject::destroyed
void destroyed(QObject *obj)
KDDockWidgets::Location_OnLeft
@ Location_OnLeft
Definition: KDDockWidgets.h:47
KDDockWidgets::Location_OnRight
@ Location_OnRight
Top docking location
Definition: KDDockWidgets.h:49
KDDockWidgets
Definition: Config.cpp:36
KDDockWidgets::Location_None
@ Location_None
Definition: KDDockWidgets.h:46
QPoint

© 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 Mon Mar 7 2022 02:01:20 for KDDockWidgets API Documentation by doxygen 1.8.20