\sa {QML Animation and Transitions}, {declarative/animation/states}{states example}, {qmlstates}{States}, {QtQml}
*/
-QQuickTransitionInstance::QQuickTransitionInstance()
- : m_anim(0)
-{
-}
-
-QQuickTransitionInstance::~QQuickTransitionInstance()
-{
- delete m_anim;
-}
-
-void QQuickTransitionInstance::start()
-{
- if (m_anim)
- m_anim->start();
-}
-
-void QQuickTransitionInstance::stop()
-{
- if (m_anim)
- m_anim->stop();
-}
-
-bool QQuickTransitionInstance::isRunning() const
-{
- return m_anim && m_anim->state() == QAbstractAnimationJob::Running;
-}
-
-
//ParallelAnimationWrapper allows us to do a "callback" when the animation finishes, rather than connecting
//and disconnecting signals and slots frequently
class ParallelAnimationWrapper : public QParallelAnimationGroupJob
virtual void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState);
};
-class QQuickTransitionPrivate : public QObjectPrivate
+class QQuickTransitionPrivate : public QObjectPrivate, QAnimationJobChangeListener
{
Q_DECLARE_PUBLIC(QQuickTransition)
public:
QQuickTransitionPrivate()
- : fromState(QLatin1String("*")), toState(QLatin1String("*")),
- reversed(false), reversible(false), enabled(true)
+ : fromState(QLatin1String("*")), toState(QLatin1String("*"))
+ , runningInstanceCount(0), state(QAbstractAnimationJob::Stopped)
+ , reversed(false), reversible(false), enabled(true)
{
}
+ void removeStateChangeListener(QAbstractAnimationJob *anim)
+ {
+ if (anim)
+ anim->removeAnimationChangeListener(this, QAbstractAnimationJob::StateChange);
+ }
+
QString fromState;
QString toState;
+ quint32 runningInstanceCount;
+ QAbstractAnimationJob::State state;
bool reversed;
bool reversible;
bool enabled;
+protected:
+ virtual void animationStateChanged(QAbstractAnimationJob *, QAbstractAnimationJob::State, QAbstractAnimationJob::State);
static void append_animation(QQmlListProperty<QQuickAbstractAnimation> *list, QQuickAbstractAnimation *a);
static int animation_count(QQmlListProperty<QQuickAbstractAnimation> *list);
}
}
+void QQuickTransitionPrivate::animationStateChanged(QAbstractAnimationJob *, QAbstractAnimationJob::State newState, QAbstractAnimationJob::State)
+{
+ Q_Q(QQuickTransition);
+
+ if (newState == QAbstractAnimationJob::Running) {
+ if (!runningInstanceCount)
+ emit q->runningChanged();
+ runningInstanceCount++;
+ } else if (newState == QAbstractAnimationJob::Stopped) {
+ runningInstanceCount--;
+ if (!runningInstanceCount)
+ emit q->runningChanged();
+ }
+}
+
void ParallelAnimationWrapper::updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState)
{
QParallelAnimationGroupJob::updateState(newState, oldState);
}
}
+QQuickTransitionInstance::QQuickTransitionInstance(QQuickTransitionPrivate *transition, QAbstractAnimationJob *anim)
+ : m_transition(transition)
+ , m_anim(anim)
+{
+}
+
+QQuickTransitionInstance::~QQuickTransitionInstance()
+{
+ m_transition->removeStateChangeListener(m_anim);
+ delete m_anim;
+}
+
+void QQuickTransitionInstance::start()
+{
+ if (m_anim)
+ m_anim->start();
+}
+
+void QQuickTransitionInstance::stop()
+{
+ if (m_anim)
+ m_anim->stop();
+}
+
+bool QQuickTransitionInstance::isRunning() const
+{
+ return m_anim && m_anim->state() == QAbstractAnimationJob::Running;
+}
QQuickTransition::QQuickTransition(QObject *parent)
: QObject(*(new QQuickTransitionPrivate), parent)
group->setDirection(d->reversed ? QAbstractAnimationJob::Backward : QAbstractAnimationJob::Forward);
- QQuickTransitionInstance *wrapper = new QQuickTransitionInstance;
- wrapper->m_anim = group;
+ group->addAnimationChangeListener(d, QAbstractAnimationJob::StateChange);
+ QQuickTransitionInstance *wrapper = new QQuickTransitionInstance(d, group);
return wrapper;
}
}
/*!
+ \qmlproperty bool QtQuick2::Transition::running
+
+ This property holds whether the transition is currently running.
+
+ This property is read only.
+*/
+bool QQuickTransition::running() const
+{
+ Q_D(const QQuickTransition);
+ return d->runningInstanceCount;
+}
+
+
+/*!
\qmlproperty list<Animation> QtQuick2::Transition::animations
\default
#define QQUICKTRANSITION_H
#include "qquickstate_p.h"
+#include <private/qabstractanimationjob_p.h>
#include <qqml.h>
#include <QtCore/qobject.h>
class QQuickTransitionPrivate;
class QQuickTransitionManager;
class QQuickTransition;
-class QAbstractAnimationJob;
class Q_QUICK_EXPORT QQuickTransitionInstance
{
public:
- QQuickTransitionInstance();
+ QQuickTransitionInstance(QQuickTransitionPrivate *transition, QAbstractAnimationJob *anim);
~QQuickTransitionInstance();
void start();
bool isRunning() const;
private:
+ QQuickTransitionPrivate *m_transition;
QAbstractAnimationJob *m_anim;
friend class QQuickTransition;
};
Q_PROPERTY(QString from READ fromState WRITE setFromState NOTIFY fromChanged)
Q_PROPERTY(QString to READ toState WRITE setToState NOTIFY toChanged)
Q_PROPERTY(bool reversible READ reversible WRITE setReversible NOTIFY reversibleChanged)
+ Q_PROPERTY(bool running READ running NOTIFY runningChanged)
Q_PROPERTY(QQmlListProperty<QQuickAbstractAnimation> animations READ animations)
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
Q_CLASSINFO("DefaultProperty", "animations")
bool enabled() const;
void setEnabled(bool enabled);
+ bool running() const;
+
QQmlListProperty<QQuickAbstractAnimation> animations();
QQuickTransitionInstance *prepare(QQuickStateOperation::ActionList &actions,
void toChanged();
void reversibleChanged();
void enabledChanged();
+ void runningChanged();
};
QT_END_NAMESPACE