Implement LinePad for easy line selection
[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             if (lineSelector.selectedIndex === -1) {
82                 text = text.toUpperCase()
83                 return
84             }
85         }
86
87          MouseArea {
88              anchors.fill: parent
89              drag.target: gline
90              drag.axis: Drag.YAxis
91              drag.minimumY: 0
92              drag.maximumY: parent.height
93          }
94     }
95
96     LineSheet {
97         id: lineSheet
98         onAccepted: gline.text = currentLine
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: lineSheet.open()
115     }
116
117     TextField {
118         placeholderText: 'Station'
119         id: gstation
120
121         anchors {
122             top: gline.bottom
123             left: parent.left
124             right: stationPickerButton.left
125             topMargin: 10
126             leftMargin: 10
127             rightMargin: 10*stationPickerButton.opacity
128         }
129     }
130
131     StationSheet {
132         id: stationSheet
133     }
134
135     Button {
136         id: stationPickerButton
137
138         anchors {
139             top: gstation.top
140             bottom: gstation.bottom
141             right: parent.right
142             rightMargin: 10
143         }
144
145         Behavior on opacity { PropertyAnimation { } }
146
147         opacity: gline.text !== '' // XXX: Check if the line is valid
148
149         width: lineSearchButton.width * opacity
150         //iconSource: 'image://theme/icon-m-common-location-picker'
151         iconSource: 'image://theme/icon-m-toolbar-list'
152
153         onClicked: {
154             stationSheet.open()
155             stationSheet.loadData(gline.text)
156         }
157     }
158
159     ResultRealtime {
160         id: realtimeResult
161
162         anchors {
163             margins: 10
164             top: gstation.bottom
165             left: parent.left
166             bottom: parent.bottom
167             right: parent.right
168         }
169
170         clip: true
171
172         gline: stationSheet.currentLine
173         gstation: stationSheet.currentStation
174         gdirection: stationSheet.currentDirection
175
176         sourceUrl: stationSheet.currentUrl
177     }
178 }
179