diff --git a/src/core/DialogChooseLevel.qml b/src/core/DialogChooseLevel.qml --- a/src/core/DialogChooseLevel.qml +++ b/src/core/DialogChooseLevel.qml @@ -58,7 +58,7 @@ property var difficultiesModel: [] property QtObject currentActivity - property string chosenLevel + property var chosenLevels: [] property var activityData onActivityDataChanged: loadData() @@ -108,9 +108,17 @@ border.color: "black" border.width: 1 + property bool inMenu: false + + onVisibleChanged: { + if(visible) { + configLoader.initializePanel() + } + } + function initialize() { // dataset information - chosenLevel = currentActivity.currentLevel + chosenLevels = currentActivity.currentLevels difficultiesModel = [] if(currentActivity.levels.length == 0) { print("no levels to load for", activityName) @@ -145,7 +153,7 @@ } onLoaded: { - difficultiesModel.push({"level": currentFile.level, "objective": item.objective, "difficulty": item.difficulty}) + difficultiesModel.push({"level": currentFile.level, "objective": item.objective, "difficulty": item.difficulty, "selectedInConfig": chosenLevels.includes(currentFile.level)}) if(dataFiles.length != 0) { start() } @@ -204,7 +212,7 @@ // Header buttons Row { id: datasetOptionsRow - height: datasetVisibleButton.height + height: dialogChooseLevel.height / 12 width: parent.width spacing: parent.width / 4 anchors.leftMargin: parent.width / 8 @@ -212,6 +220,8 @@ id: datasetVisibleButton text: qsTr("Dataset") enabled: hasDataset + height: parent.height + opacity: enabled ? 1 : 0 width: parent.width / 3 property bool selected: true style: GCButtonStyle { @@ -223,6 +233,8 @@ id: optionsVisibleButton text: qsTr("Options") enabled: hasConfig + height: parent.height + opacity: enabled ? 1 : 0 width: parent.width / 3 style: GCButtonStyle { selected: !datasetVisibleButton.selected @@ -257,13 +269,22 @@ active: optionsVisibleButton.enabled source: active ? "qrc:/gcompris/src/activities/"+activityName+"/ActivityConfig.qml" : "" - onItemChanged: { + // Load configuration at start of activity + // in the menu, it's done when the visibility property + // of the dialog changes + onItemChanged: if(!inMenu) { initializePanel(); } + + function initializePanel() { if(item) { - item.background = dialogChooseLevel - dialogChooseLevel.saveData.connect(save) + // only connect once the signal to save data + if(item.background !== dialogChooseLevel) { + item.background = dialogChooseLevel + dialogChooseLevel.saveData.connect(save) + } getInitialConfiguration() } } + function getInitialConfiguration() { activityData = Qt.binding(function() { return item.dataToSave }) if(item) { @@ -281,9 +302,6 @@ visible: datasetVisibleButton.selected spacing: 10 - ExclusiveGroup { - id: levelsGroup - } Repeater { id: difficultiesRepeater delegate: Row { @@ -299,9 +317,20 @@ id: objective width: dialogChooseLevel.width - 30 - difficultyIcon.width - 2 * flick.anchors.margins text: modelData.objective - exclusiveGroup: levelsGroup - checked: chosenLevel === modelData.level - onClicked: chosenLevel = modelData.level + // to be fixed by all last used levels + checked: modelData.selectedInConfig + onClicked: { + if(checked) { + chosenLevels.push(modelData.level) + } + else if(chosenLevels.length > 1) { + chosenLevels.splice(chosenLevels.indexOf(modelData.level), 1) + } + else { + // At least one must be selected + checked = true; + } + } } } } @@ -323,12 +352,13 @@ // Footer buttons Row { id: saveAndPlayRow - height: cancelButton.height + height: dialogChooseLevel.height / 12 width: parent.width spacing: parent.width / 16 Button { id: cancelButton text: qsTr("Cancel") + height: parent.height width: parent.width / 4 property bool selected: true style: GCButtonStyle {} @@ -337,17 +367,21 @@ Button { id: saveButton text: qsTr("Save") + height: parent.height width: parent.width / 4 property bool selected: true style: GCButtonStyle { } onClicked: { saveData(); + close(); } } Button { id: saveAndStartButton text: qsTr("Save and start") + height: parent.height width: parent.width / 3 + visible: inMenu === true style: GCButtonStyle { } onClicked: { saveData(); @@ -371,4 +405,4 @@ File { id: activityConfigFile } -} +} \ No newline at end of file