From e0d86a3b3da044c565a34f3a66335e3e977e1d63 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 12 Jun 2009 10:56:38 +1000 Subject: Behavior fixes. You can now write x: Behavior { NumericAnimation { duration: 500 } }, rather than having to specify the target and property for the animation explicitly. Also other minor fixes. --- examples/declarative/behaviours/test.qml | 15 ++++----------- src/declarative/util/qmlanimation.cpp | 26 ++++++++++++++++++++++++-- src/declarative/util/qmlanimation.h | 7 ++++--- src/declarative/util/qmlbehaviour.cpp | 32 +++++++++++++++++++------------- src/declarative/util/qmlbehaviour.h | 6 ++---- 5 files changed, 53 insertions(+), 33 deletions(-) diff --git a/examples/declarative/behaviours/test.qml b/examples/declarative/behaviours/test.qml index bb7109e..e6a50cd 100644 --- a/examples/declarative/behaviours/test.qml +++ b/examples/declarative/behaviours/test.qml @@ -54,7 +54,7 @@ Rect { width: 100 height: 100 id: bluerect - x: Behaviour { + x: Behavior { SequentialAnimation { NumericAnimation { target: bluerect @@ -73,13 +73,9 @@ Rect { duration: 250 } } - NumericAnimation { - target: bluerect - property: "x" - duration: 500 - } + NumericAnimation { duration: 500 } } - parent: Behaviour { + parent: Behavior { SequentialAnimation { NumericAnimation { target: bluerect @@ -87,10 +83,7 @@ Rect { to: 0 duration: 150 } - SetPropertyAction { - target: bluerect - property: "parent" - } + SetPropertyAction {} NumericAnimation { target: bluerect properties: "opacity" diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index d4aea81..7df249e 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -1168,12 +1168,17 @@ void QmlSetPropertyAction::transition(QmlStateActions &actions, } }; - QStringList props = d->properties.split(QLatin1Char(',')); + QStringList props = d->properties.isEmpty() ? QStringList() : d->properties.split(QLatin1Char(',')); for (int ii = 0; ii < props.count(); ++ii) props[ii] = props.at(ii).trimmed(); if (!d->propertyName.isEmpty() && !props.contains(d->propertyName)) props.append(d->propertyName); + if (d->userProperty.isValid() && props.isEmpty() && !target()) { + props.append(d->userProperty.value.name()); + d->target = d->userProperty.value.object(); + } + QmlSetPropertyAnimationAction *data = new QmlSetPropertyAnimationAction; QSet objs; @@ -1649,12 +1654,17 @@ void QmlNumericAnimation::transition(QmlStateActions &actions, } }; - QStringList props = d->properties.split(QLatin1Char(',')); + QStringList props = d->properties.isEmpty() ? QStringList() : d->properties.split(QLatin1Char(',')); for (int ii = 0; ii < props.count(); ++ii) props[ii] = props.at(ii).trimmed(); if (!d->propertyName.isEmpty() && !props.contains(d->propertyName)) props.append(d->propertyName); + if (d->userProperty.isValid() && props.isEmpty() && !target()) { + props.append(d->userProperty.value.name()); + d->target = d->userProperty.value.object(); + } + NTransitionData *data = new NTransitionData; QSet objs; @@ -1785,6 +1795,12 @@ void QmlSequentialAnimation::transition(QmlStateActions &actions, inc = -1; from = d->animations.count() - 1; } + + //### needed for Behavior + if (d->userProperty.isValid() && d->propertyName.isEmpty() && !target()) { + for (int i = 0; i < d->animations.count(); ++i) + d->animations.at(i)->setTarget(d->userProperty); + } //XXX removing and readding isn't ideal; we do it to get around the problem mentioned below. for (int i = d->ag->animationCount()-1; i >= 0; --i) @@ -1870,6 +1886,12 @@ void QmlParallelAnimation::transition(QmlStateActions &actions, { Q_D(QmlAnimationGroup); + //### needed for Behavior + if (d->userProperty.isValid() && d->propertyName.isEmpty() && !target()) { + for (int i = 0; i < d->animations.count(); ++i) + d->animations.at(i)->setTarget(d->userProperty); + } + for (int ii = 0; ii < d->animations.count(); ++ii) { d->animations.at(ii)->transition(actions, modified, direction); } diff --git a/src/declarative/util/qmlanimation.h b/src/declarative/util/qmlanimation.h index 8b9ecc2..5ab9dda 100644 --- a/src/declarative/util/qmlanimation.h +++ b/src/declarative/util/qmlanimation.h @@ -91,6 +91,8 @@ public: QString property() const; void setProperty(const QString &); + virtual void setTarget(const QmlMetaProperty &); + void classBegin(); void componentComplete(); @@ -109,7 +111,6 @@ public Q_SLOTS: void complete(); protected: - virtual void setTarget(const QmlMetaProperty &); QmlAbstractAnimation(QmlAbstractAnimationPrivate &dd, QObject *parent); public: @@ -446,8 +447,8 @@ Q_SIGNALS: }; QML_DECLARE_TYPE(QmlVariantAnimation) -#endif // QMLANIMATION_H - QT_END_NAMESPACE QT_END_HEADER + +#endif // QMLANIMATION_H diff --git a/src/declarative/util/qmlbehaviour.cpp b/src/declarative/util/qmlbehaviour.cpp index 077f666..3617541 100644 --- a/src/declarative/util/qmlbehaviour.cpp +++ b/src/declarative/util/qmlbehaviour.cpp @@ -44,11 +44,11 @@ #include "qmltransition.h" #include "qmlbehaviour.h" #include - +#include QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(QmlBehaviour,Behaviour) +QML_DEFINE_TYPE(QmlBehaviour,Behavior) class QmlBehaviourData : public QObject { @@ -92,18 +92,21 @@ public: { QmlConcreteList::append(a); _parent->group->addAnimation(a->qtAnimation()); + if (_parent->property.isValid()) { + a->setTarget(_parent->property); + } } virtual void clear() { QmlConcreteList::clear(); } //### private: QmlBehaviourPrivate *_parent; }; AnimationList operations; - QSequentialAnimationGroup *group; + QParallelAnimationGroup *group; }; /*! - \qmlclass Behaviour QmlBehaviour - \brief The Behaviour element allows you to specify a default animation for a property change. + \qmlclass Behavior QmlBehaviour + \brief The Behavior element allows you to specify a default animation for a property change. In example below, the rect will use a bounce easing curve over 200 millisecond for any changes to its y property: \code @@ -111,7 +114,7 @@ public: width: 20; height: 20 color: "#00ff00" y: 200 //initial value - y: Behaviour { + y: Behavior { NumericAnimation { easing: "easeOutBounce(amplitude:100)" duration: 200 @@ -126,14 +129,14 @@ QmlBehaviour::QmlBehaviour(QObject *parent) { Q_D(QmlBehaviour); d->valueData = new QmlBehaviourData(this); - d->group = new QSequentialAnimationGroup(this); + d->group = new QParallelAnimationGroup(this); } /*! - \qmlproperty QVariant Behaviour::fromValue - This property holds a selector specifying a starting value for the behaviour + \qmlproperty QVariant Behavior::fromValue + This property holds a selector specifying a starting value for the behavior - If you only want the behaviour to apply when the change starts at a + If you only want the behavior to apply when the change starts at a specific value you can specify fromValue. This selector is used in conjunction with the toValue selector. */ @@ -151,10 +154,10 @@ void QmlBehaviour::setFromValue(const QVariant &v) } /*! - \qmlproperty QVariant Behaviour::toValue - This property holds a selector specifying a ending value for the behaviour + \qmlproperty QVariant Behavior::toValue + This property holds a selector specifying a ending value for the behavior - If you only want the behaviour to apply when the change ends at a + If you only want the behavior to apply when the change ends at a specific value you can specify toValue. This selector is used in conjunction with the fromValue selector. */ @@ -230,6 +233,9 @@ void QmlBehaviour::setTarget(const QmlMetaProperty &property) d->property = property; d->currentValue = property.read(); d->property.connectNotifier(this, SLOT(propertyValueChanged())); + for (int ii = 0; ii < d->operations.count(); ++ii) { + d->operations.at(ii)->setTarget(property); + } } void QmlBehaviour::classBegin() diff --git a/src/declarative/util/qmlbehaviour.h b/src/declarative/util/qmlbehaviour.h index aef53a3..7cc83b2 100644 --- a/src/declarative/util/qmlbehaviour.h +++ b/src/declarative/util/qmlbehaviour.h @@ -88,10 +88,8 @@ private Q_SLOTS: }; QML_DECLARE_TYPE(QmlBehaviour) - -#endif // QMLBEHAVIOUR_H - - QT_END_NAMESPACE QT_END_HEADER + +#endif // QMLBEHAVIOUR_H -- cgit v0.12