c6deee0238d4bc9b6b1e37b7d6964a9b2e192fa1
[pywienerlinien] / qml / MainPage.qml
1 import QtQuick 1.1
2 import com.nokia.meego 1.0
3 import QtMobility.location 1.1
4
5 import "UIConstants.js" as UIConstants
6 import "ExtrasConstants.js" as ExtrasConstants
7
8 Page {
9     tools: commonTools
10     orientationLock: PageOrientation.LockPortrait
11
12     property bool canRefresh: realtimeResult.sourceUrl != '' || (realtimeResult.isStation && realtimeResult.gstation != '')
13     //property alias stationSelect: stationSelector
14     property variant nearbyStations
15
16     function search() {
17         lineSearchButton.clicked()
18     }
19
20     function refresh() {
21         realtimeResult.refresh()
22     }
23
24     function fillNearbyStations(lat, lon) {
25         nearbyStations = itip.get_nearby_stations(lat, lon)
26     }
27
28     function showNearby() {
29         console.log("show nearby")
30
31         var stations = nearbyStations;
32         stationSelectorModel.clear();
33         for (var idx in stations) {
34             stationSelectorModel.append({'name': stations[idx]});
35         }
36
37         stationSelector.open();
38     }
39
40     Text {
41         visible: !parent.canRefresh
42         anchors.centerIn: parent
43         font.pixelSize: 30
44         text: '<p><strong>Welcome, traveller!<br></strong></p><p>Press <img src="image://theme/icon-m-toolbar-search"> to search for<br>departure information.</p><p>Press <img src="image://theme/icon-m-toolbar-view-menu"> for nearby stations.<br></p><p><strong>Have a safe journey.</strong></p>'
45     }
46
47     Rectangle {
48         id: header
49         anchors {
50             top: parent.top
51             left: parent.left
52             right: parent.right
53             margins: -1
54         }
55         border {
56             color: 'black'
57             width: 1
58         }
59
60         gradient: Gradient {
61             GradientStop { position: 0; color: '#777' }
62             GradientStop { position: 1; color: '#aaa' }
63         }
64
65         height: 80
66         color: 'white'
67
68         Image {
69             id: logo
70             source: 'logo.png'
71
72             anchors {
73                 verticalCenter: parent.verticalCenter
74                 left: parent.left
75                 leftMargin: 10
76             }
77         }
78
79     }
80
81     PositionSource {
82         id: positionSource
83         updateInterval: 10000
84
85         active: true
86
87         onPositionChanged: {
88             fillNearbyStations(positionSource.position.coordinate.latitude, positionSource.position.coordinate.longitude)
89         }
90     }
91
92     SelectionDialog {
93         id: stationSelector
94         titleText: 'Select nearby station'
95
96         model: ListModel {
97             id: stationSelectorModel
98         }
99
100         onAccepted: {
101             realtimeResult.isStation = true
102             realtimeResult.gline = ''
103             realtimeResult.sourceUrl = ''
104             gline.text = ''
105             gstation.text = stationSelectorModel.get(selectedIndex).name
106             realtimeResult.gstation = stationSelectorModel.get(selectedIndex).name
107             console.log('station to get: ' + realtimeResult.gstation)
108         }
109     }
110
111     TextField {
112         visible: false
113         placeholderText: 'Line'
114
115         id: gline
116         anchors {
117             top: parent.top
118             left: parent.left
119             topMargin: 20
120             leftMargin: 10
121             rightMargin: 10
122             right: lineSearchButton.left
123         }
124
125         onTextChanged: {
126             gstation.text = ''
127         }
128
129          MouseArea {
130              anchors.fill: parent
131              drag.target: gline
132              drag.axis: Drag.YAxis
133              drag.minimumY: 0
134              drag.maximumY: parent.height
135          }
136     }
137
138     LineSheet {
139         id: lineSheet
140         onAccepted: {
141             gline.text = currentLine
142
143             /* We usually want to select a station after selecting a line */
144             stationPickerButton.clicked()
145         }
146     }
147
148     Button {
149         id: lineSearchButton
150         visible: false
151
152         anchors {
153             top: gline.top
154             bottom: gline.bottom
155             right: parent.right
156             rightMargin: 10
157         }
158
159         width: 60
160         iconSource: 'image://theme/icon-m-common-search'
161
162         onClicked: {
163             lineSheet.currentLine = ''
164             lineSheet.open()
165         }
166     }
167
168     TextField {
169         placeholderText: 'Station'
170         id: gstation
171         visible: false
172
173         anchors {
174             top: gline.bottom
175             left: parent.left
176             right: stationPickerButton.left
177             topMargin: 10
178             leftMargin: 10
179             rightMargin: 10*stationPickerButton.opacity
180         }
181     }
182
183     StationSheet {
184         id: stationSheet
185         onAccepted: {
186             gstation.text = stationSheet.currentStation
187
188             realtimeResult.gline = stationSheet.currentLine
189             realtimeResult.gdirection = stationSheet.currentDirection
190             realtimeResult.isStation = false
191             realtimeResult.sourceUrl = itip.get_directions_url(stationSheet.currentLine, stationSheet.currentDirection, stationSheet.currentStation)
192             realtimeResult.gstation = stationSheet.currentStation
193             
194             console.debug('url to get: ' + realtimeResult.sourceUrl)
195             realtimeResult.refresh()
196         }
197     }
198
199     Button {
200         id: stationPickerButton
201
202         anchors {
203             top: gstation.top
204             bottom: gstation.bottom
205             right: parent.right
206             rightMargin: 10
207         }
208
209         visible: false
210
211         width: lineSearchButton.width * opacity
212         //iconSource: 'image://theme/icon-m-common-location-picker'
213         iconSource: 'image://theme/icon-m-toolbar-list'
214
215         onClicked: {
216             stationSheet.open()
217             stationSheet.loadData(gline.text)
218         }
219     }
220
221     ResultRealtime {
222         id: realtimeResult
223
224         anchors {
225             margins: 10
226             top: header.bottom
227             left: parent.left
228             bottom: parent.bottom
229             right: parent.right
230         }
231
232         clip: true
233
234         gline: stationSheet.currentLine
235         gstation: stationSheet.currentStation
236         gdirection: stationSheet.currentDirection
237
238         sourceUrl: stationSheet.currentUrl
239     }
240 }
241