diff --git a/src/activities/digital_electricity/ActivityConfig.qml b/src/activities/digital_electricity/ActivityConfig.qml new file mode 100644 --- /dev/null +++ b/src/activities/digital_electricity/ActivityConfig.qml @@ -0,0 +1,67 @@ +/* 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" +import "digital_electricity.js" as Activity + +Item { + id: activityConfiguration + property Item background + property alias modeBox: modeBox + width: if(background) background.width + property var availableModes: [ + { "text": qsTr("Tutorial Mode"), "value": "tutorial" }, + { "text": qsTr("Free Mode"), "value": "free" } + ] + 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"] = "tutorial"; + 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}; + Activity.reset() + } +} diff --git a/src/activities/digital_electricity/DigitalElectricity.qml b/src/activities/digital_electricity/DigitalElectricity.qml --- a/src/activities/digital_electricity/DigitalElectricity.qml +++ b/src/activities/digital_electricity/DigitalElectricity.qml @@ -33,9 +33,6 @@ onStart: focus = true onStop: {} - property string mode: "tutorial" - property bool isTutorialMode: mode == "tutorial" ? true : false - pageComponent: Image { id: background anchors.fill: parent @@ -47,7 +44,7 @@ property bool hori: background.width >= background.height Component.onCompleted: { - dialogActivityConfig.getInitialConfiguration() + dialogActivityConfig.initialize() activity.start.connect(start) activity.stop.connect(stop) } @@ -113,8 +110,9 @@ property alias displayTruthTable: inputOutputTxt.displayTruthTable property alias dataset: dataset property alias tutorialDataset: tutorialDataset + property string mode: "tutorial" + property bool isTutorialMode: mode == "tutorial" ? true : false property alias infoImage: infoImage - property bool isTutorialMode: activity.isTutorialMode property alias tutorialInstruction: tutorialInstruction property real toolsMargin: 90 * ApplicationInfo.ratio property real zoomLvl: 0.25 @@ -432,55 +430,15 @@ } } - DialogActivityConfig { + DialogChooseLevel { id: dialogActivityConfig - currentActivity: activity - content: Component { - Item { - property alias modesComboBox: modesComboBox - - property var availableModes: [ - { "text": qsTr("Tutorial Mode"), "value": "tutorial" }, - { "text": qsTr("Free Mode"), "value": "free" }, - ] - - Flow { - id: flow - spacing: 5 - width: dialogActivityConfig.width - GCComboBox { - id: modesComboBox - model: availableModes - background: dialogActivityConfig - label: qsTr("Select your Mode") - } - } - } + currentActivity: activity.activityInfo + onClose: { + home(); } - - onClose: home(); - onLoadData: { - if(dataToSave && dataToSave["modes"]) { - activity.mode = dataToSave["modes"]; - } - } - - onSaveData: { - var newMode = dialogActivityConfig.configItem.availableModes[dialogActivityConfig.configItem.modesComboBox.currentIndex].value; - if (newMode !== activity.mode) { - activity.mode = newMode; - dataToSave = {"modes": activity.mode}; - Activity.reset() - } - } - - function setDefaultValues() { - for(var i = 0 ; i < dialogActivityConfig.configItem.availableModes.length; i ++) { - if(dialogActivityConfig.configItem.availableModes[i].value === activity.mode) { - dialogActivityConfig.configItem.modesComboBox.currentIndex = i; - break; - } + if(activityData && activityData["mode"]) { + items.mode = activityData["mode"]; } } } @@ -492,7 +450,7 @@ BarButton { id: okButton - visible: activity.isTutorialMode + visible: items.isTutorialMode anchors { bottom: bar.top right: parent.right @@ -507,15 +465,13 @@ Bar { id: bar - content: BarEnumContent { value: help | home | ( activity.isTutorialMode ? level : 0) | reload | config} + content: BarEnumContent { value: help | home | (items.isTutorialMode ? level : 0) | reload | activityConfig} onHelpClicked: {displayDialog(dialogHelp)} onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() onReloadClicked: Activity.reset() - onConfigClicked: { - dialogActivityConfig.active = true - dialogActivityConfig.setDefaultValues() + onActivityConfigClicked: { displayDialog(dialogActivityConfig) } }