summaryrefslogtreecommitdiffstats
path: root/src/corelib/animation
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 14:13:26 +0200
committeraxis <qt-info@nokia.com>2011-04-27 14:33:44 +0200
commiteae8fb85997d82ecec0743ba3e470681129bff41 (patch)
tree286a31dce764e209a1e2db556d6c78d400561a2e /src/corelib/animation
parent38be0d13830efd2d98281c645c3a60afe05ffece (diff)
Initial import from qtquick2.
Branched from the monolithic repo, Qt qtquick2 branch, at commit a4a585d2ee907746682846ae6e8a48e19deef469
Diffstat (limited to 'src/corelib/animation')
-rw-r--r--src/corelib/animation/qabstractanimation.cpp56
-rw-r--r--src/corelib/animation/qabstractanimation.h3
-rw-r--r--src/corelib/animation/qabstractanimation_p.h5
3 files changed, 59 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;
diff --git a/src/corelib/animation/qabstractanimation.h b/src/corelib/animation/qabstractanimation.h
index 0900870ce2..a0cb0f93d0 100644
--- a/src/corelib/animation/qabstractanimation.h
+++ b/src/corelib/animation/qabstractanimation.h
@@ -141,9 +141,12 @@ class Q_CORE_EXPORT QAnimationDriver : public QObject
public:
QAnimationDriver(QObject *parent = 0);
+ ~QAnimationDriver();
void advance();
+
void install();
+ void uninstall();
bool isRunning() const;
diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h
index ba92960f6b..1cba4644a8 100644
--- a/src/corelib/animation/qabstractanimation_p.h
+++ b/src/corelib/animation/qabstractanimation_p.h
@@ -180,10 +180,15 @@ public:
static void updateAnimationTimer();
void installAnimationDriver(QAnimationDriver *driver);
+ void uninstallAnimationDriver(QAnimationDriver *driver);
+ bool canUninstallAnimationDriver(QAnimationDriver *driver);
void restartAnimationTimer();
void updateAnimationsTime();
+ //useful for profiling/debugging
+ int runningAnimationCount() { return animations.count(); }
+
protected:
void timerEvent(QTimerEvent *);