Fix Flickable generated release event with pressDelay.
authorMartin Jones <martin.jones@jollamobile.com>
Wed, 8 Jan 2014 07:04:35 +0000 (17:04 +1000)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 8 Jan 2014 23:54:55 +0000 (00:54 +0100)
Map mouse position to grabber when forwarding release event due to
release before pressDelay timeout.

Task-number: QTBUG-34570
Change-Id: I7214077c9ac95f77407cf66f9dad52f577eccd79
Reviewed-by: Matthew Vogt <matthew.vogt@qinetic.com.au>
src/quick/items/qquickflickable.cpp
tests/auto/quick/qquickflickable/data/pressDelay.qml
tests/auto/quick/qquickflickable/tst_qquickflickable.cpp

index 3b592004c9b9bce4e211a73ea5916d200cd7cf21..7cc37e05569125e3e3aaea34788484414292a247 100644 (file)
@@ -1234,7 +1234,11 @@ void QQuickFlickable::mouseReleaseEvent(QMouseEvent *event)
             d->replayDelayedPress();
 
             // Now send the release
-            window()->sendEvent(window()->mouseGrabberItem(), event);
+            if (window()->mouseGrabberItem()) {
+                QPointF localPos = window()->mouseGrabberItem()->mapFromScene(event->windowPos());
+                QScopedPointer<QMouseEvent> mouseEvent(QQuickWindowPrivate::cloneMouseEvent(event, &localPos));
+                window()->sendEvent(window()->mouseGrabberItem(), mouseEvent.data());
+            }
 
             // And the event has been consumed
             d->stealMouse = false;
index 18a5840504c3bdacbab930305d9fc199b4ce432a..a69c4af6de158435cec14ad5f93f2e27112807d8 100644 (file)
@@ -8,6 +8,11 @@ Flickable {
     contentHeight: 400
     pressDelay: 100
 
+    property real pressX
+    property real pressY
+    property real releaseX
+    property real releaseY
+
     MouseArea {
         id: ma
         objectName: "mouseArea"
@@ -16,6 +21,15 @@ Flickable {
         width: 240
         height: 100
 
+        onPressed: {
+            pressX = mouse.x
+            pressY = mouse.y
+        }
+        onReleased: {
+            releaseX = mouse.x
+            releaseY = mouse.y
+        }
+
         Rectangle {
             anchors.fill: parent
             color: parent.pressed ? 'blue' : 'green'
index 794f9a8af631121bc20f32ce3f075172b6718977..86321c775e2148496814fdff1deac844983a918c 100644 (file)
@@ -412,6 +412,29 @@ void tst_qquickflickable::pressDelay()
     QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(150, 150));
     QCOMPARE(clickedSpy.count(),1);
 
+    // Press and release position should match
+    QCOMPARE(flickable->property("pressX").toReal(), flickable->property("releaseX").toReal());
+    QCOMPARE(flickable->property("pressY").toReal(), flickable->property("releaseY").toReal());
+
+
+    // Test a quick tap within the pressDelay timeout
+    clickedSpy.clear();
+    QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(180, 180));
+
+    // The press should not occur immediately
+    QVERIFY(mouseArea->property("pressed").toBool() == false);
+
+    QCOMPARE(clickedSpy.count(),0);
+
+    // On release the press, release and clicked signal should be emitted
+    QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(180, 180));
+    QCOMPARE(clickedSpy.count(),1);
+
+    // Press and release position should match
+    QCOMPARE(flickable->property("pressX").toReal(), flickable->property("releaseX").toReal());
+    QCOMPARE(flickable->property("pressY").toReal(), flickable->property("releaseY").toReal());
+
+
     // QTBUG-31168
     QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(150, 110));