diff --git a/src/activities/missing-letter/ActivityConfig.qml b/src/activities/missing-letter/ActivityConfig.qml new file mode 100644 index 000000000..48ac641c2 --- /dev/null +++ b/src/activities/missing-letter/ActivityConfig.qml @@ -0,0 +1,92 @@ +/* GCompris - ActivityConfig.qml + * + * Copyright (C) 2020 Johnny Jazeix + * + * Authors: + * Johnny Jazeix + * + * 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 GCompris 1.0 + +import "../../core" +import "qrc:/gcompris/src/core/core.js" as Core + +Item { + id: activityConfiguration + property Item background + property alias localeBox: localeBox + property string locale: "system" + property string configurationLocale: "system" + width: if(background) background.width + property alias availableLangs: langs.languages + LanguageList { + id: langs + } + + Column { + spacing: 10 + Flow { + spacing: 5 + width: activityConfiguration.width + GCComboBox { + id: localeBox + model: langs.languages + background: activityConfiguration.background + label: qsTr("Select your locale") + } + } + } + + function setLocale(localeToSet) { + // Store the locale as-is to be displayed in menu + configurationLocale = localeToSet + activityConfiguration.locale = Core.resolveLocale(localeToSet) + } + + property var dataToSave + function setDefaultValues() { + var localeUtf8 = dataToSave.locale; + if(localeUtf8 !== "system") { + localeUtf8 += ".UTF-8"; + } + + if(dataToSave.locale) { + setLocale(localeUtf8) + } + else { + activityConfiguration.localeBox.currentIndex = 0 + setLocale(activityConfiguration.availableLangs[0].locale) + } + + for(var i = 0 ; i < activityConfiguration.availableLangs.length ; i ++) { + if(activityConfiguration.availableLangs[i].locale === localeUtf8) { + activityConfiguration.localeBox.currentIndex = i; + break; + } + } + } + + function saveValues() { + var newLocale = activityConfiguration.availableLangs[activityConfiguration.localeBox.currentIndex].locale; + // Remove .UTF-8 + if(newLocale.indexOf('.') != -1) { + newLocale = newLocale.substring(0, newLocale.indexOf('.')) + } + + setLocale(newLocale); + dataToSave = {"locale": newLocale, "activityLocale": activityConfiguration.locale} + } +} diff --git a/src/activities/missing-letter/MissingLetter.qml b/src/activities/missing-letter/MissingLetter.qml index 8c1efd8e2..e7438c425 100644 --- a/src/activities/missing-letter/MissingLetter.qml +++ b/src/activities/missing-letter/MissingLetter.qml @@ -1,387 +1,326 @@ /* GCompris - missing-letter.qml * * Copyright (C) 2014 "Amit Tomar" * * Authors: * "Pascal Georges" (GTK+ version) * "Amit Tomar" (Qt Quick port) * * 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 GCompris 1.0 import "../../core" import "qrc:/gcompris/src/core/core.js" as Core import "missing-letter.js" as Activity ActivityBase { id: activity onStart: focus = true onStop: {} // When going on configuration, it steals the focus and re set it to the activity. // We need to set it back to the textinput item in order to have key events. onFocusChanged: { if(focus) { Activity.focusTextInput() } } pageComponent: Image { id: background source: Activity.url + "background.svg" sourceSize.width: Math.max(parent.width, parent.height) fillMode: Image.PreserveAspectCrop // system locale by default property string locale: "system" property bool englishFallback: false property bool downloadWordsNeeded: false signal start signal stop Component.onCompleted: { - dialogActivityConfig.getInitialConfiguration() + dialogActivityConfig.initialize() activity.start.connect(start) activity.stop.connect(stop) } // Add here the QML items you need to access in javascript QtObject { id: items property Item main: activity.main property alias background: background property alias bar: bar property alias bonus: bonus property alias score: score property alias questionImage: questionImage property alias questionText: questionText property alias answers: answers property GCAudio audioVoices: activity.audioVoices property alias englishFallbackDialog: englishFallbackDialog property alias parser: parser property alias locale: background.locale property string answer property alias textinput: textinput property bool isGoodAnswer: false property bool buttonsBlocked: false } onStart: { Activity.init(items) Activity.focusTextInput() Activity.start() } onStop: { Activity.stop() } TextInput { // Helper element to capture composed key events like french รด which // are not available via Keys.onPressed() on linux. Must be // disabled on mobile! id: textinput anchors.centerIn: background enabled: !ApplicationInfo.isMobile focus: true visible: false onTextChanged: { if (text != '') { var typedText = text var answerText = Activity.getCurrentQuestion().answer if(ApplicationSettings.fontCapitalization === Font.AllUppercase) typedText = text.toLocaleUpperCase() else if(ApplicationSettings.fontCapitalization === Font.AllLowercase) typedText = text.toLocaleLowerCase() if(!items.isGoodAnswer && (typedText === answerText)) { questionAnim.start() Activity.showAnswer() } text = ''; } } } // Buttons with possible answers shown on the left of screen Column { id: buttonHolder spacing: 10 * ApplicationInfo.ratio x: holder.x - width - 10 * ApplicationInfo.ratio y: holder.y add: Transition { NumberAnimation { properties: "y"; from: holder.y; duration: 500 } } Repeater { id: answers AnswerButton { width: 120 * ApplicationInfo.ratio height: (holder.height - buttonHolder.spacing * answers.model.length) / answers.model.length textLabel: modelData blockAllButtonClicks: items.buttonsBlocked isCorrectAnswer: modelData === items.answer onCorrectlyPressed: questionAnim.start() onPressed: { items.buttonsBlocked = true if(!items.isGoodAnswer) { modelData == items.answer ? Activity.showAnswer() : '' } } onIncorrectlyPressed: items.buttonsBlocked = false } } } // Picture holder for different images being shown Rectangle { id: holder width: Math.max(questionImage.width * 1.1, questionImage.height * 1.1) height: questionTextBg.y + questionTextBg.height x: (background.width - width - 130 * ApplicationInfo.ratio) / 2 + 130 * ApplicationInfo.ratio y: 20 color: "black" radius: 10 border.width: 2 border.color: "black" gradient: Gradient { GradientStop { position: 0.0; color: "#80FFFFFF" } GradientStop { position: 0.9; color: "#80EEEEEE" } GradientStop { position: 1.0; color: "#80AAAAAA" } } Item { id: spacer height: 20 } Image { id: questionImage anchors.horizontalCenter: holder.horizontalCenter anchors.top: spacer.bottom width: Math.min((background.width - 120 * ApplicationInfo.ratio) * 0.7, (background.height - 100 * ApplicationInfo.ratio) * 0.7) height: width } Rectangle { id: questionTextBg width: holder.width height: questionText.height * 1.1 anchors.horizontalCenter: holder.horizontalCenter anchors.top: questionImage.bottom radius: 10 border.width: 2 border.color: "black" gradient: Gradient { GradientStop { position: 0.0; color: "#000" } GradientStop { position: 0.9; color: "#666" } GradientStop { position: 1.0; color: "#AAA" } } GCText { id: questionText horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter style: Text.Outline styleColor: "black" color: "white" fontSize: largeSize wrapMode: Text.WordWrap width: holder.width SequentialAnimation { id: questionAnim NumberAnimation { target: questionText property: 'scale' to: 1.05 duration: 500 easing.type: Easing.OutQuad } NumberAnimation { target: questionText property: 'scale' to: 0.95 duration: 1000 easing.type: Easing.OutQuad } NumberAnimation { target: questionText property: 'scale' to: 1.0 duration: 500 easing.type: Easing.OutQuad } ScriptAction { script: Activity.nextSubLevel() } } } } } Score { id: score anchors.bottom: undefined anchors.bottomMargin: 10 * ApplicationInfo.ratio anchors.right: parent.right anchors.rightMargin: 10 * ApplicationInfo.ratio anchors.top: parent.top } - DialogActivityConfig { + DialogChooseLevel { id: dialogActivityConfig - currentActivity: activity - property string configurationLocale: "system" - - content: Component { - Item { - property alias localeBox: localeBox - height: column.height - - property alias availableLangs: langs.languages - LanguageList { - id: langs - } - - Column { - id: column - spacing: 10 - width: parent.width - - Flow { - spacing: 5 - width: dialogActivityConfig.width - GCComboBox { - id: localeBox - model: langs.languages - background: dialogActivityConfig - label: qsTr("Select your locale") - } - } - } - } + currentActivity: activity.activityInfo + onClose: { + home() } - - onClose: home() - - function setLocale(localeToSet) { - // Store the locale as-is to be displayed in menu - configurationLocale = localeToSet - background.locale = Core.resolveLocale(localeToSet) + onSaveData: { + levelFolder = dialogActivityConfig.chosenLevels + currentActivity.currentLevels = dialogActivityConfig.chosenLevels + ApplicationSettings.setCurrentLevels(currentActivity.name, dialogActivityConfig.chosenLevels) } - onLoadData: { - if(dataToSave && dataToSave["locale"]) { - setLocale(dataToSave["locale"]) + if(activityData && activityData["activityLocale"]) { + background.locale = activityData["activityLocale"]; } else { - setLocale(background.locale) + background.locale = Core.resolveLocale(background.locale) } } - onSaveData: { - var oldLocale = configurationLocale; - var newLocale = - dialogActivityConfig.configItem.availableLangs[dialogActivityConfig.loader.item.localeBox.currentIndex].locale; - // Remove .UTF-8 - if(newLocale.indexOf('.') != -1) { - newLocale = newLocale.substring(0, newLocale.indexOf('.')) - } - dataToSave = {"locale": newLocale } - - setLocale(newLocale) - // Restart the activity with new information - if(oldLocale !== newLocale) { - background.stop(); - background.start(); - } - } - - - function setDefaultValues() { - var localeUtf8 = configurationLocale; - if(configurationLocale != "system") { - localeUtf8 += ".UTF-8"; - } - - for(var i = 0 ; i < dialogActivityConfig.configItem.availableLangs.length ; i ++) { - if(dialogActivityConfig.configItem.availableLangs[i].locale === localeUtf8) { - dialogActivityConfig.loader.item.localeBox.currentIndex = i; - break; - } - } + onStartActivity: { + background.stop() + background.start() } } DialogHelp { id: dialogHelp onClose: home() } Bar { id: bar - content: BarEnumContent { value: help | home | level | repeat | config } + content: BarEnumContent { value: help | home | level | repeat | activityConfig } onHelpClicked: displayDialog(dialogHelp) onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() onRepeatClicked: Activity.playCurrentWord() - onConfigClicked: { - dialogActivityConfig.active = true - dialogActivityConfig.setDefaultValues() + onActivityConfigClicked: { displayDialog(dialogActivityConfig) } } Bonus { id: bonus onStart: items.buttonsBlocked = true onStop: items.buttonsBlocked = false Component.onCompleted: win.connect(Activity.nextLevel) } JsonParser { id: parser onError: console.error("missing letter: Error parsing json: " + msg); } Loader { id: englishFallbackDialog sourceComponent: GCDialog { parent: activity.main message: qsTr("We are sorry, we don't have yet a translation for your language.") + " " + qsTr("GCompris is developed by the KDE community, you can translate GCompris by joining a translation team on %2").arg("https://l10n.kde.org/") + "

" + qsTr("We switched to English for this activity but you can select another language in the configuration dialog.") onClose: background.englishFallback = false } anchors.fill: parent focus: true active: background.englishFallback onStatusChanged: if (status == Loader.Ready) item.start() } } }