Switch to the stationListProxyModel in QML
[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
5 Page {
6     property variant stationView
7     id: stationListPage
8     tools: ToolBarLayout {
9         id: toolBar
10         ToolIcon { iconId: "icon-m-toolbar-back"; onClicked: pageStack.pop(); }
11         ToolIcon { iconId: "icon-m-toolbar-settings"; onClicked: settingsSheet.open(); }
12         ToolIcon { iconId: "icon-m-toolbar-view-menu"; }
13     }
14
15     function loadStation()
16     {
17         var component = Qt.createComponent("StationPage.qml");
18         if (component.status == Component.Ready) {
19             var view = component.createObject(stationListPage)
20             stationListPage.stationView = view
21             pageStack.push(view)
22             view.html = "<h1>Hello World</h1><p>Lorem ipsum</p>"
23         }
24         else
25             console.log('Cannot load component: ' + component.errorString());
26     }
27
28     function highlightSearch(s)
29     {
30         return s.replace(searchField.text,
31                          '<span style="text-decoration:underline">' +
32                          searchField.text + '</span>')
33     }
34
35     Column {
36         width: parent.width
37         height: parent.height
38         TextField {
39             id: searchField
40             width: parent.width
41             placeholderText: "Search..."
42             platformStyle: TextFieldStyle { paddingRight: clearButton.width }
43             onTextChanged: {
44             }
45             Image {
46                 id: clearButton
47                 anchors.right: parent.right
48                 anchors.verticalCenter: parent.verticalCenter
49                 source: "image://theme/icon-m-input-clear"
50                 MouseArea {
51                     anchors.fill: parent
52                     onClicked: {
53                         inputContext.reset()
54                         searchField.text = ""
55                     }
56                 }
57             }
58         }
59         Rectangle {
60             height: 16
61         }
62         ListView {
63             id: stationListView
64             clip: true
65             width: parent.width
66             height: parent.height
67             model:  stationListProxyModel
68             /*
69             model: ListModel {
70                 id: model
71                 ListElement {
72                     name: "Genova Voltri"
73                 }
74                 ListElement {
75                     name: "Genova Sestri Ponente"
76                 }
77                 ListElement {
78                     name: "Genova Cornigliano"
79                 }
80                 ListElement {
81                     name: "Genova Sampierdarena"
82                 }
83                 ListElement {
84                     name: "Genova Via di Francia"
85                 }
86                 ListElement {
87                     name: "Genova Piazza Principe"
88                 }
89                 ListElement {
90                     name: "Genova Brignole"
91                 }
92                 ListElement {
93                     name: "Genova Sturla"
94                 }
95                 ListElement {
96                     name: "Genova Quinto"
97                 }
98                 ListElement {
99                     name: "Genova Nervi"
100                 }
101             }*/
102             delegate: Item {
103                 id: listItem
104                 height: 48
105                 width: parent.width
106                 BorderImage {
107                     id: background
108                     anchors.fill: parent
109                     // Fill page borders
110                     visible: mouseArea.pressed
111                     source: "image://theme/meegotouch-list-background-pressed-center"
112                 }
113                 Row {
114                     anchors.fill: parent
115
116                     Column {
117                         anchors.verticalCenter: parent.verticalCenter
118
119                         Label {
120                             id: mainText
121                             text: highlightSearch(model.display)
122                             font.bold: true
123                         }
124                     }
125                 }
126                 MouseArea {
127                     id: mouseArea
128                     anchors.fill: background
129                     onClicked: {
130                         stationListPage.loadStation(model.display)
131                     }
132                 }
133             }
134         }
135     }
136
137     Sheet {
138         id: settingsSheet
139         acceptButtonText: "Save"
140         rejectButtonText: "Cancel"
141         content: Item {
142             x: 16
143             y: 16
144             width: parent.width - 32
145             height: parent.height - 32
146             Column {
147                 spacing: 16
148                 anchors.fill: parent
149                 Row {
150                     height: 40
151                     spacing: 16
152                     anchors.left: parent.left
153                     anchors.right: parent.right
154                     Label {
155                         font.bold: true
156                         text: "Show Last Station on Startup"
157                         anchors.verticalCenter: parent.verticalCenter
158                     }
159                     Switch {
160                         anchors.verticalCenter: parent.verticalCenter
161                         id: showLastStationSwitch
162                         anchors.right: parent.right
163                     }
164                 }
165                 Row {
166                     height: 40
167                     spacing: 16
168                     anchors.left: parent.left
169                     anchors.right: parent.right
170                     Label {
171                         font.bold: true
172                         text: "Update Display Periodically"
173                         anchors.verticalCenter: parent.verticalCenter
174                     }
175                     Switch {
176                         anchors.verticalCenter: parent.verticalCenter
177                         anchors.right: parent.right
178                         id: periodicCheckSwitch
179                     }
180                 }
181             }
182         }
183     }
184 }
185