Change QStringList to QVariant for Departures
[pywienerlinien] / qml / ResultRealtime.qml
1 import QtQuick 1.1
2 import com.nokia.meego 1.0
3 import com.nokia.extras 1.0
4 import "UIConstants.js" as UIConstants
5 import "ExtrasConstants.js" as ExtrasConstants
6
7 Item {
8     id: resultRealtime
9
10     property string gline: ''
11     property string gstation: ''
12     property string gdirection: ''
13
14     property string sourceUrl: ''
15     property bool busy: true
16
17     function refresh() {
18         busy = true
19         itip.load_departures(sourceUrl)
20         console.log('refreshing')
21     }
22
23     onSourceUrlChanged: {
24         refresh()
25         console.log('source url changed: ' + sourceUrl)
26     }
27
28     Connections {
29         target: itip
30
31         onDeparturesLoaded: {
32             busy = false
33             departuresModel.clear()
34
35             var departures = itip.get_departures()
36
37             for (var d in departures) {
38                 console.log('time: ' + departures[d].time)
39                 var row = {'line': departures[d].line, 'station': departures[d].station, 'destination': departures[d].direction, 'departure': departures[d].time, 'lowfloor': departures[d].lowfloor}
40                 departuresModel.append(row)
41             }
42         }
43     }
44
45     Component {
46         id: departureDelegate
47
48         Item {
49             width: parent.width
50             height: 80
51
52             BorderImage {
53                 anchors.fill: parent
54                 visible: mouseArea.pressed
55                 source: theme.inverted ? 'image://theme/meegotouch-list-inverted-background-pressed-vertical-center': 'image://theme/meegotouch-list-background-pressed-vertical-center'
56             }
57
58             Item {
59                 anchors.fill: parent
60                 anchors.margins: UIConstants.DEFAULT_MARGIN
61
62                 Row {
63                     spacing: 10
64                     Text {
65                         id: l
66                         text: line // <----
67                         anchors.verticalCenter: parent.verticalCenter
68                         //width: 70
69                         font.pixelSize: UIConstants.FONT_XLARGE
70                         font.bold: true
71                         font.family: ExtrasConstants.FONT_FAMILY_LIGHT
72                         color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
73                     }
74
75                     Column {
76                         anchors.verticalCenter: parent.verticalCenter
77
78                         Text {
79                             id: s
80                             text: station // <----
81                             width: parent.parent.parent.width - l.width - dep.width - 15
82                             elide: Text.ElideRight
83                             font.pixelSize: UIConstants.FONT_LARGE
84                             font.family: ExtrasConstants.FONT_FAMILY_LIGHT
85                             color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
86                         }
87
88                         Text {
89                             id: d
90                             text: destination // <----
91                             width: parent.parent.parent.width - l.width - dep.width - 15
92                             elide: Text.ElideRight
93                             color: !theme.inverted ? UIConstants.COLOR_SECONDARY_FOREGROUND : UIConstants.COLOR_INVERTED_SECONDARY_FOREGROUND
94                             font.family: ExtrasConstants.FONT_FAMILY_LIGHT
95                             font.pixelSize: UIConstants.FONT_LSMALL
96                         }
97                     }
98                 }
99             }
100
101             Column {
102                 anchors.right: parent.right
103                 anchors.verticalCenter: parent.verticalCenter
104                 Text {
105                     id: dep
106                     // FIXME strange int float transformation appears
107                     text: departure
108                     anchors.right: parent.right
109                     anchors.rightMargin: UIConstants.DEFAULT_MARGIN
110                     font.italic: lowfloor == 1
111                     font.bold: true
112                     font.pixelSize: UIConstants.FONT_XLARGE
113                     font.family: ExtrasConstants.FONT_FAMILY_LIGHT
114                     color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
115                 }
116             }
117
118             MouseArea {
119                 id: mouseArea
120                 anchors.fill: parent
121                 onClicked: {
122                     console.debug("clicked: " + l.text)
123                 }
124             }
125         }
126     }
127
128     ListView {
129         id: list
130         width: parent.width; height: parent.height
131
132         header: Rectangle {
133             width: parent.width
134             height: childrenRect.height + 2*UIConstants.DEFAULT_MARGIN
135             color: "lightsteelblue"
136             radius: 5.0
137             smooth: true
138
139             Text {
140                 anchors {
141                     top: parent.top
142                     left: parent.left
143                     right: parent.right
144                     margins: UIConstants.DEFAULT_MARGIN
145                 }
146
147                 text: 'Richtung ' + gdirection
148                 elide: Text.ElideRight
149                 font.bold: true
150                 font.family: ExtrasConstants.FONT_FAMILY_LIGHT
151                 font.pixelSize: UIConstants.FONT_LSMALL
152             }
153         }
154
155         model: ListModel {
156             id: departuresModel
157         }
158         delegate: departureDelegate
159
160         visible: !resultRealtime.busy && resultRealtime.sourceUrl != ''
161     }
162
163     ScrollDecorator {
164         id: scrolldecorator
165         flickableItem: list
166         platformStyle: ScrollDecoratorStyle {}
167     }
168
169     BusyIndicator {
170         id: busyIndicator
171         visible: resultRealtime.busy && resultRealtime.sourceUrl != ''
172         running: visible
173         platformStyle: BusyIndicatorStyle { size: 'large' }
174         anchors.centerIn: parent
175     }
176 }