aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickmultipointtoucharea
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2018-08-29 19:59:53 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2018-08-30 18:24:50 +0000
commit9e9acff340032bd4ec5ee6fbd1b13cd51e14ca3d (patch)
treee5ae9cb1f0316734e035f2428daf9a594e2aa4e3 /tests/auto/quick/qquickmultipointtoucharea
parent920f50731a8fe7507aece1318c9e91f3f12b525e (diff)
MultiPointTouchArea: capture the mouse position on press
QTouchEvent::TouchPoint already remembers the start position from where the touch point was pressed. But when MPTA handles mouse events, it populates a synthetic touchpoint (the _mouseQpaTouchPoint variable). So to be fully consistent, it needs to store the mouse press position there too. Since this was not done, gestureStarted was emitted for almost any mouse movement (while pressed) because the stored startPos was 0,0, so MPTA would nearly always think the drag threshold had already been exceeded. In a QML onGestureStarted callback gesture.touchPoints[0].startX and startY were always zero too. Amends fe2de633f9b9454ec8a9c2a5874ad85f49d8d54d Fixes: QTBUG-70258 Change-Id: I5bc0abbe0cb52c1aa02d60a76c52ec26bb0683e6 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'tests/auto/quick/qquickmultipointtoucharea')
-rw-r--r--tests/auto/quick/qquickmultipointtoucharea/data/mouse.qml9
-rw-r--r--tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp53
2 files changed, 62 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickmultipointtoucharea/data/mouse.qml b/tests/auto/quick/qquickmultipointtoucharea/data/mouse.qml
index 0abcc76f7c..b0410dac4a 100644
--- a/tests/auto/quick/qquickmultipointtoucharea/data/mouse.qml
+++ b/tests/auto/quick/qquickmultipointtoucharea/data/mouse.qml
@@ -6,6 +6,9 @@ MultiPointTouchArea {
property int touchCount: 0
property int cancelCount: 0
+ property int gestureStartedX: 0
+ property int gestureStartedY: 0
+ property bool grabGesture: false
minimumTouchPoints: 1
maximumTouchPoints: 4
@@ -17,6 +20,12 @@ MultiPointTouchArea {
onPressed: { touchCount = touchPoints.length }
onTouchUpdated: { touchCount = touchPoints.length }
onCanceled: { cancelCount = touchPoints.length }
+ onGestureStarted: {
+ gestureStartedX = gesture.touchPoints[0].startX
+ gestureStartedY = gesture.touchPoints[0].startY
+ if (grabGesture)
+ gesture.grab()
+ }
Rectangle {
color: "red"
diff --git a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp
index 73f3cab318..d4ad282701 100644
--- a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp
+++ b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp
@@ -69,6 +69,8 @@ private slots:
void transformedTouchArea();
void mouseInteraction();
void mouseInteraction_data();
+ void mouseGestureStarted_data();
+ void mouseGestureStarted();
void cancel();
private:
@@ -1196,6 +1198,57 @@ void tst_QQuickMultiPointTouchArea::mouseInteraction()
QCOMPARE(area->property("touchCount").toInt(), 0);
}
+void tst_QQuickMultiPointTouchArea::mouseGestureStarted_data()
+{
+ QTest::addColumn<bool>("grabGesture");
+ QTest::addColumn<int>("distanceFromOrigin");
+
+ QTest::newRow("near origin, don't grab") << false << 4;
+ QTest::newRow("near origin, grab") << true << 4;
+ QTest::newRow("away from origin, don't grab") << false << 100;
+ QTest::newRow("away from origin, grab") << true << 100;
+}
+
+void tst_QQuickMultiPointTouchArea::mouseGestureStarted() // QTBUG-70258
+{
+ const int dragThreshold = QGuiApplication::styleHints()->startDragDistance();
+ QFETCH(bool, grabGesture);
+ QFETCH(int, distanceFromOrigin);
+
+ QScopedPointer<QQuickView> view(createAndShowView("mouse.qml"));
+ QVERIFY(view->rootObject() != nullptr);
+
+ QQuickMultiPointTouchArea *area = qobject_cast<QQuickMultiPointTouchArea *>(view->rootObject());
+ QVERIFY(area);
+ area->setProperty("grabGesture", grabGesture);
+ QQuickTouchPoint *point1 = view->rootObject()->findChild<QQuickTouchPoint*>("point1");
+ QCOMPARE(point1->pressed(), false);
+ QSignalSpy gestureStartedSpy(area, SIGNAL(gestureStarted(QQuickGrabGestureEvent *)));
+
+ QPoint p1 = QPoint(distanceFromOrigin, distanceFromOrigin);
+ QTest::mousePress(view.data(), Qt::LeftButton, Qt::NoModifier, p1);
+ QCOMPARE(gestureStartedSpy.count(), 0);
+
+ p1 += QPoint(dragThreshold, dragThreshold);
+ QTest::mouseMove(view.data(), p1);
+ QCOMPARE(gestureStartedSpy.count(), 0);
+
+ p1 += QPoint(1, 1);
+ QTest::mouseMove(view.data(), p1);
+ QTRY_COMPARE(gestureStartedSpy.count(), 1);
+ QTRY_COMPARE(area->property("gestureStartedX").toInt(), distanceFromOrigin);
+ QCOMPARE(area->property("gestureStartedY").toInt(), distanceFromOrigin);
+
+ p1 += QPoint(10, 10);
+ QTest::mouseMove(view.data(), p1);
+ // if nobody called gesteure->grab(), gestureStarted will keep happening
+ QTRY_COMPARE(gestureStartedSpy.count(), grabGesture ? 1 : 2);
+ QCOMPARE(area->property("gestureStartedX").toInt(), distanceFromOrigin);
+ QCOMPARE(area->property("gestureStartedY").toInt(), distanceFromOrigin);
+
+ QTest::mouseRelease(view.data(), Qt::LeftButton);
+}
+
void tst_QQuickMultiPointTouchArea::cancel()
{
QScopedPointer<QQuickView> window(createAndShowView("cancel.qml"));