Moved SearchBar to its own qml file
[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         // TODO compile RegExp on change, or find a way to cleanly use
31         // stationListProxyModel.filterRegExp
32         if (searchField.text.length) {
33             var r = new RegExp(searchField.text, 'i')
34             var match = r.exec(s)
35             return s.replace(r, '<span style="text-decoration:underline">' +
36                              match + '</span>')
37         } else {
38             return s
39         }
40     }
41
42     Column {
43         x: 16
44         y: 16
45         width: parent.width - 32
46         height: parent.height
47         spacing: 16
48         SearchBar {
49             id: searchField
50         }
51         Binding {
52             target: stationListProxyModel
53             property: "searchPattern"
54             value: searchField.text
55         }
56         ListView {
57             id: stationListView
58             clip: true
59             width: parent.width
60             height: parent.height
61             model:  stationListProxyModel
62             delegate: Item {
63                 id: listItem
64                 height: 48
65                 width: parent.width
66                 BorderImage {
67                     id: background
68                     anchors.fill: parent
69                     // Fill page borders
70                     visible: mouseArea.pressed
71                     source: "image://theme/meegotouch-list-background-pressed-center"
72                 }
73                 Row {
74                     anchors.fill: parent
75
76                     Column {
77                         anchors.verticalCenter: parent.verticalCenter
78
79                         Label {
80                             id: mainText
81                             text: highlightSearch(model.display)
82                             font.bold: true
83                         }
84                     }
85                 }
86                 MouseArea {
87                     id: mouseArea
88                     anchors.fill: background
89                     onClicked: {
90                         stationListPage.loadStation(model.display)
91                     }
92                 }
93             }
94         }
95     }
96
97     Sheet {
98         id: settingsSheet
99         acceptButtonText: "Save"
100         rejectButtonText: "Cancel"
101         content: Item {
102             x: 16
103             y: 16
104             width: parent.width - 32
105             height: parent.height - 32
106             Column {
107                 spacing: 16
108                 anchors.fill: parent
109                 Row {
110                     height: 40
111                     spacing: 16
112                     anchors.left: parent.left
113                     anchors.right: parent.right
114                     Label {
115                         font.bold: true
116                         text: "Show Last Station on Startup"
117                         anchors.verticalCenter: parent.verticalCenter
118                     }
119                     Switch {
120                         anchors.verticalCenter: parent.verticalCenter
121                         id: showLastStationSwitch
122                         anchors.right: parent.right
123                     }
124                 }
125                 Row {
126                     height: 40
127                     spacing: 16
128                     anchors.left: parent.left
129                     anchors.right: parent.right
130                     Label {
131                         font.bold: true
132                         text: "Update Display Periodically"
133                         anchors.verticalCenter: parent.verticalCenter
134                     }
135                     Switch {
136                         anchors.verticalCenter: parent.verticalCenter
137                         anchors.right: parent.right
138                         id: periodicCheckSwitch
139                     }
140                 }
141             }
142         }
143     }
144 }
145