replaced get_departures with DataModel in pyside
[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         }
46     }
47
48     Component {
49         id: departureDelegate
50
51         Item {
52             width: parent.width
53             height: 80
54
55             BorderImage {
56                 anchors.fill: parent
57                 visible: mouseArea.pressed
58                 source: theme.inverted ? 'image://theme/meegotouch-list-inverted-background-pressed-vertical-center': 'image://theme/meegotouch-list-background-pressed-vertical-center'
59             }
60
61             Item {
62                 anchors.fill: parent
63                 anchors.margins: UIConstants.DEFAULT_MARGIN
64
65                 Row {
66                     spacing: 10
67                     Text {
68                         id: l
69                         text: model.line // <----
70                         anchors.verticalCenter: parent.verticalCenter
71                         //width: 70
72                         font.pixelSize: UIConstants.FONT_XLARGE
73                         font.bold: true
74                         font.family: ExtrasConstants.FONT_FAMILY_LIGHT
75                         color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
76                     }
77
78                     Column {
79                         anchors.verticalCenter: parent.verticalCenter
80
81                         Text {
82                             id: s
83                             text: model.station // <----
84                             width: parent.parent.parent.width - l.width - dep.width - 15
85                             elide: Text.ElideRight
86                             font.pixelSize: UIConstants.FONT_LARGE
87                             font.family: ExtrasConstants.FONT_FAMILY_LIGHT
88                             color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
89                         }
90
91                         Text {
92                             id: d
93                             text: model.direction // <----
94                             width: parent.parent.parent.width - l.width - dep.width - 15
95                             elide: Text.ElideRight
96                             color: !theme.inverted ? UIConstants.COLOR_SECONDARY_FOREGROUND : UIConstants.COLOR_INVERTED_SECONDARY_FOREGROUND
97                             font.family: ExtrasConstants.FONT_FAMILY_LIGHT
98                             font.pixelSize: UIConstants.FONT_LSMALL
99                         }
100                     }
101                 }
102             }
103
104             Column {
105                 anchors.right: parent.right
106                 anchors.verticalCenter: parent.verticalCenter
107                 Text {
108                     id: dep
109                     // FIXME strange int float transformation appears
110                     text: model.time
111                     anchors.right: parent.right
112                     anchors.rightMargin: UIConstants.DEFAULT_MARGIN
113                     font.italic: lowfloor
114                     font.bold: true
115                     font.pixelSize: UIConstants.FONT_XLARGE
116                     font.family: ExtrasConstants.FONT_FAMILY_LIGHT
117                     color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
118                 }
119             }
120
121             MouseArea {
122                 id: mouseArea
123                 anchors.fill: parent
124                 onClicked: {
125                     console.debug("clicked: " + l.text)
126                 }
127             }
128         }
129     }
130
131     ListView {
132         id: list
133         width: parent.width; height: parent.height
134
135         header: Rectangle {
136             width: parent.width
137             height: childrenRect.height + 2*UIConstants.DEFAULT_MARGIN
138             color: "lightsteelblue"
139             radius: 5.0
140             smooth: true
141
142             Text {
143                 id: header
144
145                 anchors {
146                     top: parent.top
147                     left: parent.left
148                     right: parent.right
149                     margins: UIConstants.DEFAULT_MARGIN
150                 }
151
152                 text: 'Richtung ' + gdirection
153                 elide: Text.ElideRight
154                 font.bold: true
155                 font.family: ExtrasConstants.FONT_FAMILY_LIGHT
156                 font.pixelSize: UIConstants.FONT_LSMALL
157             }
158         }
159
160         model: resultModel
161         delegate: departureDelegate
162
163         visible: !resultRealtime.busy && isCorrectInput()
164     }
165
166     ScrollDecorator {
167         id: scrolldecorator
168         flickableItem: list
169         platformStyle: ScrollDecoratorStyle {}
170     }
171
172     BusyIndicator {
173         id: busyIndicator
174         visible: resultRealtime.busy && isCorrectInput()
175         running: visible
176         platformStyle: BusyIndicatorStyle { size: 'large' }
177         anchors.centerIn: parent
178     }
179 }