aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp')
-rw-r--r--tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp127
1 files changed, 127 insertions, 0 deletions
diff --git a/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp b/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp
index 9c9ca2fe00..2cb26124ae 100644
--- a/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp
+++ b/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp
@@ -69,8 +69,11 @@ private slots:
void touchPassiveGrabbers_data();
void touchPassiveGrabbers();
void touchPinchAndMouseMove();
+ void unsuitableEventDuringDrag();
+ void underModalLayer();
private:
+ void sendWheelEvent(QQuickView &window, QPoint pos, QPoint angleDelta, QPoint pixelDelta, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, bool inverted);
void createView(QScopedPointer<QQuickView> &window, const char *fileName);
QSet<QQuickPointerHandler *> passiveGrabbers(QQuickWindow *window, int pointId = 0);
QPointingDevice *touchDevice;
@@ -821,6 +824,130 @@ void tst_DragHandler::touchPinchAndMouseMove()
}
}
+void tst_DragHandler::unsuitableEventDuringDrag()
+{
+ QScopedPointer<QQuickView> windowPtr;
+ createView(windowPtr, "dragAndWheel.qml");
+ QQuickView *window = windowPtr.data();
+ auto root = window->rootObject();
+ QQmlProperty changeCount(root, "changeCount");
+ QQmlProperty wheelHandlerEnabled(root, "wheelHandlerEnabled");
+ bool ok = false;
+ QCOMPARE(changeCount.read().toInt(&ok), 0);
+ QVERIFY(ok);
+ QCOMPARE(wheelHandlerEnabled.read().toBool(), true);
+
+ QPoint p1(100, 100);
+ QPoint p2(150, 150);
+
+ QTest::QTouchEventSequence touch = QTest::touchEvent(window, touchDevice);
+ // When we start dragging...
+ touch.press(3,p1).commit();
+ touch.move(3, p2).commit();
+ QQuickTouchUtils::flush(window);
+ // the DragHandler becomes active
+ ok = false;
+ QCOMPARE(changeCount.read().toInt(&ok), 1);
+ QVERIFY(ok);
+ QCOMPARE(wheelHandlerEnabled.read().toBool(), false);
+
+ // When a scroll event arrives while we are dragging
+ sendWheelEvent(*window, p2, QPoint(160, 120), QPoint(-360, 120), Qt::NoModifier, Qt::ScrollBegin, false);
+ // nothing changes because the DragHandler is still active, and the wheel handler stays disabled
+ ok = false;
+ QCOMPARE(changeCount.read().toInt(&ok), 1);
+ QVERIFY(ok);
+ QCOMPARE(wheelHandlerEnabled.read().toBool(), false);
+
+ // When we stop dragging...
+ touch.release(3, p2).commit();
+ QQuickTouchUtils::flush(window);
+
+ // the wheel handler becomes active again
+ ok = false;
+ QCOMPARE(changeCount.read().toInt(&ok), 2);
+ QVERIFY(ok);
+ QCOMPARE(wheelHandlerEnabled.read().toBool(), true);
+
+ // During the whole sequence the wheel handler never got a wheel event
+ // as it was disabled:
+ QQmlProperty gotWheel(root, "gotWheel");
+ QVERIFY(!gotWheel.read().toBool());
+
+ // If the WheelHandler is unconditionally enabled...
+ wheelHandlerEnabled.write(true);
+ // it receives scroll events during drags.
+ touch.press(4,p2).commit();
+ touch.move(4, p1).commit();
+ QQuickTouchUtils::flush(window);
+ sendWheelEvent(*window, p2, QPoint(160, 120), QPoint(-360, 120), Qt::NoModifier, Qt::ScrollBegin, false);
+ touch.release(4, p2).commit();
+ QQuickTouchUtils::flush(window);
+ QVERIFY(gotWheel.read().toBool());
+}
+
+void tst_DragHandler::sendWheelEvent(QQuickView &window, QPoint pos, QPoint angleDelta, QPoint pixelDelta, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, bool inverted)
+{
+ QWheelEvent wheelEvent(pos, window.mapToGlobal(pos), pixelDelta, angleDelta,
+ Qt::NoButton, modifiers, phase, inverted);
+ QGuiApplication::sendEvent(&window, &wheelEvent);
+ qApp->processEvents();
+ QQuickTouchUtils::flush(&window);
+}
+
+class ModalLayer : public QQuickItem {
+public:
+ explicit ModalLayer(QQuickItem* parent = nullptr) : QQuickItem(parent) {
+ this->setAcceptedMouseButtons(Qt::AllButtons);
+ this->setAcceptTouchEvents(true);
+ this->setKeepMouseGrab(true);
+ this->setKeepTouchGrab(true);
+ }
+
+ bool event(QEvent* event) override {
+ switch (event->type()) {
+ case QEvent::KeyPress:
+ case QEvent::MouseMove:
+ case QEvent::MouseButtonPress:
+ case QEvent::MouseButtonRelease:
+ case QEvent::MouseTrackingChange:
+ case QEvent::MouseButtonDblClick:
+ case QEvent::Wheel:
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchCancel:
+ case QEvent::TouchEnd: {
+ qCDebug(lcPointerTests) << "BLOCK!" << event->type();
+ return true;
+ }
+ default: break;
+ }
+ return QQuickItem::event(event);
+ }
+};
+
+void tst_DragHandler::underModalLayer() // QTBUG-78258
+{
+ qmlRegisterType<ModalLayer>("Test", 1, 0, "ModalLayer");
+
+ const int dragThreshold = QGuiApplication::styleHints()->startDragDistance();
+ QScopedPointer<QQuickView> windowPtr;
+ createView(windowPtr, "dragHandlerUnderModalLayer.qml");
+ QQuickView * window = windowPtr.data();
+ QPointer<QQuickDragHandler> dragHandler = window->rootObject()->findChild<QQuickDragHandler*>();
+ QVERIFY(dragHandler);
+
+ QPoint p1(250, 250);
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, p1);
+ p1 += QPoint(dragThreshold, dragThreshold);
+ QTest::mouseMove(window, p1);
+ QVERIFY(!dragHandler->active());
+ p1 += QPoint(dragThreshold, dragThreshold);
+ QTest::mouseMove(window, p1);
+ QVERIFY(!dragHandler->active());
+ QTest::mouseRelease(window, Qt::LeftButton);
+}
+
QTEST_MAIN(tst_DragHandler)
#include "tst_qquickdraghandler.moc"