From 128a0c387801194a690f646cde6579bbf804b7de Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 25 Jun 2009 15:07:21 +1000 Subject: Refactoring animation code. Greatly simplify the NumericAnimation and ColorAnimation classes. Still need to optimize. --- src/declarative/util/qmlanimation.cpp | 651 +++++----------------------------- src/declarative/util/qmlanimation.h | 167 +++------ src/declarative/util/qmlanimation_p.h | 60 ---- 3 files changed, 131 insertions(+), 747 deletions(-) diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 4776391..f2a91eb 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -373,7 +373,7 @@ void QmlAbstractAnimation::setRepeat(bool r) int QmlAbstractAnimation::currentTime() { - qtAnimation()->currentTime(); + return qtAnimation()->currentTime(); } void QmlAbstractAnimation::setCurrentTime(int time) @@ -716,9 +716,9 @@ QAbstractAnimation *QmlPauseAnimation::qtAnimation() */ QmlColorAnimation::QmlColorAnimation(QObject *parent) -: QmlAbstractAnimation(*(new QmlColorAnimationPrivate), parent) +: QmlVariantAnimation(parent) { - Q_D(QmlColorAnimation); + Q_D(QmlVariantAnimation); d->init(); } @@ -726,46 +726,6 @@ QmlColorAnimation::~QmlColorAnimation() { } -void QmlColorAnimationPrivate::init() -{ - Q_Q(QmlColorAnimation); - ca = new QmlTimeLineValueAnimator(q); - ca->setStartValue(QVariant(0.0f)); - ca->setEndValue(QVariant(1.0f)); -} - -/*! - \qmlproperty int ColorAnimation::duration - This property holds the duration of the color transition, in milliseconds. - - The default value is 250. -*/ -/*! - \property QmlColorAnimation::duration - \brief the duration of the transition, in milliseconds. - - The default value is 250. -*/ -int QmlColorAnimation::duration() const -{ - Q_D(const QmlColorAnimation); - return d->ca->duration(); -} - -void QmlColorAnimation::setDuration(int duration) -{ - if (duration < 0) { - qWarning("QmlColorAnimation: Cannot set a duration of < 0"); - return; - } - - Q_D(QmlColorAnimation); - if (d->ca->duration() == duration) - return; - d->ca->setDuration(duration); - emit durationChanged(duration); -} - /*! \qmlproperty color ColorAnimation::from This property holds the starting color. @@ -776,18 +736,13 @@ void QmlColorAnimation::setDuration(int duration) */ QColor QmlColorAnimation::from() const { - Q_D(const QmlColorAnimation); - return d->fromValue; + Q_D(const QmlVariantAnimation); + return d->from.value(); } void QmlColorAnimation::setFrom(const QColor &f) { - Q_D(QmlColorAnimation); - if (d->fromIsDefined && f == d->fromValue) - return; - d->fromValue = f; - d->fromIsDefined = f.isValid(); - emit fromChanged(f); + QmlVariantAnimation::setFrom(f); } /*! @@ -800,202 +755,15 @@ void QmlColorAnimation::setFrom(const QColor &f) */ QColor QmlColorAnimation::to() const { - Q_D(const QmlColorAnimation); - return d->toValue; + Q_D(const QmlVariantAnimation); + return d->to.value(); } void QmlColorAnimation::setTo(const QColor &t) { - Q_D(QmlColorAnimation); - if (d->toIsDefined && t == d->toValue) - return; - d->toValue = t; - d->toIsDefined = t.isValid(); - emit toChanged(t); -} - -/*! - \qmlproperty string ColorAnimation::easing - This property holds the easing curve used for the transition. - - Each channel of the color is eased using the same easing curve. - See NumericAnimation::easing for a full discussion of easing, - and a list of available curves. -*/ -QString QmlColorAnimation::easing() const -{ - Q_D(const QmlColorAnimation); - return d->easing; -} - -void QmlColorAnimation::setEasing(const QString &e) -{ - Q_D(QmlColorAnimation); - if (d->easing == e) - return; - - d->easing = e; - d->ca->setEasingCurve(stringToCurve(d->easing)); - emit easingChanged(e); -} - -/*! - \qmlproperty list ColorAnimation::filter - This property holds the items selected to be affected by this animation (all if not set). - \sa exclude -*/ -QList *QmlColorAnimation::filter() -{ - Q_D(QmlColorAnimation); - return &d->filter; -} - -/*! - \qmlproperty list ColorAnimation::exclude - This property holds the items not to be affected by this animation. - \sa filter -*/ -QList *QmlColorAnimation::exclude() -{ - Q_D(QmlColorAnimation); - return &d->exclude; -} - -void QmlColorAnimation::prepare(QmlMetaProperty &p) -{ - Q_D(QmlColorAnimation); - if (d->userProperty.isNull) - d->property = p; - else - d->property = d->userProperty; - d->fromSourced = false; - d->value.QmlTimeLineValue::setValue(0.); - d->ca->setAnimValue(&d->value, QAbstractAnimation::KeepWhenStopped); - d->ca->setFromSourcedValue(&d->fromSourced); -} - -QAbstractAnimation *QmlColorAnimation::qtAnimation() -{ - Q_D(QmlColorAnimation); - return d->ca; -} - -void QmlColorAnimation::transition(QmlStateActions &actions, - QmlMetaProperties &modified, - TransitionDirection direction) -{ - Q_D(QmlColorAnimation); - Q_UNUSED(direction); - - struct NTransitionData : public QmlTimeLineValue - { - QmlStateActions actions; - void write(QmlMetaProperty &property, const QVariant &color) - { - if (property.propertyType() == QVariant::Color) { - property.write(color); - } - } - - void setValue(qreal v) - { - QmlTimeLineValue::setValue(v); - for (int ii = 0; ii < actions.count(); ++ii) { - Action &action = actions[ii]; - - QColor to(action.toValue.value()); - - if (v == 1.) { - write(action.property, to); - } else { - if (action.fromValue.isNull()) { - action.fromValue = action.property.read(); - if (action.fromValue.isNull()) - action.fromValue = QVariant(QColor()); - } - - QColor from(action.fromValue.value()); - - QVariant newColor = QmlColorAnimationPrivate::colorInterpolator(&from, &to, v); - write(action.property, newColor); - } - } - } - }; - - //XXX should we get rid of this? - QStringList props; - props << QLatin1String("color"); - if (!d->propertyName.isEmpty() && !props.contains(d->propertyName)) - props.append(d->propertyName); - - NTransitionData *data = new NTransitionData; - - QSet objs; - for (int ii = 0; ii < actions.count(); ++ii) { - Action &action = actions[ii]; - - QObject *obj = action.property.object(); - QString propertyName = action.property.name(); - - if ((d->filter.isEmpty() || d->filter.contains(obj)) && - (!d->exclude.contains(obj)) && props.contains(propertyName) && - (!target() || target() == obj)) { - objs.insert(obj); - Action myAction = action; - - if (d->fromIsDefined) { - myAction.fromValue = QVariant(d->fromValue); - } else { - myAction.fromValue = QVariant(); - } - if (d->toIsDefined) - myAction.toValue = QVariant(d->toValue); - - modified << action.property; - data->actions << myAction; - action.fromValue = myAction.toValue; - } - } - - if (d->toValue.isValid() && 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->fromIsDefined) - myAction.fromValue = QVariant(d->fromValue); - - myAction.toValue = QVariant(d->toValue); - myAction.bv = 0; - myAction.event = 0; - data->actions << myAction; - } - } - - if (data->actions.count()) - d->ca->setAnimValue(data, QAbstractAnimation::DeleteWhenStopped); - else - delete data; + QmlVariantAnimation::setTo(t); } -QVariantAnimation::Interpolator QmlColorAnimationPrivate::colorInterpolator = 0; - -void QmlColorAnimationPrivate::valueChanged(qreal v) -{ - if (!fromSourced) { - if (!fromIsDefined) { - fromValue = qvariant_cast(property.read()); - } - fromSourced = true; - } - - if (property.propertyType() == QVariant::Color) { - QVariant newColor = colorInterpolator(&fromValue, &toValue, v); - property.write(newColor); - } -} QML_DEFINE_TYPE(QmlColorAnimation,ColorAnimation) /*! @@ -1428,9 +1196,9 @@ QML_DEFINE_TYPE(QmlParentChangeAction,ParentChangeAction) */ QmlNumericAnimation::QmlNumericAnimation(QObject *parent) -: QmlAbstractAnimation(*(new QmlNumericAnimationPrivate), parent) +: QmlVariantAnimation(parent) { - Q_D(QmlNumericAnimation); + Q_D(QmlVariantAnimation); d->init(); } @@ -1438,46 +1206,6 @@ QmlNumericAnimation::~QmlNumericAnimation() { } -void QmlNumericAnimationPrivate::init() -{ - Q_Q(QmlNumericAnimation); - na = new QmlTimeLineValueAnimator(q); - na->setStartValue(QVariant(0.0f)); - na->setEndValue(QVariant(1.0f)); -} - -/*! - \qmlproperty int NumericAnimation::duration - This property holds the duration of the transition, in milliseconds. - - The default value is 250. -*/ -/*! - \property QmlNumericAnimation::duration - \brief the duration of the transition, in milliseconds. - - The default value is 250. -*/ -int QmlNumericAnimation::duration() const -{ - Q_D(const QmlNumericAnimation); - return d->na->duration(); -} - -void QmlNumericAnimation::setDuration(int duration) -{ - if (duration < 0) { - qWarning("QmlNumericAnimation: Cannot set a duration of < 0"); - return; - } - - Q_D(QmlNumericAnimation); - if (d->na->duration() == duration) - return; - d->na->setDuration(duration); - emit durationChanged(duration); -} - /*! \qmlproperty real NumericAnimation::from This property holds the starting value. @@ -1489,17 +1217,13 @@ void QmlNumericAnimation::setDuration(int duration) */ qreal QmlNumericAnimation::from() const { - Q_D(const QmlNumericAnimation); - return d->from; + Q_D(const QmlVariantAnimation); + return d->from.toDouble(); //### toFloat? } void QmlNumericAnimation::setFrom(qreal f) { - Q_D(QmlNumericAnimation); - if (!d->from.isNull && f == d->from) - return; - d->from = f; - emit fromChanged(f); + QmlVariantAnimation::setFrom(f); } /*! @@ -1513,280 +1237,13 @@ void QmlNumericAnimation::setFrom(qreal f) */ qreal QmlNumericAnimation::to() const { - Q_D(const QmlNumericAnimation); - return d->to; + Q_D(const QmlVariantAnimation); + return d->to.toDouble(); //### toFloat? } void QmlNumericAnimation::setTo(qreal t) { - Q_D(QmlNumericAnimation); - if (!d->to.isNull && t == d->to) - return; - d->to = t; - emit toChanged(t); -} - -/*! - \qmlproperty string NumericAnimation::easing - \brief the easing curve used for the transition. - - Available values are: - - \list - \i \e easeNone - Easing equation function for a simple linear tweening, with no easing. - \i \e easeInQuad - Easing equation function for a quadratic (t^2) easing in: accelerating from zero velocity. - \i \e easeOutQuad - Easing equation function for a quadratic (t^2) easing out: decelerating to zero velocity. - \i \e easeInOutQuad - Easing equation function for a quadratic (t^2) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInQuad - Easing equation function for a quadratic (t^2) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInCubic - Easing equation function for a cubic (t^3) easing in: accelerating from zero velocity. - \i \e easeOutCubic - Easing equation function for a cubic (t^3) easing out: decelerating from zero velocity. - \i \e easeInOutCubic - Easing equation function for a cubic (t^3) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInCubic - Easing equation function for a cubic (t^3) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInQuart - Easing equation function for a quartic (t^4) easing in: accelerating from zero velocity. - \i \e easeOutQuart - Easing equation function for a quartic (t^4) easing out: decelerating from zero velocity. - \i \e easeInOutQuart - Easing equation function for a quartic (t^4) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInQuart - Easing equation function for a quartic (t^4) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInQuint - Easing equation function for a quintic (t^5) easing in: accelerating from zero velocity. - \i \e easeOutQuint - Easing equation function for a quintic (t^5) easing out: decelerating from zero velocity. - \i \e easeInOutQuint - Easing equation function for a quintic (t^5) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInQuint - Easing equation function for a quintic (t^5) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInSine - Easing equation function for a sinusoidal (sin(t)) easing in: accelerating from zero velocity. - \i \e easeOutSine - Easing equation function for a sinusoidal (sin(t)) easing out: decelerating from zero velocity. - \i \e easeInOutSine - Easing equation function for a sinusoidal (sin(t)) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInSine - Easing equation function for a sinusoidal (sin(t)) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInExpo - Easing equation function for an exponential (2^t) easing in: accelerating from zero velocity. - \i \e easeOutExpo - Easing equation function for an exponential (2^t) easing out: decelerating from zero velocity. - \i \e easeInOutExpo - Easing equation function for an exponential (2^t) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInExpo - Easing equation function for an exponential (2^t) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInCirc - Easing equation function for a circular (sqrt(1-t^2)) easing in: accelerating from zero velocity. - \i \e easeOutCirc - Easing equation function for a circular (sqrt(1-t^2)) easing out: decelerating from zero velocity. - \i \e easeInOutCirc - Easing equation function for a circular (sqrt(1-t^2)) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInCirc - Easing equation function for a circular (sqrt(1-t^2)) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing in: accelerating from zero velocity. The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. - \i \e easeOutElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing out: decelerating from zero velocity. The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. - \i \e easeInOutElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing out/in: deceleration until halfway, then acceleration. - \i \e easeInBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity. - \i \e easeOutBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out: decelerating from zero velocity. - \i \e easeInOutBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration. - \i \e easeOutBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out: decelerating from zero velocity. - \i \e easeInBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in: accelerating from zero velocity. - \i \e easeInOutBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out: acceleration until halfway, then deceleration. - \i \e easeOutInBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out/in: deceleration until halfway, then acceleration. - \endlist -*/ - -/*! - \property QmlNumericAnimation::easing - This property holds the easing curve to use. - - \sa QEasingCurve -*/ -QString QmlNumericAnimation::easing() const -{ - Q_D(const QmlNumericAnimation); - return d->easing; -} - -void QmlNumericAnimation::setEasing(const QString &e) -{ - Q_D(QmlNumericAnimation); - if (d->easing == e) - return; - - d->easing = e; - d->na->setEasingCurve(stringToCurve(d->easing)); - emit easingChanged(e); -} - -/*! - \qmlproperty string NumericAnimation::properties - This property holds the properties this animation should be applied to. - - This is a comma-separated list of properties that should use - this animation when they change. -*/ -/*! - \property QmlNumericAnimation::properties - \brief the properties this animation should be applied to. - - properties holds a comma-separated list of properties that should use - this animation when they change. -*/ -QString QmlNumericAnimation::properties() const -{ - Q_D(const QmlNumericAnimation); - return d->properties; -} - -void QmlNumericAnimation::setProperties(const QString &prop) -{ - Q_D(QmlNumericAnimation); - if (d->properties == prop) - return; - - d->properties = prop; - emit propertiesChanged(prop); -} - -/*! - \qmlproperty list NumericAnimation::filter - This property holds the items selected to be affected by this animation (all if not set). - \sa exclude -*/ -QList *QmlNumericAnimation::filter() -{ - Q_D(QmlNumericAnimation); - return &d->filter; -} - -/*! - \qmlproperty list NumericAnimation::exclude - This property holds the items not to be affected by this animation. - \sa filter -*/ -QList *QmlNumericAnimation::exclude() -{ - Q_D(QmlNumericAnimation); - return &d->exclude; -} - -void QmlNumericAnimationPrivate::valueChanged(qreal r) -{ - if (!fromSourced) { - if (from.isNull) { - fromValue = qvariant_cast(property.read()); - } else { - fromValue = from; - } - fromSourced = true; - } - - if (r == 1.) { - property.write(to.value); - } else { - qreal val = fromValue + (to-fromValue) * r; - property.write(val); - } -} - -void QmlNumericAnimation::prepare(QmlMetaProperty &p) -{ - Q_D(QmlNumericAnimation); - if (d->userProperty.isNull) - d->property = p; - else - d->property = d->userProperty; - d->fromSourced = false; - d->value.QmlTimeLineValue::setValue(0.); - d->na->setAnimValue(&d->value, QAbstractAnimation::KeepWhenStopped); - d->na->setFromSourcedValue(&d->fromSourced); -} - -QAbstractAnimation *QmlNumericAnimation::qtAnimation() -{ - Q_D(QmlNumericAnimation); - return d->na; -} - -void QmlNumericAnimation::transition(QmlStateActions &actions, - QmlMetaProperties &modified, - TransitionDirection direction) -{ - Q_D(QmlNumericAnimation); - Q_UNUSED(direction); - - struct NTransitionData : public QmlTimeLineValue - { - QmlStateActions actions; - void setValue(qreal v) - { - QmlTimeLineValue::setValue(v); - for (int ii = 0; ii < actions.count(); ++ii) { - Action &action = actions[ii]; - - QmlBehaviour::_ignore = true; - if (v == 1.) - action.property.write(action.toValue.toDouble()); - else { - if (action.fromValue.isNull()) { - action.fromValue = action.property.read(); - if (action.fromValue.isNull()) { - action.fromValue = QVariant(0.); - } - } - qreal start = action.fromValue.toDouble(); - qreal end = action.toValue.toDouble(); - qreal val = start + (end-start) * v; - action.property.write(val); - } - QmlBehaviour::_ignore = false; - } - } - }; - - QStringList props = d->properties.isEmpty() ? QStringList() : d->properties.split(QLatin1Char(',')); - for (int ii = 0; ii < props.count(); ++ii) - props[ii] = props.at(ii).trimmed(); - if (!d->propertyName.isEmpty() && !props.contains(d->propertyName)) - props.append(d->propertyName); - - if (d->userProperty.isValid() && props.isEmpty() && !target()) { - props.append(d->userProperty.value.name()); - d->target = d->userProperty.value.object(); - } - - NTransitionData *data = new NTransitionData; - - QSet objs; - for (int ii = 0; ii < actions.count(); ++ii) { - Action &action = actions[ii]; - - QObject *obj = action.property.object(); - QString propertyName = action.property.name(); - - if ((d->filter.isEmpty() || d->filter.contains(obj)) && - (!d->exclude.contains(obj)) && props.contains(propertyName) && - (!target() || target() == obj)) { - objs.insert(obj); - Action myAction = action; - if (d->from.isValid()) { - myAction.fromValue = QVariant(d->from); - } else { - myAction.fromValue = QVariant(); - } - if (d->to.isValid()) - myAction.toValue = QVariant(d->to); - - modified << action.property; - - data->actions << myAction; - action.fromValue = myAction.toValue; - } - } - - if (d->to.isValid() && 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()) - myAction.fromValue = QVariant(d->from); - - myAction.toValue = QVariant(d->to); - myAction.bv = 0; - myAction.event = 0; - data->actions << myAction; - } - } - - if (data->actions.count()) { - d->na->setAnimValue(data, QAbstractAnimation::DeleteWhenStopped); - } else { - delete data; - } + QmlVariantAnimation::setTo(t); } QML_DEFINE_TYPE(QmlNumericAnimation,NumericAnimation) @@ -1971,6 +1428,7 @@ void QmlParallelAnimation::transition(QmlStateActions &actions, QML_DEFINE_TYPE(QmlParallelAnimation,ParallelAnimation) +//### profile and optimize QVariant QmlVariantAnimationPrivate::interpolateVariant(const QVariant &from, const QVariant &to, qreal progress) { if (from.userType() != to.userType()) @@ -1981,6 +1439,8 @@ QVariant QmlVariantAnimationPrivate::interpolateVariant(const QVariant &from, co } //convert a variant from string type to another animatable type +//### should use any registered string convertor +//### profile and optimize void QmlVariantAnimationPrivate::convertVariant(QVariant &variant, QVariant::Type type) { if (variant.type() != QVariant::String) { @@ -2137,10 +1597,53 @@ void QmlVariantAnimation::setTo(const QVariant &t) /*! \qmlproperty string VariantAnimation::easing - This property holds the easing curve used for the transition. + \brief the easing curve used for the transition. + + Available values are: - See NumericAnimation::easing for a full discussion of easing, - and a list of available curves. + \list + \i \e easeNone - Easing equation function for a simple linear tweening, with no easing. + \i \e easeInQuad - Easing equation function for a quadratic (t^2) easing in: accelerating from zero velocity. + \i \e easeOutQuad - Easing equation function for a quadratic (t^2) easing out: decelerating to zero velocity. + \i \e easeInOutQuad - Easing equation function for a quadratic (t^2) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInQuad - Easing equation function for a quadratic (t^2) easing out/in: deceleration until halfway, then acceleration. + \i \e easeInCubic - Easing equation function for a cubic (t^3) easing in: accelerating from zero velocity. + \i \e easeOutCubic - Easing equation function for a cubic (t^3) easing out: decelerating from zero velocity. + \i \e easeInOutCubic - Easing equation function for a cubic (t^3) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInCubic - Easing equation function for a cubic (t^3) easing out/in: deceleration until halfway, then acceleration. + \i \e easeInQuart - Easing equation function for a quartic (t^4) easing in: accelerating from zero velocity. + \i \e easeOutQuart - Easing equation function for a quartic (t^4) easing out: decelerating from zero velocity. + \i \e easeInOutQuart - Easing equation function for a quartic (t^4) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInQuart - Easing equation function for a quartic (t^4) easing out/in: deceleration until halfway, then acceleration. + \i \e easeInQuint - Easing equation function for a quintic (t^5) easing in: accelerating from zero velocity. + \i \e easeOutQuint - Easing equation function for a quintic (t^5) easing out: decelerating from zero velocity. + \i \e easeInOutQuint - Easing equation function for a quintic (t^5) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInQuint - Easing equation function for a quintic (t^5) easing out/in: deceleration until halfway, then acceleration. + \i \e easeInSine - Easing equation function for a sinusoidal (sin(t)) easing in: accelerating from zero velocity. + \i \e easeOutSine - Easing equation function for a sinusoidal (sin(t)) easing out: decelerating from zero velocity. + \i \e easeInOutSine - Easing equation function for a sinusoidal (sin(t)) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInSine - Easing equation function for a sinusoidal (sin(t)) easing out/in: deceleration until halfway, then acceleration. + \i \e easeInExpo - Easing equation function for an exponential (2^t) easing in: accelerating from zero velocity. + \i \e easeOutExpo - Easing equation function for an exponential (2^t) easing out: decelerating from zero velocity. + \i \e easeInOutExpo - Easing equation function for an exponential (2^t) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInExpo - Easing equation function for an exponential (2^t) easing out/in: deceleration until halfway, then acceleration. + \i \e easeInCirc - Easing equation function for a circular (sqrt(1-t^2)) easing in: accelerating from zero velocity. + \i \e easeOutCirc - Easing equation function for a circular (sqrt(1-t^2)) easing out: decelerating from zero velocity. + \i \e easeInOutCirc - Easing equation function for a circular (sqrt(1-t^2)) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInCirc - Easing equation function for a circular (sqrt(1-t^2)) easing out/in: deceleration until halfway, then acceleration. + \i \e easeInElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing in: accelerating from zero velocity. The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. + \i \e easeOutElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing out: decelerating from zero velocity. The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. + \i \e easeInOutElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInElastic - Easing equation function for an elastic (exponentially decaying sine wave) easing out/in: deceleration until halfway, then acceleration. + \i \e easeInBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity. + \i \e easeOutBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out: decelerating from zero velocity. + \i \e easeInOutBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInBack - Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration. + \i \e easeOutBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out: decelerating from zero velocity. + \i \e easeInBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in: accelerating from zero velocity. + \i \e easeInOutBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out: acceleration until halfway, then deceleration. + \i \e easeOutInBounce - Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out/in: deceleration until halfway, then acceleration. + \endlist */ /*! @@ -2230,8 +1733,7 @@ void QmlVariantAnimationPrivate::valueChanged(qreal r) if (r == 1.) { property.write(to); } else { - QVariant val = interpolateVariant(from, to, r); - property.write(val); + property.write(interpolateVariant(from, to, r)); } } @@ -2266,7 +1768,7 @@ void QmlVariantAnimation::transition(QmlStateActions &actions, Q_D(QmlVariantAnimation); Q_UNUSED(direction); - struct NTransitionData : public QmlTimeLineValue + struct PropertyUpdater : public QmlTimeLineValue { QmlStateActions actions; void setValue(qreal v) @@ -2275,28 +1777,38 @@ void QmlVariantAnimation::transition(QmlStateActions &actions, for (int ii = 0; ii < actions.count(); ++ii) { Action &action = actions[ii]; + QmlBehaviour::_ignore = true; if (v == 1.) action.property.write(action.toValue); else { if (action.fromValue.isNull()) { action.fromValue = action.property.read(); /*if (action.fromValue.isNull()) - action.fromValue = QVariant(0.);*/ //XXX can we give a default value for any type? + action.fromValue = QVariant(0.);*/ //### can/should we give a default value for any type? } QVariant val = QmlVariantAnimationPrivate::interpolateVariant(action.fromValue, action.toValue, v); action.property.write(val); } + QmlBehaviour::_ignore = false; } } }; - QStringList props = d->properties.split(QLatin1Char(',')); + QStringList props = d->properties.isEmpty() ? QStringList() : d->properties.split(QLatin1Char(',')); for (int ii = 0; ii < props.count(); ++ii) props[ii] = props.at(ii).trimmed(); if (!d->propertyName.isEmpty() && !props.contains(d->propertyName)) props.append(d->propertyName); - NTransitionData *data = new NTransitionData; + /* ### we used to select properties of name 'color' by default for color animations + props << QLatin1String("color");*/ + + if (d->userProperty.isValid() && props.isEmpty() && !target()) { + props.append(d->userProperty.value.name()); + d->target = d->userProperty.value.object(); + } + + PropertyUpdater *data = new PropertyUpdater; QSet objs; for (int ii = 0; ii < actions.count(); ++ii) { @@ -2339,7 +1851,6 @@ void QmlVariantAnimation::transition(QmlStateActions &actions, d->convertVariant(d->from, (QVariant::Type)myAction.property.propertyType()); myAction.fromValue = d->from; } - d->convertVariant(d->to, (QVariant::Type)myAction.property.propertyType()); myAction.toValue = d->to; myAction.bv = 0; diff --git a/src/declarative/util/qmlanimation.h b/src/declarative/util/qmlanimation.h index b0dd261..00ff3d7 100644 --- a/src/declarative/util/qmlanimation.h +++ b/src/declarative/util/qmlanimation.h @@ -160,53 +160,6 @@ protected: }; QML_DECLARE_TYPE(QmlPauseAnimation) -class QmlColorAnimationPrivate; -class QmlColorAnimation : public QmlAbstractAnimation -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlColorAnimation) - Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) - Q_PROPERTY(QColor from READ from WRITE setFrom NOTIFY fromChanged) - Q_PROPERTY(QColor to READ to WRITE setTo NOTIFY toChanged) - Q_PROPERTY(QString easing READ easing WRITE setEasing NOTIFY easingChanged) - Q_PROPERTY(QList* filter READ filter) - Q_PROPERTY(QList* exclude READ exclude) - -public: - QmlColorAnimation(QObject *parent=0); - virtual ~QmlColorAnimation(); - - int duration() const; - void setDuration(int); - - QColor from() const; - void setFrom(const QColor &); - - QColor to() const; - void setTo(const QColor &); - - QString easing() const; - void setEasing(const QString &); - - QList *filter(); - - QList *exclude(); - -protected: - virtual void transition(QmlStateActions &actions, - QmlMetaProperties &modified, - TransitionDirection direction); - virtual QAbstractAnimation *qtAnimation(); - virtual void prepare(QmlMetaProperty &); - -Q_SIGNALS: - void durationChanged(int); - void fromChanged(const QColor &); - void toChanged(const QColor &); - void easingChanged(const QString &); -}; -QML_DECLARE_TYPE(QmlColorAnimation) - class QmlRunScriptActionPrivate; class QmlRunScriptAction : public QmlAbstractAnimation { @@ -293,32 +246,32 @@ protected: }; QML_DECLARE_TYPE(QmlParentChangeAction) -class QmlNumericAnimationPrivate; -class QmlNumericAnimation : public QmlAbstractAnimation +class QmlVariantAnimationPrivate; +class QmlVariantAnimation : public QmlAbstractAnimation { Q_OBJECT - Q_DECLARE_PRIVATE(QmlNumericAnimation) + Q_DECLARE_PRIVATE(QmlVariantAnimation) Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) - Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged) - Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged) + Q_PROPERTY(QVariant from READ from WRITE setFrom NOTIFY fromChanged) + Q_PROPERTY(QVariant to READ to WRITE setTo NOTIFY toChanged) Q_PROPERTY(QString easing READ easing WRITE setEasing NOTIFY easingChanged) Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged) Q_PROPERTY(QList* filter READ filter) Q_PROPERTY(QList* exclude READ exclude) public: - QmlNumericAnimation(QObject *parent=0); - virtual ~QmlNumericAnimation(); + QmlVariantAnimation(QObject *parent=0); + virtual ~QmlVariantAnimation(); int duration() const; void setDuration(int); - qreal from() const; - void setFrom(qreal); + QVariant from() const; + void setFrom(const QVariant &); - qreal to() const; - void setTo(qreal); + QVariant to() const; + void setTo(const QVariant &); QString easing() const; void setEasing(const QString &); @@ -338,19 +291,51 @@ protected: Q_SIGNALS: void durationChanged(int); - void fromChanged(qreal); - void toChanged(qreal); + void fromChanged(QVariant); + void toChanged(QVariant); void easingChanged(const QString &); void propertiesChanged(const QString &); }; -QML_DECLARE_TYPE(QmlNumericAnimation) +QML_DECLARE_TYPE(QmlVariantAnimation) -#if 0 -class QmlDiscreteAnimation : public QmlAbstractAnimation +class QmlColorAnimation : public QmlVariantAnimation { -Q_OBJECT + Q_OBJECT + Q_DECLARE_PRIVATE(QmlVariantAnimation) + Q_PROPERTY(QColor from READ from WRITE setFrom NOTIFY fromChanged) + Q_PROPERTY(QColor to READ to WRITE setTo NOTIFY toChanged) + +public: + QmlColorAnimation(QObject *parent=0); + virtual ~QmlColorAnimation(); + + QColor from() const; + void setFrom(const QColor &); + + QColor to() const; + void setTo(const QColor &); +}; +QML_DECLARE_TYPE(QmlColorAnimation) + +class QmlNumericAnimation : public QmlVariantAnimation +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QmlVariantAnimation) + + Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged) + Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged) + +public: + QmlNumericAnimation(QObject *parent=0); + virtual ~QmlNumericAnimation(); + + qreal from() const; + void setFrom(qreal); + + qreal to() const; + void setTo(qreal); }; -#endif +QML_DECLARE_TYPE(QmlNumericAnimation) class QmlAnimationGroupPrivate; class QmlAnimationGroup : public QmlAbstractAnimation @@ -404,58 +389,6 @@ protected: }; QML_DECLARE_TYPE(QmlParallelAnimation) -class QmlVariantAnimationPrivate; -class QmlVariantAnimation : public QmlAbstractAnimation -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlVariantAnimation) - - Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged) - Q_PROPERTY(QVariant from READ from WRITE setFrom NOTIFY fromChanged) - Q_PROPERTY(QVariant to READ to WRITE setTo NOTIFY toChanged) - Q_PROPERTY(QString easing READ easing WRITE setEasing NOTIFY easingChanged) - Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged) - Q_PROPERTY(QList* filter READ filter) - Q_PROPERTY(QList* exclude READ exclude) - -public: - QmlVariantAnimation(QObject *parent=0); - virtual ~QmlVariantAnimation(); - - int duration() const; - void setDuration(int); - - QVariant from() const; - void setFrom(const QVariant &); - - QVariant to() const; - void setTo(const QVariant &); - - QString easing() const; - void setEasing(const QString &); - - QString properties() const; - void setProperties(const QString &); - - QList *filter(); - QList *exclude(); - -protected: - virtual void transition(QmlStateActions &actions, - QmlMetaProperties &modified, - TransitionDirection direction); - virtual QAbstractAnimation *qtAnimation(); - virtual void prepare(QmlMetaProperty &); - -Q_SIGNALS: - void durationChanged(int); - void fromChanged(QVariant); - void toChanged(QVariant); - void easingChanged(const QString &); - void propertiesChanged(const QString &); -}; -QML_DECLARE_TYPE(QmlVariantAnimation) - QT_END_NAMESPACE QT_END_HEADER diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index f09ab88..ff31895 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -207,40 +207,6 @@ public: QPauseAnimation *pa; }; -class QmlColorAnimationPrivate : public QmlAbstractAnimationPrivate -{ - Q_DECLARE_PUBLIC(QmlColorAnimation) -public: - QmlColorAnimationPrivate() - : QmlAbstractAnimationPrivate(), fromSourced(false), fromIsDefined(false), toIsDefined(false), - ca(0), value(this, &QmlColorAnimationPrivate::valueChanged) - { - if (!colorInterpolator) - colorInterpolator = QVariantAnimationPrivate::getInterpolator(QVariant::Color); - } - - void init(); - - QString easing; - - QColor fromValue; - QColor toValue; - - QList filter; - QList exclude; - - bool fromSourced; - bool fromIsDefined; - bool toIsDefined; - - QmlTimeLineValueAnimator *ca; - virtual void valueChanged(qreal); - - QmlTimeLineValueProxy value; - - static QVariantAnimation::Interpolator colorInterpolator; -}; - class QmlRunScriptActionPrivate : public QmlAbstractAnimationPrivate { Q_DECLARE_PUBLIC(QmlRunScriptAction) @@ -295,32 +261,6 @@ public: QActionAnimation *cpa; }; -class QmlNumericAnimationPrivate : public QmlAbstractAnimationPrivate -{ - Q_DECLARE_PUBLIC(QmlNumericAnimation) -public: - QmlNumericAnimationPrivate() - : QmlAbstractAnimationPrivate(), fromSourced(false), na(0), value(this, &QmlNumericAnimationPrivate::valueChanged) {} - - void init(); - - QmlNullableValue from; - QmlNullableValue to; - - QString easing; - - QString properties; - QList filter; - QList exclude; - - bool fromSourced; - qreal fromValue; - QmlTimeLineValueAnimator *na; - virtual void valueChanged(qreal); - - QmlTimeLineValueProxy value; -}; - class QmlAnimationGroupPrivate : public QmlAbstractAnimationPrivate { Q_DECLARE_PUBLIC(QmlAnimationGroup) -- cgit v0.12