Warning, /education/gcompris/src/activities/gletters/Gletters.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - gletters.qml 0002 * 0003 * SPDX-FileCopyrightText: 2014 Holger Kaelberer <holger.k@elberer.de> 0004 * 0005 * Authors: 0006 * Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version) 0007 * Holger Kaelberer <holger.k@elberer.de> (Qt Quick port) 0008 * 0009 * SPDX-License-Identifier: GPL-3.0-or-later 0010 */ 0011 0012 import QtQuick 2.12 0013 import GCompris 1.0 0014 0015 import "../../core" 0016 import "qrc:/gcompris/src/core/core.js" as Core 0017 import "gletters.js" as Activity 0018 0019 ActivityBase { 0020 id: activity 0021 0022 // Overload this in your activity to change it 0023 // Put you default-<locale>.json files in it 0024 property string dataSetUrl: "qrc:/gcompris/src/activities/gletters/resource/" 0025 0026 property bool uppercaseOnly: false 0027 0028 property int speedSetting: 10 0029 0030 property string activityName: "gletters" 0031 0032 property bool useDataset: false 0033 0034 /* mode of the activity, "letter" (gletters) or "word" (wordsgame):*/ 0035 property string mode: "letter" 0036 0037 // Override if you want to replace texts by your image 0038 function getImage(key) { 0039 return "" 0040 } 0041 0042 // Override if you want to replace texts by the domino 0043 function getDominoValues(key) { 0044 return [] 0045 } 0046 0047 onStart: focus = true 0048 onStop: {} 0049 0050 // When going on configuration, it steals the focus and re set it to the activity. 0051 // We need to set it back to the textinput item in order to have key events. 0052 onFocusChanged: { 0053 if(focus) { 0054 Activity.focusTextInput() 0055 } 0056 } 0057 0058 pageComponent: Image { 0059 id: background 0060 source: activity.dataSetUrl + "background.svg" 0061 fillMode: Image.PreserveAspectCrop 0062 sourceSize.height: parent.height 0063 0064 signal start 0065 signal stop 0066 0067 // system locale by default 0068 property string locale: "system" 0069 0070 Component.onCompleted: { 0071 dialogActivityConfig.initialize() 0072 activity.start.connect(start) 0073 activity.stop.connect(stop) 0074 } 0075 0076 QtObject { 0077 id: items 0078 property Item main: activity.main 0079 property Item ourActivity: activity 0080 property GCAudio audioVoices: activity.audioVoices 0081 readonly property var levels: activity.datasetLoader.data.length !== 0 ? activity.datasetLoader.data : null 0082 property string instructionText: "" 0083 property alias background: background 0084 property int currentLevel: activity.currentLevel 0085 property alias bonus: bonus 0086 property alias wordlist: wordlist 0087 property alias score: score 0088 property alias keyboard: keyboard 0089 property alias wordDropTimer: wordDropTimer 0090 property GCSfx audioEffects: activity.audioEffects 0091 property alias locale: background.locale 0092 property alias textinput: textinput 0093 property bool inputLocked: false 0094 } 0095 0096 onStart: { 0097 // for smallnumbers and smallnumbers2, we want to have the application locale, not the system one 0098 if(activity.activityName !== "gletters") { 0099 var overridenLocale = ApplicationSettings.locale 0100 // Remove .UTF-8 0101 if(overridenLocale.indexOf('.') != -1) { 0102 overridenLocale = overridenLocale.substring(0, overridenLocale.indexOf('.')) 0103 } 0104 background.locale = overridenLocale 0105 } 0106 0107 Activity.start(items, uppercaseOnly, mode, speedSetting); 0108 Activity.focusTextInput() 0109 } 0110 onStop: { Activity.stop() } 0111 0112 //instruction rectangle 0113 Rectangle { 0114 id: instruction 0115 anchors { 0116 top: parent.top 0117 topMargin: 5 0118 horizontalCenter: parent.horizontalCenter 0119 } 0120 height: instructionTxt.contentHeight * 1.1 0121 width: Math.max(Math.min(parent.width * 0.8, instructionTxt.text.length * 10), parent.width * 0.3) 0122 opacity: 0.8 0123 visible: items.levels 0124 radius: 10 0125 border.width: 2 0126 z: 10 0127 border.color: "#DDD" 0128 color: "#373737" 0129 0130 Behavior on opacity { PropertyAnimation { duration: 200 } } 0131 0132 //shows/hides the Instruction 0133 MouseArea { 0134 anchors.fill: parent 0135 onClicked: instruction.opacity = instruction.opacity == 0 ? 0.8 : 0 0136 } 0137 0138 GCText { 0139 id: instructionTxt 0140 anchors { 0141 top: parent.top 0142 topMargin: 5 0143 horizontalCenter: parent.horizontalCenter 0144 } 0145 opacity: instruction.opacity 0146 z: instruction.z 0147 fontSize: smallSize 0148 color: "white" 0149 text: items.instructionText 0150 horizontalAlignment: Text.AlignHCenter 0151 width: parent.width * 0.8 0152 wrapMode: TextEdit.WordWrap 0153 } 0154 } 0155 0156 TextInput { 0157 // Helper element to capture composed key events like french รด which 0158 // are not available via Keys.onPressed() on linux. Must be 0159 // disabled on mobile! 0160 id: textinput 0161 anchors.centerIn: background 0162 enabled: !ApplicationInfo.isMobile 0163 focus: true 0164 visible: false 0165 0166 onTextChanged: { 0167 if (text != "") { 0168 Activity.processKeyPress(text); 0169 text = ""; 0170 } 0171 } 0172 } 0173 0174 DialogChooseLevel { 0175 id: dialogActivityConfig 0176 currentActivity: activity.activityInfo 0177 onClose: { 0178 home() 0179 } 0180 onSaveData: { 0181 levelFolder = dialogActivityConfig.chosenLevels 0182 currentActivity.currentLevels = dialogActivityConfig.chosenLevels 0183 ApplicationSettings.setCurrentLevels(currentActivity.name, dialogActivityConfig.chosenLevels) 0184 } 0185 onLoadData: { 0186 if (activity.activityName === "gletters") { 0187 if(activityData && activityData["locale"]) { 0188 background.locale = Core.resolveLocale(activityData["locale"]); 0189 activity.uppercaseOnly = activityData["uppercaseMode"] === "true" ? true : false; 0190 } 0191 else { 0192 background.locale = Core.resolveLocale(background.locale) 0193 } 0194 } else if (activity.activityName === "smallnumbers2") { 0195 if(activityData && activityData["mode"]) { 0196 activity.dominoMode = activityData["mode"]; 0197 } 0198 } 0199 if(activityData && activityData["speedSetting"]) { 0200 activity.speedSetting = activityData["speedSetting"]; 0201 } 0202 } 0203 onStartActivity: { 0204 background.stop() 0205 background.start() 0206 } 0207 } 0208 0209 DialogHelp { 0210 id: dialogHelp 0211 onClose: home() 0212 } 0213 0214 Bar { 0215 id: bar 0216 level: items.currentLevel + 1 0217 anchors.bottom: keyboard.top 0218 content: BarEnumContent { value: help | home | level | activityConfig } 0219 onHelpClicked: { 0220 displayDialog(dialogHelp) 0221 } 0222 onPreviousLevelClicked: Activity.previousLevel() 0223 onNextLevelClicked: Activity.nextLevel() 0224 onHomeClicked: activity.home() 0225 onActivityConfigClicked: { 0226 displayDialog(dialogActivityConfig) 0227 } 0228 } 0229 0230 Bonus { 0231 id: bonus 0232 interval: 2000 0233 Component.onCompleted: win.connect(Activity.nextLevel) 0234 } 0235 0236 Score { 0237 id: score 0238 anchors.right: parent.right 0239 anchors.rightMargin: 10 * ApplicationInfo.ratio 0240 anchors.bottom: bar.top 0241 } 0242 0243 Connections { 0244 target: audioVoices 0245 onDone: { 0246 // If we have won, we wait until the last voice has played to play the bonus 0247 if(items.inputLocked && !bonus.isPlaying) { 0248 items.bonus.good("lion"); 0249 } 0250 } 0251 } 0252 VirtualKeyboard { 0253 id: keyboard 0254 anchors.bottom: parent.bottom 0255 anchors.horizontalCenter: parent.horizontalCenter 0256 width: parent.width 0257 onKeypress: Activity.processKeyPress(text) 0258 onError: console.log("VirtualKeyboard error: " + msg); 0259 } 0260 0261 Wordlist { 0262 id: wordlist 0263 defaultFilename: activity.dataSetUrl + "default-en.json" 0264 // To switch between locales: xx_XX stored in configuration and 0265 // possibly correct xx if available (ie fr_FR for french but dataset is fr.) 0266 useDefault: false 0267 filename: "" 0268 0269 onError: console.log("Gletters: Wordlist error: " + msg); 0270 } 0271 0272 Timer { 0273 id: wordDropTimer 0274 repeat: false 0275 onTriggered: Activity.dropWord(); 0276 } 0277 } 0278 }