diff options
author | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2009-05-04 13:19:45 (GMT) |
---|---|---|
committer | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2009-05-05 10:04:50 (GMT) |
commit | 7771d6e6bc015e7341b6790f1c1e8800a778025a (patch) | |
tree | 58347b05ae44fdb7be2f39a34ef3528235923ad0 /src/declarative/util | |
parent | 1fb2457414749daef08935a36534991bca5ad562 (diff) | |
download | Qt-7771d6e6bc015e7341b6790f1c1e8800a778025a.zip Qt-7771d6e6bc015e7341b6790f1c1e8800a778025a.tar.gz Qt-7771d6e6bc015e7341b6790f1c1e8800a778025a.tar.bz2 |
Fixed qml's variant and color animations when started without transition
When the 'from' field is not set, it was not updated after running an
animation twice. Now the color and variant animations behave as
the numeric one, updating the 'from' value at the start of each run.
Reviewed-by: Michael Brasser
Diffstat (limited to 'src/declarative/util')
-rw-r--r-- | src/declarative/util/qmlanimation.cpp | 36 | ||||
-rw-r--r-- | src/declarative/util/qmlanimation_p.h | 17 |
2 files changed, 35 insertions, 18 deletions
diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 4b8ce4e..08a7a28 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -703,9 +703,10 @@ QColor QmlColorAnimation::from() const void QmlColorAnimation::setFrom(const QColor &f) { Q_D(QmlColorAnimation); - if (d->fromValue.isValid() && f == d->fromValue) + if (d->fromIsDefined && f == d->fromValue) return; d->fromValue = f; + d->fromIsDefined = f.isValid(); emit fromChanged(f); } @@ -726,9 +727,10 @@ QColor QmlColorAnimation::to() const void QmlColorAnimation::setTo(const QColor &t) { Q_D(QmlColorAnimation); - if (d->toValue.isValid() && t == d->toValue) + if (d->toIsDefined && t == d->toValue) return; d->toValue = t; + d->toIsDefined = t.isValid(); emit toChanged(t); } @@ -860,9 +862,13 @@ void QmlColorAnimation::transition(QmlStateActions &actions, (!target() || target() == obj)) { objs.insert(obj); Action myAction = action; - if (d->fromValue.isValid()) + + if (d->fromIsDefined) { myAction.fromValue = QVariant(d->fromValue); - if (d->toValue.isValid()) + } else { + myAction.fromValue = QVariant(); + } + if (d->toIsDefined) myAction.toValue = QVariant(d->toValue); modified << action.property; @@ -877,7 +883,7 @@ void QmlColorAnimation::transition(QmlStateActions &actions, Action myAction; myAction.property = QmlMetaProperty(obj, props.at(jj)); - if (d->fromValue.isValid()) + if (d->fromIsDefined) myAction.fromValue = QVariant(d->fromValue); myAction.toValue = QVariant(d->toValue); @@ -898,7 +904,7 @@ QVariantAnimation::Interpolator QmlColorAnimationPrivate::colorInterpolator = 0; void QmlColorAnimationPrivate::valueChanged(qreal v) { if (!fromSourced) { - if (!fromValue.isValid()) { + if (!fromIsDefined) { fromValue = qvariant_cast<QColor>(property.read()); } fromSourced = true; @@ -1993,9 +1999,10 @@ QVariant QmlVariantAnimation::from() const void QmlVariantAnimation::setFrom(const QVariant &f) { Q_D(QmlVariantAnimation); - if (d->from.isValid() && f == d->from) + if (d->fromIsDefined && f == d->from) return; d->from = f; + d->fromIsDefined = f.isValid(); emit fromChanged(f); } @@ -2017,9 +2024,10 @@ QVariant QmlVariantAnimation::to() const void QmlVariantAnimation::setTo(const QVariant &t) { Q_D(QmlVariantAnimation); - if (d->to.isValid() && t == d->to) + if (d->toIsDefined && t == d->to) return; d->to = t; + d->toIsDefined = t.isValid(); emit toChanged(t); } @@ -2109,7 +2117,7 @@ QList<QObject *> *QmlVariantAnimation::exclude() void QmlVariantAnimationPrivate::valueChanged(qreal r) { if (!fromSourced) { - if (!from.isValid()) { + if (!fromIsDefined) { from = property.read(); } fromSourced = true; @@ -2138,7 +2146,7 @@ void QmlVariantAnimation::prepare(QmlMetaProperty &p) d->property = d->userProperty; d->convertVariant(d->to, (QVariant::Type)d->property.propertyType()); - if (d->from.isValid()) + if (d->fromIsDefined) d->convertVariant(d->from, (QVariant::Type)d->property.propertyType()); d->fromSourced = false; @@ -2198,12 +2206,12 @@ void QmlVariantAnimation::transition(QmlStateActions &actions, objs.insert(obj); Action myAction = action; - if (d->from.isValid()) { + if (d->fromIsDefined) { myAction.fromValue = d->from; } else { myAction.fromValue = QVariant(); } - if (d->to.isValid()) + if (d->toIsDefined) myAction.toValue = d->to; d->convertVariant(myAction.fromValue, (QVariant::Type)myAction.property.propertyType()); @@ -2216,13 +2224,13 @@ void QmlVariantAnimation::transition(QmlStateActions &actions, } } - if (d->to.isValid() && target() && !objs.contains(target())) { + if (d->toIsDefined && target() && !objs.contains(target())) { QObject *obj = target(); for (int jj = 0; jj < props.count(); ++jj) { Action myAction; myAction.property = QmlMetaProperty(obj, props.at(jj)); - if (d->from.isValid()) { + if (d->fromIsDefined) { d->convertVariant(d->from, (QVariant::Type)myAction.property.propertyType()); myAction.fromValue = d->from; } diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index 4fcaa47..06b7c08 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -203,7 +203,8 @@ class QmlColorAnimationPrivate : public QmlAbstractAnimationPrivate Q_DECLARE_PUBLIC(QmlColorAnimation); public: QmlColorAnimationPrivate() - : QmlAbstractAnimationPrivate(), fromSourced(false), ca(0), value(this, &QmlColorAnimationPrivate::valueChanged) + : QmlAbstractAnimationPrivate(), fromSourced(false), fromIsDefined(false), toIsDefined(false), + ca(0), value(this, &QmlColorAnimationPrivate::valueChanged) { if (!colorInterpolator) colorInterpolator = QVariantAnimationPrivate::getInterpolator(QVariant::Color); @@ -213,11 +214,16 @@ public: QString easing; + QColor fromValue; + QColor toValue; + QList<QObject *> filter; QList<QObject *> exclude; + bool fromSourced; - QColor fromValue; - QColor toValue; + bool fromIsDefined; + bool toIsDefined; + QmlTimeLineValueAnimator *ca; virtual void valueChanged(qreal); @@ -350,7 +356,8 @@ class QmlVariantAnimationPrivate : public QmlAbstractAnimationPrivate Q_DECLARE_PUBLIC(QmlVariantAnimation); public: QmlVariantAnimationPrivate() - : QmlAbstractAnimationPrivate(), fromSourced(false), va(0), value(this, &QmlVariantAnimationPrivate::valueChanged) {} + : QmlAbstractAnimationPrivate(), fromSourced(false), fromIsDefined(false), toIsDefined(false), + va(0), value(this, &QmlVariantAnimationPrivate::valueChanged) {} void init(); @@ -364,6 +371,8 @@ public: QList<QObject *> exclude; bool fromSourced; + bool fromIsDefined; + bool toIsDefined; QmlTimeLineValueAnimator *va; virtual void valueChanged(qreal); |