diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-01-31 12:54:40 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-08-06 12:46:08 +0000 |
commit | acf7c8073b0c8a0440c62f66469865f8bf1decd5 (patch) | |
tree | 9b95b0cc7833172d9036a87cafda1b67e165945e /tests/auto/quick/touchmouse | |
parent | 814ff4c73ced4706da8ca72e5124a59523e5efc4 (diff) |
QQuickWindow: obey AA_SynthesizeMouseForUnhandledTouchEvents
Until now, AA_SynthesizeMouseForUnhandledTouchEvents has only affected
behavior of QGuiApplicationPrivate::processTouchEvent, but had no
effect in Qt Quick. QQuickWindow also accepts the touch event
just to make sure that QGuiApplication will not synthesize mouse
from touch, because it would be redundant: QQuickWindow does that
for itself.
Now we make it have an effect in Qt Quick too: skip mouse synthesis
if it is set to false. This provides a way to simplify the
event delivery. If you set it false, then you cannot manipulate old
mouse-only items like MouseArea and Flickable on a touchscreen.
(You can of course use event handlers for that.)
[ChangeLog][QtQuick][QQuickWindow] You can now disable touch->mouse
event synthesis in QtQuick by calling
qGuiApp.setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, false);
This will simplify and speed up event delivery, and it will also prevent
any and all interaction with mouse-only items like MouseArea and
Flickable on a touchscreen.
Task-number: QTBUG-52748
Change-Id: I71f1731b5abaeabd9dbce1112cd23bc97d24c12a
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'tests/auto/quick/touchmouse')
-rw-r--r-- | tests/auto/quick/touchmouse/tst_touchmouse.cpp | 64 |
1 files changed, 42 insertions, 22 deletions
diff --git a/tests/auto/quick/touchmouse/tst_touchmouse.cpp b/tests/auto/quick/touchmouse/tst_touchmouse.cpp index 2fc56c2ad8..052d81b6de 100644 --- a/tests/auto/quick/touchmouse/tst_touchmouse.cpp +++ b/tests/auto/quick/touchmouse/tst_touchmouse.cpp @@ -176,6 +176,7 @@ public: private slots: void initTestCase(); + void simpleTouchEvent_data(); void simpleTouchEvent(); void testEventFilter(); void mouse(); @@ -226,15 +227,22 @@ QQuickView *tst_TouchMouse::createView() void tst_TouchMouse::initTestCase() { - // This test assumes that we don't get synthesized mouse events from QGuiApplication - qApp->setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, false); - QQmlDataTest::initTestCase(); qmlRegisterType<EventItem>("Qt.test", 1, 0, "EventItem"); } +void tst_TouchMouse::simpleTouchEvent_data() +{ + QTest::addColumn<bool>("synthMouse"); // AA_SynthesizeMouseForUnhandledTouchEvents + QTest::newRow("no synth") << false; + QTest::newRow("synth") << true; +} + void tst_TouchMouse::simpleTouchEvent() { + QFETCH(bool, synthMouse); + qApp->setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, synthMouse); + QScopedPointer<QQuickView> window(createView()); window->setSource(testFileUrl("singleitem.qml")); window->show(); @@ -251,16 +259,16 @@ void tst_TouchMouse::simpleTouchEvent() QTest::touchEvent(window.data(), device).press(0, p1, window.data()); QQuickTouchUtils::flush(window.data()); // Get a touch and then mouse event offered - QCOMPARE(eventItem1->eventList.size(), 2); + QCOMPARE(eventItem1->eventList.size(), synthMouse ? 2 : 1); QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin); p1 += QPoint(10, 0); QTest::touchEvent(window.data(), device).move(0, p1, window.data()); QQuickTouchUtils::flush(window.data()); // Not accepted, no updates - QCOMPARE(eventItem1->eventList.size(), 2); + QCOMPARE(eventItem1->eventList.size(), synthMouse ? 2 : 1); QTest::touchEvent(window.data(), device).release(0, p1, window.data()); QQuickTouchUtils::flush(window.data()); - QCOMPARE(eventItem1->eventList.size(), 2); + QCOMPARE(eventItem1->eventList.size(), synthMouse ? 2 : 1); eventItem1->eventList.clear(); // Accept touch @@ -288,10 +296,11 @@ void tst_TouchMouse::simpleTouchEvent() p1 = QPoint(20, 20); QTest::touchEvent(window.data(), device).press(0, p1, window.data()); QQuickTouchUtils::flush(window.data()); - QCOMPARE(eventItem1->eventList.size(), 2); + QCOMPARE(eventItem1->eventList.size(), synthMouse ? 2 : 1); QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin); - QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonPress); - QCOMPARE(window->mouseGrabberItem(), eventItem1); + if (synthMouse) + QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonPress); + QCOMPARE(window->mouseGrabberItem(), synthMouse ? eventItem1 : nullptr); QPoint localPos = eventItem1->mapFromScene(p1).toPoint(); QPoint globalPos = window->mapToGlobal(p1); @@ -299,21 +308,31 @@ void tst_TouchMouse::simpleTouchEvent() QCOMPARE(eventItem1->eventList.at(0).points.at(0).pos().toPoint(), localPos); QCOMPARE(eventItem1->eventList.at(0).points.at(0).scenePos().toPoint(), scenePos); QCOMPARE(eventItem1->eventList.at(0).points.at(0).screenPos().toPoint(), globalPos); - QCOMPARE(eventItem1->eventList.at(1).mousePos, localPos); - QCOMPARE(eventItem1->eventList.at(1).mousePosGlobal, globalPos); + if (synthMouse) { + QCOMPARE(eventItem1->eventList.at(1).mousePos, localPos); + QCOMPARE(eventItem1->eventList.at(1).mousePosGlobal, globalPos); + } p1 += QPoint(10, 0); QTest::touchEvent(window.data(), device).move(0, p1, window.data()); QQuickTouchUtils::flush(window.data()); - QCOMPARE(eventItem1->eventList.size(), 4); - QCOMPARE(eventItem1->eventList.at(2).type, QEvent::TouchUpdate); - QCOMPARE(eventItem1->eventList.at(3).type, QEvent::MouseMove); + QCOMPARE(eventItem1->eventList.size(), synthMouse ? 4 : 1); + if (synthMouse) { + QCOMPARE(eventItem1->eventList.at(2).type, QEvent::TouchUpdate); + QCOMPARE(eventItem1->eventList.at(3).type, QEvent::MouseMove); + } + // else, if there was no synth-mouse and we didn't accept the touch, + // TouchUpdate was not sent to eventItem1 either. QTest::touchEvent(window.data(), device).release(0, p1, window.data()); QQuickTouchUtils::flush(window.data()); - QCOMPARE(eventItem1->eventList.size(), 7); - QCOMPARE(eventItem1->eventList.at(4).type, QEvent::TouchEnd); - QCOMPARE(eventItem1->eventList.at(5).type, QEvent::MouseButtonRelease); - QCOMPARE(eventItem1->eventList.at(6).type, QEvent::UngrabMouse); + QCOMPARE(eventItem1->eventList.size(), synthMouse ? 7 : 1); + if (synthMouse) { + QCOMPARE(eventItem1->eventList.at(4).type, QEvent::TouchEnd); + QCOMPARE(eventItem1->eventList.at(5).type, QEvent::MouseButtonRelease); + QCOMPARE(eventItem1->eventList.at(6).type, QEvent::UngrabMouse); + } + // else, if there was no synth-mouse and we didn't accept the touch, + // TouchEnd was not sent to eventItem1 either. eventItem1->eventList.clear(); // wait to avoid getting a double click event @@ -326,16 +345,17 @@ void tst_TouchMouse::simpleTouchEvent() p1 = QPoint(20, 20); QTest::touchEvent(window.data(), device).press(0, p1, window.data()); QQuickTouchUtils::flush(window.data()); - QCOMPARE(eventItem1->eventList.size(), 2); + QCOMPARE(eventItem1->eventList.size(), synthMouse ? 2 : 1); QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin); - QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonPress); + if (synthMouse) + QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonPress); p1 += QPoint(10, 0); QTest::touchEvent(window.data(), device).move(0, p1, window.data()); QQuickTouchUtils::flush(window.data()); - QCOMPARE(eventItem1->eventList.size(), 2); + QCOMPARE(eventItem1->eventList.size(), synthMouse ? 2 : 1); QTest::touchEvent(window.data(), device).release(0, p1, window.data()); QQuickTouchUtils::flush(window.data()); - QCOMPARE(eventItem1->eventList.size(), 2); + QCOMPARE(eventItem1->eventList.size(), synthMouse ? 2 : 1); eventItem1->eventList.clear(); // wait to avoid getting a double click event |