aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2011-09-07 12:39:58 +1000
committerQt by Nokia <qt-info@nokia.com>2011-09-19 01:05:17 +0200
commit48e333595fd81192a8cc2befa509407cc7a43381 (patch)
treea5e8db90201117d71d5677c67c249d086fcf508a /tests
parent38fc46c5d81f08328cec474e2f7f8b9285bccefc (diff)
PathAnimation updates.
Allow smooth orientation changes, smooth interruptions, and implicit "from" in PathAnimation. Change-Id: I2191f6df89ec25d78b1d498827281803a07129c9 Reviewed-on: http://codereview.qt-project.org/4378 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qdeclarativeanimations/data/pathAnimation2.qml26
-rw-r--r--tests/auto/declarative/qdeclarativeanimations/data/pathAnimationNoStart.qml27
-rw-r--r--tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp120
3 files changed, 151 insertions, 22 deletions
diff --git a/tests/auto/declarative/qdeclarativeanimations/data/pathAnimation2.qml b/tests/auto/declarative/qdeclarativeanimations/data/pathAnimation2.qml
new file mode 100644
index 0000000000..951c5b2e57
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeanimations/data/pathAnimation2.qml
@@ -0,0 +1,26 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 400
+ height: 400
+
+ Rectangle {
+ id: redRect
+ color: "red"
+ width: 100; height: 100
+ x: 50; y: 50
+ }
+
+ PathAnimation {
+ target: redRect
+ duration: 100;
+ endRotation: 0
+ orientationEntryInterval: .1
+ orientationExitInterval: .1
+ orientation: PathAnimation.RightFirst
+ path: Path {
+ startX: 50; startY: 50
+ PathLine { x: 300; y: 300 }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeanimations/data/pathAnimationNoStart.qml b/tests/auto/declarative/qdeclarativeanimations/data/pathAnimationNoStart.qml
new file mode 100644
index 0000000000..be3501fabb
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeanimations/data/pathAnimationNoStart.qml
@@ -0,0 +1,27 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 400
+ height: 400
+
+ Rectangle {
+ id: redRect
+ color: "red"
+ width: 100; height: 100
+ x: 50; y: 50
+ }
+
+ PathAnimation {
+ target: redRect
+ duration: 100;
+ path: Path {
+ //no startX/Y defined (should automatically start from redRects pos)
+ PathCubic {
+ x: 300; y: 300
+
+ control1X: 300; control1Y: 50
+ control2X: 50; control2Y: 300
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp
index df840e9d5c..303268eba6 100644
--- a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp
+++ b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp
@@ -50,6 +50,9 @@
#include <QVariantAnimation>
#include <QEasingCurve>
+#include <limits.h>
+#include <math.h>
+
#include "../../../shared/util.h"
#ifdef Q_OS_SYMBIAN
@@ -72,6 +75,7 @@ private slots:
void simpleRotation();
void simplePath();
void pathInterpolator();
+ void pathWithNoStart();
void alwaysRunToEnd();
void complete();
void resume();
@@ -220,33 +224,71 @@ void tst_qdeclarativeanimations::simpleRotation()
void tst_qdeclarativeanimations::simplePath()
{
- QDeclarativeEngine engine;
- QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/pathAnimation.qml"));
- QSGRectangle *rect = qobject_cast<QSGRectangle*>(c.create());
- QVERIFY(rect);
+ {
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/pathAnimation.qml"));
+ QSGRectangle *rect = qobject_cast<QSGRectangle*>(c.create());
+ QVERIFY(rect);
- QSGRectangle *redRect = rect->findChild<QSGRectangle*>();
- QVERIFY(redRect);
- QSGPathAnimation *pathAnim = rect->findChild<QSGPathAnimation*>();
- QVERIFY(pathAnim);
+ QSGRectangle *redRect = rect->findChild<QSGRectangle*>();
+ QVERIFY(redRect);
+ QSGPathAnimation *pathAnim = rect->findChild<QSGPathAnimation*>();
+ QVERIFY(pathAnim);
+
+ pathAnim->start();
+ pathAnim->pause();
+
+ pathAnim->setCurrentTime(30);
+ QCOMPARE(redRect->x(), qreal(167));
+ QCOMPARE(redRect->y(), qreal(104));
+
+ pathAnim->setCurrentTime(100);
+ QCOMPARE(redRect->x(), qreal(300));
+ QCOMPARE(redRect->y(), qreal(300));
+
+ //verify animation runs to end
+ pathAnim->start();
+ QCOMPARE(redRect->x(), qreal(50));
+ QCOMPARE(redRect->y(), qreal(50));
+ QTRY_COMPARE(redRect->x(), qreal(300));
+ QCOMPARE(redRect->y(), qreal(300));
+
+ pathAnim->setOrientation(QSGPathAnimation::RightFirst);
+ QCOMPARE(pathAnim->orientation(), QSGPathAnimation::RightFirst);
+ pathAnim->start();
+ QTRY_VERIFY(redRect->rotation() != 0);
+ pathAnim->stop();
+ }
- pathAnim->start();
- pathAnim->pause();
+ {
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/pathAnimation2.qml"));
+ QSGRectangle *rect = qobject_cast<QSGRectangle*>(c.create());
+ QVERIFY(rect);
- pathAnim->setCurrentTime(50);
- QCOMPARE(redRect->x(), qreal(175));
- QCOMPARE(redRect->y(), qreal(175));
+ QSGRectangle *redRect = rect->findChild<QSGRectangle*>();
+ QVERIFY(redRect);
+ QSGPathAnimation *pathAnim = rect->findChild<QSGPathAnimation*>();
+ QVERIFY(pathAnim);
- pathAnim->setCurrentTime(100);
- QCOMPARE(redRect->x(), qreal(300));
- QCOMPARE(redRect->y(), qreal(300));
+ QCOMPARE(pathAnim->orientation(), QSGPathAnimation::RightFirst);
- //verify animation runs to end
- pathAnim->start();
- QCOMPARE(redRect->x(), qreal(50));
- QCOMPARE(redRect->y(), qreal(50));
- QTRY_COMPARE(redRect->x(), qreal(300));
- QCOMPARE(redRect->y(), qreal(300));
+ pathAnim->start();
+ pathAnim->pause();
+ QCOMPARE(redRect->x(), qreal(50));
+ QCOMPARE(redRect->y(), qreal(50));
+ QCOMPARE(redRect->rotation(), qreal(-360));
+
+ pathAnim->setCurrentTime(50);
+ QCOMPARE(redRect->x(), qreal(175));
+ QCOMPARE(redRect->y(), qreal(175));
+ QCOMPARE(redRect->rotation(), qreal(-315));
+
+ pathAnim->setCurrentTime(100);
+ QCOMPARE(redRect->x(), qreal(300));
+ QCOMPARE(redRect->y(), qreal(300));
+ QCOMPARE(redRect->rotation(), qreal(0));
+ }
}
void tst_qdeclarativeanimations::pathInterpolator()
@@ -274,6 +316,40 @@ void tst_qdeclarativeanimations::pathInterpolator()
QCOMPARE(interpolator->angle(), qreal(0));
}
+void tst_qdeclarativeanimations::pathWithNoStart()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/pathAnimationNoStart.qml"));
+ QSGRectangle *rect = qobject_cast<QSGRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QSGRectangle *redRect = rect->findChild<QSGRectangle*>();
+ QVERIFY(redRect);
+ QSGPathAnimation *pathAnim = rect->findChild<QSGPathAnimation*>();
+ QVERIFY(pathAnim);
+
+ pathAnim->start();
+ pathAnim->pause();
+ QCOMPARE(redRect->x(), qreal(50));
+ QCOMPARE(redRect->y(), qreal(50));
+
+ pathAnim->setCurrentTime(50);
+ QCOMPARE(redRect->x(), qreal(175));
+ QCOMPARE(redRect->y(), qreal(175));
+
+ pathAnim->setCurrentTime(100);
+ QCOMPARE(redRect->x(), qreal(300));
+ QCOMPARE(redRect->y(), qreal(300));
+
+ redRect->setX(100);
+ redRect->setY(100);
+ pathAnim->start();
+ QCOMPARE(redRect->x(), qreal(100));
+ QCOMPARE(redRect->y(), qreal(100));
+ QTRY_COMPARE(redRect->x(), qreal(300));
+ QCOMPARE(redRect->y(), qreal(300));
+}
+
void tst_qdeclarativeanimations::alwaysRunToEnd()
{
QSGRectangle rect;