From 14ac380da38388829738910e96dcc5dbb35a448c Mon Sep 17 00:00:00 2001 From: Charles Yin Date: Thu, 17 May 2012 14:43:43 +1000 Subject: Add completeToBeginning()/completeToEnd() to animation controller Change-Id: I1abac96754cc82c8e0e00c58a27c09b68c5075c1 Reviewed-by: Michael Brasser --- src/qml/animations/qabstractanimationjob.cpp | 35 +++++++++++++++++++++++++--- src/qml/animations/qabstractanimationjob_p.h | 8 +++++-- 2 files changed, 38 insertions(+), 5 deletions(-) (limited to 'src/qml/animations') diff --git a/src/qml/animations/qabstractanimationjob.cpp b/src/qml/animations/qabstractanimationjob.cpp index 285937db2a..52ec00e7e0 100644 --- a/src/qml/animations/qabstractanimationjob.cpp +++ b/src/qml/animations/qabstractanimationjob.cpp @@ -271,6 +271,8 @@ QAbstractAnimationJob::QAbstractAnimationJob() , m_isPause(false) , m_isGroup(false) , m_disableUserControl(false) + , m_hasCurrentTimeChangeListeners(false) + { } @@ -449,7 +451,7 @@ void QAbstractAnimationJob::setCurrentTime(int msecs) RETURN_IF_DELETED(updateCurrentTime(m_currentTime)); if (m_currentLoop != oldLoop) - currentLoopChanged(m_currentLoop); + currentLoopChanged(); // All animations are responsible for stopping the animation when their // own end state is reached; in this case the animation is time driven, @@ -458,6 +460,9 @@ void QAbstractAnimationJob::setCurrentTime(int msecs) || (m_direction == Backward && m_totalCurrentTime == 0)) { stop(); } + + if (m_hasCurrentTimeChangeListeners) + currentTimeChanged(m_currentTime); } void QAbstractAnimationJob::start() @@ -549,9 +554,8 @@ void QAbstractAnimationJob::stateChanged(QAbstractAnimationJob::State newState, } } -void QAbstractAnimationJob::currentLoopChanged(int currentLoop) +void QAbstractAnimationJob::currentLoopChanged() { - Q_UNUSED(currentLoop); for (int i = 0; i < changeListeners.count(); ++i) { const QAbstractAnimationJob::ChangeListener &change = changeListeners.at(i); if (change.types & QAbstractAnimationJob::CurrentLoop) { @@ -560,14 +564,39 @@ void QAbstractAnimationJob::currentLoopChanged(int currentLoop) } } +void QAbstractAnimationJob::currentTimeChanged(int currentTime) +{ + Q_ASSERT(m_hasCurrentTimeChangeListeners); + + for (int i = 0; i < changeListeners.count(); ++i) { + const QAbstractAnimationJob::ChangeListener &change = changeListeners.at(i); + if (change.types & QAbstractAnimationJob::CurrentTime) { + RETURN_IF_DELETED(change.listener->animationCurrentTimeChanged(this, currentTime)); + } + } +} + void QAbstractAnimationJob::addAnimationChangeListener(QAnimationJobChangeListener *listener, QAbstractAnimationJob::ChangeTypes changes) { + if (changes & QAbstractAnimationJob::CurrentTime) + m_hasCurrentTimeChangeListeners = true; + changeListeners.append(ChangeListener(listener, changes)); } void QAbstractAnimationJob::removeAnimationChangeListener(QAnimationJobChangeListener *listener, QAbstractAnimationJob::ChangeTypes changes) { + m_hasCurrentTimeChangeListeners = false; + changeListeners.removeOne(ChangeListener(listener, changes)); + + for (int i = 0; i < changeListeners.count(); ++i) { + const QAbstractAnimationJob::ChangeListener &change = changeListeners.at(i); + if (change.types & QAbstractAnimationJob::CurrentTime) { + m_hasCurrentTimeChangeListeners = true; + break; + } + } } QT_END_NAMESPACE diff --git a/src/qml/animations/qabstractanimationjob_p.h b/src/qml/animations/qabstractanimationjob_p.h index 47869826ec..e889a12aed 100644 --- a/src/qml/animations/qabstractanimationjob_p.h +++ b/src/qml/animations/qabstractanimationjob_p.h @@ -107,7 +107,8 @@ public: enum ChangeType { Completion = 0x01, StateChange = 0x02, - CurrentLoop = 0x04 + CurrentLoop = 0x04, + CurrentTime = 0x08 }; Q_DECLARE_FLAGS(ChangeTypes, ChangeType) @@ -126,8 +127,9 @@ protected: void finished(); void stateChanged(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState); - void currentLoopChanged(int currentLoop); + void currentLoopChanged(); void directionChanged(QAbstractAnimationJob::Direction); + void currentTimeChanged(int currentTime); //definition int m_loopCount; @@ -158,6 +160,7 @@ protected: bool m_isPause:1; bool m_isGroup:1; bool m_disableUserControl:1; + bool m_hasCurrentTimeChangeListeners:1; friend class QQmlAnimationTimer; friend class QAnimationGroupJob; @@ -169,6 +172,7 @@ public: virtual void animationFinished(QAbstractAnimationJob *) {} virtual void animationStateChanged(QAbstractAnimationJob *, QAbstractAnimationJob::State, QAbstractAnimationJob::State) {} virtual void animationCurrentLoopChanged(QAbstractAnimationJob *) {} + virtual void animationCurrentTimeChanged(QAbstractAnimationJob *, int) {} }; class Q_QML_PRIVATE_EXPORT QQmlAnimationTimer : public QAbstractAnimationTimer -- cgit v1.2.3