diff --git a/src/activities/mosaic/ActivityInfo.qml b/src/activities/mosaic/ActivityInfo.qml --- a/src/activities/mosaic/ActivityInfo.qml +++ b/src/activities/mosaic/ActivityInfo.qml @@ -37,4 +37,5 @@ credit: "" section: "puzzle" createdInVersion: 0 + levels: "1,2,3,4" } diff --git a/src/activities/mosaic/Mosaic.qml b/src/activities/mosaic/Mosaic.qml --- a/src/activities/mosaic/Mosaic.qml +++ b/src/activities/mosaic/Mosaic.qml @@ -44,6 +44,7 @@ property var areaWithKeyboardFocus: selector Component.onCompleted: { + dialogActivityConfig.initialize() activity.start.connect(start) activity.stop.connect(stop) } @@ -56,11 +57,18 @@ property alias question: question property alias answer: answer property alias selector: selector - property alias nbItems: column.nbItems property alias background: background property alias bar: bar property alias bonus: bonus property string selectedItem + property var levels: activity.datasetLoader.data + property int nbItems + property int selectorLayoutColumns + property int selectorLayoutRows + property int questionLayoutColumns + property int questionLayoutRows + property string modelDisplayLayout + property real scaleGridRatio } onStart: { Activity.start(items) } @@ -112,34 +120,32 @@ id: column spacing: 10 x: parent.width * 0.05 - y: parent.height * 0.05 + y: column.verticalMode ? parent.height * 0.01 : parent.height * 0.05 width: parent.width * 0.9 property int nbItems: 24 property bool horizontal: background.width >= background.height - property int nbColumns: Activity.questionLayout[nbItems][0] - property int nbLines: Activity.questionLayout[nbItems][1] + property bool verticalMode: items.modelDisplayLayout === "singleColumn" + property int nbColumns: items.questionLayoutColumns + property int nbLines: items.questionLayoutRows property int itemWidth: horizontal ? Math.min(width / 2 / nbColumns - 10 - 10 / nbColumns / 2, parent.height / 2 / nbLines - 10 - 10 / nbLines / 2) : Math.min(width / nbColumns - 10 - 10 / nbColumns / 2, parent.height * 0.25 / nbLines - 10 - 10 / nbLines / 2) property int itemHeight: itemWidth - property int nbSelectorColumns: horizontal ? - Activity.selectorLayout[nbItems][0] : - Activity.selectorLayout[nbItems][0] / 2 - property int nbSelectorLines: horizontal ? - Activity.selectorLayout[nbItems][1] : - Activity.selectorLayout[nbItems][1] * 2 + property int nbSelectorColumns + property int nbSelectorLines Grid { id: row spacing: 10 - columns: column.horizontal ? 2 : 1 + columns: column.verticalMode ? 1 : (column.horizontal ? 2 : 1) // === The Question Area === Rectangle { + id: questionRectangle height: (column.itemHeight + 10) * column.nbLines width: column.horizontal ? column.width / 2 : column.width + 10 color: "#55333333" @@ -158,6 +164,7 @@ interactive: false keyNavigationWraps: true delegate: Image { + id: imageQuestionId source: Activity.url + modelData fillMode: Image.PreserveAspectFit width: question.cellWidth - 5 * ApplicationInfo.ratio @@ -170,6 +177,7 @@ // === The Answer Area === Rectangle { + id: answerRectangle height: (column.itemHeight + 10) * column.nbLines width: column.horizontal ? column.width / 2 : column.width + 10 color: "#55333333" @@ -221,7 +229,6 @@ } } } - function selectCurrentCell(selectedCell) { Activity.answerSelected(selectedCell.cellIndex) } @@ -235,6 +242,7 @@ // === The Selector === Rectangle { + id: selectorRectangle height: (column.itemWidth + 10) * column.nbSelectorLines width: column.width + 10 color: "#661111AA" @@ -275,6 +283,37 @@ readonly property string imageName: modelData states: [ + State { + name: "singleColumn" + when: column.verticalMode + PropertyChanges { + target: column + nbSelectorColumns: items.selectorLayoutColumns + nbSelectorLines: items.selectorLayoutRows + } + PropertyChanges { + target: selectorRectangle + height: (column.itemHeight + 20) * (column.nbLines / 1.05) + width: column.horizontal ? column.width / 2 : column.width + 10 + } + }, + State { + name: "doubleColumn" + when: !column.verticalMode + PropertyChanges { + target: column + nbSelectorColumns: horizontal ? + items.selectorLayoutColumns : + items.selectorLayoutColumns / 2 + nbSelectorLines: horizontal ? + items.selectorLayoutRows : + items.selectorLayoutRows * 2 + } + PropertyChanges { + target: selectorRectangle + width: column.width + 10 + } + }, State { name: "notclicked" when: !imageId.iAmSelected && !mouseArea.containsMouse @@ -307,6 +346,7 @@ scale: 1 } } + ] SequentialAnimation { @@ -358,17 +398,39 @@ } } + DialogChooseLevel { + id: dialogActivityConfig + currentActivity: activity.activityInfo + + onSaveData: { + levelFolder = dialogActivityConfig.chosenLevels + currentActivity.currentLevels = dialogActivityConfig.chosenLevels + ApplicationSettings.setCurrentLevels(currentActivity.name, dialogActivityConfig.chosenLevels) + // restart activity on saving + background.start() + } + onClose: { + home() + } + onStartActivity: { + background.start() + } + } + DialogHelp { id: dialogHelp onClose: home() } Bar { id: bar - content: BarEnumContent { value: help | home | level } + content: BarEnumContent { value: help | home | level | activityConfig} onHelpClicked: { displayDialog(dialogHelp) } + onActivityConfigClicked: { + displayDialog(dialogActivityConfig) + } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() diff --git a/src/activities/mosaic/mosaic.js b/src/activities/mosaic/mosaic.js --- a/src/activities/mosaic/mosaic.js +++ b/src/activities/mosaic/mosaic.js @@ -23,60 +23,21 @@ .import QtQuick 2.6 as Quick .import "qrc:/gcompris/src/core/core.js" as Core -var images = [ - "aquarela_colors.svg", - "giraffe.svg", - "pencil.svg", - "mouse_on_cheese.svg", - "mushroom_house.svg", - "pencils_paper.svg", - "pencils.svg", - "white_cake.svg", - "die_1.svg", - "die_2.svg", - "die_3.svg", - "die_4.svg", - "die_5.svg", - "die_6.svg", - "die_7.svg", - "die_0.svg", - "digital_die0.svg", - "digital_die1.svg", - "digital_die2.svg", - "digital_die3.svg", - "digital_die4.svg", - "digital_die5.svg", - "digital_die6.svg", - "digital_die7.svg" - ] - var questionModel var answerModel var selectorModel var url = "qrc:/gcompris/src/activities/mosaic/resource/" -// What is the grid layout based on the number of items -var questionLayout = { - 8: [4, 2], - 16: [4, 4], - 24: [6, 4] -} - -var selectorLayout = { - 8: [8, 1], - 16: [8, 2], - 24: [12, 2] -} - var currentLevel = 0 -var numberOfLevel = 16 +var numberOfLevel var items function start(items_) { items = items_ currentLevel = 0 initLevel() + numberOfLevel = items.levels.length } function stop() { @@ -86,21 +47,16 @@ items.bar.level = currentLevel + 1 items.background.areaWithKeyboardFocus = items.selector items.selectedItem = "" + items.nbItems = items.levels[currentLevel].nbOfCells + items.questionLayoutColumns = items.levels[currentLevel].layout[0][0] + items.questionLayoutRows = items.levels[currentLevel].layout[0][1] + items.selectorLayoutColumns = items.levels[currentLevel].layout[1][0] + items.selectorLayoutRows = items.levels[currentLevel].layout[1][1] + items.modelDisplayLayout = items.levels[currentLevel].modelDisplayLayout + items.scaleGridRatio = items.levels[currentLevel].scaleGridRatio + selectorModel = items.levels[currentLevel].images - if(currentLevel < 4) { - items.nbItems = 8 - selectorModel = images.slice(currentLevel, - currentLevel + items.nbItems); - } else if(currentLevel < 8) { - items.nbItems = 16 - selectorModel = images.slice(currentLevel - 4, - currentLevel - 4 + items.nbItems); - } else { - items.nbItems = 24 - selectorModel = images.slice(0, items.nbItems); - } items.selector.model = selectorModel - questionModel = Core.shuffle(selectorModel) items.question.model = questionModel diff --git a/src/activities/mosaic/resource/1/Data.qml b/src/activities/mosaic/resource/1/Data.qml new file mode 100644 --- /dev/null +++ b/src/activities/mosaic/resource/1/Data.qml @@ -0,0 +1,97 @@ + /* GCompris - Data.qml + * + * Copyright (C) 2020 Deepak Kumar + * + * Authors: + * Deepak Kumar + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +import GCompris 1.0 + +Data { + objective: qsTr("Up to 6 items are placed on single line.") + difficulty: 2 + + property var images: [ + "aquarela_colors.svg", + "giraffe.svg", + "pencil.svg", + "mouse_on_cheese.svg", + "mushroom_house.svg", + "pencils_paper.svg", + "pencils.svg", + "white_cake.svg", + "die_1.svg", + "die_2.svg", + "die_3.svg", + "die_4.svg", + "die_5.svg", + "die_6.svg", + "die_7.svg", + "die_0.svg", + "digital_die0.svg", + "digital_die1.svg", + "digital_die2.svg", + "digital_die3.svg", + "digital_die4.svg", + "digital_die5.svg", + "digital_die6.svg", + "digital_die7.svg" + ] + + data: [ + { + "nbOfCells": 3, + "layout": [ + [3,1], + [3,1] + ], + "modelDisplayLayout": "singleColumn", + "scaleGridRatio": 1, + "images": images.slice(0,3) + }, + { + "nbOfCells": 4, + "layout": [ + [4,1], + [4,1] + ], + "modelDisplayLayout": "singleColumn", + "scaleGridRatio": 1, + "images": images.slice(1,5) + }, + { + "nbOfCells": 5, + "layout": [ + [5,1], + [5,1] + ], + "modelDisplayLayout": "singleColumn", + "scaleGridRatio": 1, + "images": images.slice(2,7) + }, + { + "nbOfCells": 6, + "layout": [ + [6,1], + [6,1] + ], + "modelDisplayLayout": "singleColumn", + "scaleGridRatio": 1, + "images": images.slice(3,9) + + } + ] +} diff --git a/src/activities/mosaic/resource/2/Data.qml b/src/activities/mosaic/resource/2/Data.qml new file mode 100644 --- /dev/null +++ b/src/activities/mosaic/resource/2/Data.qml @@ -0,0 +1,106 @@ +/* GCompris - Data.qml + * + * Copyright (C) 2020 Deepak Kumar + * + * Authors: + * Deepak Kumar + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +import GCompris 1.0 + +Data { + objective: qsTr("Up to 8 items are placed on single line.") + difficulty: 2 + + property var images: [ + "aquarela_colors.svg", + "giraffe.svg", + "pencil.svg", + "mouse_on_cheese.svg", + "mushroom_house.svg", + "pencils_paper.svg", + "pencils.svg", + "white_cake.svg", + "die_1.svg", + "die_2.svg", + "die_3.svg", + "die_4.svg", + "die_5.svg", + "die_6.svg", + "die_7.svg", + "die_0.svg", + "digital_die0.svg", + "digital_die1.svg", + "digital_die2.svg", + "digital_die3.svg", + "digital_die4.svg", + "digital_die5.svg", + "digital_die6.svg", + "digital_die7.svg" + ] + + data: [ + { + "nbOfCells": 3, + "layout": [ + [3,1], + [3,1] + ], + "modelDisplayLayout": "singleColumn", + "scaleGridRatio": 1, + "images": images.slice(0,3) + }, + { + "nbOfCells": 4, + "layout": [ + [4,1], + [4,1] + ], + "modelDisplayLayout": "singleColumn", + "scaleGridRatio": 1, + "images": images.slice(1,5) + }, + { + "nbOfCells": 5, + "layout": [ + [5,1], + [5,1] + ], + "modelDisplayLayout": "singleColumn", + "scaleGridRatio": 1, + "images": images.slice(2,7) + }, + { + "nbOfCells": 6, + "layout": [ + [6,1], + [6,1] + ], + "modelDisplayLayout": "singleColumn", + "scaleGridRatio": 1, + "images": images.slice(3,9) + }, + { + "nbOfCells": 8, + "layout": [ + [8,1], + [8,1] + ], + "modelDisplayLayout": "singleColumn", + "scaleGridRatio": 1, + "images": images.slice(5,13) + } + ] +} diff --git a/src/activities/mosaic/resource/3/Data.qml b/src/activities/mosaic/resource/3/Data.qml new file mode 100644 --- /dev/null +++ b/src/activities/mosaic/resource/3/Data.qml @@ -0,0 +1,137 @@ +/* GCompris - Data.qml + * + * Copyright (C) 2020 Deepak Kumar + * + * Authors: + * Deepak Kumar + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +import GCompris 1.0 + +Data { + objective: qsTr("Up to 16 items are placed on multiple lines.") + difficulty: 3 + + property var images: [ + "aquarela_colors.svg", + "giraffe.svg", + "pencil.svg", + "mouse_on_cheese.svg", + "mushroom_house.svg", + "pencils_paper.svg", + "pencils.svg", + "white_cake.svg", + "die_1.svg", + "die_2.svg", + "die_3.svg", + "die_4.svg", + "die_5.svg", + "die_6.svg", + "die_7.svg", + "die_0.svg", + "digital_die0.svg", + "digital_die1.svg", + "digital_die2.svg", + "digital_die3.svg", + "digital_die4.svg", + "digital_die5.svg", + "digital_die6.svg", + "digital_die7.svg" + ] + + data: [ + { + "nbOfCells": 8, + "layout": [ + [4,2], + [8,1] + ], + "modelDisplayLayout": "doubleColumn", + "scaleGridRatio": 1.7, + "images": images.slice(0,8) + }, + { + "nbOfCells": 8, + "layout": [ + [4,2], + [8,1] + ], + "modelDisplayLayout": "doubleColumn", + "scaleGridRatio": 1.7, + "images": images.slice(1,9) + }, + { + "nbOfCells": 8, + "layout": [ + [4,2], + [8,1] + ], + "modelDisplayLayout": "doubleColumn", + "scaleGridRatio": 1.7, + "images": images.slice(2,10) + }, + { + "nbOfCells": 8, + "layout": [ + [4,2], + [8,1] + ], + "modelDisplayLayout": "doubleColumn", + "scaleGridRatio": 1.7, + "images": images.slice(3,11) + }, + { + "nbOfCells": 16, + "layout": [ + [4,4], + [8,2] + ], + "modelDisplayLayout": "doubleColumn", + "scaleGridRatio": 1.7, + "images": images.slice(4,20) + }, + { + "nbOfCells": 16, + "layout": [ + [4,4], + [8,2] + ], + "modelDisplayLayout": "doubleColumn", + "scaleGridRatio": 1.7, + "images": images.slice(5,21) + }, + { + "nbOfCells": 16, + "layout": [ + [4,4], + [8,2] + ], + "modelDisplayLayout": "doubleColumn", + "scaleGridRatio": 1.7, + "images": images.slice(6,22) + }, + { + "nbOfCells": 16, + "layout": [ + [4,4], + [8,2] + ], + "modelDisplayLayout": "doubleColumn", + "scaleGridRatio": 1.7, + "images": images.slice(2,18) + } + ] +} + diff --git a/src/activities/mosaic/resource/4/Data.qml b/src/activities/mosaic/resource/4/Data.qml new file mode 100644 --- /dev/null +++ b/src/activities/mosaic/resource/4/Data.qml @@ -0,0 +1,137 @@ +/* GCompris - Data.qml + * + * Copyright (C) 2020 Deepak Kumar + * + * Authors: + * Deepak Kumar + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +import GCompris 1.0 + +Data { + objective: qsTr("Up to 24 items are placed on multiple lines.") + difficulty: 4 + + property var images: [ + "aquarela_colors.svg", + "giraffe.svg", + "pencil.svg", + "mouse_on_cheese.svg", + "mushroom_house.svg", + "pencils_paper.svg", + "pencils.svg", + "white_cake.svg", + "die_1.svg", + "die_2.svg", + "die_3.svg", + "die_4.svg", + "die_5.svg", + "die_6.svg", + "die_7.svg", + "die_0.svg", + "digital_die0.svg", + "digital_die1.svg", + "digital_die2.svg", + "digital_die3.svg", + "digital_die4.svg", + "digital_die5.svg", + "digital_die6.svg", + "digital_die7.svg" + ] + + data: [ + { + "nbOfCells": 24, + "layout": [ + [6,4], + [12,2] + ], + "modelDisplayLayout": "doubleColumn", + "scaleGridRatio": 1.9, + "images": images.slice(0,24) + }, + { + "nbOfCells": 24, + "layout": [ + [6,4], + [12,2] + ], + "modelDisplayLayout": "doubleColumn", + "scaleGridRatio": 1.9, + "images": images.slice(0,24) + }, + { + "nbOfCells": 24, + "layout": [ + [6,4], + [12,2] + ], + "modelDisplayLayout": "doubleColumn", + "scaleGridRatio": 1.9, + "images": images.slice(0,24) + }, + { + "nbOfCells": 24, + "layout": [ + [6,4], + [12,2] + ], + "modelDisplayLayout": "doubleColumn", + "scaleGridRatio": 1.9, + "images": images.slice(0,24) + }, + { + "nbOfCells": 24, + "layout": [ + [6,4], + [12,2] + ], + "modelDisplayLayout": "doubleColumn", + "scaleGridRatio": 1.9, + "images": images.slice(0,24) + }, + { + "nbOfCells": 24, + "layout": [ + [6,4], + [12,2] + ], + "modelDisplayLayout": "doubleColumn", + "scaleGridRatio": 1.9, + "images": images.slice(0,24) + }, + { + "nbOfCells": 24, + "layout": [ + [6,4], + [12,2] + ], + "modelDisplayLayout": "doubleColumn", + "scaleGridRatio": 1.9, + "images": images.slice(0,24) + }, + { + "nbOfCells": 24, + "layout": [ + [6,4], + [12,2] + ], + "modelDisplayLayout": "doubleColumn", + "scaleGridRatio": 1.9, + "images": images.slice(0,24) + } + ] +} +