From eae8fb85997d82ecec0743ba3e470681129bff41 Mon Sep 17 00:00:00 2001 From: Qt by Nokia Date: Wed, 27 Apr 2011 14:13:26 +0200 Subject: Initial import from qtquick2. Branched from the monolithic repo, Qt qtquick2 branch, at commit a4a585d2ee907746682846ae6e8a48e19deef469 --- src/corelib/animation/qabstractanimation.cpp | 56 +++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 5 deletions(-) (limited to 'src/corelib/animation/qabstractanimation.cpp') diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 602cf8a6fd..f399d7c4cf 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -260,7 +260,8 @@ void QUnifiedTimer::restartAnimationTimer() } else if (!driver->isRunning() || isPauseTimerActive) { driver->start(); isPauseTimerActive = false; - } + } else if (runningLeafAnimations == 0) + driver->stop(); } void QUnifiedTimer::setTimingInterval(int interval) @@ -389,19 +390,49 @@ int QUnifiedTimer::closestPauseAnimationTimeToFinish() return closestTimeToFinish; } + void QUnifiedTimer::installAnimationDriver(QAnimationDriver *d) { - if (driver->isRunning()) { - qWarning("QUnifiedTimer: Cannot change animation driver while animations are running"); + if (driver != &defaultDriver) { + qWarning("QUnifiedTimer: animation driver already installed..."); return; } - if (driver && driver != &defaultDriver) - delete driver; + if (driver->isRunning()) { + driver->stop(); + d->start(); + } driver = d; + +} + + +void QUnifiedTimer::uninstallAnimationDriver(QAnimationDriver *d) +{ + if (driver != d) { + qWarning("QUnifiedTimer: trying to uninstall a driver that is not installed..."); + return; + } + + driver = &defaultDriver; + + if (d->isRunning()) { + d->stop(); + driver->start(); + } } +/*! + Returns true if \a d is the currently installed animation driver + and is not the default animation driver (which can never be uninstalled). +*/ +bool QUnifiedTimer::canUninstallAnimationDriver(QAnimationDriver *d) +{ + return d == driver && driver != &defaultDriver; +} + + /*! \class QAnimationDriver @@ -424,6 +455,12 @@ QAnimationDriver::QAnimationDriver(QAnimationDriverPrivate &dd, QObject *parent) { } +QAnimationDriver::~QAnimationDriver() +{ + QUnifiedTimer *timer = QUnifiedTimer::instance(true); + if (timer->canUninstallAnimationDriver(this)) + uninstall(); +} /*! Advances the animation based on the current time. This function should @@ -453,6 +490,15 @@ void QAnimationDriver::install() timer->installAnimationDriver(this); } +/*! + Uninstalls this animation driver. + */ +void QAnimationDriver::uninstall() +{ + QUnifiedTimer *timer = QUnifiedTimer::instance(true); + timer->uninstallAnimationDriver(this); +} + bool QAnimationDriver::isRunning() const { return d_func()->running; -- cgit v1.2.3