Cleanup SailfishOS StationListPage.qml
[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
43                 onTextChanged: stationListPage.searchPattern = searchField.text
44                 width: stationListPage.width
45                 EnterKey.onClicked: searchField.focus = false
46             }
47         }
48         SilicaListView {
49             id: stationListView
50             clip: true
51             width: parent.width
52             cacheBuffer: 4 * Theme.itemSizeExtraSmall
53             anchors.top: header.bottom
54             anchors.bottom: parent.bottom
55             model:  stationListProxyModel
56             delegate: ListItem {
57                 id: listItem
58                 contentHeight: Theme.itemSizeExtraSmall
59                 width: parent.width
60                 Label {
61                     id: mainText
62                     anchors {
63                         fill: parent
64                         margins: Theme.paddingMedium
65                     }
66                     x: Theme.paddingLarge
67                     textFormat: Text.StyledText
68                     text: model.name ? Private.highlightSearch(model.name, Theme.highlightColor) : ""
69                     verticalAlignment: Text.AlignVCenter
70                 }
71                 Image {
72                     id: favoriteIndicator
73                     visible: model.favorite
74                     source: "image://theme/icon-m-favorite-selected"
75                     anchors {
76                         verticalCenter: parent.verticalCenter
77                         right: parent.right
78                     }
79                 }
80                 onClicked: {
81                     searchField.focus = false
82                     Private.loadStation(model.name, model.code)
83                 }
84                 menu: contextMenu
85                 Component {
86                     id: contextMenu
87                     ContextMenu {
88                         MenuItem {
89                             text: model.favorite ? qsTr("Remove from Favorites") : qsTr("Add to Favorites")
90                             onClicked: {
91                                 model.favorite ^= true
92                                 console.log("Favorite Stations:" + settings.favoriteStations)
93                             }
94                         }
95                         MenuItem {
96                             text: qsTr("Show on the map")
97                             onClicked: Qt.openUrlExternally("geo:" + model.latitude + "," + model.longitude)
98                         }
99                     }
100                 }
101             }
102             VerticalScrollDecorator {}
103         }
104     }
105 }