Adjust PinchArea autotest to check pinch events with transformations
authorAdriano Rezende <atdrez@gmail.com>
Sun, 26 Feb 2012 16:26:32 +0000 (17:26 +0100)
committerQt by Nokia <qt-info@nokia.com>
Fri, 13 Jul 2012 15:01:28 +0000 (17:01 +0200)
Tests pinch events with graphical transformations applied to the element.

Change-Id: I35810d9859678d4c468c0c1e8614f0928d52775b
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com>
tests/auto/quick/qquickpincharea/data/transformedPinchArea.qml [new file with mode: 0644]
tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp

diff --git a/tests/auto/quick/qquickpincharea/data/transformedPinchArea.qml b/tests/auto/quick/qquickpincharea/data/transformedPinchArea.qml
new file mode 100644 (file)
index 0000000..7d5d88a
--- /dev/null
@@ -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
+            }
+        }
+    }
+}
index e29ed48..f24daa3 100644 (file)
@@ -41,6 +41,7 @@
 
 #include <QtTest/QtTest>
 #include <QtTest/QSignalSpy>
+#include <QtGui/QStyleHints>
 #include <private/qquickpincharea_p.h>
 #include <QtQuick/private/qquickrectangle_p.h>
 #include <QtQuick/qquickview.h>
@@ -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<QPoint>("p1");
+    QTest::addColumn<QPoint>("p2");
+    QTest::addColumn<bool>("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<QQuickPinchArea*>("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);