diff --git a/src/activities/superbrain/ActivityConfig.qml b/src/activities/superbrain/ActivityConfig.qml new file mode 100644 --- /dev/null +++ b/src/activities/superbrain/ActivityConfig.qml @@ -0,0 +1,65 @@ +/* GCompris - ActivityConfig.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 QtQuick 2.6 + +import "../../core" + +Item { + id: activityConfiguration + property Item background + property alias modeBox: modeBox + width: if(background) background.width + property var availableModes: [ + { "text": qsTr("Colors"), "value": "color" }, + { "text": qsTr("Shapes"), "value": "symbol" } + ] + Flow { + id: flow + spacing: 5 + width: parent.width + GCComboBox { + id: modeBox + model: availableModes + background: activityConfiguration.background + label: qsTr("Select your mode") + } + } + + property var dataToSave + + function setDefaultValues() { + if(dataToSave["mode"] === undefined) { + dataToSave["mode"] = "color"; + modeBox.currentIndex = 0 + } + for(var i = 0 ; i < availableModes.length ; i ++) { + if(availableModes[i].value === dataToSave["mode"]) { + modeBox.currentIndex = i; + break; + } + } + } + + function saveValues() { + var newMode = availableModes[modeBox.currentIndex].value; + dataToSave = {"mode": newMode}; + } +} diff --git a/src/activities/superbrain/SearchItem.qml b/src/activities/superbrain/SearchItem.qml --- a/src/activities/superbrain/SearchItem.qml +++ b/src/activities/superbrain/SearchItem.qml @@ -33,7 +33,7 @@ Image { id: symbol - visible: Activity.mode === "symbol" + visible: items.mode === "symbol" fillMode: Image.PreserveAspectFit source: Activity.symbols[root.searchItemIndex] anchors.left: parent.left @@ -44,7 +44,7 @@ } Rectangle { id: symbolHighlighter - visible: (Activity.mode === "symbol") && root.highlightSymbol + visible: (items.mode === "symbol") && root.highlightSymbol anchors.fill: parent width: parent.width height: parent.height @@ -55,7 +55,7 @@ Rectangle { id: color - visible: Activity.mode === "color" + visible: items.mode === "color" color: Activity.colors[root.searchItemIndex] anchors.fill: parent width: parent.width diff --git a/src/activities/superbrain/Superbrain.qml b/src/activities/superbrain/Superbrain.qml --- a/src/activities/superbrain/Superbrain.qml +++ b/src/activities/superbrain/Superbrain.qml @@ -50,7 +50,7 @@ } Component.onCompleted: { - dialogActivityConfig.getInitialConfiguration() + dialogActivityConfig.initialize() activity.start.connect(start) activity.stop.connect(stop) } @@ -67,6 +67,7 @@ property alias guessModel: guessModel property alias guessColumn: guessColumn property alias currentRepeater: currentRepeater + property string mode: "color" } onStart: { Activity.start(items) } @@ -620,71 +621,29 @@ onClose: home() } - DialogActivityConfig { + DialogChooseLevel { id: dialogActivityConfig - currentActivity: activity - content: Component { - Item { - property alias modeBox: modeBox - - property var availableModes: [ - { "text": qsTr("Colors"), "value": "color" }, - { "text": qsTr("Shapes"), "value": "symbol" } - ] - - Flow { - id: flow - spacing: 5 - width: dialogActivityConfig.width - GCComboBox { - id: modeBox - model: availableModes - background: dialogActivityConfig - label: qsTr("Select your mode") - } - } - } + currentActivity: activity.activityInfo + onClose: { + home() } - onClose: home() onLoadData: { - if(dataToSave && dataToSave["mode"]) { - Activity.mode = dataToSave["mode"]; - } - } - - onSaveData: { - var newMode = dialogActivityConfig.configItem.availableModes[dialogActivityConfig.configItem.modeBox.currentIndex].value; - if (newMode !== Activity.mode) { - chooserGrid.model = new Array(); - Activity.mode = newMode; - dataToSave = {"mode": Activity.mode}; - Activity.initLevel(); - } - } - - function setDefaultValues() { - for(var i = 0 ; i < dialogActivityConfig.configItem.availableModes.length ; i ++) { - if(dialogActivityConfig.configItem.availableModes[i].value === Activity.mode) { - dialogActivityConfig.configItem.modeBox.currentIndex = i; - break; - } + if(activityData && activityData["mode"]) { + items.mode = activityData["mode"]; } } } Bar { id: bar - content: BarEnumContent { value: help | home | level | config } + content: BarEnumContent { value: help | home | level | activityConfig } onHelpClicked: { displayDialog(dialogHelp) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() - onConfigClicked: { - dialogActivityConfig.active = true - // Set default values - dialogActivityConfig.setDefaultValues(); + onActivityConfigClicked: { displayDialog(dialogActivityConfig) } } diff --git a/src/activities/superbrain/superbrain.js b/src/activities/superbrain/superbrain.js --- a/src/activities/superbrain/superbrain.js +++ b/src/activities/superbrain/superbrain.js @@ -53,7 +53,6 @@ "#FF04611a", // dark green "#FFa0174b", // dark magenta ]; -var mode = "color"; var symbols = [ baseUrl + "darkblue_star.svg", baseUrl + "lightgreen_triangle.svg",