diff options
Diffstat (limited to 'src/corelib/animation/qabstractanimation.cpp')
-rw-r--r-- | src/corelib/animation/qabstractanimation.cpp | 122 |
1 files changed, 100 insertions, 22 deletions
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 602cf8a6fd..7d74de8e44 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -201,16 +201,17 @@ void QUnifiedTimer::ensureTimerUpdate() { QUnifiedTimer *inst = QUnifiedTimer::instance(false); if (inst && inst->isPauseTimerActive) - inst->updateAnimationsTime(); + inst->updateAnimationsTime(-1); } -void QUnifiedTimer::updateAnimationsTime() +void QUnifiedTimer::updateAnimationsTime(qint64 timeStep) { //setCurrentTime can get this called again while we're the for loop. At least with pauseAnimations if(insideTick) return; - qint64 totalElapsed = time.elapsed(); + qint64 totalElapsed = timeStep >= 0 ? timeStep : time.elapsed(); + // ignore consistentTiming in case the pause timer is active int delta = (consistentTiming && !isPauseTimerActive) ? timingInterval : totalElapsed - lastTick; @@ -260,7 +261,8 @@ void QUnifiedTimer::restartAnimationTimer() } else if (!driver->isRunning() || isPauseTimerActive) { driver->start(); isPauseTimerActive = false; - } + } else if (runningLeafAnimations == 0) + driver->stop(); } void QUnifiedTimer::setTimingInterval(int interval) @@ -302,7 +304,7 @@ void QUnifiedTimer::timerEvent(QTimerEvent *event) if (event->timerId() == animationTimer.timerId()) { // update current time on all top level animations - updateAnimationsTime(); + updateAnimationsTime(-1); restartAnimationTimer(); } } @@ -389,19 +391,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,35 +456,69 @@ 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 - be continuously called by the driver while the animation is running. + Advances the animation based to the specified \a timeStep. This function should + be continuously called by the driver subclasses while the animation is running. - \internal + If \a timeStep is positive, it will be used as the current time in the + calculations; otherwise, the current clock time will be used. */ -void QAnimationDriver::advance() + +void QAnimationDriver::advanceAnimation(qint64 timeStep) { QUnifiedTimer *instance = QUnifiedTimer::instance(); // update current time on all top level animations - instance->updateAnimationsTime(); + instance->updateAnimationsTime(timeStep); instance->restartAnimationTimer(); } + +/*! + Advances the animation. This function should be continously called + by the driver while the animation is running. + */ + +void QAnimationDriver::advance() +{ + advanceAnimation(-1); +} + + + /*! Installs this animation driver. The animation driver is thread local and will only apply for the thread its installed in. - - \internal */ + void QAnimationDriver::install() { QUnifiedTimer *timer = QUnifiedTimer::instance(true); 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; @@ -463,7 +529,7 @@ void QAnimationDriver::start() { Q_D(QAnimationDriver); if (!d->running) { - started(); + emit started(); d->running = true; } } @@ -473,16 +539,28 @@ void QAnimationDriver::stop() { Q_D(QAnimationDriver); if (d->running) { - stopped(); + emit stopped(); d->running = false; } } + +/*! + \fn qint64 QAnimationDriver::elapsed() const + + Returns the number of milliseconds since the animations was started. + */ + +qint64 QAnimationDriver::elapsed() const +{ + return QUnifiedTimer::instance()->time.elapsed(); +} + /*! \fn QAnimationDriver::started() - This function is called by the animation framework to notify the driver - that it should start running. + This signal is emitted by the animation framework to notify the driver + that continous animation has started. \internal */ @@ -490,8 +568,8 @@ void QAnimationDriver::stop() /*! \fn QAnimationDriver::stopped() - This function is called by the animation framework to notify the driver - that it should stop running. + This signal is emitted by the animation framework to notify the driver + that continous animation has stopped. \internal */ |