From: David Llewellyn-Jones Date: Sat, 14 Jul 2018 18:56:08 +0000 (+0100) Subject: Add duration entry dialog X-Git-Url: https://www.flypig.org.uk/git/?p=harbour-pedalo.git;a=commitdiff_plain;h=badbb9139e0e5b3bc114ae7c150e6d9ab5183566;ds=sidebyside Add duration entry dialog --- diff --git a/harbour-pedalo.pro b/harbour-pedalo.pro index 26b606e..1ec2ced 100644 --- a/harbour-pedalo.pro +++ b/harbour-pedalo.pro @@ -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 diff --git a/qml/pages/AddJourney.qml b/qml/pages/AddJourney.qml index 9d7a436..a9124ae 100644 --- a/qml/pages/AddJourney.qml +++ b/qml/pages/AddJourney.qml @@ -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 index 0000000..95e2dff --- /dev/null +++ b/qml/pages/DurationEditDialog.qml @@ -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 + } + } + } + } + } + } + } +} diff --git a/translations/harbour-pedalo-de.ts b/translations/harbour-pedalo-de.ts index b4b309c..2a19b3f 100644 --- a/translations/harbour-pedalo-de.ts +++ b/translations/harbour-pedalo-de.ts @@ -42,6 +42,23 @@ Mein Cover + + DurationEditDialog + + LTR + + + + h + "Hour abbrevation. Should be short form if possible." + + + + min + "Minute abbrevation. Should be short form if possible." + + + JourneyList diff --git a/translations/harbour-pedalo.ts b/translations/harbour-pedalo.ts index 098c5b2..74b615b 100644 --- a/translations/harbour-pedalo.ts +++ b/translations/harbour-pedalo.ts @@ -42,6 +42,23 @@ + + DurationEditDialog + + LTR + + + + h + "Hour abbrevation. Should be short form if possible." + + + + min + "Minute abbrevation. Should be short form if possible." + + + JourneyList