Commit 0f038021 authored by Bruno Coudoin's avatar Bruno Coudoin
Browse files

scalesboard, added support for the numpad

parent 1395335c
......@@ -28,18 +28,8 @@ Item {
property string text
property bool displayed: text != "" ? true : false
property string answer
// The backspace code comming from the virtual keyboard
property string backspaceCode
property string userEntry
property string questionMark: qsTr('?')
function init() {
forceActiveFocus()
userEntry = questionMark
}
Rectangle {
id: questionBg
x: questionText.x - 4
......@@ -74,46 +64,8 @@ Item {
}
Keys.onPressed: {
if(event.key === Qt.Key_Backspace) {
backspace()
} else {
appendText(event.text)
}
}
function backspace() {
userEntry = userEntry.slice(0, -1)
if(userEntry.length === 0) {
userEntry = questionMark
return
} else {
return
}
}
function appendText(text) {
if(text === question.backspaceCode) {
backspace()
return
}
var number = parseInt(text)
if(isNaN(number)) {
return
}
if(userEntry === questionMark) {
userEntry = ""
}
if(userEntry.length >= question.answer.length + 1) {
return
}
userEntry += text
onUserEntryChanged: {
if(userEntry === question.answer)
bonus.good("flower")
}
}
......@@ -66,6 +66,7 @@ ActivityBase {
property alias masseCenterModel: masseAreaCenter.masseModel
property alias masseRightModel: masseAreaRight.masseModel
property alias question: question
property alias numpad: numpad
}
onStart: { Activity.start(items) }
......@@ -263,9 +264,23 @@ ActivityBase {
numberOfSubLevels: items.numberOfSubLevels
currentSubLevel: items.currentSubLevel
opacity: question.displayed ? 0 : 1
}
NumPad {
id: numpad
onAnswerChanged: question.userEntry = answer
maxDigit: ('' + items.giftWeight).length + 1
opacity: question.displayed ? 1 : 0
}
Keys.onPressed: {
numpad.updateAnswer(event.key, true);
}
Keys.onReleased: {
numpad.updateAnswer(event.key, false);
}
Bonus {
id: bonus
......
......@@ -53,7 +53,7 @@ function displayLevel()
{
initCompleted = false
items.question.init()
items.numpad.answer = ""
items.masseAreaLeft.init()
items.masseAreaRight.init()
items.masseAreaCenter.init()
......
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