2 import Sailfish.Silica 1.0
7 property string title: "Add journey"
8 property var start: new Date()
9 property int duration: 0
10 property int overtook: -1
11 property int overtakenby: -1
12 property int index: -1
15 var structured = new Date(0, 0, 0, 0, parseInt(duration / 60))
16 durationTime.value = Qt.formatTime(structured, 'hh:mm')
17 endTime.time = new Date(0, 0, 0, start.getHours() + structured.getHours(), start.getMinutes() + structured.getMinutes())
21 startDate.value = Qt.formatDate(start, 'd MMM yyyy')
22 startTime.value = Qt.formatTime(start, 'hh:mm')
24 var structured = new Date(0, 0, 0, 0, parseInt(duration / 60))
25 endTime.time = new Date(0, 0, 0, start.getHours() + structured.getHours(), start.getMinutes() + structured.getMinutes())
28 // The effective value will be restricted by ApplicationWindow.allowedOrientations
29 allowedOrientations: Orientation.All
34 contentHeight: headerItem.height + Theme.paddingLarge + (isPortrait ?
35 (journeyEditColumnFirst.implicitHeight + journeyEditColumnSecond.implicitHeight) :
36 Math.max(journeyEditColumnFirst.implicitHeight, journeyEditColumnSecond.implicitHeight))
38 VerticalScrollDecorator {}
42 title: journeyEditDialog.title
46 id: journeyEditColumnFirst
47 spacing: Theme.paddingMedium
48 width: isPortrait ? parent.width : (parent.width * 0.5)
55 value: Qt.formatDate(start, 'd MMM yyyy')
58 var dialog = pageStack.push("Sailfish.Silica.DatePickerDialog", { date: start })
59 dialog.accepted.connect(function() {
60 start = new Date(dialog.year, dialog.month - 1, dialog.day, start.getHours(), start.getMinutes())
67 label: qsTr("Start time")
68 value: Qt.formatTime(start, 'hh:mm')
71 var dialog = pageStack.push("Sailfish.Silica.TimePickerDialog", { hour: start.getHours(), minute: start.getMinutes()})
72 dialog.accepted.connect(function() {
73 start = new Date(start.getFullYear(), start.getMonth(), start.getDate(), dialog.hour, dialog.minute)
80 property date time: new Date()
81 label: qsTr("End time")
82 value: Qt.formatTime(time, 'hh:mm')
85 var dialog = pageStack.push("Sailfish.Silica.TimePickerDialog", { hour: time.getHours(), minute: time.getMinutes()})
86 dialog.accepted.connect(function() {
87 // We have to hack around the fact that % in Javascript is 'remainder' and not 'mod' (hence will happpily return negative numbers)
88 duration = ((((((dialog.hour - start.getHours()) * 60) + (dialog.minute - start.getMinutes())) * 60) % 86400) + 86400) % 86400
89 // Updating the duration will automatically trigger the end time to be udpated
93 value = Qt.formatTime(time, 'hh:mm')
99 label: qsTr("Duration")
100 value: Qt.formatTime(new Date(0, 0, 0, 0, parseInt(duration / 60)), 'hh:mm')
103 var dialog = pageStack.push("DurationEditDialog.qml", { hour: parseInt(duration / (60 * 60)), minute: parseInt(duration / 60) % 60})
104 dialog.accepted.connect(function() {
105 duration = ((dialog.hour * 60) + dialog.minute) * 60
112 id: journeyEditColumnSecond
113 spacing: Theme.paddingMedium
114 width: isPortrait ? parent.width : (parent.width * 0.5)
115 x: isPortrait ? 0 : (parent.width * 0.5)
116 y: isPortrait ? journeyEditColumnFirst.y + journeyEditColumnFirst.height + Theme.paddingLarge : journeyEditColumnFirst.y
121 inputMethodHints: Qt.ImhDigitsOnly
122 label: qsTr("Cycles which you overtook")
123 placeholderText: label
124 text: overtook >= 0 ? "" + overtook : ""
125 horizontalAlignment: TextInput.AlignLeft
126 EnterKey.iconSource: "image://theme/icon-m-enter-next"
127 EnterKey.onClicked: slower.focus = true
133 inputMethodHints: Qt.ImhDigitsOnly
134 label: qsTr("Cycles which overtook you")
135 placeholderText: label
136 text: overtakenby >= 0 ? "" + overtakenby : ""
137 horizontalAlignment: TextInput.AlignLeft
138 EnterKey.iconSource: "image://theme/icon-m-enter-accept"
139 EnterKey.onClicked: journeyEditDialog.accept()
146 var overtook = parseInt(faster.text)
147 var overtakenby = parseInt(slower.text)
149 journeymodel.addJourney(start, duration, overtook, overtakenby)
152 journeymodel.editJourney(index, start, duration, overtook, overtakenby)