1d6bd59e84044fe7f9ded5eb298e57df70ad5401
[pywienerlinien] / qml / LinePad.qml
1
2 import QtQuick 1.0
3
4 Rectangle {
5     id: linePad
6     property alias currentLine: inputLine.text
7
8     /* List of available lines - will be filled w/ real data by LineSheet */
9     property variant availableLines: ['59A', '63A', '58']
10
11     property variant matches: availableLines
12
13     onMatchesChanged: {
14         if (matches !== undefined) {
15             if (matches.length == 1) {
16                 inputLine.text = matches[0];
17             }
18         }
19     }
20
21     function getMatches(prefix) {
22         var result = [];
23
24         for (var i in availableLines) {
25             var line = availableLines[i];
26             if (line.indexOf(prefix) == 0) {
27                 result.push(line);
28             }
29         }
30
31         return result;
32     }
33
34     height: 800
35     width: 480
36
37     Text {
38         id: inputLine
39         horizontalAlignment: Text.AlignHCenter
40         verticalAlignment: Text.AlignVCenter
41         height: 100
42         anchors {
43             top: parent.top
44             left: parent.left
45             right: parent.right
46         }
47
48         font {
49             pixelSize: height * .9
50             bold: true
51         }
52
53         text: ''
54         onTextChanged: {
55             if (text != '') {
56                 linePad.matches = linePad.getMatches(text);
57             } else {
58                 linePad.matches = linePad.availableLines;
59             }
60         }
61
62         Image {
63             source: 'image://theme/icon-m-toolbar-backspace'
64             anchors {
65                 verticalCenter: parent.verticalCenter
66                 right: parent.right
67                 margins: 20
68             }
69
70             MouseArea {
71                 anchors {
72                     fill: parent
73                     margins: -(inputLine.height - height)/2
74                 }
75                 onClicked: inputLine.text = ''
76             }
77         }
78     }
79
80     Item {
81         id: inputState
82         property bool isMetro: inputLine.text[0] == 'U'
83     }
84
85     Repeater {
86         model: [1,2,3, 4,5,6, 7,8,9, 'A',0,'B', 'D','U','VRT', 'O','N','WLB']
87
88         Rectangle {
89             id: inputElement
90             property variant ch: modelData
91             property bool isCandidate
92
93             isCandidate: {
94                 for (var i in linePad.matches) {
95                     if (ch == matches[i][inputLine.text.length]) {
96                         return true;
97                     } else if ((ch == 'VRT' || ch == 'WLB') && inputLine.text == '') {
98                         return true;
99                     }
100                 }
101
102                 return false;
103             }
104
105             opacity: isCandidate?1:.15
106             Behavior on opacity { PropertyAnimation { } }
107
108             color: {
109                 if (inputState.isMetro) {
110                     switch (ch) {
111                         case 1: return '#E20A16';
112                         case 2: return '#764785';
113                         case 3: return '#F76013';
114                         case 4: return '#008131';
115                         case 6: return '#88471F';
116                     }
117                 }
118                 return (index%2?'#ddd':'#eee');
119             }
120             width: parent.width/3
121             height: (parent.height-inputLine.height)/6
122             x: width*(index%3)
123             y: inputLine.height + height*parseInt(index/3)
124
125             Text {
126                 anchors.centerIn: parent
127                 text: modelData
128                 font {
129                     pixelSize: parent.height * .5
130                     bold: true
131                 }
132                 color: {
133                     if (inputState.isMetro) {
134                         return 'white';
135                     } else if (inputElement.isCandidate) {
136                         return 'black';
137                     }
138
139                     return '#ddd';
140                 }
141             }
142
143             MouseArea {
144                 anchors.fill: parent
145                 onClicked: {
146                     inputLine.text += modelData
147                 }
148             }
149         }
150     }
151 }
152