Flesh out UI, provide journey data model
[harbour-pedalo.git] / qml / pages / AddJourney.qml
1 import QtQuick 2.0
2 import Sailfish.Silica 1.0
3
4 Dialog {
5     id: addJourneyDialog
6     canAccept: true
7     property string title: "Add journey"
8
9     // The effective value will be restricted by ApplicationWindow.allowedOrientations
10     allowedOrientations: Orientation.All
11
12     SilicaFlickable {
13         id: addJourneyView
14         anchors.fill: parent
15         contentHeight: addJourneyColumn.implicitHeight
16
17         VerticalScrollDecorator {}
18
19         Column {
20             id: addJourneyColumn
21             spacing: Theme.paddingMedium
22             width: parent.width
23
24             DialogHeader {
25                 title: addJourneyDialog.title
26             }
27
28             ValueButton {
29                 id: startDate
30                 function openDateDialog() {
31                     var dialog = pageStack.push("Sailfish.Silica.DatePickerDialog", {
32                                     date: value
33                                  })
34
35                     dialog.accepted.connect(function() {
36                         value = dialog.dateText
37                         selectedDate = dialog.date
38                     })
39                 }
40
41                 label: "Date"
42                 value: Qt.formatDate(new Date(), 'd MMM yyyy')
43                 width: parent.width
44                 onClicked: openDateDialog()
45             }
46
47             ValueButton {
48                 id: startTime
49                 property date time: new Date()
50                 label: qsTr("Start time")
51                 value: Qt.formatTime(time, 'hh:mm')
52                 width: parent.width
53                 onClicked: {
54                     console.log("Hours: " + time.getHours())
55                     console.log("Mins: " + time.getMinutes())
56                     var dialog = pageStack.push("Sailfish.Silica.TimePickerDialog", { hour: time.getHours(), minute: time.getMinutes()})
57                     dialog.accepted.connect(function() {
58                         time = new Date(0, 0, 0, dialog.hour, dialog.minute)
59                     })
60                 }
61                 onTimeChanged: {
62                     value = Qt.formatTime(time, 'hh:mm')
63                     endTime.time = new Date(0, 0, 0, startTime.time.getHours() + durationTime.duration.getHours(), startTime.time.getMinutes() + durationTime.duration.getMinutes())
64                 }
65             }
66
67             ValueButton {
68                 id: endTime
69                 property date time: new Date()
70                 label: qsTr("End time")
71                 value: Qt.formatTime(time, 'hh:mm')
72                 width: parent.width
73                 onClicked: {
74                     var dialog = pageStack.push("Sailfish.Silica.TimePickerDialog", { hour: time.getHours(), minute: time.getMinutes()})
75                     dialog.accepted.connect(function() {
76                         time = new Date(0, 0, 0, dialog.hour, dialog.minute)
77                     })
78                 }
79                 onTimeChanged: {
80                     value = Qt.formatTime(time, 'hh:mm')
81                     durationTime.duration = new Date(0, 0, 0, endTime.time.getHours() - startTime.time.getHours(), endTime.time.getMinutes() - startTime.time.getMinutes())
82                 }
83             }
84
85             ValueButton {
86                 id: durationTime
87                 property date duration: new Date(0, 0, 0, 0, 0)
88                 label: qsTr("Duration")
89                 value: Qt.formatTime(duration, 'hh:mm')
90                 width: parent.width
91                 onClicked: {
92                     var dialog = pageStack.push("Sailfish.Silica.TimePickerDialog", { hour: duration.getHours(), minute: duration.getMinutes()})
93                     dialog.accepted.connect(function() {
94                         duration = new Date(0, 0, 0, dialog.hour, dialog.minute)
95                     })
96                 }
97                 onDurationChanged: {
98                     value = Qt.formatTime(duration, 'hh:mm')
99                     endTime.time = new Date(0, 0, 0, startTime.time.getHours() + durationTime.duration.getHours(), startTime.time.getMinutes() + durationTime.duration.getMinutes())
100                 }
101             }
102
103             TextField {
104                 id: faster
105                 width: parent.width
106                 inputMethodHints: Qt.ImhDigitsOnly
107                 label: qsTr("Cycles which you overtook")
108                 placeholderText: label
109                 horizontalAlignment: TextInput.AlignLeft
110                 EnterKey.iconSource: "image://theme/icon-m-enter-next"
111                 EnterKey.onClicked: slower.focus = true
112             }
113
114             TextField {
115                 id: slower
116                 width: parent.width
117                 inputMethodHints: Qt.ImhDigitsOnly
118                 label: qsTr("Cycles which overtook you")
119                 placeholderText: label
120                 horizontalAlignment: TextInput.AlignLeft
121                 EnterKey.iconSource: "image://theme/icon-m-enter-next"
122                 EnterKey.onClicked: addJourneyDialog.accept()
123             }
124         }
125     }
126 }