Commit 2415f353 authored by Bruno Coudoin's avatar Bruno Coudoin
Browse files

guessnumber, added support for the numpad

parent 633f726b
......@@ -35,8 +35,7 @@ Rectangle {
color: "black"
}
// The backspace code comming from the vitual keyboard
property string backspaceCode
property string userEntry
// A top gradient
Rectangle {
......@@ -50,62 +49,20 @@ Rectangle {
}
}
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: parent.forceActiveFocus()
}
Keys.onPressed: {
if(event.key === Qt.Key_Backspace) {
backspace()
}
appendText(event.text)
}
function backspace() {
userEntry.text = userEntry.text.slice(0, -1)
if(userEntry.text.length === 0) {
userEntry.text = "?"
return
} else {
//Activity.setUserAnswer(parseInt(userEntry.text))
return
}
}
function appendText(text) {
if(text === answerBackground.backspaceCode) {
backspace()
return
}
var number = parseInt(text)
if(isNaN(number))
return
if(userEntry.text === "?") {
userEntry.text = ""
}
if(userEntry.text.length >= 2) {
return
}
userEntry.text += text
Activity.setUserAnswer(parseInt(userEntry.text))
}
GCText {
id: userEntry
id: userEntryText
anchors.fill: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: "?"
text: answerBackground.userEntry
color: "black"
font.pointSize: 28
style: Text.Outline
styleColor: "white"
}
onUserEntryChanged: {
if(userEntry != "")
Activity.setUserAnswer(parseInt(userEntry))
}
}
......@@ -54,7 +54,8 @@ ActivityBase {
property alias helico: helico
property alias textArea: textArea
property alias infoText: userInfo
property alias answerArea: answer
property alias answerArea: answerArea
property alias numpad: numpad
}
onStart: { Activity.start(items) }
......@@ -70,7 +71,7 @@ ActivityBase {
anchors.topMargin: 10
anchors.left: parent.left
horizontalAlignment: Text.AlignHCenter
width: parent.width - answer.width - 10
width: parent.width - answerArea.width - 10
wrapMode: TextEdit.WordWrap
color: "white"
font.bold: true
......@@ -78,9 +79,9 @@ ActivityBase {
}
AnswerArea {
id: answer
id: answerArea
anchors.right: parent.right
anchors.rightMargin: 10
anchors.rightMargin: numpad.columnWidth + 10
anchors.top: parent.top
anchors.topMargin: 10
}
......@@ -95,6 +96,21 @@ ActivityBase {
font.pointSize: 16
}
NumPad {
id: numpad
onAnswerChanged: answerArea.userEntry = answer
maxDigit: 2
columnWidth: 60
}
Keys.onPressed: {
numpad.updateAnswer(event.key, true);
}
Keys.onReleased: {
numpad.updateAnswer(event.key, false);
}
DialogHelp {
id: dialogHelp
onClose: home()
......
......@@ -42,6 +42,7 @@ function initLevel() {
items.helico.init()
items.helico.state = "horizontal"
items.infoText.text = ""
items.numpad.resetText()
switch(currentLevel) {
case 0: currentMax = 20
numberToGuess = getRandomInt(1,currentMax)
......@@ -57,7 +58,6 @@ function initLevel() {
break;
}
items.textArea.text = qsTr("Guess a number between 1 and %1").arg(currentMax);
items.answerArea.forceActiveFocus()
}
function nextLevel() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment