summaryrefslogtreecommitdiffstats
path: root/src/corelib/animation/qabstractanimation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/animation/qabstractanimation.cpp')
-rw-r--r--src/corelib/animation/qabstractanimation.cpp56
1 files changed, 51 insertions, 5 deletions
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,20 +390,50 @@ 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
\brief The QAnimationDriver class is used to exchange the mechanism that drives animations.
@@ -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;