1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qdeclarativeanimation_p.h"
43 #include "qdeclarativeanimation_p_p.h"
45 #include <private/qdeclarativestateoperations_p.h>
46 #include <private/qdeclarativecontext_p.h>
48 #include <qdeclarativepropertyvaluesource.h>
49 #include <qdeclarative.h>
50 #include <qdeclarativeinfo.h>
51 #include <qdeclarativeexpression.h>
52 #include <private/qdeclarativestringconverters_p.h>
53 #include <private/qdeclarativeglobal_p.h>
54 #include <private/qdeclarativemetatype_p.h>
55 #include <private/qdeclarativevaluetype_p.h>
56 #include <private/qdeclarativeproperty_p.h>
57 #include <private/qdeclarativeengine_p.h>
62 #include <QParallelAnimationGroup>
63 #include <QSequentialAnimationGroup>
64 #include <QtCore/qset.h>
65 #include <QtCore/qrect.h>
66 #include <QtCore/qpoint.h>
67 #include <QtCore/qsize.h>
68 #include <QtCore/qmath.h>
70 #include <private/qvariantanimation_p.h>
75 \qmlclass Animation QDeclarativeAbstractAnimation
76 \inqmlmodule QtQuick 2
77 \ingroup qml-animation-transition
78 \brief The Animation element is the base of all QML animations.
80 The Animation element cannot be used directly in a QML file. It exists
81 to provide a set of common properties and methods, available across all the
82 other animation types that inherit from it. Attempting to use the Animation
83 element directly will result in an error.
86 QDeclarativeAbstractAnimation::QDeclarativeAbstractAnimation(QObject *parent)
87 : QObject(*(new QDeclarativeAbstractAnimationPrivate), parent)
91 QDeclarativeAbstractAnimation::~QDeclarativeAbstractAnimation()
95 QDeclarativeAbstractAnimation::QDeclarativeAbstractAnimation(QDeclarativeAbstractAnimationPrivate &dd, QObject *parent)
101 \qmlproperty bool QtQuick2::Animation::running
102 This property holds whether the animation is currently running.
104 The \c running property can be set to declaratively control whether or not
105 an animation is running. The following example will animate a rectangle
106 whenever the \l MouseArea is pressed.
110 width: 100; height: 100
111 NumberAnimation on x {
112 running: myMouse.pressed
115 MouseArea { id: myMouse }
119 Likewise, the \c running property can be read to determine if the animation
120 is running. In the following example the text element will indicate whether
121 or not the animation is running.
124 NumberAnimation { id: myAnimation }
125 Text { text: myAnimation.running ? "Animation is running" : "Animation is not running" }
128 Animations can also be started and stopped imperatively from JavaScript
129 using the \c start() and \c stop() methods.
131 By default, animations are not running. Though, when the animations are assigned to properties,
132 as property value sources using the \e on syntax, they are set to running by default.
134 bool QDeclarativeAbstractAnimation::isRunning() const
136 Q_D(const QDeclarativeAbstractAnimation);
140 // the behavior calls this function
141 void QDeclarativeAbstractAnimation::notifyRunningChanged(bool running)
143 Q_D(QDeclarativeAbstractAnimation);
144 if (d->disableUserControl && d->running != running) {
145 d->running = running;
146 emit runningChanged(running);
150 //commence is called to start an animation when it is used as a
151 //simple animation, and not as part of a transition
152 void QDeclarativeAbstractAnimationPrivate::commence()
154 Q_Q(QDeclarativeAbstractAnimation);
156 QDeclarativeStateActions actions;
157 QDeclarativeProperties properties;
158 q->transition(actions, properties, QDeclarativeAbstractAnimation::Forward);
160 q->qtAnimation()->start();
161 if (q->qtAnimation()->state() == QAbstractAnimation::Stopped) {
167 QDeclarativeProperty QDeclarativeAbstractAnimationPrivate::createProperty(QObject *obj, const QString &str, QObject *infoObj)
169 QDeclarativeProperty prop(obj, str, qmlContext(infoObj));
170 if (!prop.isValid()) {
171 qmlInfo(infoObj) << QDeclarativeAbstractAnimation::tr("Cannot animate non-existent property \"%1\"").arg(str);
172 return QDeclarativeProperty();
173 } else if (!prop.isWritable()) {
174 qmlInfo(infoObj) << QDeclarativeAbstractAnimation::tr("Cannot animate read-only property \"%1\"").arg(str);
175 return QDeclarativeProperty();
180 void QDeclarativeAbstractAnimation::setRunning(bool r)
182 Q_D(QDeclarativeAbstractAnimation);
183 if (!d->componentComplete) {
186 d->avoidPropertyValueSourceStart = true;
187 else if (!d->registered) {
188 d->registered = true;
189 QDeclarativeEnginePrivate *engPriv = QDeclarativeEnginePrivate::get(qmlEngine(this));
190 engPriv->registerFinalizeCallback(this, this->metaObject()->indexOfSlot("componentFinalized()"));
198 if (d->group || d->disableUserControl) {
199 qmlInfo(this) << "setRunning() cannot be used on non-root animation nodes.";
205 bool supressStart = false;
206 if (d->alwaysRunToEnd && d->loopCount != 1
207 && qtAnimation()->state() == QAbstractAnimation::Running) {
208 //we've restarted before the final loop finished; restore proper loop count
209 if (d->loopCount == -1)
210 qtAnimation()->setLoopCount(d->loopCount);
212 qtAnimation()->setLoopCount(qtAnimation()->currentLoop() + d->loopCount);
213 supressStart = true; //we want the animation to continue, rather than restart
216 if (!d->connectedTimeLine) {
217 FAST_CONNECT(qtAnimation(), SIGNAL(finished()), this, SLOT(timelineComplete()))
218 d->connectedTimeLine = true;
224 if (d->alwaysRunToEnd) {
225 if (d->loopCount != 1)
226 qtAnimation()->setLoopCount(qtAnimation()->currentLoop()+1); //finish the current loop
228 qtAnimation()->stop();
233 emit runningChanged(d->running);
237 \qmlproperty bool QtQuick2::Animation::paused
238 This property holds whether the animation is currently paused.
240 The \c paused property can be set to declaratively control whether or not
241 an animation is paused.
243 Animations can also be paused and resumed imperatively from JavaScript
244 using the \c pause() and \c resume() methods.
246 By default, animations are not paused.
248 bool QDeclarativeAbstractAnimation::isPaused() const
250 Q_D(const QDeclarativeAbstractAnimation);
254 void QDeclarativeAbstractAnimation::setPaused(bool p)
256 Q_D(QDeclarativeAbstractAnimation);
260 if (d->group || d->disableUserControl) {
261 qmlInfo(this) << "setPaused() cannot be used on non-root animation nodes.";
267 if (!d->componentComplete)
271 qtAnimation()->pause();
273 qtAnimation()->resume();
275 emit pausedChanged(d->paused);
278 void QDeclarativeAbstractAnimation::classBegin()
280 Q_D(QDeclarativeAbstractAnimation);
281 d->componentComplete = false;
284 void QDeclarativeAbstractAnimation::componentComplete()
286 Q_D(QDeclarativeAbstractAnimation);
287 d->componentComplete = true;
290 void QDeclarativeAbstractAnimation::componentFinalized()
292 Q_D(QDeclarativeAbstractAnimation);
304 \qmlproperty bool QtQuick2::Animation::alwaysRunToEnd
305 This property holds whether the animation should run to completion when it is stopped.
307 If this true the animation will complete its current iteration when it
308 is stopped - either by setting the \c running property to false, or by
309 calling the \c stop() method. The \c complete() method is not effected
312 This behavior is most useful when the \c repeat property is set, as the
313 animation will finish playing normally but not restart.
315 By default, the alwaysRunToEnd property is not set.
317 \note alwaysRunToEnd has no effect on animations in a Transition.
319 bool QDeclarativeAbstractAnimation::alwaysRunToEnd() const
321 Q_D(const QDeclarativeAbstractAnimation);
322 return d->alwaysRunToEnd;
325 void QDeclarativeAbstractAnimation::setAlwaysRunToEnd(bool f)
327 Q_D(QDeclarativeAbstractAnimation);
328 if (d->alwaysRunToEnd == f)
331 d->alwaysRunToEnd = f;
332 emit alwaysRunToEndChanged(f);
336 \qmlproperty int QtQuick2::Animation::loops
337 This property holds the number of times the animation should play.
339 By default, \c loops is 1: the animation will play through once and then stop.
341 If set to Animation.Infinite, the animation will continuously repeat until it is explicitly
342 stopped - either by setting the \c running property to false, or by calling
343 the \c stop() method.
345 In the following example, the rectangle will spin indefinitely.
349 width: 100; height: 100; color: "green"
350 RotationAnimation on rotation {
351 loops: Animation.Infinite
358 int QDeclarativeAbstractAnimation::loops() const
360 Q_D(const QDeclarativeAbstractAnimation);
364 void QDeclarativeAbstractAnimation::setLoops(int loops)
366 Q_D(QDeclarativeAbstractAnimation);
370 if (loops == d->loopCount)
373 d->loopCount = loops;
374 qtAnimation()->setLoopCount(loops);
375 emit loopCountChanged(loops);
379 int QDeclarativeAbstractAnimation::currentTime()
381 return qtAnimation()->currentLoopTime();
384 void QDeclarativeAbstractAnimation::setCurrentTime(int time)
386 qtAnimation()->setCurrentTime(time);
389 QDeclarativeAnimationGroup *QDeclarativeAbstractAnimation::group() const
391 Q_D(const QDeclarativeAbstractAnimation);
395 void QDeclarativeAbstractAnimation::setGroup(QDeclarativeAnimationGroup *g)
397 Q_D(QDeclarativeAbstractAnimation);
401 static_cast<QDeclarativeAnimationGroupPrivate *>(d->group->d_func())->animations.removeAll(this);
405 if (d->group && !static_cast<QDeclarativeAnimationGroupPrivate *>(d->group->d_func())->animations.contains(this))
406 static_cast<QDeclarativeAnimationGroupPrivate *>(d->group->d_func())->animations.append(this);
408 //if (g) //if removed from a group, then the group should no longer be the parent
413 \qmlmethod QtQuick2::Animation::start()
414 \brief Starts the animation.
416 If the animation is already running, calling this method has no effect. The
417 \c running property will be true following a call to \c start().
419 void QDeclarativeAbstractAnimation::start()
425 \qmlmethod QtQuick2::Animation::pause()
426 \brief Pauses the animation.
428 If the animation is already paused, calling this method has no effect. The
429 \c paused property will be true following a call to \c pause().
431 void QDeclarativeAbstractAnimation::pause()
437 \qmlmethod QtQuick2::Animation::resume()
438 \brief Resumes a paused animation.
440 If the animation is not paused, calling this method has no effect. The
441 \c paused property will be false following a call to \c resume().
443 void QDeclarativeAbstractAnimation::resume()
449 \qmlmethod QtQuick2::Animation::stop()
450 \brief Stops the animation.
452 If the animation is not running, calling this method has no effect. The
453 \c running property will be false following a call to \c stop().
455 Normally \c stop() stops the animation immediately, and the animation has
456 no further influence on property values. In this example animation
459 NumberAnimation on x { from: 0; to: 100; duration: 500 }
462 was stopped at time 250ms, the \c x property will have a value of 50.
464 However, if the \c alwaysRunToEnd property is set, the animation will
465 continue running until it completes and then stop. The \c running property
466 will still become false immediately.
468 void QDeclarativeAbstractAnimation::stop()
474 \qmlmethod QtQuick2::Animation::restart()
475 \brief Restarts the animation.
477 This is a convenience method, and is equivalent to calling \c stop() and
480 void QDeclarativeAbstractAnimation::restart()
487 \qmlmethod QtQuick2::Animation::complete()
488 \brief Stops the animation, jumping to the final property values.
490 If the animation is not running, calling this method has no effect. The
491 \c running property will be false following a call to \c complete().
493 Unlike \c stop(), \c complete() immediately fast-forwards the animation to
494 its end. In the following example,
497 NumberAnimation on x { from: 0; to: 100; duration: 500 }
500 calling \c stop() at time 250ms will result in the \c x property having
501 a value of 50, while calling \c complete() will set the \c x property to
502 100, exactly as though the animation had played the whole way through.
504 void QDeclarativeAbstractAnimation::complete()
507 qtAnimation()->setCurrentTime(qtAnimation()->duration());
511 void QDeclarativeAbstractAnimation::setTarget(const QDeclarativeProperty &p)
513 Q_D(QDeclarativeAbstractAnimation);
514 d->defaultProperty = p;
516 if (!d->avoidPropertyValueSourceStart)
521 we rely on setTarget only being called when used as a value source
522 so this function allows us to do the same thing as setTarget without
525 void QDeclarativeAbstractAnimation::setDefaultTarget(const QDeclarativeProperty &p)
527 Q_D(QDeclarativeAbstractAnimation);
528 d->defaultProperty = p;
532 don't allow start/stop/pause/resume to be manually invoked,
533 because something else (like a Behavior) already has control
536 void QDeclarativeAbstractAnimation::setDisableUserControl()
538 Q_D(QDeclarativeAbstractAnimation);
539 d->disableUserControl = true;
542 void QDeclarativeAbstractAnimation::transition(QDeclarativeStateActions &actions,
543 QDeclarativeProperties &modified,
544 TransitionDirection direction)
551 void QDeclarativeAbstractAnimation::timelineComplete()
553 Q_D(QDeclarativeAbstractAnimation);
555 if (d->alwaysRunToEnd && d->loopCount != 1) {
556 //restore the proper loopCount for the next run
557 qtAnimation()->setLoopCount(d->loopCount);
562 \qmlclass PauseAnimation QDeclarativePauseAnimation
563 \inqmlmodule QtQuick 2
564 \ingroup qml-animation-transition
566 \brief The PauseAnimation element provides a pause for an animation.
568 When used in a SequentialAnimation, PauseAnimation is a step when
569 nothing happens, for a specified duration.
571 A 500ms animation sequence, with a 100ms pause between two animations:
573 SequentialAnimation {
574 NumberAnimation { ... duration: 200 }
575 PauseAnimation { duration: 100 }
576 NumberAnimation { ... duration: 200 }
580 \sa {QML Animation and Transitions}, {declarative/animation/basics}{Animation basics example}
582 QDeclarativePauseAnimation::QDeclarativePauseAnimation(QObject *parent)
583 : QDeclarativeAbstractAnimation(*(new QDeclarativePauseAnimationPrivate), parent)
585 Q_D(QDeclarativePauseAnimation);
589 QDeclarativePauseAnimation::~QDeclarativePauseAnimation()
593 void QDeclarativePauseAnimationPrivate::init()
595 Q_Q(QDeclarativePauseAnimation);
596 pa = new QPauseAnimation;
597 QDeclarative_setParent_noEvent(pa, q);
601 \qmlproperty int QtQuick2::PauseAnimation::duration
602 This property holds the duration of the pause in milliseconds
604 The default value is 250.
606 int QDeclarativePauseAnimation::duration() const
608 Q_D(const QDeclarativePauseAnimation);
609 return d->pa->duration();
612 void QDeclarativePauseAnimation::setDuration(int duration)
615 qmlInfo(this) << tr("Cannot set a duration of < 0");
619 Q_D(QDeclarativePauseAnimation);
620 if (d->pa->duration() == duration)
622 d->pa->setDuration(duration);
623 emit durationChanged(duration);
626 QAbstractAnimation *QDeclarativePauseAnimation::qtAnimation()
628 Q_D(QDeclarativePauseAnimation);
633 \qmlclass ColorAnimation QDeclarativeColorAnimation
634 \inqmlmodule QtQuick 2
635 \ingroup qml-animation-transition
636 \inherits PropertyAnimation
637 \brief The ColorAnimation element animates changes in color values.
639 ColorAnimation is a specialized PropertyAnimation that defines an
640 animation to be applied when a color value changes.
642 Here is a ColorAnimation applied to the \c color property of a \l Rectangle
643 as a property value source. It animates the \c color property's value from
644 its current value to a value of "red", over 1000 milliseconds:
646 \snippet doc/src/snippets/declarative/coloranimation.qml 0
648 Like any other animation element, a ColorAnimation can be applied in a
649 number of ways, including transitions, behaviors and property value
650 sources. The \l {QML Animation and Transitions} documentation shows a
651 variety of methods for creating animations.
653 For convenience, when a ColorAnimation is used in a \l Transition, it will
654 animate any \c color properties that have been modified during the state
655 change. If a \l{PropertyAnimation::}{property} or
656 \l{PropertyAnimation::}{properties} are explicitly set for the animation,
657 then those are used instead.
659 \sa {QML Animation and Transitions}, {declarative/animation/basics}{Animation basics example}
661 QDeclarativeColorAnimation::QDeclarativeColorAnimation(QObject *parent)
662 : QDeclarativePropertyAnimation(parent)
664 Q_D(QDeclarativePropertyAnimation);
665 d->interpolatorType = QMetaType::QColor;
666 d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
667 d->defaultToInterpolatorType = true;
670 QDeclarativeColorAnimation::~QDeclarativeColorAnimation()
675 \qmlproperty color QtQuick2::ColorAnimation::from
676 This property holds the color value at which the animation should begin.
678 For example, the following animation is not applied until a color value
679 has reached "#c0c0c0":
684 // States are defined here...
687 transition: Transition {
688 NumberAnimation { from: "#c0c0c0"; duration: 2000 }
693 If the ColorAnimation is defined within a \l Transition or \l Behavior,
694 this value defaults to the value defined in the starting state of the
695 \l Transition, or the current value of the property at the moment the
696 \l Behavior is triggered.
698 \sa {QML Animation and Transitions}
700 QColor QDeclarativeColorAnimation::from() const
702 Q_D(const QDeclarativePropertyAnimation);
703 return d->from.value<QColor>();
706 void QDeclarativeColorAnimation::setFrom(const QColor &f)
708 QDeclarativePropertyAnimation::setFrom(f);
712 \qmlproperty color QtQuick2::ColorAnimation::to
714 This property holds the color value at which the animation should end.
716 If the ColorAnimation is defined within a \l Transition or \l Behavior,
717 this value defaults to the value defined in the end state of the
718 \l Transition, or the value of the property change that triggered the
721 \sa {QML Animation and Transitions}
723 QColor QDeclarativeColorAnimation::to() const
725 Q_D(const QDeclarativePropertyAnimation);
726 return d->to.value<QColor>();
729 void QDeclarativeColorAnimation::setTo(const QColor &t)
731 QDeclarativePropertyAnimation::setTo(t);
737 \qmlclass ScriptAction QDeclarativeScriptAction
738 \inqmlmodule QtQuick 2
739 \ingroup qml-animation-transition
741 \brief The ScriptAction element allows scripts to be run during an animation.
743 ScriptAction can be used to run a script at a specific point in an animation.
746 SequentialAnimation {
750 ScriptAction { script: doSomething(); }
757 When used as part of a Transition, you can also target a specific
758 StateChangeScript to run using the \c scriptName property.
760 \snippet doc/src/snippets/declarative/states/statechangescript.qml state and transition
762 \sa StateChangeScript
764 QDeclarativeScriptAction::QDeclarativeScriptAction(QObject *parent)
765 :QDeclarativeAbstractAnimation(*(new QDeclarativeScriptActionPrivate), parent)
767 Q_D(QDeclarativeScriptAction);
771 QDeclarativeScriptAction::~QDeclarativeScriptAction()
775 void QDeclarativeScriptActionPrivate::init()
777 Q_Q(QDeclarativeScriptAction);
778 rsa = new QActionAnimation(&proxy);
779 QDeclarative_setParent_noEvent(rsa, q);
783 \qmlproperty script QtQuick2::ScriptAction::script
784 This property holds the script to run.
786 QDeclarativeScriptString QDeclarativeScriptAction::script() const
788 Q_D(const QDeclarativeScriptAction);
792 void QDeclarativeScriptAction::setScript(const QDeclarativeScriptString &script)
794 Q_D(QDeclarativeScriptAction);
799 \qmlproperty string QtQuick2::ScriptAction::scriptName
800 This property holds the the name of the StateChangeScript to run.
802 This property is only valid when ScriptAction is used as part of a transition.
803 If both script and scriptName are set, scriptName will be used.
805 \note When using scriptName in a reversible transition, the script will only
806 be run when the transition is being run forwards.
808 QString QDeclarativeScriptAction::stateChangeScriptName() const
810 Q_D(const QDeclarativeScriptAction);
814 void QDeclarativeScriptAction::setStateChangeScriptName(const QString &name)
816 Q_D(QDeclarativeScriptAction);
820 void QDeclarativeScriptActionPrivate::execute()
822 Q_Q(QDeclarativeScriptAction);
823 if (hasRunScriptScript && reversing)
826 QDeclarativeScriptString scriptStr = hasRunScriptScript ? runScriptScript : script;
828 if (!scriptStr.script().isEmpty()) {
829 QDeclarativeExpression expr(scriptStr);
832 qmlInfo(q) << expr.error();
836 void QDeclarativeScriptAction::transition(QDeclarativeStateActions &actions,
837 QDeclarativeProperties &modified,
838 TransitionDirection direction)
840 Q_D(QDeclarativeScriptAction);
843 d->hasRunScriptScript = false;
844 d->reversing = (direction == Backward);
845 for (int ii = 0; ii < actions.count(); ++ii) {
846 QDeclarativeAction &action = actions[ii];
848 if (action.event && action.event->typeName() == QLatin1String("StateChangeScript")
849 && static_cast<QDeclarativeStateChangeScript*>(action.event)->name() == d->name) {
850 d->runScriptScript = static_cast<QDeclarativeStateChangeScript*>(action.event)->script();
851 d->hasRunScriptScript = true;
852 action.actionDone = true;
853 break; //only match one (names should be unique)
858 QAbstractAnimation *QDeclarativeScriptAction::qtAnimation()
860 Q_D(QDeclarativeScriptAction);
867 \qmlclass PropertyAction QDeclarativePropertyAction
868 \inqmlmodule QtQuick 2
869 \ingroup qml-animation-transition
871 \brief The PropertyAction element allows immediate property changes during animation.
873 PropertyAction is used to specify an immediate property change during an
874 animation. The property change is not animated.
876 It is useful for setting non-animated property values during an animation.
878 For example, here is a SequentialAnimation that sets the image's
879 \l {Image::}{smooth} property to \c true, animates the width of the image,
880 then sets \l {Image::}{smooth} back to \c false:
882 \snippet doc/src/snippets/declarative/propertyaction.qml standalone
884 PropertyAction is also useful for setting the exact point at which a property
885 change should occur during a \l Transition. For example, if PropertyChanges
886 was used in a \l State to rotate an item around a particular
887 \l {Item::}{transformOrigin}, it might be implemented like this:
889 \snippet doc/src/snippets/declarative/propertyaction.qml transition
891 However, with this code, the \c transformOrigin is not set until \e after
892 the animation, as a \l State is taken to define the values at the \e end of
893 a transition. The animation would rotate at the default \c transformOrigin,
894 then jump to \c Item.BottomRight. To fix this, insert a PropertyAction
895 before the RotationAnimation begins:
897 \snippet doc/src/snippets/declarative/propertyaction-sequential.qml sequential
899 This immediately sets the \c transformOrigin property to the value defined
900 in the end state of the \l Transition (i.e. the value defined in the
901 PropertyAction object) so that the rotation animation begins with the
902 correct transform origin.
904 \sa {QML Animation and Transitions}, QtDeclarative
906 QDeclarativePropertyAction::QDeclarativePropertyAction(QObject *parent)
907 : QDeclarativeAbstractAnimation(*(new QDeclarativePropertyActionPrivate), parent)
909 Q_D(QDeclarativePropertyAction);
913 QDeclarativePropertyAction::~QDeclarativePropertyAction()
917 void QDeclarativePropertyActionPrivate::init()
919 Q_Q(QDeclarativePropertyAction);
920 spa = new QActionAnimation;
921 QDeclarative_setParent_noEvent(spa, q);
924 QObject *QDeclarativePropertyAction::target() const
926 Q_D(const QDeclarativePropertyAction);
930 void QDeclarativePropertyAction::setTarget(QObject *o)
932 Q_D(QDeclarativePropertyAction);
936 emit targetChanged();
939 QString QDeclarativePropertyAction::property() const
941 Q_D(const QDeclarativePropertyAction);
942 return d->propertyName;
945 void QDeclarativePropertyAction::setProperty(const QString &n)
947 Q_D(QDeclarativePropertyAction);
948 if (d->propertyName == n)
951 emit propertyChanged();
955 \qmlproperty Object QtQuick2::PropertyAction::target
956 \qmlproperty list<Object> QtQuick2::PropertyAction::targets
957 \qmlproperty string QtQuick2::PropertyAction::property
958 \qmlproperty string QtQuick2::PropertyAction::properties
960 These properties determine the items and their properties that are
961 affected by this action.
963 The details of how these properties are interpreted in different situations
964 is covered in the \l{PropertyAnimation::properties}{corresponding} PropertyAnimation
969 QString QDeclarativePropertyAction::properties() const
971 Q_D(const QDeclarativePropertyAction);
972 return d->properties;
975 void QDeclarativePropertyAction::setProperties(const QString &p)
977 Q_D(QDeclarativePropertyAction);
978 if (d->properties == p)
981 emit propertiesChanged(p);
984 QDeclarativeListProperty<QObject> QDeclarativePropertyAction::targets()
986 Q_D(QDeclarativePropertyAction);
987 return QDeclarativeListProperty<QObject>(this, d->targets);
991 \qmlproperty list<Object> QtQuick2::PropertyAction::exclude
992 This property holds the objects that should not be affected by this action.
996 QDeclarativeListProperty<QObject> QDeclarativePropertyAction::exclude()
998 Q_D(QDeclarativePropertyAction);
999 return QDeclarativeListProperty<QObject>(this, d->exclude);
1003 \qmlproperty any QtQuick2::PropertyAction::value
1004 This property holds the value to be set on the property.
1006 If the PropertyAction is defined within a \l Transition or \l Behavior,
1007 this value defaults to the value defined in the end state of the
1008 \l Transition, or the value of the property change that triggered the
1011 QVariant QDeclarativePropertyAction::value() const
1013 Q_D(const QDeclarativePropertyAction);
1017 void QDeclarativePropertyAction::setValue(const QVariant &v)
1019 Q_D(QDeclarativePropertyAction);
1020 if (d->value.isNull || d->value != v) {
1022 emit valueChanged(v);
1026 QAbstractAnimation *QDeclarativePropertyAction::qtAnimation()
1028 Q_D(QDeclarativePropertyAction);
1032 void QDeclarativePropertyAction::transition(QDeclarativeStateActions &actions,
1033 QDeclarativeProperties &modified,
1034 TransitionDirection direction)
1036 Q_D(QDeclarativePropertyAction);
1037 Q_UNUSED(direction);
1039 struct QDeclarativeSetPropertyAnimationAction : public QAbstractAnimationAction
1041 QDeclarativeStateActions actions;
1042 virtual void doAction()
1044 for (int ii = 0; ii < actions.count(); ++ii) {
1045 const QDeclarativeAction &action = actions.at(ii);
1046 QDeclarativePropertyPrivate::write(action.property, action.toValue, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding);
1051 QStringList props = d->properties.isEmpty() ? QStringList() : d->properties.split(QLatin1Char(','));
1052 for (int ii = 0; ii < props.count(); ++ii)
1053 props[ii] = props.at(ii).trimmed();
1054 if (!d->propertyName.isEmpty())
1055 props << d->propertyName;
1057 QList<QObject*> targets = d->targets;
1059 targets.append(d->target);
1061 bool hasSelectors = !props.isEmpty() || !targets.isEmpty() || !d->exclude.isEmpty();
1063 if (d->defaultProperty.isValid() && !hasSelectors) {
1064 props << d->defaultProperty.name();
1065 targets << d->defaultProperty.object();
1068 QDeclarativeSetPropertyAnimationAction *data = new QDeclarativeSetPropertyAnimationAction;
1070 bool hasExplicit = false;
1071 //an explicit animation has been specified
1072 if (d->value.isValid()) {
1073 for (int i = 0; i < props.count(); ++i) {
1074 for (int j = 0; j < targets.count(); ++j) {
1075 QDeclarativeAction myAction;
1076 myAction.property = d->createProperty(targets.at(j), props.at(i), this);
1077 if (myAction.property.isValid()) {
1078 myAction.toValue = d->value;
1079 QDeclarativePropertyAnimationPrivate::convertVariant(myAction.toValue, myAction.property.propertyType());
1080 data->actions << myAction;
1082 for (int ii = 0; ii < actions.count(); ++ii) {
1083 QDeclarativeAction &action = actions[ii];
1084 if (action.property.object() == myAction.property.object() &&
1085 myAction.property.name() == action.property.name()) {
1086 modified << action.property;
1087 break; //### any chance there could be multiples?
1096 for (int ii = 0; ii < actions.count(); ++ii) {
1097 QDeclarativeAction &action = actions[ii];
1099 QObject *obj = action.property.object();
1100 QString propertyName = action.property.name();
1101 QObject *sObj = action.specifiedObject;
1102 QString sPropertyName = action.specifiedProperty;
1103 bool same = (obj == sObj);
1105 if ((targets.isEmpty() || targets.contains(obj) || (!same && targets.contains(sObj))) &&
1106 (!d->exclude.contains(obj)) && (same || (!d->exclude.contains(sObj))) &&
1107 (props.contains(propertyName) || (!same && props.contains(sPropertyName)))) {
1108 QDeclarativeAction myAction = action;
1110 if (d->value.isValid())
1111 myAction.toValue = d->value;
1112 QDeclarativePropertyAnimationPrivate::convertVariant(myAction.toValue, myAction.property.propertyType());
1114 modified << action.property;
1115 data->actions << myAction;
1116 action.fromValue = myAction.toValue;
1120 if (data->actions.count()) {
1121 d->spa->setAnimAction(data, QAbstractAnimation::DeleteWhenStopped);
1128 \qmlclass NumberAnimation QDeclarativeNumberAnimation
1129 \inqmlmodule QtQuick 2
1130 \ingroup qml-animation-transition
1131 \inherits PropertyAnimation
1132 \brief The NumberAnimation element animates changes in qreal-type values.
1134 NumberAnimation is a specialized PropertyAnimation that defines an
1135 animation to be applied when a numerical value changes.
1137 Here is a NumberAnimation applied to the \c x property of a \l Rectangle
1138 as a property value source. It animates the \c x value from its current
1139 value to a value of 50, over 1000 milliseconds:
1141 \snippet doc/src/snippets/declarative/numberanimation.qml 0
1143 Like any other animation element, a NumberAnimation can be applied in a
1144 number of ways, including transitions, behaviors and property value
1145 sources. The \l {QML Animation and Transitions} documentation shows a
1146 variety of methods for creating animations.
1148 Note that NumberAnimation may not animate smoothly if there are irregular
1149 changes in the number value that it is tracking. If this is the case, use
1150 SmoothedAnimation instead.
1152 \sa {QML Animation and Transitions}, {declarative/animation/basics}{Animation basics example}
1154 QDeclarativeNumberAnimation::QDeclarativeNumberAnimation(QObject *parent)
1155 : QDeclarativePropertyAnimation(parent)
1160 QDeclarativeNumberAnimation::QDeclarativeNumberAnimation(QDeclarativePropertyAnimationPrivate &dd, QObject *parent)
1161 : QDeclarativePropertyAnimation(dd, parent)
1166 QDeclarativeNumberAnimation::~QDeclarativeNumberAnimation()
1170 void QDeclarativeNumberAnimation::init()
1172 Q_D(QDeclarativePropertyAnimation);
1173 d->interpolatorType = QMetaType::QReal;
1174 d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
1178 \qmlproperty real QtQuick2::NumberAnimation::from
1179 This property holds the starting value for the animation.
1181 For example, the following animation is not applied until the \c x value
1190 transition: Transition {
1191 NumberAnimation { properties: "x"; from: 100; duration: 200 }
1196 If the NumberAnimation is defined within a \l Transition or \l Behavior,
1197 this value defaults to the value defined in the starting state of the
1198 \l Transition, or the current value of the property at the moment the
1199 \l Behavior is triggered.
1201 \sa {QML Animation and Transitions}
1204 qreal QDeclarativeNumberAnimation::from() const
1206 Q_D(const QDeclarativePropertyAnimation);
1207 return d->from.toReal();
1210 void QDeclarativeNumberAnimation::setFrom(qreal f)
1212 QDeclarativePropertyAnimation::setFrom(f);
1216 \qmlproperty real QtQuick2::NumberAnimation::to
1217 This property holds the end value for the animation.
1219 If the NumberAnimation is defined within a \l Transition or \l Behavior,
1220 this value defaults to the value defined in the end state of the
1221 \l Transition, or the value of the property change that triggered the
1224 \sa {QML Animation and Transitions}
1226 qreal QDeclarativeNumberAnimation::to() const
1228 Q_D(const QDeclarativePropertyAnimation);
1229 return d->to.toReal();
1232 void QDeclarativeNumberAnimation::setTo(qreal t)
1234 QDeclarativePropertyAnimation::setTo(t);
1240 \qmlclass Vector3dAnimation QDeclarativeVector3dAnimation
1241 \inqmlmodule QtQuick 2
1242 \ingroup qml-animation-transition
1243 \inherits PropertyAnimation
1244 \brief The Vector3dAnimation element animates changes in QVector3d values.
1246 Vector3dAnimation is a specialized PropertyAnimation that defines an
1247 animation to be applied when a Vector3d value changes.
1249 Like any other animation element, a Vector3dAnimation can be applied in a
1250 number of ways, including transitions, behaviors and property value
1251 sources. The \l {QML Animation and Transitions} documentation shows a
1252 variety of methods for creating animations.
1254 \sa {QML Animation and Transitions}, {declarative/animation/basics}{Animation basics example}
1256 QDeclarativeVector3dAnimation::QDeclarativeVector3dAnimation(QObject *parent)
1257 : QDeclarativePropertyAnimation(parent)
1259 Q_D(QDeclarativePropertyAnimation);
1260 d->interpolatorType = QMetaType::QVector3D;
1261 d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
1262 d->defaultToInterpolatorType = true;
1265 QDeclarativeVector3dAnimation::~QDeclarativeVector3dAnimation()
1270 \qmlproperty real QtQuick2::Vector3dAnimation::from
1271 This property holds the starting value for the animation.
1273 If the Vector3dAnimation is defined within a \l Transition or \l Behavior,
1274 this value defaults to the value defined in the starting state of the
1275 \l Transition, or the current value of the property at the moment the
1276 \l Behavior is triggered.
1278 \sa {QML Animation and Transitions}
1280 QVector3D QDeclarativeVector3dAnimation::from() const
1282 Q_D(const QDeclarativePropertyAnimation);
1283 return d->from.value<QVector3D>();
1286 void QDeclarativeVector3dAnimation::setFrom(QVector3D f)
1288 QDeclarativePropertyAnimation::setFrom(f);
1292 \qmlproperty real QtQuick2::Vector3dAnimation::to
1293 This property holds the end value for the animation.
1295 If the Vector3dAnimation is defined within a \l Transition or \l Behavior,
1296 this value defaults to the value defined in the end state of the
1297 \l Transition, or the value of the property change that triggered the
1300 \sa {QML Animation and Transitions}
1302 QVector3D QDeclarativeVector3dAnimation::to() const
1304 Q_D(const QDeclarativePropertyAnimation);
1305 return d->to.value<QVector3D>();
1308 void QDeclarativeVector3dAnimation::setTo(QVector3D t)
1310 QDeclarativePropertyAnimation::setTo(t);
1316 \qmlclass RotationAnimation QDeclarativeRotationAnimation
1317 \inqmlmodule QtQuick 2
1318 \ingroup qml-animation-transition
1319 \inherits PropertyAnimation
1320 \brief The RotationAnimation element animates changes in rotation values.
1322 RotationAnimation is a specialized PropertyAnimation that gives control
1323 over the direction of rotation during an animation.
1325 By default, it rotates in the direction
1326 of the numerical change; a rotation from 0 to 240 will rotate 240 degrees
1327 clockwise, while a rotation from 240 to 0 will rotate 240 degrees
1328 counterclockwise. The \l direction property can be set to specify the
1329 direction in which the rotation should occur.
1331 In the following example we use RotationAnimation to animate the rotation
1332 between states via the shortest path:
1334 \snippet doc/src/snippets/declarative/rotationanimation.qml 0
1336 Notice the RotationAnimation did not need to set a \l target
1337 value. As a convenience, when used in a transition, RotationAnimation will rotate all
1338 properties named "rotation" or "angle". You can override this by providing
1339 your own properties via \l {PropertyAnimation::properties}{properties} or
1340 \l {PropertyAnimation::property}{property}.
1342 Also, note the \l Rectangle will be rotated around its default
1343 \l {Item::}{transformOrigin} (which is \c Item.Center). To use a different
1344 transform origin, set the origin in the PropertyChanges object and apply
1345 the change at the start of the animation using PropertyAction. See the
1346 PropertyAction documentation for more details.
1348 Like any other animation element, a RotationAnimation can be applied in a
1349 number of ways, including transitions, behaviors and property value
1350 sources. The \l {QML Animation and Transitions} documentation shows a
1351 variety of methods for creating animations.
1353 \sa {QML Animation and Transitions}, {declarative/animation/basics}{Animation basics example}
1355 QVariant _q_interpolateShortestRotation(qreal &f, qreal &t, qreal progress)
1359 while(diff > 180.0){
1363 while(diff < -180.0){
1367 return QVariant(f + (newt - f) * progress);
1370 QVariant _q_interpolateClockwiseRotation(qreal &f, qreal &t, qreal progress)
1378 return QVariant(f + (newt - f) * progress);
1381 QVariant _q_interpolateCounterclockwiseRotation(qreal &f, qreal &t, qreal progress)
1389 return QVariant(f + (newt - f) * progress);
1392 QDeclarativeRotationAnimation::QDeclarativeRotationAnimation(QObject *parent)
1393 : QDeclarativePropertyAnimation(*(new QDeclarativeRotationAnimationPrivate), parent)
1395 Q_D(QDeclarativeRotationAnimation);
1396 d->interpolatorType = QMetaType::QReal;
1397 d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
1398 d->defaultProperties = QLatin1String("rotation,angle");
1401 QDeclarativeRotationAnimation::~QDeclarativeRotationAnimation()
1406 \qmlproperty real QtQuick2::RotationAnimation::from
1407 This property holds the starting value for the animation.
1409 For example, the following animation is not applied until the \c angle value
1418 transition: Transition {
1419 RotationAnimation { properties: "angle"; from: 100; duration: 2000 }
1424 If the RotationAnimation is defined within a \l Transition or \l Behavior,
1425 this value defaults to the value defined in the starting state of the
1426 \l Transition, or the current value of the property at the moment the
1427 \l Behavior is triggered.
1429 \sa {QML Animation and Transitions}
1431 qreal QDeclarativeRotationAnimation::from() const
1433 Q_D(const QDeclarativeRotationAnimation);
1434 return d->from.toReal();
1437 void QDeclarativeRotationAnimation::setFrom(qreal f)
1439 QDeclarativePropertyAnimation::setFrom(f);
1443 \qmlproperty real QtQuick2::RotationAnimation::to
1444 This property holds the end value for the animation..
1446 If the RotationAnimation is defined within a \l Transition or \l Behavior,
1447 this value defaults to the value defined in the end state of the
1448 \l Transition, or the value of the property change that triggered the
1451 \sa {QML Animation and Transitions}
1453 qreal QDeclarativeRotationAnimation::to() const
1455 Q_D(const QDeclarativeRotationAnimation);
1456 return d->to.toReal();
1459 void QDeclarativeRotationAnimation::setTo(qreal t)
1461 QDeclarativePropertyAnimation::setTo(t);
1465 \qmlproperty enumeration QtQuick2::RotationAnimation::direction
1466 This property holds the direction of the rotation.
1468 Possible values are:
1471 \o RotationAnimation.Numerical (default) - Rotate by linearly interpolating between the two numbers.
1472 A rotation from 10 to 350 will rotate 340 degrees clockwise.
1473 \o RotationAnimation.Clockwise - Rotate clockwise between the two values
1474 \o RotationAnimation.Counterclockwise - Rotate counterclockwise between the two values
1475 \o RotationAnimation.Shortest - Rotate in the direction that produces the shortest animation path.
1476 A rotation from 10 to 350 will rotate 20 degrees counterclockwise.
1479 QDeclarativeRotationAnimation::RotationDirection QDeclarativeRotationAnimation::direction() const
1481 Q_D(const QDeclarativeRotationAnimation);
1482 return d->direction;
1485 void QDeclarativeRotationAnimation::setDirection(QDeclarativeRotationAnimation::RotationDirection direction)
1487 Q_D(QDeclarativeRotationAnimation);
1488 if (d->direction == direction)
1491 d->direction = direction;
1492 switch(d->direction) {
1494 d->interpolator = reinterpret_cast<QVariantAnimation::Interpolator>(&_q_interpolateClockwiseRotation);
1496 case Counterclockwise:
1497 d->interpolator = reinterpret_cast<QVariantAnimation::Interpolator>(&_q_interpolateCounterclockwiseRotation);
1500 d->interpolator = reinterpret_cast<QVariantAnimation::Interpolator>(&_q_interpolateShortestRotation);
1503 d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
1507 emit directionChanged();
1512 QDeclarativeAnimationGroup::QDeclarativeAnimationGroup(QObject *parent)
1513 : QDeclarativeAbstractAnimation(*(new QDeclarativeAnimationGroupPrivate), parent)
1517 QDeclarativeAnimationGroup::QDeclarativeAnimationGroup(QDeclarativeAnimationGroupPrivate &dd, QObject *parent)
1518 : QDeclarativeAbstractAnimation(dd, parent)
1522 void QDeclarativeAnimationGroupPrivate::append_animation(QDeclarativeListProperty<QDeclarativeAbstractAnimation> *list, QDeclarativeAbstractAnimation *a)
1524 QDeclarativeAnimationGroup *q = qobject_cast<QDeclarativeAnimationGroup *>(list->object);
1527 // This is an optimization for the parenting that already occurs via addAnimation
1528 QDeclarative_setParent_noEvent(a->qtAnimation(), q->d_func()->ag);
1529 q->d_func()->ag->addAnimation(a->qtAnimation());
1533 void QDeclarativeAnimationGroupPrivate::clear_animation(QDeclarativeListProperty<QDeclarativeAbstractAnimation> *list)
1535 QDeclarativeAnimationGroup *q = qobject_cast<QDeclarativeAnimationGroup *>(list->object);
1537 while (q->d_func()->animations.count()) {
1538 QDeclarativeAbstractAnimation *firstAnim = q->d_func()->animations.at(0);
1539 QDeclarative_setParent_noEvent(firstAnim->qtAnimation(), 0);
1540 q->d_func()->ag->removeAnimation(firstAnim->qtAnimation());
1541 firstAnim->setGroup(0);
1546 QDeclarativeAnimationGroup::~QDeclarativeAnimationGroup()
1550 QDeclarativeListProperty<QDeclarativeAbstractAnimation> QDeclarativeAnimationGroup::animations()
1552 Q_D(QDeclarativeAnimationGroup);
1553 QDeclarativeListProperty<QDeclarativeAbstractAnimation> list(this, d->animations);
1554 list.append = &QDeclarativeAnimationGroupPrivate::append_animation;
1555 list.clear = &QDeclarativeAnimationGroupPrivate::clear_animation;
1560 \qmlclass SequentialAnimation QDeclarativeSequentialAnimation
1561 \inqmlmodule QtQuick 2
1562 \ingroup qml-animation-transition
1564 \brief The SequentialAnimation element allows animations to be run sequentially.
1566 The SequentialAnimation and ParallelAnimation elements allow multiple
1567 animations to be run together. Animations defined in a SequentialAnimation
1568 are run one after the other, while animations defined in a ParallelAnimation
1569 are run at the same time.
1571 The following example runs two number animations in a sequence. The \l Rectangle
1572 animates to a \c x position of 50, then to a \c y position of 50.
1574 \snippet doc/src/snippets/declarative/sequentialanimation.qml 0
1576 Animations defined within a \l Transition are automatically run in parallel,
1577 so SequentialAnimation can be used to enclose the animations in a \l Transition
1578 if this is the preferred behavior.
1580 Like any other animation element, a SequentialAnimation can be applied in a
1581 number of ways, including transitions, behaviors and property value
1582 sources. The \l {QML Animation and Transitions} documentation shows a
1583 variety of methods for creating animations.
1585 \note Once an animation has been grouped into a SequentialAnimation or
1586 ParallelAnimation, it cannot be individually started and stopped; the
1587 SequentialAnimation or ParallelAnimation must be started and stopped as a group.
1589 \sa ParallelAnimation, {QML Animation and Transitions}, {declarative/animation/basics}{Animation basics example}
1592 QDeclarativeSequentialAnimation::QDeclarativeSequentialAnimation(QObject *parent) :
1593 QDeclarativeAnimationGroup(parent)
1595 Q_D(QDeclarativeAnimationGroup);
1596 d->ag = new QSequentialAnimationGroup;
1597 QDeclarative_setParent_noEvent(d->ag, this);
1600 QDeclarativeSequentialAnimation::~QDeclarativeSequentialAnimation()
1604 QAbstractAnimation *QDeclarativeSequentialAnimation::qtAnimation()
1606 Q_D(QDeclarativeAnimationGroup);
1610 void QDeclarativeSequentialAnimation::transition(QDeclarativeStateActions &actions,
1611 QDeclarativeProperties &modified,
1612 TransitionDirection direction)
1614 Q_D(QDeclarativeAnimationGroup);
1618 if (direction == Backward) {
1620 from = d->animations.count() - 1;
1623 bool valid = d->defaultProperty.isValid();
1624 for (int ii = from; ii < d->animations.count() && ii >= 0; ii += inc) {
1626 d->animations.at(ii)->setDefaultTarget(d->defaultProperty);
1627 d->animations.at(ii)->transition(actions, modified, direction);
1634 \qmlclass ParallelAnimation QDeclarativeParallelAnimation
1635 \inqmlmodule QtQuick 2
1636 \ingroup qml-animation-transition
1638 \brief The ParallelAnimation element allows animations to be run in parallel.
1640 The SequentialAnimation and ParallelAnimation elements allow multiple
1641 animations to be run together. Animations defined in a SequentialAnimation
1642 are run one after the other, while animations defined in a ParallelAnimation
1643 are run at the same time.
1645 The following animation runs two number animations in parallel. The \l Rectangle
1646 moves to (50,50) by animating its \c x and \c y properties at the same time.
1648 \snippet doc/src/snippets/declarative/parallelanimation.qml 0
1650 Like any other animation element, a ParallelAnimation can be applied in a
1651 number of ways, including transitions, behaviors and property value
1652 sources. The \l {QML Animation and Transitions} documentation shows a
1653 variety of methods for creating animations.
1655 \note Once an animation has been grouped into a SequentialAnimation or
1656 ParallelAnimation, it cannot be individually started and stopped; the
1657 SequentialAnimation or ParallelAnimation must be started and stopped as a group.
1659 \sa SequentialAnimation, {QML Animation and Transitions}, {declarative/animation/basics}{Animation basics example}
1661 QDeclarativeParallelAnimation::QDeclarativeParallelAnimation(QObject *parent) :
1662 QDeclarativeAnimationGroup(parent)
1664 Q_D(QDeclarativeAnimationGroup);
1665 d->ag = new QParallelAnimationGroup;
1666 QDeclarative_setParent_noEvent(d->ag, this);
1669 QDeclarativeParallelAnimation::~QDeclarativeParallelAnimation()
1673 QAbstractAnimation *QDeclarativeParallelAnimation::qtAnimation()
1675 Q_D(QDeclarativeAnimationGroup);
1679 void QDeclarativeParallelAnimation::transition(QDeclarativeStateActions &actions,
1680 QDeclarativeProperties &modified,
1681 TransitionDirection direction)
1683 Q_D(QDeclarativeAnimationGroup);
1684 bool valid = d->defaultProperty.isValid();
1685 for (int ii = 0; ii < d->animations.count(); ++ii) {
1687 d->animations.at(ii)->setDefaultTarget(d->defaultProperty);
1688 d->animations.at(ii)->transition(actions, modified, direction);
1694 //convert a variant from string type to another animatable type
1695 void QDeclarativePropertyAnimationPrivate::convertVariant(QVariant &variant, int type)
1697 if (variant.userType() != QVariant::String) {
1698 variant.convert((QVariant::Type)type);
1703 case QVariant::Rect: {
1704 variant.setValue(QDeclarativeStringConverters::rectFFromString(variant.toString()).toRect());
1707 case QVariant::RectF: {
1708 variant.setValue(QDeclarativeStringConverters::rectFFromString(variant.toString()));
1711 case QVariant::Point: {
1712 variant.setValue(QDeclarativeStringConverters::pointFFromString(variant.toString()).toPoint());
1715 case QVariant::PointF: {
1716 variant.setValue(QDeclarativeStringConverters::pointFFromString(variant.toString()));
1719 case QVariant::Size: {
1720 variant.setValue(QDeclarativeStringConverters::sizeFFromString(variant.toString()).toSize());
1723 case QVariant::SizeF: {
1724 variant.setValue(QDeclarativeStringConverters::sizeFFromString(variant.toString()));
1727 case QVariant::Color: {
1728 variant.setValue(QDeclarativeStringConverters::colorFromString(variant.toString()));
1731 case QVariant::Vector3D: {
1732 variant.setValue(QDeclarativeStringConverters::vector3DFromString(variant.toString()));
1736 if (QDeclarativeValueTypeFactory::isValueType((uint)type)) {
1737 variant.convert((QVariant::Type)type);
1739 QDeclarativeMetaType::StringConverter converter = QDeclarativeMetaType::customStringConverter(type);
1741 variant = converter(variant.toString());
1748 \qmlclass PropertyAnimation QDeclarativePropertyAnimation
1749 \inqmlmodule QtQuick 2
1750 \ingroup qml-animation-transition
1752 \brief The PropertyAnimation element animates changes in property values.
1754 PropertyAnimation provides a way to animate changes to a property's value.
1756 It can be used to define animations in a number of ways:
1759 \o In a \l Transition
1761 For example, to animate any objects that have changed their \c x or \c y properties
1762 as a result of a state change, using an \c InOutQuad easing curve:
1764 \snippet doc/src/snippets/declarative/propertyanimation.qml transition
1769 For example, to animate all changes to a rectangle's \c x property:
1771 \snippet doc/src/snippets/declarative/propertyanimation.qml behavior
1774 \o As a property value source
1776 For example, to repeatedly animate the rectangle's \c x property:
1778 \snippet doc/src/snippets/declarative/propertyanimation.qml propertyvaluesource
1781 \o In a signal handler
1783 For example, to fade out \c theObject when clicked:
1786 anchors.fill: theObject
1787 onClicked: PropertyAnimation { target: theObject; property: "opacity"; to: 0 }
1793 For example, to animate \c rect's \c width property over 500ms, from its current width to 30:
1795 \snippet doc/src/snippets/declarative/propertyanimation.qml standalone
1799 Depending on how the animation is used, the set of properties normally used will be
1800 different. For more information see the individual property documentation, as well
1801 as the \l{QML Animation and Transitions} introduction.
1803 Note that PropertyAnimation inherits the abstract \l Animation element.
1804 This includes additional properties and methods for controlling the animation.
1806 \sa {QML Animation and Transitions}, {declarative/animation/basics}{Animation basics example}
1809 QDeclarativePropertyAnimation::QDeclarativePropertyAnimation(QObject *parent)
1810 : QDeclarativeAbstractAnimation(*(new QDeclarativePropertyAnimationPrivate), parent)
1812 Q_D(QDeclarativePropertyAnimation);
1816 QDeclarativePropertyAnimation::QDeclarativePropertyAnimation(QDeclarativePropertyAnimationPrivate &dd, QObject *parent)
1817 : QDeclarativeAbstractAnimation(dd, parent)
1819 Q_D(QDeclarativePropertyAnimation);
1823 QDeclarativePropertyAnimation::~QDeclarativePropertyAnimation()
1827 void QDeclarativePropertyAnimationPrivate::init()
1829 Q_Q(QDeclarativePropertyAnimation);
1830 va = new QDeclarativeBulkValueAnimator;
1831 QDeclarative_setParent_noEvent(va, q);
1835 \qmlproperty int QtQuick2::PropertyAnimation::duration
1836 This property holds the duration of the animation, in milliseconds.
1838 The default value is 250.
1840 int QDeclarativePropertyAnimation::duration() const
1842 Q_D(const QDeclarativePropertyAnimation);
1843 return d->va->duration();
1846 void QDeclarativePropertyAnimation::setDuration(int duration)
1849 qmlInfo(this) << tr("Cannot set a duration of < 0");
1853 Q_D(QDeclarativePropertyAnimation);
1854 if (d->va->duration() == duration)
1856 d->va->setDuration(duration);
1857 emit durationChanged(duration);
1861 \qmlproperty real QtQuick2::PropertyAnimation::from
1862 This property holds the starting value for the animation.
1864 If the PropertyAnimation is defined within a \l Transition or \l Behavior,
1865 this value defaults to the value defined in the starting state of the
1866 \l Transition, or the current value of the property at the moment the
1867 \l Behavior is triggered.
1869 \sa {QML Animation and Transitions}
1871 QVariant QDeclarativePropertyAnimation::from() const
1873 Q_D(const QDeclarativePropertyAnimation);
1877 void QDeclarativePropertyAnimation::setFrom(const QVariant &f)
1879 Q_D(QDeclarativePropertyAnimation);
1880 if (d->fromIsDefined && f == d->from)
1883 d->fromIsDefined = f.isValid();
1884 emit fromChanged(f);
1888 \qmlproperty real QtQuick2::PropertyAnimation::to
1889 This property holds the end value for the animation.
1891 If the PropertyAnimation is defined within a \l Transition or \l Behavior,
1892 this value defaults to the value defined in the end state of the
1893 \l Transition, or the value of the property change that triggered the
1896 \sa {QML Animation and Transitions}
1898 QVariant QDeclarativePropertyAnimation::to() const
1900 Q_D(const QDeclarativePropertyAnimation);
1904 void QDeclarativePropertyAnimation::setTo(const QVariant &t)
1906 Q_D(QDeclarativePropertyAnimation);
1907 if (d->toIsDefined && t == d->to)
1910 d->toIsDefined = t.isValid();
1915 \qmlproperty enumeration QtQuick2::PropertyAnimation::easing.type
1916 \qmlproperty real QtQuick2::PropertyAnimation::easing.amplitude
1917 \qmlproperty real QtQuick2::PropertyAnimation::easing.overshoot
1918 \qmlproperty real QtQuick2::PropertyAnimation::easing.period
1919 \qmlproperty list<real> QtQuick2::PropertyAnimation::easing.bezierCurve
1920 \brief the easing curve used for the animation.
1922 To specify an easing curve you need to specify at least the type. For some curves you can also specify
1923 amplitude, period and/or overshoot (more details provided after the table). The default easing curve is
1927 PropertyAnimation { properties: "y"; easing.type: Easing.InOutElastic; easing.amplitude: 2.0; easing.period: 1.5 }
1930 Available types are:
1935 \o Easing curve for a linear (t) function: velocity is constant.
1936 \o \inlineimage qeasingcurve-linear.png
1939 \o Easing curve for a quadratic (t^2) function: accelerating from zero velocity.
1940 \o \inlineimage qeasingcurve-inquad.png
1942 \o \c Easing.OutQuad
1943 \o Easing curve for a quadratic (t^2) function: decelerating to zero velocity.
1944 \o \inlineimage qeasingcurve-outquad.png
1946 \o \c Easing.InOutQuad
1947 \o Easing curve for a quadratic (t^2) function: acceleration until halfway, then deceleration.
1948 \o \inlineimage qeasingcurve-inoutquad.png
1950 \o \c Easing.OutInQuad
1951 \o Easing curve for a quadratic (t^2) function: deceleration until halfway, then acceleration.
1952 \o \inlineimage qeasingcurve-outinquad.png
1954 \o \c Easing.InCubic
1955 \o Easing curve for a cubic (t^3) function: accelerating from zero velocity.
1956 \o \inlineimage qeasingcurve-incubic.png
1958 \o \c Easing.OutCubic
1959 \o Easing curve for a cubic (t^3) function: decelerating from zero velocity.
1960 \o \inlineimage qeasingcurve-outcubic.png
1962 \o \c Easing.InOutCubic
1963 \o Easing curve for a cubic (t^3) function: acceleration until halfway, then deceleration.
1964 \o \inlineimage qeasingcurve-inoutcubic.png
1966 \o \c Easing.OutInCubic
1967 \o Easing curve for a cubic (t^3) function: deceleration until halfway, then acceleration.
1968 \o \inlineimage qeasingcurve-outincubic.png
1970 \o \c Easing.InQuart
1971 \o Easing curve for a quartic (t^4) function: accelerating from zero velocity.
1972 \o \inlineimage qeasingcurve-inquart.png
1974 \o \c Easing.OutQuart
1975 \o Easing curve for a quartic (t^4) function: decelerating from zero velocity.
1976 \o \inlineimage qeasingcurve-outquart.png
1978 \o \c Easing.InOutQuart
1979 \o Easing curve for a quartic (t^4) function: acceleration until halfway, then deceleration.
1980 \o \inlineimage qeasingcurve-inoutquart.png
1982 \o \c Easing.OutInQuart
1983 \o Easing curve for a quartic (t^4) function: deceleration until halfway, then acceleration.
1984 \o \inlineimage qeasingcurve-outinquart.png
1986 \o \c Easing.InQuint
1987 \o Easing curve for a quintic (t^5) function: accelerating from zero velocity.
1988 \o \inlineimage qeasingcurve-inquint.png
1990 \o \c Easing.OutQuint
1991 \o Easing curve for a quintic (t^5) function: decelerating from zero velocity.
1992 \o \inlineimage qeasingcurve-outquint.png
1994 \o \c Easing.InOutQuint
1995 \o Easing curve for a quintic (t^5) function: acceleration until halfway, then deceleration.
1996 \o \inlineimage qeasingcurve-inoutquint.png
1998 \o \c Easing.OutInQuint
1999 \o Easing curve for a quintic (t^5) function: deceleration until halfway, then acceleration.
2000 \o \inlineimage qeasingcurve-outinquint.png
2003 \o Easing curve for a sinusoidal (sin(t)) function: accelerating from zero velocity.
2004 \o \inlineimage qeasingcurve-insine.png
2006 \o \c Easing.OutSine
2007 \o Easing curve for a sinusoidal (sin(t)) function: decelerating from zero velocity.
2008 \o \inlineimage qeasingcurve-outsine.png
2010 \o \c Easing.InOutSine
2011 \o Easing curve for a sinusoidal (sin(t)) function: acceleration until halfway, then deceleration.
2012 \o \inlineimage qeasingcurve-inoutsine.png
2014 \o \c Easing.OutInSine
2015 \o Easing curve for a sinusoidal (sin(t)) function: deceleration until halfway, then acceleration.
2016 \o \inlineimage qeasingcurve-outinsine.png
2019 \o Easing curve for an exponential (2^t) function: accelerating from zero velocity.
2020 \o \inlineimage qeasingcurve-inexpo.png
2022 \o \c Easing.OutExpo
2023 \o Easing curve for an exponential (2^t) function: decelerating from zero velocity.
2024 \o \inlineimage qeasingcurve-outexpo.png
2026 \o \c Easing.InOutExpo
2027 \o Easing curve for an exponential (2^t) function: acceleration until halfway, then deceleration.
2028 \o \inlineimage qeasingcurve-inoutexpo.png
2030 \o \c Easing.OutInExpo
2031 \o Easing curve for an exponential (2^t) function: deceleration until halfway, then acceleration.
2032 \o \inlineimage qeasingcurve-outinexpo.png
2035 \o Easing curve for a circular (sqrt(1-t^2)) function: accelerating from zero velocity.
2036 \o \inlineimage qeasingcurve-incirc.png
2038 \o \c Easing.OutCirc
2039 \o Easing curve for a circular (sqrt(1-t^2)) function: decelerating from zero velocity.
2040 \o \inlineimage qeasingcurve-outcirc.png
2042 \o \c Easing.InOutCirc
2043 \o Easing curve for a circular (sqrt(1-t^2)) function: acceleration until halfway, then deceleration.
2044 \o \inlineimage qeasingcurve-inoutcirc.png
2046 \o \c Easing.OutInCirc
2047 \o Easing curve for a circular (sqrt(1-t^2)) function: deceleration until halfway, then acceleration.
2048 \o \inlineimage qeasingcurve-outincirc.png
2050 \o \c Easing.InElastic
2051 \o Easing curve for an elastic (exponentially decaying sine wave) function: accelerating from zero velocity.
2052 \br The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter.
2053 \o \inlineimage qeasingcurve-inelastic.png
2055 \o \c Easing.OutElastic
2056 \o Easing curve for an elastic (exponentially decaying sine wave) function: decelerating from zero velocity.
2057 \br The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter.
2058 \o \inlineimage qeasingcurve-outelastic.png
2060 \o \c Easing.InOutElastic
2061 \o Easing curve for an elastic (exponentially decaying sine wave) function: acceleration until halfway, then deceleration.
2062 \o \inlineimage qeasingcurve-inoutelastic.png
2064 \o \c Easing.OutInElastic
2065 \o Easing curve for an elastic (exponentially decaying sine wave) function: deceleration until halfway, then acceleration.
2066 \o \inlineimage qeasingcurve-outinelastic.png
2069 \o Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity.
2070 \o \inlineimage qeasingcurve-inback.png
2072 \o \c Easing.OutBack
2073 \o Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing out: decelerating to zero velocity.
2074 \o \inlineimage qeasingcurve-outback.png
2076 \o \c Easing.InOutBack
2077 \o Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration.
2078 \o \inlineimage qeasingcurve-inoutback.png
2080 \o \c Easing.OutInBack
2081 \o Easing curve for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration.
2082 \o \inlineimage qeasingcurve-outinback.png
2084 \o \c Easing.InBounce
2085 \o Easing curve for a bounce (exponentially decaying parabolic bounce) function: accelerating from zero velocity.
2086 \o \inlineimage qeasingcurve-inbounce.png
2088 \o \c Easing.OutBounce
2089 \o Easing curve for a bounce (exponentially decaying parabolic bounce) function: decelerating from zero velocity.
2090 \o \inlineimage qeasingcurve-outbounce.png
2092 \o \c Easing.InOutBounce
2093 \o Easing curve for a bounce (exponentially decaying parabolic bounce) function easing in/out: acceleration until halfway, then deceleration.
2094 \o \inlineimage qeasingcurve-inoutbounce.png
2096 \o \c Easing.OutInBounce
2097 \o Easing curve for a bounce (exponentially decaying parabolic bounce) function easing out/in: deceleration until halfway, then acceleration.
2098 \o \inlineimage qeasingcurve-outinbounce.png
2101 \o Custom easing curve defined by the easing.bezierCurve property.
2105 \c easing.amplitude is only applicable for bounce and elastic curves (curves of type
2106 \c Easing.InBounce, \c Easing.OutBounce, \c Easing.InOutBounce, \c Easing.OutInBounce, \c Easing.InElastic,
2107 \c Easing.OutElastic, \c Easing.InOutElastic or \c Easing.OutInElastic).
2109 \c easing.overshoot is only applicable if \c easing.type is: \c Easing.InBack, \c Easing.OutBack,
2110 \c Easing.InOutBack or \c Easing.OutInBack.
2112 \c easing.period is only applicable if easing.type is: \c Easing.InElastic, \c Easing.OutElastic,
2113 \c Easing.InOutElastic or \c Easing.OutInElastic.
2115 \c easing.bezierCurve is only applicable if easing.type is: \c Easing.Bezier. This property is a list<real> containing
2116 groups of three points defining a curve from 0,0 to 1,1 - control1, control2,
2117 end point: [cx1, cy1, cx2, cy2, endx, endy, ...]. The last point must be 1,1.
2119 See the \l {declarative/animation/easing}{easing} example for a demonstration of
2120 the different easing settings.
2122 QEasingCurve QDeclarativePropertyAnimation::easing() const
2124 Q_D(const QDeclarativePropertyAnimation);
2125 return d->va->easingCurve();
2128 void QDeclarativePropertyAnimation::setEasing(const QEasingCurve &e)
2130 Q_D(QDeclarativePropertyAnimation);
2131 if (d->va->easingCurve() == e)
2134 d->va->setEasingCurve(e);
2135 emit easingChanged(e);
2138 QObject *QDeclarativePropertyAnimation::target() const
2140 Q_D(const QDeclarativePropertyAnimation);
2144 void QDeclarativePropertyAnimation::setTarget(QObject *o)
2146 Q_D(QDeclarativePropertyAnimation);
2150 emit targetChanged();
2153 QString QDeclarativePropertyAnimation::property() const
2155 Q_D(const QDeclarativePropertyAnimation);
2156 return d->propertyName;
2159 void QDeclarativePropertyAnimation::setProperty(const QString &n)
2161 Q_D(QDeclarativePropertyAnimation);
2162 if (d->propertyName == n)
2164 d->propertyName = n;
2165 emit propertyChanged();
2168 QString QDeclarativePropertyAnimation::properties() const
2170 Q_D(const QDeclarativePropertyAnimation);
2171 return d->properties;
2174 void QDeclarativePropertyAnimation::setProperties(const QString &prop)
2176 Q_D(QDeclarativePropertyAnimation);
2177 if (d->properties == prop)
2180 d->properties = prop;
2181 emit propertiesChanged(prop);
2185 \qmlproperty string QtQuick2::PropertyAnimation::properties
2186 \qmlproperty list<Object> QtQuick2::PropertyAnimation::targets
2187 \qmlproperty string QtQuick2::PropertyAnimation::property
2188 \qmlproperty Object QtQuick2::PropertyAnimation::target
2190 These properties are used as a set to determine which properties should be animated.
2191 The singular and plural forms are functionally identical, e.g.
2193 NumberAnimation { target: theItem; property: "x"; to: 500 }
2195 has the same meaning as
2197 NumberAnimation { targets: theItem; properties: "x"; to: 500 }
2199 The singular forms are slightly optimized, so if you do have only a single target/property
2200 to animate you should try to use them.
2202 The \c targets property allows multiple targets to be set. For example, this animates the
2203 \c x property of both \c itemA and \c itemB:
2206 NumberAnimation { targets: [itemA, itemB]; properties: "x"; to: 500 }
2209 In many cases these properties do not need to be explicitly specified, as they can be
2210 inferred from the animation framework:
2214 \o Value Source / Behavior
2215 \o When an animation is used as a value source or in a Behavior, the default target and property
2216 name to be animated can both be inferred.
2220 width: 100; height: 100
2221 color: Qt.rgba(0,0,1)
2222 NumberAnimation on x { to: 500; loops: Animation.Infinite } //animate theRect's x property
2223 Behavior on y { NumberAnimation {} } //animate theRect's y property
2228 \o When used in a transition, a property animation is assumed to match \e all targets
2229 but \e no properties. In practice, that means you need to specify at least the properties
2230 in order for the animation to do anything.
2234 width: 100; height: 100
2235 color: Qt.rgba(0,0,1)
2236 Item { id: uselessItem }
2239 PropertyChanges { target: theRect; x: 200; y: 200; z: 4 }
2240 PropertyChanges { target: uselessItem; x: 10; y: 10; z: 2 }
2242 transitions: Transition {
2243 //animate both theRect's and uselessItem's x and y to their final values
2244 NumberAnimation { properties: "x,y" }
2246 //animate theRect's z to its final value
2247 NumberAnimation { target: theRect; property: "z" }
2253 \o When an animation is used standalone, both the target and property need to be
2254 explicitly specified.
2258 width: 100; height: 100
2259 color: Qt.rgba(0,0,1)
2260 //need to explicitly specify target and property
2261 NumberAnimation { id: theAnim; target: theRect; property: "x"; to: 500 }
2263 anchors.fill: parent
2264 onClicked: theAnim.start()
2270 As seen in the above example, properties is specified as a comma-separated string of property names to animate.
2272 \sa exclude, {QML Animation and Transitions}
2274 QDeclarativeListProperty<QObject> QDeclarativePropertyAnimation::targets()
2276 Q_D(QDeclarativePropertyAnimation);
2277 return QDeclarativeListProperty<QObject>(this, d->targets);
2281 \qmlproperty list<Object> QtQuick2::PropertyAnimation::exclude
2282 This property holds the items not to be affected by this animation.
2283 \sa PropertyAnimation::targets
2285 QDeclarativeListProperty<QObject> QDeclarativePropertyAnimation::exclude()
2287 Q_D(QDeclarativePropertyAnimation);
2288 return QDeclarativeListProperty<QObject>(this, d->exclude);
2291 QAbstractAnimation *QDeclarativePropertyAnimation::qtAnimation()
2293 Q_D(QDeclarativePropertyAnimation);
2297 void QDeclarativeAnimationPropertyUpdater::setValue(qreal v)
2299 bool deleted = false;
2300 wasDeleted = &deleted;
2301 if (reverse) //QVariantAnimation sends us 1->0 when reversed, but we are expecting 0->1
2303 for (int ii = 0; ii < actions.count(); ++ii) {
2304 QDeclarativeAction &action = actions[ii];
2307 QDeclarativePropertyPrivate::write(action.property, action.toValue, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding);
2309 if (!fromSourced && !fromDefined) {
2310 action.fromValue = action.property.read();
2311 if (interpolatorType)
2312 QDeclarativePropertyAnimationPrivate::convertVariant(action.fromValue, interpolatorType);
2314 if (!interpolatorType) {
2315 int propType = action.property.propertyType();
2316 if (!prevInterpolatorType || prevInterpolatorType != propType) {
2317 prevInterpolatorType = propType;
2318 interpolator = QVariantAnimationPrivate::getInterpolator(prevInterpolatorType);
2322 QDeclarativePropertyPrivate::write(action.property, interpolator(action.fromValue.constData(), action.toValue.constData(), v), QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding);
2331 void QDeclarativePropertyAnimation::transition(QDeclarativeStateActions &actions,
2332 QDeclarativeProperties &modified,
2333 TransitionDirection direction)
2335 Q_D(QDeclarativePropertyAnimation);
2337 QStringList props = d->properties.isEmpty() ? QStringList() : d->properties.split(QLatin1Char(','));
2338 for (int ii = 0; ii < props.count(); ++ii)
2339 props[ii] = props.at(ii).trimmed();
2340 if (!d->propertyName.isEmpty())
2341 props << d->propertyName;
2343 QList<QObject*> targets = d->targets;
2345 targets.append(d->target);
2347 bool hasSelectors = !props.isEmpty() || !targets.isEmpty() || !d->exclude.isEmpty();
2348 bool useType = (props.isEmpty() && d->defaultToInterpolatorType) ? true : false;
2350 if (d->defaultProperty.isValid() && !hasSelectors) {
2351 props << d->defaultProperty.name();
2352 targets << d->defaultProperty.object();
2355 if (props.isEmpty() && !d->defaultProperties.isEmpty()) {
2356 props << d->defaultProperties.split(QLatin1Char(','));
2359 QDeclarativeAnimationPropertyUpdater *data = new QDeclarativeAnimationPropertyUpdater;
2360 data->interpolatorType = d->interpolatorType;
2361 data->interpolator = d->interpolator;
2362 data->reverse = direction == Backward ? true : false;
2363 data->fromSourced = false;
2364 data->fromDefined = d->fromIsDefined;
2366 bool hasExplicit = false;
2367 //an explicit animation has been specified
2368 if (d->toIsDefined) {
2369 for (int i = 0; i < props.count(); ++i) {
2370 for (int j = 0; j < targets.count(); ++j) {
2371 QDeclarativeAction myAction;
2372 myAction.property = d->createProperty(targets.at(j), props.at(i), this);
2373 if (myAction.property.isValid()) {
2374 if (d->fromIsDefined) {
2375 myAction.fromValue = d->from;
2376 d->convertVariant(myAction.fromValue, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType());
2378 myAction.toValue = d->to;
2379 d->convertVariant(myAction.toValue, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType());
2380 data->actions << myAction;
2382 for (int ii = 0; ii < actions.count(); ++ii) {
2383 QDeclarativeAction &action = actions[ii];
2384 if (action.property.object() == myAction.property.object() &&
2385 myAction.property.name() == action.property.name()) {
2386 modified << action.property;
2387 break; //### any chance there could be multiples?
2396 for (int ii = 0; ii < actions.count(); ++ii) {
2397 QDeclarativeAction &action = actions[ii];
2399 QObject *obj = action.property.object();
2400 QString propertyName = action.property.name();
2401 QObject *sObj = action.specifiedObject;
2402 QString sPropertyName = action.specifiedProperty;
2403 bool same = (obj == sObj);
2405 if ((targets.isEmpty() || targets.contains(obj) || (!same && targets.contains(sObj))) &&
2406 (!d->exclude.contains(obj)) && (same || (!d->exclude.contains(sObj))) &&
2407 (props.contains(propertyName) || (!same && props.contains(sPropertyName))
2408 || (useType && action.property.propertyType() == d->interpolatorType))) {
2409 QDeclarativeAction myAction = action;
2411 if (d->fromIsDefined)
2412 myAction.fromValue = d->from;
2414 myAction.fromValue = QVariant();
2416 myAction.toValue = d->to;
2418 d->convertVariant(myAction.fromValue, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType());
2419 d->convertVariant(myAction.toValue, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType());
2421 modified << action.property;
2423 data->actions << myAction;
2424 action.fromValue = myAction.toValue;
2428 if (data->actions.count()) {
2429 if (!d->rangeIsSet) {
2430 d->va->setStartValue(qreal(0));
2431 d->va->setEndValue(qreal(1));
2432 d->rangeIsSet = true;
2434 d->va->setAnimValue(data, QAbstractAnimation::DeleteWhenStopped);
2435 d->va->setFromSourcedValue(&data->fromSourced);
2436 d->actions = &data->actions;
2439 d->va->setFromSourcedValue(0); //clear previous data
2440 d->va->setAnimValue(0, QAbstractAnimation::DeleteWhenStopped); //clear previous data
2446 QDeclarativeScriptActionPrivate::QDeclarativeScriptActionPrivate()
2447 : QDeclarativeAbstractAnimationPrivate(), hasRunScriptScript(false), reversing(false), proxy(this), rsa(0) {}