Add duration entry dialog
authorDavid Llewellyn-Jones <david@flypig.co.uk>
Sat, 14 Jul 2018 18:56:08 +0000 (19:56 +0100)
committerDavid Llewellyn-Jones <david@flypig.co.uk>
Sat, 14 Jul 2018 18:56:08 +0000 (19:56 +0100)
harbour-pedalo.pro
qml/pages/AddJourney.qml
qml/pages/DurationEditDialog.qml [new file with mode: 0644]
translations/harbour-pedalo-de.ts
translations/harbour-pedalo.ts

index 26b606e..1ec2ced 100644 (file)
@@ -45,6 +45,7 @@ DISTFILES += qml/harbour-pedalo.qml \
     qml/pages/Stats.qml \
     qml/pages/JourneyList.qml \
     qml/pages/About.qml \
+    qml/pages/DurationEditDialog.qml \
     qml/components/InfoRow.qml
 
 SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172
index 9d7a436..a9124ae 100644 (file)
@@ -79,8 +79,9 @@ Dialog {
                 onClicked: {
                     var dialog = pageStack.push("Sailfish.Silica.TimePickerDialog", { hour: time.getHours(), minute: time.getMinutes()})
                     dialog.accepted.connect(function() {
-                        time = new Date(0, 0, 0, dialog.hour, dialog.minute)
-                        duration = ((endTime.time.getHours() - start.getHours()) * 60) + (endTime.time.getMinutes() - start.getMinutes()) * 60
+                        // We have to hack around the fact that % in Javascript is 'remainder' and not 'mod' (hence will happpily return negative numbers)
+                        duration = ((((((dialog.hour - start.getHours()) * 60) + (dialog.minute - start.getMinutes())) * 60) % 86400) + 86400) % 86400
+                        // Updating the duration will automatically trigger the end time to be udpated
                     })
                 }
                 onTimeChanged: {
@@ -94,7 +95,7 @@ Dialog {
                 value: Qt.formatTime(new Date(0, 0, 0, 0, parseInt(duration / 60)), 'hh:mm')
                 width: parent.width
                 onClicked: {
-                    var dialog = pageStack.push("Sailfish.Silica.TimePickerDialog", { hour: parseInt(duration / (60 * 60)), minute: parseInt(duration / 60) % 60})
+                    var dialog = pageStack.push("DurationEditDialog.qml", { hour: parseInt(duration / (60 * 60)), minute: parseInt(duration / 60) % 60})
                     dialog.accepted.connect(function() {
                         duration = ((dialog.hour * 60) + dialog.minute) * 60
                     })
diff --git a/qml/pages/DurationEditDialog.qml b/qml/pages/DurationEditDialog.qml
new file mode 100644 (file)
index 0000000..95e2dff
--- /dev/null
@@ -0,0 +1,91 @@
+import QtQuick 2.0
+import Sailfish.Silica 1.0
+//import "editdialog"
+//import "../common"
+
+// Amended version of /usr/share/jolla-clock/pages/ClockEditDialog.qml
+Dialog {
+    id: dialog
+
+    property alias hour: timePicker.hour
+    property alias minute: timePicker.minute
+
+    property Item timePicker: timePicker
+    property bool leftToRight: qsTr("LTR") !== "RTL"
+
+    canAccept: true
+
+    SilicaFlickable {
+        anchors.fill: parent
+        contentHeight: column.height
+        flickableDirection: Flickable.VerticalFlick
+
+        Column {
+            id: column
+
+            width: parent.width
+            spacing: Theme.paddingLarge
+
+            DialogHeader {
+                id: header
+            }
+            Item {
+                height: childrenRect.height
+                width: parent.width
+                TimePicker {
+                    id: timePicker
+                    x: isPortrait ? (column.width-width)/2 : Theme.horizontalPageMargin
+                    // otherwise in 12h mode this caused timer 00:00 to display as 12:00am
+                    hourMode: DateTime.TwentyFourHours
+
+                    Column {
+                        id: timerLabelColumn
+                        anchors.centerIn: parent
+
+                        //: Can have two values: "LTR" if remaining time in timer item should be written in "[value] [unit]" order i.e. "2 min", or "RTL" i.e. right-to-left like in Arabic writing systems
+                        spacing: -Theme.paddingMedium
+                        Row {
+                            spacing: Theme.paddingSmall
+                            anchors.horizontalCenter: parent.horizontalCenter
+                            layoutDirection: leftToRight ? Qt.LeftToRight : Qt.RightToLeft
+                            Label {
+                                id: hours
+                                text: timePicker.hour.toLocaleString()
+                                font.pixelSize: Theme.fontSizeHuge
+                                height: Math.min(implicitHeight, (timePicker.height*0.4 - timerLabelColumn.spacing)/2)
+                                fontSizeMode: Text.VerticalFit
+                            }
+                            Label {
+                                id: hoursLabel
+                                //: "Hour abbrevation. Should be short form if possible."
+                                text: qsTr("h")
+                                anchors.baseline: hours.baseline
+                                opacity: 0.7
+                            }
+                        }
+                        Row {
+                            spacing: Theme.paddingSmall
+                            anchors.horizontalCenter: parent.horizontalCenter
+                            layoutDirection: leftToRight ? Qt.LeftToRight : Qt.RightToLeft
+                            Label {
+                                id: minutes
+                                text: timePicker.minute.toLocaleString()
+                                font.pixelSize: Theme.fontSizeHuge
+                                height: Math.min(implicitHeight, (timePicker.height*0.4 - timerLabelColumn.spacing)/2)
+                                fontSizeMode: Text.VerticalFit
+                            }
+                            Label {
+                                id: minuteLabel
+                                //: "Minute abbrevation. Should be short form if possible."
+                                text: qsTr("min")
+                                anchors.baseline: minutes.baseline
+                                verticalAlignment: Text.AlignBottom
+                                opacity: 0.7
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
index b4b309c..2a19b3f 100644 (file)
     </message>
 </context>
 <context>
+    <name>DurationEditDialog</name>
+    <message>
+        <source>LTR</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>h</source>
+        <extracomment>&quot;Hour abbrevation. Should be short form if possible.&quot;</extracomment>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>min</source>
+        <extracomment>&quot;Minute abbrevation. Should be short form if possible.&quot;</extracomment>
+        <translation type="unfinished"></translation>
+    </message>
+</context>
+<context>
     <name>JourneyList</name>
     <message>
         <source>Journey list</source>
index 098c5b2..74b615b 100644 (file)
     </message>
 </context>
 <context>
+    <name>DurationEditDialog</name>
+    <message>
+        <source>LTR</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>h</source>
+        <extracomment>&quot;Hour abbrevation. Should be short form if possible.&quot;</extracomment>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <source>min</source>
+        <extracomment>&quot;Minute abbrevation. Should be short form if possible.&quot;</extracomment>
+        <translation type="unfinished"></translation>
+    </message>
+</context>
+<context>
     <name>JourneyList</name>
     <message>
         <source>Journey list</source>