Initial import from the monolithic Qt.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qmlvisual / qdeclarativespringanimation / follow.qml
1 import QtQuick 1.0
2
3 Rectangle {
4     color: "#ffffff"
5     width: 320; height: 240
6
7     Rectangle {
8         id: rect
9         color: "#00ff00"
10         y: 200; width: 60; height: 20
11         SequentialAnimation on y {
12             loops: Animation.Infinite
13             NumberAnimation {
14                 to: 20; duration: 500
15                 easing.type: "InOutQuad"
16             }
17             NumberAnimation {
18                 to: 200; duration: 2000
19                 easing.type: "OutBounce"
20             }
21             PauseAnimation { duration: 1000 }
22         }
23     }
24
25     // Velocity
26     Rectangle {
27         color: "#ff0000"
28         x: rect.width; width: rect.width; height: 20
29         y: rect.y
30         Behavior on y { SpringAnimation { velocity: 200 } }
31     }
32
33     // Spring
34     Rectangle {
35         color: "#ff0000"
36         x: rect.width * 2; width: rect.width/2; height: 20
37         y: rect.y
38         Behavior on y { SpringAnimation { spring: 1.0; damping: 0.2 } }
39     }
40     Rectangle {
41         color: "#880000"
42         x: rect.width * 2.5; width: rect.width/2; height: 20
43         y: rect.y
44         Behavior on y { SpringAnimation { spring: 1.0; damping: 0.2; mass: 3.0 } } // "heavier" object
45     }
46
47     // Follow mouse
48     MouseArea {
49         id: mouseRegion
50         anchors.fill: parent
51         Rectangle {
52             id: ball
53             property int targetX: mouseRegion.mouseX - 10
54             property int targetY: mouseRegion.mouseY - 10
55
56             x: targetX
57             y: targetY
58             width: 20; height: 20
59             radius: 10
60             color: "#0000ff"
61
62             Behavior on x { SpringAnimation { spring: 1.0; damping: 0.05; epsilon: 0.25 } }
63             Behavior on y { SpringAnimation { spring: 1.0; damping: 0.05; epsilon: 0.25 } }
64
65             states: [
66                 State {
67                     name: "following"
68                     when: ball.x != ball.targetX || ball.y != ball.targetY
69                     PropertyChanges { target: ball; color: "#ff0000" }
70                 }
71             ]
72             transitions: [
73                 Transition {
74                     ColorAnimation { duration: 200 }
75                 }
76             ]
77         }
78     }
79 }