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