get nearby stations from sqlite3 db
[pywienerlinien] / qml / MainPage.qml
1 import QtQuick 1.1
2 import com.nokia.meego 1.0
3
4 import "UIConstants.js" as UIConstants
5 import "ExtrasConstants.js" as ExtrasConstants
6
7 Page {
8     tools: commonTools
9
10     property bool canRefresh: realtimeResult.sourceUrl != ''
11
12     function refresh() {
13         realtimeResult.refresh()
14     }
15
16     SelectionDialog {
17         id: lineSelector
18         titleText: 'Select line'
19
20         model: ListModel {
21             id: lineSelectorModel
22
23             Component.onCompleted: {
24                 var lines = itip.get_lines()
25
26                 for (var idx in lines) {
27                     lineSelectorModel.append({'name': lines[idx]})
28                 }
29             }
30         }
31
32         // XXX It would be nice if we could make a delegate with
33         // icons (i.e. U1, U2, ... in the right colors), but we
34         // would have to "copy" the default delegate style
35
36         onAccepted: {
37             console.log('accepted: ' + selectedIndex)
38             gline.text = lineSelectorModel.get(selectedIndex).name
39         }
40     }
41
42     TextField {
43         placeholderText: 'Line'
44
45         id: gline
46         anchors {
47             top: parent.top
48             left: parent.left
49             topMargin: 20
50             leftMargin: 10
51             rightMargin: 10
52             right: lineSearchButton.left
53         }
54
55         onTextChanged: {
56             // TODO: Check if text matches an item in lineSelectorModel and
57             // set selectedIndex in lineSelector to the right item
58             gstation.text = ''
59
60             if (lineSelector.selectedIndex == -1) {
61                 return
62             }
63
64             // Disable selection in line selector if user changes the text
65             if (lineSelectorModel.get(lineSelector.selectedIndex).name != text) {
66                 lineSelector.selectedIndex = -1
67             }
68         }
69
70          MouseArea {
71              anchors.fill: parent
72              drag.target: gline
73              drag.axis: Drag.YAxis
74              drag.minimumY: 0
75              drag.maximumY: parent.height
76          }
77     }
78
79     /*
80     LineSheet {
81         id: lineSheet
82     }*/
83
84     Button {
85         id: lineSearchButton
86
87         anchors {
88             top: gline.top
89             bottom: gline.bottom
90             right: parent.right
91             rightMargin: 10
92         }
93
94         width: 60
95         iconSource: 'image://theme/icon-m-common-search'
96
97         onClicked: lineSelector.open()
98     }
99
100     TextField {
101         placeholderText: 'Station'
102         id: gstation
103
104         anchors {
105             top: gline.bottom
106             left: parent.left
107             right: stationPickerButton.left
108             topMargin: 10
109             leftMargin: 10
110             rightMargin: 10*stationPickerButton.opacity
111         }
112     }
113
114     StationSheet {
115         id: stationSheet
116     }
117
118     Button {
119         id: stationPickerButton
120
121         anchors {
122             top: gstation.top
123             bottom: gstation.bottom
124             right: parent.right
125             rightMargin: 10
126         }
127
128         Behavior on opacity { PropertyAnimation { } }
129
130         opacity: gline.text != '' // XXX: Check if the line is valid
131
132         width: lineSearchButton.width * opacity
133         //iconSource: 'image://theme/icon-m-common-location-picker'
134         iconSource: 'image://theme/icon-m-toolbar-list'
135
136         onClicked: {
137             stationSheet.open()
138             stationSheet.loadData(gline.text)
139         }
140     }
141
142     ResultRealtime {
143         id: realtimeResult
144
145         anchors {
146             margins: 10
147             top: gstation.bottom
148             left: parent.left
149             bottom: parent.bottom
150             right: parent.right
151         }
152
153         clip: true
154
155         gline: stationSheet.currentLine
156         gstation: stationSheet.currentStation
157         gdirection: stationSheet.currentDirection
158
159         sourceUrl: stationSheet.currentUrl
160     }
161 }
162