Warning, /education/gcompris/src/activities/hangman/ActivityConfig.qml is written in an unsupported language. File is not indexed.

0001 /* GCompris - ActivityConfig.qml
0002  *
0003  * SPDX-FileCopyrightText: 2020 Johnny Jazeix <jazeix@gmail.com>
0004  *
0005  * Authors:
0006  *   Johnny Jazeix <jazeix@gmail.com>
0007  *
0008  *   SPDX-License-Identifier: GPL-3.0-or-later
0009  */
0010 import QtQuick 2.12
0011 import GCompris 1.0
0012 
0013 import "../../core"
0014 import "qrc:/gcompris/src/core/core.js" as Core
0015 
0016 Item {
0017     id: activityConfiguration
0018     property Item background
0019     property string locale: "system"
0020     property string configurationLocale: "system"
0021     property bool easyModeImage: true
0022     property bool easyModeAudio: true
0023     height: childrenRect.height
0024     width: flick.width
0025     property alias availableLangs: langs.languages
0026     LanguageList {
0027         id: langs
0028     }
0029 
0030     Column {
0031         id: innerColumn
0032         spacing: 10 * ApplicationInfo.ratio
0033         width: activityConfiguration.width
0034         GCComboBox {
0035             id: localeBox
0036             model: langs.languages
0037             background: activityConfiguration.background
0038             label: qsTr("Select your locale")
0039         }
0040         GCDialogCheckBox {
0041             id: easyModeImageBox
0042             text: qsTr("Display the image to find as hint")
0043             checked: easyModeImage
0044             onCheckedChanged: {
0045                 easyModeImage = checked
0046             }
0047         }
0048         GCDialogCheckBox {
0049             id: easyModeAudioBox
0050             text: qsTr("Speak the words to find (if available) when three attempts are remaining")
0051             checked: easyModeAudio
0052             onCheckedChanged: {
0053                 easyModeAudio = checked
0054             }
0055         }
0056     }
0057 
0058     function setLocale(localeToSet) {
0059         // Store the locale as-is to be displayed in menu
0060         configurationLocale = localeToSet
0061         activityConfiguration.locale = Core.resolveLocale(localeToSet)
0062     }
0063 
0064     property var dataToSave
0065 
0066     function setDefaultValues() {
0067         var localeUtf8 = dataToSave.locale;
0068         if(localeUtf8 !== "system") {
0069             localeUtf8 += ".UTF-8";
0070         }
0071 
0072         if(dataToSave.locale) {
0073             setLocale(localeUtf8)
0074         }
0075         else {
0076             localeBox.currentIndex = 0
0077             setLocale(activityConfiguration.availableLangs[0].locale)
0078         }
0079 
0080         if(dataToSave["easyModeImage"] === undefined && dataToSave["easyMode"] === undefined) {
0081             dataToSave["easyModeImage"] = "true";
0082         }
0083         easyModeImageBox.checked = (dataToSave.easyModeImage ? dataToSave.easyModeImage === "true" : dataToSave.easyMode === "true")
0084         if(dataToSave["easyModeAudio"] === undefined) {
0085             dataToSave["easyModeAudio"] = "true";
0086         }
0087         easyModeAudioBox.checked = (dataToSave.easyModeAudio === "true")
0088 
0089         for(var i = 0 ; i < activityConfiguration.availableLangs.length ; i ++) {
0090             if(activityConfiguration.availableLangs[i].locale === localeUtf8) {
0091                 localeBox.currentIndex = i;
0092                 break;
0093             }
0094         }
0095     }
0096 
0097     function saveValues() {
0098         var newLocale = activityConfiguration.availableLangs[localeBox.currentIndex].locale;
0099         // Remove .UTF-8
0100         if(newLocale.indexOf('.') != -1) {
0101             newLocale = newLocale.substring(0, newLocale.indexOf('.'))
0102         }
0103 
0104         setLocale(newLocale);
0105 
0106         dataToSave = {"locale": newLocale, "activityLocale": activityConfiguration.locale,
0107                       "easyModeImage": "" + easyModeImage,
0108                       "easyModeAudio": "" + easyModeAudio}
0109     }
0110 }