diff options
author | Martin Jones <martin.jones@nokia.com> | 2011-07-25 13:21:25 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-07-25 06:08:56 +0200 |
commit | 647ea955f3d1c45cce978a9b85b4732baf49a040 (patch) | |
tree | 48369fb5ef32a27e2fcfc46c34d32350cbf4da30 /tests | |
parent | 408ecd82db47aba68b1ab5e4ed48045c24268a7d (diff) |
Handle pinch correctly when one point is released and repressed.
The pinch is not finished at the time one point is released. Ensure
that a onPinchStarted is called each time a repress happens, and
that onPinchFinished is called when all points are released.
Fixes: QTBUG-19632
Change-Id: I467dd612383f7dd11d58a9df063dd86860796216
Reviewed-on: http://codereview.qt.nokia.com/2059
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qsgpincharea/data/pinchproperties.qml | 4 | ||||
-rw-r--r-- | tests/auto/declarative/qsgpincharea/tst_qsgpincharea.cpp | 80 |
2 files changed, 84 insertions, 0 deletions
diff --git a/tests/auto/declarative/qsgpincharea/data/pinchproperties.qml b/tests/auto/declarative/qsgpincharea/data/pinchproperties.qml index a1cd11302f..44d116184e 100644 --- a/tests/auto/declarative/qsgpincharea/data/pinchproperties.qml +++ b/tests/auto/declarative/qsgpincharea/data/pinchproperties.qml @@ -3,6 +3,7 @@ Rectangle { id: whiteRect property variant center property real scale + property int pointCount: 0 width: 240; height: 320 color: "white" Rectangle { @@ -32,14 +33,17 @@ Rectangle { onPinchStarted: { whiteRect.center = pinch.center whiteRect.scale = pinch.scale + whiteRect.pointCount = pinch.pointCount; } onPinchUpdated: { whiteRect.center = pinch.center whiteRect.scale = pinch.scale + whiteRect.pointCount = pinch.pointCount; } onPinchFinished: { whiteRect.center = pinch.center whiteRect.scale = pinch.scale + whiteRect.pointCount = pinch.pointCount; } } } diff --git a/tests/auto/declarative/qsgpincharea/tst_qsgpincharea.cpp b/tests/auto/declarative/qsgpincharea/tst_qsgpincharea.cpp index abfa85c098..2e93f71a49 100644 --- a/tests/auto/declarative/qsgpincharea/tst_qsgpincharea.cpp +++ b/tests/auto/declarative/qsgpincharea/tst_qsgpincharea.cpp @@ -61,6 +61,7 @@ private slots: void pinchProperties(); void scale(); void pan(); + void retouch(); private: QSGView *createView(); @@ -310,6 +311,85 @@ void tst_QSGPinchArea::pan() delete canvas; } +// test pinch, release one point, touch again to continue pinch +void tst_QSGPinchArea::retouch() +{ + QSGView *canvas = createView(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/pinchproperties.qml")); + canvas->show(); + canvas->setFocus(); + QTest::qWaitForWindowShown(canvas); + QVERIFY(canvas->rootObject() != 0); + qApp->processEvents(); + + QSGPinchArea *pinchArea = canvas->rootObject()->findChild<QSGPinchArea*>("pincharea"); + QSGPinch *pinch = pinchArea->pinch(); + QVERIFY(pinchArea != 0); + QVERIFY(pinch != 0); + + QSGItem *root = qobject_cast<QSGItem*>(canvas->rootObject()); + QVERIFY(root != 0); + + QSignalSpy startedSpy(pinchArea, SIGNAL(pinchStarted(QSGPinchEvent *))); + QSignalSpy finishedSpy(pinchArea, SIGNAL(pinchFinished(QSGPinchEvent *))); + + // target + QSGItem *blackRect = canvas->rootObject()->findChild<QSGItem*>("blackrect"); + QVERIFY(blackRect != 0); + + QPoint p1(80, 80); + QPoint p2(100, 100); + + QTest::touchEvent(canvas).press(0, p1); + QTest::touchEvent(canvas).stationary(0).press(1, p2); + p1 -= QPoint(10,10); + p2 += QPoint(10,10); + QTest::touchEvent(canvas).move(0, p1).move(1, p2); + + QCOMPARE(root->property("scale").toReal(), 1.0); + + p1 -= QPoint(10,10); + p2 += QPoint(10,10); + QTest::touchEvent(canvas).move(0, p1).move(1, p2); + + QCOMPARE(startedSpy.count(), 1); + + 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); + + QCOMPARE(canvas->rootObject()->property("pointCount").toInt(), 2); + + QCOMPARE(startedSpy.count(), 1); + QCOMPARE(finishedSpy.count(), 0); + + QTest::touchEvent(canvas).stationary(0).release(1, p2); + + QCOMPARE(startedSpy.count(), 1); + QCOMPARE(finishedSpy.count(), 0); + + QCOMPARE(canvas->rootObject()->property("pointCount").toInt(), 1); + + QTest::touchEvent(canvas).stationary(0).press(1, p2); + p1 -= QPoint(10,10); + p2 += QPoint(10,10); + QTest::touchEvent(canvas).move(0, p1).move(1, p2); + + // Lifting and retouching results in onPinchStarted being called again + QCOMPARE(startedSpy.count(), 2); + QCOMPARE(finishedSpy.count(), 0); + + QCOMPARE(canvas->rootObject()->property("pointCount").toInt(), 2); + + QTest::touchEvent(canvas).release(0, p1).release(1, p2); + + QCOMPARE(startedSpy.count(), 2); + QCOMPARE(finishedSpy.count(), 1); + + delete canvas; +} + + QSGView *tst_QSGPinchArea::createView() { QSGView *canvas = new QSGView(0); |