summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGatis Paeglis <gatis.paeglis@qt.io>2019-03-26 00:02:22 +0100
committerGatis Paeglis <gatis.paeglis@qt.io>2019-03-26 13:49:53 +0000
commit243c8403903781a28832e0bf34ce962058300e99 (patch)
treeb6c447b43bfe8cd278d4cc57c8bd9b6e84527ab0 /tests
parentc3226bd5cc6bf009d2fb3c233a09f3ef5cf618e9 (diff)
Drag'n'Drop: fix dnd regression
DragEnter events always should start with the default state, which is accepted = false. This was a copy-and-paste error introduced by f8944a7f07112c85dc4f66848cabb490514cd28e. Fixes: QTBUG-73977 Change-Id: I34b3ea97c9b4f4fc040a9e6f1befd6124533361d Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp
index 431d6ba960..8b558aa56f 100644
--- a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp
+++ b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp
@@ -46,6 +46,9 @@
#include <private/qwindow_p.h>
#include <private/qguiapplication_p.h>
#include <qpa/qplatformintegration.h>
+#include <qpa/qwindowsysteminterface.h>
+#include <qpa/qplatformdrag.h>
+#include <private/qhighdpiscaling_p.h>
#include <QtTest/private/qtesthelpers_p.h>
@@ -87,6 +90,7 @@ private slots:
#if QT_CONFIG(draganddrop)
void tst_dnd();
void tst_dnd_events();
+ void tst_dnd_propagation();
#endif
void tst_qtbug35600();
@@ -744,6 +748,77 @@ void tst_QWidget_window::tst_dnd_events()
QCOMPARE(dndWidget._dndEvents, expectedDndEvents);
}
+
+class DropTarget : public QWidget
+{
+public:
+ explicit DropTarget()
+ {
+ setAcceptDrops(true);
+
+ const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry();
+ auto width = availableGeometry.width() / 6;
+ auto height = availableGeometry.height() / 4;
+
+ setGeometry(availableGeometry.x() + 200, availableGeometry.y() + 200, width, height);
+
+ QLabel *label = new QLabel(QStringLiteral("Test"), this);
+ label->setGeometry(40, 40, 60, 60);
+ label->setAcceptDrops(true);
+ }
+
+ void dragEnterEvent(QDragEnterEvent *event) override
+ {
+ event->accept();
+ mDndEvents.append("enter ");
+ }
+
+ void dragMoveEvent(QDragMoveEvent *event) override
+ {
+ event->acceptProposedAction();
+ }
+
+ void dragLeaveEvent(QDragLeaveEvent *) override
+ {
+ mDndEvents.append("leave ");
+ }
+
+ void dropEvent(QDropEvent *event) override
+ {
+ event->accept();
+ mDndEvents.append("drop ");
+ }
+
+ QString mDndEvents;
+};
+
+void tst_QWidget_window::tst_dnd_propagation()
+{
+ QMimeData mimeData;
+ mimeData.setText(QLatin1String("testmimetext"));
+
+ DropTarget target;
+ target.show();
+ QVERIFY(QTest::qWaitForWindowActive(&target));
+
+ Qt::DropActions supportedActions = Qt::DropAction::CopyAction;
+ QWindow *window = target.windowHandle();
+
+ auto posInsideDropTarget = QHighDpi::toNativePixels(QPoint(20, 20), window->screen());
+ auto posInsideLabel = QHighDpi::toNativePixels(QPoint(60, 60), window->screen());
+
+ // Enter DropTarget.
+ QWindowSystemInterface::handleDrag(window, &mimeData, posInsideDropTarget, supportedActions, 0, 0);
+ // Enter QLabel. This will propagate because default QLabel does
+ // not accept the drop event in dragEnterEvent().
+ QWindowSystemInterface::handleDrag(window, &mimeData, posInsideLabel, supportedActions, 0, 0);
+ // Drop on QLabel. DropTarget will get dropEvent(), because it accepted the event.
+ QWindowSystemInterface::handleDrop(window, &mimeData, posInsideLabel, supportedActions, 0, 0);
+
+ QGuiApplication::processEvents();
+
+ QCOMPARE(target.mDndEvents, "enter leave enter drop ");
+}
#endif
void tst_QWidget_window::tst_qtbug35600()