From 2821134d18f221505983bfbdd622470cb363d9a6 Mon Sep 17 00:00:00 2001 From: Adriano Rezende Date: Sun, 26 Feb 2012 17:26:32 +0100 Subject: [PATCH] Adjust PinchArea autotest to check pinch events with transformations Tests pinch events with graphical transformations applied to the element. Change-Id: I35810d9859678d4c468c0c1e8614f0928d52775b Reviewed-by: Frederik Gladhorn --- .../qquickpincharea/data/transformedPinchArea.qml | 33 ++++++++++ .../quick/qquickpincharea/tst_qquickpincharea.cpp | 65 ++++++++++++++++++++ 2 files changed, 98 insertions(+), 0 deletions(-) create mode 100644 tests/auto/quick/qquickpincharea/data/transformedPinchArea.qml diff --git a/tests/auto/quick/qquickpincharea/data/transformedPinchArea.qml b/tests/auto/quick/qquickpincharea/data/transformedPinchArea.qml new file mode 100644 index 0000000..7d5d88a --- /dev/null +++ b/tests/auto/quick/qquickpincharea/data/transformedPinchArea.qml @@ -0,0 +1,33 @@ +import QtQuick 2.0 + +Rectangle { + width: 400 + height: 400 + + Rectangle { + x: 100 + y: 100 + width: 200 + height: 200 + rotation: 45 + + Rectangle { + id: rect + scale: 0.5 + color: "black" + anchors.fill: parent + + PinchArea { + anchors.fill: parent + objectName: "pinchArea" + + property bool pinching: false + + pinch.target: rect + pinch.dragAxis: Drag.XandYAxis + onPinchStarted: pinching = true + onPinchFinished: pinching = false + } + } + } +} diff --git a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp index e29ed48..f24daa3 100644 --- a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp +++ b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -60,6 +61,8 @@ private slots: void scale(); void pan(); void retouch(); + void transformedPinchArea_data(); + void transformedPinchArea(); private: QQuickView *createView(); @@ -414,6 +417,68 @@ void tst_QQuickPinchArea::retouch() delete canvas; } +void tst_QQuickPinchArea::transformedPinchArea_data() +{ + QTest::addColumn("p1"); + QTest::addColumn("p2"); + QTest::addColumn("shouldPinch"); + + QTest::newRow("checking inner pinch 1") + << QPoint(200, 140) << QPoint(200, 260) << true; + + QTest::newRow("checking inner pinch 2") + << QPoint(140, 200) << QPoint(200, 140) << true; + + QTest::newRow("checking inner pinch 3") + << QPoint(140, 200) << QPoint(260, 200) << true; + + QTest::newRow("checking outer pinch 1") + << QPoint(140, 140) << QPoint(260, 260) << false; + + QTest::newRow("checking outer pinch 2") + << QPoint(140, 140) << QPoint(200, 200) << false; + + QTest::newRow("checking outer pinch 3") + << QPoint(140, 260) << QPoint(260, 260) << false; +} + +void tst_QQuickPinchArea::transformedPinchArea() +{ + QFETCH(QPoint, p1); + QFETCH(QPoint, p2); + QFETCH(bool, shouldPinch); + + QQuickView *canvas = createView(); + canvas->setSource(testFileUrl("transformedPinchArea.qml")); + canvas->show(); + canvas->requestActivateWindow(); + QTest::qWaitForWindowShown(canvas); + QVERIFY(canvas->rootObject() != 0); + qApp->processEvents(); + + QQuickPinchArea *pinchArea = canvas->rootObject()->findChild("pinchArea"); + QVERIFY(pinchArea != 0); + + const int threshold = qApp->styleHints()->startDragDistance(); + + { + QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(canvas, device); + // start pinch + pinchSequence.press(0, p1, canvas).commit(); + // In order for the stationary point to remember its previous position, + // we have to reuse the same pinchSequence object. + pinchSequence.stationary(0).press(1, p2, canvas).commit(); + pinchSequence.stationary(0).move(1, p2 + QPoint(threshold * 2, 0), canvas).commit(); + QCOMPARE(pinchArea->property("pinching").toBool(), shouldPinch); + + // release pinch + pinchSequence.release(0, p1, canvas).release(1, p2, canvas).commit(); + QCOMPARE(pinchArea->property("pinching").toBool(), false); + } + + delete canvas; +} + QQuickView *tst_QQuickPinchArea::createView() { QQuickView *canvas = new QQuickView(0); -- 1.7.2.5