summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-06-24 06:40:12 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-06-24 06:40:12 (GMT)
commitd0f83cb45f27b2814326344ded548a02c2ebe583 (patch)
tree70eb73dbe90e6d84e6f547748efe97edd0b5ad91
parentb63f5cf3ba74acc88ff816f5bf08767a7e4a6b67 (diff)
downloadQt-d0f83cb45f27b2814326344ded548a02c2ebe583.zip
Qt-d0f83cb45f27b2814326344ded548a02c2ebe583.tar.gz
Qt-d0f83cb45f27b2814326344ded548a02c2ebe583.tar.bz2
Add pause/resume functionality for animations.
-rw-r--r--src/declarative/util/qmlanimation.cpp62
-rw-r--r--src/declarative/util/qmlanimation.h6
-rw-r--r--src/declarative/util/qmlanimation_p.h3
3 files changed, 70 insertions, 1 deletions
diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp
index 7df249e..2a6cad9 100644
--- a/src/declarative/util/qmlanimation.cpp
+++ b/src/declarative/util/qmlanimation.cpp
@@ -255,6 +255,44 @@ void QmlAbstractAnimation::setRunning(bool r)
emit runningChanged(d->running);
}
+/*!
+ \qmlproperty bool Animation::paused
+ This property holds whether the animation is currently paused.
+
+ The \c paused property can be set to declaratively control whether or not
+ an animation is paused.
+
+ Animations can also be paused and resumed imperatively from JavaScript
+ using the \c pause() and \c resume() methods.
+
+ By default, animations are not paused.
+*/
+bool QmlAbstractAnimation::isPaused() const
+{
+ Q_D(const QmlAbstractAnimation);
+ return d->paused;
+}
+
+void QmlAbstractAnimation::setPaused(bool p)
+{
+ Q_D(QmlAbstractAnimation);
+ if (d->paused == p)
+ return;
+
+ if (d->group) {
+ qWarning("QmlAbstractAnimation: setPaused() cannot be used on non-root animation nodes");
+ return;
+ }
+
+ d->paused = p;
+ if (d->paused)
+ qtAnimation()->pause();
+ else
+ qtAnimation()->resume();
+
+ emit pausedChanged(d->running);
+}
+
void QmlAbstractAnimation::classBegin()
{
Q_D(QmlAbstractAnimation);
@@ -430,6 +468,30 @@ void QmlAbstractAnimation::start()
}
/*!
+ \qmlmethod Animation::pause()
+ \brief Pauses the animation.
+
+ If the animation is already paused, calling this method has no effect. The
+ \c paused property will be true following a call to \c pause().
+*/
+void QmlAbstractAnimation::pause()
+{
+ setPaused(true);
+}
+
+/*!
+ \qmlmethod Animation::resume()
+ \brief Resumes a paused animation.
+
+ If the animation is not paused, calling this method has no effect. The
+ \c paused property will be false following a call to \c resume().
+*/
+void QmlAbstractAnimation::resume()
+{
+ setPaused(false);
+}
+
+/*!
\qmlmethod Animation::stop()
\brief Stops the animation.
diff --git a/src/declarative/util/qmlanimation.h b/src/declarative/util/qmlanimation.h
index 5ab9dda..0452159 100644
--- a/src/declarative/util/qmlanimation.h
+++ b/src/declarative/util/qmlanimation.h
@@ -65,6 +65,7 @@ class QmlAbstractAnimation : public QmlPropertyValueSource, public QmlParserStat
Q_INTERFACES(QmlParserStatus)
Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged)
+ Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged)
Q_PROPERTY(bool finishPlaying READ finishPlaying WRITE setFinishPlaying NOTIFY finishPlayingChanged())
Q_PROPERTY(bool repeat READ repeat WRITE setRepeat NOTIFY repeatChanged)
Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged)
@@ -78,6 +79,8 @@ public:
bool isRunning() const;
void setRunning(bool);
+ bool isPaused() const;
+ void setPaused(bool);
bool finishPlaying() const;
void setFinishPlaying(bool);
bool repeat() const;
@@ -100,6 +103,7 @@ Q_SIGNALS:
void started();
void completed();
void runningChanged(bool);
+ void pausedChanged(bool);
void repeatChanged(bool);
void targetChanged(QObject *, const QString &);
void finishPlayingChanged(bool);
@@ -107,6 +111,8 @@ Q_SIGNALS:
public Q_SLOTS:
void restart();
void start();
+ void pause();
+ void resume();
void stop();
void complete();
diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h
index e5a7384..f09ab88 100644
--- a/src/declarative/util/qmlanimation_p.h
+++ b/src/declarative/util/qmlanimation_p.h
@@ -172,11 +172,12 @@ class QmlAbstractAnimationPrivate : public QObjectPrivate
Q_DECLARE_PUBLIC(QmlAbstractAnimation)
public:
QmlAbstractAnimationPrivate()
- : running(false), finishPlaying(false), repeat(false),
+ : running(false), paused(false), finishPlaying(false), repeat(false),
connectedTimeLine(false), componentComplete(true), startOnCompletion(false),
target(0), group(0) {}
bool running;
+ bool paused;
bool finishPlaying;
bool repeat;
bool connectedTimeLine;