Properly copy all event parameters in deliverMouseEvent()

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>
This commit is contained in:
Laszlo Agocs 2012-04-03 12:24:52 +03:00 committed by Qt by Nokia
parent 664a0e3f49
commit aa959012a8
3 changed files with 16 additions and 13 deletions

View 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());

View 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);

View 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);