summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/animation/qabstractanimation.cpp187
-rw-r--r--src/corelib/animation/qabstractanimation_p.h41
-rw-r--r--src/corelib/animation/qanimationgroup_p.h4
-rw-r--r--src/corelib/animation/qpauseanimation.cpp1
-rw-r--r--tests/auto/auto.pro1
-rw-r--r--tests/auto/qpauseanimation/qpauseanimation.pro5
-rw-r--r--tests/auto/qpauseanimation/tst_qpauseanimation.cpp392
7 files changed, 584 insertions, 47 deletions
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp
index a4a8853..9e50784 100644
--- a/src/corelib/animation/qabstractanimation.cpp
+++ b/src/corelib/animation/qabstractanimation.cpp
@@ -144,6 +144,7 @@
#include "qabstractanimation.h"
#include "qanimationgroup.h"
+
#include <QtCore/qdebug.h>
#include "qabstractanimation_p.h"
@@ -176,7 +177,8 @@ Q_GLOBAL_STATIC(QThreadStorage<QUnifiedTimer *>, unifiedTimer)
QUnifiedTimer::QUnifiedTimer() :
QObject(), lastTick(0), timingInterval(DEFAULT_TIMER_INTERVAL),
- currentAnimationIdx(0), consistentTiming(false)
+ currentAnimationIdx(0), consistentTiming(false), isPauseTimerActive(false),
+ runningLeafAnimations(0)
{
}
@@ -192,50 +194,96 @@ QUnifiedTimer *QUnifiedTimer::instance()
return inst;
}
+void QUnifiedTimer::ensureTimerUpdate(QAbstractAnimation *animation)
+{
+ if (isPauseTimerActive) {
+ updateAnimationsTime();
+ } else {
+ // this code is needed when ensureTimerUpdate is called from setState because we update
+ // the currentTime when an animation starts running (otherwise we could remove it)
+ animation->setCurrentTime(animation->currentTime());
+ }
+}
+
+void QUnifiedTimer::updateAnimationsTime()
+{
+ // this is simply the time we last received a tick
+ const int oldLastTick = lastTick;
+ // ignore consistentTiming in case the pause timer is active
+ if (consistentTiming && !isPauseTimerActive)
+ lastTick = oldLastTick + timingInterval;
+ else
+ lastTick = time.elapsed();
+ const int delta = lastTick - oldLastTick;
+
+ //we make sure we only call update time if the time has actually changed
+ //it might happen in some cases that the time doesn't change because events are delayed
+ //when the CPU load is high
+ if (delta) {
+ for (currentAnimationIdx = 0; currentAnimationIdx < animations.count(); ++currentAnimationIdx) {
+ QAbstractAnimation *animation = animations.at(currentAnimationIdx);
+ int elapsed = QAbstractAnimationPrivate::get(animation)->totalCurrentTime
+ + (animation->direction() == QAbstractAnimation::Forward ? delta : -delta);
+ animation->setCurrentTime(elapsed);
+ }
+ currentAnimationIdx = 0;
+ }
+}
+
+void QUnifiedTimer::restartAnimationTimer()
+{
+ if (runningLeafAnimations == 0 && !runningPauseAnimations.isEmpty()) {
+ int closestTimeToFinish = closestPauseAnimationTimeToFinish();
+ animationTimer.start(closestTimeToFinish, this);
+ isPauseTimerActive = true;
+ } else if (!animationTimer.isActive() || isPauseTimerActive) {
+ animationTimer.start(timingInterval, this);
+ isPauseTimerActive = false;
+ }
+}
+
void QUnifiedTimer::timerEvent(QTimerEvent *event)
{
if (event->timerId() == startStopAnimationTimer.timerId()) {
startStopAnimationTimer.stop();
+
//we transfer the waiting animations into the "really running" state
animations += animationsToStart;
animationsToStart.clear();
if (animations.isEmpty()) {
animationTimer.stop();
- } else if (!animationTimer.isActive()) {
- animationTimer.start(timingInterval, this);
- lastTick = 0;
- time.start();
- }
- } else if (event->timerId() == animationTimer.timerId()) {
- //this is simply the time we last received a tick
- const int oldLastTick = lastTick;
- lastTick = consistentTiming ? oldLastTick + timingInterval : time.elapsed();
-
- //we make sure we only call update time if the time has actually changed
- //it might happen in some cases that the time doesn't change because events are delayed
- //when the CPU load is high
- if (const int delta = lastTick - oldLastTick) {
- for (currentAnimationIdx = 0; currentAnimationIdx < animations.count(); ++currentAnimationIdx) {
- QAbstractAnimation *animation = animations.at(currentAnimationIdx);
- int elapsed = QAbstractAnimationPrivate::get(animation)->totalCurrentTime
- + (animation->direction() == QAbstractAnimation::Forward ? delta : -delta);
- animation->setCurrentTime(elapsed);
+ isPauseTimerActive = false;
+ // invalidate the start reference time
+ time = QTime();
+ } else {
+ restartAnimationTimer();
+ if (!time.isValid()) {
+ lastTick = 0;
+ time.start();
}
- currentAnimationIdx = 0;
}
+ } else if (event->timerId() == animationTimer.timerId()) {
+ // update current time on all top level animations
+ updateAnimationsTime();
+ restartAnimationTimer();
}
}
-void QUnifiedTimer::registerAnimation(QAbstractAnimation *animation)
+void QUnifiedTimer::registerAnimation(QAbstractAnimation *animation, bool isTopLevel)
{
- Q_ASSERT(!QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer);
- QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer = true;
- animationsToStart << animation;
- startStopAnimationTimer.start(STARTSTOP_TIMER_DELAY, this);
+ registerRunningAnimation(animation);
+ if (isTopLevel) {
+ Q_ASSERT(!QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer);
+ QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer = true;
+ animationsToStart << animation;
+ startStopAnimationTimer.start(STARTSTOP_TIMER_DELAY, this);
+ }
}
void QUnifiedTimer::unregisterAnimation(QAbstractAnimation *animation)
{
+ unregisterRunningAnimation(animation);
+
if (!QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer)
return;
@@ -253,6 +301,46 @@ void QUnifiedTimer::unregisterAnimation(QAbstractAnimation *animation)
QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer = false;
}
+void QUnifiedTimer::registerRunningAnimation(QAbstractAnimation *animation)
+{
+ if (QAbstractAnimationPrivate::get(animation)->isGroup)
+ return;
+
+ if (QAbstractAnimationPrivate::get(animation)->isPause)
+ runningPauseAnimations << animation;
+ else
+ runningLeafAnimations++;
+}
+
+void QUnifiedTimer::unregisterRunningAnimation(QAbstractAnimation *animation)
+{
+ if (QAbstractAnimationPrivate::get(animation)->isGroup)
+ return;
+
+ if (QAbstractAnimationPrivate::get(animation)->isPause)
+ runningPauseAnimations.removeOne(animation);
+ else
+ runningLeafAnimations--;
+}
+
+int QUnifiedTimer::closestPauseAnimationTimeToFinish()
+{
+ int closestTimeToFinish = INT_MAX;
+ for (int i = 0; i < runningPauseAnimations.size(); ++i) {
+ QAbstractAnimation *animation = runningPauseAnimations.at(i);
+ int timeToFinish;
+
+ if (animation->direction() == QAbstractAnimation::Forward)
+ timeToFinish = animation->totalDuration() - QAbstractAnimationPrivate::get(animation)->totalCurrentTime;
+ else
+ timeToFinish = QAbstractAnimationPrivate::get(animation)->totalCurrentTime;
+
+ if (timeToFinish < closestTimeToFinish)
+ closestTimeToFinish = timeToFinish;
+ }
+ return closestTimeToFinish;
+}
+
void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState)
{
Q_Q(QAbstractAnimation);
@@ -270,7 +358,7 @@ void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState)
//here we reset the time if needed
//we don't call setCurrentTime because this might change the way the animation
//behaves: changing the state or changing the current value
- totalCurrentTime = currentTime =(direction == QAbstractAnimation::Forward) ?
+ totalCurrentTime = currentTime = (direction == QAbstractAnimation::Forward) ?
0 : (loopCount == -1 ? q->duration() : q->totalDuration());
}
@@ -292,23 +380,31 @@ void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState)
switch (state) {
case QAbstractAnimation::Paused:
- q->setCurrentTime(currentTime);
+ if (hasRegisteredTimer)
+ // currentTime needs to be updated if pauseTimer is active
+ QUnifiedTimer::instance()->ensureTimerUpdate(q);
if (!guard)
return;
QUnifiedTimer::instance()->unregisterAnimation(q);
break;
case QAbstractAnimation::Running:
- // this ensures that the value is updated now that the animation is running
- if (oldState == QAbstractAnimation::Stopped) {
- q->setCurrentTime(currentTime);
- if (!guard)
- return;
- }
+ {
+ bool isTopLevel = !group || group->state() == QAbstractAnimation::Stopped;
+
+ // this ensures that the value is updated now that the animation is running
+ if (oldState == QAbstractAnimation::Stopped) {
+ if (isTopLevel)
+ // currentTime needs to be updated if pauseTimer is active
+ QUnifiedTimer::instance()->ensureTimerUpdate(q);
+ if (!guard)
+ return;
+ }
- if (state == QAbstractAnimation::Running) {
- // Register timer if our parent is not running
- if (!group || group->state() == QAbstractAnimation::Stopped)
- QUnifiedTimer::instance()->registerAnimation(q);
+ // test needed in case we stop in the setCurrentTime inside ensureTimerUpdate (zero duration)
+ if (state == QAbstractAnimation::Running) {
+ // register timer if our parent is not running
+ QUnifiedTimer::instance()->registerAnimation(q, isTopLevel);
+ }
}
break;
case QAbstractAnimation::Stopped:
@@ -453,7 +549,6 @@ void QAbstractAnimation::setDirection(Direction direction)
if (d->direction == direction)
return;
- d->direction = direction;
if (state() == Stopped) {
if (direction == Backward) {
d->currentTime = duration();
@@ -463,7 +558,19 @@ void QAbstractAnimation::setDirection(Direction direction)
d->currentLoop = 0;
}
}
+
+ // the commands order below is important: first we need to setCurrentTime with the old direction,
+ // then update the direction on this and all children and finally restart the pauseTimer if needed
+ if (d->hasRegisteredTimer)
+ QUnifiedTimer::instance()->ensureTimerUpdate(this);
+
+ d->direction = direction;
updateDirection(direction);
+
+ if (d->hasRegisteredTimer)
+ // needed to update the timer interval in case of a pause animation
+ QUnifiedTimer::instance()->restartAnimationTimer();
+
emit directionChanged(direction);
}
@@ -660,7 +767,7 @@ void QAbstractAnimation::stop()
/*!
Pauses the animation. When the animation is paused, state() returns Paused.
- The value of currentTime will remain unchanged until resume() or start()
+ The value of currentTime will remain unchanged until resume() or start()
is called. If you want to continue from the current time, call resume().
\sa start(), state(), resume()
diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h
index 8066d32..bef0499 100644
--- a/src/corelib/animation/qabstractanimation_p.h
+++ b/src/corelib/animation/qabstractanimation_p.h
@@ -70,12 +70,14 @@ public:
QAbstractAnimationPrivate()
: state(QAbstractAnimation::Stopped),
direction(QAbstractAnimation::Forward),
- deleteWhenStopped(false),
totalCurrentTime(0),
currentTime(0),
loopCount(1),
currentLoop(0),
+ deleteWhenStopped(false),
hasRegisteredTimer(false),
+ isPause(false),
+ isGroup(false),
group(0)
{
}
@@ -89,7 +91,6 @@ public:
QAbstractAnimation::State state;
QAbstractAnimation::Direction direction;
- bool deleteWhenStopped;
void setState(QAbstractAnimation::State state);
int totalCurrentTime;
@@ -97,7 +98,10 @@ public:
int loopCount;
int currentLoop;
+ bool deleteWhenStopped;
bool hasRegisteredTimer;
+ bool isPause;
+ bool isGroup;
QAnimationGroup *group;
@@ -115,14 +119,14 @@ public:
//XXX this is needed by dui
static Q_CORE_EXPORT QUnifiedTimer *instance();
- void registerAnimation(QAbstractAnimation *animation);
+ void registerAnimation(QAbstractAnimation *animation, bool isTopLevel);
void unregisterAnimation(QAbstractAnimation *animation);
//defines the timing interval. Default is DEFAULT_TIMER_INTERVAL
void setTimingInterval(int interval)
{
timingInterval = interval;
- if (animationTimer.isActive()) {
+ if (animationTimer.isActive() && !isPauseTimerActive) {
//we changed the timing interval
animationTimer.start(timingInterval, this);
}
@@ -134,21 +138,46 @@ public:
*/
void setConsistentTiming(bool consistent) { consistentTiming = consistent; }
+ /*
+ this is used for updating the currentTime of all animations in case the pause
+ timer is active or, otherwise, only of the animation passed as parameter.
+ */
+ void ensureTimerUpdate(QAbstractAnimation *animation);
+
+ /*
+ this will evaluate the need of restarting the pause timer in case there is still
+ some pause animations running.
+ */
+ void restartAnimationTimer();
protected:
void timerEvent(QTimerEvent *);
private:
- // timer used for all active animations
+ // timer used for all active (running) animations
QBasicTimer animationTimer;
- // timer used to delay the check if we should start/stop the global timer
+ // timer used to delay the check if we should start/stop the animation timer
QBasicTimer startStopAnimationTimer;
+
QTime time;
int lastTick;
int timingInterval;
int currentAnimationIdx;
bool consistentTiming;
+ // bool to indicate that only pause animations are active
+ bool isPauseTimerActive;
+
QList<QAbstractAnimation*> animations, animationsToStart;
+
+ // this is the count of running animations that are not a group neither a pause animation
+ int runningLeafAnimations;
+ QList<QAbstractAnimation*> runningPauseAnimations;
+
+ void registerRunningAnimation(QAbstractAnimation *animation);
+ void unregisterRunningAnimation(QAbstractAnimation *animation);
+
+ void updateAnimationsTime();
+ int closestPauseAnimationTimeToFinish();
};
QT_END_NAMESPACE
diff --git a/src/corelib/animation/qanimationgroup_p.h b/src/corelib/animation/qanimationgroup_p.h
index 45eab58..bb1cfb3 100644
--- a/src/corelib/animation/qanimationgroup_p.h
+++ b/src/corelib/animation/qanimationgroup_p.h
@@ -68,7 +68,9 @@ class QAnimationGroupPrivate : public QAbstractAnimationPrivate
Q_DECLARE_PUBLIC(QAnimationGroup)
public:
QAnimationGroupPrivate()
- { }
+ {
+ isGroup = true;
+ }
virtual void animationInsertedAt(int index) { Q_UNUSED(index) };
virtual void animationRemovedAt(int index);
diff --git a/src/corelib/animation/qpauseanimation.cpp b/src/corelib/animation/qpauseanimation.cpp
index 2fd12aa..d90f001 100644
--- a/src/corelib/animation/qpauseanimation.cpp
+++ b/src/corelib/animation/qpauseanimation.cpp
@@ -75,6 +75,7 @@ class QPauseAnimationPrivate : public QAbstractAnimationPrivate
public:
QPauseAnimationPrivate() : QAbstractAnimationPrivate(), duration(0)
{
+ isPause = true;
}
int duration;
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index f3ecdae..60da6c7 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -234,6 +234,7 @@ SUBDIRS += \
qpainterpath \
qpalette \
qparallelanimationgroup \
+ qpauseanimation \
qpathclipper \
qpen \
qpicture \
diff --git a/tests/auto/qpauseanimation/qpauseanimation.pro b/tests/auto/qpauseanimation/qpauseanimation.pro
new file mode 100644
index 0000000..4599cf0
--- /dev/null
+++ b/tests/auto/qpauseanimation/qpauseanimation.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+QT = core gui
+SOURCES += tst_qpauseanimation.cpp
+
+
diff --git a/tests/auto/qpauseanimation/tst_qpauseanimation.cpp b/tests/auto/qpauseanimation/tst_qpauseanimation.cpp
new file mode 100644
index 0000000..0c742af
--- /dev/null
+++ b/tests/auto/qpauseanimation/tst_qpauseanimation.cpp
@@ -0,0 +1,392 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <QtCore/qpauseanimation.h>
+#include <QtCore/qpropertyanimation.h>
+#include <QtCore/qsequentialanimationgroup.h>
+
+#include <private/qabstractanimation_p.h>
+
+//TESTED_CLASS=QPauseAnimation
+//TESTED_FILES=
+
+class TestablePauseAnimation : public QPauseAnimation
+{
+ Q_OBJECT
+public:
+ TestablePauseAnimation(QObject *parent = 0)
+ : QPauseAnimation(parent),
+ m_updateCurrentTimeCount(0)
+ {
+ }
+
+ int m_updateCurrentTimeCount;
+protected:
+ void updateCurrentTime(int currentTime)
+ {
+ //qDebug() << this << "update current time: " << currentTime;
+ QPauseAnimation::updateCurrentTime(currentTime);
+ ++m_updateCurrentTimeCount;
+ }
+};
+
+class tst_QPauseAnimation : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QPauseAnimation();
+ virtual ~tst_QPauseAnimation();
+
+public Q_SLOTS:
+ void init();
+ void cleanup();
+
+private slots:
+ void changeDirectionWhileRunning();
+ void noTimerUpdates_data();
+ void noTimerUpdates();
+ void mulitplePauseAnimations();
+ void pauseAndPropertyAnimations();
+ void pauseResume();
+ void sequentialPauseGroup();
+ void sequentialGroupWithPause();
+ void multipleSequentialGroups();
+ void zeroDuration();
+};
+
+tst_QPauseAnimation::tst_QPauseAnimation()
+{
+}
+
+tst_QPauseAnimation::~tst_QPauseAnimation()
+{
+}
+
+void tst_QPauseAnimation::init()
+{
+ qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State");
+ qRegisterMetaType<QAbstractAnimation::DeletionPolicy>("QAbstractAnimation::DeletionPolicy");
+}
+
+void tst_QPauseAnimation::cleanup()
+{
+}
+
+void tst_QPauseAnimation::changeDirectionWhileRunning()
+{
+ QUnifiedTimer *timer = QUnifiedTimer::instance();
+ timer->setConsistentTiming(true);
+
+ TestablePauseAnimation animation;
+ animation.setDuration(400);
+ animation.start();
+ QTest::qWait(100);
+ QVERIFY(animation.state() == QAbstractAnimation::Running);
+ animation.setDirection(QAbstractAnimation::Backward);
+ QTest::qWait(animation.totalDuration() + 50);
+ QVERIFY(animation.state() == QAbstractAnimation::Stopped);
+
+ timer->setConsistentTiming(false);
+}
+
+void tst_QPauseAnimation::noTimerUpdates_data()
+{
+ QTest::addColumn<int>("duration");
+ QTest::addColumn<int>("loopCount");
+
+ QTest::newRow("0") << 200 << 1;
+ QTest::newRow("1") << 160 << 1;
+ QTest::newRow("2") << 160 << 2;
+ QTest::newRow("3") << 200 << 3;
+}
+
+void tst_QPauseAnimation::noTimerUpdates()
+{
+ QUnifiedTimer *timer = QUnifiedTimer::instance();
+ timer->setConsistentTiming(true);
+
+ QFETCH(int, duration);
+ QFETCH(int, loopCount);
+
+ TestablePauseAnimation animation;
+ animation.setDuration(duration);
+ animation.setLoopCount(loopCount);
+ animation.start();
+ QTest::qWait(animation.totalDuration() + 100);
+ QVERIFY(animation.state() == QAbstractAnimation::Stopped);
+ QCOMPARE(animation.m_updateCurrentTimeCount, 2);
+
+ timer->setConsistentTiming(false);
+}
+
+void tst_QPauseAnimation::mulitplePauseAnimations()
+{
+ QUnifiedTimer *timer = QUnifiedTimer::instance();
+ timer->setConsistentTiming(true);
+
+ TestablePauseAnimation animation;
+ animation.setDuration(200);
+
+ TestablePauseAnimation animation2;
+ animation2.setDuration(800);
+
+ animation.start();
+ animation2.start();
+ QTest::qWait(animation.totalDuration() + 100);
+ QVERIFY(animation.state() == QAbstractAnimation::Stopped);
+ QVERIFY(animation2.state() == QAbstractAnimation::Running);
+ QCOMPARE(animation.m_updateCurrentTimeCount, 2);
+ QCOMPARE(animation2.m_updateCurrentTimeCount, 2);
+
+ QTest::qWait(550);
+ QVERIFY(animation2.state() == QAbstractAnimation::Stopped);
+ QCOMPARE(animation2.m_updateCurrentTimeCount, 3);
+
+ timer->setConsistentTiming(false);
+}
+
+void tst_QPauseAnimation::pauseAndPropertyAnimations()
+{
+ QUnifiedTimer *timer = QUnifiedTimer::instance();
+ timer->setConsistentTiming(true);
+
+ TestablePauseAnimation pause;
+ pause.setDuration(200);
+
+ QObject o;
+ o.setProperty("ole", 42);
+
+ QPropertyAnimation animation(&o, "ole");
+ animation.setEndValue(43);
+
+ pause.start();
+
+ QTest::qWait(100);
+ animation.start();
+
+ QVERIFY(animation.state() == QAbstractAnimation::Running);
+ QVERIFY(pause.state() == QAbstractAnimation::Running);
+ QCOMPARE(pause.m_updateCurrentTimeCount, 2);
+
+ QTest::qWait(animation.totalDuration() + 100);
+
+ QVERIFY(animation.state() == QAbstractAnimation::Stopped);
+ QVERIFY(pause.state() == QAbstractAnimation::Stopped);
+ QVERIFY(pause.m_updateCurrentTimeCount > 3);
+
+ timer->setConsistentTiming(false);
+}
+
+void tst_QPauseAnimation::pauseResume()
+{
+ TestablePauseAnimation animation;
+ animation.setDuration(400);
+ animation.start();
+ QVERIFY(animation.state() == QAbstractAnimation::Running);
+ QTest::qWait(200);
+ animation.pause();
+ QVERIFY(animation.state() == QAbstractAnimation::Paused);
+ animation.start();
+ QTest::qWait(250);
+ QVERIFY(animation.state() == QAbstractAnimation::Stopped);
+ QCOMPARE(animation.m_updateCurrentTimeCount, 3);
+}
+
+void tst_QPauseAnimation::sequentialPauseGroup()
+{
+ QSequentialAnimationGroup group;
+
+ TestablePauseAnimation animation1(&group);
+ animation1.setDuration(200);
+ TestablePauseAnimation animation2(&group);
+ animation2.setDuration(200);
+ TestablePauseAnimation animation3(&group);
+ animation3.setDuration(200);
+
+ group.start();
+
+ QVERIFY(group.state() == QAbstractAnimation::Running);
+ QVERIFY(animation1.state() == QAbstractAnimation::Running);
+ QVERIFY(animation2.state() == QAbstractAnimation::Stopped);
+ QVERIFY(animation3.state() == QAbstractAnimation::Stopped);
+
+ QTest::qWait(250);
+
+ QVERIFY(group.state() == QAbstractAnimation::Running);
+ QVERIFY(animation1.state() == QAbstractAnimation::Stopped);
+ QCOMPARE(&animation2, group.currentAnimation());
+ QVERIFY(animation2.state() == QAbstractAnimation::Running);
+ QVERIFY(animation3.state() == QAbstractAnimation::Stopped);
+
+ QTest::qWait(250);
+
+ QVERIFY(group.state() == QAbstractAnimation::Running);
+ QVERIFY(animation1.state() == QAbstractAnimation::Stopped);
+ QVERIFY(animation2.state() == QAbstractAnimation::Stopped);
+ QCOMPARE(&animation3, group.currentAnimation());
+ QVERIFY(animation3.state() == QAbstractAnimation::Running);
+
+ QTest::qWait(250);
+
+ QVERIFY(group.state() == QAbstractAnimation::Stopped);
+ QVERIFY(animation1.state() == QAbstractAnimation::Stopped);
+ QVERIFY(animation2.state() == QAbstractAnimation::Stopped);
+ QVERIFY(animation3.state() == QAbstractAnimation::Stopped);
+
+ QCOMPARE(animation1.m_updateCurrentTimeCount, 2);
+ QCOMPARE(animation2.m_updateCurrentTimeCount, 2);
+ QCOMPARE(animation3.m_updateCurrentTimeCount, 2);
+}
+
+void tst_QPauseAnimation::sequentialGroupWithPause()
+{
+ QSequentialAnimationGroup group;
+
+ QObject o;
+ o.setProperty("ole", 42);
+
+ QPropertyAnimation animation(&o, "ole", &group);
+ animation.setEndValue(43);
+ TestablePauseAnimation pause(&group);
+ pause.setDuration(250);
+
+ group.start();
+
+ QVERIFY(group.state() == QAbstractAnimation::Running);
+ QVERIFY(animation.state() == QAbstractAnimation::Running);
+ QVERIFY(pause.state() == QAbstractAnimation::Stopped);
+
+ QTest::qWait(300);
+
+ QVERIFY(group.state() == QAbstractAnimation::Running);
+ QVERIFY(animation.state() == QAbstractAnimation::Stopped);
+ QCOMPARE(&pause, group.currentAnimation());
+ QVERIFY(pause.state() == QAbstractAnimation::Running);
+
+ QTest::qWait(300);
+
+ QVERIFY(group.state() == QAbstractAnimation::Stopped);
+ QVERIFY(animation.state() == QAbstractAnimation::Stopped);
+ QVERIFY(pause.state() == QAbstractAnimation::Stopped);
+
+ QCOMPARE(pause.m_updateCurrentTimeCount, 2);
+}
+
+void tst_QPauseAnimation::multipleSequentialGroups()
+{
+ QUnifiedTimer *timer = QUnifiedTimer::instance();
+ timer->setConsistentTiming(true);
+
+ QParallelAnimationGroup group;
+ group.setLoopCount(2);
+
+ QSequentialAnimationGroup subgroup1(&group);
+
+ QObject o;
+ o.setProperty("ole", 42);
+
+ QPropertyAnimation animation(&o, "ole", &subgroup1);
+ animation.setEndValue(43);
+ animation.setDuration(300);
+ TestablePauseAnimation pause(&subgroup1);
+ pause.setDuration(200);
+
+ QSequentialAnimationGroup subgroup2(&group);
+
+ o.setProperty("ole2", 42);
+ QPropertyAnimation animation2(&o, "ole2", &subgroup2);
+ animation2.setEndValue(43);
+ animation2.setDuration(200);
+ TestablePauseAnimation pause2(&subgroup2);
+ pause2.setDuration(250);
+
+ QSequentialAnimationGroup subgroup3(&group);
+
+ TestablePauseAnimation pause3(&subgroup3);
+ pause3.setDuration(400);
+
+ o.setProperty("ole3", 42);
+ QPropertyAnimation animation3(&o, "ole3", &subgroup3);
+ animation3.setEndValue(43);
+ animation3.setDuration(200);
+
+ QSequentialAnimationGroup subgroup4(&group);
+
+ TestablePauseAnimation pause4(&subgroup4);
+ pause4.setDuration(310);
+
+ TestablePauseAnimation pause5(&subgroup4);
+ pause5.setDuration(60);
+
+ group.start();
+
+ QVERIFY(group.state() == QAbstractAnimation::Running);
+ QVERIFY(subgroup1.state() == QAbstractAnimation::Running);
+ QVERIFY(subgroup2.state() == QAbstractAnimation::Running);
+ QVERIFY(subgroup3.state() == QAbstractAnimation::Running);
+ QVERIFY(subgroup4.state() == QAbstractAnimation::Running);
+
+ QTest::qWait(group.totalDuration() + 100);
+
+ QVERIFY(group.state() == QAbstractAnimation::Stopped);
+ QVERIFY(subgroup1.state() == QAbstractAnimation::Stopped);
+ QVERIFY(subgroup2.state() == QAbstractAnimation::Stopped);
+ QVERIFY(subgroup3.state() == QAbstractAnimation::Stopped);
+ QVERIFY(subgroup4.state() == QAbstractAnimation::Stopped);
+
+ QCOMPARE(pause5.m_updateCurrentTimeCount, 4);
+
+ timer->setConsistentTiming(false);
+}
+
+void tst_QPauseAnimation::zeroDuration()
+{
+ TestablePauseAnimation animation;
+ animation.start();
+ QTest::qWait(animation.totalDuration() + 100);
+ QVERIFY(animation.state() == QAbstractAnimation::Stopped);
+ QCOMPARE(animation.m_updateCurrentTimeCount, 1);
+}
+
+QTEST_MAIN(tst_QPauseAnimation)
+#include "tst_qpauseanimation.moc"