Added experimental LineSheet to replace lineSelector
[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     LineSheet {
79         id: lineSheet
80     }
81
82     Button {
83         id: lineSearchButton
84
85         anchors {
86             top: gline.top
87             bottom: gline.bottom
88             right: parent.right
89             rightMargin: 10
90         }
91
92         width: 60
93         iconSource: 'image://theme/icon-m-common-search'
94
95         onClicked: lineSelector.open()
96     }
97
98     TextField {
99         placeholderText: 'Station'
100         id: gstation
101
102         anchors {
103             top: gline.bottom
104             left: parent.left
105             right: stationPickerButton.left
106             topMargin: 10
107             leftMargin: 10
108             rightMargin: 10*stationPickerButton.opacity
109         }
110     }
111
112     StationSheet {
113         id: stationSheet
114     }
115
116     Button {
117         id: stationPickerButton
118
119         anchors {
120             top: gstation.top
121             bottom: gstation.bottom
122             right: parent.right
123             rightMargin: 10
124         }
125
126         Behavior on opacity { PropertyAnimation { } }
127
128         opacity: gline.text != '' // XXX: Check if the line is valid
129
130         width: lineSearchButton.width * opacity
131         //iconSource: 'image://theme/icon-m-common-location-picker'
132         iconSource: 'image://theme/icon-m-toolbar-list'
133
134         onClicked: {
135             stationSheet.open()
136             stationSheet.loadData(gline.text)
137         }
138     }
139
140     ResultRealtime {
141         id: realtimeResult
142
143         anchors {
144             margins: 10
145             top: gstation.bottom
146             left: parent.left
147             bottom: parent.bottom
148             right: parent.right
149         }
150
151         clip: true
152
153         gline: stationSheet.currentLine
154         gstation: stationSheet.currentStation
155         gdirection: stationSheet.currentDirection
156
157         sourceUrl: stationSheet.currentUrl
158     }
159 }
160