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