12 new nosetests for departure parsing
[pywienerlinien] / qml / MainPage.qml
1 import QtQuick 1.1
2 import com.nokia.meego 1.0
3
4 import "UIConstants.js" as UIConstants
5 import "ExtrasConstants.js" as ExtrasConstants
6
7 Page {
8     tools: commonTools
9
10     property bool canRefresh: realtimeResult.sourceUrl != ''
11
12     function refresh() {
13         realtimeResult.refresh()
14     }
15
16     SelectionDialog {
17         id: lineSelector
18         titleText: 'Select line'
19
20         model: ListModel {
21             id: lineSelectorModel
22
23             Component.onCompleted: {
24                 var lines = itip.get_lines()
25
26                 for (var idx in lines) {
27                     lineSelectorModel.append({'name': lines[idx]})
28                 }
29             }
30         }
31
32         // XXX It would be nice if we could make a delegate with
33         // icons (i.e. U1, U2, ... in the right colors), but we
34         // would have to "copy" the default delegate style
35
36         onAccepted: {
37             console.log('accepted: ' + selectedIndex)
38             gline.text = lineSelectorModel.get(selectedIndex).name
39         }
40     }
41
42     SelectionDialog {
43         id: stationSelector
44         titleText: 'Select nearby station'
45
46         model: ListModel {
47             id: stationSelectorModel
48
49             Component.onCompleted: {
50                 var stations = itip.get_nearby_stations(positionSource.position.coordinate.latitude, positionSource.position.coordinate.longitude)
51
52                 for (var idx in stations) {
53                     stationSelectorModel.append({'name': stations[idx]})
54                 }
55             }
56         }
57
58         // XXX It would be nice if we could make a delegate with
59         // icons (i.e. U1, U2, ... in the right colors), but we
60         // would have to "copy" the default delegate style
61
62         onAccepted: {
63             console.log('accepted: ' + lineSelectorModel.get(selectedIndex).name)
64             //gline.text = lineSelectorModel.get(selectedIndex).name
65         }
66     }
67
68     TextField {
69         placeholderText: 'Line'
70
71         id: gline
72         anchors {
73             top: parent.top
74             left: parent.left
75             topMargin: 20
76             leftMargin: 10
77             rightMargin: 10
78             right: lineSearchButton.left
79         }
80
81         onTextChanged: {
82             // TODO: Check if text matches an item in lineSelectorModel and
83             // set selectedIndex in lineSelector to the right item
84             gstation.text = ''
85
86             if (lineSelector.selectedIndex == -1) {
87                 return
88             }
89
90             // Disable selection in line selector if user changes the text
91             if (lineSelectorModel.get(lineSelector.selectedIndex).name != text) {
92                 lineSelector.selectedIndex = -1
93             }
94         }
95
96          MouseArea {
97              anchors.fill: parent
98              drag.target: gline
99              drag.axis: Drag.YAxis
100              drag.minimumY: 0
101              drag.maximumY: parent.height
102          }
103     }
104
105     /*
106     LineSheet {
107         id: lineSheet
108     }*/
109
110     Button {
111         id: lineSearchButton
112
113         anchors {
114             top: gline.top
115             bottom: gline.bottom
116             right: parent.right
117             rightMargin: 10
118         }
119
120         width: 60
121         iconSource: 'image://theme/icon-m-common-search'
122
123         onClicked: lineSelector.open()
124     }
125
126     TextField {
127         placeholderText: 'Station'
128         id: gstation
129
130         anchors {
131             top: gline.bottom
132             left: parent.left
133             right: stationPickerButton.left
134             topMargin: 10
135             leftMargin: 10
136             rightMargin: 10*stationPickerButton.opacity
137         }
138     }
139
140     StationSheet {
141         id: stationSheet
142     }
143
144     Button {
145         id: stationPickerButton
146
147         anchors {
148             top: gstation.top
149             bottom: gstation.bottom
150             right: parent.right
151             rightMargin: 10
152         }
153
154         Behavior on opacity { PropertyAnimation { } }
155
156         opacity: gline.text != '' // XXX: Check if the line is valid
157
158         width: lineSearchButton.width * opacity
159         //iconSource: 'image://theme/icon-m-common-location-picker'
160         iconSource: 'image://theme/icon-m-toolbar-list'
161
162         onClicked: {
163             stationSheet.open()
164             stationSheet.loadData(gline.text)
165         }
166     }
167
168     ResultRealtime {
169         id: realtimeResult
170
171         anchors {
172             margins: 10
173             top: gstation.bottom
174             left: parent.left
175             bottom: parent.bottom
176             right: parent.right
177         }
178
179         clip: true
180
181         gline: stationSheet.currentLine
182         gstation: stationSheet.currentStation
183         gdirection: stationSheet.currentDirection
184
185         sourceUrl: stationSheet.currentUrl
186     }
187 }
188