From ba2b28fb849b80a0f2f8f4cffb6a774d0e6ff287 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 30 Jan 2012 17:04:42 +0100 Subject: [PATCH] Fix unhandled touch events not being ignored. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Unhandled touch events need to be ignored in order for things like mouse event synthetization in QtGui to work. Change-Id: I6fe9dad205c8bb8547d2424c2e2a3b3518598006 Reviewed-by: Andras Becsi Reviewed-by: Samuel Rødal --- src/quick/items/qquickcanvas.cpp | 7 +- tests/auto/qtquick2/qquickitem/tst_qquickitem.cpp | 100 +++++++++++++++++++--- 2 files changed, 95 insertions(+), 12 deletions(-) diff --git a/src/quick/items/qquickcanvas.cpp b/src/quick/items/qquickcanvas.cpp index 5aa244c..8f4078d 100644 --- a/src/quick/items/qquickcanvas.cpp +++ b/src/quick/items/qquickcanvas.cpp @@ -1063,6 +1063,8 @@ bool QQuickCanvasPrivate::deliverTouchEvent(QTouchEvent *event) deliverTouchPoints(rootItem, event, event->touchPoints(), &acceptedNewPoints, &updatedPoints); if (acceptedNewPoints.count() > 0) event->accept(); + else + event->ignore(); return event->isAccepted(); } @@ -1095,7 +1097,10 @@ bool QQuickCanvasPrivate::deliverTouchEvent(QTouchEvent *event) deliverTouchPoints(rootItem, event, newPoints, &acceptedNewPoints, &updatedPoints); if (acceptedNewPoints.count() > 0 || updatedPoints.count() != prevCount) event->accept(); - } + else + event->ignore(); + } else + event->ignore(); if (event->touchPointStates() & Qt::TouchPointReleased) { for (int i=0; iaccept(); ++pressCount; } virtual void mouseReleaseEvent(QMouseEvent *event) { event->accept(); ++releaseCount; } - virtual void touchEvent(QTouchEvent *event) { event->accept(); } + virtual void touchEvent(QTouchEvent *event) { + touchEventReached = true; + event->setAccepted(acceptIncomingTouchEvents); + } virtual void wheelEvent(QWheelEvent *event) { event->accept(); ++wheelCount; } }; @@ -139,7 +147,8 @@ private slots: void enabledFocus(); void mouseGrab(); - void touchEventAccept(); + void touchEventAcceptIgnore_data(); + void touchEventAcceptIgnore(); void polishOutsideAnimation(); void polishOnCompleted(); @@ -1016,8 +1025,18 @@ void tst_qquickitem::mouseGrab() delete canvas; } -void tst_qquickitem::touchEventAccept() +void tst_qquickitem::touchEventAcceptIgnore_data() +{ + QTest::addColumn("itemSupportsTouch"); + + QTest::newRow("with touch") << true; + QTest::newRow("without touch") << false; +} + +void tst_qquickitem::touchEventAcceptIgnore() { + QFETCH(bool, itemSupportsTouch); + TestCanvas *canvas = new TestCanvas; canvas->resize(100, 100); canvas->show(); @@ -1025,18 +1044,77 @@ void tst_qquickitem::touchEventAccept() TestItem *item = new TestItem; item->setSize(QSizeF(100, 100)); item->setParentItem(canvas->rootItem()); + item->acceptIncomingTouchEvents = itemSupportsTouch; - static QTouchDevice* device = new QTouchDevice; - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device); + static QTouchDevice* device = 0; + if (!device) { + device =new QTouchDevice; + device->setType(QTouchDevice::TouchScreen); + QWindowSystemInterface::registerTouchDevice(device); + } + + // Send Begin, Update & End touch sequence + { + QTouchEvent::TouchPoint point; + point.setId(1); + point.setPos(QPointF(50, 50)); + point.setScreenPos(point.pos()); + point.setState(Qt::TouchPointPressed); - QTouchEvent *event = new QTouchEvent(QEvent::TouchBegin, device); + QTouchEvent event(QEvent::TouchBegin, device, + Qt::NoModifier, + Qt::TouchPointPressed, + QList() << point); + event.setAccepted(true); - bool accepted = canvas->event(event); + item->touchEventReached = false; - QVERIFY(accepted && event->isAccepted()); + bool accepted = canvas->event(&event); + + QVERIFY(item->touchEventReached); + QCOMPARE(accepted && event.isAccepted(), itemSupportsTouch); + } + { + QTouchEvent::TouchPoint point; + point.setId(1); + point.setPos(QPointF(60, 60)); + point.setScreenPos(point.pos()); + point.setState(Qt::TouchPointMoved); + + QTouchEvent event(QEvent::TouchUpdate, device, + Qt::NoModifier, + Qt::TouchPointMoved, + QList() << point); + event.setAccepted(true); + + item->touchEventReached = false; + + bool accepted = canvas->event(&event); + + QCOMPARE(item->touchEventReached, itemSupportsTouch); + QCOMPARE(accepted && event.isAccepted(), itemSupportsTouch); + } + { + QTouchEvent::TouchPoint point; + point.setId(1); + point.setPos(QPointF(60, 60)); + point.setScreenPos(point.pos()); + point.setState(Qt::TouchPointReleased); + + QTouchEvent event(QEvent::TouchEnd, device, + Qt::NoModifier, + Qt::TouchPointReleased, + QList() << point); + event.setAccepted(true); + + item->touchEventReached = false; + + bool accepted = canvas->event(&event); + + QCOMPARE(item->touchEventReached, itemSupportsTouch); + QCOMPARE(accepted && event.isAccepted(), itemSupportsTouch); + } - delete event; delete item; delete canvas; } -- 2.7.4