Commit c6ec4ae1 authored by Timothée Giet's avatar Timothée Giet
Browse files

learn_digits, add keyboard controls

parent 9e4f4043
......@@ -30,6 +30,10 @@ ActivityBase {
onStart: focus = true
onStop: {}
Keys.onPressed: {
Activity.processKey(event);
}
pageComponent: Image {
id: background
source: "qrc:/gcompris/src/activities/braille_fun/resource/hillside.svg"
......@@ -64,6 +68,7 @@ ActivityBase {
property int answer: 0
property int question: 0
property int circlesModel: 3
property int selectedCircle: -1
property bool inputLocked: false
property var levels: activity.datasetLoader.data
}
......@@ -190,6 +195,15 @@ ActivityBase {
width: isHorizontal ? itemWidth * items.circlesModel : itemWidth
height: isHorizontal ? itemWidth : itemWidth * items.circlesModel
anchors.centerIn: circlesBackground
Rectangle {
id: circlesSelector
width: circlesArea.itemWidth
height: circlesArea.itemWidth
radius: 10 * ApplicationInfo.ratio
color: "#803ACAFF"
visible: items.selectedCircle > -1
anchors.centerIn: circlesLine.itemAt(items.selectedCircle)
}
Repeater {
id: circlesLine
model: items.circlesModel
......@@ -202,6 +216,16 @@ ActivityBase {
isFilled = false;
circleColor = "#00ffffff";
}
function clickCircle() {
if(!isFilled) {
++items.answer;
circleColor = "#ffd2611d";
} else {
--items.answer;
circleColor = "#00ffffff";
}
isFilled = !isFilled
}
width: circlesArea.itemWidth
height: width
x: isHorizontal ? width * index : 0
......@@ -221,16 +245,7 @@ ActivityBase {
MouseArea {
id: circleInput
anchors.fill: parent
onClicked: {
if(!parent.isFilled) {
++items.answer;
circleColor = "#ffd2611d";
} else {
--items.answer;
circleColor = "#00ffffff";
}
parent.isFilled = !parent.isFilled
}
onClicked: parent.clickCircle();
}
}
}
......
......@@ -54,6 +54,8 @@ function initLevel() {
items.currentSubLevel = 0;
items.nbSubLevel = questionsArray.length;
initQuestion();
if(items.selectedCircle >= 0)
items.selectedCircle = 0;
}
function nextLevel() {
......@@ -124,3 +126,26 @@ function stopVoice() {
items.audioVoices.stop();
items.audioVoices.clearQueue();
}
function processKey(event) {
if(items.inputLocked)
return;
if(event.key === Qt.Key_Right || event.key === Qt.Key_Down) {
if(items.selectedCircle < items.circlesModel - 1 )
++items.selectedCircle;
else
items.selectedCircle = 0;
} else if(event.key === Qt.Key_Left || event.key === Qt.Key_Up) {
if(items.selectedCircle > 0)
--items.selectedCircle;
else
items.selectedCircle = items.circlesModel - 1;
} else if(event.key === Qt.Key_Space) {
if(items.selectedCircle >= 0)
items.circlesLine.itemAt(items.selectedCircle).clickCircle();
} else if(event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
checkAnswer();
} else if(event.key === Qt.Key_Tab) {
playLetter(items.question.toString());
}
}
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