ec6ae9b2c888dd1aa5efa6befd99249fed64cbf8
[profile/ivi/qtdeclarative.git] / examples / declarative / animation / easing / easing.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the examples of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
11 **
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
14 ** met:
15 **   * Redistributions of source code must retain the above copyright
16 **     notice, this list of conditions and the following disclaimer.
17 **   * Redistributions in binary form must reproduce the above copyright
18 **     notice, this list of conditions and the following disclaimer in
19 **     the documentation and/or other materials provided with the
20 **     distribution.
21 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 **     the names of its contributors may be used to endorse or promote
23 **     products derived from this software without specific prior written
24 **     permission.
25 **
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 import QtQuick 2.0
42 import "content"
43
44 Rectangle {
45     id: window
46     width: 600; height: 460; color: "#232323"
47
48     property var easingCurve: [ 0.2, 0.2, 0.13, 0.65, 0.2, 0.8,
49                                 0.624, 0.98, 0.93, 0.95, 1, 1 ]
50
51     ListModel {
52         id: easingTypes
53         ListElement { name: "Easing.Linear"; type: Easing.Linear; ballColor: "DarkRed" }
54         ListElement { name: "Easing.InQuad"; type: Easing.InQuad; ballColor: "IndianRed" }
55         ListElement { name: "Easing.OutQuad"; type: Easing.OutQuad; ballColor: "Salmon" }
56         ListElement { name: "Easing.InOutQuad"; type: Easing.InOutQuad; ballColor: "Tomato" }
57         ListElement { name: "Easing.OutInQuad"; type: Easing.OutInQuad; ballColor: "DarkOrange" }
58         ListElement { name: "Easing.InCubic"; type: Easing.InCubic; ballColor: "Gold" }
59         ListElement { name: "Easing.OutCubic"; type: Easing.OutCubic; ballColor: "Yellow" }
60         ListElement { name: "Easing.InOutCubic"; type: Easing.InOutCubic; ballColor: "PeachPuff" }
61         ListElement { name: "Easing.OutInCubic"; type: Easing.OutInCubic; ballColor: "Thistle" }
62         ListElement { name: "Easing.InQuart"; type: Easing.InQuart; ballColor: "Orchid" }
63         ListElement { name: "Easing.OutQuart"; type: Easing.OutQuart; ballColor: "Purple" }
64         ListElement { name: "Easing.InOutQuart"; type: Easing.InOutQuart; ballColor: "SlateBlue" }
65         ListElement { name: "Easing.OutInQuart"; type: Easing.OutInQuart; ballColor: "Chartreuse" }
66         ListElement { name: "Easing.InQuint"; type: Easing.InQuint; ballColor: "LimeGreen" }
67         ListElement { name: "Easing.OutQuint"; type: Easing.OutQuint; ballColor: "SeaGreen" }
68         ListElement { name: "Easing.InOutQuint"; type: Easing.InOutQuint; ballColor: "DarkGreen" }
69         ListElement { name: "Easing.OutInQuint"; type: Easing.OutInQuint; ballColor: "Olive" }
70         ListElement { name: "Easing.InSine"; type: Easing.InSine; ballColor: "DarkSeaGreen" }
71         ListElement { name: "Easing.OutSine"; type: Easing.OutSine; ballColor: "Teal" }
72         ListElement { name: "Easing.InOutSine"; type: Easing.InOutSine; ballColor: "Turquoise" }
73         ListElement { name: "Easing.OutInSine"; type: Easing.OutInSine; ballColor: "SteelBlue" }
74         ListElement { name: "Easing.InExpo"; type: Easing.InExpo; ballColor: "SkyBlue" }
75         ListElement { name: "Easing.OutExpo"; type: Easing.OutExpo; ballColor: "RoyalBlue" }
76         ListElement { name: "Easing.InOutExpo"; type: Easing.InOutExpo; ballColor: "MediumBlue" }
77         ListElement { name: "Easing.OutInExpo"; type: Easing.OutInExpo; ballColor: "MidnightBlue" }
78         ListElement { name: "Easing.InCirc"; type: Easing.InCirc; ballColor: "CornSilk" }
79         ListElement { name: "Easing.OutCirc"; type: Easing.OutCirc; ballColor: "Bisque" }
80         ListElement { name: "Easing.InOutCirc"; type: Easing.InOutCirc; ballColor: "RosyBrown" }
81         ListElement { name: "Easing.OutInCirc"; type: Easing.OutInCirc; ballColor: "SandyBrown" }
82         ListElement { name: "Easing.InElastic"; type: Easing.InElastic; ballColor: "DarkGoldenRod" }
83         ListElement { name: "Easing.OutElastic"; type: Easing.OutElastic; ballColor: "Chocolate" }
84         ListElement { name: "Easing.InOutElastic"; type: Easing.InOutElastic; ballColor: "SaddleBrown" }
85         ListElement { name: "Easing.OutInElastic"; type: Easing.OutInElastic; ballColor: "Brown" }
86         ListElement { name: "Easing.InBack"; type: Easing.InBack; ballColor: "Maroon" }
87         ListElement { name: "Easing.OutBack"; type: Easing.OutBack; ballColor: "LavenderBlush" }
88         ListElement { name: "Easing.InOutBack"; type: Easing.InOutBack; ballColor: "MistyRose" }
89         ListElement { name: "Easing.OutInBack"; type: Easing.OutInBack; ballColor: "Gainsboro" }
90         ListElement { name: "Easing.OutBounce"; type: Easing.OutBounce; ballColor: "Silver" }
91         ListElement { name: "Easing.InBounce"; type: Easing.InBounce; ballColor: "DimGray" }
92         ListElement { name: "Easing.InOutBounce"; type: Easing.InOutBounce; ballColor: "SlateGray" }
93         ListElement { name: "Easing.OutInBounce"; type: Easing.OutInBounce; ballColor: "DarkSlateGray" }
94         ListElement { name: "Easing.Bezier"; type: Easing.Bezier; ballColor: "Chartreuse"; }
95     }
96
97     Component {
98         id: delegate
99
100         Item {
101             height: 56; width: window.width
102
103             Text { text: name; anchors.centerIn: parent; color: "White" }
104
105             Rectangle {
106                 id: slot1; color: "#121212"; x: 30; height: 46; width: 46
107                 border.color: "#343434"; border.width: 1; radius: 12
108                 anchors.verticalCenter: parent.verticalCenter
109             }
110
111             Rectangle {
112                 id: slot2; color: "#121212"; x: window.width - 76; height: 46; width: 46
113                 border.color: "#343434"; border.width: 1; radius: 12
114                 anchors.verticalCenter: parent.verticalCenter
115             }
116
117             Rectangle {
118                 id: rect; x: 30; color: "#454545"
119                 border.color: "White"; border.width: 2
120                 height: 46; width: 46; radius: 12
121                 anchors.verticalCenter: parent.verticalCenter
122
123                 MouseArea {
124                     onClicked: if (rect.state == '') rect.state = "right"; else rect.state = ''
125                     anchors.fill: parent
126                     anchors.margins: -5 // Make MouseArea bigger than the rectangle, itself
127                 }
128
129                 states : State {
130                     name: "right"
131                     PropertyChanges { target: rect; x: window.width - 76; color: ballColor }
132                 }
133
134                 transitions: Transition {
135                     NumberAnimation { properties: "x"; easing.type: type; easing.bezierCurve: getBezierCurve(name); duration: 1000 }
136                     ColorAnimation { properties: "color"; easing.type: type; easing.bezierCurve: getBezierCurve(name); duration: 1000 }
137                 }
138             }
139         }
140     }
141
142     Flickable {
143         anchors.fill: parent
144         contentHeight: layout.height+50
145         Rectangle {
146             id: titlePane
147             color: "#444444"
148             height: 35
149             anchors { top: parent.top; left: parent.left; right: parent.right }
150             QuitButton {
151                 id: quitButton
152                 anchors.verticalCenter: parent.verticalCenter
153                 anchors.right: parent.right
154                 anchors.rightMargin: 10
155             }
156         }
157         Column {
158             id: layout
159             anchors { top: titlePane.bottom; topMargin: 10; left: parent.left; right: parent.right }
160             Repeater { model: easingTypes; delegate: delegate }
161         }
162     }
163
164     function getBezierCurve(name)
165     {
166         if (name === "Easing.Bezier")
167             return easingCurve;
168         return [];
169     }
170 }