diff options
-rw-r--r-- | src/quick/items/qquickpincharea.cpp | 46 | ||||
-rw-r--r-- | src/quick/items/qquickpincharea_p.h | 1 | ||||
-rw-r--r-- | tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp | 64 |
3 files changed, 110 insertions, 1 deletions
diff --git a/src/quick/items/qquickpincharea.cpp b/src/quick/items/qquickpincharea.cpp index 33f4bade3a..8a391b7aea 100644 --- a/src/quick/items/qquickpincharea.cpp +++ b/src/quick/items/qquickpincharea.cpp @@ -346,8 +346,11 @@ void QQuickPinchArea::touchEvent(QTouchEvent *event) case QEvent::TouchEnd: clearPinch(); break; + case QEvent::TouchCancel: + cancelPinch(); + break; default: - QQuickItem::event(event); + QQuickItem::touchEvent(event); } } @@ -384,6 +387,47 @@ void QQuickPinchArea::clearPinch() setKeepMouseGrab(false); } +void QQuickPinchArea::cancelPinch() +{ + Q_D(QQuickPinchArea); + + d->touchPoints.clear(); + if (d->inPinch) { + d->inPinch = false; + QPointF pinchCenter = mapFromScene(d->sceneLastCenter); + QQuickPinchEvent pe(d->pinchStartCenter, d->pinchStartScale, d->pinchStartAngle, d->pinchStartRotation); + pe.setStartCenter(d->pinchStartCenter); + pe.setPreviousCenter(pinchCenter); + pe.setPreviousAngle(d->pinchLastAngle); + pe.setPreviousScale(d->pinchLastScale); + pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); + pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); + pe.setPoint1(pe.startPoint1()); + pe.setPoint2(pe.startPoint2()); + emit pinchFinished(&pe); + + d->pinchLastScale = d->pinchStartScale; + d->sceneLastCenter = d->sceneStartCenter; + d->pinchLastAngle = d->pinchStartAngle; + d->lastPoint1 = pe.startPoint1(); + d->lastPoint2 = pe.startPoint2(); + updatePinchTarget(); + + if (d->pinch && d->pinch->target()) + d->pinch->setActive(false); + } + d->pinchStartDist = 0; + d->pinchActivated = false; + d->initPinch = false; + d->pinchRejected = false; + d->stealMouse = false; + d->id1 = -1; + QQuickWindow *win = window(); + if (win && win->mouseGrabberItem() == this) + ungrabMouse(); + setKeepMouseGrab(false); +} + void QQuickPinchArea::updatePinch() { Q_D(QQuickPinchArea); diff --git a/src/quick/items/qquickpincharea_p.h b/src/quick/items/qquickpincharea_p.h index 57f9a87e07..d2de59b5d6 100644 --- a/src/quick/items/qquickpincharea_p.h +++ b/src/quick/items/qquickpincharea_p.h @@ -279,6 +279,7 @@ protected: private: void clearPinch(); + void cancelPinch(); void updatePinch(); void updatePinchTarget(); void handlePress(); diff --git a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp index 3d5dcaaaaf..8063453993 100644 --- a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp +++ b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp @@ -54,6 +54,7 @@ private slots: void scale(); void pan(); void retouch(); + void cancel(); void transformedPinchArea_data(); void transformedPinchArea(); @@ -421,6 +422,69 @@ void tst_QQuickPinchArea::retouch() } } +void tst_QQuickPinchArea::cancel() +{ + QQuickView *window = createView(); + QScopedPointer<QQuickView> scope(window); + window->setSource(testFileUrl("pinchproperties.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + QVERIFY(window->rootObject() != 0); + qApp->processEvents(); + + QQuickPinchArea *pinchArea = window->rootObject()->findChild<QQuickPinchArea*>("pincharea"); + QQuickPinch *pinch = pinchArea->pinch(); + QVERIFY(pinchArea != 0); + QVERIFY(pinch != 0); + + QQuickItem *root = qobject_cast<QQuickItem*>(window->rootObject()); + QVERIFY(root != 0); + + // target + QQuickItem *blackRect = window->rootObject()->findChild<QQuickItem*>("blackrect"); + QVERIFY(blackRect != 0); + + QPoint p1(80, 80); + QPoint p2(100, 100); + { + QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, device); + pinchSequence.press(0, p1, window).commit(); + QQuickTouchUtils::flush(window); + // In order for the stationary point to remember its previous position, + // we have to reuse the same pinchSequence object. Otherwise if we let it + // be destroyed and then start a new sequence, point 0 will default to being + // stationary at 0, 0, and PinchArea will filter out that touchpoint because + // it is outside its bounds. + pinchSequence.stationary(0).press(1, p2, window).commit(); + QQuickTouchUtils::flush(window); + p1 -= QPoint(10,10); + p2 += QPoint(10,10); + pinchSequence.move(0, p1,window).move(1, p2,window).commit(); + QQuickTouchUtils::flush(window); + + QCOMPARE(root->property("scale").toReal(), 1.0); + QVERIFY(root->property("pinchActive").toBool()); + + p1 -= QPoint(10,10); + p2 += QPoint(10,10); + pinchSequence.move(0, p1,window).move(1, p2,window).commit(); + QQuickTouchUtils::flush(window); + + QCOMPARE(root->property("scale").toReal(), 1.5); + QCOMPARE(root->property("center").toPointF(), QPointF(40, 40)); // blackrect is at 50,50 + QCOMPARE(blackRect->scale(), 1.5); + + QTouchEvent cancelEvent(QEvent::TouchCancel); + QCoreApplication::sendEvent(window, &cancelEvent); + QQuickTouchUtils::flush(window); + + QCOMPARE(root->property("scale").toReal(), 1.0); + QCOMPARE(root->property("center").toPointF(), QPointF(40, 40)); // blackrect is at 50,50 + QCOMPARE(blackRect->scale(), 1.0); + QVERIFY(!root->property("pinchActive").toBool()); + } +} + void tst_QQuickPinchArea::transformedPinchArea_data() { QTest::addColumn<QPoint>("p1"); |