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