fixing routing.py bug, if time is 24:00
[pywienerlinien] / qml / LinePad.qml
1
2 import QtQuick 1.0
3 import QtMobility.feedback 1.1
4
5 Rectangle {
6     id: linePad
7     property alias currentLine: inputLine.text
8
9     signal accept
10
11     /* List of available lines - will be filled w/ real data by LineSheet */
12     property variant availableLines: ['59A', '63A', '58']
13
14     property variant matches: availableLines
15
16     onMatchesChanged: {
17         if (matches !== undefined) {
18             if (matches.length == 1) {
19                 inputLine.text = matches[0];
20                 accept();
21             }
22         }
23     }
24
25     function getMatches(prefix) {
26         var result = [];
27
28         for (var i in availableLines) {
29             var line = availableLines[i];
30             if (line.indexOf(prefix) == 0) {
31                 result.push(line);
32             }
33         }
34
35         return result;
36     }
37
38     height: 800
39     width: 480
40
41      HapticsEffect {
42          id: buttonFeedback
43
44          /**
45           * Ideally we would use ThemeEffect here,
46           * but on Harmattan it has no effect (sic)
47           **/
48
49          attackIntensity: 0.5
50          attackTime: 100
51          intensity: 1.0
52          duration: 50
53          fadeTime: 0
54          fadeIntensity: 0.0
55      }
56
57     Text {
58         id: inputLine
59         horizontalAlignment: Text.AlignHCenter
60         verticalAlignment: Text.AlignVCenter
61         height: 100
62         anchors {
63             top: parent.top
64             left: parent.left
65             right: parent.right
66         }
67
68         font {
69             pixelSize: height * .9
70             bold: true
71         }
72
73         text: ''
74         onTextChanged: {
75             if (text != '') {
76                 linePad.matches = linePad.getMatches(text);
77             } else {
78                 linePad.matches = linePad.availableLines;
79             }
80         }
81
82         Image {
83             source: 'image://theme/icon-m-toolbar-backspace'
84             anchors {
85                 verticalCenter: parent.verticalCenter
86                 right: parent.right
87                 margins: 20
88             }
89
90             MouseArea {
91                 anchors {
92                     fill: parent
93                     margins: -30
94                 }
95                 onClicked: {
96                     buttonFeedback.start()
97                     inputLine.text = ''
98                 }
99             }
100         }
101     }
102
103     Item {
104         id: inputState
105         property bool isMetro: inputLine.text[0] == 'U'
106     }
107
108     Repeater {
109         model: [1,2,3, 4,5,6, 7,8,9, 'A',0,'B', 'D','U','VRT', 'O','N','WLB']
110
111         Rectangle {
112             id: inputElement
113             property variant ch: modelData
114             property bool isCandidate
115
116             isCandidate: {
117                 for (var i in linePad.matches) {
118                     if (ch == matches[i][inputLine.text.length]) {
119                         return true;
120                     } else if ((ch == 'VRT' || ch == 'WLB') && inputLine.text == '') {
121                         return true;
122                     }
123                 }
124
125                 return false;
126             }
127
128             opacity: isCandidate?1:.15
129             Behavior on opacity { PropertyAnimation { } }
130
131             color: {
132                 if (inputState.isMetro) {
133                     switch (ch) {
134                         case 1: return '#E20A16';
135                         case 2: return '#764785';
136                         case 3: return '#F76013';
137                         case 4: return '#008131';
138                         case 6: return '#88471F';
139                     }
140                 }
141                 return (index%2?'#ddd':'#eee');
142             }
143             width: parent.width/3
144             height: (parent.height-inputLine.height)/6
145             x: width*(index%3)
146             y: inputLine.height + height*parseInt(index/3)
147
148             Image {
149                 source: 'ubahnicon.png'
150                 anchors {
151                     horizontalCenter: parent.horizontalCenter
152                     bottom: parent.bottom
153                 }
154                 visible: (inputElement.ch === 'U')
155             }
156
157             Text {
158                 id: text
159                 visible: (inputElement.ch !== 'U')
160                 anchors.centerIn: parent
161                 text: modelData
162                 font {
163                     pixelSize: parent.height * .5
164                     bold: true
165                 }
166                 color: {
167                     if (inputState.isMetro || ch == 'U') {
168                         return 'white';
169                     } else if (inputElement.isCandidate) {
170                         return 'black';
171                     }
172
173                     return '#ddd';
174                 }
175             }
176
177             MouseArea {
178                 anchors.fill: parent
179                 onClicked: {
180                     if( inputElement.isCandidate) {
181                         buttonFeedback.start()
182                         inputLine.text += modelData
183                     }
184                 }
185             }
186         }
187     }
188 }
189