diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-09-27 17:48:55 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-09-28 17:18:23 +0000 |
commit | 0533725c60198aeced54ad53454a09a3b3691394 (patch) | |
tree | c5a4e74cb7351c2cc2588cd6570c6aea51a4d18a /tests/auto | |
parent | ad78142247bc06fa318b67d3a990f19b9c911a5a (diff) |
Flickable: don't react to any mouse button other than the left
In case of mouse "chording", ignore all other buttons.
Fixes: QTBUG-96909
Change-Id: Ib091b271390c5b4e3aafbbe24d2dc7b6f08db175
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit f91aa3b4d8ae7bfba65a8252099ded3b428f7acf)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/quick/qquickflickable/data/dragon.qml | 15 | ||||
-rw-r--r-- | tests/auto/quick/qquickflickable/tst_qquickflickable.cpp | 50 |
2 files changed, 65 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickflickable/data/dragon.qml b/tests/auto/quick/qquickflickable/data/dragon.qml new file mode 100644 index 0000000000..b82477453b --- /dev/null +++ b/tests/auto/quick/qquickflickable/data/dragon.qml @@ -0,0 +1,15 @@ +import QtQuick 2.12 + +Flickable { + id: flick + width: 320 + height: 320 + contentWidth: 500 + contentHeight: 500 + Text { + anchors.centerIn: parent + font.pixelSize: 50 + text: "🐉" + color: flick.dragging ? "orange" : "grey" + } +} diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index 57c9dda230..2146836048 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -205,6 +205,8 @@ private slots: void synchronousDrag(); void visibleAreaBinding(); void parallelTouch(); + void ignoreNonLeftMouseButtons(); + void ignoreNonLeftMouseButtons_data(); private: void flickWithTouch(QQuickWindow *window, const QPoint &from, const QPoint &to); @@ -2649,6 +2651,54 @@ void tst_qquickflickable::parallelTouch() // QTBUG-30840 QTRY_VERIFY(!flickable2->isMoving()); } +void tst_qquickflickable::ignoreNonLeftMouseButtons() // QTBUG-96909 +{ + QFETCH(Qt::MouseButton, otherButton); + const int threshold = qApp->styleHints()->startDragDistance(); + QQuickView view; + view.setSource(testFileUrl("dragon.qml")); + view.show(); + view.requestActivate(); + QQuickFlickable *flickable = static_cast<QQuickFlickable *>(view.rootObject()); + QSignalSpy dragSpy(flickable, &QQuickFlickable::draggingChanged); + + // Drag with left button + QPoint p1(100, 100); + moveAndPress(&view, p1); + for (int i = 0; i < 8; ++i) { + p1 -= QPoint(threshold, threshold); + QTest::mouseMove(&view, p1, 50); + } + QVERIFY(flickable->isDragging()); + QCOMPARE(dragSpy.count(), 1); + + // Press other button too, then release left button: dragging changes to false + QTest::mousePress(&view, otherButton); + QTest::mouseRelease(&view, Qt::LeftButton); + QTRY_COMPARE(flickable->isDragging(), false); + QCOMPARE(dragSpy.count(), 2); + + // Drag further with the other button held: Flickable ignores it + for (int i = 0; i < 8; ++i) { + p1 -= QPoint(threshold, threshold); + QTest::mouseMove(&view, p1, 50); + } + QCOMPARE(flickable->isDragging(), false); + QCOMPARE(dragSpy.count(), 2); + + // Release other button: nothing happens + QTest::mouseRelease(&view, otherButton); + QCOMPARE(dragSpy.count(), 2); +} + +void tst_qquickflickable::ignoreNonLeftMouseButtons_data() +{ + QTest::addColumn<Qt::MouseButton>("otherButton"); + + QTest::newRow("right") << Qt::RightButton; + QTest::newRow("middle") << Qt::MiddleButton; +} + QTEST_MAIN(tst_qquickflickable) #include "tst_qquickflickable.moc" |