Warning, /education/gcompris/src/activities/algebra_by/Algebra.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - Algebra.qml 0002 * 0003 * SPDX-FileCopyrightText: 2014 Aruna Sankaranarayanan <aruna.evam@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-3.0-or-later 0006 */ 0007 0008 import QtQuick 2.12 0009 import GCompris 1.0 0010 0011 import "../../core" 0012 import "algebra.js" as Activity 0013 0014 ActivityBase { 0015 id: activity 0016 property int speedSetting: 5 0017 0018 onStart: { 0019 focus = true; 0020 } 0021 0022 pageComponent: Image { 0023 id: background 0024 source: "qrc:/gcompris/src/activities/algebra_by/resource/background.svg" 0025 fillMode: Image.PreserveAspectCrop 0026 sourceSize.width: width 0027 sourceSize.height: height 0028 signal start 0029 signal stop 0030 0031 Component.onCompleted: { 0032 dialogActivityConfig.initialize() 0033 activity.start.connect(start) 0034 activity.stop.connect(stop) 0035 } 0036 0037 Item { 0038 id: items 0039 property alias background: background 0040 property int currentLevel: activity.currentLevel 0041 property alias bonus: bonus 0042 property alias score: score 0043 property alias errorRectangle: errorRectangle 0044 property alias okButton: okButton 0045 property alias balloon: balloon 0046 property alias iAmReady: iAmReady 0047 property alias firstOp: firstOp 0048 property alias secondOp: secondOp 0049 property alias numpad: numpad 0050 property int result 0051 readonly property var levels: activity.datasetLoader.data 0052 property GCSfx audioEffects: activity.audioEffects 0053 property bool buttonsBlocked: false 0054 } 0055 0056 onStart: { 0057 operand.text = Activity.operandText; 0058 Activity.start(items, operand, speedSetting); 0059 } 0060 0061 onStop: Activity.stop() 0062 0063 DialogChooseLevel { 0064 id: dialogActivityConfig 0065 currentActivity: activity.activityInfo 0066 onClose: { 0067 home() 0068 } 0069 onSaveData: { 0070 levelFolder = dialogActivityConfig.chosenLevels 0071 currentActivity.currentLevels = dialogActivityConfig.chosenLevels 0072 ApplicationSettings.setCurrentLevels(currentActivity.name, dialogActivityConfig.chosenLevels) 0073 } 0074 0075 onLoadData: { 0076 if(activityData && activityData["speedSetting"]) { 0077 activity.speedSetting = activityData["speedSetting"]; 0078 } 0079 } 0080 0081 onStartActivity: { 0082 background.stop() 0083 background.start() 0084 } 0085 } 0086 0087 DialogHelp { 0088 id: dialogHelpLeftRight 0089 onClose: home() 0090 } 0091 0092 Bar { 0093 id: bar 0094 level: items.currentLevel + 1 0095 content: BarEnumContent { value: (help | home | level | activityConfig) } 0096 onHelpClicked: { 0097 displayDialog(dialogHelpLeftRight) 0098 } 0099 onPreviousLevelClicked: { 0100 Activity.previousLevel() 0101 } 0102 onNextLevelClicked: { 0103 Activity.nextLevel() 0104 } 0105 onActivityConfigClicked: { 0106 displayDialog(dialogActivityConfig) 0107 } 0108 onHomeClicked: home() 0109 } 0110 0111 BarButton { 0112 id: okButton 0113 x: parent.width * 0.7 0114 z: 10 0115 source: "qrc:/gcompris/src/core/resource/bar_ok.svg" 0116 anchors.verticalCenter: score.verticalCenter 0117 anchors.left: score.right 0118 anchors.leftMargin: 0.2 * height 0119 height: bar.height; 0120 width: height 0121 sourceSize.height: height 0122 sourceSize.width: height 0123 onClicked: Activity.checkAnswer(); 0124 enabled: visible && !items.buttonsBlocked && numpad.answer != "" 0125 } 0126 0127 Keys.onReturnPressed: validateKey(); 0128 0129 Keys.onEnterPressed: validateKey(); 0130 0131 function validateKey() { 0132 if(iAmReady.visible) { 0133 iAmReady.clicked(); 0134 } else if(okButton.enabled === true) { 0135 okButton.clicked() 0136 okButtonAnimation.start() 0137 } 0138 } 0139 0140 SequentialAnimation { 0141 id: okButtonAnimation 0142 running: false 0143 NumberAnimation { target: okButton; property: "scale"; to: 0.9; duration: 70 } 0144 NumberAnimation { target: okButton; property: "scale"; to: 1; duration: 70 } 0145 } 0146 0147 Balloon { 0148 id: balloon 0149 onTimeout: bonus.bad("smiley") 0150 } 0151 0152 Score { 0153 id: score 0154 x: parent.width * 0.25 0155 anchors.verticalCenter: parent.verticalCenter 0156 anchors.right: undefined 0157 anchors.bottom: undefined 0158 currentSubLevel: 0 0159 numberOfSubLevels: 10 0160 onStop: Activity.questionsLeft() 0161 } 0162 0163 Bonus { 0164 id: bonus 0165 Component.onCompleted: { 0166 loose.connect(Activity.run) 0167 win.connect(Activity.nextLevel) 0168 } 0169 } 0170 0171 ReadyButton { 0172 id: iAmReady 0173 onClicked: Activity.run() 0174 } 0175 0176 Flow { 0177 id: textFlow 0178 x: parent.width / 2 - width / 2 0179 y: 80 0180 width: parent.width / 2 0181 height: 100 0182 anchors.margins: 4 0183 spacing: 10 0184 0185 AlgebraText { 0186 id: firstOp 0187 visible: !iAmReady.visible 0188 } 0189 0190 AlgebraText { 0191 id: operand 0192 visible: firstOp.visible 0193 } 0194 0195 AlgebraText { 0196 id: secondOp 0197 visible: !iAmReady.visible 0198 } 0199 0200 AlgebraText { 0201 id: equals 0202 visible: firstOp.visible 0203 text: "=" 0204 } 0205 0206 AlgebraText { 0207 id: result 0208 visible: !iAmReady.visible 0209 text: numpad.answer 0210 } 0211 } 0212 0213 ErrorRectangle { 0214 id: errorRectangle 0215 anchors.top: textFlow.top 0216 anchors.bottom: okButton.top 0217 anchors.left: background.left 0218 anchors.right: background.right 0219 anchors.bottomMargin: 10 * ApplicationInfo.ratio 0220 imageSize: okButton.width 0221 function releaseControls() { 0222 Activity.run(); 0223 } 0224 } 0225 0226 NumPad { 0227 id: numpad 0228 maxDigit: ('' + items.result).length + 1 0229 enableInput: !items.buttonsBlocked 0230 } 0231 0232 Keys.onPressed: { 0233 if(!items.buttonsBlocked) 0234 numpad.updateAnswer(event.key, true); 0235 } 0236 0237 Keys.onReleased: { 0238 if(!items.buttonsBlocked) 0239 numpad.updateAnswer(event.key, false); 0240 } 0241 } 0242 }