diff options
-rw-r--r-- | src/corelib/animation/qpropertyanimation.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qanimationgroup/tst_qanimationgroup.cpp | 32 | ||||
-rw-r--r-- | tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp | 10 |
3 files changed, 41 insertions, 7 deletions
diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp index adf3527..edcabaa 100644 --- a/src/corelib/animation/qpropertyanimation.cpp +++ b/src/corelib/animation/qpropertyanimation.cpp @@ -233,14 +233,16 @@ void QPropertyAnimation::updateState(QAbstractAnimation::State oldState, d->updateMetaProperty(); QPropertyAnimation *oldAnim = hash->value(key, 0); if (oldAnim) { - //we try to stop the top level group + // try to stop the top level group QAbstractAnimation *current = oldAnim; while(current->group() && current->state() != Stopped) current = current->group(); current->stop(); } hash->insert(key, this); // Initialize start value - if (d->target && !d->defaultStartValue.isValid() && (d->atBeginning() || d->atEnd())) { + // ### review this line below, d->atEnd() ? + // ### avoid entering a state where start value is not set + if (d->target && (d->atBeginning() || d->atEnd())) { d->setDefaultStartValue(d->target->property(d->propertyName.constData())); } } else if (hash->value(key) == this) { diff --git a/tests/auto/qanimationgroup/tst_qanimationgroup.cpp b/tests/auto/qanimationgroup/tst_qanimationgroup.cpp index 3cf5631..2952a39 100644 --- a/tests/auto/qanimationgroup/tst_qanimationgroup.cpp +++ b/tests/auto/qanimationgroup/tst_qanimationgroup.cpp @@ -69,6 +69,7 @@ private slots: void setParentAutoAdd(); void beginNestedGroup(); void addChildTwice(); + void loopWithoutStartValue(); }; tst_QAnimationGroup::tst_QAnimationGroup() @@ -377,5 +378,36 @@ void tst_QAnimationGroup::addChildTwice() delete parent; } +void tst_QAnimationGroup::loopWithoutStartValue() +{ + QAnimationGroup *parent = new QSequentialAnimationGroup(); + QObject o; + o.setProperty("ole", 0); + QCOMPARE(o.property("ole").toInt(), 0); + + QPropertyAnimation anim1(&o, "ole"); + anim1.setEndValue(-50); + anim1.setDuration(100); + + QPropertyAnimation anim2(&o, "ole"); + anim2.setEndValue(50); + anim2.setDuration(100); + + parent->addAnimation(&anim1); + parent->addAnimation(&anim2); + + parent->setLoopCount(-1); + parent->start(); + + QVERIFY(anim1.startValue().isNull()); + QCOMPARE(anim1.currentValue().toInt(), 0); + QCOMPARE(parent->currentLoop(), 0); + + parent->setCurrentTime(200); + QCOMPARE(parent->currentLoop(), 1); + QCOMPARE(anim1.currentValue().toInt(), 50); + parent->stop(); +} + QTEST_MAIN(tst_QAnimationGroup) #include "tst_qanimationgroup.moc" diff --git a/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp b/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp index 2ab0605..437c862 100644 --- a/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp +++ b/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp @@ -42,7 +42,6 @@ #include <QtTest/QtTest> #include <QtCore/qpropertyanimation.h> -#include <QtGui/qitemanimation.h> #include <QtGui/qwidget.h> //TESTED_CLASS=QPropertyAnimation @@ -526,13 +525,14 @@ void tst_QPropertyAnimation::startWithoutStartValue() anim.setEndValue(110); anim.start(); current = anim.currentValue().toInt(); - QCOMPARE(current, 42); // the initial default start value - + // the default start value will reevaluate the current property + // and set it to the end value of the last iteration + QCOMPARE(current, 100); QTest::qWait(100); current = anim.currentValue().toInt(); //it is somewhere in the animation - QVERIFY(current > 42); - QVERIFY(current < 110); + QVERIFY(current >= 100); + QVERIFY(current <= 110); } void tst_QPropertyAnimation::playForwardBackward() |