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