diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-12-12 21:45:03 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-12-21 19:33:19 +0000 |
commit | 92dff998b3bf73ee0ad9d636454379869318975f (patch) | |
tree | 0a74f43a415594af31352f540fa2496888f508e8 /src | |
parent | fd9d88e3a9f24eb84d029fb9324b4f03ae58ffeb (diff) |
Expose the target value in Behaviors
So that nested animation can use it.
Change-Id: Ief40cda1dfe1ad9a38cf0d18fbf34456dc36e2ee
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/util/qquickbehavior.cpp | 24 | ||||
-rw-r--r-- | src/quick/util/qquickbehavior_p.h | 4 | ||||
-rw-r--r-- | src/quick/util/qquickutilmodule.cpp | 2 |
3 files changed, 26 insertions, 4 deletions
diff --git a/src/quick/util/qquickbehavior.cpp b/src/quick/util/qquickbehavior.cpp index d024c0099b..76d464e7f8 100644 --- a/src/quick/util/qquickbehavior.cpp +++ b/src/quick/util/qquickbehavior.cpp @@ -171,9 +171,28 @@ void QQuickBehavior::setEnabled(bool enabled) emit enabledChanged(); } +/*! + \qmlproperty Variant QtQuick::Behavior::targetValue + + This property holds the target value of the property being controlled by the Behavior. + This value is set by the Behavior before the animation is started. + + \since QtQuick 2.13 +*/ +QVariant QQuickBehavior::targetValue() const +{ + Q_D(const QQuickBehavior); + return d->targetValue; +} + void QQuickBehavior::write(const QVariant &value) { Q_D(QQuickBehavior); + const bool targetValueHasChanged = d->targetValue != value; + if (targetValueHasChanged) { + d->targetValue = value; + emit targetValueChanged(); // emitting the signal here should allow + } // d->enabled to change if scripted by the user. bool bypass = !d->enabled || !d->finalized || QQmlEnginePrivate::designerMode(); if (!bypass) qmlExecuteDeferred(this); @@ -181,16 +200,13 @@ void QQuickBehavior::write(const QVariant &value) if (d->animationInstance) d->animationInstance->stop(); QQmlPropertyPrivate::write(d->property, value, QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding); - d->targetValue = value; return; } bool behaviorActive = d->animation->isRunning(); - if (behaviorActive && value == d->targetValue) + if (behaviorActive && !targetValueHasChanged) return; - d->targetValue = value; - if (d->animationInstance && (d->animationInstance->duration() != -1 || d->animationInstance->isRenderThreadProxy()) diff --git a/src/quick/util/qquickbehavior_p.h b/src/quick/util/qquickbehavior_p.h index f939597d15..80a51d77af 100644 --- a/src/quick/util/qquickbehavior_p.h +++ b/src/quick/util/qquickbehavior_p.h @@ -69,6 +69,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickBehavior : public QObject, public QQmlPropert Q_CLASSINFO("DefaultProperty", "animation") Q_PROPERTY(QQuickAbstractAnimation *animation READ animation WRITE setAnimation) Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(QVariant targetValue READ targetValue NOTIFY targetValueChanged REVISION 13) Q_CLASSINFO("DeferredPropertyNames", "animation") public: @@ -84,8 +85,11 @@ public: bool enabled() const; void setEnabled(bool enabled); + QVariant targetValue() const; + Q_SIGNALS: void enabledChanged(); + void targetValueChanged(); private Q_SLOTS: void componentFinalized(); diff --git a/src/quick/util/qquickutilmodule.cpp b/src/quick/util/qquickutilmodule.cpp index 31d4d4c437..5147ebc6f6 100644 --- a/src/quick/util/qquickutilmodule.cpp +++ b/src/quick/util/qquickutilmodule.cpp @@ -135,4 +135,6 @@ void QQuickUtilModule::defineModule() qmlRegisterUncreatableType<QQuickAbstractAnimation, 12>("QtQuick", 2, 12, "Animation", QQuickAbstractAnimation::tr("Animation is an abstract class")); + // 5.13 + qmlRegisterType<QQuickBehavior, 13>("QtQuick", 2, 13, "Behavior"); } |