X-Git-Url: https://www.flypig.org.uk/git/?p=harbour-pedalo.git;a=blobdiff_plain;f=qml%2Fcover%2FCoverPage.qml;fp=qml%2Fcover%2FCoverPage.qml;h=a4a911b8937afd813b921f8186ae1f1afa18a413;hp=fc562d5d7200d6d9ee0b911d9353614ec1fde633;hb=48a4da912f9df07681ba68d33475e1d43cfab571;hpb=70180c4c4fd2807d16f90562d6876f3f07d388b1 diff --git a/qml/cover/CoverPage.qml b/qml/cover/CoverPage.qml index fc562d5..a4a911b 100644 --- a/qml/cover/CoverPage.qml +++ b/qml/cover/CoverPage.qml @@ -1,22 +1,111 @@ 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() + } + } } } }