diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-08-21 22:22:13 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-08-22 11:51:36 +0000 |
commit | 0eb65826c85aee9431c1a1f4ef3289abac2ae27d (patch) | |
tree | 63b660ff671671e7ffa9bf44d43b8ead0678fddd | |
parent | d83cb16d3cecad7ec2e9b45416620b87b52f2885 (diff) |
Ensure that SinglePointHandler handles touch points
A QQuickPointerTouchEvent's button and buttons properties are not
currently set (although we had some uncertainty in the past about
whether it would be appropriate for a touch press to simulate a left
button press). So it seems that f2ba3bd9792500b4d3fcfd23b03098a32641ef4f
broke the behavior of PointHandler on touchscreens.
Change-Id: I890cc9889e847636c8f385753e47a078ec582195
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
-rw-r--r-- | src/quick/handlers/qquickpointhandler.cpp | 6 | ||||
-rw-r--r-- | tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp | 54 |
2 files changed, 58 insertions, 2 deletions
diff --git a/src/quick/handlers/qquickpointhandler.cpp b/src/quick/handlers/qquickpointhandler.cpp index 854fadf5cf..3bc1c06a1a 100644 --- a/src/quick/handlers/qquickpointhandler.cpp +++ b/src/quick/handlers/qquickpointhandler.cpp @@ -139,13 +139,15 @@ void QQuickPointHandler::handleEventPoint(QQuickEventPoint *point) { switch (point->state()) { case QQuickEventPoint::Pressed: - if ((point->pointerEvent()->buttons() & acceptedButtons()) != Qt::NoButton) { + if (point->pointerEvent()->asPointerTouchEvent() || + (point->pointerEvent()->buttons() & acceptedButtons()) != Qt::NoButton) { setPassiveGrab(point); setActive(true); } break; case QQuickEventPoint::Released: - if ((point->pointerEvent()->buttons() & acceptedButtons()) == Qt::NoButton) + if (point->pointerEvent()->asPointerTouchEvent() || + (point->pointerEvent()->buttons() & acceptedButtons()) == Qt::NoButton) setActive(false); break; default: diff --git a/tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp b/tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp index 4253937280..d91c89d833 100644 --- a/tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp @@ -48,16 +48,19 @@ class tst_PointHandler : public QQmlDataTest Q_OBJECT public: tst_PointHandler() + : touchDevice(QTest::createTouchDevice()) {} private slots: void initTestCase(); + void singleTouch(); void pressedMultipleButtons_data(); void pressedMultipleButtons(); private: void createView(QScopedPointer<QQuickView> &window, const char *fileName); + QTouchDevice *touchDevice; }; void tst_PointHandler::createView(QScopedPointer<QQuickView> &window, const char *fileName) @@ -81,6 +84,57 @@ void tst_PointHandler::initTestCase() QQmlDataTest::initTestCase(); } +void tst_PointHandler::singleTouch() +{ + QScopedPointer<QQuickView> windowPtr; + createView(windowPtr, "pointTracker.qml"); + QQuickView * window = windowPtr.data(); + QQuickItem *tracker = window->rootObject()->findChild<QQuickItem *>("pointTracker"); + QVERIFY(tracker); + QQuickPointHandler *handler = window->rootObject()->findChild<QQuickPointHandler *>("pointHandler"); + QVERIFY(handler); + + QSignalSpy activeSpy(handler, SIGNAL(activeChanged())); + QSignalSpy pointSpy(handler, SIGNAL(pointChanged())); + QSignalSpy translationSpy(handler, SIGNAL(translationChanged())); + + QPoint point(100,100); + QTest::touchEvent(window, touchDevice).press(1, point, window); + QQuickTouchUtils::flush(window); + QTRY_COMPARE(handler->active(), true); + QCOMPARE(activeSpy.count(), 1); + QCOMPARE(pointSpy.count(), 1); + QCOMPARE(handler->point().position().toPoint(), point); + QCOMPARE(handler->point().scenePosition().toPoint(), point); + QCOMPARE(handler->point().pressedButtons(), Qt::NoButton); + QCOMPARE(handler->translation(), QVector2D()); + QCOMPARE(translationSpy.count(), 1); + + point += QPoint(10, 10); + QTest::touchEvent(window, touchDevice).move(1, point, window); + QQuickTouchUtils::flush(window); + QCOMPARE(handler->active(), true); + QCOMPARE(activeSpy.count(), 1); + QCOMPARE(pointSpy.count(), 2); + QCOMPARE(handler->point().position().toPoint(), point); + QCOMPARE(handler->point().scenePosition().toPoint(), point); + QCOMPARE(handler->point().pressPosition().toPoint(), QPoint(100, 100)); + QCOMPARE(handler->point().scenePressPosition().toPoint(), QPoint(100, 100)); + QCOMPARE(handler->point().pressedButtons(), Qt::NoButton); + QVERIFY(handler->point().velocity().x() > 0); + QVERIFY(handler->point().velocity().y() > 0); + QCOMPARE(handler->translation(), QVector2D(10, 10)); + QCOMPARE(translationSpy.count(), 2); + + QTest::touchEvent(window, touchDevice).release(1, point, window); + QQuickTouchUtils::flush(window); + QTRY_COMPARE(handler->active(), false); + QCOMPARE(activeSpy.count(), 2); + QCOMPARE(pointSpy.count(), 3); + QCOMPARE(handler->translation(), QVector2D()); + QCOMPARE(translationSpy.count(), 3); +} + void tst_PointHandler::pressedMultipleButtons_data() { QTest::addColumn<Qt::MouseButtons>("accepted"); |