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

0001 /* GCompris - baby_keyboard.qml
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 import QtQuick 2.12
0011 import GCompris 1.0
0012 
0013 import "../../core"
0014 import "baby_keyboard.js" as Activity
0015 
0016 ActivityBase {
0017     id: activity
0018 
0019     onStart: focus = true
0020     onStop: {}
0021 
0022     // When opening a dialog, it steals the focus and re set it to the activity.
0023     // We need to set it back to the textinput item in order to have key events.
0024     onFocusChanged: {
0025         if(focus) {
0026             Activity.focusTextInput()
0027         }
0028     }
0029 
0030     pageComponent: Image {
0031         id: background
0032         anchors.fill: parent
0033         source: "qrc:/gcompris/src/activities/menu/resource/background.svg"
0034         fillMode: Image.PreserveAspectCrop
0035         sourceSize.width: width
0036         sourceSize.height: height
0037 
0038         signal start
0039         signal stop
0040 
0041         property string locale: ApplicationSettings.locale
0042 
0043         Component.onCompleted: {
0044             activity.start.connect(start);
0045             activity.stop.connect(stop);
0046         }
0047 
0048         // Add here the QML items you need to access in javascript
0049         QtObject {
0050             id: items
0051             property GCAudio audioVoices: activity.audioVoices
0052             property GCSfx audioEffects: activity.audioEffects
0053             property alias typedText: typedText
0054             property alias textinput: textinput
0055             property alias locale: background.locale
0056             property alias fileId: fileId
0057         }
0058 
0059         onStart: {
0060             Activity.start(items);
0061             keyboard.populate();
0062             Activity.focusTextInput();
0063         }
0064         onStop: { Activity.stop() }
0065 
0066         Item {
0067             id: layoutArea
0068             anchors.top: background.top
0069             anchors.bottom: bar.top
0070             anchors.left: background.left
0071             anchors.right: background.right
0072 
0073             MouseArea {
0074                 anchors.fill: parent
0075                 onClicked: {
0076                     textinput.focus = false;
0077                     textinput.focus = true;
0078                     textinput.forceActiveFocus();
0079                 }
0080             }
0081         }
0082 
0083         Rectangle {
0084             id: textBG
0085             visible: typedText.text != ""
0086             color: "#80ffffff"
0087             width: typedText.contentWidth * 2
0088             height: typedText.contentHeight
0089             radius: 16
0090         }
0091 
0092         GCText {
0093             id: typedText
0094             anchors.centerIn: textBG
0095             text: ""
0096             fontSize: 54
0097             font.bold: true
0098             color: "#d2611d"
0099             style: Text.Outline
0100             styleColor: "white"
0101         }
0102 
0103         states: [
0104             State {
0105                 name: "regularKeyboard"
0106                 when: !Qt.inputMethod.visible
0107                 AnchorChanges {
0108                     target: textBG
0109                     anchors.top: undefined
0110                     anchors.horizontalCenter: layoutArea.horizontalCenter
0111                     anchors.verticalCenter: layoutArea.verticalCenter
0112                 }
0113             },
0114             State {
0115                 name: "mobileKeyboard"
0116                 when: Qt.inputMethod.visible
0117                 AnchorChanges {
0118                     target: textBG
0119                     anchors.top: layoutArea.top
0120                     anchors.horizontalCenter: layoutArea.horizontalCenter
0121                     anchors.verticalCenter: undefined
0122                 }
0123             }
0124         ]
0125 
0126         TextEdit {
0127             id: textinput
0128             focus: true
0129             visible: false
0130             inputMethodHints: Qt.ImhNoPredictiveText
0131             onTextChanged: {
0132                 if (text != "") {
0133                     Activity.processKeyPress(text);
0134                     text = "";
0135                 }
0136             }
0137         }
0138 
0139         Keys.onPressed: {
0140             Activity.playSound();
0141         }
0142 
0143         File {
0144             id: fileId
0145         }
0146 
0147         DialogHelp {
0148             id: dialogHelp
0149             onClose: home()
0150         }
0151 
0152         Bar {
0153             id: bar
0154             anchors.bottom: keyboard.top
0155             content: BarEnumContent { value: help | home }
0156             onHelpClicked: {
0157                 displayDialog(dialogHelp);
0158             }
0159             onHomeClicked: activity.home();
0160         }
0161 
0162         VirtualKeyboard {
0163             id: keyboard
0164             anchors.bottom: parent.bottom
0165             anchors.horizontalCenter: parent.horizontalCenter
0166             width: parent.width
0167             visible: ApplicationSettings.isVirtualKeyboard && !ApplicationInfo.isMobile
0168             onKeypress: {
0169                 if(text == backspace || text == newline)
0170                     Activity.playSound();
0171                 else
0172                     Activity.processKeyPress(text);
0173             }
0174             shiftKey: true
0175             onError: console.log("VirtualKeyboard error: " + msg);
0176             readonly property string newline: "\u21B2"
0177 
0178             function populate() {
0179                 layout = [
0180                 [
0181                     { label: "0" },
0182                     { label: "1" },
0183                     { label: "2" },
0184                     { label: "3" },
0185                     { label: "4" },
0186                     { label: "5" },
0187                     { label: "6" },
0188                     { label: "7" },
0189                     { label: "8" },
0190                     { label: "9" }
0191                 ],
0192                 [
0193                     { label: "A" },
0194                     { label: "B" },
0195                     { label: "C" },
0196                     { label: "D" },
0197                     { label: "E" },
0198                     { label: "F" },
0199                     { label: "G" },
0200                     { label: "H" },
0201                     { label: "I" }
0202                 ],
0203                 [
0204                     { label: "J" },
0205                     { label: "K" },
0206                     { label: "L" },
0207                     { label: "M" },
0208                     { label: "N" },
0209                     { label: "O" },
0210                     { label: "P" },
0211                     { label: "Q" },
0212                     { label: "R" }
0213                 ],
0214                 [
0215                     { label: "S" },
0216                     { label: "T" },
0217                     { label: "U" },
0218                     { label: "V" },
0219                     { label: "W" },
0220                     { label: "X" },
0221                     { label: "Y" },
0222                     { label: "Z" },
0223                     { label: " " },
0224                     { label: backspace },
0225                     { label: newline }
0226                 ]
0227             ]
0228             }
0229 
0230         }
0231     }
0232 
0233 }