diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-06-25 23:25:19 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-06-25 23:25:19 (GMT) |
commit | 91a7af3f44dc941929e0f93b98b2f2074f26086d (patch) | |
tree | 227a79f797e637f7097e30f46a5a53e62d5f3827 /src/declarative/util | |
parent | 128a0c387801194a690f646cde6579bbf804b7de (diff) | |
download | Qt-91a7af3f44dc941929e0f93b98b2f2074f26086d.zip Qt-91a7af3f44dc941929e0f93b98b2f2074f26086d.tar.gz Qt-91a7af3f44dc941929e0f93b98b2f2074f26086d.tar.bz2 |
Optimize refactored animation classes.
Diffstat (limited to 'src/declarative/util')
-rw-r--r-- | src/declarative/util/qmlanimation.cpp | 42 | ||||
-rw-r--r-- | src/declarative/util/qmlanimation_p.h | 4 |
2 files changed, 34 insertions, 12 deletions
diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index f2a91eb..4e637d5 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -720,6 +720,8 @@ QmlColorAnimation::QmlColorAnimation(QObject *parent) { Q_D(QmlVariantAnimation); d->init(); + d->interpolatorType = QMetaType::QColor; + d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType); } QmlColorAnimation::~QmlColorAnimation() @@ -1200,6 +1202,8 @@ QmlNumericAnimation::QmlNumericAnimation(QObject *parent) { Q_D(QmlVariantAnimation); d->init(); + d->interpolatorType = QMetaType::QReal; + d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType); } QmlNumericAnimation::~QmlNumericAnimation() @@ -1726,6 +1730,7 @@ void QmlVariantAnimationPrivate::valueChanged(qreal r) if (!fromSourced) { if (!fromIsDefined) { from = property.read(); + convertVariant(from, (QVariant::Type)(interpolatorType ? interpolatorType : property.propertyType())); } fromSourced = true; } @@ -1733,7 +1738,10 @@ void QmlVariantAnimationPrivate::valueChanged(qreal r) if (r == 1.) { property.write(to); } else { - property.write(interpolateVariant(from, to, r)); + if (interpolator) + property.write(interpolator(from.constData(), to.constData(), r)); + else + property.write(interpolateVariant(from, to, r)); //### optimize } } @@ -1751,9 +1759,9 @@ void QmlVariantAnimation::prepare(QmlMetaProperty &p) else d->property = d->userProperty; - d->convertVariant(d->to, (QVariant::Type)d->property.propertyType()); + d->convertVariant(d->to, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : d->property.propertyType())); if (d->fromIsDefined) - d->convertVariant(d->from, (QVariant::Type)d->property.propertyType()); + d->convertVariant(d->from, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : d->property.propertyType())); d->fromSourced = false; d->value.QmlTimeLineValue::setValue(0.); @@ -1771,6 +1779,9 @@ void QmlVariantAnimation::transition(QmlStateActions &actions, struct PropertyUpdater : public QmlTimeLineValue { QmlStateActions actions; + int interpolatorType; //for Numeric/ColorAnimation + int prevInterpolatorType; //for generic + QVariantAnimation::Interpolator interpolator; void setValue(qreal v) { QmlTimeLineValue::setValue(v); @@ -1783,11 +1794,18 @@ void QmlVariantAnimation::transition(QmlStateActions &actions, else { if (action.fromValue.isNull()) { action.fromValue = action.property.read(); - /*if (action.fromValue.isNull()) - action.fromValue = QVariant(0.);*/ //### can/should we give a default value for any type? + if (interpolatorType) + QmlVariantAnimationPrivate::convertVariant(action.fromValue, (QVariant::Type)interpolatorType); + } + if (!interpolatorType) { + int propType = action.property.propertyType(); + if (!prevInterpolatorType || prevInterpolatorType != propType) { + prevInterpolatorType = propType; + interpolator = QVariantAnimationPrivate::getInterpolator(prevInterpolatorType); + } } - QVariant val = QmlVariantAnimationPrivate::interpolateVariant(action.fromValue, action.toValue, v); - action.property.write(val); + if (interpolator) + action.property.write(interpolator(action.fromValue.constData(), action.toValue.constData(), v)); } QmlBehaviour::_ignore = false; } @@ -1809,6 +1827,8 @@ void QmlVariantAnimation::transition(QmlStateActions &actions, } PropertyUpdater *data = new PropertyUpdater; + data->interpolatorType = d->interpolatorType; + data->interpolator = d->interpolator; QSet<QObject *> objs; for (int ii = 0; ii < actions.count(); ++ii) { @@ -1831,8 +1851,8 @@ void QmlVariantAnimation::transition(QmlStateActions &actions, if (d->toIsDefined) myAction.toValue = d->to; - d->convertVariant(myAction.fromValue, (QVariant::Type)myAction.property.propertyType()); - d->convertVariant(myAction.toValue, (QVariant::Type)myAction.property.propertyType()); + d->convertVariant(myAction.fromValue, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : d->property.propertyType())); + d->convertVariant(myAction.toValue, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : d->property.propertyType())); modified << action.property; @@ -1848,10 +1868,10 @@ void QmlVariantAnimation::transition(QmlStateActions &actions, myAction.property = QmlMetaProperty(obj, props.at(jj)); if (d->fromIsDefined) { - d->convertVariant(d->from, (QVariant::Type)myAction.property.propertyType()); + d->convertVariant(d->from, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : d->property.propertyType())); myAction.fromValue = d->from; } - d->convertVariant(d->to, (QVariant::Type)myAction.property.propertyType()); + d->convertVariant(d->to, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : d->property.propertyType())); myAction.toValue = d->to; myAction.bv = 0; myAction.event = 0; diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index ff31895..7b0649a 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -306,7 +306,7 @@ class QmlVariantAnimationPrivate : public QmlAbstractAnimationPrivate public: QmlVariantAnimationPrivate() : QmlAbstractAnimationPrivate(), fromSourced(false), fromIsDefined(false), toIsDefined(false), - va(0), value(this, &QmlVariantAnimationPrivate::valueChanged) {} + interpolatorType(0), interpolator(0), va(0), value(this, &QmlVariantAnimationPrivate::valueChanged) {} void init(); @@ -322,6 +322,8 @@ public: bool fromSourced; bool fromIsDefined; bool toIsDefined; + int interpolatorType; + QVariantAnimation::Interpolator interpolator; QmlTimeLineValueAnimator *va; virtual void valueChanged(qreal); |