a4b3a98b98ff4bb73573095e6eeaaf805982405d
[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     Image {
10         id: logo
11         source: 'logo.png'
12
13         anchors {
14             topMargin: 25
15             top: parent.top
16             horizontalCenter: parent.horizontalCenter
17         }
18     }
19
20     SelectionDialog {
21         id: lineSelector
22         titleText: 'Select line'
23
24         model: ListModel {
25             id: lineSelectorModel
26
27             Component.onCompleted: {
28                 var lines = itip.get_lines()
29
30                 for (var idx in lines) {
31                     lineSelectorModel.append({'name': lines[idx]})
32                 }
33             }
34         }
35
36         // XXX It would be nice if we could make a delegate with
37         // icons (i.e. U1, U2, ... in the right colors), but we
38         // would have to "copy" the default delegate style
39
40         onAccepted: {
41             console.log('accepted: ' + selectedIndex)
42             gline.text = lineSelectorModel.get(selectedIndex).name
43         }
44     }
45
46     TextField {
47         placeholderText: 'Line'
48
49         id: gline
50         anchors {
51             top: logo.bottom
52             left: parent.left
53             topMargin: 20
54             leftMargin: 10
55             rightMargin: 10
56             right: lineSearchButton.left
57         }
58
59         onTextChanged: {
60             // TODO: Check if text matches an item in lineSelectorModel and
61             // set selectedIndex in lineSelector to the right item
62
63             if (lineSelector.selectedIndex == -1) {
64                 return
65             }
66
67             // Disable selection in line selector if user changes the text
68             if (lineSelectorModel.get(lineSelector.selectedIndex).name != text) {
69                 lineSelector.selectedIndex = -1
70             }
71         }
72
73          MouseArea {
74              anchors.fill: parent
75              drag.target: gline
76              drag.axis: Drag.YAxis
77              drag.minimumY: 0
78              drag.maximumY: parent.height
79          }
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         anchors {
102             top: gline.bottom
103             left: parent.left
104             right: parent.right
105             topMargin: 10
106             leftMargin: 10
107             rightMargin: 10
108         }
109     }
110
111     ResultRealtime { id: resu }
112
113     Button {
114         id: btnSearch
115         text: 'Search'
116         anchors {
117             top: gstation.bottom
118             topMargin: 10
119             horizontalCenter: parent.horizontalCenter
120         }
121         onClicked: {
122             resu.gline = gline.text
123             resu.gstation = gstation.text
124             pageStack.push(resu)
125             itip.search(gline.text, gstation.text)
126             resu.busy = false
127         }
128     }
129 }
130