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