summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2010-02-17 03:21:46 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2010-02-18 05:17:15 (GMT)
commit05cbd2fe4b5d9cbdef3be52b6d14d2d20255641a (patch)
treedecbeb2a21a1b022bf5f3d5773935a33691c9ca8
parent9fb06ea43e807f2bbb40de89e9af5f2cca02212f (diff)
downloadQt-05cbd2fe4b5d9cbdef3be52b6d14d2d20255641a.zip
Qt-05cbd2fe4b5d9cbdef3be52b6d14d2d20255641a.tar.gz
Qt-05cbd2fe4b5d9cbdef3be52b6d14d2d20255641a.tar.bz2
Fix bugs and add tests related to manual start/stop control of animations.
This better enforces the restriction on starting an animation that is not top-level, or is part of a Transition or Behavior.
-rw-r--r--src/declarative/util/qmlanimation.cpp19
-rw-r--r--src/declarative/util/qmlanimation_p_p.h3
-rw-r--r--tests/auto/declarative/qmlanimations/data/dontStart.qml19
-rw-r--r--tests/auto/declarative/qmlanimations/data/dontStart2.qml19
-rw-r--r--tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp33
-rw-r--r--tests/auto/declarative/qmlbehaviors/data/dontStart.qml18
-rw-r--r--tests/auto/declarative/qmlbehaviors/tst_qmlbehaviors.cpp15
7 files changed, 116 insertions, 10 deletions
diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp
index dd783ca..4b33af0 100644
--- a/src/declarative/util/qmlanimation.cpp
+++ b/src/declarative/util/qmlanimation.cpp
@@ -243,8 +243,12 @@ QmlMetaProperty QmlAbstractAnimationPrivate::createProperty(QObject *obj, const
void QmlAbstractAnimation::setRunning(bool r)
{
Q_D(QmlAbstractAnimation);
- if (r == false)
- d->avoidPropertyValueSourceStart = true;
+ if (!d->componentComplete) {
+ d->running = r;
+ if (r == false)
+ d->avoidPropertyValueSourceStart = true;
+ return;
+ }
if (d->running == r)
return;
@@ -266,10 +270,7 @@ void QmlAbstractAnimation::setRunning(bool r)
this, SLOT(timelineComplete()));
d->connectedTimeLine = true;
}
- if (d->componentComplete)
- d->commence();
- else
- d->startOnCompletion = true;
+ d->commence();
emit started();
} else {
if (d->alwaysRunToEnd) {
@@ -331,9 +332,11 @@ void QmlAbstractAnimation::classBegin()
void QmlAbstractAnimation::componentComplete()
{
Q_D(QmlAbstractAnimation);
- if (d->startOnCompletion)
- d->commence();
d->componentComplete = true;
+ if (d->running) {
+ d->running = false;
+ setRunning(true);
+ }
}
/*!
diff --git a/src/declarative/util/qmlanimation_p_p.h b/src/declarative/util/qmlanimation_p_p.h
index 288aaa8..ee0c291 100644
--- a/src/declarative/util/qmlanimation_p_p.h
+++ b/src/declarative/util/qmlanimation_p_p.h
@@ -209,7 +209,7 @@ class QmlAbstractAnimationPrivate : public QObjectPrivate
public:
QmlAbstractAnimationPrivate()
: running(false), paused(false), alwaysRunToEnd(false), repeat(false),
- connectedTimeLine(false), componentComplete(true), startOnCompletion(false),
+ connectedTimeLine(false), componentComplete(true),
avoidPropertyValueSourceStart(false), disableUserControl(false), group(0) {}
bool running:1;
@@ -218,7 +218,6 @@ public:
bool repeat:1;
bool connectedTimeLine:1;
bool componentComplete:1;
- bool startOnCompletion:1;
bool avoidPropertyValueSourceStart:1;
bool disableUserControl:1;
diff --git a/tests/auto/declarative/qmlanimations/data/dontStart.qml b/tests/auto/declarative/qmlanimations/data/dontStart.qml
new file mode 100644
index 0000000..36417db
--- /dev/null
+++ b/tests/auto/declarative/qmlanimations/data/dontStart.qml
@@ -0,0 +1,19 @@
+import Qt 4.6
+
+Rectangle {
+ id: wrapper
+ width: 600
+ height: 400
+
+ Rectangle {
+ id: redRect
+ width: 100; height: 100
+ color: Qt.rgba(1,0,0)
+ x: SequentialAnimation {
+ running: false
+ NumberAnimation { objectName: "MyAnim"; running: true }
+ }
+
+ }
+
+}
diff --git a/tests/auto/declarative/qmlanimations/data/dontStart2.qml b/tests/auto/declarative/qmlanimations/data/dontStart2.qml
new file mode 100644
index 0000000..1a6540f
--- /dev/null
+++ b/tests/auto/declarative/qmlanimations/data/dontStart2.qml
@@ -0,0 +1,19 @@
+import Qt 4.6
+
+Rectangle {
+ id: wrapper
+ width: 600
+ height: 400
+
+ Rectangle {
+ id: redRect
+ width: 100; height: 100
+ color: Qt.rgba(1,0,0)
+
+ transitions: Transition {
+ SequentialAnimation {
+ NumberAnimation { id: myAnim; objectName: "MyAnim"; running: true }
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp b/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp
index b4759d4..54e6e27 100644
--- a/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp
+++ b/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp
@@ -71,6 +71,7 @@ private slots:
void invalidDuration();
void attached();
void propertyValueSourceDefaultStart();
+ void dontStart();
};
#define QTIMED_COMPARE(lhs, rhs) do { \
@@ -634,6 +635,38 @@ void tst_qmlanimations::propertyValueSourceDefaultStart()
}
}
+
+void tst_qmlanimations::dontStart()
+{
+ {
+ QmlEngine engine;
+
+ QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/dontStart.qml"));
+
+ QTest::ignoreMessage(QtWarningMsg, "QmlAbstractAnimation: setRunning() cannot be used on non-root animation nodes");
+ QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QmlAbstractAnimation *myAnim = rect->findChild<QmlAbstractAnimation*>("MyAnim");
+ QVERIFY(myAnim && myAnim->qtAnimation());
+ QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped);
+ }
+
+ {
+ QmlEngine engine;
+
+ QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/dontStart2.qml"));
+
+ QTest::ignoreMessage(QtWarningMsg, "QmlAbstractAnimation: setRunning() cannot be used on non-root animation nodes");
+ QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create());
+ QVERIFY(rect);
+
+ QmlAbstractAnimation *myAnim = rect->findChild<QmlAbstractAnimation*>("MyAnim");
+ QVERIFY(myAnim && myAnim->qtAnimation());
+ QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped);
+ }
+}
+
QTEST_MAIN(tst_qmlanimations)
#include "tst_qmlanimations.moc"
diff --git a/tests/auto/declarative/qmlbehaviors/data/dontStart.qml b/tests/auto/declarative/qmlbehaviors/data/dontStart.qml
new file mode 100644
index 0000000..ba7cc9c
--- /dev/null
+++ b/tests/auto/declarative/qmlbehaviors/data/dontStart.qml
@@ -0,0 +1,18 @@
+import Qt 4.6
+
+Rectangle {
+ id: wrapper
+ width: 600
+ height: 400
+
+ Rectangle {
+ id: redRect
+ width: 100; height: 100
+ color: Qt.rgba(1,0,0)
+ x: Behavior {
+ NumberAnimation { objectName: "MyAnim"; running: true }
+ }
+
+ }
+
+}
diff --git a/tests/auto/declarative/qmlbehaviors/tst_qmlbehaviors.cpp b/tests/auto/declarative/qmlbehaviors/tst_qmlbehaviors.cpp
index 47bd329..5f199ef 100644
--- a/tests/auto/declarative/qmlbehaviors/tst_qmlbehaviors.cpp
+++ b/tests/auto/declarative/qmlbehaviors/tst_qmlbehaviors.cpp
@@ -67,6 +67,7 @@ private slots:
void nonSelectingBehavior();
void reassignedAnimation();
void disabled();
+ void dontStart();
};
void tst_qmlbehaviors::simpleBehavior()
@@ -278,7 +279,21 @@ void tst_qmlbehaviors::disabled()
rect->setState("moved");
qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x();
QCOMPARE(x, qreal(200)); //should change immediately
+}
+
+void tst_qmlbehaviors::dontStart()
+{
+ QmlEngine engine;
+
+ QmlComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/dontStart.qml"));
+
+ QTest::ignoreMessage(QtWarningMsg, "QmlAbstractAnimation: setRunning() cannot be used on non-root animation nodes");
+ QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create());
+ QVERIFY(rect);
+ QmlAbstractAnimation *myAnim = rect->findChild<QmlAbstractAnimation*>("MyAnim");
+ QVERIFY(myAnim && myAnim->qtAnimation());
+ QVERIFY(myAnim->qtAnimation()->state() == QAbstractAnimation::Stopped);
}
QTEST_MAIN(tst_qmlbehaviors)