aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2021-04-28 09:59:06 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2021-05-06 00:40:10 +0200
commit9ec72c1917ec46e5228fd4d08dcaa8b5ed86885b (patch)
treeefc24fad4d7c674253a2834e5b0bb129f95759d3 /tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
parent152e12dc22cc0fd07cf90bcd35ae0e05b8b46fa0 (diff)
Make tst_qquickflickable check scaling of drag threshold
We continue to enforce the drag threshold in local (transformed) coordinates: if Flickable should wait until the user drags 12 pixels, but it's scaled to half-size, it will start dragging after only 6 pixels of movement, for example. But if it's also rotated, then the required distance becomes a projection of the actual drag vector onto the vector along which the Flickable should move past the (scaled) drag threshold. I.e. if we rotate the Flickable's parent by 45°, the required distance should be 12 / 2 * √2 ≈ 8.5; 9 pixels will exceed the threshold, then. tst_qquickflickable::clickAndDragWhenTransformed is modified to prove it (at least when a 2D scale is applied). The test should be OK on hidpi because qApp->styleHints()->startDragDistance() is already adjusted. Change-Id: I035a462c75e7c5aba876a67c1b996bccab2c5364 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/quick/qquickflickable/tst_qquickflickable.cpp')
-rw-r--r--tests/auto/quick/qquickflickable/tst_qquickflickable.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
index 57c9dda230..3d57cae9da 100644
--- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
+++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
@@ -1688,7 +1688,8 @@ void tst_qquickflickable::clickAndDragWhenTransformed()
QTRY_COMPARE(flickable->property("itemPressed").toBool(), true);
QTest::mouseRelease(view.data(), Qt::LeftButton, Qt::NoModifier, QPoint(200, 200));
- const int threshold = qApp->styleHints()->startDragDistance();
+ // drag threshold is scaled according to the scene scaling
+ const int threshold = qApp->styleHints()->startDragDistance() * flickable->parentItem()->scale();
// drag outside bounds
moveAndPress(view.data(), QPoint(160, 160));
@@ -1701,10 +1702,18 @@ void tst_qquickflickable::clickAndDragWhenTransformed()
// drag inside bounds
moveAndPress(view.data(), QPoint(200, 140));
+ QCOMPARE(flickable->keepMouseGrab(), false);
QTest::qWait(10);
+ // Flickable should get interested in dragging when the drag is beyond the
+ // threshold distance along the hypoteneuse of the 45° rotation
+ const int deltaPastRotatedThreshold = threshold * 1.414 + 1;
+ QTest::mouseMove(view.data(), QPoint(200 + deltaPastRotatedThreshold, 140));
+ qCDebug(lcTests) << "transformed flickable dragging yet?" << flickable->isDragging() <<
+ "after dragging by" << deltaPastRotatedThreshold << "past scaled threshold" << threshold;
+ QCOMPARE(flickable->isDragging(), false); // Flickable never grabs on the first drag past the threshold
+ QCOMPARE(flickable->keepMouseGrab(), true); // but it plans to do it next time!
QTest::mouseMove(view.data(), QPoint(200 + threshold * 2, 140));
- QTest::mouseMove(view.data(), QPoint(200 + threshold * 3, 140));
- QCOMPARE(flickable->isDragging(), true);
+ QCOMPARE(flickable->isDragging(), true); // it grabs only during the second drag past the threshold
QCOMPARE(flickable->property("itemPressed").toBool(), false);
moveAndRelease(view.data(), QPoint(220, 140));
}