Warning, /education/gcompris/src/activities/guesscount/Guesscount.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - guesscount.qml 0002 * 0003 * SPDX-FileCopyrightText: 2016 RAHUL YADAV <rahulyadav170923@gmail.com> 0004 * 0005 * Authors: 0006 * Pascal Georges <pascal.georges1@free.fr> (GTK+ version) 0007 * RAHUL YADAV <rahulyadav170923@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 "../../core" 0014 import "guesscount.js" as Activity 0015 import "dataset.js" as Data 0016 0017 ActivityBase { 0018 id: activity 0019 0020 onStart: focus = true 0021 onStop: {} 0022 property bool needRestart: true 0023 0024 pageComponent: Image { 0025 id: background 0026 anchors.fill: parent 0027 source: Activity.baseUrl + "/backgroundW01.svg" 0028 signal start 0029 signal stop 0030 Component.onCompleted: { 0031 dialogActivityConfig.initialize() 0032 activity.start.connect(start) 0033 activity.stop.connect(stop) 0034 } 0035 MouseArea { 0036 anchors.fill: parent 0037 onClicked: { 0038 if(warningDialog.visible) 0039 warningDialog.visible = false 0040 } 0041 } 0042 0043 // Add here the QML items you need to access in javascript 0044 QtObject { 0045 id: items 0046 property Item main: activity.main 0047 property alias background: background 0048 property int currentLevel: activity.currentLevel 0049 property alias bonus: bonus 0050 property alias score: score 0051 property alias operatorRow: operatorRow 0052 property alias operandRow: operandRow 0053 property var data 0054 readonly property var levels: activity.datasetLoader.data 0055 property int result: 0 0056 property alias warningDialog: warningDialog 0057 property GCSfx audioEffects: activity.audioEffects 0058 property bool clearOperations: false 0059 property bool solved: false 0060 property var levelArr: Data.defaultOperators 0061 property string mode: "builtin" 0062 property int currentlevel 0063 property var resultArr: ["", "", "", ""] 0064 } 0065 0066 onStart: if (activity.needRestart) { 0067 Activity.start(items); 0068 activity.needRestart = false; 0069 } 0070 else 0071 Activity.initLevel(); 0072 onStop: { Activity.stop() } 0073 0074 JsonParser { 0075 id: parser 0076 onError: console.error("Guesscount: Error parsing JSON: " + msg); 0077 } 0078 0079 Loader { 0080 id: admin 0081 active: false 0082 sourceComponent: Column { 0083 spacing: 10 0084 width: parent.width 0085 height: parent.height 0086 0087 Repeater { 0088 id:levels 0089 model: 8 0090 Admin { 0091 id:level 0092 level: modelData+1 0093 width: parent.width 0094 height: parent.height 0095 data: items.data 0096 } 0097 } 0098 } 0099 } 0100 0101 Item { 0102 id: top 0103 z: 10 0104 height: parent.height/10 0105 anchors { 0106 left: parent.left 0107 right: parent.right 0108 top: parent.top 0109 margins: 20 * ApplicationInfo.ratio 0110 } 0111 Score { 0112 id: score 0113 width: parent.width * 0.2 0114 height: parent.height 0115 radius: 20 0116 anchors.left: parent.left 0117 anchors.right: undefined 0118 anchors.top: undefined 0119 anchors.bottom: undefined 0120 currentSubLevel: 0 0121 onStop: Activity.nextSubLevel() 0122 0123 } 0124 Rectangle { 0125 id: guessLabel 0126 width: parent.width * 0.7 0127 height: parent.height 0128 radius: 20 0129 color: "orange" 0130 anchors { 0131 left: score.right 0132 leftMargin: 20 * ApplicationInfo.ratio 0133 } 0134 Rectangle { 0135 id: insideFill 0136 width: parent.width - anchors.margins 0137 height: parent.height - anchors.margins 0138 anchors.verticalCenter: parent.verticalCenter 0139 anchors.horizontalCenter: parent.horizontalCenter 0140 anchors.margins: parent.height/4 0141 radius: 10 0142 color: "#E8E8E8" 0143 } 0144 GCText { 0145 id: guess 0146 anchors.horizontalCenter: parent.horizontalCenter 0147 anchors.verticalCenter: parent.verticalCenter 0148 width: insideFill.width 0149 height: insideFill.height 0150 fontSizeMode: Text.Fit 0151 minimumPointSize: 7 0152 fontSize: mediumSize 0153 verticalAlignment: Text.AlignVCenter 0154 horizontalAlignment: Text.AlignHCenter 0155 text: qsTr("Guesscount: %1").arg(items.result) 0156 } 0157 } 0158 } 0159 0160 Column { 0161 id: col 0162 spacing: 10 0163 anchors.top: top.bottom 0164 anchors.topMargin: 20 0165 anchors.left: parent.left 0166 anchors.leftMargin: 5 0167 width: parent.width 0168 height: parent.height-top.height-background.height/5 0169 OperatorRow { 0170 id: operatorRow 0171 width: parent.width 0172 height: parent.height/7 0173 mode: items.mode 0174 } 0175 OperandRow { 0176 id: operandRow 0177 width: parent.width 0178 height: parent.height/7 0179 } 0180 Repeater { 0181 id: repeat 0182 model: operatorRow.repeater.model.length 0183 delegate: OperationRow { 0184 id: operationRow 0185 width: col.width 0186 height: col.height/7 0187 property alias operationRow: operationRow 0188 noOfRows: operatorRow.repeater.model.length 0189 rowNo: modelData 0190 guesscount: items.result 0191 prevText: index != 0 ? items.resultArr[index - 1] : "" 0192 prevComplete: prevText != "" ? true : false 0193 reparent: items.clearOperations 0194 // This workaround is needed to fix a bug caused by the repeater creating instances from 0195 // the last item to the first one but only the very first time it is loaded, so we can't 0196 // safely bind values to repeat.itemAt(index-1).property. Using an intermediate array is 0197 // the only solution I found. Also changes directly inside the array aren't detected by 0198 // the binding, so it needs to be copied to and from another temporary array. 0199 onTextChanged: { 0200 var tmpResultArr = items.resultArr 0201 tmpResultArr[index] = text 0202 items.resultArr = tmpResultArr 0203 } 0204 } 0205 } 0206 } 0207 0208 DialogHelp { 0209 id: dialogHelp 0210 onClose: home() 0211 } 0212 0213 DialogChooseLevel { 0214 id: dialogActivityConfig 0215 currentActivity: activity.activityInfo 0216 onSaveData: { 0217 levelFolder = dialogActivityConfig.chosenLevels 0218 currentActivity.currentLevels = dialogActivityConfig.chosenLevels 0219 ApplicationSettings.setCurrentLevels(currentActivity.name, dialogActivityConfig.chosenLevels) 0220 activity.needRestart = true 0221 } 0222 onClose: { 0223 if(Activity.configDone(items.levelArr)){ 0224 Activity.initLevel() 0225 home() 0226 } 0227 } 0228 onLoadData: { 0229 if(activityData && activityData["mode"]) { 0230 items.mode = activityData["mode"] 0231 if(activityData["levelArr"] === undefined) { 0232 items.levelArr = activityData["levelArr"] 0233 0234 } 0235 if(activityData["levelArr"]) { 0236 items.levelArr = activityData["levelArr"] 0237 } 0238 } 0239 else { 0240 items.mode = "builtin" 0241 items.levelArr = Activity.defaultOperators 0242 } 0243 } 0244 onStartActivity: { 0245 background.stop() 0246 background.start() 0247 } 0248 } 0249 0250 Bar { 0251 id: bar 0252 level: items.currentLevel + 1 0253 content: BarEnumContent { value: help | home | level | activityConfig } 0254 onHelpClicked: { 0255 displayDialog(dialogHelp) 0256 } 0257 onPreviousLevelClicked: { 0258 Activity.previousLevel() 0259 } 0260 onNextLevelClicked: { 0261 Activity.nextLevel() 0262 } 0263 onActivityConfigClicked: { 0264 displayDialog(dialogActivityConfig) 0265 } 0266 onHomeClicked: activity.home() 0267 } 0268 0269 Bonus { 0270 id: bonus 0271 Component.onCompleted: win.connect(Activity.nextLevel) 0272 } 0273 0274 Rectangle { 0275 id: warningDialog 0276 width: parent.width*0.49 0277 height: parent.height/6 0278 visible: false 0279 color: "#373737" 0280 radius: 30 0281 property alias dialogText: dialogText 0282 anchors.centerIn: parent 0283 GCText { 0284 id: dialogText 0285 anchors.centerIn: parent 0286 anchors { 0287 centerIn: warningDialog 0288 } 0289 opacity: warningDialog.opacity 0290 z: warningDialog.z 0291 fontSize: background.vert ? regularSize : smallSize 0292 color: "white" 0293 horizontalAlignment: Text.AlignHCenter 0294 width: parent.width 0295 wrapMode: TextEdit.WordWrap 0296 } 0297 states: [ 0298 State { 0299 when: warningDialog.visible 0300 PropertyChanges { 0301 target: top 0302 opacity: 0.5 0303 } 0304 PropertyChanges { 0305 target: col 0306 opacity: 0.5 0307 } 0308 }, 0309 State { 0310 when: !warningDialog.visible 0311 PropertyChanges { 0312 target: top 0313 opacity: 1 0314 } 0315 PropertyChanges { 0316 target: col 0317 opacity: 1 0318 } 0319 } 0320 ] 0321 } 0322 } 0323 }