Warning, /education/gcompris/src/activities/comparator/Comparator.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - Comparator.qml 0002 * 0003 * SPDX-FileCopyrightText: 2022 Aastha Chauhan <aastha.chauhan01@gmail.com> 0004 * 0005 * Authors: 0006 * Aastha Chauhan <aastha.chauhan01@gmail.com> 0007 * Timothée Giet <animtim@gmail.com> 0008 * SPDX-License-Identifier: GPL-3.0-or-later 0009 */ 0010 import QtQuick 2.12 0011 import GCompris 1.0 0012 import QtQml.Models 2.12 0013 import QtQuick.Controls 2.12 0014 0015 import "../../core" 0016 import "comparator.js" as Activity 0017 0018 ActivityBase { 0019 id: activity 0020 0021 onStart: focus = true 0022 onStop: {} 0023 0024 pageComponent: Image { 0025 id: background 0026 source: "qrc:/gcompris/src/activities/chess/resource/background-wood.svg" 0027 anchors.centerIn: parent 0028 anchors.fill: parent 0029 fillMode: Image.PreserveAspectCrop 0030 sourceSize.height: height 0031 signal start 0032 signal stop 0033 property int layoutMargins: ApplicationInfo.ratio * 10 0034 0035 Component.onCompleted: { 0036 activity.start.connect(start) 0037 activity.stop.connect(stop) 0038 } 0039 0040 function resetSelectedButton() { 0041 symbolSelectionList.currentIndex = -1; 0042 } 0043 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 GCSfx audioEffects: activity.audioEffects 0051 readonly property var levels: activity.datasetLoader.data 0052 property alias dataListModel: dataListModel 0053 property int selectedLine: -1 0054 property int spacingOfElement: 20 * ApplicationInfo.ratio 0055 property int sizeOfElement: 36 * ApplicationInfo.ratio 0056 property int numberOfRowsCompleted: 0 0057 property alias score: score 0058 property bool horizontalLayout: layoutArea.width >= layoutArea.height 0059 property bool buttonsBlocked: false 0060 } 0061 0062 onStart: { Activity.start(items) } 0063 onStop: { Activity.stop() } 0064 0065 Item { 0066 id: layoutArea 0067 anchors { 0068 top: parent.top 0069 left: parent.left 0070 right: parent.right 0071 bottom: bar.top 0072 bottomMargin: bar.height * 0.5 0073 } 0074 } 0075 0076 ListModel { 0077 id: dataListModel 0078 } 0079 0080 Keys.enabled: !bonus.isPlaying 0081 Keys.onPressed: { 0082 if(items.buttonsBlocked) 0083 return; 0084 switch(event.key) { 0085 case Qt.Key_Less: 0086 event.accepted = true; 0087 symbolSelectionList.enterSign("<"); 0088 break; 0089 case Qt.Key_Equal: 0090 event.accepted = true; 0091 symbolSelectionList.enterSign("="); 0092 break; 0093 case Qt.Key_Greater: 0094 event.accepted = true; 0095 symbolSelectionList.enterSign(">"); 0096 break; 0097 case Qt.Key_Up: 0098 event.accepted = true; 0099 Activity.upAction(); 0100 break; 0101 case Qt.Key_Down: 0102 event.accepted = true; 0103 Activity.downAction(); 0104 break; 0105 case Qt.Key_Left: 0106 event.accepted = true; 0107 symbolSelectionList.decrementCurrentIndex(); 0108 break; 0109 case Qt.Key_Right: 0110 event.accepted = true; 0111 symbolSelectionList.incrementCurrentIndex(); 0112 break; 0113 case Qt.Key_Space: 0114 event.accepted = true; 0115 if(symbolSelectionList.currentItem) { 0116 symbolSelectionList.currentItem.clicked(); 0117 } 0118 break; 0119 case Qt.Key_Return: 0120 case Qt.Key_Enter: 0121 event.accepted = true; 0122 if(okButton.visible) { 0123 okButton.clicked(); 0124 } 0125 break; 0126 case Qt.Key_Backspace: 0127 event.accepted = true; 0128 var equation = dataListModel.get(items.selectedLine); 0129 if(equation.symbol != "") { 0130 equation.symbol = ""; 0131 items.numberOfRowsCompleted --; 0132 equation.isValidationImageVisible = false; 0133 } 0134 break; 0135 } 0136 } 0137 0138 Rectangle { 0139 id: wholeExerciceDisplay 0140 // width defined in states 0141 height: items.sizeOfElement * lineRepeater.count 0142 anchors.horizontalCenter: layoutArea.horizontalCenter 0143 anchors.verticalCenter: layoutArea.verticalCenter 0144 anchors.verticalCenterOffset: -symbolSelectionList.height 0145 color: "#F2F2F2" 0146 Column { 0147 id: wholeExerciceDisplayContent 0148 spacing: 0 0149 anchors.horizontalCenter: parent.horizontalCenter 0150 anchors.verticalCenter: parent.verticalCenter 0151 width: parent.width 0152 height: parent.height 0153 Repeater { 0154 id: lineRepeater 0155 model: dataListModel 0156 delegate: ComparatorLine { 0157 } 0158 } 0159 } 0160 } 0161 0162 Item { 0163 id: upDownButtonSet 0164 anchors.verticalCenter: wholeExerciceDisplay.verticalCenter 0165 anchors.right: wholeExerciceDisplay.left 0166 anchors.rightMargin: background.layoutMargins 0167 height: upButton.height * 3 0168 width: upButton.width 0169 BarButton { 0170 id: upButton 0171 source: "qrc:/gcompris/src/activities/path_encoding/resource/arrow.svg" 0172 // height defined in states 0173 width: height 0174 sourceSize.height: height * scale 0175 rotation: -90 0176 anchors.top: parent.top 0177 anchors.right: parent.right 0178 Rectangle { 0179 anchors.fill: parent 0180 radius: width * 0.5 0181 color: "#FFFFFF" 0182 border.color: "#000000" 0183 border.width: 4 0184 opacity: 0.2 0185 } 0186 onClicked: { 0187 Activity.upAction() 0188 } 0189 } 0190 BarButton { 0191 id: downButton 0192 source: "qrc:/gcompris/src/activities/path_encoding/resource/arrow.svg" 0193 height: upButton.height 0194 width: height 0195 sourceSize.height: height * scale 0196 rotation: 90 0197 anchors.bottom: parent.bottom 0198 anchors.right: parent.right 0199 Rectangle { 0200 anchors.fill: parent 0201 radius: width * 0.5 0202 color: "#FFFFFF" 0203 border.color: "#000000" 0204 border.width: 4 0205 opacity: 0.2 0206 } 0207 onClicked: { 0208 Activity.downAction() 0209 } 0210 } 0211 } 0212 0213 ListView { 0214 id: symbolSelectionList 0215 height: Math.min(wholeExerciceDisplay.width * 0.2, items.sizeOfElement * 1.5) 0216 width: height * 4 0217 anchors.top: wholeExerciceDisplay.bottom 0218 anchors.topMargin: background.layoutMargins 0219 anchors.horizontalCenter: wholeExerciceDisplay.horizontalCenter 0220 orientation: Qt.Horizontal 0221 interactive: false 0222 keyNavigationWraps: true 0223 spacing: height * 0.5 0224 currentIndex: -1 0225 model: ["<", "=", ">"] 0226 delegate: ComparatorSign { 0227 height: ListView.view.height 0228 width: height 0229 signValue: modelData 0230 isSelected: ListView.isCurrentItem 0231 } 0232 function enterSign(sign) { 0233 //increment the numberOfRowsCompleted if there was no symbol previously 0234 if(dataListModel.get(items.selectedLine).symbol === "") { 0235 items.numberOfRowsCompleted ++; 0236 } 0237 dataListModel.get(items.selectedLine).symbol = sign; 0238 dataListModel.get(items.selectedLine).isValidationImageVisible = false; 0239 } 0240 } 0241 0242 BarButton { 0243 id: okButton 0244 source: "qrc:/gcompris/src/core/resource/bar_ok.svg" 0245 visible: items.numberOfRowsCompleted == dataListModel.count 0246 sourceSize.width: 60 * ApplicationInfo.ratio 0247 enabled: !bonus.isPlaying 0248 anchors { 0249 bottom: score.top 0250 bottomMargin: background.layoutMargins 0251 horizontalCenter: score.horizontalCenter 0252 } 0253 onClicked: { 0254 Activity.checkAnswer() 0255 } 0256 } 0257 0258 DialogHelp { 0259 id: dialogHelp 0260 onClose: home() 0261 } 0262 0263 DialogChooseLevel { 0264 id: dialogActivityConfig 0265 currentActivity: activity.activityInfo 0266 0267 onSaveData: { 0268 levelFolder = dialogActivityConfig.chosenLevels 0269 currentActivity.currentLevels = dialogActivityConfig.chosenLevels 0270 ApplicationSettings.setCurrentLevels(currentActivity.name, dialogActivityConfig.chosenLevels) 0271 // restart activity on saving 0272 background.start() 0273 } 0274 onClose: { 0275 home() 0276 } 0277 onStartActivity: { 0278 background.start() 0279 } 0280 } 0281 0282 Score { 0283 id: score 0284 anchors.right: layoutArea.right 0285 anchors.bottom: layoutArea.bottom 0286 anchors.rightMargin: background.layoutMargins 0287 anchors.bottomMargin: background.layoutMargins 0288 anchors.horizontalCenterOffset: layoutArea.width * 0.375 0289 onStop: Activity.nextSubLevel() 0290 } 0291 0292 states: [ 0293 State { 0294 name: "isHorizontalLayout" 0295 when: items.horizontalLayout 0296 AnchorChanges { 0297 target: score 0298 anchors.right: undefined 0299 anchors.horizontalCenter: layoutArea.horizontalCenter 0300 } 0301 PropertyChanges { 0302 target: wholeExerciceDisplay 0303 width: layoutArea.width * 0.5 0304 anchors.horizontalCenterOffset: -items.sizeOfElement 0305 } 0306 PropertyChanges { 0307 target: upButton 0308 height: Math.max(layoutArea.height * 0.1, items.sizeOfElement) 0309 } 0310 }, 0311 State { 0312 name: "isVerticalLayout" 0313 when: !items.horizontalLayout 0314 AnchorChanges { 0315 target: score 0316 anchors.right: layoutArea.right 0317 anchors.horizontalCenter: undefined 0318 } 0319 PropertyChanges { 0320 target: wholeExerciceDisplay 0321 width: layoutArea.width * 0.7 0322 anchors.horizontalCenterOffset: 0 0323 } 0324 PropertyChanges { 0325 target: upButton 0326 height: layoutArea.width * 0.1 0327 } 0328 } 0329 ] 0330 0331 MouseArea { 0332 id: inputLock 0333 anchors.fill: layoutArea 0334 enabled: items.buttonsBlocked 0335 } 0336 0337 Bar { 0338 id: bar 0339 level: items.currentLevel + 1 0340 content: BarEnumContent { value: help | home | level | activityConfig } 0341 onHelpClicked: { 0342 displayDialog(dialogHelp) 0343 } 0344 onPreviousLevelClicked: Activity.previousLevel() 0345 onNextLevelClicked: Activity.nextLevel() 0346 onHomeClicked: activity.home() 0347 onActivityConfigClicked: { 0348 displayDialog(dialogActivityConfig) 0349 } 0350 } 0351 0352 Bonus { 0353 id: bonus 0354 Component.onCompleted: win.connect(Activity.nextLevel) 0355 } 0356 } 0357 }