Commit 2a1d62b5 authored by Deepak  Kumar's avatar Deepak Kumar Committed by Johnny Jazeix

digital_electricity, move config to activityconfig (multiple dataset style)

parent 30da527f
/* GCompris - ActivityConfig.qml
*
* Copyright (C) 2020 Deepak Kumar <deepakdk2431@gmail.com>
*
* Authors:
* Deepak Kumar <deepakdk2431@gmail.com>
*
* 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 <https://www.gnu.org/licenses/>.
*/
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()
}
}
......@@ -33,9 +33,6 @@ ActivityBase {
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 @@ ActivityBase {
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 @@ ActivityBase {
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 @@ ActivityBase {
}
}
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 @@ ActivityBase {
BarButton {
id: okButton
visible: activity.isTutorialMode
visible: items.isTutorialMode
anchors {
bottom: bar.top
right: parent.right
......@@ -507,15 +465,13 @@ ActivityBase {
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)
}
}
......
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