diff --git a/src/testlib/qtesttouch.h b/src/testlib/qtesttouch.h index b021934355..986d88c686 100644 --- a/src/testlib/qtesttouch.h +++ b/src/testlib/qtesttouch.h @@ -65,7 +65,8 @@ QT_MODULE(Test) #ifdef QT_WIDGETS_LIB extern Q_GUI_EXPORT void qt_translateRawTouchEvent(QWidget *window, QTouchEvent::DeviceType deviceType, - const QList &touchPoints); + const QList &touchPoints, + ulong timestamp); #endif namespace QTest @@ -141,7 +142,7 @@ namespace QTest #ifdef QT_WIDGETS_LIB else if (targetWidget) { - qt_translateRawTouchEvent(targetWidget, deviceType, points.values()); + qt_translateRawTouchEvent(targetWidget, deviceType, points.values(), 0); } #endif } diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index e2a7b27430..07d2632b52 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -5215,7 +5215,8 @@ int QApplicationPrivate::findClosestTouchPointId(const QPointF &screenPos) void QApplicationPrivate::translateRawTouchEvent(QWidget *window, QTouchEvent::DeviceType deviceType, - const QList &touchPoints) + const QList &touchPoints, + ulong timestamp) { QApplicationPrivate *d = self; typedef QPair > StatesAndTouchPoints; @@ -5352,6 +5353,7 @@ void QApplicationPrivate::translateRawTouchEvent(QWidget *window, it.value().first, it.value().second); updateTouchPointsForWidget(widget, &touchEvent); + touchEvent.setTimestamp(timestamp); switch (touchEvent.type()) { case QEvent::TouchBegin: @@ -5374,10 +5376,11 @@ void QApplicationPrivate::translateRawTouchEvent(QWidget *window, } Q_WIDGETS_EXPORT void qt_translateRawTouchEvent(QWidget *window, - QTouchEvent::DeviceType deviceType, - const QList &touchPoints) + QTouchEvent::DeviceType deviceType, + const QList &touchPoints, + ulong timestamp) { - QApplicationPrivate::translateRawTouchEvent(window, deviceType, touchPoints); + QApplicationPrivate::translateRawTouchEvent(window, deviceType, touchPoints, timestamp); } #ifndef QT_NO_GESTURES diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index 092eaa35a4..77a02bd5ab 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -499,7 +499,8 @@ public: void removeTouchPoint(int touchPointId); static void translateRawTouchEvent(QWidget *widget, QTouchEvent::DeviceType deviceType, - const QList &touchPoints); + const QList &touchPoints, + ulong timestamp); #if defined(Q_WS_WIN) static bool HasTouchSupport; diff --git a/src/widgets/kernel/qwidgetwindow_qpa.cpp b/src/widgets/kernel/qwidgetwindow_qpa.cpp index 32a446fa54..7d8b57f233 100644 --- a/src/widgets/kernel/qwidgetwindow_qpa.cpp +++ b/src/widgets/kernel/qwidgetwindow_qpa.cpp @@ -289,7 +289,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) void QWidgetWindow::handleTouchEvent(QTouchEvent *event) { - QApplicationPrivate::translateRawTouchEvent(m_widget, event->deviceType(), event->touchPoints()); + QApplicationPrivate::translateRawTouchEvent(m_widget, event->deviceType(), event->touchPoints(), event->timestamp()); } void QWidgetWindow::handleKeyEvent(QKeyEvent *event) diff --git a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp index d76265c42a..4583e79561 100644 --- a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp +++ b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp @@ -50,6 +50,7 @@ public: bool seenTouchBegin, seenTouchUpdate, seenTouchEnd; bool acceptTouchBegin, acceptTouchUpdate, acceptTouchEnd; bool deleteInTouchBegin, deleteInTouchUpdate, deleteInTouchEnd; + ulong timestamp; tst_QTouchEventWidget() : QWidget() @@ -76,6 +77,7 @@ public: if (seenTouchEnd) qWarning("TouchBegin: TouchEnd cannot happen before TouchBegin"); seenTouchBegin = !seenTouchBegin && !seenTouchUpdate && !seenTouchEnd; touchBeginPoints = static_cast(event)->touchPoints(); + timestamp = static_cast(event)->timestamp(); event->setAccepted(acceptTouchBegin); if (deleteInTouchBegin) delete this; @@ -85,6 +87,7 @@ public: if (seenTouchEnd) qWarning("TouchUpdate: TouchEnd cannot happen before TouchUpdate"); seenTouchUpdate = seenTouchBegin && !seenTouchEnd; touchUpdatePoints = static_cast(event)->touchPoints(); + timestamp = static_cast(event)->timestamp(); event->setAccepted(acceptTouchUpdate); if (deleteInTouchUpdate) delete this; @@ -94,6 +97,7 @@ public: if (seenTouchEnd) qWarning("TouchEnd: already seen a TouchEnd"); seenTouchEnd = seenTouchBegin && !seenTouchEnd; touchEndPoints = static_cast(event)->touchPoints(); + timestamp = static_cast(event)->timestamp(); event->setAccepted(acceptTouchEnd); if (deleteInTouchEnd) delete this; @@ -572,13 +576,16 @@ void tst_QTouchEvent::basicRawEventTranslation() rawTouchPoint.setState(Qt::TouchPointPressed); rawTouchPoint.setScreenPos(screenPos); rawTouchPoint.setNormalizedPos(normalized(rawTouchPoint.pos(), screenGeometry)); + const ulong timestamp = 1234; qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, - QList() << rawTouchPoint); + QList() << rawTouchPoint, + timestamp); QVERIFY(touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); QCOMPARE(touchWidget.touchBeginPoints.count(), 1); + QCOMPARE(touchWidget.timestamp, timestamp); QTouchEvent::TouchPoint touchBeginPoint = touchWidget.touchBeginPoints.first(); QCOMPARE(touchBeginPoint.id(), rawTouchPoint.id()); QCOMPARE(touchBeginPoint.state(), rawTouchPoint.state()); @@ -605,7 +612,8 @@ void tst_QTouchEvent::basicRawEventTranslation() rawTouchPoint.setNormalizedPos(normalized(rawTouchPoint.pos(), screenGeometry)); qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, - QList() << rawTouchPoint); + QList() << rawTouchPoint, + 0); QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -636,7 +644,8 @@ void tst_QTouchEvent::basicRawEventTranslation() rawTouchPoint.setNormalizedPos(normalized(rawTouchPoint.pos(), screenGeometry)); qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, - QList() << rawTouchPoint); + QList() << rawTouchPoint, + 0); QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(touchWidget.seenTouchEnd); @@ -700,7 +709,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() rawTouchPoints[1].setState(Qt::TouchPointPressed); rawTouchPoints[1].setScreenPos(rightScreenPos); rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints); + qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints, 0); QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -761,7 +770,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() rawTouchPoints[1].setState(Qt::TouchPointMoved); rawTouchPoints[1].setScreenPos(centerScreenPos); rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints); + qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints, 0); QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -822,7 +831,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() rawTouchPoints[1].setState(Qt::TouchPointReleased); rawTouchPoints[1].setScreenPos(centerScreenPos); rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints); + qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints, 0); QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -915,7 +924,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() rawTouchPoints[1].setState(Qt::TouchPointPressed); rawTouchPoints[1].setScreenPos(rightScreenPos); rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchPad, rawTouchPoints); + qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchPad, rawTouchPoints, 0); QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -976,7 +985,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() rawTouchPoints[1].setState(Qt::TouchPointMoved); rawTouchPoints[1].setScreenPos(centerScreenPos); rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchPad, rawTouchPoints); + qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchPad, rawTouchPoints, 0); QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -1037,7 +1046,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() rawTouchPoints[1].setState(Qt::TouchPointReleased); rawTouchPoints[1].setScreenPos(centerScreenPos); rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchPad, rawTouchPoints); + qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchPad, rawTouchPoints, 0); QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -1295,20 +1304,20 @@ void tst_QTouchEvent::deleteInRawEventTranslation() rawTouchPoints[2].setNormalizedPos(normalized(rawTouchPoints[2].pos(), screenGeometry)); // generate begin events on all widgets, the left widget should die - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints); + qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints, 0); QVERIFY(pl.isNull() && !pc.isNull() && !pr.isNull()); // generate update events on all widget, the center widget should die rawTouchPoints[0].setState(Qt::TouchPointMoved); rawTouchPoints[1].setState(Qt::TouchPointMoved); rawTouchPoints[2].setState(Qt::TouchPointMoved); - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints); + qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints, 0); // generate end events on all widget, the right widget should die rawTouchPoints[0].setState(Qt::TouchPointReleased); rawTouchPoints[1].setState(Qt::TouchPointReleased); rawTouchPoints[2].setState(Qt::TouchPointReleased); - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints); + qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints, 0); } void tst_QTouchEvent::crashInQGraphicsSceneAfterNotHandlingTouchBegin() diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index 5e22340b5b..a2470ceba8 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -1941,22 +1941,22 @@ void tst_QApplication::touchEventPropagation() TouchEventPropagationTestWidget window; window.setObjectName("1. window"); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); QVERIFY(!window.seenTouchEvent); QVERIFY(!window.seenMouseEvent); window.reset(); window.setAttribute(Qt::WA_AcceptTouchEvents); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); QVERIFY(window.seenTouchEvent); QVERIFY(!window.seenMouseEvent); window.reset(); window.acceptTouchEvent = true; - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); QVERIFY(window.seenTouchEvent); QVERIFY(!window.seenMouseEvent); } @@ -1968,8 +1968,8 @@ void tst_QApplication::touchEventPropagation() TouchEventPropagationTestWidget widget(&window); widget.setObjectName("2. widget"); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); QVERIFY(!widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); QVERIFY(!window.seenTouchEvent); @@ -1978,8 +1978,8 @@ void tst_QApplication::touchEventPropagation() window.reset(); widget.reset(); widget.setAttribute(Qt::WA_AcceptTouchEvents); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); QVERIFY(widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); QVERIFY(!window.seenTouchEvent); @@ -1988,8 +1988,8 @@ void tst_QApplication::touchEventPropagation() window.reset(); widget.reset(); widget.acceptMouseEvent = true; - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); QVERIFY(widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); QVERIFY(!window.seenTouchEvent); @@ -1998,8 +1998,8 @@ void tst_QApplication::touchEventPropagation() window.reset(); widget.reset(); widget.acceptTouchEvent = true; - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); QVERIFY(widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); QVERIFY(!window.seenTouchEvent); @@ -2009,8 +2009,8 @@ void tst_QApplication::touchEventPropagation() widget.reset(); widget.setAttribute(Qt::WA_AcceptTouchEvents, false); window.setAttribute(Qt::WA_AcceptTouchEvents); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); QVERIFY(!widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); QVERIFY(window.seenTouchEvent); @@ -2019,8 +2019,8 @@ void tst_QApplication::touchEventPropagation() window.reset(); widget.reset(); window.acceptTouchEvent = true; - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); QVERIFY(!widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); QVERIFY(window.seenTouchEvent); @@ -2030,8 +2030,8 @@ void tst_QApplication::touchEventPropagation() widget.reset(); widget.acceptMouseEvent = true; // doesn't matter, touch events are propagated first window.acceptTouchEvent = true; - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); QVERIFY(!widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); QVERIFY(window.seenTouchEvent);