summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/declarative/fx/qfxanchors.cpp6
-rw-r--r--src/declarative/fx/qfxflipable.cpp2
-rw-r--r--src/declarative/fx/qfxhighlightfilter.cpp2
-rw-r--r--src/declarative/fx/qfxlayouts.cpp24
-rw-r--r--src/declarative/qml/qmldom.cpp10
-rw-r--r--src/declarative/util/qmlanimation.cpp885
-rw-r--r--src/declarative/util/qmlanimation.h170
-rw-r--r--src/declarative/util/qmlanimation_p.h72
-rw-r--r--src/declarative/util/qmlbehaviour.cpp2
-rw-r--r--src/declarative/util/qmlfollow.cpp2
10 files changed, 304 insertions, 871 deletions
diff --git a/src/declarative/fx/qfxanchors.cpp b/src/declarative/fx/qfxanchors.cpp
index 3da58a2..feac96e 100644
--- a/src/declarative/fx/qfxanchors.cpp
+++ b/src/declarative/fx/qfxanchors.cpp
@@ -772,6 +772,7 @@ void QFxAnchors::setLeftMargin(int offset)
if (d->leftMargin == offset)
return;
d->leftMargin = offset;
+ d->updateHorizontalAnchors();
emit leftMarginChanged();
}
@@ -787,6 +788,7 @@ void QFxAnchors::setRightMargin(int offset)
if (d->rightMargin == offset)
return;
d->rightMargin = offset;
+ d->updateHorizontalAnchors();
emit rightMarginChanged();
}
@@ -802,6 +804,7 @@ void QFxAnchors::setHorizontalCenterOffset(int offset)
if (d->hCenterOffset == offset)
return;
d->hCenterOffset = offset;
+ d->updateHorizontalAnchors();
emit horizontalCenterOffsetChanged();
}
@@ -817,6 +820,7 @@ void QFxAnchors::setTopMargin(int offset)
if (d->topMargin == offset)
return;
d->topMargin = offset;
+ d->updateVerticalAnchors();
emit topMarginChanged();
}
@@ -832,6 +836,7 @@ void QFxAnchors::setBottomMargin(int offset)
if (d->bottomMargin == offset)
return;
d->bottomMargin = offset;
+ d->updateVerticalAnchors();
emit bottomMarginChanged();
}
@@ -847,6 +852,7 @@ void QFxAnchors::setVerticalCenterOffset(int offset)
if (d->vCenterOffset == offset)
return;
d->vCenterOffset = offset;
+ d->updateVerticalAnchors();
emit verticalCenterOffsetChanged();
}
diff --git a/src/declarative/fx/qfxflipable.cpp b/src/declarative/fx/qfxflipable.cpp
index 4c02e74..9595724 100644
--- a/src/declarative/fx/qfxflipable.cpp
+++ b/src/declarative/fx/qfxflipable.cpp
@@ -94,7 +94,7 @@ Flipable {
]
transitions: [
Transition {
- NumericAnimation {
+ NumberAnimation {
easing: "easeInOutQuad"
properties: "rotation"
}
diff --git a/src/declarative/fx/qfxhighlightfilter.cpp b/src/declarative/fx/qfxhighlightfilter.cpp
index 1671fc6..78a91af 100644
--- a/src/declarative/fx/qfxhighlightfilter.cpp
+++ b/src/declarative/fx/qfxhighlightfilter.cpp
@@ -80,7 +80,7 @@ Text {
text: "Highlight"
filter: Highlight {
source: "pics/highlight.png"
- xOffset: NumericAnimation {
+ xOffset: NumberAnimation {
running: true
repeat: true
from: 320
diff --git a/src/declarative/fx/qfxlayouts.cpp b/src/declarative/fx/qfxlayouts.cpp
index a975778..e27135c 100644
--- a/src/declarative/fx/qfxlayouts.cpp
+++ b/src/declarative/fx/qfxlayouts.cpp
@@ -132,7 +132,7 @@ BaseLayout {
id: layout
y: 0
move: Transition {
- NumericAnimation {
+ NumberAnimation {
properties: "y"
ease: "easeOutBounce"
}
@@ -161,7 +161,7 @@ BaseLayout {
id: layout
y: 0
add: Transition {
- NumericAnimation {
+ NumberAnimation {
target: layout.item
properties: "opacity"
from: 0
@@ -196,7 +196,7 @@ BaseLayout {
id: layout
y: 0
remove: Transition {
- NumericAnimation {
+ NumberAnimation {
target: layout.item
properties: "opacity"
from: 1
@@ -512,7 +512,7 @@ VerticalLayout {
VerticalLayout {
id: layout
remove: Transition {
- NumericAnimation {
+ NumberAnimation {
target: layout.item
properties: "opacity"
from: 1
@@ -539,7 +539,7 @@ VerticalLayout {
VerticalLayout {
id: layout
add: Transition {
- NumericAnimation {
+ NumberAnimation {
target: layout.item
properties: "opacity"
from: 0
@@ -566,7 +566,7 @@ VerticalLayout {
VerticalLayout {
id: layout
move: Transition {
- NumericAnimation {
+ NumberAnimation {
properties: "y"
ease: "easeOutBounce"
}
@@ -683,7 +683,7 @@ HorizontalLayout {
HorizontalLayout {
id: layout
remove: Transition {
- NumericAnimation {
+ NumberAnimation {
target: layout.item
properties: "opacity"
from: 1
@@ -705,7 +705,7 @@ HorizontalLayout {
HorizontalLayout {
id: layout
add: Transition {
- NumericAnimation {
+ NumberAnimation {
target: layout.item
properties: "opacity"
from: 0
@@ -727,7 +727,7 @@ HorizontalLayout {
HorizontalLayout {
id: layout
move: Transition {
- NumericAnimation {
+ NumberAnimation {
properties: "x"
ease: "easeOutBounce"
}
@@ -875,7 +875,7 @@ GridLayout {
GridLayout {
id: layout
remove: Transition {
- NumericAnimation {
+ NumberAnimation {
target: layout.item
properties: "opacity"
from: 1
@@ -900,7 +900,7 @@ GridLayout {
GridLayout {
id: layout
add: Transition {
- NumericAnimation {
+ NumberAnimation {
target: layout.item
properties: "opacity"
from: 0
@@ -923,7 +923,7 @@ GridLayout {
GridLayout {
id: layout
move: Transition {
- NumericAnimation {
+ NumberAnimation {
properties: "x,y"
ease: "easeOutBounce"
}
diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp
index 42b40b6..5271dc5 100644
--- a/src/declarative/qml/qmldom.cpp
+++ b/src/declarative/qml/qmldom.cpp
@@ -969,11 +969,11 @@ void QmlDomValueBinding::setBinding(const QString &expression)
In QML, value sources are special value generating types that may be
assigned to properties. Value sources inherit the QmlPropertyValueSource
class. In the example below, the "x" property is being assigned the
- NumericAnimation value source.
+ NumberAnimation value source.
\qml
Rect {
- x: NumericAnimation {
+ x: NumberAnimation {
from: 0
to: 100
repeat: true
@@ -1018,11 +1018,11 @@ QmlDomValueValueSource &QmlDomValueValueSource::operator=(const QmlDomValueValue
/*!
Return the value source object.
- In the example below, an object representing the NumericAnimation will be
+ In the example below, an object representing the NumberAnimation will be
returned.
\qml
Rect {
- x: NumericAnimation {
+ x: NumberAnimation {
from: 0
to: 100
repeat: true
@@ -1367,7 +1367,7 @@ Item {
\qml
Item {
x: 10
- x: NumericAnimation {
+ x: NumberAnimation {
running: false
from: 0
to: 100
diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp
index e5f1138..4ee5545 100644
--- a/src/declarative/util/qmlanimation.cpp
+++ b/src/declarative/util/qmlanimation.cpp
@@ -60,7 +60,7 @@
/* TODO:
Check for any memory leaks
easing should be a QEasingCurve-type property
- All other XXXs
+ All other XXXs and ###s
*/
QT_BEGIN_NAMESPACE
@@ -85,11 +85,17 @@ QEasingCurve stringToCurve(const QString &curve)
QString prop_str =
easeName.mid(idx + 1, easeName.length() - 1 - idx - 1);
normalizedCurve = easeName.left(idx);
+ if (!normalizedCurve.startsWith(QLatin1String("ease"))) {
+ qWarning("QEasingCurve: Easing function '%s' must start with 'ease'",
+ curve.toLatin1().constData());
+ }
props = prop_str.split(QLatin1Char(','));
}
- normalizedCurve = normalizedCurve.mid(4);
+ if (normalizedCurve.startsWith(QLatin1String("ease")))
+ normalizedCurve = normalizedCurve.mid(4);
+
//XXX optimize?
int index = QEasingCurve::staticMetaObject.indexOfEnumerator("Type");
QMetaEnum me = QEasingCurve::staticMetaObject.enumerator(index);
@@ -179,7 +185,7 @@ QmlAbstractAnimation::QmlAbstractAnimation(QmlAbstractAnimationPrivate &dd, QObj
\code
Rect {
width: 100; height: 100
- x: NumericAnimation {
+ x: NumberAnimation {
running: MyMouse.pressed
from: 0; to: 100
}
@@ -192,7 +198,7 @@ QmlAbstractAnimation::QmlAbstractAnimation(QmlAbstractAnimationPrivate &dd, QObj
or not the animation is running.
\code
- NumericAnimation { id: MyAnimation }
+ NumberAnimation { id: MyAnimation }
Text { text: MyAnimation.running ? "Animation is running" : "Animation is not running" }
\endcode
@@ -349,7 +355,7 @@ void QmlAbstractAnimation::setFinishPlaying(bool f)
\code
Rect {
- rotation: NumericAnimation { running: true; repeat: true; from: 0 to: 360 }
+ rotation: NumberAnimation { running: true; repeat: true; from: 0 to: 360 }
}
\endcode
*/
@@ -371,6 +377,16 @@ void QmlAbstractAnimation::setRepeat(bool r)
emit repeatChanged(r);
}
+int QmlAbstractAnimation::currentTime()
+{
+ return qtAnimation()->currentTime();
+}
+
+void QmlAbstractAnimation::setCurrentTime(int time)
+{
+ qtAnimation()->setCurrentTime(time);
+}
+
QmlAnimationGroup *QmlAbstractAnimation::group() const
{
Q_D(const QmlAbstractAnimation);
@@ -502,7 +518,7 @@ void QmlAbstractAnimation::resume()
no further influence on property values. In this example animation
\code
Rect {
- x: NumericAnimation { from: 0; to: 100; duration: 500 }
+ x: NumberAnimation { from: 0; to: 100; duration: 500 }
}
\endcode
was stopped at time 250ms, the \c x property will have a value of 50.
@@ -540,7 +556,7 @@ void QmlAbstractAnimation::restart()
its end. In the following example,
\code
Rect {
- x: NumericAnimation { from: 0; to: 100; duration: 500 }
+ x: NumberAnimation { from: 0; to: 100; duration: 500 }
}
\endcode
calling \c stop() at time 250ms will result in the \c x property having
@@ -596,9 +612,9 @@ void QmlAbstractAnimation::timelineComplete()
A 500ms animation sequence, with a 100ms pause between two animations:
\code
SequentialAnimation {
- NumericAnimation { ... duration: 200 }
+ NumberAnimation { ... duration: 200 }
PauseAnimation { duration: 100 }
- NumericAnimation { ... duration: 200 }
+ NumberAnimation { ... duration: 200 }
}
\endcode
*/
@@ -683,16 +699,12 @@ QAbstractAnimation *QmlPauseAnimation::qtAnimation()
/*!
\qmlclass ColorAnimation QmlColorAnimation
- \inherits Animation
+ \inherits PropertyAnimation
\brief The ColorAnimation allows you to animate color changes.
\code
ColorAnimation { from: "white"; to: "#c0c0c0"; duration: 100 }
\endcode
-
- The default property animated is \c color, but like other animations,
- this can be changed by setting \c property. The \c color property will
- still animate. XXX is this a bug?
*/
/*!
\internal
@@ -706,56 +718,18 @@ QAbstractAnimation *QmlPauseAnimation::qtAnimation()
*/
QmlColorAnimation::QmlColorAnimation(QObject *parent)
-: QmlAbstractAnimation(*(new QmlColorAnimationPrivate), parent)
+: QmlPropertyAnimation(parent)
{
- Q_D(QmlColorAnimation);
+ Q_D(QmlPropertyAnimation);
d->init();
+ d->interpolatorType = QMetaType::QColor;
+ d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
}
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.
@@ -766,18 +740,13 @@ void QmlColorAnimation::setDuration(int duration)
*/
QColor QmlColorAnimation::from() const
{
- Q_D(const QmlColorAnimation);
- return d->fromValue;
+ Q_D(const QmlPropertyAnimation);
+ return d->from.value<QColor>();
}
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);
+ QmlPropertyAnimation::setFrom(f);
}
/*!
@@ -790,200 +759,15 @@ void QmlColorAnimation::setFrom(const QColor &f)
*/
QColor QmlColorAnimation::to() const
{
- Q_D(const QmlColorAnimation);
- return d->toValue;
+ Q_D(const QmlPropertyAnimation);
+ return d->to.value<QColor>();
}
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<Item> ColorAnimation::filter
- This property holds the items selected to be affected by this animation (all if not set).
- \sa exclude
-*/
-QList<QObject *> *QmlColorAnimation::filter()
-{
- Q_D(QmlColorAnimation);
- return &d->filter;
+ QmlPropertyAnimation::setTo(t);
}
-/*!
- \qmlproperty list<Item> ColorAnimation::exclude
- This property holds the items not to be affected by this animation.
- \sa filter
-*/
-QList<QObject *> *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<QColor>());
-
- 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<QColor>());
-
- 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<QObject *> 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);
- data->actions << myAction;
- }
- }
-
- if (data->actions.count())
- d->ca->setAnimValue(data, QAbstractAnimation::DeleteWhenStopped);
- else
- delete data;
-}
-
-QVariantAnimation::Interpolator QmlColorAnimationPrivate::colorInterpolator = 0;
-
-void QmlColorAnimationPrivate::valueChanged(qreal v)
-{
- if (!fromSourced) {
- if (!fromIsDefined) {
- fromValue = qvariant_cast<QColor>(property.read());
- }
- fromSourced = true;
- }
-
- if (property.propertyType() == QVariant::Color) {
- QVariant newColor = colorInterpolator(&fromValue, &toValue, v);
- property.write(newColor);
- }
-}
QML_DEFINE_TYPE(QmlColorAnimation,ColorAnimation)
/*!
@@ -1393,389 +1177,82 @@ void QmlParentChangeAction::transition(QmlStateActions &actions,
QML_DEFINE_TYPE(QmlParentChangeAction,ParentChangeAction)
/*!
- \qmlclass NumericAnimation QmlNumericAnimation
- \inherits Animation
- \brief The NumericAnimation allows you to animate changes in properties of type qreal.
+ \qmlclass NumberAnimation QmlNumberAnimation
+ \inherits PropertyAnimation
+ \brief The NumberAnimation allows you to animate changes in properties of type qreal.
Animate a set of properties over 200ms, from their values in the start state to
their values in the end state of the transition:
\code
- NumericAnimation { properties: "x,y,scale"; duration: 200 }
+ NumberAnimation { properties: "x,y,scale"; duration: 200 }
\endcode
*/
/*!
\internal
- \class QmlNumericAnimation
+ \class QmlNumberAnimation
\ingroup group_animation
\ingroup group_states
- \brief The QmlNumericAnimation class allows you to animate changes in properties of type qreal.
+ \brief The QmlNumberAnimation class allows you to animate changes in properties of type qreal.
- A QmlNumericAnimation object can be instantiated in Qml using the tag
- \l{xmlNumericAnimation} {&lt;NumericAnimation&gt;}.
+ A QmlNumberAnimation object can be instantiated in Qml using the tag
+ \l{xmlNumberAnimation} {&lt;NumberAnimation&gt;}.
*/
-QmlNumericAnimation::QmlNumericAnimation(QObject *parent)
-: QmlAbstractAnimation(*(new QmlNumericAnimationPrivate), parent)
+QmlNumberAnimation::QmlNumberAnimation(QObject *parent)
+: QmlPropertyAnimation(parent)
{
- Q_D(QmlNumericAnimation);
+ Q_D(QmlPropertyAnimation);
d->init();
+ d->interpolatorType = QMetaType::QReal;
+ d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
}
-QmlNumericAnimation::~QmlNumericAnimation()
-{
-}
-
-void QmlNumericAnimationPrivate::init()
+QmlNumberAnimation::~QmlNumberAnimation()
{
- 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
+ \qmlproperty real NumberAnimation::from
This property holds the starting value.
If not set, then the value defined in the start state of the transition.
*/
/*!
- \property QmlNumericAnimation::from
+ \property QmlNumberAnimation::from
\brief the starting value.
*/
-qreal QmlNumericAnimation::from() const
+qreal QmlNumberAnimation::from() const
{
- Q_D(const QmlNumericAnimation);
- return d->from;
+ Q_D(const QmlPropertyAnimation);
+ return d->from.toDouble(); //### toFloat?
}
-void QmlNumericAnimation::setFrom(qreal f)
+void QmlNumberAnimation::setFrom(qreal f)
{
- Q_D(QmlNumericAnimation);
- if (!d->from.isNull && f == d->from)
- return;
- d->from = f;
- emit fromChanged(f);
+ QmlPropertyAnimation::setFrom(f);
}
/*!
- \qmlproperty real NumericAnimation::to
+ \qmlproperty real NumberAnimation::to
This property holds the ending value.
If not set, then the value defined in the end state of the transition.
*/
/*!
- \property QmlNumericAnimation::to
+ \property QmlNumberAnimation::to
\brief the ending value.
*/
-qreal QmlNumericAnimation::to() const
-{
- Q_D(const QmlNumericAnimation);
- return d->to;
-}
-
-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<Item> NumericAnimation::filter
- This property holds the items selected to be affected by this animation (all if not set).
- \sa exclude
-*/
-QList<QObject *> *QmlNumericAnimation::filter()
-{
- Q_D(QmlNumericAnimation);
- return &d->filter;
-}
-
-/*!
- \qmlproperty list<Item> NumericAnimation::exclude
- This property holds the items not to be affected by this animation.
- \sa filter
-*/
-QList<QObject *> *QmlNumericAnimation::exclude()
-{
- Q_D(QmlNumericAnimation);
- return &d->exclude;
-}
-
-void QmlNumericAnimationPrivate::valueChanged(qreal r)
-{
- if (!fromSourced) {
- if (from.isNull) {
- fromValue = qvariant_cast<qreal>(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)
+qreal QmlNumberAnimation::to() const
{
- 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);
+ Q_D(const QmlPropertyAnimation);
+ return d->to.toDouble(); //### toFloat?
}
-QAbstractAnimation *QmlNumericAnimation::qtAnimation()
+void QmlNumberAnimation::setTo(qreal t)
{
- Q_D(QmlNumericAnimation);
- return d->na;
+ QmlPropertyAnimation::setTo(t);
}
-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<QObject *> 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);
- data->actions << myAction;
- }
- }
-
- if (data->actions.count()) {
- d->na->setAnimValue(data, QAbstractAnimation::DeleteWhenStopped);
- } else {
- delete data;
- }
-}
-
-QML_DEFINE_TYPE(QmlNumericAnimation,NumericAnimation)
+QML_DEFINE_TYPE(QmlNumberAnimation,NumberAnimation)
QmlAnimationGroup::QmlAnimationGroup(QObject *parent)
: QmlAbstractAnimation(*(new QmlAnimationGroupPrivate), parent)
@@ -1804,8 +1281,8 @@ QmlList<QmlAbstractAnimation *> *QmlAnimationGroup::animations()
\code
SequentialAnimation {
- NumericAnimation { target: MyItem; property: "x"; to: 100 }
- NumericAnimation { target: MyItem; property: "x"; to: 0 }
+ NumberAnimation { target: MyItem; property: "x"; to: 100 }
+ NumberAnimation { target: MyItem; property: "x"; to: 0 }
}
\endcode
@@ -1887,8 +1364,8 @@ QML_DEFINE_TYPE(QmlSequentialAnimation,SequentialAnimation)
\code
ParallelAnimation {
- NumericAnimation { target: MyItem; property: "x"; to: 100 }
- NumericAnimation { target: MyItem; property: "y"; to: 100 }
+ NumberAnimation { target: MyItem; property: "x"; to: 100 }
+ NumberAnimation { target: MyItem; property: "y"; to: 100 }
}
\endcode
@@ -1957,17 +1434,23 @@ void QmlParallelAnimation::transition(QmlStateActions &actions,
QML_DEFINE_TYPE(QmlParallelAnimation,ParallelAnimation)
-QVariant QmlVariantAnimationPrivate::interpolateVariant(const QVariant &from, const QVariant &to, qreal progress)
+//### profile and optimize
+QVariant QmlPropertyAnimationPrivate::interpolateVariant(const QVariant &from, const QVariant &to, qreal progress)
{
if (from.userType() != to.userType())
return QVariant();
QVariantAnimation::Interpolator interpolator = QVariantAnimationPrivate::getInterpolator(from.userType());
- return interpolator(from.constData(), to.constData(), progress);
+ if (interpolator)
+ return interpolator(from.constData(), to.constData(), progress);
+ else
+ return QVariant();
}
//convert a variant from string type to another animatable type
-void QmlVariantAnimationPrivate::convertVariant(QVariant &variant, QVariant::Type type)
+//### should use any registered string convertor
+//### profile and optimize
+void QmlPropertyAnimationPrivate::convertVariant(QVariant &variant, QVariant::Type type)
{
if (variant.type() != QVariant::String) {
variant.convert(type);
@@ -2010,9 +1493,9 @@ void QmlVariantAnimationPrivate::convertVariant(QVariant &variant, QVariant::Typ
}
/*!
- \qmlclass VariantAnimation QmlVariantAnimation
+ \qmlclass PropertyAnimation QmlPropertyAnimation
\inherits Animation
- \brief The VariantAnimation allows you to animate changes in properties of type QVariant.
+ \brief The PropertyAnimation allows you to animate property changes.
Animate a size property over 200ms, from its current size to 20-by-20:
\code
@@ -2020,51 +1503,51 @@ void QmlVariantAnimationPrivate::convertVariant(QVariant &variant, QVariant::Typ
\endcode
*/
-QmlVariantAnimation::QmlVariantAnimation(QObject *parent)
-: QmlAbstractAnimation(*(new QmlVariantAnimationPrivate), parent)
+QmlPropertyAnimation::QmlPropertyAnimation(QObject *parent)
+: QmlAbstractAnimation(*(new QmlPropertyAnimationPrivate), parent)
{
- Q_D(QmlVariantAnimation);
+ Q_D(QmlPropertyAnimation);
d->init();
}
-QmlVariantAnimation::~QmlVariantAnimation()
+QmlPropertyAnimation::~QmlPropertyAnimation()
{
}
-void QmlVariantAnimationPrivate::init()
+void QmlPropertyAnimationPrivate::init()
{
- Q_Q(QmlVariantAnimation);
+ Q_Q(QmlPropertyAnimation);
va = new QmlTimeLineValueAnimator(q);
va->setStartValue(QVariant(0.0f));
va->setEndValue(QVariant(1.0f));
}
/*!
- \qmlproperty int VariantAnimation::duration
+ \qmlproperty int PropertyAnimation::duration
This property holds the duration of the transition, in milliseconds.
The default value is 250.
*/
/*!
- \property QmlVariantAnimation::duration
+ \property QmlPropertyAnimation::duration
\brief the duration of the transition, in milliseconds.
The default value is 250.
*/
-int QmlVariantAnimation::duration() const
+int QmlPropertyAnimation::duration() const
{
- Q_D(const QmlVariantAnimation);
+ Q_D(const QmlPropertyAnimation);
return d->va->duration();
}
-void QmlVariantAnimation::setDuration(int duration)
+void QmlPropertyAnimation::setDuration(int duration)
{
if (duration < 0) {
- qWarning("QmlVariantAnimation: Cannot set a duration of < 0");
+ qWarning("QmlPropertyAnimation: Cannot set a duration of < 0");
return;
}
- Q_D(QmlVariantAnimation);
+ Q_D(QmlPropertyAnimation);
if (d->va->duration() == duration)
return;
d->va->setDuration(duration);
@@ -2072,23 +1555,23 @@ void QmlVariantAnimation::setDuration(int duration)
}
/*!
- \qmlproperty real VariantAnimation::from
+ \qmlproperty real PropertyAnimation::from
This property holds the starting value.
If not set, then the value defined in the start state of the transition.
*/
/*!
- \property QmlVariantAnimation::from
+ \property QmlPropertyAnimation::from
\brief the starting value.
*/
-QVariant QmlVariantAnimation::from() const
+QVariant QmlPropertyAnimation::from() const
{
- Q_D(const QmlVariantAnimation);
+ Q_D(const QmlPropertyAnimation);
return d->from;
}
-void QmlVariantAnimation::setFrom(const QVariant &f)
+void QmlPropertyAnimation::setFrom(const QVariant &f)
{
- Q_D(QmlVariantAnimation);
+ Q_D(QmlPropertyAnimation);
if (d->fromIsDefined && f == d->from)
return;
d->from = f;
@@ -2097,23 +1580,23 @@ void QmlVariantAnimation::setFrom(const QVariant &f)
}
/*!
- \qmlproperty real VariantAnimation::to
+ \qmlproperty real PropertyAnimation::to
This property holds the ending value.
If not set, then the value defined in the end state of the transition.
*/
/*!
- \property QmlVariantAnimation::to
+ \property QmlPropertyAnimation::to
\brief the ending value.
*/
-QVariant QmlVariantAnimation::to() const
+QVariant QmlPropertyAnimation::to() const
{
- Q_D(const QmlVariantAnimation);
+ Q_D(const QmlPropertyAnimation);
return d->to;
}
-void QmlVariantAnimation::setTo(const QVariant &t)
+void QmlPropertyAnimation::setTo(const QVariant &t)
{
- Q_D(QmlVariantAnimation);
+ Q_D(QmlPropertyAnimation);
if (d->toIsDefined && t == d->to)
return;
d->to = t;
@@ -2122,28 +1605,71 @@ void QmlVariantAnimation::setTo(const QVariant &t)
}
/*!
- \qmlproperty string VariantAnimation::easing
- This property holds the easing curve used for the transition.
+ \qmlproperty string PropertyAnimation::easing
+ \brief the easing curve used for the transition.
- See NumericAnimation::easing for a full discussion of easing,
- and a list of available curves.
+ 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 QmlVariantAnimation::easing
+ \property QmlPropertyAnimation::easing
\brief the easing curve to use.
\sa QEasingCurve
*/
-QString QmlVariantAnimation::easing() const
+QString QmlPropertyAnimation::easing() const
{
- Q_D(const QmlVariantAnimation);
+ Q_D(const QmlPropertyAnimation);
return d->easing;
}
-void QmlVariantAnimation::setEasing(const QString &e)
+void QmlPropertyAnimation::setEasing(const QString &e)
{
- Q_D(QmlVariantAnimation);
+ Q_D(QmlPropertyAnimation);
if (d->easing == e)
return;
@@ -2153,28 +1679,28 @@ void QmlVariantAnimation::setEasing(const QString &e)
}
/*!
- \qmlproperty string VariantAnimation::properties
+ \qmlproperty string PropertyAnimation::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 QmlVariantAnimation::properties
+ \property QmlPropertyAnimation::properties
\brief the properties this animation should be applied to
properties holds a copy separated list of properties that should use
this animation when they change.
*/
-QString QmlVariantAnimation::properties() const
+QString QmlPropertyAnimation::properties() const
{
- Q_D(const QmlVariantAnimation);
+ Q_D(const QmlPropertyAnimation);
return d->properties;
}
-void QmlVariantAnimation::setProperties(const QString &prop)
+void QmlPropertyAnimation::setProperties(const QString &prop)
{
- Q_D(QmlVariantAnimation);
+ Q_D(QmlPropertyAnimation);
if (d->properties == prop)
return;
@@ -2183,32 +1709,33 @@ void QmlVariantAnimation::setProperties(const QString &prop)
}
/*!
- \qmlproperty list<Item> VariantAnimation::filter
+ \qmlproperty list<Item> PropertyAnimation::filter
This property holds the items selected to be affected by this animation (all if not set).
\sa exclude
*/
-QList<QObject *> *QmlVariantAnimation::filter()
+QList<QObject *> *QmlPropertyAnimation::filter()
{
- Q_D(QmlVariantAnimation);
+ Q_D(QmlPropertyAnimation);
return &d->filter;
}
/*!
- \qmlproperty list<Item> VariantAnimation::exclude
+ \qmlproperty list<Item> PropertyAnimation::exclude
This property holds the items not to be affected by this animation.
\sa filter
*/
-QList<QObject *> *QmlVariantAnimation::exclude()
+QList<QObject *> *QmlPropertyAnimation::exclude()
{
- Q_D(QmlVariantAnimation);
+ Q_D(QmlPropertyAnimation);
return &d->exclude;
}
-void QmlVariantAnimationPrivate::valueChanged(qreal r)
+void QmlPropertyAnimationPrivate::valueChanged(qreal r)
{
if (!fromSourced) {
if (!fromIsDefined) {
from = property.read();
+ convertVariant(from, (QVariant::Type)(interpolatorType ? interpolatorType : property.propertyType()));
}
fromSourced = true;
}
@@ -2216,28 +1743,30 @@ void QmlVariantAnimationPrivate::valueChanged(qreal r)
if (r == 1.) {
property.write(to);
} else {
- QVariant val = interpolateVariant(from, to, r);
- property.write(val);
+ if (interpolator)
+ property.write(interpolator(from.constData(), to.constData(), r));
+ else
+ property.write(interpolateVariant(from, to, r)); //### optimize
}
}
-QAbstractAnimation *QmlVariantAnimation::qtAnimation()
+QAbstractAnimation *QmlPropertyAnimation::qtAnimation()
{
- Q_D(QmlVariantAnimation);
+ Q_D(QmlPropertyAnimation);
return d->va;
}
-void QmlVariantAnimation::prepare(QmlMetaProperty &p)
+void QmlPropertyAnimation::prepare(QmlMetaProperty &p)
{
- Q_D(QmlVariantAnimation);
+ Q_D(QmlPropertyAnimation);
if (d->userProperty.isNull)
d->property = 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.);
@@ -2245,44 +1774,66 @@ void QmlVariantAnimation::prepare(QmlMetaProperty &p)
d->va->setFromSourcedValue(&d->fromSourced);
}
-void QmlVariantAnimation::transition(QmlStateActions &actions,
+void QmlPropertyAnimation::transition(QmlStateActions &actions,
QmlMetaProperties &modified,
TransitionDirection direction)
{
- Q_D(QmlVariantAnimation);
+ Q_D(QmlPropertyAnimation);
Q_UNUSED(direction);
- struct NTransitionData : public QmlTimeLineValue
+ struct PropertyUpdater : public QmlTimeLineValue
{
QmlStateActions actions;
+ int interpolatorType; //for Number/ColorAnimation
+ int prevInterpolatorType; //for generic
+ QVariantAnimation::Interpolator interpolator;
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);
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?
+ if (interpolatorType)
+ QmlPropertyAnimationPrivate::convertVariant(action.fromValue, (QVariant::Type)interpolatorType);
}
- QVariant val = QmlVariantAnimationPrivate::interpolateVariant(action.fromValue, action.toValue, v);
- action.property.write(val);
+ if (!interpolatorType) {
+ int propType = action.property.propertyType();
+ if (!prevInterpolatorType || prevInterpolatorType != propType) {
+ prevInterpolatorType = propType;
+ interpolator = QVariantAnimationPrivate::getInterpolator(prevInterpolatorType);
+ }
+ }
+ if (interpolator)
+ action.property.write(interpolator(action.fromValue.constData(), action.toValue.constData(), v));
}
+ 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;
+ data->interpolatorType = d->interpolatorType;
+ data->interpolator = d->interpolator;
QSet<QObject *> objs;
for (int ii = 0; ii < actions.count(); ++ii) {
@@ -2305,8 +1856,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 : myAction.property.propertyType()));
+ d->convertVariant(myAction.toValue, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : myAction.property.propertyType()));
modified << action.property;
@@ -2322,11 +1873,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 : myAction.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 : myAction.property.propertyType()));
myAction.toValue = d->to;
data->actions << myAction;
}
@@ -2339,7 +1889,6 @@ void QmlVariantAnimation::transition(QmlStateActions &actions,
}
}
-//XXX whats the best name for this? (just Animation?)
-QML_DEFINE_TYPE(QmlVariantAnimation,VariantAnimation)
+QML_DEFINE_TYPE(QmlPropertyAnimation,PropertyAnimation)
QT_END_NAMESPACE
diff --git a/src/declarative/util/qmlanimation.h b/src/declarative/util/qmlanimation.h
index 0452159..110c43e 100644
--- a/src/declarative/util/qmlanimation.h
+++ b/src/declarative/util/qmlanimation.h
@@ -86,6 +86,9 @@ public:
bool repeat() const;
void setRepeat(bool);
+ int currentTime();
+ void setCurrentTime(int);
+
QmlAnimationGroup *group() const;
void setGroup(QmlAnimationGroup *);
@@ -157,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<QObject *>* filter READ filter)
- Q_PROPERTY(QList<QObject *>* 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<QObject *> *filter();
-
- QList<QObject *> *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
{
@@ -290,32 +246,32 @@ protected:
};
QML_DECLARE_TYPE(QmlParentChangeAction)
-class QmlNumericAnimationPrivate;
-class QmlNumericAnimation : public QmlAbstractAnimation
+class QmlPropertyAnimationPrivate;
+class QmlPropertyAnimation : public QmlAbstractAnimation
{
Q_OBJECT
- Q_DECLARE_PRIVATE(QmlNumericAnimation)
+ Q_DECLARE_PRIVATE(QmlPropertyAnimation)
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<QObject *>* filter READ filter)
Q_PROPERTY(QList<QObject *>* exclude READ exclude)
public:
- QmlNumericAnimation(QObject *parent=0);
- virtual ~QmlNumericAnimation();
+ QmlPropertyAnimation(QObject *parent=0);
+ virtual ~QmlPropertyAnimation();
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 &);
@@ -335,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(QmlPropertyAnimation)
+
+class QmlColorAnimation : public QmlPropertyAnimation
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QmlPropertyAnimation)
+ 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)
-#if 0
-class QmlDiscreteAnimation : public QmlAbstractAnimation
+class QmlNumberAnimation : public QmlPropertyAnimation
{
-Q_OBJECT
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QmlPropertyAnimation)
+
+ Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged)
+ Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged)
+
+public:
+ QmlNumberAnimation(QObject *parent=0);
+ virtual ~QmlNumberAnimation();
+
+ qreal from() const;
+ void setFrom(qreal);
+
+ qreal to() const;
+ void setTo(qreal);
};
-#endif
+QML_DECLARE_TYPE(QmlNumberAnimation)
class QmlAnimationGroupPrivate;
class QmlAnimationGroup : public QmlAbstractAnimation
@@ -401,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<QObject *>* filter READ filter)
- Q_PROPERTY(QList<QObject *>* 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<QObject *> *filter();
- QList<QObject *> *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..da5ed97 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<QObject *> filter;
- QList<QObject *> exclude;
-
- bool fromSourced;
- bool fromIsDefined;
- bool toIsDefined;
-
- QmlTimeLineValueAnimator *ca;
- virtual void valueChanged(qreal);
-
- QmlTimeLineValueProxy<QmlColorAnimationPrivate> 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<qreal> from;
- QmlNullableValue<qreal> to;
-
- QString easing;
-
- QString properties;
- QList<QObject *> filter;
- QList<QObject *> exclude;
-
- bool fromSourced;
- qreal fromValue;
- QmlTimeLineValueAnimator *na;
- virtual void valueChanged(qreal);
-
- QmlTimeLineValueProxy<QmlNumericAnimationPrivate> value;
-};
-
class QmlAnimationGroupPrivate : public QmlAbstractAnimationPrivate
{
Q_DECLARE_PUBLIC(QmlAnimationGroup)
@@ -360,13 +300,13 @@ public:
QAnimationGroup *ag;
};
-class QmlVariantAnimationPrivate : public QmlAbstractAnimationPrivate
+class QmlPropertyAnimationPrivate : public QmlAbstractAnimationPrivate
{
- Q_DECLARE_PUBLIC(QmlVariantAnimation)
+ Q_DECLARE_PUBLIC(QmlPropertyAnimation)
public:
- QmlVariantAnimationPrivate()
+ QmlPropertyAnimationPrivate()
: QmlAbstractAnimationPrivate(), fromSourced(false), fromIsDefined(false), toIsDefined(false),
- va(0), value(this, &QmlVariantAnimationPrivate::valueChanged) {}
+ interpolatorType(0), interpolator(0), va(0), value(this, &QmlPropertyAnimationPrivate::valueChanged) {}
void init();
@@ -382,11 +322,13 @@ public:
bool fromSourced;
bool fromIsDefined;
bool toIsDefined;
+ int interpolatorType;
+ QVariantAnimation::Interpolator interpolator;
QmlTimeLineValueAnimator *va;
virtual void valueChanged(qreal);
- QmlTimeLineValueProxy<QmlVariantAnimationPrivate> value;
+ QmlTimeLineValueProxy<QmlPropertyAnimationPrivate> value;
static QVariant interpolateVariant(const QVariant &from, const QVariant &to, qreal progress);
static void convertVariant(QVariant &variant, QVariant::Type type);
diff --git a/src/declarative/util/qmlbehaviour.cpp b/src/declarative/util/qmlbehaviour.cpp
index 3617541..4beca5e 100644
--- a/src/declarative/util/qmlbehaviour.cpp
+++ b/src/declarative/util/qmlbehaviour.cpp
@@ -115,7 +115,7 @@ public:
color: "#00ff00"
y: 200 //initial value
y: Behavior {
- NumericAnimation {
+ NumberAnimation {
easing: "easeOutBounce(amplitude:100)"
duration: 200
}
diff --git a/src/declarative/util/qmlfollow.cpp b/src/declarative/util/qmlfollow.cpp
index cf3d629..d3b3617 100644
--- a/src/declarative/util/qmlfollow.cpp
+++ b/src/declarative/util/qmlfollow.cpp
@@ -183,7 +183,7 @@ void QmlFollowPrivate::stop()
y: SequentialAnimation {
running: true
repeat: true
- NumericAnimation {
+ NumberAnimation {
to: 200
easing: "easeOutBounce(amplitude:100)"
duration: 2000