1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
14 | ** written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Free Documentation License
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
20 | ** file.
|
---|
21 | **
|
---|
22 | ** If you have questions regarding the use of this file, please contact
|
---|
23 | ** Nokia at [email protected].
|
---|
24 | ** $QT_END_LICENSE$
|
---|
25 | **
|
---|
26 | ****************************************************************************/
|
---|
27 |
|
---|
28 | /*!
|
---|
29 | \page qdeclarativeanimation.html
|
---|
30 | \title QML Animation
|
---|
31 |
|
---|
32 |
|
---|
33 | In QML, animations are created by applying animation objects to object property
|
---|
34 | values to gradually change them over time. Animation objects are created from
|
---|
35 | the built-in set of animation elements, which can be used to animate various
|
---|
36 | types of property values. In addition, animation objects can be applied in
|
---|
37 | different ways depending on the context in which they are required.
|
---|
38 |
|
---|
39 | To create an animation, use an appropriate animation element for the type of
|
---|
40 | the property that is to be animated, and apply the animation depending on the
|
---|
41 | type of behavior that is required. This page describes the \l {Types of
|
---|
42 | Animations} that can be created and the \l {Animation Elements} that are used
|
---|
43 | to create these animations.
|
---|
44 |
|
---|
45 |
|
---|
46 | \section1 Types of Animations
|
---|
47 |
|
---|
48 | An animation is created in different ways depending on the context in which it
|
---|
49 | is required. Suppose a \l Rectangle's movement - that is, changes in its \c x
|
---|
50 | or \c y property values - should be animated. The semantics of the animation
|
---|
51 | differ depending on whether you want to create:
|
---|
52 |
|
---|
53 | \list
|
---|
54 | \o An animation that moves the \l Rectangle as soon as it is created, to a
|
---|
55 | known position
|
---|
56 | \o An animation that only triggers when the \l Rectangle is moved by external
|
---|
57 | sources - for example, when the mouse is clicked, animate the movement to the
|
---|
58 | mouse position
|
---|
59 | \o An animation that triggers when a particular signal is received
|
---|
60 | \o A standalone animation that is not bound to the \l Rectangle's movement, but
|
---|
61 | instead can be started and stopped from script as required
|
---|
62 | \o An animation that only triggers during \l{QML States}{state changes}
|
---|
63 | \endlist
|
---|
64 |
|
---|
65 | To support these different types of animation methods, QML provides several
|
---|
66 | methods for defining an animation. These are:
|
---|
67 |
|
---|
68 | \list
|
---|
69 | \o Creating an \l{Animations as Property Value Sources}{animation using
|
---|
70 | property value sources}, to immediately animate a specific property
|
---|
71 | \o Using \l{Behavioral Animations}{behavioral animations}, which are triggered
|
---|
72 | when a property changes value
|
---|
73 | \o \l{Animations in a Signal Handler}{Within a signal handler}, to be triggered
|
---|
74 | when a signal is received
|
---|
75 | \o As a \l{Standalone Animation}{standalone animation}, that can be
|
---|
76 | started/stopped from script and can be rebound to different objects
|
---|
77 | \o Using \l{Transitions}{transitions}, to provide animations between \l{QML
|
---|
78 | States}{state changes}
|
---|
79 | \endlist
|
---|
80 |
|
---|
81 | These methods are demonstrated below. Notice these examples use
|
---|
82 | PropertyAnimation, which is one of several QML elements that can be used to
|
---|
83 | create an animation. See the \l {Animation Elements} section further below for
|
---|
84 | details.
|
---|
85 |
|
---|
86 |
|
---|
87 |
|
---|
88 | \section2 Animations as Property Value Sources
|
---|
89 |
|
---|
90 | An animation is applied as a \l{QDeclarativePropertyValueSource}{property value
|
---|
91 | source} using the \e Animation \bold on \e Property syntax. Here is a \l
|
---|
92 | Rectangle whose movement is animated using this method:
|
---|
93 |
|
---|
94 | \snippet doc/src/snippets/declarative/animation-propertyvaluesource.qml 0
|
---|
95 |
|
---|
96 | This applies a PropertyAnimation to the \l Rectangle's \c x and \c y properties
|
---|
97 | to animate from their current values (i.e. zero) to 50, over 1000 milliseconds.
|
---|
98 | The animation starts as soon as the \l Rectangle is loaded. To animate from
|
---|
99 | specific values rather than the current \c x and \c y values, set the
|
---|
100 | PropertyAnimation's \l {PropertyAnimation::}{from} property.
|
---|
101 |
|
---|
102 | Specifying an animation as a property value source is useful for animating a
|
---|
103 | property to a particular value as soon as the object is loaded.
|
---|
104 |
|
---|
105 |
|
---|
106 | \section2 Behavioral Animations
|
---|
107 |
|
---|
108 | Often an animation should be applied whenever a particular property value
|
---|
109 | changes. In these cases, a \l Behavior can be used to specify a default
|
---|
110 | animation for a property change. Here is an example:
|
---|
111 |
|
---|
112 | \snippet doc/src/snippets/declarative/animation-behavioral.qml 0
|
---|
113 |
|
---|
114 | This \l Rectangle has \l Behavior objects applied to its \c x and \c y
|
---|
115 | properties. Whenever these properties change (in this case, when the mouse is
|
---|
116 | clicked within the parent \l Item), the PropertyAnimation objects defined
|
---|
117 | within the behaviors will be applied to these properties, thus animating the \l
|
---|
118 | Rectangle's movement to its new position. Unlike the method of \l {Animations
|
---|
|
---|