Work in progress on QML
[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     property variant stationView
8     id: stationListPage
9     Binding {
10         target: stationListProxyModel
11         property: "searchPattern"
12         value: searchField.text
13     }
14     Binding {
15         target: stationListProxyModel
16         property: "sortingMode"
17         value: header.currentIndex
18     }
19     Binding {
20         target: stationListView
21         property: "section.property"
22         value: header.currentIndex === 0 ? "name" : ""
23     }
24     SilicaListView {
25         id: stationListView
26         clip: true
27         width: parent.width
28         cacheBuffer: 10
29         anchors.fill: parent
30         model:  stationListProxyModel
31         header: Column {
32             ComboBox {
33                 id: header
34                 currentIndex: stationListProxyModel.sortingMode
35                 menu: ContextMenu {
36                     MenuItem {
37                         text: qsTr("by Name")
38                     }
39                     MenuItem {
40                         text: qsTr("by Distance")
41                     }
42                     MenuItem {
43                         text: qsTr("Recently Seen")
44                     }
45                 }
46                 label: qsTr("Stations")
47             }
48             SearchField {
49                 id: searchField
50                 placeholderText: qsTr("Search station...")
51             }
52         }
53         section {
54             criteria: ViewSection.FirstCharacter
55             delegate: Item {
56                 width: parent.width
57                 height: Theme.itemSizeSmall
58                 anchors {
59                     margins: Theme.paddingMedium
60                 }
61                 Image {
62                     anchors {
63                         left: parent.left
64                         right: sectionLabel.left
65                         verticalCenter: parent.verticalCenter
66                         margins: Theme.paddingMedium
67                     }
68                     source: "image://theme/meegotouch-separator-" + (theme.inverted ? "inverted-" : "") + "background-horizontal"
69                 }
70                 Label {
71                     id: sectionLabel
72                     anchors {
73                         right: sectionRightMargin.left
74                         verticalCenter: parent.verticalCenter
75                     }
76                     text: section
77                 }
78                 Item {
79                     id: sectionRightMargin
80                     anchors {
81                         right: parent.right
82                     }
83                     width: Theme.paddingMedium
84                     height: Theme.paddingMedium
85                 }
86             }
87             delegate: BackgroundItem {
88                 id: listItem
89                 height: Theme.itemSizeSmall
90                 width: parent.width
91                 Label {
92                     id: mainText
93                     x: Theme.paddingLarge
94                     text: Private.highlightSearch(model.name, Theme.highlightColor)
95                 }
96                 onClicked: Private.loadStation(model.name, model.code)
97             }
98         }
99     }
100     ScrollDecorator {
101         id: decorator
102         flickable: stationListView
103     }
104 }