aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/util
diff options
context:
space:
mode:
authorCharles Yin <charles.yin@nokia.com>2012-05-17 14:43:43 +1000
committerQt by Nokia <qt-info@nokia.com>2012-05-23 05:28:00 +0200
commit14ac380da38388829738910e96dcc5dbb35a448c (patch)
tree7c8bb30f240d3b35e98356899a98418022a3c4e0 /src/quick/util
parent3765c84723738f736dc48a1e3aaf13991198818a (diff)
Add completeToBeginning()/completeToEnd() to animation controller
Change-Id: I1abac96754cc82c8e0e00c58a27c09b68c5075c1 Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'src/quick/util')
-rw-r--r--src/quick/util/qquickanimationcontroller.cpp92
-rw-r--r--src/quick/util/qquickanimationcontroller_p.h2
2 files changed, 93 insertions, 1 deletions
diff --git a/src/quick/util/qquickanimationcontroller.cpp b/src/quick/util/qquickanimationcontroller.cpp
index 2b5d174caa..52a58339a6 100644
--- a/src/quick/util/qquickanimationcontroller.cpp
+++ b/src/quick/util/qquickanimationcontroller.cpp
@@ -46,12 +46,15 @@
QT_BEGIN_NAMESPACE
-class QQuickAnimationControllerPrivate : public QObjectPrivate
+class QQuickAnimationControllerPrivate : public QObjectPrivate, QAnimationJobChangeListener
{
Q_DECLARE_PUBLIC(QQuickAnimationController)
public:
QQuickAnimationControllerPrivate()
: progress(0.0), animation(0), animationInstance(0), finalized(false) {}
+ virtual void animationFinished(QAbstractAnimationJob *job);
+ virtual void animationCurrentTimeChanged(QAbstractAnimationJob *job, int currentTime);
+
qreal progress;
QQuickAbstractAnimation *animation;
@@ -60,6 +63,34 @@ public:
};
+void QQuickAnimationControllerPrivate::animationFinished(QAbstractAnimationJob *job)
+{
+ Q_Q(QQuickAnimationController);
+ Q_ASSERT(animationInstance && animationInstance == job);
+
+ animationInstance->removeAnimationChangeListener(this, QAbstractAnimationJob::Completion | QAbstractAnimationJob::CurrentTime);
+
+ if (animationInstance->direction() == QAbstractAnimationJob::Forward && progress != 1) {
+ progress = 1;
+ emit q->progressChanged();
+ } else if (animationInstance->direction() == QAbstractAnimationJob::Backward && progress != 0) {
+ progress = 0;
+ emit q->progressChanged();
+ }
+
+}
+
+void QQuickAnimationControllerPrivate::animationCurrentTimeChanged(QAbstractAnimationJob *job, int currentTime)
+{
+ Q_Q(QQuickAnimationController);
+ Q_ASSERT(animationInstance && animationInstance == job);
+ const qreal newProgress = currentTime * 1.0 / animationInstance->duration();
+ if (progress != newProgress) {
+ progress = newProgress;
+ emit q->progressChanged();
+ }
+}
+
/*!
\qmlclass AnimationController QQuickAnimationController
\inqmlmodule QtQuick 2
@@ -200,6 +231,65 @@ void QQuickAnimationController::componentFinalized()
reload();
}
+/*!
+ \qmlmethod QtQuick2::AnimationController::completeToBeginning()
+ \brief Finishes running the controlled animation in a backwards direction.
+
+ After calling this method, the animation runs normally from the current progress point
+ in a backwards direction to the beginning state.
+
+ The animation controller's progress value will be automatically updated while the animation is running.
+
+ \sa completeToEnd(), progress()
+*/
+void QQuickAnimationController::completeToBeginning()
+{
+ Q_D(QQuickAnimationController);
+ if (!d->animationInstance)
+ return;
+
+ if (d->progress == 0)
+ return;
+
+ d->animationInstance->addAnimationChangeListener(d, QAbstractAnimationJob::Completion | QAbstractAnimationJob::CurrentTime);
+ d->animationInstance->setDirection(QAbstractAnimationJob::Backward);
+
+ //Disable and then enable user control to trigger the animation instance's state change
+ d->animationInstance->setDisableUserControl();
+ d->animationInstance->setEnableUserControl();
+ d->animationInstance->start();
+}
+
+/*!
+ \qmlmethod QtQuick2::AnimationController::completeToEnd()
+ \brief Finishes running the controlled animation in a forwards direction.
+
+ After calling this method, the animation runs normally from the current progress point
+ in a forwards direction to the end state.
+
+ The animation controller's progress value will be automatically updated while the animation is running.
+
+ \sa completeToBeginning(), progress()
+*/
+void QQuickAnimationController::completeToEnd()
+{
+ Q_D(QQuickAnimationController);
+ if (!d->animationInstance)
+ return;
+
+ if (d->progress == 1)
+ return;
+
+ d->animationInstance->addAnimationChangeListener(d, QAbstractAnimationJob::Completion | QAbstractAnimationJob::CurrentTime);
+ d->animationInstance->setDirection(QAbstractAnimationJob::Forward);
+
+ //Disable and then enable user control to trigger the animation instance's state change
+ d->animationInstance->setDisableUserControl();
+ d->animationInstance->setEnableUserControl();
+ d->animationInstance->start();
+}
+
+
QT_END_NAMESPACE
diff --git a/src/quick/util/qquickanimationcontroller_p.h b/src/quick/util/qquickanimationcontroller_p.h
index 2b2b2a84ec..2813bf2bd9 100644
--- a/src/quick/util/qquickanimationcontroller_p.h
+++ b/src/quick/util/qquickanimationcontroller_p.h
@@ -80,6 +80,8 @@ Q_SIGNALS:
void animationChanged();
public Q_SLOTS:
void reload();
+ void completeToBeginning();
+ void completeToEnd();
private Q_SLOTS:
void componentFinalized();
void updateProgress();