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

0001 /* GCompris - AnswerArea.qml
0002 *
0003 * SPDX-FileCopyrightText: 2014 Thib ROMAIN <thibrom@gmail.com>
0004 *
0005 * Authors:
0006 *   Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version)
0007 *   Thib ROMAIN <thibrom@gmail.com> (Qt Quick port)
0008 *
0009 *   SPDX-License-Identifier: GPL-3.0-or-later
0010 */
0011 import QtQuick 2.12
0012 import GCompris 1.0
0013 import "enumerate.js" as Activity
0014 
0015 import "../../core"
0016 
0017 Rectangle {
0018     id: answerBackground
0019     width: Math.min(140 * ApplicationInfo.ratio, background.width / 4)
0020     height: width / 2
0021     radius: 10
0022     border {
0023         width: activeFocus && state === "default" ?  5 : 1
0024         color: "#373737"
0025     }
0026 
0027     states: [
0028         State {
0029             name: "badAnswer"
0030             PropertyChanges {target: answerBackground ; color: "#ea5454"} //red
0031         },
0032         State {
0033             name: "goodAnswer"
0034             PropertyChanges {target: answerBackground ; color: "#54ea54"} //green
0035         },
0036         State {
0037             name: "default"
0038             PropertyChanges {target: answerBackground ; color: activeFocus ? "#63ede5" : "#eeeeee"} //light blue, grey
0039         }
0040     ]
0041 
0042     property string imgPath
0043 
0044     // True when the value is entered correctly
0045     property bool valid: false
0046 
0047     Component.onCompleted: Activity.registerAnswerItem(answerBackground)
0048 
0049     onValidChanged: valid ? Activity.playAudio() : null
0050 
0051     // A top gradient
0052     Rectangle {
0053         anchors.fill: parent
0054         anchors.margins: parent.activeFocus ?  5 : 1
0055         radius: 10
0056         visible: answerBackground.state === "default"
0057         gradient: Gradient {
0058             GradientStop { position: 0.0; color: valid ? "#ff54ea54" : "#CCFFFFFF" }
0059             GradientStop { position: 0.5; color: valid ? "#ff54ea54" : "#80FFFFFF" }
0060             GradientStop { position: 1.0; color: valid ? "#ff54ea54" : "#00000000" }
0061         }
0062     }
0063 
0064     MouseArea {
0065         id: mouseArea
0066         anchors.fill: parent
0067         enabled: !items.buttonsBlocked
0068         onClicked: {
0069             Activity.registerAnswerItem(answerBackground)
0070             Activity.resetAnswerAreaColor();
0071         }
0072     }
0073 
0074     Image {
0075         id: img
0076         anchors {
0077             left: parent.left
0078             leftMargin: 10
0079             verticalCenter: parent.verticalCenter
0080         }
0081         height: parent.height * 0.75
0082         width: height
0083         source: imgPath
0084         fillMode: Image.PreserveAspectFit
0085     }
0086 
0087     Keys.onPressed: {
0088         if(!items.buttonsBlocked)
0089             appendText(event.text);
0090     }
0091 
0092     function appendText(text) {
0093         var number = parseInt(text)
0094         if(isNaN(number))
0095             return
0096 
0097         if(userEntry.text === "?") {
0098             userEntry.text = ""
0099         }
0100 
0101         if(Activity.lockKeyboard === false) {
0102             userEntry.text = text;
0103             Activity.resetAnswerAreaColor();
0104         }
0105         if(Activity.answersMode === 1 && Activity.lockKeyboard === false) {
0106             valid = Activity.setUserAnswer(imgPath, parseInt(userEntry.text));
0107             Activity.checkAnswersAuto();
0108         } else {
0109             Activity.setUserAnswer(imgPath, parseInt(userEntry.text));
0110             Activity.enableOkButton();
0111             }
0112     }
0113 
0114     GCText {
0115         id: userEntry
0116         anchors {
0117             left: img.right
0118             verticalCenter: img.verticalCenter
0119             leftMargin: 10
0120         }
0121         text: "?"
0122         color: "black"
0123         fontSize: 28
0124         style: Text.Outline
0125         styleColor: "white"
0126     }
0127 
0128 }