summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorLeonardo Sobral Cunha <leo.cunha@nokia.com>2010-02-12 07:19:51 (GMT)
committerLeonardo Sobral Cunha <leo.cunha@nokia.com>2010-03-30 03:54:12 (GMT)
commit7a060ca401b4e260fd08c854213024b050a67ff2 (patch)
tree50745dec7be82136622ae0ccaa0430caa8e0d5a8 /tests/auto
parent68d3e2da7719ff0fc230e8204946b27018e42c14 (diff)
downloadQt-7a060ca401b4e260fd08c854213024b050a67ff2.zip
Qt-7a060ca401b4e260fd08c854213024b050a67ff2.tar.gz
Qt-7a060ca401b4e260fd08c854213024b050a67ff2.tar.bz2
Change and rename qml EaseFollow to SmoothedAnimation
QDeclarativeSmoothedAnimation inherits from QDeclarativeNumberAnimation, as a consequence SmoothedAnimation can be used inside Behaviors and as PropertySourceValues, like any other animation. The old EaseFollow properties changed to comply with the other declarative animations ('source' changed to 'to'), so now 'to' changes are not automatically 'followed' anymore. You can achieve the following behavior by putting a SmoothedAnimation inside a Behavior of a property that is bound to another, as the following example: If you want to follow an hypothetical rect1, you should do now: Rectangle { color: "green" width: 60; height: 60; x: rect1.x - 5; y: rect1.y - 5; Behavior on x { SmoothedAnimation { velocity: 200 } } Behavior on y { SmoothedAnimation { velocity: 200 } } } SmoothedAnimation also supports animating multiple target(s)/property(ies) in the transition case. When a QDeclarativeSmoothedAnimation is restarted, it will match the QDeclarativeProperty which were being animated and transfer the corresponding track velocity to the new starting animations. QSmoothedAnimation is an uncontrolled animation, duration == -1. The duration is set as -1 to avoid consecutive animation state changes stop()/start(). This is particularly useful when using QSmoothAnimation to 'follow' another property, which is also being animated (change the 'to' property every tick). Reviewed-by: Michael Brasser
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/qdeclarativeeasefollow/data/easefollow1.qml2
-rw-r--r--tests/auto/declarative/qdeclarativeeasefollow/data/easefollow2.qml4
-rw-r--r--tests/auto/declarative/qdeclarativeeasefollow/data/easefollow3.qml4
-rw-r--r--tests/auto/declarative/qdeclarativeeasefollow/data/easefollowBehavior.qml23
-rw-r--r--tests/auto/declarative/qdeclarativeeasefollow/data/easefollowValueSource.qml13
-rw-r--r--tests/auto/declarative/qdeclarativeeasefollow/tst_qdeclarativeeasefollow.cpp119
-rw-r--r--tests/auto/declarative/qdeclarativelistview/data/listviewtest.qml2
-rw-r--r--tests/auto/declarative/qmlvisual/qdeclarativeeasefollow/easefollow.qml15
-rw-r--r--tests/auto/declarative/qmlvisual/qdeclarativegridview/gridview2.qml9
9 files changed, 160 insertions, 31 deletions
diff --git a/tests/auto/declarative/qdeclarativeeasefollow/data/easefollow1.qml b/tests/auto/declarative/qdeclarativeeasefollow/data/easefollow1.qml
index 0cc19eb..cfece41 100644
--- a/tests/auto/declarative/qdeclarativeeasefollow/data/easefollow1.qml
+++ b/tests/auto/declarative/qdeclarativeeasefollow/data/easefollow1.qml
@@ -1,3 +1,3 @@
import Qt 4.6
-EaseFollow {}
+SmoothedAnimation {}
diff --git a/tests/auto/declarative/qdeclarativeeasefollow/data/easefollow2.qml b/tests/auto/declarative/qdeclarativeeasefollow/data/easefollow2.qml
index b65964e..74a110d 100644
--- a/tests/auto/declarative/qdeclarativeeasefollow/data/easefollow2.qml
+++ b/tests/auto/declarative/qdeclarativeeasefollow/data/easefollow2.qml
@@ -1,5 +1,5 @@
import Qt 4.6
-EaseFollow {
- source: 10; duration: 300; enabled: true; reversingMode: EaseFollow.Immediate
+SmoothedAnimation {
+ to: 10; duration: 300; reversingMode: SmoothedAnimation.Immediate
}
diff --git a/tests/auto/declarative/qdeclarativeeasefollow/data/easefollow3.qml b/tests/auto/declarative/qdeclarativeeasefollow/data/easefollow3.qml
index f8886e9..3111e82 100644
--- a/tests/auto/declarative/qdeclarativeeasefollow/data/easefollow3.qml
+++ b/tests/auto/declarative/qdeclarativeeasefollow/data/easefollow3.qml
@@ -1,6 +1,6 @@
import Qt 4.6
-EaseFollow {
- source: 10; velocity: 250; enabled: false; reversingMode: EaseFollow.Sync
+SmoothedAnimation {
+ to: 10; velocity: 250; reversingMode: SmoothedAnimation.Sync
maximumEasingTime: 150
}
diff --git a/tests/auto/declarative/qdeclarativeeasefollow/data/easefollowBehavior.qml b/tests/auto/declarative/qdeclarativeeasefollow/data/easefollowBehavior.qml
new file mode 100644
index 0000000..eb06344
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeeasefollow/data/easefollowBehavior.qml
@@ -0,0 +1,23 @@
+import Qt 4.6
+
+Rectangle {
+ width: 400; height: 400; color: "blue"
+
+ Rectangle {
+ id: rect1
+ color: "red"
+ width: 60; height: 60;
+ x: 100; y: 100;
+ SmoothedAnimation on x { to: 200; velocity: 500 }
+ SmoothedAnimation on y { to: 200; velocity: 500 }
+ }
+
+ Rectangle {
+ objectName: "theRect"
+ color: "green"
+ width: 60; height: 60;
+ x: rect1.x; y: rect1.y;
+ Behavior on x { SmoothedAnimation { objectName: "easeX"; velocity: 400 } }
+ Behavior on y { SmoothedAnimation { objectName: "easeY"; velocity: 400 } }
+ }
+ }
diff --git a/tests/auto/declarative/qdeclarativeeasefollow/data/easefollowValueSource.qml b/tests/auto/declarative/qdeclarativeeasefollow/data/easefollowValueSource.qml
new file mode 100644
index 0000000..9ae744c
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeeasefollow/data/easefollowValueSource.qml
@@ -0,0 +1,13 @@
+import Qt 4.6
+
+Rectangle {
+ width: 300; height: 300;
+ Rectangle {
+ objectName: "theRect"
+ color: "red"
+ width: 60; height: 60;
+ x: 100; y: 100;
+ SmoothedAnimation on x { objectName: "easeX"; to: 200; velocity: 500 }
+ SmoothedAnimation on y { objectName: "easeY"; to: 200; duration: 250; velocity: 500 }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeeasefollow/tst_qdeclarativeeasefollow.cpp b/tests/auto/declarative/qdeclarativeeasefollow/tst_qdeclarativeeasefollow.cpp
index 036eec0..401688b 100644
--- a/tests/auto/declarative/qdeclarativeeasefollow/tst_qdeclarativeeasefollow.cpp
+++ b/tests/auto/declarative/qdeclarativeeasefollow/tst_qdeclarativeeasefollow.cpp
@@ -42,6 +42,7 @@
#include <QtDeclarative/qdeclarativeengine.h>
#include <QtDeclarative/qdeclarativecomponent.h>
#include <private/qdeclarativeeasefollow_p.h>
+#include <private/qdeclarativerectangle_p.h>
#include <private/qdeclarativevaluetype_p.h>
#include "../../../shared/util.h"
@@ -55,6 +56,9 @@ private slots:
void defaultValues();
void values();
void disabled();
+ void simpleAnimation();
+ void valueSource();
+ void behavior();
private:
QDeclarativeEngine engine;
@@ -68,16 +72,15 @@ void tst_qdeclarativeeasefollow::defaultValues()
{
QDeclarativeEngine engine;
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/easefollow1.qml"));
- QDeclarativeEaseFollow *obj = qobject_cast<QDeclarativeEaseFollow*>(c.create());
+ QDeclarativeSmoothedAnimation *obj = qobject_cast<QDeclarativeSmoothedAnimation*>(c.create());
QVERIFY(obj != 0);
- QCOMPARE(obj->sourceValue(), 0.);
+ QCOMPARE(obj->to(), 0.);
QCOMPARE(obj->velocity(), 200.);
- QCOMPARE(obj->enabled(), true);
- QCOMPARE(obj->duration(), -1.);
- QCOMPARE(obj->maximumEasingTime(), -1.);
- QCOMPARE(obj->reversingMode(), QDeclarativeEaseFollow::Eased);
+ QCOMPARE(obj->duration(), -1);
+ QCOMPARE(obj->maximumEasingTime(), -1);
+ QCOMPARE(obj->reversingMode(), QDeclarativeSmoothedAnimation::Eased);
delete obj;
}
@@ -86,16 +89,15 @@ void tst_qdeclarativeeasefollow::values()
{
QDeclarativeEngine engine;
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/easefollow2.qml"));
- QDeclarativeEaseFollow *obj = qobject_cast<QDeclarativeEaseFollow*>(c.create());
+ QDeclarativeSmoothedAnimation *obj = qobject_cast<QDeclarativeSmoothedAnimation*>(c.create());
QVERIFY(obj != 0);
- QCOMPARE(obj->sourceValue(), 10.);
+ QCOMPARE(obj->to(), 10.);
QCOMPARE(obj->velocity(), 200.);
- QCOMPARE(obj->enabled(), true);
- QCOMPARE(obj->duration(), 300.);
- QCOMPARE(obj->maximumEasingTime(), -1.);
- QCOMPARE(obj->reversingMode(), QDeclarativeEaseFollow::Immediate);
+ QCOMPARE(obj->duration(), 300);
+ QCOMPARE(obj->maximumEasingTime(), -1);
+ QCOMPARE(obj->reversingMode(), QDeclarativeSmoothedAnimation::Immediate);
delete obj;
}
@@ -104,19 +106,102 @@ void tst_qdeclarativeeasefollow::disabled()
{
QDeclarativeEngine engine;
QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/easefollow3.qml"));
- QDeclarativeEaseFollow *obj = qobject_cast<QDeclarativeEaseFollow*>(c.create());
+ QDeclarativeSmoothedAnimation *obj = qobject_cast<QDeclarativeSmoothedAnimation*>(c.create());
QVERIFY(obj != 0);
- QCOMPARE(obj->sourceValue(), 10.);
+ QCOMPARE(obj->to(), 10.);
QCOMPARE(obj->velocity(), 250.);
- QCOMPARE(obj->enabled(), false);
- QCOMPARE(obj->maximumEasingTime(), 150.);
- QCOMPARE(obj->reversingMode(), QDeclarativeEaseFollow::Sync);
+ QCOMPARE(obj->maximumEasingTime(), 150);
+ QCOMPARE(obj->reversingMode(), QDeclarativeSmoothedAnimation::Sync);
delete obj;
}
+void tst_qdeclarativeeasefollow::simpleAnimation()
+{
+ QDeclarativeRectangle rect;
+ QDeclarativeSmoothedAnimation animation;
+ animation.setTarget(&rect);
+ animation.setProperty("x");
+ animation.setTo(200);
+ animation.setDuration(250);
+ QVERIFY(animation.target() == &rect);
+ QVERIFY(animation.property() == "x");
+ QVERIFY(animation.to() == 200);
+ animation.start();
+ QVERIFY(animation.isRunning());
+ QTest::qWait(animation.duration());
+ QTRY_COMPARE(rect.x(), qreal(200));
+
+ rect.setX(0);
+ animation.start();
+ animation.pause();
+ QVERIFY(animation.isRunning());
+ QVERIFY(animation.isPaused());
+ animation.setCurrentTime(125);
+ QVERIFY(animation.currentTime() == 125);
+ QCOMPARE(rect.x(), qreal(100));
+}
+
+void tst_qdeclarativeeasefollow::valueSource()
+{
+ QDeclarativeEngine engine;
+
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/easefollowValueSource.qml"));
+
+ QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QDeclarativeRectangle *theRect = rect->findChild<QDeclarativeRectangle*>("theRect");
+ QVERIFY(theRect);
+
+ QDeclarativeSmoothedAnimation *easeX = rect->findChild<QDeclarativeSmoothedAnimation*>("easeX");
+ QVERIFY(easeX);
+ QVERIFY(easeX->isRunning());
+
+ QDeclarativeSmoothedAnimation *easeY = rect->findChild<QDeclarativeSmoothedAnimation*>("easeY");
+ QVERIFY(easeY);
+ QVERIFY(easeY->isRunning());
+
+ // XXX get the proper duration
+ QTest::qWait(100);
+
+ QTRY_VERIFY(!easeX->isRunning());
+ QTRY_VERIFY(!easeY->isRunning());
+
+ QTRY_COMPARE(theRect->x(), qreal(200));
+ QTRY_COMPARE(theRect->y(), qreal(200));
+}
+
+void tst_qdeclarativeeasefollow::behavior()
+{
+ QDeclarativeEngine engine;
+
+ QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/easefollowBehavior.qml"));
+
+ QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QDeclarativeRectangle *theRect = rect->findChild<QDeclarativeRectangle*>("theRect");
+ QVERIFY(theRect);
+
+ QDeclarativeSmoothedAnimation *easeX = rect->findChild<QDeclarativeSmoothedAnimation*>("easeX");
+ QVERIFY(easeX);
+
+ QDeclarativeSmoothedAnimation *easeY = rect->findChild<QDeclarativeSmoothedAnimation*>("easeY");
+ QVERIFY(easeY);
+
+ // XXX get the proper duration
+ QTest::qWait(400);
+
+ QTRY_VERIFY(!easeX->isRunning());
+ QTRY_VERIFY(!easeY->isRunning());
+
+ QTRY_COMPARE(theRect->x(), qreal(200));
+ QTRY_COMPARE(theRect->y(), qreal(200));
+}
+
QTEST_MAIN(tst_qdeclarativeeasefollow)
#include "tst_qdeclarativeeasefollow.moc"
diff --git a/tests/auto/declarative/qdeclarativelistview/data/listviewtest.qml b/tests/auto/declarative/qdeclarativelistview/data/listviewtest.qml
index cc64c3f..40fc436 100644
--- a/tests/auto/declarative/qdeclarativelistview/data/listviewtest.qml
+++ b/tests/auto/declarative/qdeclarativelistview/data/listviewtest.qml
@@ -98,7 +98,7 @@ Rectangle {
},
Component {
id: invalidHl
- EaseFollow {}
+ SmoothedAnimation {}
}
]
ListView {
diff --git a/tests/auto/declarative/qmlvisual/qdeclarativeeasefollow/easefollow.qml b/tests/auto/declarative/qmlvisual/qdeclarativeeasefollow/easefollow.qml
index 121328b..ee94857 100644
--- a/tests/auto/declarative/qmlvisual/qdeclarativeeasefollow/easefollow.qml
+++ b/tests/auto/declarative/qmlvisual/qdeclarativeeasefollow/easefollow.qml
@@ -15,26 +15,31 @@ Rectangle {
Rectangle {
width: 50; height: 20; y: 60; color: "red"
- EaseFollow on x { source: rect.x; velocity: 400 }
+ x: rect.x
+ Behavior on x { SmoothedAnimation { velocity: 400 } }
}
Rectangle {
width: 50; height: 20; y: 90; color: "yellow"
- EaseFollow on x { source: rect.x; velocity: 300; reversingMode: EaseFollow.Immediate }
+ x: rect.x
+ Behavior on x { SmoothedAnimation { velocity: 300; reversingMode: SmoothedAnimation.Immediate } }
}
Rectangle {
width: 50; height: 20; y: 120; color: "green"
- EaseFollow on x { source: rect.x; reversingMode: EaseFollow.Sync }
+ x: rect.x
+ Behavior on x { SmoothedAnimation { reversingMode: SmoothedAnimation.Sync } }
}
Rectangle {
width: 50; height: 20; y: 150; color: "purple"
- EaseFollow on x { source: rect.x; maximumEasingTime: 200 }
+ x: rect.x
+ Behavior on x { SmoothedAnimation { maximumEasingTime: 200 } }
}
Rectangle {
width: 50; height: 20; y: 180; color: "blue"
- EaseFollow on x { source: rect.x; duration: 300 }
+ x: rect.x
+ Behavior on x { SmoothedAnimation { duration: 300 } }
}
}
diff --git a/tests/auto/declarative/qmlvisual/qdeclarativegridview/gridview2.qml b/tests/auto/declarative/qmlvisual/qdeclarativegridview/gridview2.qml
index f4fb863..d8512eb 100644
--- a/tests/auto/declarative/qmlvisual/qdeclarativegridview/gridview2.qml
+++ b/tests/auto/declarative/qmlvisual/qdeclarativegridview/gridview2.qml
@@ -48,9 +48,12 @@ Rectangle {
flickableData: [
Rectangle {
color: "transparent"; border.color: "white"; border.width: 8; z: 3000
- height: 100; width: 100; x: 4; y: 4
- EaseFollow on x { source: gridView.currentItem.x; velocity: 500 }
- EaseFollow on y { source: gridView.currentItem.y; velocity: 500 }
+ height: 100; width: 100
+ x: gridView.currentItem.x
+ y: gridView.currentItem.y
+
+ Behavior on x { SmoothedAnimation { velocity: 500 } }
+ Behavior on y { SmoothedAnimation { velocity: 500 } }
}
]
}