Properly copy all event parameters in deliverMouseEvent()
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>
Tue, 3 Apr 2012 09:24:52 +0000 (12:24 +0300)
committerQt by Nokia <qt-info@nokia.com>
Thu, 5 Apr 2012 07:50:05 +0000 (09:50 +0200)
Timestamp and capabilities were missing. One of the very special flick
test cases needs to be fixed, because setting the proper timestamp
will now generate correct velocities. A potentially dangerous, legacy
implementation of flick() has also been updated to match how QTestLib
works in Qt 5.

Change-Id: Ibc99f7212ba21d41a419eaadac2fdda730658dc6
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/quick/items/qquickcanvas.cpp
tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
tests/auto/quick/shared/viewtestutil.cpp

index 29733e9..382c5e8 100644 (file)
@@ -1092,8 +1092,12 @@ bool QQuickCanvasPrivate::deliverMouseEvent(QMouseEvent *event)
         QQuickMouseEventEx me(event->type(), transform.map(event->windowPos()),
                                 event->windowPos(), event->screenPos(),
                                 event->button(), event->buttons(), event->modifiers());
-        if (QQuickMouseEventEx::extended(event))
-            me.setVelocity(QQuickMouseEventEx::extended(event)->velocity());
+        QQuickMouseEventEx *eventEx = QQuickMouseEventEx::extended(event);
+        if (eventEx) {
+            me.setVelocity(eventEx->velocity());
+            me.setCapabilities(eventEx->capabilities());
+        }
+        me.setTimestamp(event->timestamp());
         me.accept();
         q->sendEvent(mouseGrabberItem, &me);
         event->setAccepted(me.isAccepted());
index 2ed42e7..f926dbe 100644 (file)
@@ -443,11 +443,14 @@ void tst_qquickflickable::movingAndDragging()
 
     // Vertical with a quick press-move-release: should cause a flick in release.
     QSignalSpy vFlickSpy(flickable, SIGNAL(flickingVerticallyChanged()));
-
-    QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(50, 90));
-    QTest::qWait(10);
-    QTest::mouseMove(canvas, QPoint(50, 40));
-    QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(50, 40));
+    // Use something that generates a huge velocity just to make it testable.
+    // In practice this feature matters on touchscreen devices where the
+    // underlying drivers will hopefully provide a pre-calculated velocity
+    // (based on more data than what the UI gets), thus making this use case
+    // working even with small movements.
+    QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(50, 10));
+    QTest::mouseMove(canvas, QPoint(50, 300), 10);
+    QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(50, 100), 10);
 
     QCOMPARE(vFlickSpy.count(), 1);
 
index d00a0e2..1c4319f 100644 (file)
@@ -88,12 +88,8 @@ void QQuickViewTestUtil::flick(QQuickView *canvas, const QPoint &from, const QPo
     // send press, five equally spaced moves, and release.
     QTest::mousePress(canvas, Qt::LeftButton, 0, from);
 
-    for (int i = 0; i < pointCount; ++i) {
-        QMouseEvent mv(QEvent::MouseMove, from + (i+1)*diff/pointCount, Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
-        QGuiApplication::sendEvent(canvas, &mv);
-        QTest::qWait(duration/pointCount);
-        QCoreApplication::processEvents();
-    }
+    for (int i = 0; i < pointCount; ++i)
+        QTest::mouseMove(canvas, from + (i+1)*diff/pointCount, duration / pointCount);
 
     QTest::mouseRelease(canvas, Qt::LeftButton, 0, to);
     QTest::qWait(50);