Added Header combo-box
[quandoparte] / application / resources / harmattan / qml / StationListPage.qml
1 import QtQuick 1.0
2 import QtMobility.location 1.1
3 import com.nokia.meego 1.0
4 import net.cirulla.quandoparte 1.0
5
6 Page {
7     property variant stationView
8     id: stationListPage
9     Component.onCompleted: {
10         stationListProxyModel.sortingMode = StationListProxyModel.AlphaSorting
11     }
12     tools: ToolBarLayout {
13         id: toolBar
14         ToolIcon { iconId: "icon-m-toolbar-back"; onClicked: pageStack.pop(); }
15         ToolIcon { iconId: "icon-m-toolbar-settings"; onClicked: settingsSheet.open(); }
16         ToolIcon { iconId: "icon-m-toolbar-view-menu"; }
17     }
18
19     function loadStation()
20     {
21         var component = Qt.createComponent("StationPage.qml");
22         if (component.status == Component.Ready) {
23             var view = component.createObject(stationListPage)
24             stationListPage.stationView = view
25             pageStack.push(view)
26             view.html = "<h1>Hello World</h1><p>Lorem ipsum</p>"
27         }
28         else
29             console.log('Cannot load component: ' + component.errorString());
30     }
31
32     function highlightSearch(s)
33     {
34         // TODO compile RegExp on change, or find a way to cleanly use
35         // stationListProxyModel.filterRegExp
36         if (searchField.text.length) {
37             var r = new RegExp(searchField.text, 'i')
38             var match = r.exec(s)
39             return s.replace(r, '<span style="text-decoration:underline">' +
40                              match + '</span>')
41         } else {
42             return s
43         }
44     }
45
46     PageHeader {
47         id: header
48         anchors.top: parent.top
49         text: qsTr("Stations")
50         options: ListModel {
51             id: dialogOptions
52             ListElement {
53                 name: QT_TR_NOOP("Stations by Name")
54             }
55             ListElement {
56                 name: QT_TR_NOOP("Stations by Distance")
57             }
58             ListElement {
59                 name: QT_TR_NOOP("Stations Recently Seen")
60             }
61         }
62         onSelectedIndexChanged: {
63             header.text = dialogOptions.get(selectedIndex).name
64             switch (selectedIndex) {
65             case 0:
66                 stationListProxyModel.sortingMode = StationListProxyModel.AlphaSorting
67                 break;
68             case 1:
69                 stationListProxyModel.sortingMode = StationListProxyModel.DistanceSorting
70                 break;
71             case 2:
72                 stationListProxyModel.sortingMode = StationListProxyModel.RecentUsageSorting
73                 break;
74             }
75         }
76     }
77     SearchBar {
78         id: searchField
79         anchors.top: header.bottom
80     }
81     Binding {
82         target: stationListProxyModel
83         property: "searchPattern"
84         value: searchField.text
85     }
86     Column {
87         x: 16
88         y: 16
89         anchors.top: searchField.bottom
90         width: parent.width - 32
91         height: parent.height
92         spacing: 16
93         ListView {
94             id: stationListView
95             clip: true
96             width: parent.width
97             height: parent.height
98             model:  stationListProxyModel
99             delegate: Item {
100                 id: listItem
101                 height: 48
102                 width: parent.width
103                 BorderImage {
104                     id: background
105                     anchors.fill: parent
106                     // Fill page borders
107                     visible: mouseArea.pressed
108                     source: "image://theme/meegotouch-list-background-pressed-center"
109                 }
110                 Row {
111                     anchors.fill: parent
112
113                     Column {
114                         anchors.verticalCenter: parent.verticalCenter
115
116                         Label {
117                             id: mainText
118                             text: highlightSearch(model.display)
119                             font.bold: true
120                         }
121                     }
122                 }
123                 MouseArea {
124                     id: mouseArea
125                     anchors.fill: background
126                     onClicked: {
127                         stationListPage.loadStation(model.display)
128                     }
129                 }
130             }
131         }
132     }
133
134     Sheet {
135         id: settingsSheet
136         acceptButtonText: qsTr("Save")
137         rejectButtonText: qsTr("Cancel")
138         content: Item {
139             x: 16
140             y: 16
141             width: parent.width - 32
142             height: parent.height - 32
143             Column {
144                 spacing: 16
145                 anchors.fill: parent
146                 Row {
147                     height: 40
148                     spacing: 16
149                     anchors.left: parent.left
150                     anchors.right: parent.right
151                     Label {
152                         font.bold: true
153                         text: "Show Last Station on Startup"
154                         anchors.verticalCenter: parent.verticalCenter
155                     }
156                     Switch {
157                         anchors.verticalCenter: parent.verticalCenter
158                         id: showLastStationSwitch
159                         anchors.right: parent.right
160                     }
161                 }
162                 Row {
163                     height: 40
164                     spacing: 16
165                     anchors.left: parent.left
166                     anchors.right: parent.right
167                     Label {
168                         font.bold: true
169                         text: "Update Display Periodically"
170                         anchors.verticalCenter: parent.verticalCenter
171                     }
172                     Switch {
173                         anchors.verticalCenter: parent.verticalCenter
174                         anchors.right: parent.right
175                         id: periodicCheckSwitch
176                     }
177                 }
178             }
179         }
180     }
181 }
182