added android components
[mardrone] / mardrone / imports / com / nokia / android.1.1 / ProgressBar.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the Qt Components project.
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 1.1
42 import Qt.labs.components 1.1
43 import "." 1.1
44
45 Item {
46     id: root
47
48     // Common Public API
49     property alias minimumValue: model.minimumValue
50     property alias maximumValue: model.maximumValue
51     property alias value: model.value
52     property bool indeterminate: false
53
54     // Symbian specific API
55     property bool platformInverted: false
56
57     implicitWidth: Math.max(50, screen.width / 2) // TODO: use screen.displayWidth
58     implicitHeight: privateStyle.sliderThickness
59
60     BorderImage {
61         id: background
62
63         source: privateStyle.imagePath("qtg_fr_progressbar_track", root.platformInverted)
64         border { left: platformStyle.borderSizeMedium; top: 0; right: platformStyle.borderSizeMedium; bottom: 0 }
65         anchors.fill: parent
66     }
67
68     Loader {
69         id: progressBarContent
70
71         LayoutMirroring.enabled: false
72         LayoutMirroring.childrenInherit: true
73
74         states: [
75             State {
76                 name: "indeterminate"
77                 when: root.indeterminate
78                 PropertyChanges { target: progressBarContent; sourceComponent: indeterminateContent; anchors.fill: parent }
79             },
80             State {
81                 name: "determinate"
82                 when: !root.indeterminate
83                 PropertyChanges { target: progressBarContent; sourceComponent: determinateContent }
84                 AnchorChanges {
85                     target: progressBarContent
86                     anchors.top: parent.top
87                     anchors.bottom: parent.bottom
88                     anchors.left: parent.left
89                 }
90             }
91         ]
92     }
93
94
95     Component {
96         id: indeterminateContent
97
98         Item {
99             anchors.fill: parent
100
101             Item {
102                 id: indeterminateImageMask
103
104                 // Mask margins prevent indeterminateImage to appear outside the rounded
105                 // frame corners, hardcoded 3 has been instructed by UX
106                 anchors { fill: parent; leftMargin: 3; rightMargin: 3 }
107                 clip: true
108
109                 Image {
110                     id: indeterminateImage
111
112                     x: parent.x
113                     height: parent.height
114                     width: parent.width + height // height is the amount of horizontal movement
115                     fillMode: Image.TileHorizontally
116                     source: privateStyle.imagePath(root.platformInverted ? "qtg_graf_progressbar_wait_inverse"
117                                                                          : "qtg_graf_progressbar_wait")
118
119                     NumberAnimation on x {
120                         loops: Animation.Infinite
121                         running: true
122                         from: 0
123                         to: -indeterminateImage.height // see indeterminateImage.width
124                         easing.type: Easing.Linear
125                         duration: privateStyle.sliderThickness * 30
126                     }
127                 }
128             }
129
130             BorderImage {
131                 id: indeterminateOverlay
132
133                 anchors.fill: parent
134                 source: privateStyle.imagePath("qtg_fr_progressbar_overlay", root.platformInverted)
135                 border {
136                     left: platformStyle.borderSizeMedium
137                     right: platformStyle.borderSizeMedium
138                     top: 0
139                     bottom: 0
140                 }
141             }
142         }
143     }
144
145     Component {
146         id: determinateContent
147
148         Item {
149             id: progressMask
150
151             width: model.position
152             clip: true
153
154             BorderImage {
155                 id: progress
156
157                 source: privateStyle.imagePath("qtg_fr_progressbar_fill", root.platformInverted)
158                 border {
159                     left: platformStyle.borderSizeMedium
160                     right: platformStyle.borderSizeMedium
161                     top: 0
162                     bottom: 0
163                 }
164                 height: parent.height
165                 width: root.width
166             }
167         }
168     }
169
170     RangeModel {
171         id: model
172         minimumValue: 0.0
173         maximumValue: 1.0
174         positionAtMinimum: 0.0
175         positionAtMaximum: background.width
176     }
177 }
178