2 * Copyright (C) 2013 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 import "../Components"
18 import "Gradient.js" as Gradient
20 import Ubuntu.Components 1.3
27 property int animDuration: 10
31 objectName: "infographicPrivate"
32 property bool useDotAnimation: true
33 property int circleModifier: useDotAnimation ? 1 : 2
34 property bool animating: dotHideAnimTimer.running
35 || dotShowAnimTimer.running
36 || circleChangeAnimTimer.running
41 ignoreUnknownSignals: model === undefined
43 onDataAboutToAppear: startHideAnimation() // hide "no data" label
44 onDataAppeared: startShowAnimation()
46 onDataAboutToChange: startHideAnimation()
47 onDataChanged: startShowAnimation()
49 onDataAboutToDisappear: startHideAnimation()
50 onDataDisappeared: startShowAnimation() // show "no data" label
53 function startShowAnimation() {
54 dotHideAnimTimer.stop()
55 notification.hideAnim.stop()
57 if (d.useDotAnimation) {
58 dotShowAnimTimer.startFromBeginning()
60 notification.showAnim.start()
63 function startHideAnimation() {
64 dotShowAnimTimer.stop()
65 circleChangeAnimTimer.stop()
66 notification.showAnim.stop()
68 if (d.useDotAnimation) {
69 dotHideAnimTimer.startFromBeginning()
71 circleChangeAnimTimer.startFromBeginning()
73 notification.hideAnim.start()
76 visible: model.username !== ""
78 Component.onCompleted: startShowAnimation()
82 objectName: "dataCircle"
84 property real divisor: 1.5
86 width: Math.min(parent.height, parent.width) / divisor
89 anchors.centerIn: parent
92 id: circleChangeAnimTimer
94 property int pastCircleCounter
95 property int presentCircleCounter
97 interval: notification.duration
101 if (pastCircleCounter < pastCircles.count) {
102 var nextCircle = pastCircles.itemAt(pastCircleCounter++)
103 if (nextCircle !== null) nextCircle.pastCircleChangeAnim.start()
105 if (pastCircleCounter > pastCircles.count / 2) {
106 var nextCircle = presentCircles.itemAt(presentCircleCounter++)
107 if (nextCircle !== null) nextCircle.presentCircleChangeAnim.start()
109 if (presentCircleCounter > infographic.model.currentDay && pastCircleCounter >= pastCircles.count) {
114 function startFromBeginning() {
115 circleChangeAnimTimer.pastCircleCounter = 0
116 circleChangeAnimTimer.presentCircleCounter = 0
123 objectName: "pastCircles"
124 model: infographic.model.secondMonth
126 delegate: ObjectPositioner {
127 property alias pastCircleChangeAnim: pastCircleChangeAnim
130 count: pastCircles.count
131 radius: dataCircle.width / 2
132 halfSize: pastCircle.width / 2
137 objectName: "pastCircle" + index
139 property real divisor: 1.8
140 property real circleOpacity: 0.1
142 width: dataCircle.width / divisor
143 height: dataCircle.height / divisor
146 visible: modelData !== undefined
149 SequentialAnimation {
150 id: pastCircleChangeAnim
157 to: pastCircle.circleOpacity
158 easing.type: Easing.OutCurve
159 duration: circleChangeAnimTimer.interval * d.circleModifier
165 easing.type: Easing.OutCurve
166 duration: circleChangeAnimTimer.interval * d.circleModifier
171 to: Gradient.threeColorByIndex(index, count, infographic.model.secondColor)
172 easing.type: Easing.OutCurve
173 duration: circleChangeAnimTimer.interval * d.circleModifier
183 objectName: "presentCircles"
184 model: infographic.model.firstMonth
186 delegate: ObjectPositioner {
187 property alias presentCircleChangeAnim: presentCircleChangeAnim
190 count: presentCircles.count
191 radius: dataCircle.width / 2
192 halfSize: presentCircle.width / 2
197 objectName: "presentCircle" + index
199 property real divisor: 1.8
200 property real circleOpacity: 0.3
202 width: dataCircle.width / divisor
203 height: dataCircle.height / divisor
206 visible: modelData !== undefined
209 SequentialAnimation {
210 id: presentCircleChangeAnim
216 target: presentCircle
218 to: presentCircle.circleOpacity
219 easing.type: Easing.OutCurve
220 duration: circleChangeAnimTimer.interval * d.circleModifier
223 target: presentCircle
226 easing.type: Easing.OutCurve
227 duration: circleChangeAnimTimer.interval * d.circleModifier
230 target: presentCircle
232 to: Gradient.threeColorByIndex(index, infographic.model.currentDay, infographic.model.firstColor)
233 easing.type: Easing.OutCurve
234 duration: circleChangeAnimTimer.interval * d.circleModifier
244 objectName: "backgroundCircle"
248 source: "graphics/infographic_circle_back.png"
254 property int dotCounter: 0
256 interval: animDuration * 0.5; running: false; repeat: true
258 if (dotCounter < dots.count) {
259 var nextDot = dots.itemAt(dotCounter);
261 nextDot.unlockAnimation.start();
262 if (++dotCounter == Math.round(dots.count / 2)) {
263 circleChangeAnimTimer.startFromBeginning();
271 function startFromBeginning() {
272 if (!dotShowAnimTimer.running)
282 property int dotCounter
284 interval: animDuration * 0.5
288 if (dotCounter >= 0) {
289 var nextDot = dots.itemAt(dotCounter--)
290 nextDot.changeAnimation.start()
294 if (dotCounter == 0) {
295 infographic.model.readyForDataChange()
299 function startFromBeginning() {
300 if (!dotHideAnimTimer.running)
301 dotCounter = dots.count - 1
311 model: infographic.model.firstMonth
313 delegate: ObjectPositioner {
314 property alias unlockAnimation: dotUnlockAnim
315 property alias changeAnimation: dotChangeAnim
317 property int currentDay: infographic.model.currentDay
321 radius: backgroundCircle.width / 2
322 halfSize: dot.width / 2
323 posOffset: radius / dot.width / 3
328 objectName: "dot" + index
330 property real baseOpacity: 0.4
332 width: units.dp(5) * parent.radius / 200
333 height: units.dp(5) * parent.radius / 200
336 state: index < currentDay ? "filled" : index == currentDay ? "pointer" : "unfilled"
344 duration: dotShowAnimTimer.interval
353 duration: dotHideAnimTimer.interval
363 property alias hideAnim: decreaseOpacity
364 property alias showAnim: increaseOpacity
366 property real baseOpacity: 0.6
367 property real duration: dotShowAnimTimer.interval * 5
369 height: 0.7 * backgroundCircle.width
370 width: notification.height
371 anchors.centerIn: parent
373 text: infographic.model.label
375 wrapMode: Text.WordWrap
376 horizontalAlignment: Text.AlignHCenter
377 verticalAlignment: Text.AlignVCenter
386 to: notification.baseOpacity
387 duration: notification.duration * dots.count
395 from: notification.baseOpacity
397 duration: notification.duration * dots.count
398 onStopped: if (!d.useDotAnimation) infographic.model.readyForDataChange()
404 anchors.fill: dataCircle
408 d.useDotAnimation = false
409 infographic.model.nextDataSource()