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