Add flashy spiral timer to cover
[harbour-pedalo.git] / qml / cover / CoverPage.qml
1 import QtQuick 2.0
2 import Sailfish.Silica 1.0
3 import harbour.pedalo.settings 1.0
4
5 CoverBackground {
6     id: root
7     property bool update: status === Cover.Active && currentStatus.cycling
8
9     onUpdateChanged: {
10         stopwatch.updateseconds()
11         stopwatchtrigger.restart()
12     }
13
14     Item {
15         id: stopwatch
16         property int seconds: 0
17         property int fast: seconds < 60 * 10
18         property bool update: root.update
19
20         Timer {
21             id: stopwatchtrigger
22             interval: stopwatch.fast ? 200 : 5000
23             running: root.update
24             repeat: true
25             triggeredOnStart: true
26             onTriggered: {
27                 stopwatch.updateseconds()
28             }
29         }
30
31         function updateseconds() {
32             stopwatch.seconds = (new Date().getTime() - currentStatus.startTime) / 1000
33         }
34     }
35
36     Item {
37         id: contents
38
39         width: Theme.coverSizeLarge.width
40         height: Theme.coverSizeLarge.height
41         property real xScale: root.width / contents.width
42
43         transform: Scale {
44             xScale: contents.xScale
45             yScale: root.height / contents.height
46         }
47
48     ClockView {
49         id: clockView
50
51         anchors {
52             top: parent.top
53             left: parent.left
54             right: parent.right
55             margins: Theme.paddingLarge
56         }
57         height: width
58     }
59
60     LargeItem {
61         id: stopwatchView
62
63         anchors {
64             top: clockView.bottom
65             topMargin: Theme.paddingMedium
66             leftMargin: Theme.paddingLarge
67             rightMargin: Theme.paddingLarge
68         }
69
70         textVisible: root.update
71
72         title: qsTr("Pedalo")
73
74         text: {
75             if (stopwatch.seconds < 60) {
76                 return qsTr("%n seconds", "", stopwatch.seconds)
77             } else if (stopwatch.seconds < 60*60) {
78                 return qsTr("%1 minutes").arg(Math.floor(stopwatch.seconds/60))
79             } else {
80                 var minutes = Math.floor(stopwatch.seconds/60)
81                 var hours = Math.floor(minutes/60)
82                 minutes = minutes % 60
83                 return qsTrId("%1h %2min").arg(hours).arg(minutes)
84             }
85         }
86     }
87     }
88
89     CoverActionList {
90         id: coverAction
91
92         CoverAction {
93             iconSource: currentStatus.cycling ? Settings.getImageUrl("icon-cover-journey-finish") : Settings.getImageUrl("icon-cover-journey-start")
94             onTriggered: {
95                 if (currentStatus.cycling) {
96                     app.activate()
97                     app.showMainPage(PageStackAction.Immediate)
98
99                     var dialog = pageStack.push(Qt.resolvedUrl("../pages/JourneyEdit.qml"), {title: "Finish journey", start: journeymodel.epochToDateTime(currentStatus.startTime), duration: currentStatus.getDuration()})
100
101                     dialog.accepted.connect(function() {
102                         currentStatus.cycling = false
103                     })
104                 }
105                 else {
106                     currentStatus.startJourney()
107                 }
108             }
109         }
110     }
111 }