uppercase line names (fixes #14)
[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             text = text.toUpperCase()
61
62             if (lineSelector.selectedIndex == -1) {
63                 return
64             }
65
66             // Disable selection in line selector if user changes the text
67             if (lineSelectorModel.get(lineSelector.selectedIndex).name != text) {
68                 lineSelector.selectedIndex = -1
69             }
70         }
71
72          MouseArea {
73              anchors.fill: parent
74              drag.target: gline
75              drag.axis: Drag.YAxis
76              drag.minimumY: 0
77              drag.maximumY: parent.height
78          }
79     }
80
81     /*
82     LineSheet {
83         id: lineSheet
84     }*/
85
86     Button {
87         id: lineSearchButton
88
89         anchors {
90             top: gline.top
91             bottom: gline.bottom
92             right: parent.right
93             rightMargin: 10
94         }
95
96         width: 60
97         iconSource: 'image://theme/icon-m-common-search'
98
99         onClicked: lineSelector.open()
100     }
101
102     TextField {
103         placeholderText: 'Station'
104         id: gstation
105
106         anchors {
107             top: gline.bottom
108             left: parent.left
109             right: stationPickerButton.left
110             topMargin: 10
111             leftMargin: 10
112             rightMargin: 10*stationPickerButton.opacity
113         }
114     }
115
116     StationSheet {
117         id: stationSheet
118     }
119
120     Button {
121         id: stationPickerButton
122
123         anchors {
124             top: gstation.top
125             bottom: gstation.bottom
126             right: parent.right
127             rightMargin: 10
128         }
129
130         Behavior on opacity { PropertyAnimation { } }
131
132         opacity: gline.text != '' // XXX: Check if the line is valid
133
134         width: lineSearchButton.width * opacity
135         //iconSource: 'image://theme/icon-m-common-location-picker'
136         iconSource: 'image://theme/icon-m-toolbar-list'
137
138         onClicked: {
139             stationSheet.open()
140             stationSheet.loadData(gline.text)
141         }
142     }
143
144     ResultRealtime {
145         id: realtimeResult
146
147         anchors {
148             margins: 10
149             top: gstation.bottom
150             left: parent.left
151             bottom: parent.bottom
152             right: parent.right
153         }
154
155         clip: true
156
157         gline: stationSheet.currentLine
158         gstation: stationSheet.currentStation
159         gdirection: stationSheet.currentDirection
160
161         sourceUrl: stationSheet.currentUrl
162     }
163 }
164