• Skip to content
  • Skip to link menu
KDE API Documentation - NumPad.qml Source File (GCompris-qt)
  • KDE Home
  • Contact Us
 

GCompris-qt

  • src
  • core
NumPad.qml
1 /* GCompris - NumPad.qml
2  *
3  * Copyright (C) 2014 Aruna Sankaranarayanan <arunasank@src.gnome.org>
4  *
5  * Authors:
6  * Aruna Sankaranarayanan <arunasank@src.gnome.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, see <http://www.gnu.org/licenses/>.
20  */
21 import QtQuick 2.2
22 import GCompris 1.0
23 
24 Item {
25 
26  id: containerPanel
27  anchors.fill: parent
28 
29  property variant colours: ["#ea7025", "#67c111", "#00bde3", "#bde300","#e3004c"]
30  property variant numbers: [0,1,2,3,4]
31  property string answer: ""
32  property bool answerFlag: false
33  property var leftPanelComponent: leftPanel
34  property var rightPanelComponent: rightPanel
35  property var backspaceButtonComponent:backspaceButton
36  property int maxDigit: 2
37  property int columnWidth: 80 * ApplicationInfo.ratio
38 
39  signal answer
40 
41  visible: ApplicationSettings.isVirtualKeyboard
42 
43  Column {
44  id: leftPanel
45  width: columnWidth
46  height: parent.height - 90 * ApplicationInfo.ratio
47  opacity: 0.8
48 
49  Repeater {
50  model:5
51 
52  Rectangle{
53  width: parent.width
54  height: parent.height/5
55  color: colours[index]
56  border.color: Qt.darker(color)
57  border.width:2
58 
59  GCText {
60  anchors.horizontalCenter: parent.horizontalCenter
61  anchors.verticalCenter: parent.verticalCenter
62  text: numbers[index]
63  fontSize: 28
64  font.bold: true
65 
66  }
67 
68  MouseArea {
69  // Create an bigger area than the top rectangle to suit fingers
70  anchors {
71  left: parent.left
72  top: parent.top
73  bottom: parent.bottom
74  }
75  width: parent.width * 2
76  enabled: ApplicationSettings.isVirtualKeyboard &&
77  containerPanel.opacity > 0
78 
79  onClicked :{
80  if(answer.length < maxDigit)
81  answer += numbers[index]
82  }
83  onPressed: {
84  leftPanel.children[index].color = Qt.lighter(colours[index])
85  leftPanel.children[index].border.width = 5
86  }
87  onReleased: {
88  leftPanel.children[index].color = colours[index]
89  leftPanel.children[index].border.width = 2
90  }
91  }
92  }
93 
94  }
95  }
96 
97 
98  Column {
99  id: rightPanel
100  width: columnWidth
101  height: parent.height - 90 * ApplicationInfo.ratio
102  x: parent.width - columnWidth
103  opacity: 0.8
104 
105  Repeater {
106  model: 5
107 
108  Rectangle {
109  width: parent.width
110  height: parent.height/5
111  color: colours[index]
112  border.color: Qt.darker(color)
113  border.width:2
114 
115  GCText {
116  anchors.horizontalCenter: parent.horizontalCenter
117  anchors.verticalCenter: parent.verticalCenter
118  text: numbers[index] + 5
119  fontSize: 28
120  font.bold: true
121 
122  }
123  MouseArea {
124  // Create an bigger area than the top rectangle to suit fingers
125  anchors {
126  right: parent.right
127  top: parent.top
128  bottom: parent.bottom
129  }
130  width: parent.width * 2
131  enabled: ApplicationSettings.isVirtualKeyboard &&
132  containerPanel.opacity > 0
133 
134  onClicked: {
135  if(answer.length < maxDigit)
136  answer += numbers[index] + 5
137  }
138  onPressed: {
139  rightPanel.children[index].color = Qt.lighter(colours[index])
140  rightPanel.children[index].border.width = 5
141  }
142  onReleased: {
143  rightPanel.children[index].color = colours[index]
144  rightPanel.children[index].border.width = 2
145  }
146  }
147  }
148  }
149  Rectangle {
150  id: backspaceButton
151  width: parent.width
152  height: containerPanel.height - rightPanel.height
153  color: "white"
154  border.color: "black"
155  border.width:2
156 
157  GCText {
158  anchors.horizontalCenter: parent.horizontalCenter
159  anchors.verticalCenter: parent.verticalCenter
160  text: "←"
161  fontSize: 28
162  font.bold: true
163  }
164 
165  MouseArea {
166  anchors.fill: parent
167  enabled: ApplicationSettings.isVirtualKeyboard &&
168  containerPanel.opacity > 0
169 
170  onClicked: {
171  answer = answer.substring(0,answer.length - 1)
172  }
173  onPressed: {
174  backspaceButton.color = Qt.lighter("white")
175  backspaceButton.border.width = 5
176  }
177 
178  onReleased: {
179  backspaceButton.color = "white"
180  backspaceButton.border.width = 2
181  }
182  }
183  }
184  }
185 
186  function resetText()
187  {
188  answer = ""
189  }
190 
191  function updateAnswer(key, isKeyPressed){
192  var keyValue;
193 
194  switch(key)
195  {
196  case Qt.Key_0 :
197  keyValue = 0;
198  break;
199  case Qt.Key_1:
200  keyValue = 1;
201  break;
202  case Qt.Key_2:
203  keyValue = 2;
204  break;
205  case Qt.Key_3:
206  keyValue = 3;
207  break;
208  case Qt.Key_4:
209  keyValue = 4;
210  break;
211  case Qt.Key_5:
212  keyValue = 5;
213  break;
214  case Qt.Key_6:
215  keyValue = 6;
216  break;
217  case Qt.Key_7:
218  keyValue = 7;
219  break;
220  case Qt.Key_8:
221  keyValue = 8;
222  break;
223  case Qt.Key_9:
224  keyValue = 9;
225  break;
226  case Qt.Key_Backspace:
227  keyValue = 10;
228  }
229 
230  if(isKeyPressed && !answerFlag)
231  {
232  if(keyValue < 5 && answer.length < maxDigit)
233  {
234 
235  answer += keyValue;
236  leftPanel.children[keyValue].color = Qt.lighter(colours[keyValue])
237  leftPanel.children[keyValue].border.width = 5
238  }
239  else if(keyValue < 10 && answer.length < maxDigit)
240  {
241  answer += keyValue;
242  rightPanel.children[keyValue - 5].color = Qt.lighter(colours[keyValue - 5])
243  rightPanel.children[keyValue - 5].border.width = 5
244  }
245  else if(keyValue === 10)
246  {
247  answer = answer.substring(0,answer.length - 1);
248  backspaceButton.color = Qt.lighter("white")
249  backspaceButton.border.width = 5
250  }
251  }
252  else
253  {
254  if(keyValue < 5)
255  {
256  leftPanel.children[keyValue].color = colours[keyValue]
257  leftPanel.children[keyValue].border.width = 2
258  }
259  else if(keyValue < 10)
260  {
261 
262  rightPanel.children[keyValue - 5].color = colours[keyValue - 5]
263  rightPanel.children[keyValue - 5].border.width = 2
264  }
265  else if(keyValue === 10)
266  {
267  backspaceButton.color = "white"
268  backspaceButton.border.width = 2
269  }
270  }
271 
272  }
273 }
274 
ApplicationSettings::isVirtualKeyboard
bool isVirtualKeyboard
Whether on-screen keyboard should be enabled per default in activities that use it.
Definition: ApplicationSettings.h:94
GCText
A QML component unifying text presentation in GCompris.
Definition: GCText.qml:47
QtQuick
GCompris
ApplicationSettings
Singleton that contains GCompris' persistent settings.
Definition: ApplicationSettings.h:63
ApplicationInfo
A general purpose singleton that exposes miscellaneous native functions to the QML layer...
Definition: ApplicationInfo.h:43
ApplicationInfo::ratio
qreal ratio
Ratio factor used for scaling of sizes on high-dpi devices.
Definition: ApplicationInfo.h:91
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Tue Jun 2 2015 21:47:47 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

GCompris-qt

Skip menu "GCompris-qt"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List
  • Modules

Class Picker

Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal