8ede92363afe65926e64c3b1a00e870d67be0231
[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             objectName:
57                     searchField.focus = false
58             delegate: ListItem {
59                 id: listItem
60                 contentHeight: Theme.itemSizeExtraSmall
61                 width: parent.width
62                 Label {
63                     id: mainText
64                     anchors {
65                         fill: parent
66                         margins: Theme.paddingMedium
67                     }
68                     x: Theme.paddingLarge
69                     textFormat: Text.StyledText
70                     text: model.name ? Private.highlightSearch(model.name, Theme.highlightColor) : ""
71                     verticalAlignment: Text.AlignVCenter
72                 }
73                 Image {
74                     id: favoriteIndicator
75                     visible: model.favorite
76                     source: "image://theme/icon-m-favorite-selected"
77                     anchors {
78                         verticalCenter: parent.verticalCenter
79                         right: parent.right
80                     }
81                 }
82                 onClicked: {
83                     Private.loadStation(model.name, model.code)
84                 }
85                 //onPressAndHold: contextMenu.show(listItem)
86                 menu: contextMenu
87                 Component {
88                     id: contextMenu
89                     ContextMenu {
90                         MenuItem {
91                             text: model.favorite ? qsTr("Remove from Favorites") : qsTr("Add to Favorites")
92                             onClicked: {
93                                 console.log("Favorite Stations (before):" + settings.favoriteStations)
94                                 model.favorite ^= true
95                                 /*
96                                 var index = settings.favoriteStations.indexOf(model.name)
97                                 if (index === -1)
98                                     settings.favoriteStations.push(model.name)
99                                 else settings.favoriteStations.splice(index, 1)
100                                 */
101                                 console.log("Favorite Stations (after):" + settings.favoriteStations)
102                             }
103                         }
104                         MenuItem {
105                             text: qsTr("Show on the map")
106                             onClicked: Qt.openUrlExternally("geo:" + model.latitude + "," + model.longitude)
107                         }
108                     }
109                 }
110             }
111             VerticalScrollDecorator {}
112         }
113     }
114 }