From b855240b782395f94315f43ea3e7e182299fac48 Mon Sep 17 00:00:00 2001 From: Matthew Vogt Date: Thu, 16 Feb 2012 14:43:03 +1000 Subject: Rename QDeclarative symbols to QQuick and QQml Symbols beginning with QDeclarative are already exported by the quick1 module. Users can apply the bin/rename-qtdeclarative-symbols.sh script to modify client code using the previous names of the renamed symbols. Task-number: QTBUG-23737 Change-Id: Ifaa482663767634931e8711a8e9bf6e404859e66 Reviewed-by: Martin Jones --- .../quick/qquickpincharea/data/pinchproperties.qml | 50 +++ .../auto/quick/qquickpincharea/qquickpincharea.pro | 15 + .../quick/qquickpincharea/tst_qquickpincharea.cpp | 404 +++++++++++++++++++++ 3 files changed, 469 insertions(+) create mode 100644 tests/auto/quick/qquickpincharea/data/pinchproperties.qml create mode 100644 tests/auto/quick/qquickpincharea/qquickpincharea.pro create mode 100644 tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp (limited to 'tests/auto/quick/qquickpincharea') diff --git a/tests/auto/quick/qquickpincharea/data/pinchproperties.qml b/tests/auto/quick/qquickpincharea/data/pinchproperties.qml new file mode 100644 index 0000000000..44d116184e --- /dev/null +++ b/tests/auto/quick/qquickpincharea/data/pinchproperties.qml @@ -0,0 +1,50 @@ +import QtQuick 2.0 +Rectangle { + id: whiteRect + property variant center + property real scale + property int pointCount: 0 + width: 240; height: 320 + color: "white" + Rectangle { + id: blackRect + objectName: "blackrect" + color: "black" + y: 50 + x: 50 + width: 100 + height: 100 + opacity: (whiteRect.width-blackRect.x+whiteRect.height-blackRect.y-199)/200 + Text { text: blackRect.opacity} + PinchArea { + id: pincharea + objectName: "pincharea" + anchors.fill: parent + pinch.target: blackRect + pinch.dragAxis: Drag.XandYAxis + pinch.minimumX: 0 + pinch.maximumX: whiteRect.width-blackRect.width + pinch.minimumY: 0 + pinch.maximumY: whiteRect.height-blackRect.height + pinch.minimumScale: 1.0 + pinch.maximumScale: 2.0 + pinch.minimumRotation: 0.0 + pinch.maximumRotation: 90.0 + 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/quick/qquickpincharea/qquickpincharea.pro b/tests/auto/quick/qquickpincharea/qquickpincharea.pro new file mode 100644 index 0000000000..514dd25a5a --- /dev/null +++ b/tests/auto/quick/qquickpincharea/qquickpincharea.pro @@ -0,0 +1,15 @@ +CONFIG += testcase +TARGET = tst_qquickpincharea +macx:CONFIG -= app_bundle + +SOURCES += tst_qquickpincharea.cpp + +include (../../shared/util.pri) + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +CONFIG += parallel_test + +QT += core-private gui-private qml-private quick-private testlib diff --git a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp new file mode 100644 index 0000000000..6e83d41c4e --- /dev/null +++ b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp @@ -0,0 +1,404 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include "../../shared/util.h" + +class tst_QQuickPinchArea: public QQmlDataTest +{ + Q_OBJECT +public: + tst_QQuickPinchArea() : device(0) { } +private slots: + void initTestCase(); + void cleanupTestCase(); + void pinchProperties(); + void scale(); + void pan(); + void retouch(); + +private: + QQuickView *createView(); + QTouchDevice *device; +}; +void tst_QQuickPinchArea::initTestCase() +{ + QQmlDataTest::initTestCase(); + if (!device) { + device = new QTouchDevice; + device->setType(QTouchDevice::TouchScreen); + QWindowSystemInterface::registerTouchDevice(device); + } +} + +void tst_QQuickPinchArea::cleanupTestCase() +{ + +} +void tst_QQuickPinchArea::pinchProperties() +{ + QQuickView *canvas = createView(); + canvas->setSource(testFileUrl("pinchproperties.qml")); + canvas->show(); + canvas->requestActivateWindow(); + QVERIFY(canvas->rootObject() != 0); + + QQuickPinchArea *pinchArea = canvas->rootObject()->findChild("pincharea"); + QQuickPinch *pinch = pinchArea->pinch(); + QVERIFY(pinchArea != 0); + QVERIFY(pinch != 0); + + // target + QQuickItem *blackRect = canvas->rootObject()->findChild("blackrect"); + QVERIFY(blackRect != 0); + QVERIFY(blackRect == pinch->target()); + QQuickItem *rootItem = qobject_cast(canvas->rootObject()); + QVERIFY(rootItem != 0); + QSignalSpy targetSpy(pinch, SIGNAL(targetChanged())); + pinch->setTarget(rootItem); + QCOMPARE(targetSpy.count(),1); + pinch->setTarget(rootItem); + QCOMPARE(targetSpy.count(),1); + + // axis + QCOMPARE(pinch->axis(), QQuickPinch::XandYAxis); + QSignalSpy axisSpy(pinch, SIGNAL(dragAxisChanged())); + pinch->setAxis(QQuickPinch::XAxis); + QCOMPARE(pinch->axis(), QQuickPinch::XAxis); + QCOMPARE(axisSpy.count(),1); + pinch->setAxis(QQuickPinch::XAxis); + QCOMPARE(axisSpy.count(),1); + + // minimum and maximum drag properties + QSignalSpy xminSpy(pinch, SIGNAL(minimumXChanged())); + QSignalSpy xmaxSpy(pinch, SIGNAL(maximumXChanged())); + QSignalSpy yminSpy(pinch, SIGNAL(minimumYChanged())); + QSignalSpy ymaxSpy(pinch, SIGNAL(maximumYChanged())); + + QCOMPARE(pinch->xmin(), 0.0); + QCOMPARE(pinch->xmax(), rootItem->width()-blackRect->width()); + QCOMPARE(pinch->ymin(), 0.0); + QCOMPARE(pinch->ymax(), rootItem->height()-blackRect->height()); + + pinch->setXmin(10); + pinch->setXmax(10); + pinch->setYmin(10); + pinch->setYmax(10); + + QCOMPARE(pinch->xmin(), 10.0); + QCOMPARE(pinch->xmax(), 10.0); + QCOMPARE(pinch->ymin(), 10.0); + QCOMPARE(pinch->ymax(), 10.0); + + QCOMPARE(xminSpy.count(),1); + QCOMPARE(xmaxSpy.count(),1); + QCOMPARE(yminSpy.count(),1); + QCOMPARE(ymaxSpy.count(),1); + + pinch->setXmin(10); + pinch->setXmax(10); + pinch->setYmin(10); + pinch->setYmax(10); + + QCOMPARE(xminSpy.count(),1); + QCOMPARE(xmaxSpy.count(),1); + QCOMPARE(yminSpy.count(),1); + QCOMPARE(ymaxSpy.count(),1); + + // minimum and maximum scale properties + QSignalSpy scaleMinSpy(pinch, SIGNAL(minimumScaleChanged())); + QSignalSpy scaleMaxSpy(pinch, SIGNAL(maximumScaleChanged())); + + QCOMPARE(pinch->minimumScale(), 1.0); + QCOMPARE(pinch->maximumScale(), 2.0); + + pinch->setMinimumScale(0.5); + pinch->setMaximumScale(1.5); + + QCOMPARE(pinch->minimumScale(), 0.5); + QCOMPARE(pinch->maximumScale(), 1.5); + + QCOMPARE(scaleMinSpy.count(),1); + QCOMPARE(scaleMaxSpy.count(),1); + + pinch->setMinimumScale(0.5); + pinch->setMaximumScale(1.5); + + QCOMPARE(scaleMinSpy.count(),1); + QCOMPARE(scaleMaxSpy.count(),1); + + // minimum and maximum rotation properties + QSignalSpy rotMinSpy(pinch, SIGNAL(minimumRotationChanged())); + QSignalSpy rotMaxSpy(pinch, SIGNAL(maximumRotationChanged())); + + QCOMPARE(pinch->minimumRotation(), 0.0); + QCOMPARE(pinch->maximumRotation(), 90.0); + + pinch->setMinimumRotation(-90.0); + pinch->setMaximumRotation(45.0); + + QCOMPARE(pinch->minimumRotation(), -90.0); + QCOMPARE(pinch->maximumRotation(), 45.0); + + QCOMPARE(rotMinSpy.count(),1); + QCOMPARE(rotMaxSpy.count(),1); + + pinch->setMinimumRotation(-90.0); + pinch->setMaximumRotation(45.0); + + QCOMPARE(rotMinSpy.count(),1); + QCOMPARE(rotMaxSpy.count(),1); + + delete canvas; +} + +QTouchEvent::TouchPoint makeTouchPoint(int id, QPoint p, QQuickView *v, QQuickItem *i) +{ + QTouchEvent::TouchPoint touchPoint(id); + touchPoint.setPos(i->mapFromScene(p)); + touchPoint.setScreenPos(v->mapToGlobal(p)); + touchPoint.setScenePos(p); + return touchPoint; +} + +void tst_QQuickPinchArea::scale() +{ + QQuickView *canvas = createView(); + canvas->setSource(testFileUrl("pinchproperties.qml")); + canvas->show(); + canvas->requestActivateWindow(); + QTest::qWaitForWindowShown(canvas); + QVERIFY(canvas->rootObject() != 0); + qApp->processEvents(); + + QQuickPinchArea *pinchArea = canvas->rootObject()->findChild("pincharea"); + QQuickPinch *pinch = pinchArea->pinch(); + QVERIFY(pinchArea != 0); + QVERIFY(pinch != 0); + + QQuickItem *root = qobject_cast(canvas->rootObject()); + QVERIFY(root != 0); + + // target + QQuickItem *blackRect = canvas->rootObject()->findChild("blackrect"); + QVERIFY(blackRect != 0); + + QPoint p1(80, 80); + QPoint p2(100, 100); + + QTest::touchEvent(canvas, device).press(0, p1, canvas); + QTest::touchEvent(canvas, device).stationary(0).press(1, p2, canvas); + p1 -= QPoint(10,10); + p2 += QPoint(10,10); + QTest::touchEvent(canvas, device).move(0, p1,canvas).move(1, p2,canvas); + + QCOMPARE(root->property("scale").toReal(), 1.0); + + p1 -= QPoint(10,10); + p2 += QPoint(10,10); + QTest::touchEvent(canvas, device).move(0, p1,canvas).move(1, p2,canvas); + + 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); + + // scale beyond bound + p1 -= QPoint(50,50); + p2 += QPoint(50,50); + QTest::touchEvent(canvas, device).move(0, p1, canvas).move(1, p2, canvas); + + QCOMPARE(blackRect->scale(), 2.0); + + QTest::touchEvent(canvas, device).release(0, p1, canvas).release(1, p2, canvas); + + delete canvas; +} + +void tst_QQuickPinchArea::pan() +{ + QQuickView *canvas = createView(); + canvas->setSource(testFileUrl("pinchproperties.qml")); + canvas->show(); + canvas->requestActivateWindow(); + QTest::qWaitForWindowShown(canvas); + QVERIFY(canvas->rootObject() != 0); + qApp->processEvents(); + + QQuickPinchArea *pinchArea = canvas->rootObject()->findChild("pincharea"); + QQuickPinch *pinch = pinchArea->pinch(); + QVERIFY(pinchArea != 0); + QVERIFY(pinch != 0); + + QQuickItem *root = qobject_cast(canvas->rootObject()); + QVERIFY(root != 0); + + // target + QQuickItem *blackRect = canvas->rootObject()->findChild("blackrect"); + QVERIFY(blackRect != 0); + + QPoint p1(80, 80); + QPoint p2(100, 100); + + QTest::touchEvent(canvas, device).press(0, p1, canvas); + QTest::touchEvent(canvas, device).stationary(0).press(1, p2, canvas); + p1 += QPoint(10,10); + p2 += QPoint(10,10); + QTest::touchEvent(canvas, device).move(0, p1, canvas).move(1, p2, canvas); + + QCOMPARE(root->property("scale").toReal(), 1.0); + + p1 += QPoint(10,10); + p2 += QPoint(10,10); + QTest::touchEvent(canvas, device).move(0, p1, canvas).move(1, p2, canvas); + + QCOMPARE(root->property("center").toPointF(), QPointF(60, 60)); // blackrect is at 50,50 + + QCOMPARE(blackRect->x(), 60.0); + QCOMPARE(blackRect->y(), 60.0); + + // pan x beyond bound + p1 += QPoint(100,100); + p2 += QPoint(100,100); + QTest::touchEvent(canvas, device).move(0, p1, canvas).move(1, p2, canvas); + + QCOMPARE(blackRect->x(), 140.0); + QCOMPARE(blackRect->y(), 160.0); + + QTest::touchEvent(canvas, device).release(0, p1, canvas).release(1, p2, canvas); + + delete canvas; +} + +// test pinch, release one point, touch again to continue pinch +void tst_QQuickPinchArea::retouch() +{ + QQuickView *canvas = createView(); + canvas->setSource(testFileUrl("pinchproperties.qml")); + canvas->show(); + canvas->requestActivateWindow(); + QTest::qWaitForWindowShown(canvas); + QVERIFY(canvas->rootObject() != 0); + qApp->processEvents(); + + QQuickPinchArea *pinchArea = canvas->rootObject()->findChild("pincharea"); + QQuickPinch *pinch = pinchArea->pinch(); + QVERIFY(pinchArea != 0); + QVERIFY(pinch != 0); + + QQuickItem *root = qobject_cast(canvas->rootObject()); + QVERIFY(root != 0); + + QSignalSpy startedSpy(pinchArea, SIGNAL(pinchStarted(QQuickPinchEvent *))); + QSignalSpy finishedSpy(pinchArea, SIGNAL(pinchFinished(QQuickPinchEvent *))); + + // target + QQuickItem *blackRect = canvas->rootObject()->findChild("blackrect"); + QVERIFY(blackRect != 0); + + QPoint p1(80, 80); + QPoint p2(100, 100); + + QTest::touchEvent(canvas, device).press(0, p1, canvas); + QTest::touchEvent(canvas, device).stationary(0).press(1, p2, canvas); + p1 -= QPoint(10,10); + p2 += QPoint(10,10); + QTest::touchEvent(canvas, device).move(0, p1, canvas).move(1, p2, canvas); + + QCOMPARE(root->property("scale").toReal(), 1.0); + + p1 -= QPoint(10,10); + p2 += QPoint(10,10); + QTest::touchEvent(canvas, device).move(0, p1, canvas).move(1, p2, canvas); + + 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, device).stationary(0).release(1, p2, canvas); + + QCOMPARE(startedSpy.count(), 1); + QCOMPARE(finishedSpy.count(), 0); + + QCOMPARE(canvas->rootObject()->property("pointCount").toInt(), 1); + + QTest::touchEvent(canvas, device).stationary(0).press(1, p2, canvas); + p1 -= QPoint(10,10); + p2 += QPoint(10,10); + QTest::touchEvent(canvas, device).move(0, p1, canvas).move(1, p2, canvas); + + // 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, device).release(0, p1, canvas).release(1, p2, canvas); + + QCOMPARE(startedSpy.count(), 2); + QCOMPARE(finishedSpy.count(), 1); + + delete canvas; +} + + +QQuickView *tst_QQuickPinchArea::createView() +{ + QQuickView *canvas = new QQuickView(0); + canvas->setGeometry(0,0,240,320); + + return canvas; +} + +QTEST_MAIN(tst_QQuickPinchArea) + +#include "tst_qquickpincharea.moc" -- cgit v1.2.3