From 32898d39fbbe0939b6bb21da7f3ad725fb8e0ee3 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 16 Feb 2010 15:59:50 +1000 Subject: Minor animation class cleanup. --- src/declarative/util/qmlanimation.cpp | 44 +++++++++++++++------------------ src/declarative/util/qmlanimation_p.h | 1 - src/declarative/util/qmlanimation_p_p.h | 9 ++++--- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index e36a1cc..cdd5e9a 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -210,10 +210,16 @@ bool QmlAbstractAnimation::isRunning() const return d->running; } +//commence is called to start an animation when it is used as a +//simple animation, and not as part of a transition void QmlAbstractAnimationPrivate::commence() { Q_Q(QmlAbstractAnimation); - q->prepare(userProperty.value); + + QmlStateActions actions; + QmlMetaProperties properties; + q->transition(actions, properties, QmlAbstractAnimation::Forward); + q->qtAnimation()->start(); if (q->qtAnimation()->state() != QAbstractAnimation::Running) { running = false; @@ -313,7 +319,7 @@ void QmlAbstractAnimation::setPaused(bool p) else qtAnimation()->resume(); - emit pausedChanged(d->running); + emit pausedChanged(d->paused); } void QmlAbstractAnimation::classBegin() @@ -532,8 +538,7 @@ void QmlAbstractAnimation::complete() void QmlAbstractAnimation::setTarget(const QmlMetaProperty &p) { Q_D(QmlAbstractAnimation); - if (d->userProperty.isNull) - d->userProperty = p; + d->defaultProperty = p; if (!d->avoidPropertyValueSourceStart) setRunning(true); @@ -545,16 +550,7 @@ void QmlAbstractAnimation::setTarget(const QmlMetaProperty &p) void QmlAbstractAnimation::setDefaultTarget(const QmlMetaProperty &p) { Q_D(QmlAbstractAnimation); - d->userProperty = p; -} - -//prepare is called before an animation begins -//(when an animation is used as a simple animation, and not as part of a transition) -void QmlAbstractAnimation::prepare(QmlMetaProperty &) -{ - QmlStateActions actions; - QmlMetaProperties properties; - transition(actions, properties, QmlAbstractAnimation::Forward); + d->defaultProperty = p; } void QmlAbstractAnimation::transition(QmlStateActions &actions, @@ -1012,9 +1008,9 @@ void QmlPropertyAction::transition(QmlStateActions &actions, bool hasSelectors = !props.isEmpty() || !targets.isEmpty() || !d->exclude.isEmpty(); - if (d->userProperty.isValid() && !hasSelectors) { - props << d->userProperty.value.name(); - targets << d->userProperty.value.object(); + if (d->defaultProperty.isValid() && !hasSelectors) { + props << d->defaultProperty.name(); + targets << d->defaultProperty.object(); } QmlSetPropertyAnimationAction *data = new QmlSetPropertyAnimationAction; @@ -1467,10 +1463,10 @@ void QmlSequentialAnimation::transition(QmlStateActions &actions, from = d->animations.count() - 1; } - bool valid = d->userProperty.isValid(); + bool valid = d->defaultProperty.isValid(); for (int ii = from; ii < d->animations.count() && ii >= 0; ii += inc) { if (valid) - d->animations.at(ii)->setDefaultTarget(d->userProperty); + d->animations.at(ii)->setDefaultTarget(d->defaultProperty); d->animations.at(ii)->transition(actions, modified, direction); } } @@ -1523,10 +1519,10 @@ void QmlParallelAnimation::transition(QmlStateActions &actions, TransitionDirection direction) { Q_D(QmlAnimationGroup); - bool valid = d->userProperty.isValid(); + bool valid = d->defaultProperty.isValid(); for (int ii = 0; ii < d->animations.count(); ++ii) { if (valid) - d->animations.at(ii)->setDefaultTarget(d->userProperty); + d->animations.at(ii)->setDefaultTarget(d->defaultProperty); d->animations.at(ii)->transition(actions, modified, direction); } } @@ -2140,9 +2136,9 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions, bool hasSelectors = !props.isEmpty() || !targets.isEmpty() || !d->exclude.isEmpty(); bool useType = (props.isEmpty() && d->propertyName.isEmpty() && d->defaultToInterpolatorType) ? true : false; - if (d->userProperty.isValid() && !hasSelectors) { - props << d->userProperty.value.name(); - targets << d->userProperty.value.object(); + if (d->defaultProperty.isValid() && !hasSelectors) { + props << d->defaultProperty.name(); + targets << d->defaultProperty.object(); } PropertyUpdater *data = new PropertyUpdater; diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index cd4f575..4e8102c 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -124,7 +124,6 @@ public: virtual void transition(QmlStateActions &actions, QmlMetaProperties &modified, TransitionDirection direction); - void prepare(QmlMetaProperty &); //### make private virtual QAbstractAnimation *qtAnimation() = 0; private Q_SLOTS: diff --git a/src/declarative/util/qmlanimation_p_p.h b/src/declarative/util/qmlanimation_p_p.h index 2dc59f9..91f9f88 100644 --- a/src/declarative/util/qmlanimation_p_p.h +++ b/src/declarative/util/qmlanimation_p_p.h @@ -108,6 +108,8 @@ public: { if (state() == Running) stop(); + if (policy == DeleteWhenStopped) + delete animAction; animAction = action; policy = p; } @@ -126,12 +128,12 @@ protected: animAction = 0; } } - } else if (newState == Stopped && policy == DeleteWhenStopped) { + } /*else if (newState == Stopped && policy == DeleteWhenStopped) { if (!running) { delete animAction; animAction = 0; } - } + }*/ } private: @@ -222,9 +224,8 @@ public: void commence(); - QmlNullableValue userProperty; + QmlMetaProperty defaultProperty; - QmlMetaProperty property; QmlAnimationGroup *group; static QmlMetaProperty createProperty(QObject *obj, const QString &str, QObject *infoObj); -- cgit v0.12