eef2e38abb4f00bf9c492bc1d1a028b2891bd933
[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     SilicaFlickable {
16         interactive: !stationListView.flicking
17         anchors.fill: parent
18         pressDelay: 0
19         PullDownMenu {
20             MenuItem {
21                 text: qsTr("About Quando Parte")
22                 onClicked: pageStack.push(Qt.resolvedUrl("AboutPage.qml"))
23             }
24             MenuItem {
25                 text: qsTr("Stations by Name")
26                 onClicked: stationListProxyModel.sortingMode = StationListProxyModel.AlphaSorting
27             }
28             MenuItem {
29                 text: qsTr("Stations by Distance")
30                 onClicked: stationListProxyModel.sortingMode = StationListProxyModel.DistanceSorting
31             }
32             MenuItem {
33                 text: qsTr("Stations Recently Seen")
34                 onClicked: stationListProxyModel.sortingMode = StationListProxyModel.RecentUsageSorting
35             }
36         }
37         PageHeader {
38             id: header
39             SearchField {
40                 id: searchField
41                 placeholderText: qsTr("Search station...")
42                 inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
43                 onTextChanged: stationListPage.searchPattern = searchField.text
44                 width: stationListPage.width
45                 EnterKey.onClicked: searchField.focus = false
46                 EnterKey.iconSource: "image://theme/icon-m-enter-close"
47             }
48         }
49         SilicaListView {
50             id: stationListView
51             clip: true
52             width: parent.width
53             cacheBuffer: 4 * Theme.itemSizeExtraSmall
54             anchors.top: header.bottom
55             anchors.bottom: parent.bottom
56             model:  stationListProxyModel
57             delegate: ListItem {
58                 id: listItem
59                 contentHeight: Theme.itemSizeExtraSmall
60                 width: parent.width
61                 Label {
62                     id: mainText
63                     anchors {
64                         fill: parent
65                         margins: Theme.paddingMedium
66                     }
67                     x: Theme.paddingLarge
68                     textFormat: Text.StyledText
69                     text: model.name ? Private.highlightSearch(model.name, Theme.highlightColor) : ""
70                     verticalAlignment: Text.AlignVCenter
71                 }
72                 Image {
73                     id: favoriteIndicator
74                     visible: model.favorite
75                     source: "image://theme/icon-m-favorite-selected"
76                     anchors {
77                         verticalCenter: parent.verticalCenter
78                         right: parent.right
79                     }
80                 }
81                 menu: contextMenu
82                 Component {
83                     id: contextMenu
84                     ContextMenu {
85                         MenuItem {
86                             text: model.favorite ? qsTr("Remove from Favorites") : qsTr("Add to Favorites")
87                             onClicked: {
88                                 model.favorite ^= true
89                                 console.log("Favorite Stations:" + settings.favoriteStations)
90                             }
91                         }
92                         MenuItem {
93                             text: qsTr("Show on the map")
94                             onClicked: Qt.openUrlExternally("geo:" + model.latitude + "," + model.longitude)
95                         }
96                     }
97                 }
98                 onPressed: searchField.focus = false
99                 onClicked: Private.loadStation(model.name, model.code)
100             }
101             VerticalScrollDecorator {}
102         }
103     }
104 }