summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qmainwindow.cpp
diff options
context:
space:
mode:
authorDavid Redondo <qt@david-redondo.de>2023-03-10 16:44:20 +0100
committerDavid Redondo <qt@david-redondo.de>2023-06-02 19:53:34 +0200
commit581c4bcb62a9d3cbb4c33df3f0f7a0a965225e74 (patch)
tree22da571a5a8c0d5fdbfd14a17654cf3a8b28d5ba /src/widgets/widgets/qmainwindow.cpp
parent1eb4d17cb48a70501ebf51fc8732e14fec2cc12f (diff)
Use platform drags for drags of docks and toolbars on wayland
On Wayland we can't know where windows are in relation to each other so the whole mechanism was broken, toolbars were unmovable once undocked and could be blindly redocked. Dockwidgets had native toolbars to move them around but could not be redocked. This introduces an alternative code path that uses a platform drag with a special mimetype that enables the platform to issue a combined drag and window move using the relevant protocol. Should the protocol not be available this doesn't make things actively worse as it will be similar broken as before. Fixes: QTBUG-87332 Change-Id: I3b8bdc0b1bc22569a64cb8bf7ca7d37d223936a6 Reviewed-by: David Edmundson <davidedmundson@kde.org> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/widgets/widgets/qmainwindow.cpp')
-rw-r--r--src/widgets/widgets/qmainwindow.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/widgets/widgets/qmainwindow.cpp b/src/widgets/widgets/qmainwindow.cpp
index a5f7973994..0fc8aeace7 100644
--- a/src/widgets/widgets/qmainwindow.cpp
+++ b/src/widgets/widgets/qmainwindow.cpp
@@ -25,6 +25,7 @@
#include <qstyle.h>
#include <qdebug.h>
#include <qpainter.h>
+#include <qmimedata.h>
#include <private/qwidget_p.h>
#if QT_CONFIG(toolbar)
@@ -36,6 +37,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
class QMainWindowPrivate : public QWidgetPrivate
{
Q_DECLARE_PUBLIC(QMainWindow)
@@ -121,6 +124,7 @@ void QMainWindowPrivate::init()
const int metric = q->style()->pixelMetric(QStyle::PM_ToolBarIconSize, nullptr, q);
iconSize = QSize(metric, metric);
q->setAttribute(Qt::WA_Hover);
+ q->setAcceptDrops(true);
}
/*
@@ -1296,6 +1300,22 @@ bool QMainWindow::event(QEvent *event)
if (!d->explicitIconSize)
setIconSize(QSize());
break;
+#if QT_CONFIG(draganddrop)
+ case QEvent::DragEnter:
+ case QEvent::Drop:
+ if (!d->layout->draggingWidget)
+ break;
+ event->accept();
+ return true;
+ case QEvent::DragMove: {
+ if (!d->layout->draggingWidget)
+ break;
+ auto dragMoveEvent = static_cast<QDragMoveEvent *>(event);
+ d->layout->hover(d->layout->draggingWidget, dragMoveEvent->position().toPoint());
+ event->accept();
+ return true;
+ }
+#endif
default:
break;
}