diff options
-rw-r--r-- | src/quicktemplates2/qquickdrawer.cpp | 12 | ||||
-rw-r--r-- | tests/auto/drawer/data/flickable.qml (renamed from tests/auto/drawer/data/flicking.qml) | 0 | ||||
-rw-r--r-- | tests/auto/drawer/tst_drawer.cpp | 65 |
3 files changed, 53 insertions, 24 deletions
diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp index 5fdc8be4..2ca0f6c3 100644 --- a/src/quicktemplates2/qquickdrawer.cpp +++ b/src/quicktemplates2/qquickdrawer.cpp @@ -301,10 +301,12 @@ bool QQuickDrawerPrivate::grabMouse(QQuickItem *item, QMouseEvent *event) const int threshold = qMax(20, QGuiApplication::styleHints()->startDragDistance() + 5); bool overThreshold = false; if (position > 0 || dragMargin > 0) { + const bool xOverThreshold = QQuickWindowPrivate::dragOverThreshold(movePoint.x() - pressPoint.x(), Qt::XAxis, event, threshold); + const bool yOverThreshold = QQuickWindowPrivate::dragOverThreshold(movePoint.y() - pressPoint.y(), Qt::YAxis, event, threshold); if (edge == Qt::LeftEdge || edge == Qt::RightEdge) - overThreshold = QQuickWindowPrivate::dragOverThreshold(movePoint.x() - pressPoint.x(), Qt::XAxis, event, threshold); + overThreshold = xOverThreshold && !yOverThreshold; else - overThreshold = QQuickWindowPrivate::dragOverThreshold(movePoint.y() - pressPoint.y(), Qt::YAxis, event, threshold); + overThreshold = yOverThreshold && !xOverThreshold; } // Don't be too eager to steal presses outside the drawer (QTBUG-53929) @@ -351,10 +353,12 @@ bool QQuickDrawerPrivate::grabTouch(QQuickItem *item, QTouchEvent *event) // larger threshold to avoid being too eager to steal touch (QTBUG-50045) const int threshold = qMax(20, QGuiApplication::styleHints()->startDragDistance() + 5); if (position > 0 || dragMargin > 0) { + const bool xOverThreshold = QQuickWindowPrivate::dragOverThreshold(movePoint.x() - pressPoint.x(), Qt::XAxis, &point, threshold); + const bool yOverThreshold = QQuickWindowPrivate::dragOverThreshold(movePoint.y() - pressPoint.y(), Qt::YAxis, &point, threshold); if (edge == Qt::LeftEdge || edge == Qt::RightEdge) - overThreshold = QQuickWindowPrivate::dragOverThreshold(movePoint.x() - pressPoint.x(), Qt::XAxis, &point, threshold); + overThreshold = xOverThreshold && !yOverThreshold; else - overThreshold = QQuickWindowPrivate::dragOverThreshold(movePoint.y() - pressPoint.y(), Qt::YAxis, &point, threshold); + overThreshold = yOverThreshold && !xOverThreshold; } // Don't be too eager to steal presses outside the drawer (QTBUG-53929) diff --git a/tests/auto/drawer/data/flicking.qml b/tests/auto/drawer/data/flickable.qml index 62256afd..62256afd 100644 --- a/tests/auto/drawer/data/flicking.qml +++ b/tests/auto/drawer/data/flickable.qml diff --git a/tests/auto/drawer/tst_drawer.cpp b/tests/auto/drawer/tst_drawer.cpp index 37f00050..a7ebaa9e 100644 --- a/tests/auto/drawer/tst_drawer.cpp +++ b/tests/auto/drawer/tst_drawer.cpp @@ -91,7 +91,8 @@ private slots: void interactive_data(); void interactive(); - void flicking(); + void flickable_data(); + void flickable(); private: struct TouchDeviceDeleter @@ -889,9 +890,25 @@ void tst_Drawer::interactive() QCOMPARE(aboutToHideSpy.count(), 0); } -void tst_Drawer::flicking() +void tst_Drawer::flickable_data() { - QQuickApplicationHelper helper(this, QStringLiteral("flicking.qml")); + QTest::addColumn<bool>("mouse"); + QTest::addColumn<QPoint>("from"); + QTest::addColumn<QPoint>("to"); + + QTest::newRow("mouse,straight") << true << QPoint(200, 200) << QPoint(200, 100); + QTest::newRow("mouse,diagonal") << true << QPoint(200, 200) << QPoint(250, 100); + QTest::newRow("touch,straight") << false << QPoint(200, 200) << QPoint(200, 100); + QTest::newRow("touch,diagonal") << false << QPoint(200, 200) << QPoint(250, 100); +} + +void tst_Drawer::flickable() +{ + QFETCH(bool, mouse); + QFETCH(QPoint, from); + QFETCH(QPoint, to); + + QQuickApplicationHelper helper(this, QStringLiteral("flickable.qml")); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -908,23 +925,31 @@ void tst_Drawer::flicking() drawer->open(); QVERIFY(drawerOpenedSpy.wait()); - // mouse - QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(200, 200)); - for (int y = 200; y > 100; y -= 10) - QTest::mouseMove(window, QPoint(200, y), 1); - QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(200, 100)); - QVERIFY(flickable->isFlicking()); - - // reset - flickable->setContentY(0); - QVERIFY(!flickable->isFlicking()); - - // touch - QTest::touchEvent(window, touchDevice.data()).press(0, QPoint(200, 200)); - for (int y = 200; y > 100; y -= 10) - QTest::touchEvent(window, touchDevice.data()).move(0, QPoint(200, y)); - QTest::touchEvent(window, touchDevice.data()).release(0, QPoint(200, 100)); - QVERIFY(flickable->isFlicking()); + if (mouse) + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, from); + else + QTest::touchEvent(window, touchDevice.data()).press(0, from); + + static const int steps = 10; + for (int i = 0; i < steps; ++i) { + int x = i * qAbs(from.x() - to.x()) / steps; + int y = i * qAbs(from.y() - to.y()) / steps; + + if (mouse) + QTest::mouseMove(window, QPoint(x, y)); + else + QTest::touchEvent(window, touchDevice.data()).move(0, QPoint(x, y)); + QTest::qWait(1); // avoid infinite velocity + } + + QVERIFY(flickable->isDragging()); + + if (mouse) + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, to); + else + QTest::touchEvent(window, touchDevice.data()).release(0, to); + + QVERIFY(!flickable->isDragging()); } QTEST_MAIN(tst_Drawer) |