~ubuntu-branches/ubuntu/saucy/qtdeclarative-opensource-src/saucy

« back to all changes in this revision

Viewing changes to examples/quick/animation/easing/easing.qml

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 14:17:19 UTC
  • Revision ID: package-import@ubuntu.com-20130205141719-qqeyml8wslpyez52
Tags: upstream-5.0.1
ImportĀ upstreamĀ versionĀ 5.0.1

Show diffs side-by-side

added added

removed removed

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