File indexing completed on 2024-05-05 15:52:58

0001 /* GCompris - baby_keyboard.js
0002  *
0003  * SPDX-FileCopyrightText: 2020 Timothée Giet <animtim@gmail.com>
0004  *
0005  * Authors:
0006  *   Timothée Giet <animtim@gmail.com>
0007  *
0008  *   SPDX-License-Identifier: GPL-3.0-or-later
0009  */
0010 .pragma library
0011 .import QtQuick 2.12 as Quick
0012 .import GCompris 1.0 as GCompris //for ApplicationInfo
0013 .import "qrc:/gcompris/src/core/core.js" as Core
0014 
0015 var items;
0016 
0017 function start(items_) {
0018     items = items_;
0019 }
0020 
0021 function stop() {
0022     stopVoice();
0023 }
0024 
0025 function processKeyPress(text) {
0026     items.typedText.text = text.toLocaleUpperCase();
0027     playLetter(text);
0028 }
0029 
0030 function playLetter(letter) {
0031     var locale = GCompris.ApplicationInfo.getVoicesLocale(items.locale);
0032     var voiceFile = GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/"+locale+"/alphabet/"
0033                                                                        + Core.getSoundFilenamForChar(letter))
0034     stopVoice();
0035     if(items.fileId.exists(voiceFile)) {
0036         items.audioVoices.append(voiceFile);
0037     } else {
0038         items.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/bleep.wav");
0039     }
0040 }
0041 
0042 function stopVoice() {
0043     items.audioVoices.stop();
0044     items.audioVoices.clearQueue();
0045 }
0046 
0047 function playSound() {
0048     stopVoice();
0049     items.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/audioclick.wav");
0050     items.typedText.text = "";
0051 }
0052 
0053 function focusTextInput() {
0054     if (items && items.textinput)
0055         items.textinput.forceActiveFocus();
0056 }