diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-05-16 14:52:32 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-07-12 20:25:04 +0000 |
commit | 1bf1a1c460fcfb1555026cbb1127cfc6daee7ca0 (patch) | |
tree | 7135a86b43680bbbbef24b327f8811c69a78b027 /tests/auto/quick/qquickflickable | |
parent | 8092c5617092195d7df02775f423f5e420eb764f (diff) |
Add Flickable.synchronousDrag property
When it is set true, Flickable begins dragging by making the content
jump to the position where it would have been if there was no drag
threshold: that is, the content moves exactly in sync with the mouse
cursor or finger (as long as it's not hitting the bounds).
[ChangeLog][QtQuick][Flickable] Added a synchronousDrag property that
makes the content jump to the position it would have had if there was
no drag threshold, as soon as dragging begins.
Task-number: QTBUG-62902
Change-Id: I5f3b530956363172167896b0f19aec4a41bf82b3
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto/quick/qquickflickable')
-rw-r--r-- | tests/auto/quick/qquickflickable/tst_qquickflickable.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index 248f8447e0..ba266824e6 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -203,6 +203,8 @@ private slots: void overshoot(); void overshoot_data(); void overshoot_reentrant(); + void synchronousDrag_data(); + void synchronousDrag(); private: void flickWithTouch(QQuickWindow *window, const QPoint &from, const QPoint &to); @@ -2458,6 +2460,70 @@ void tst_qquickflickable::overshoot_reentrant() QCOMPARE(flickable->verticalOvershoot(), 25.0); } +void tst_qquickflickable::synchronousDrag_data() +{ + QTest::addColumn<bool>("synchronousDrag"); + + QTest::newRow("default") << false; + QTest::newRow("synch") << true; +} + +void tst_qquickflickable::synchronousDrag() +{ + QFETCH(bool, synchronousDrag); + + QScopedPointer<QQuickView> scopedWindow(new QQuickView); + QQuickView *window = scopedWindow.data(); + window->setSource(testFileUrl("longList.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + QQuickViewTestUtil::centerOnScreen(window); + QQuickViewTestUtil::moveMouseAway(window); + window->show(); + QVERIFY(window->rootObject() != nullptr); + + QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); + QVERIFY(flickable != nullptr); + QCOMPARE(flickable->synchronousDrag(), false); + flickable->setSynchronousDrag(synchronousDrag); + + QPoint p1(100, 100); + QPoint p2(95, 95); + QPoint p3(70, 70); + QPoint p4(50, 50); + QPoint p5(30, 30); + QCOMPARE(flickable->contentY(), 0.0f); + + // Drag via mouse + moveAndPress(window, p1); + QTest::mouseMove(window, p2); + QTest::mouseMove(window, p3); + QTest::mouseMove(window, p4); + QCOMPARE(flickable->contentY(), synchronousDrag ? 50.0f : 0.0f); + QTest::mouseMove(window, p5); + if (!synchronousDrag) + QVERIFY(flickable->contentY() < 50.0f); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, p5); + + // Reset to initial condition + flickable->setContentY(0); + + // Drag via touch + QTest::touchEvent(window, touchDevice).press(0, p1, window); + QQuickTouchUtils::flush(window); + QTest::touchEvent(window, touchDevice).move(0, p2, window); + QQuickTouchUtils::flush(window); + QTest::touchEvent(window, touchDevice).move(0, p3, window); + QQuickTouchUtils::flush(window); + QTest::touchEvent(window, touchDevice).move(0, p4, window); + QQuickTouchUtils::flush(window); + QCOMPARE(flickable->contentY(), synchronousDrag ? 50.0f : 0.0f); + QTest::touchEvent(window, touchDevice).move(0, p5, window); + QQuickTouchUtils::flush(window); + if (!synchronousDrag) + QVERIFY(flickable->contentY() < 50.0f); + QTest::touchEvent(window, touchDevice).release(0, p5, window); +} + QTEST_MAIN(tst_qquickflickable) #include "tst_qquickflickable.moc" |