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