summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/util/qmlbehavior.cpp34
-rw-r--r--src/declarative/util/qmlbehavior_p.h7
2 files changed, 38 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;
}
diff --git a/src/declarative/util/qmlbehavior_p.h b/src/declarative/util/qmlbehavior_p.h
index b61df32..581a0a8 100644
--- a/src/declarative/util/qmlbehavior_p.h
+++ b/src/declarative/util/qmlbehavior_p.h
@@ -63,6 +63,7 @@ class Q_DECLARATIVE_EXPORT QmlBehavior : public QObject, public QmlPropertyValue
Q_INTERFACES(QmlPropertyValueInterceptor)
Q_CLASSINFO("DefaultProperty", "animation")
Q_PROPERTY(QmlAbstractAnimation *animation READ animation WRITE setAnimation)
+ Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
public:
QmlBehavior(QObject *parent=0);
@@ -73,6 +74,12 @@ public:
QmlAbstractAnimation *animation();
void setAnimation(QmlAbstractAnimation *);
+
+ bool enabled() const;
+ void setEnabled(bool enabled);
+
+Q_SIGNALS:
+ void enabledChanged();
};
QT_END_NAMESPACE