source: trunk/doc/src/declarative/animation.qdoc@ 846

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 14.8 KB
Line 
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
33In QML, animations are created by applying animation objects to object property
34values to gradually change them over time. Animation objects are created from
35the built-in set of animation elements, which can be used to animate various
36types of property values. In addition, animation objects can be applied in
37different ways depending on the context in which they are required.
38
39To create an animation, use an appropriate animation element for the type of
40the property that is to be animated, and apply the animation depending on the
41type of behavior that is required. This page describes the \l {Types of
42Animations} that can be created and the \l {Animation Elements} that are used
43to create these animations.
44
45
46\section1 Types of Animations
47
48An animation is created in different ways depending on the context in which it
49is required. Suppose a \l Rectangle's movement - that is, changes in its \c x
50or \c y property values - should be animated. The semantics of the animation
51differ 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
55known position
56\o An animation that only triggers when the \l Rectangle is moved by external
57sources - for example, when the mouse is clicked, animate the movement to the
58mouse 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
61instead 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
65To support these different types of animation methods, QML provides several
66methods for defining an animation. These are:
67
68\list
69\o Creating an \l{Animations as Property Value Sources}{animation using
70property value sources}, to immediately animate a specific property
71\o Using \l{Behavioral Animations}{behavioral animations}, which are triggered
72when a property changes value
73\o \l{Animations in a Signal Handler}{Within a signal handler}, to be triggered
74when a signal is received
75\o As a \l{Standalone Animation}{standalone animation}, that can be
76started/stopped from script and can be rebound to different objects
77\o Using \l{Transitions}{transitions}, to provide animations between \l{QML
78States}{state changes}
79\endlist
80
81These methods are demonstrated below. Notice these examples use
82PropertyAnimation, which is one of several QML elements that can be used to
83create an animation. See the \l {Animation Elements} section further below for
84details.
85
86
87
88\section2 Animations as Property Value Sources
89
90An animation is applied as a \l{QDeclarativePropertyValueSource}{property value
91source} using the \e Animation \bold on \e Property syntax. Here is a \l
92Rectangle whose movement is animated using this method:
93
94\snippet doc/src/snippets/declarative/animation-propertyvaluesource.qml 0
95
96This applies a PropertyAnimation to the \l Rectangle's \c x and \c y properties
97to animate from their current values (i.e. zero) to 50, over 1000 milliseconds.
98The animation starts as soon as the \l Rectangle is loaded. To animate from
99specific values rather than the current \c x and \c y values, set the
100PropertyAnimation's \l {PropertyAnimation::}{from} property.
101
102Specifying an animation as a property value source is useful for animating a
103property to a particular value as soon as the object is loaded.
104
105
106\section2 Behavioral Animations
107
108Often an animation should be applied whenever a particular property value
109changes. In these cases, a \l Behavior can be used to specify a default
110animation for a property change. Here is an example:
111
112\snippet doc/src/snippets/declarative/animation-behavioral.qml 0
113
114This \l Rectangle has \l Behavior objects applied to its \c x and \c y
115properties. Whenever these properties change (in this case, when the mouse is
116clicked within the parent \l Item), the PropertyAnimation objects defined
117within the behaviors will be applied to these properties, thus animating the \l
118Rectangle's movement to its new position. Unlike the method of \l {Animations