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