Implement Station map lookup
[quandoparte] / application / resources / sailfish / qml / pages / StationListPage.qml
1 import QtQuick 2.0
2 import QtLocation 5.0
3 import Sailfish.Silica 1.0
4 import net.cirulla.quandoparte 1.0
5 import "StationListPage.js" as Private
6
7 Page {
8     id: stationListPage
9     property variant stationView
10     property string searchPattern
11     Binding {
12         target: stationListProxyModel
13         property: "searchPattern"
14         value: stationListPage.searchPattern
15     }
16     SilicaListView {
17         id: stationListView
18         clip: true
19         width: parent.width
20         cacheBuffer: 10
21         anchors.top: parent.top
22         anchors.bottom: parent.bottom
23         model:  stationListProxyModel
24         PullDownMenu {
25             MenuItem {
26                 text: qsTr("About Quando Parte")
27                 onClicked: pageStack.push(Qt.resolvedUrl("AboutPage.qml"))
28             }
29             MenuItem {
30                 text: qsTr("Stations by Name")
31                 onClicked: stationListProxyModel.sortingMode = StationListProxyModel.AlphaSorting
32             }
33             MenuItem {
34                 text: qsTr("Stations by Distance")
35                 onClicked: stationListProxyModel.sortingMode = StationListProxyModel.DistanceSorting
36             }
37             MenuItem {
38                 text: qsTr("Stations Recently Seen")
39                 onClicked: stationListProxyModel.sortingMode = StationListProxyModel.RecentUsageSorting
40             }
41         }
42         header: SearchField {
43             id: searchField
44             placeholderText: qsTr("Search station...")
45             onTextChanged: stationListPage.searchPattern = searchField.text
46             width: stationListPage.width
47         }
48         delegate: BackgroundItem {
49             id: listItem
50             height: Theme.itemSizeSmall
51             width: parent.width
52             Label {
53                 id: mainText
54                 anchors {
55                     verticalCenter: parent.Center
56                     margins: Theme.paddingMedium
57                 }
58                 x: Theme.paddingLarge
59                 textFormat: Text.StyledText
60                 text: model.name ? Private.highlightSearch(model.name, Theme.highlightColor) : ""
61             }
62             onClicked: Private.loadStation(model.name, model.code)
63             onPressAndHold: contextMenu.show(listItem)
64             ContextMenu {
65                 id: contextMenu
66                 MenuItem {
67                     text: qsTr("Show on the map")
68                     onClicked: Qt.openUrlExternally("geo:" + model.longitude + "," + model.latitude)
69                 }
70             }
71         }
72     }
73 }