1708d2021a7c0054876ba59384ae83219a09efcf
[harbour-pedalo.git] / qml / pages / JourneyList.qml
1 import QtQuick 2.0
2 import Sailfish.Silica 1.0
3
4 Page {
5     id: page
6
7     // The effective value will be restricted by ApplicationWindow.allowedOrientations
8     allowedOrientations: Orientation.All
9     property int columnwidth: page.width - 2 * Theme.horizontalPageMargin
10
11     SilicaListView {
12         id: listView
13         model: journeymodel
14         anchors.fill: parent
15         header: PageHeader {
16             title: qsTr("Journey list")
17         }
18         delegate: ListItem {
19             id: delegate
20             menu: journeyMenuComponent
21
22             Row {
23                 spacing: Theme.paddingLarge
24                 x: Theme.horizontalPageMargin
25
26                 Label {
27                     width: columnwidth / 3.0
28                     text: Qt.formatDate(journeymodel.epochToDate(start), "d MMM yyyy")
29                     color: delegate.highlighted ? Theme.highlightColor : Theme.primaryColor
30                 }
31                 Label {
32                     width: columnwidth / 3.0
33                     text: Qt.formatTime(journeymodel.epochToTime(start), "hh:mm")
34                     color: delegate.highlighted ? Theme.highlightColor : Theme.primaryColor
35                 }
36                 Label {
37                     width: columnwidth / 3.0
38                     text: Qt.formatTime(new Date(0, 0, 0, 0, 0, duration), 'hh:mm')
39                     color: delegate.highlighted ? Theme.highlightColor : Theme.primaryColor
40                 }
41             }
42             onClicked: pageStack.push(Qt.resolvedUrl("JourneyInfo.qml"), {title: "Journey info", index: index, start: journeymodel.epochToDateTime(start), duration: duration, overtook: overtook, overtakenby: overtakenby})
43
44             Component {
45                 id: journeyMenuComponent
46                 ContextMenu {
47                     MenuItem {
48                         text: qsTr("Edit")
49                         onClicked: pageStack.push(Qt.resolvedUrl("JourneyEdit.qml"), {title: "Edit journey", index: index, start: journeymodel.epochToDateTime(start), duration: duration, overtook: overtook, overtakenby: overtakenby})
50                     }
51                     MenuItem {
52                         text: qsTr("Delete")
53                         onClicked: remove(index)
54                     }
55                 }
56             }
57
58             function remove(index) {
59                 remorseAction(qsTr("Deleting journey"), function() {
60                     onClicked: journeymodel.deleteJourney(index)
61                 })
62             }
63         }
64         VerticalScrollDecorator {}
65     }
66 }