Bump version to 0.2.2
[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) - 4 * Theme.paddingLarge
10
11     SilicaListView {
12         id: listView
13         model: journeymodel
14         anchors.fill: parent
15         header: Column {
16             width: page.width
17             spacing: Theme.paddingLarge
18             height: implicitHeight + Theme.paddingLarge
19
20             PageHeader {
21                 id: headerItem
22                 title: qsTr("Journey list")
23             }
24
25             Row {
26                 spacing: Theme.paddingLarge
27                 x: Theme.horizontalPageMargin
28                 y: headerItem.height
29
30                 Label {
31                     width: columnwidth * 0.34
32                     text: "Date"
33                     color: Theme.secondaryColor
34                 }
35                 Label {
36                     width: columnwidth * 0.18
37                     text: "Start"
38                     color: Theme.secondaryColor
39                 }
40                 Label {
41                     width: columnwidth * 0.18
42                     text: "Length"
43                     color: Theme.secondaryColor
44                 }
45                 Label {
46                     width: columnwidth * 0.15
47                     text: "+"
48                     color: Theme.secondaryColor
49                     horizontalAlignment: Text.AlignRight
50                 }
51                 Label {
52                     width: columnwidth * 0.15
53                     text: "-"
54                     color: Theme.secondaryColor
55                     horizontalAlignment: Text.AlignRight
56                 }
57             }
58         }
59
60         delegate: ListItem {
61             id: delegate
62             menu: journeyMenuComponent
63
64             Row {
65                 spacing: Theme.paddingLarge
66                 x: Theme.horizontalPageMargin
67
68                 Label {
69                     width: columnwidth * 0.34
70                     text: Qt.formatDate(journeymodel.epochToDate(start), "d MMM yyyy")
71                     color: delegate.highlighted ? Theme.highlightColor : Theme.primaryColor
72                 }
73                 Label {
74                     width: columnwidth * 0.18
75                     text: Qt.formatTime(journeymodel.epochToTime(start), "hh:mm")
76                     color: delegate.highlighted ? Theme.highlightColor : Theme.primaryColor
77                 }
78                 Label {
79                     width: columnwidth * 0.18
80                     text: Qt.formatTime(new Date(0, 0, 0, 0, 0, duration), 'hh:mm')
81                     color: delegate.highlighted ? Theme.highlightColor : Theme.primaryColor
82                 }
83                 Label {
84                     width: columnwidth * 0.15
85                     text: overtook
86                     color: delegate.highlighted ? Theme.highlightColor : Theme.primaryColor
87                     horizontalAlignment: Text.AlignRight
88                 }
89                 Label {
90                     width: columnwidth * 0.15
91                     text: overtakenby
92                     color: delegate.highlighted ? Theme.highlightColor : Theme.primaryColor
93                     horizontalAlignment: Text.AlignRight
94                 }
95             }
96             onClicked: pageStack.push(Qt.resolvedUrl("JourneyInfo.qml"), {title: "Journey info", index: index, start: journeymodel.epochToDateTime(start), duration: duration, overtook: overtook, overtakenby: overtakenby})
97
98             Component {
99                 id: journeyMenuComponent
100                 ContextMenu {
101                     MenuItem {
102                         text: qsTr("Edit")
103                         onClicked: pageStack.push(Qt.resolvedUrl("JourneyEdit.qml"), {title: "Edit journey", index: index, start: journeymodel.epochToDateTime(start), duration: duration, overtook: overtook, overtakenby: overtakenby})
104                     }
105                     MenuItem {
106                         text: qsTr("Delete")
107                         onClicked: remove(index)
108                     }
109                 }
110             }
111
112             function remove(index) {
113                 remorseAction(qsTr("Deleting journey"), function() {
114                     onClicked: journeymodel.deleteJourney(index)
115                 })
116             }
117         }
118         VerticalScrollDecorator {}
119     }
120 }