diff --git a/src/activities/algorithm/Algorithm.qml b/src/activities/algorithm/Algorithm.qml --- a/src/activities/algorithm/Algorithm.qml +++ b/src/activities/algorithm/Algorithm.qml @@ -52,7 +52,6 @@ property alias choiceTray: choiceTray property alias question: question property alias answer: answer - property alias choice: choice property GCSfx audioEffects: activity.audioEffects property alias background: background property alias bar: bar @@ -64,23 +63,32 @@ onStart: { Activity.start(items) } onStop: { Activity.stop() } + property bool keyNavigationVisible: false + + Keys.onPressed: { + keyNavigationVisible = true + if(event.key === Qt.Key_Left) + choiceGridView.moveCurrentIndexLeft() + if(event.key === Qt.Key_Right) + choiceGridView.moveCurrentIndexRight() + if(event.key === Qt.Key_Space || event.key === Qt.Key_Enter || event.key === Qt.Key_Return) + choiceGridView.currentItem.clicked() + } + Column { id: column spacing: 10 - x: parent.width * 0.1 - y: parent.height * 0.1 - width: parent.width * 0.8 + y: parent.height * 0.05 + width: itemWidth * Activity.images.length + anchors.horizontalCenter: parent.horizontalCenter - property int itemWidth: width / Activity.images.length - 10 - property int itemHeight: itemWidth + property int itemWidth: Math.min(background.width * 0.77 / Activity.images.length, background.height * 0.19) Rectangle { id: questionTray - height: column.itemHeight + 10 - width: parent.width + 10 + height: column.itemWidth + width: parent.width color: "#55333333" - border.color: "black" - border.width: 0 radius: 5 Row { @@ -94,9 +102,11 @@ id: question Image { source: Activity.url + modelData + '.svg' - sourceSize.height: questionTray.height - width: column.itemWidth - height: column.itemHeight + sourceSize.height: height + sourceSize.width: width + width: column.itemWidth - 6 * ApplicationInfo.ratio + height: width + fillMode: Image.PreserveAspectFit } } } @@ -104,11 +114,9 @@ Rectangle { id: answerTray - height: column.itemHeight + 10 - width: parent.width + 10 + height: column.itemWidth + width: parent.width color: "#55333333" - border.color: "black" - border.width: 0 radius: 5 Row { anchors.topMargin: 4 @@ -122,9 +130,11 @@ Image { source: "qrc:/gcompris/src/activities/algorithm/resource/" + modelData + '.svg' - sourceSize.height: answerTray.height - width: column.itemWidth - height: column.itemHeight + sourceSize.height: height + sourceSize.width: width + width: column.itemWidth - 6 * ApplicationInfo.ratio + height: width + fillMode: Image.PreserveAspectFit } } } @@ -132,78 +142,94 @@ // A spacer Item { - height: column.itemHeight / 2 + height: column.itemWidth / 2 width: parent.width } Rectangle { id: choiceTray - height: column.itemHeight + 10 - width: parent.width + 10 + height: column.itemWidth + width: parent.width color: "#55333333" - border.color: "black" - border.width: 0 radius: 5 - Row { + + GridView { + id: choiceGridView + anchors.fill: parent anchors.topMargin: 4 - anchors.bottomMargin: 4 anchors.leftMargin: 10 - anchors.rightMargin: 10 - anchors.fill: parent - spacing: 10 - Repeater { - id: choice - model: Activity.images - Image { - id: img - source: Activity.url + modelData + '.svg' - sourceSize.height: parent.height - width: column.itemWidth - height: column.itemHeight - state: "notclicked" - signal clicked - MouseArea { - id: mouseArea - hoverEnabled: true - anchors.fill: parent - onClicked: { - if(Activity.clickHandler(modelData)) { - particle.burst(20) - } - } + model: Activity.images + cellWidth: column.itemWidth - 1.5 * ApplicationInfo.ratio + cellHeight: cellWidth + interactive: false + keyNavigationWraps: true + highlightFollowsCurrentItem: true + highlight: Rectangle { + width: parent.cellWidth + height: parent.cellHeight + color: "#AAFFFFFF" + border.width: 3 + border.color: "black" + visible: background.keyNavigationVisible + Behavior on x { SpringAnimation { spring: 2; damping: 0.2 } } + Behavior on y { SpringAnimation { spring: 2; damping: 0.2 } } + } + + delegate: Image { + id: img + source: Activity.url + modelData + '.svg' + width: column.itemWidth - 5 * ApplicationInfo.ratio + height: width + sourceSize.width: width + sourceSize.height: height + fillMode: Image.PreserveAspectFit + state: "notclicked" + + signal clicked + + onClicked: { + if(Activity.clickHandler(modelData)) { + particle.burst(20) } - states: [ - State { - name: "notclicked" - PropertyChanges { - target: img - scale: 1.0 - } - }, - State { - name: "clicked" - when: mouseArea.pressed - PropertyChanges { - target: img - scale: 0.9 - } - }, - State { - name: "hover" - when: mouseArea.containsMouse - PropertyChanges { - target: img - scale: 1.1 - } + } + + MouseArea { + id: mouseArea + hoverEnabled: true + anchors.fill: parent + onClicked: img.clicked() + } + states: [ + State { + name: "notclicked" + PropertyChanges { + target: img + scale: 1.0 + } + }, + State { + name: "clicked" + when: mouseArea.pressed + PropertyChanges { + target: img + scale: 0.9 } - ] + }, + State { + name: "hover" + when: mouseArea.containsMouse + PropertyChanges { + target: img + scale: 1.1 + } + } + ] - Behavior on scale { NumberAnimation { duration: 70 } } + Behavior on scale { NumberAnimation { duration: 70 } } - ParticleSystemStarLoader { - id: particle - clip: false - } + ParticleSystemStarLoader { + id: particle + clip: false } } } @@ -233,10 +259,10 @@ Score { anchors { - bottom: parent.bottom + bottom: bar.top bottomMargin: 10 * ApplicationInfo.ratio right: parent.right - rightMargin: 10 * ApplicationInfo.ratio + rightMargin: 5 * ApplicationInfo.ratio top: undefined left: undefined }