Add flashy spiral timer to cover
[harbour-pedalo.git] / qml / cover / CoverPage.qml
index fc562d5..a4a911b 100644 (file)
 import QtQuick 2.0
 import Sailfish.Silica 1.0
+import harbour.pedalo.settings 1.0
 
 CoverBackground {
-    Label {
-        id: label
-        anchors.centerIn: parent
-        text: qsTr("My Cover")
+    id: root
+    property bool update: status === Cover.Active && currentStatus.cycling
+
+    onUpdateChanged: {
+        stopwatch.updateseconds()
+        stopwatchtrigger.restart()
+    }
+
+    Item {
+        id: stopwatch
+        property int seconds: 0
+        property int fast: seconds < 60 * 10
+        property bool update: root.update
+
+        Timer {
+            id: stopwatchtrigger
+            interval: stopwatch.fast ? 200 : 5000
+            running: root.update
+            repeat: true
+            triggeredOnStart: true
+            onTriggered: {
+                stopwatch.updateseconds()
+            }
+        }
+
+        function updateseconds() {
+            stopwatch.seconds = (new Date().getTime() - currentStatus.startTime) / 1000
+        }
+    }
+
+    Item {
+        id: contents
+
+        width: Theme.coverSizeLarge.width
+        height: Theme.coverSizeLarge.height
+        property real xScale: root.width / contents.width
+
+        transform: Scale {
+            xScale: contents.xScale
+            yScale: root.height / contents.height
+        }
+
+    ClockView {
+        id: clockView
+
+        anchors {
+            top: parent.top
+            left: parent.left
+            right: parent.right
+            margins: Theme.paddingLarge
+        }
+        height: width
+    }
+
+    LargeItem {
+        id: stopwatchView
+
+        anchors {
+            top: clockView.bottom
+            topMargin: Theme.paddingMedium
+            leftMargin: Theme.paddingLarge
+            rightMargin: Theme.paddingLarge
+        }
+
+        textVisible: root.update
+
+        title: qsTr("Pedalo")
+
+        text: {
+            if (stopwatch.seconds < 60) {
+                return qsTr("%n seconds", "", stopwatch.seconds)
+            } else if (stopwatch.seconds < 60*60) {
+                return qsTr("%1 minutes").arg(Math.floor(stopwatch.seconds/60))
+            } else {
+                var minutes = Math.floor(stopwatch.seconds/60)
+                var hours = Math.floor(minutes/60)
+                minutes = minutes % 60
+                return qsTrId("%1h %2min").arg(hours).arg(minutes)
+            }
+        }
+    }
     }
 
     CoverActionList {
         id: coverAction
 
         CoverAction {
-            iconSource: "image://theme/icon-cover-next"
-        }
+            iconSource: currentStatus.cycling ? Settings.getImageUrl("icon-cover-journey-finish") : Settings.getImageUrl("icon-cover-journey-start")
+            onTriggered: {
+                if (currentStatus.cycling) {
+                    app.activate()
+                    app.showMainPage(PageStackAction.Immediate)
 
-        CoverAction {
-            iconSource: "image://theme/icon-cover-pause"
+                    var dialog = pageStack.push(Qt.resolvedUrl("../pages/JourneyEdit.qml"), {title: "Finish journey", start: journeymodel.epochToDateTime(currentStatus.startTime), duration: currentStatus.getDuration()})
+
+                    dialog.accepted.connect(function() {
+                        currentStatus.cycling = false
+                    })
+                }
+                else {
+                    currentStatus.startJourney()
+                }
+            }
         }
     }
 }