diff options
author | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2009-04-29 12:58:38 (GMT) |
---|---|---|
committer | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2009-04-30 09:31:53 (GMT) |
commit | 2e71dc6b97dfa0f8193162019da326aa32291d5e (patch) | |
tree | 739596f22e14ad612b24f7e841e54c2e8d052c0a /src | |
parent | e2bfab6f145ddc61ef21590e69c709456e430d1c (diff) | |
download | Qt-2e71dc6b97dfa0f8193162019da326aa32291d5e.zip Qt-2e71dc6b97dfa0f8193162019da326aa32291d5e.tar.gz Qt-2e71dc6b97dfa0f8193162019da326aa32291d5e.tar.bz2 |
Using qvariant color interpolator for QmlColorAnimation
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/util/qmlanimation.cpp | 27 | ||||
-rw-r--r-- | src/declarative/util/qmlanimation_p.h | 8 |
2 files changed, 16 insertions, 19 deletions
diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index c09b378..a099e54 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -811,9 +811,9 @@ void QmlColorAnimation::transition(QmlStateActions &actions, struct NTransitionData : public QmlTimeLineValue { QmlStateActions actions; - void write(QmlMetaProperty &property, const QColor &color) + void write(QmlMetaProperty &property, const QVariant &color) { - if (property.propertyType() == qMetaTypeId<QColor>()) { + if (property.propertyType() == QVariant::Color) { property.write(color); } } @@ -837,13 +837,8 @@ void QmlColorAnimation::transition(QmlStateActions &actions, QColor from(action.fromValue.value<QColor>()); - //XXX consolidate somewhere - uint red = uint(qreal(from.red()) + v * (qreal(to.red()) - qreal(from.red()))); - uint green = uint(qreal(from.green()) + v * (qreal(to.green()) - qreal(from.green()))); - uint blue = uint(qreal(from.blue()) + v * (qreal(to.blue()) - qreal(from.blue()))); - uint alpha = uint(qreal(from.alpha()) + v * (qreal(to.alpha()) - qreal(from.alpha()))); - - write(action.property, QColor(red, green, blue, alpha)); + QVariant newColor = QmlColorAnimationPrivate::colorInterpolator(&from, &to, v); + write(action.property, newColor); } } } @@ -902,24 +897,20 @@ void QmlColorAnimation::transition(QmlStateActions &actions, delete data; } +QVariantAnimation::Interpolator QmlColorAnimationPrivate::colorInterpolator = 0; void QmlColorAnimationPrivate::valueChanged(qreal v) { if (!fromSourced) { if (!fromValue.isValid()) { - fromValue = QColor(qvariant_cast<QColor>(property.read())); + fromValue = qvariant_cast<QColor>(property.read()); } fromSourced = true; } - //XXX consolidate somewhere - uint red = uint(qreal(fromValue.red()) + v * (qreal(toValue.red()) - qreal(fromValue.red()))); - uint green = uint(qreal(fromValue.green()) + v * (qreal(toValue.green()) - qreal(fromValue.green()))); - uint blue = uint(qreal(fromValue.blue()) + v * (qreal(toValue.blue()) - qreal(fromValue.blue()))); - uint alpha = uint(qreal(fromValue.alpha()) + v * (qreal(toValue.alpha()) - qreal(fromValue.alpha()))); - - if (property.propertyType() == qMetaTypeId<QColor>()) { - property.write(QColor(red, green, blue, alpha)); + if (property.propertyType() == QVariant::Color) { + QVariant newColor = colorInterpolator(&fromValue, &toValue, v); + property.write(newColor); } } QML_DEFINE_TYPE(QmlColorAnimation,ColorAnimation); diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index 728584c..0ef89f4 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -203,7 +203,11 @@ class QmlColorAnimationPrivate : public QmlAbstractAnimationPrivate Q_DECLARE_PUBLIC(QmlColorAnimation); public: QmlColorAnimationPrivate() - : QmlAbstractAnimationPrivate(), fromSourced(false), ca(0), value(this, &QmlColorAnimationPrivate::valueChanged) {} + : QmlAbstractAnimationPrivate(), fromSourced(false), ca(0), value(this, &QmlColorAnimationPrivate::valueChanged) + { + if (!colorInterpolator) + colorInterpolator = QVariantAnimationPrivate::getInterpolator(QVariant::Color); + } void init(); @@ -218,6 +222,8 @@ public: virtual void valueChanged(qreal); QmlTimeLineValueProxy<QmlColorAnimationPrivate> value; + + static QVariantAnimation::Interpolator colorInterpolator; }; class QmlRunScriptActionPrivate : public QmlAbstractAnimationPrivate |