3532743b3f667f3a4084ed40f08d8e1ac25c11dc
[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('departure: ' + departures[d])
39                 // XXX: destination might be wrong?!
40                 var row = {'line': resultRealtime.gline, 'station': resultRealtime.gstation, 'destination': gdirection, 'departure': departures[d]}
41                 console.log('inserting: ' + row)
42                 departuresModel.append(row)
43             }
44         }
45     }
46
47     Component {
48          id: departureDelegate
49
50          Item {
51              width: parent.width
52              height: 80
53
54              BorderImage {
55                  anchors.fill: parent
56                  visible: mouseArea.pressed
57                  source: theme.inverted ? 'image://theme/meegotouch-list-inverted-background-pressed-vertical-center': 'image://theme/meegotouch-list-background-pressed-vertical-center'
58              }
59
60              Item {
61                  anchors.fill: parent
62                  anchors.margins: UIConstants.DEFAULT_MARGIN
63
64                  Row {
65                      spacing: 10
66                      Text {
67                          id: l
68                          text: line // <----
69                          anchors.verticalCenter: parent.verticalCenter
70                          width: 70
71                          font.pixelSize: UIConstants.FONT_XLARGE
72                          font.bold: true
73                          font.family: ExtrasConstants.FONT_FAMILY_LIGHT
74                          color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
75                      }
76
77                      Column {
78                          anchors.verticalCenter: parent.verticalCenter
79
80                          Text {
81                              id: s
82                              text: station // <----
83                              width: parent.parent.parent.width - l.width - dep.width - 10
84                              elide: Text.ElideRight
85                              font.pixelSize: UIConstants.FONT_LARGE
86                              font.family: ExtrasConstants.FONT_FAMILY_LIGHT
87                              color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
88                          }
89
90                          Text {
91                              id: d
92                              text: destination // <----
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.bold: true
111                      font.pixelSize: UIConstants.FONT_XLARGE
112                      font.family: ExtrasConstants.FONT_FAMILY_LIGHT
113                      color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
114                  }
115              }
116
117              MouseArea {
118                  id: mouseArea
119                  anchors.fill: parent
120                  onClicked: {
121                      console.debug("clicked: " + l.text)
122                  }
123              }
124          }
125      }
126
127      ListView {
128          id: list
129          width: parent.width; height: parent.height
130
131          header: Rectangle {
132              width: parent.width
133              height: childrenRect.height + 2*UIConstants.DEFAULT_MARGIN
134              color: "lightsteelblue"
135              radius: 5.0
136              smooth: true
137
138              Text {
139                  anchors {
140                      top: parent.top
141                      left: parent.left
142                      right: parent.right
143                      margins: UIConstants.DEFAULT_MARGIN
144                  }
145
146                  text: 'Richtung ' + gdirection
147                  elide: Text.ElideRight
148                  font.bold: true
149                  font.family: ExtrasConstants.FONT_FAMILY_LIGHT
150                  font.pixelSize: UIConstants.FONT_LSMALL
151              }
152          }
153
154          model: ListModel {
155              id: departuresModel
156          }
157          delegate: departureDelegate
158
159          visible: !resultRealtime.busy && resultRealtime.sourceUrl != ''
160      }
161
162      ScrollDecorator {
163          id: scrolldecorator
164          flickableItem: list
165          platformStyle: ScrollDecoratorStyle {}
166      }
167
168      BusyIndicator {
169          id: busyIndicator
170          visible: resultRealtime.busy && resultRealtime.sourceUrl != ''
171          running: visible
172          platformStyle: BusyIndicatorStyle { size: 'large' }
173          anchors.centerIn: parent
174      }
175 }