Merge github.com:kelvan/gotoVienna into 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 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                 text = text.toUpperCase()
111                 return
112             }
113
114             // Disable selection in line selector if user changes the text
115             if (lineSelectorModel.get(lineSelector.selectedIndex).name !== text) {
116                 lineSelector.selectedIndex = -1
117             }
118         }
119
120          MouseArea {
121              anchors.fill: parent
122              drag.target: gline
123              drag.axis: Drag.YAxis
124              drag.minimumY: 0
125              drag.maximumY: parent.height
126          }
127     }
128
129     /*
130     LineSheet {
131         id: lineSheet
132     }*/
133
134     Button {
135         id: lineSearchButton
136
137         anchors {
138             top: gline.top
139             bottom: gline.bottom
140             right: parent.right
141             rightMargin: 10
142         }
143
144         width: 60
145         iconSource: 'image://theme/icon-m-common-search'
146
147         onClicked: lineSelector.open()
148     }
149
150     TextField {
151         placeholderText: 'Station'
152         id: gstation
153
154         anchors {
155             top: gline.bottom
156             left: parent.left
157             right: stationPickerButton.left
158             topMargin: 10
159             leftMargin: 10
160             rightMargin: 10*stationPickerButton.opacity
161         }
162     }
163
164     StationSheet {
165         id: stationSheet
166     }
167
168     Button {
169         id: stationPickerButton
170
171         anchors {
172             top: gstation.top
173             bottom: gstation.bottom
174             right: parent.right
175             rightMargin: 10
176         }
177
178         Behavior on opacity { PropertyAnimation { } }
179
180         opacity: gline.text !== '' // XXX: Check if the line is valid
181
182         width: lineSearchButton.width * opacity
183         //iconSource: 'image://theme/icon-m-common-location-picker'
184         iconSource: 'image://theme/icon-m-toolbar-list'
185
186         onClicked: {
187             stationSheet.open()
188             stationSheet.loadData(gline.text)
189         }
190     }
191
192     ResultRealtime {
193         id: realtimeResult
194
195         anchors {
196             margins: 10
197             top: gstation.bottom
198             left: parent.left
199             bottom: parent.bottom
200             right: parent.right
201         }
202
203         clip: true
204
205         gline: stationSheet.currentLine
206         gstation: stationSheet.currentStation
207         gdirection: stationSheet.currentDirection
208
209         sourceUrl: stationSheet.currentUrl
210     }
211 }
212