Commit 03e1cbc9 authored by Johnny Jazeix's avatar Johnny Jazeix
Browse files

letter-in-word, add keyboard navigation

parent 5b2e5992
......@@ -41,7 +41,6 @@ Item {
//visible: index % 2 != 0 ? false : true
}
Image {
id: cardImage
anchors.top:wordPic.bottom
......@@ -70,9 +69,7 @@ Item {
color: selected && textdata.length == 1 && textdata == Activity.currentLetter ? "green" : "white"
}
}
}
ParticleSystemStarLoader {
......@@ -151,38 +148,38 @@ Item {
anchors.fill: parent
hoverEnabled: ApplicationInfo.isMobile ? false : true
onClicked: {
if(mouseActive){
if (Activity.checkWord(index)) {
successAnimation.restart();
particle.burst(30)
components.clear();
var tempword;
var j = 0;
for(var i = 0; i < spelling.length; i++) {
if(spelling.charAt(i) == Activity.currentLetter) {
tempword = spelling.substring(j, i);
if(i != j) {
components.append({"textdata": tempword})
}
components.append({"textdata": Activity.currentLetter});
j = i + 1;
select();
}
}
function select() {
if(mouseActive && !successAnimation.running) {
if (Activity.checkWord(index)) {
successAnimation.restart();
particle.burst(30)
components.clear();
var tempword;
var j = 0;
for(var i = 0; i < spelling.length; i++) {
if(spelling.charAt(i) == Activity.currentLetter) {
tempword = spelling.substring(j, i);
if(i != j) {
components.append({"textdata": tempword})
}
}
if(j < spelling.length) {
tempword = spelling.substring(j, spelling.length);
components.append({"textdata": tempword})
components.append({"textdata": Activity.currentLetter});
j = i + 1;
}
} else {
failureAnimation.restart()
}
if(j < spelling.length) {
tempword = spelling.substring(j, spelling.length);
components.append({"textdata": tempword})
}
}
else {
failureAnimation.restart()
}
}
}
}
......@@ -45,6 +45,8 @@ ActivityBase {
// system locale by default
property string locale: "system"
property bool keyboardMode: false
signal start
signal stop
signal voiceError
......@@ -70,8 +72,6 @@ ActivityBase {
property string question
}
onStart: {
activity.audioVoices.error.connect(voiceError)
Activity.start(items);
......@@ -195,7 +195,7 @@ ActivityBase {
id: planeText
width: plane.width
height: plane.height
x: - width
x: -width
anchors.top: parent.top
anchors.topMargin: 5 * ApplicationInfo.ratio
......@@ -236,7 +236,7 @@ ActivityBase {
BarButton {
id: repeatItem
source: "qrc:/gcompris/src/core/resource/bar_repeat.svg";
source: "qrc:/gcompris/src/core/resource/bar_repeat.svg"
sourceSize.width: 80 * ApplicationInfo.ratio
anchors {
top: parent.top
......@@ -249,6 +249,22 @@ ActivityBase {
}
}
Keys.onPressed: {
if(event.key === Qt.Key_Space) {
wordsView.currentItem.select()
}
}
Keys.onReleased: {
keyboardMode = true
event.accepted = false
}
Keys.onEnterPressed: wordsView.currentItem.select();
Keys.onReturnPressed: wordsView.currentItem.select();
Keys.onRightPressed: wordsView.moveCurrentIndexRight();
Keys.onLeftPressed: wordsView.moveCurrentIndexLeft();
Keys.onDownPressed: wordsView.moveCurrentIndexDown();
Keys.onUpPressed: wordsView.moveCurrentIndexUp();
ListModel {
id: wordsModel
}
......@@ -273,7 +289,7 @@ ActivityBase {
//verticalLayoutDirection: GridView.BottomToTop
layoutDirection: Qt.LeftToRight
keyNavigationWraps: true
model: wordsModel
delegate: Card {
width: background.itemWidth
......@@ -286,8 +302,17 @@ ActivityBase {
mouseActive = true;
}
}
}
highlight: Rectangle {
width: wordsView.cellWidth - wordsView.spacing
height: wordsView.cellHeight - wordsView.spacing
color: "#AAFFFFFF"
border.width: 3
border.color: "black"
visible: background.keyboardMode
Behavior on x { SpringAnimation { spring: 2; damping: 0.2 } }
Behavior on y { SpringAnimation { spring: 2; damping: 0.2 } }
}
}
......
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