diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-11-30 01:29:39 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-11-30 01:30:36 (GMT) |
commit | 68e3cab8a8183a5a88e5be092471a05692e05afe (patch) | |
tree | be1dabee49f3d8444298778fd440daa5a2a7c052 /src/declarative/util/qmlbehavior.cpp | |
parent | 85b3e8fab4a644f94a2953885f1e68369b070e64 (diff) | |
download | Qt-68e3cab8a8183a5a88e5be092471a05692e05afe.zip Qt-68e3cab8a8183a5a88e5be092471a05692e05afe.tar.gz Qt-68e3cab8a8183a5a88e5be092471a05692e05afe.tar.bz2 |
Support disabling a Behavior.
Diffstat (limited to 'src/declarative/util/qmlbehavior.cpp')
-rw-r--r-- | src/declarative/util/qmlbehavior.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/declarative/util/qmlbehavior.cpp b/src/declarative/util/qmlbehavior.cpp index 711c70d..23d3838 100644 --- a/src/declarative/util/qmlbehavior.cpp +++ b/src/declarative/util/qmlbehavior.cpp @@ -55,18 +55,21 @@ class QmlBehaviorPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QmlBehavior) public: - QmlBehaviorPrivate() : animation(0) {} + QmlBehaviorPrivate() : animation(0), enabled(true) {} QmlMetaProperty property; QVariant currentValue; QmlAbstractAnimation *animation; + bool enabled; }; /*! \qmlclass Behavior QmlBehavior \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: + Behaviors provide one way to specify \l{qmlanimation.html}{animations} in QML. + + In the example below, the rect will use a bounce easing curve over 200 millisecond for any changes to its y property: \code Rectangle { width: 20; height: 20 @@ -80,6 +83,9 @@ public: } } \endcode + + Currently only a single Behavior may be specified for a property; + this Behavior can be enabled and disabled via the \l{enabled} property. */ @@ -118,10 +124,32 @@ void QmlBehavior::setAnimation(QmlAbstractAnimation *animation) d->animation->setTarget(d->property); } +/*! + \qmlproperty bool Behavior::enabled + Whether the Behavior will be triggered when the property it is tracking changes. + + By default a Behavior is enabled. +*/ + +bool QmlBehavior::enabled() const +{ + Q_D(const QmlBehavior); + return d->enabled; +} + +void QmlBehavior::setEnabled(bool enabled) +{ + Q_D(QmlBehavior); + if (d->enabled == enabled) + return; + d->enabled = enabled; + emit enabledChanged(); +} + void QmlBehavior::write(const QVariant &value) { Q_D(QmlBehavior); - if (!d->animation) { + if (!d->animation || !d->enabled) { d->property.write(value, QmlMetaProperty::BypassInterceptor | QmlMetaProperty::DontRemoveBinding); return; } |