diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-01-12 20:17:15 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-01-14 21:01:52 +0000 |
commit | 5d0c1fc29fe97c7a121cc73e5c41a4ecb0e132ce (patch) | |
tree | e6aefa4e11160034f504293ba89dcf5dd3f5e047 /tests/auto | |
parent | ca4f26320dba0452b8b3a2910bb39ba12c109e25 (diff) |
AA_SynthesizeTouchForUnhandledMouseEvents: keep correct coordinates
QGuiApplicationPrivate::processMouseEvent() sends a
QWindowSystemInterfacePrivate::TouchEvent if the mouse event is not
accepted and AA_SynthesizeTouchForUnhandledMouseEvents is enabled.
A QPA TouchEvent always contains native touch points, which is why
it calls QWindowSystemInterfacePrivate::fromNativeTouchPoints to
translate the QMouseEvent's device-independent position back to the
raw position that it would have had if it came from a real touchscreen.
Therefore we must give that function touchpoints that are actually in
native coordinates.
It may be that some of this transformation could be avoided entirely,
but here we prove that the existing way works correctly, by adding
coordinate checking to the tst_QWindow::mouseToTouchTranslation() test.
Task-number: QTBUG-86165
Change-Id: I4c9ca2b11e9eb76d79712c187db3eb9865da581a
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit aeeac48cbdea744406f0c8abefe271f571b61d07)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 602e5a0178..3b5f395a43 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -1033,11 +1033,16 @@ public: touchEventType = event->type(); QList<QTouchEvent::TouchPoint> points = event->points(); for (int i = 0; i < points.count(); ++i) { - switch (points.at(i).state()) { + const auto &point = points.at(i); + switch (point.state()) { case QEventPoint::State::Pressed: ++touchPressedCount; if (spinLoopWhenPressed) QCoreApplication::processEvents(); + if (i == 0) { + touchPressLocalPos = point.position(); + touchPressGlobalPos = point.globalPosition(); + } break; case QEventPoint::State::Released: ++touchReleasedCount; @@ -1082,6 +1087,7 @@ public: int mousePressedCount = 0, mouseReleasedCount = 0, mouseMovedCount = 0, mouseDoubleClickedCount = 0; QString mouseSequenceSignature; QPointF mousePressScreenPos, mouseMoveScreenPos, mousePressLocalPos; + QPointF touchPressGlobalPos, touchPressLocalPos; int touchPressedCount = 0, touchReleasedCount = 0, touchMovedCount = 0; QEvent::Type touchEventType = QEvent::None; int enterEventCount = 0, leaveEventCount = 0; @@ -1307,7 +1313,8 @@ void tst_QWindow::mouseToTouchTranslation() window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); - QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10)); + const QPoint localPos(10, 10); + QTest::mouseClick(&window, Qt::LeftButton, {}, localPos); QCoreApplication::processEvents(); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); @@ -1316,12 +1323,14 @@ void tst_QWindow::mouseToTouchTranslation() QTRY_COMPARE(window.touchReleasedCount, 1); QCOMPARE(window.mouseDevice, window.touchDevice); QCOMPARE(window.touchDevice->type(), QInputDevice::DeviceType::Mouse); + QCOMPARE(window.touchPressLocalPos.toPoint(), localPos); + QCOMPARE(window.touchPressGlobalPos.toPoint(), window.mapToGlobal(localPos)); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true); window.ignoreMouse = false; - QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10)); + QTest::mouseClick(&window, Qt::LeftButton, {}, localPos); QCoreApplication::processEvents(); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); @@ -1332,14 +1341,12 @@ void tst_QWindow::mouseToTouchTranslation() window.ignoreMouse = true; - QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10)); + QTest::mouseClick(&window, Qt::LeftButton, {}, localPos); QCoreApplication::processEvents(); // touch event synthesis disabled QTRY_COMPARE(window.touchPressedCount, 1); QTRY_COMPARE(window.touchReleasedCount, 1); - - } void tst_QWindow::mouseToTouchLoop() |