From 0a7ca8efdd292f317d4c95a80485d9d51f14a694 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Tue, 23 Feb 2010 13:29:04 +1000 Subject: Adds QmlEasingValueType to qml Now it's possible to use easing curve types directly in qml as value types, {easing.type: "OutBounce"; easing.amplitude: 3}, instead of the former ugly string format, like "easeOutBounce(amplitude:3.0)". Reviewed-by: akennedy --- doc/src/declarative/animation.qdoc | 12 +- src/declarative/qml/qmlvaluetype.cpp | 70 +++++++++ src/declarative/qml/qmlvaluetype_p.h | 57 +++++++ src/declarative/util/qmlanimation.cpp | 163 ++++++--------------- src/declarative/util/qmlanimation_p.h | 9 +- src/declarative/util/qmlanimation_p_p.h | 2 +- .../qmlanimations/tst_qmlanimations.cpp | 105 ++++++------- 7 files changed, 237 insertions(+), 181 deletions(-) diff --git a/doc/src/declarative/animation.qdoc b/doc/src/declarative/animation.qdoc index d80c3fa..892535e 100644 --- a/doc/src/declarative/animation.qdoc +++ b/doc/src/declarative/animation.qdoc @@ -72,9 +72,9 @@ Rectangle { y: 0 y: SequentialAnimation { repeat: true - NumberAnimation { to: 200-img.height; easing: "easeOutBounce"; duration: 2000 } + NumberAnimation { to: 200-img.height; easing.type: "OutBounce"; duration: 2000 } PauseAnimation { duration: 1000 } - NumberAnimation { to: 0; easing: "easeOutQuad"; duration: 1000 } + NumberAnimation { to: 0; easing.type: "OutQuad"; duration: 1000 } } } } @@ -135,7 +135,7 @@ transitions: [ Transition { NumberAnimation { properties: "x,y" - easing: "easeOutBounce" + easing.type: "OutBounce" duration: 200 } } @@ -156,7 +156,7 @@ Transition { SequentialAnimation { NumberAnimation { duration: 1000 - easing: "easeOutBounce" + easing.type: "OutBounce" // animate myItem's x and y if they have changed in the state target: myItem properties: "x,y" @@ -198,7 +198,7 @@ Transition { ParallelAnimation { NumberAnimation { duration: 1000 - easing: "easeOutBounce" + easing.type: "OutBounce" targets: box1 properties: "x,y" } @@ -226,7 +226,7 @@ Rectangle { id: redRect color: "red" width: 100; height: 100 - x: Behavior { NumberAnimation { duration: 300; easing: "InOutQuad" } } + x: Behavior { NumberAnimation { duration: 300; easing.type: "InOutQuad" } } } \endqml diff --git a/src/declarative/qml/qmlvaluetype.cpp b/src/declarative/qml/qmlvaluetype.cpp index 33c3e76..e3b4219 100644 --- a/src/declarative/qml/qmlvaluetype.cpp +++ b/src/declarative/qml/qmlvaluetype.cpp @@ -75,6 +75,8 @@ QmlValueType *QmlValueTypeFactory::valueType(int t) return new QmlRectFValueType; case QVariant::Vector3D: return new QmlVector3DValueType; + case QVariant::EasingCurve: + return new QmlEasingValueType; case QVariant::Font: return new QmlFontValueType; default: @@ -473,6 +475,74 @@ void QmlVector3DValueType::setZ(qreal z) vector.setZ(z); } +QmlEasingValueType::QmlEasingValueType(QObject *parent) +: QmlValueType(parent) +{ +} + +void QmlEasingValueType::read(QObject *obj, int idx) +{ + void *a[] = { &easing, 0 }; + QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); +} + +void QmlEasingValueType::write(QObject *obj, int idx, QmlMetaProperty::WriteFlags flags) +{ + int status = -1; + void *a[] = { &easing, 0, &status, &flags }; + QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); +} + +QVariant QmlEasingValueType::value() +{ + return QVariant(easing); +} + +void QmlEasingValueType::setValue(QVariant value) +{ + easing = qvariant_cast(value); +} + +QmlEasingValueType::Type QmlEasingValueType::type() const +{ + return (QmlEasingValueType::Type)easing.type(); +} + +qreal QmlEasingValueType::amplitude() const +{ + return easing.amplitude(); +} + +qreal QmlEasingValueType::overshoot() const +{ + return easing.overshoot(); +} + +qreal QmlEasingValueType::period() const +{ + return easing.period(); +} + +void QmlEasingValueType::setType(QmlEasingValueType::Type type) +{ + easing.setType((QEasingCurve::Type)type); +} + +void QmlEasingValueType::setAmplitude(qreal amplitude) +{ + easing.setAmplitude(amplitude); +} + +void QmlEasingValueType::setOvershoot(qreal overshoot) +{ + easing.setOvershoot(overshoot); +} + +void QmlEasingValueType::setPeriod(qreal period) +{ + easing.setPeriod(period); +} + QmlFontValueType::QmlFontValueType(QObject *parent) : QmlValueType(parent), hasPixelSize(false) { diff --git a/src/declarative/qml/qmlvaluetype_p.h b/src/declarative/qml/qmlvaluetype_p.h index 0a152e8..6dd3703 100644 --- a/src/declarative/qml/qmlvaluetype_p.h +++ b/src/declarative/qml/qmlvaluetype_p.h @@ -57,6 +57,7 @@ #include #include +#include #include #include #include @@ -256,6 +257,62 @@ private: QVector3D vector; }; +class Q_AUTOTEST_EXPORT QmlEasingValueType : public QmlValueType +{ + Q_OBJECT + Q_ENUMS(Type) + + Q_PROPERTY(QmlEasingValueType::Type type READ type WRITE setType) + Q_PROPERTY(qreal amplitude READ amplitude WRITE setAmplitude) + Q_PROPERTY(qreal overshoot READ overshoot WRITE setOvershoot) + Q_PROPERTY(qreal period READ period WRITE setPeriod) +public: + enum Type { + Linear = QEasingCurve::Linear, + InQuad = QEasingCurve::InQuad, OutQuad = QEasingCurve::OutQuad, + InOutQuad = QEasingCurve::InOutQuad, OutInQuad = QEasingCurve::OutInQuad, + InCubic = QEasingCurve::InCubic, OutCubic = QEasingCurve::OutCubic, + InOutCubic = QEasingCurve::InOutCubic, OutInCubic = QEasingCurve::OutInCubic, + InQuart = QEasingCurve::InQuart, OutQuart = QEasingCurve::OutQuart, + InOutQuart = QEasingCurve::InOutQuart, OutInQuart = QEasingCurve::OutInQuart, + InQuint = QEasingCurve::InQuint, OutQuint = QEasingCurve::OutQuint, + InOutQuint = QEasingCurve::InOutQuint, OutInQuint = QEasingCurve::OutInQuint, + InSine = QEasingCurve::InSine, OutSine = QEasingCurve::OutSine, + InOutSine = QEasingCurve::InOutSine, OutInSine = QEasingCurve::OutInSine, + InExpo = QEasingCurve::InExpo, OutExpo = QEasingCurve::OutExpo, + InOutExpo = QEasingCurve::InOutExpo, OutInExpo = QEasingCurve::OutInExpo, + InCirc = QEasingCurve::InCirc, OutCirc = QEasingCurve::OutCirc, + InOutCirc = QEasingCurve::InOutCirc, OutInCirc = QEasingCurve::OutInCirc, + InElastic = QEasingCurve::InElastic, OutElastic = QEasingCurve::OutElastic, + InOutElastic = QEasingCurve::InOutElastic, OutInElastic = QEasingCurve::OutInElastic, + InBack = QEasingCurve::InBack, OutBack = QEasingCurve::OutBack, + InOutBack = QEasingCurve::InOutBack, OutInBack = QEasingCurve::OutInBack, + InBounce = QEasingCurve::InBounce, OutBounce = QEasingCurve::OutBounce, + InOutBounce = QEasingCurve::InOutBounce, OutInBounce = QEasingCurve::OutInBounce, + InCurve = QEasingCurve::InCurve, OutCurve = QEasingCurve::OutCurve, + SineCurve = QEasingCurve::SineCurve, CosineCurve = QEasingCurve::CosineCurve, + }; + + QmlEasingValueType(QObject *parent = 0); + + virtual void read(QObject *, int); + virtual void write(QObject *, int, QmlMetaProperty::WriteFlags); + virtual QVariant value(); + virtual void setValue(QVariant value); + + Type type() const; + qreal amplitude() const; + qreal overshoot() const; + qreal period() const; + void setType(Type); + void setAmplitude(qreal); + void setOvershoot(qreal); + void setPeriod(qreal); + +private: + QEasingCurve easing; +}; + class Q_AUTOTEST_EXPORT QmlFontValueType : public QmlValueType { Q_OBJECT diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 6dcce58..2f24167 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -66,79 +66,6 @@ QT_BEGIN_NAMESPACE -static QEasingCurve stringToCurve(const QString &curve, QObject *obj) -{ - QEasingCurve easingCurve; - - QString normalizedCurve = curve; - bool hasParams = curve.contains(QLatin1Char('(')); - QStringList props; - - if (hasParams) { - QString easeName = curve.trimmed(); - if (!easeName.endsWith(QLatin1Char(')'))) { - qmlInfo(obj) << QmlPropertyAnimation::tr("Unmatched parenthesis in easing function \"%1\"").arg(curve); - return easingCurve; - } - - int idx = easeName.indexOf(QLatin1Char('(')); - QString prop_str = - easeName.mid(idx + 1, easeName.length() - 1 - idx - 1); - normalizedCurve = easeName.left(idx); - if (!normalizedCurve.startsWith(QLatin1String("ease"))) { - qmlInfo(obj) << QmlPropertyAnimation::tr("Easing function \"%1\" must start with \"ease\"").arg(curve); - return easingCurve; - } - - props = prop_str.split(QLatin1Char(',')); - } - - if (normalizedCurve.startsWith(QLatin1String("ease"))) - normalizedCurve = normalizedCurve.mid(4); - - static int index = QEasingCurve::staticMetaObject.indexOfEnumerator("Type"); - static QMetaEnum me = QEasingCurve::staticMetaObject.enumerator(index); - - int value = me.keyToValue(normalizedCurve.toUtf8().constData()); - if (value < 0) { - qmlInfo(obj) << QmlPropertyAnimation::tr("Unknown easing curve \"%1\"").arg(curve); - return easingCurve; - } - easingCurve.setType((QEasingCurve::Type)value); - - if (hasParams) { - foreach(const QString &str, props) { - int sep = str.indexOf(QLatin1Char(':')); - - if (sep == -1) { - qmlInfo(obj) << QmlPropertyAnimation::tr("Improperly specified parameter in easing function \"%1\"").arg(curve); - continue; - } - - QString propName = str.left(sep).trimmed(); - bool isOk; - qreal propValue = str.mid(sep + 1).trimmed().toDouble(&isOk); - - if (propName.isEmpty() || !isOk) { - qmlInfo(obj) << QmlPropertyAnimation::tr("Improperly specified parameter in easing function \"%1\"").arg(curve); - continue; - } - - if (propName == QLatin1String("amplitude")) { - easingCurve.setAmplitude(propValue); - } else if (propName == QLatin1String("period")) { - easingCurve.setPeriod(propValue); - } else if (propName == QLatin1String("overshoot")) { - easingCurve.setOvershoot(propValue); - } else { - qmlInfo(obj) << QmlPropertyAnimation::tr("Unknown easing parameter \"%1\"").arg(propName); - continue; - } - } - } - return easingCurve; -} - QML_DEFINE_NOCREATE_TYPE(QmlAbstractAnimation) /*! @@ -1927,195 +1854,195 @@ void QmlPropertyAnimation::setTo(const QVariant &t) } /*! - \qmlproperty string PropertyAnimation::easing + \qmlproperty QEasingCurve PropertyAnimation::easing \brief the easing curve used for the transition. Available values are: \table \row - \o \c easeLinear + \o \c Linear \o Easing curve for a linear (t) function: velocity is constant. \o \inlineimage qeasingcurve-linear.png \row - \o \c easeInQuad + \o \c InQuad \o Easing curve for a quadratic (t^2) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-inquad.png \row - \o \c easeOutQuad + \o \c OutQuad \o Easing curve for a quadratic (t^2) function: decelerating to zero velocity. \o \inlineimage qeasingcurve-outquad.png \row - \o \c easeInOutQuad + \o \c InOutQuad \o Easing curve for a quadratic (t^2) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutquad.png \row - \o \c easeOutInQuad + \o \c OutInQuad \o Easing curve for a quadratic (t^2) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinquad.png \row - \o \c easeInCubic + \o \c InCubic \o Easing curve for a cubic (t^3) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-incubic.png \row - \o \c easeOutCubic + \o \c OutCubic \o Easing curve for a cubic (t^3) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outcubic.png \row - \o \c easeInOutCubic + \o \c InOutCubic \o Easing curve for a cubic (t^3) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutcubic.png \row - \o \c easeOutInCubic + \o \c OutInCubic \o Easing curve for a cubic (t^3) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outincubic.png \row - \o \c easeInQuart + \o \c InQuart \o Easing curve for a quartic (t^4) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-inquart.png \row - \o \c easeOutQuart + \o \c OutQuart \o Easing curve for a cubic (t^4) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outquart.png \row - \o \c easeInOutQuart + \o \c InOutQuart \o Easing curve for a cubic (t^4) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutquart.png \row - \o \c easeOutInQuart + \o \c OutInQuart \o Easing curve for a cubic (t^4) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinquart.png \row - \o \c easeInQuint + \o \c InQuint \o Easing curve for a quintic (t^5) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-inquint.png \row - \o \c easeOutQuint + \o \c OutQuint \o Easing curve for a cubic (t^5) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outquint.png \row - \o \c easeInOutQuint + \o \c InOutQuint \o Easing curve for a cubic (t^5) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutquint.png \row - \o \c easeOutInQuint + \o \c OutInQuint \o Easing curve for a cubic (t^5) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinquint.png \row - \o \c easeInSine + \o \c InSine \o Easing curve for a sinusoidal (sin(t)) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-insine.png \row - \o \c easeOutSine + \o \c OutSine \o Easing curve for a sinusoidal (sin(t)) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outsine.png \row - \o \c easeInOutSine + \o \c InOutSine \o Easing curve for a sinusoidal (sin(t)) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutsine.png \row - \o \c easeOutInSine + \o \c OutInSine \o Easing curve for a sinusoidal (sin(t)) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinsine.png \row - \o \c easeInExpo + \o \c InExpo \o Easing curve for an exponential (2^t) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-inexpo.png \row - \o \c easeOutExpo + \o \c OutExpo \o Easing curve for an exponential (2^t) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outexpo.png \row - \o \c easeInOutExpo + \o \c InOutExpo \o Easing curve for an exponential (2^t) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutexpo.png \row - \o \c easeOutInExpo + \o \c OutInExpo \o Easing curve for an exponential (2^t) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinexpo.png \row - \o \c easeInCirc + \o \c InCirc \o Easing curve for a circular (sqrt(1-t^2)) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-incirc.png \row - \o \c easeOutCirc + \o \c OutCirc \o Easing curve for a circular (sqrt(1-t^2)) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outcirc.png \row - \o \c easeInOutCirc + \o \c InOutCirc \o Easing curve for a circular (sqrt(1-t^2)) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutcirc.png \row - \o \c easeOutInCirc + \o \c OutInCirc \o Easing curve for a circular (sqrt(1-t^2)) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outincirc.png \row - \o \c easeInElastic + \o \c InElastic \o Easing curve for an elastic (exponentially decaying sine wave) function: accelerating from zero velocity. \br The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. \o \inlineimage qeasingcurve-inelastic.png \row - \o \c easeOutElastic + \o \c OutElastic \o Easing curve for an elastic (exponentially decaying sine wave) function: decelerating from zero velocity. \br The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter. \o \inlineimage qeasingcurve-outelastic.png \row - \o \c easeInOutElastic + \o \c InOutElastic \o Easing curve for an elastic (exponentially decaying sine wave) function: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutelastic.png \row - \o \c easeOutInElastic + \o \c OutInElastic \o Easing curve for an elastic (exponentially decaying sine wave) function: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinelastic.png \row - \o \c easeInBack + \o \c InBack \o Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity. \o \inlineimage qeasingcurve-inback.png \row - \o \c easeOutBack + \o \c OutBack \o Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing out: decelerating to zero velocity. \o \inlineimage qeasingcurve-outback.png \row - \o \c easeInOutBack + \o \c InOutBack \o Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutback.png \row - \o \c easeOutInBack + \o \c OutInBack \o Easing curve for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinback.png \row - \o \c easeInBounce + \o \c InBounce \o Easing curve for a bounce (exponentially decaying parabolic bounce) function: accelerating from zero velocity. \o \inlineimage qeasingcurve-inbounce.png \row - \o \c easeOutBounce + \o \c OutBounce \o Easing curve for a bounce (exponentially decaying parabolic bounce) function: decelerating from zero velocity. \o \inlineimage qeasingcurve-outbounce.png \row - \o \c easeInOutBounce + \o \c InOutBounce \o Easing curve for a bounce (exponentially decaying parabolic bounce) function easing in/out: acceleration until halfway, then deceleration. \o \inlineimage qeasingcurve-inoutbounce.png \row - \o \c easeOutInBounce + \o \c OutInBounce \o Easing curve for a bounce (exponentially decaying parabolic bounce) function easing out/in: deceleration until halfway, then acceleration. \o \inlineimage qeasingcurve-outinbounce.png \endtable */ -QString QmlPropertyAnimation::easing() const +QEasingCurve QmlPropertyAnimation::easing() const { Q_D(const QmlPropertyAnimation); return d->easing; } -void QmlPropertyAnimation::setEasing(const QString &e) +void QmlPropertyAnimation::setEasing(const QEasingCurve &e) { Q_D(QmlPropertyAnimation); if (d->easing == e) return; d->easing = e; - d->va->setEasingCurve(stringToCurve(d->easing, this)); + d->va->setEasingCurve(d->easing); emit easingChanged(e); } diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index 623ad8d..fd868bc 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -51,6 +51,7 @@ #include #include +#include #include #include @@ -261,7 +262,7 @@ class Q_AUTOTEST_EXPORT QmlPropertyAnimation : public QmlAbstractAnimation 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(QEasingCurve easing READ easing WRITE setEasing NOTIFY easingChanged) Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged) Q_PROPERTY(QString properties READ properties WRITE setProperties NOTIFY propertiesChanged) @@ -281,8 +282,8 @@ public: QVariant to() const; void setTo(const QVariant &); - QString easing() const; - void setEasing(const QString &); + QEasingCurve easing() const; + void setEasing(const QEasingCurve &); QObject *target() const; void setTarget(QObject *); @@ -307,7 +308,7 @@ Q_SIGNALS: void durationChanged(int); void fromChanged(QVariant); void toChanged(QVariant); - void easingChanged(const QString &); + void easingChanged(const QEasingCurve &); void propertiesChanged(const QString &); void targetChanged(QObject *, const QString &); }; diff --git a/src/declarative/util/qmlanimation_p_p.h b/src/declarative/util/qmlanimation_p_p.h index 056ce82..8c88f14 100644 --- a/src/declarative/util/qmlanimation_p_p.h +++ b/src/declarative/util/qmlanimation_p_p.h @@ -327,7 +327,7 @@ public: QVariant from; QVariant to; - QString easing; + QEasingCurve easing; QObject *target; QString propertyName; diff --git a/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp b/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp index 1f6347e..00e099e 100644 --- a/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp +++ b/tests/auto/declarative/qmlanimations/tst_qmlanimations.cpp @@ -45,6 +45,7 @@ #include #include #include +#include class tst_qmlanimations : public QObject { @@ -67,11 +68,11 @@ private slots: void mixedTypes(); void properties(); void propertiesTransition(); - void easingStringConversion(); void invalidDuration(); void attached(); void propertyValueSourceDefaultStart(); void dontStart(); + void easingProperties(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -517,57 +518,6 @@ void tst_qmlanimations::propertiesTransition() }*/ } -void tst_qmlanimations::easingStringConversion() -{ - QmlNumberAnimation *animation = new QmlNumberAnimation; - animation->setEasing("easeInOutQuad"); - QCOMPARE(animation->easing(),QLatin1String("easeInOutQuad")); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve(), QEasingCurve(QEasingCurve::InOutQuad)); - - animation->setEasing("OutQuad"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve(), QEasingCurve(QEasingCurve::OutQuad)); - - animation->setEasing("easeOutBounce(amplitude: 5)"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::OutBounce); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().amplitude(), qreal(5)); - - animation->setEasing("easeOutElastic(amplitude: 5, period: 3)"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::OutElastic); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().amplitude(), qreal(5)); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().period(), qreal(3)); - - animation->setEasing("easeInOutBack(overshoot: 2)"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::InOutBack); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().overshoot(), qreal(2)); - - QTest::ignoreMessage(QtWarningMsg, "QML NumberAnimation (unknown location) Unmatched parenthesis in easing function \"easeInOutBack(overshoot: 2\""); - animation->setEasing("easeInOutBack(overshoot: 2"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::Linear); - - QTest::ignoreMessage(QtWarningMsg, "QML NumberAnimation (unknown location) Easing function \"InOutBack(overshoot: 2)\" must start with \"ease\""); - animation->setEasing("InOutBack(overshoot: 2)"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::Linear); - - QTest::ignoreMessage(QtWarningMsg, "QML NumberAnimation (unknown location) Unknown easing curve \"NonExistantEase\""); - animation->setEasing("NonExistantEase"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::Linear); - - QTest::ignoreMessage(QtWarningMsg, "QML NumberAnimation (unknown location) Improperly specified parameter in easing function \"easeInOutElastic(amplitude 5)\""); - animation->setEasing("easeInOutElastic(amplitude 5)"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::InOutElastic); - - QTest::ignoreMessage(QtWarningMsg, "QML NumberAnimation (unknown location) Improperly specified parameter in easing function \"easeInOutElastic(amplitude: yes)\""); - animation->setEasing("easeInOutElastic(amplitude: yes)"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::InOutElastic); - QVERIFY(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().amplitude() != qreal(5)); - - QTest::ignoreMessage(QtWarningMsg, "QML NumberAnimation (unknown location) Unknown easing parameter \"nonexistentproperty\""); - animation->setEasing("easeOutQuad(nonexistentproperty: 12)"); - QCOMPARE(static_cast(((QmlAbstractAnimation*)animation)->qtAnimation())->easingCurve().type(), QEasingCurve::OutQuad); - - delete animation; -} - void tst_qmlanimations::invalidDuration() { QmlPropertyAnimation *animation = new QmlPropertyAnimation; @@ -666,6 +616,57 @@ void tst_qmlanimations::dontStart() } } +void tst_qmlanimations::easingProperties() +{ + { + QmlEngine engine; + QString componentStr = "import Qt 4.6\nNumberAnimation { easing.type: \"InOutQuad\" }"; + QmlComponent animationComponent(&engine); + animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QmlPropertyAnimation *animObject = qobject_cast(animationComponent.create()); + + QVERIFY(animObject != 0); + QCOMPARE(animObject->easing().type(), QEasingCurve::InOutQuad); + } + + { + QmlEngine engine; + QString componentStr = "import Qt 4.6\nPropertyAnimation { easing.type: \"OutBounce\"; easing.amplitude: 5.0 }"; + QmlComponent animationComponent(&engine); + animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QmlPropertyAnimation *animObject = qobject_cast(animationComponent.create()); + + QVERIFY(animObject != 0); + QCOMPARE(animObject->easing().type(), QEasingCurve::OutBounce); + QCOMPARE(animObject->easing().amplitude(), 5.0); + } + + { + QmlEngine engine; + QString componentStr = "import Qt 4.6\nPropertyAnimation { easing.type: \"OutElastic\"; easing.amplitude: 5.0; easing.period: 3.0}"; + QmlComponent animationComponent(&engine); + animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QmlPropertyAnimation *animObject = qobject_cast(animationComponent.create()); + + QVERIFY(animObject != 0); + QCOMPARE(animObject->easing().type(), QEasingCurve::OutElastic); + QCOMPARE(animObject->easing().amplitude(), 5.0); + QCOMPARE(animObject->easing().period(), 3.0); + } + + { + QmlEngine engine; + QString componentStr = "import Qt 4.6\nPropertyAnimation { easing.type: \"InOutBack\"; easing.overshoot: 2 }"; + QmlComponent animationComponent(&engine); + animationComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QmlPropertyAnimation *animObject = qobject_cast(animationComponent.create()); + + QVERIFY(animObject != 0); + QCOMPARE(animObject->easing().type(), QEasingCurve::InOutBack); + QCOMPARE(animObject->easing().overshoot(), 2.0); + } +} + QTEST_MAIN(tst_qmlanimations) #include "tst_qmlanimations.moc" -- cgit v0.12