12 #include "WindowBeingDragged_p.h"
13 #include "DragController_p.h"
15 #include "LayoutWidget_p.h"
16 #include "Logging_p.h"
19 #ifdef KDDOCKWIDGETS_QTWIDGETS
20 #include "widgets/TabBarWidget_p.h"
21 #include "widgets/TabWidgetWidget_p.h"
37 if (
auto titleBar = qobject_cast<TitleBar *>(draggable->asWidget())) {
38 if (titleBar->isVisible())
41 auto fw = qobject_cast<FloatingWindow *>(titleBar->window());
45 if (fw->titleBar() == titleBar) {
49 if (KDDockWidgets::usesNativeTitleBar())
51 return fw->titleBar();
58 WindowBeingDragged::WindowBeingDragged(FloatingWindow *fw,
Draggable *draggable)
59 : m_floatingWindow(fw)
61 , m_draggableWidget(m_draggable ? m_draggable->asWidget() : nullptr)
67 const qreal opacity = Config::self().draggedWindowOpacity();
68 if (!qIsNaN(opacity) && !qFuzzyCompare(1.0, opacity))
69 fw->setWindowOpacity(opacity);
73 WindowBeingDragged::WindowBeingDragged(
Draggable *draggable)
74 : m_draggable(draggable)
75 , m_draggableWidget(m_draggable->asWidget())
78 qWarning() << Q_FUNC_INFO <<
"Wrong ctor called.";
84 #ifdef DOCKS_DEVELOPER_MODE
87 WindowBeingDragged::WindowBeingDragged(FloatingWindow *fw)
88 : m_floatingWindow(fw)
89 , m_draggable(nullptr)
95 WindowBeingDragged::~WindowBeingDragged()
101 const qreal opacity = Config::self().draggedWindowOpacity();
102 if (!qIsNaN(opacity) && !qFuzzyCompare(1.0, opacity))
103 m_floatingWindow->setWindowOpacity(1);
107 void WindowBeingDragged::init()
109 Q_ASSERT(m_floatingWindow);
111 m_floatingWindow->raise();
114 void WindowBeingDragged::grabMouse(
bool grab)
116 if (!m_draggableWidget)
119 qCDebug(hovering) <<
"WindowBeingDragged: grab " << m_floatingWindow << grab << m_draggableWidget;
121 DragController::instance()->grabMouseFor(m_draggableWidget);
123 DragController::instance()->releaseMouse(m_draggableWidget);
128 return m_floatingWindow ? m_floatingWindow->affinities()
132 QSize WindowBeingDragged::size()
const
134 if (m_floatingWindow)
135 return m_floatingWindow->size();
140 QSize WindowBeingDragged::minSize()
const
142 if (m_floatingWindow)
143 return m_floatingWindow->layoutWidget()->layoutMinimumSize();
148 QSize WindowBeingDragged::maxSize()
const
150 if (m_floatingWindow)
151 return m_floatingWindow->layoutWidget()->layoutMaximumSizeHint();
156 bool WindowBeingDragged::contains(LayoutWidget *layoutWidget)
const
161 if (m_floatingWindow)
162 return m_floatingWindow->layoutWidget() == layoutWidget;
164 if (
auto fw = qobject_cast<FloatingWindow *>(m_draggableWidget->window())) {
166 return fw->layoutWidget() == layoutWidget && fw->hasSingleFrame();
174 if (m_floatingWindow)
175 return m_floatingWindow->dockWidgets();
180 Draggable *WindowBeingDragged::draggable()
const
185 WindowBeingDraggedWayland::WindowBeingDraggedWayland(
Draggable *draggable)
186 : WindowBeingDragged(draggable)
190 qWarning() << Q_FUNC_INFO <<
"This CTOR is only called on Wayland";
195 if (
auto tb = qobject_cast<TitleBar *>(draggable->asWidget())) {
196 if (
auto fw = tb->floatingWindow()) {
198 m_floatingWindow = fw;
199 }
else if (Frame *frame = tb->frame()) {
202 qWarning() << Q_FUNC_INFO <<
"Shouldn't happen. TitleBar of what ?";
204 }
else if (
auto fw = qobject_cast<FloatingWindow *>(draggable->asWidget())) {
207 m_floatingWindow = fw;
208 #ifdef KDDOCKWIDGETS_QTWIDGETS
209 }
else if (
auto tbw = qobject_cast<TabBarWidget *>(draggable->asWidget())) {
210 m_dockWidget = tbw->currentDockWidget();
211 }
else if (
auto tw = qobject_cast<TabWidgetWidget *>(draggable->asWidget())) {
212 m_frame = tw->frame();
215 qWarning() <<
"Unknown draggable" << draggable->asWidget()
220 WindowBeingDraggedWayland::~WindowBeingDraggedWayland()
224 QPixmap WindowBeingDraggedWayland::pixmap()
const
230 if (m_floatingWindow) {
231 m_floatingWindow->render(&p);
232 }
else if (m_frame) {
234 }
else if (m_dockWidget) {
235 m_dockWidget->render(&p);
241 QStringList WindowBeingDraggedWayland::affinities()
const
243 if (m_floatingWindow)
244 return WindowBeingDragged::affinities();
246 return m_frame->affinities();
247 else if (m_dockWidget)
248 return { m_dockWidget->affinities() };
255 if (m_floatingWindow)
256 return WindowBeingDragged::dockWidgets();
258 return m_frame->dockWidgets();
259 else if (m_dockWidget)
260 return { m_dockWidget };
265 QSize WindowBeingDraggedWayland::size()
const
267 if (m_floatingWindow)
268 return WindowBeingDragged::size();
270 return m_frame->QWidgetAdapter::size();
271 else if (m_dockWidget)
272 return m_dockWidget->size();
274 qWarning() << Q_FUNC_INFO <<
"Unknown size, shouldn't happen";
278 QSize WindowBeingDraggedWayland::minSize()
const
280 if (m_floatingWindow) {
281 return WindowBeingDragged::minSize();
282 }
else if (m_frame) {
283 return m_frame->minSize();
284 }
else if (m_dockWidget) {
288 qWarning() << Q_FUNC_INFO <<
"Unknown minSize, shouldn't happen";
292 QSize WindowBeingDraggedWayland::maxSize()
const
294 if (m_floatingWindow) {
295 return WindowBeingDragged::maxSize();
296 }
else if (m_frame) {
297 return m_frame->maxSizeHint();
298 }
else if (m_dockWidget) {
302 qWarning() << Q_FUNC_INFO <<
"Unknown maxSize, shouldn't happen";