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