a14e48db09c9161f201f0aa1dadfeecf2474d1fc
[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: stationSelector
48         titleText: 'Select nearby station'
49
50         model: ListModel {
51             id: stationSelectorModel
52         }
53
54         onAccepted: {
55             realtimeResult.isStation = true
56             realtimeResult.gstation = stationSelectorModel.get(selectedIndex).name
57             realtimeResult.gline = ''
58             realtimeResult.sourceUrl = ''
59             gline.text = ''
60             gstation.text = stationSelectorModel.get(selectedIndex).name
61             console.log('station to get: ' + realtimeResult.gstation)
62         }
63     }
64
65     TextField {
66         placeholderText: 'Line'
67
68         id: gline
69         anchors {
70             top: parent.top
71             left: parent.left
72             topMargin: 20
73             leftMargin: 10
74             rightMargin: 10
75             right: lineSearchButton.left
76         }
77
78         onTextChanged: {
79             gstation.text = ''
80         }
81
82          MouseArea {
83              anchors.fill: parent
84              drag.target: gline
85              drag.axis: Drag.YAxis
86              drag.minimumY: 0
87              drag.maximumY: parent.height
88          }
89     }
90
91     LineSheet {
92         id: lineSheet
93         onAccepted: {
94             gline.text = currentLine
95
96             /* We usually want to select a station after selecting a line */
97             stationPickerButton.clicked()
98         }
99     }
100
101     Button {
102         id: lineSearchButton
103
104         anchors {
105             top: gline.top
106             bottom: gline.bottom
107             right: parent.right
108             rightMargin: 10
109         }
110
111         width: 60
112         iconSource: 'image://theme/icon-m-common-search'
113
114         onClicked: {
115             lineSheet.currentLine = ''
116             lineSheet.open()
117         }
118     }
119
120     TextField {
121         placeholderText: 'Station'
122         id: gstation
123
124         anchors {
125             top: gline.bottom
126             left: parent.left
127             right: stationPickerButton.left
128             topMargin: 10
129             leftMargin: 10
130             rightMargin: 10*stationPickerButton.opacity
131         }
132     }
133
134     StationSheet {
135         id: stationSheet
136     }
137
138     Button {
139         id: stationPickerButton
140
141         anchors {
142             top: gstation.top
143             bottom: gstation.bottom
144             right: parent.right
145             rightMargin: 10
146         }
147
148         Behavior on opacity { PropertyAnimation { } }
149
150         opacity: gline.text !== '' // XXX: Check if the line is valid
151
152         width: lineSearchButton.width * opacity
153         //iconSource: 'image://theme/icon-m-common-location-picker'
154         iconSource: 'image://theme/icon-m-toolbar-list'
155
156         onClicked: {
157             stationSheet.open()
158             stationSheet.loadData(gline.text)
159         }
160     }
161
162     ResultRealtime {
163         id: realtimeResult
164
165         anchors {
166             margins: 10
167             top: gstation.bottom
168             left: parent.left
169             bottom: parent.bottom
170             right: parent.right
171         }
172
173         clip: true
174
175         gline: stationSheet.currentLine
176         gstation: stationSheet.currentStation
177         gdirection: stationSheet.currentDirection
178
179         sourceUrl: stationSheet.currentUrl
180     }
181 }
182