Warning, /education/gcompris/src/activities/algorithm/Algorithm.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - algorithm.qml 0002 * 0003 * SPDX-FileCopyrightText: 2014 Bharath M S <brat.197@gmail.com> 0004 * 0005 * Authors: 0006 * Christof Petig and Ingo Konrad (GTK+ version) 0007 * Bharath M S <brat.197@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 "algorithm.js" as Activity 0015 0016 ActivityBase { 0017 id: activity 0018 0019 onStart: focus = true 0020 onStop: {} 0021 0022 pageComponent: Image { 0023 id: background 0024 anchors.fill: parent 0025 source: Activity.url + "desert_scene.svg" 0026 sourceSize.width: parent.width 0027 signal start 0028 signal stop 0029 0030 Component.onCompleted: { 0031 activity.start.connect(start) 0032 activity.stop.connect(stop) 0033 } 0034 0035 // Add here the QML items you need to access in javascript 0036 QtObject { 0037 id: items 0038 property Item main: activity.main 0039 property alias questionTray: questionTray 0040 property alias answerTray: answerTray 0041 property alias choiceTray: choiceTray 0042 property alias question: question 0043 property alias answer: answer 0044 property GCSfx audioEffects: activity.audioEffects 0045 property alias background: background 0046 property int currentLevel: activity.currentLevel 0047 property alias bonus: bonus 0048 property alias score: score 0049 property int nbSubLevel: 3 0050 property int currentSubLevel: 0 0051 property bool blockClicks: false 0052 } 0053 0054 onStart: { Activity.start(items) } 0055 onStop: { Activity.stop() } 0056 0057 property bool keyNavigationVisible: false 0058 0059 Keys.enabled: !items.blockClicks 0060 Keys.onPressed: { 0061 keyNavigationVisible = true 0062 if(event.key === Qt.Key_Left) 0063 choiceGridView.moveCurrentIndexLeft() 0064 if(event.key === Qt.Key_Right) 0065 choiceGridView.moveCurrentIndexRight() 0066 if(event.key === Qt.Key_Space || event.key === Qt.Key_Enter || event.key === Qt.Key_Return) 0067 choiceGridView.currentItem.clicked() 0068 } 0069 0070 Column { 0071 id: column 0072 spacing: 10 0073 y: parent.height * 0.05 0074 width: itemWidth * Activity.images.length 0075 anchors.horizontalCenter: parent.horizontalCenter 0076 0077 property int itemWidth: Math.min(background.width * 0.75 / Activity.images.length, background.height * 0.19) 0078 0079 Rectangle { 0080 id: questionTray 0081 height: column.itemWidth 0082 width: parent.width 0083 color: "#55333333" 0084 radius: 5 0085 0086 Row { 0087 anchors.topMargin: 4 0088 anchors.bottomMargin: 4 0089 anchors.leftMargin: 5 0090 anchors.fill: parent 0091 spacing: 5.7 * ApplicationInfo.ratio 0092 Repeater { 0093 id: question 0094 // workaround for https://bugreports.qt.io/browse/QTBUG-72643 (qml binding with global variable in Repeater do not work) 0095 property alias itemWidth: column.itemWidth 0096 Image { 0097 source: Activity.url + modelData + '.svg' 0098 sourceSize.height: height 0099 sourceSize.width: width 0100 width: question.itemWidth - 6 * ApplicationInfo.ratio 0101 height: width 0102 fillMode: Image.PreserveAspectFit 0103 } 0104 } 0105 } 0106 } 0107 0108 Rectangle { 0109 id: answerTray 0110 height: column.itemWidth 0111 width: parent.width 0112 color: "#55333333" 0113 radius: 5 0114 Row { 0115 anchors.topMargin: 4 0116 anchors.bottomMargin: 4 0117 anchors.leftMargin: 5 0118 anchors.fill: parent 0119 spacing: 5.7 * ApplicationInfo.ratio 0120 Repeater { 0121 id: answer 0122 Image { 0123 source: "qrc:/gcompris/src/activities/algorithm/resource/" + 0124 modelData + '.svg' 0125 sourceSize.height: height 0126 sourceSize.width: width 0127 width: question.itemWidth - 6 * ApplicationInfo.ratio 0128 height: width 0129 fillMode: Image.PreserveAspectFit 0130 } 0131 } 0132 } 0133 } 0134 0135 // A spacer 0136 Item { 0137 height: column.itemWidth / 2 0138 width: parent.width 0139 } 0140 0141 Rectangle { 0142 id: choiceTray 0143 height: column.itemWidth + 3 * ApplicationInfo.ratio 0144 width: parent.width 0145 color: "#55333333" 0146 radius: 5 0147 0148 GridView { 0149 id: choiceGridView 0150 anchors.fill: parent 0151 model: Activity.images 0152 cellWidth: column.itemWidth 0153 cellHeight: cellWidth 0154 interactive: false 0155 keyNavigationWraps: true 0156 highlightFollowsCurrentItem: true 0157 highlight: Rectangle { 0158 width: parent.cellWidth 0159 height: parent.cellHeight 0160 color: "#AAFFFFFF" 0161 border.width: 2 0162 border.color: "white" 0163 visible: background.keyNavigationVisible 0164 Behavior on x { SpringAnimation { spring: 2; damping: 0.2 } } 0165 Behavior on y { SpringAnimation { spring: 2; damping: 0.2 } } 0166 } 0167 0168 delegate: Item { 0169 id: cellItem 0170 width: choiceGridView.cellWidth 0171 height: choiceTray.height 0172 0173 signal clicked 0174 onClicked: { 0175 if(Activity.clickHandler(modelData)) { 0176 particle.burst(20) 0177 } 0178 } 0179 0180 Image { 0181 id: img 0182 source: Activity.url + modelData + '.svg' 0183 width: question.itemWidth - 6 * ApplicationInfo.ratio 0184 height: width 0185 sourceSize.width: width 0186 sourceSize.height: height 0187 anchors.centerIn: parent 0188 fillMode: Image.PreserveAspectFit 0189 state: "notclicked" 0190 0191 MouseArea { 0192 id: mouseArea 0193 hoverEnabled: enabled 0194 enabled: !items.blockClicks 0195 anchors.fill: parent 0196 onClicked: cellItem.clicked() 0197 } 0198 states: [ 0199 State { 0200 name: "notclicked" 0201 PropertyChanges { 0202 target: img 0203 scale: 1.0 0204 } 0205 }, 0206 State { 0207 name: "clicked" 0208 when: mouseArea.pressed 0209 PropertyChanges { 0210 target: img 0211 scale: 0.9 0212 } 0213 }, 0214 State { 0215 name: "hover" 0216 when: mouseArea.containsMouse 0217 PropertyChanges { 0218 target: img 0219 scale: 1.1 0220 } 0221 } 0222 ] 0223 0224 Behavior on scale { NumberAnimation { duration: 70 } } 0225 0226 ParticleSystemStarLoader { 0227 id: particle 0228 clip: false 0229 } 0230 } 0231 } 0232 } 0233 } 0234 } 0235 0236 DialogHelp { 0237 id: dialogHelp 0238 onClose: home() 0239 } 0240 0241 Bar { 0242 id: bar 0243 level: items.currentLevel + 1 0244 content: BarEnumContent { value: help | home | level } 0245 onHelpClicked: { 0246 displayDialog(dialogHelp) 0247 } 0248 onPreviousLevelClicked: Activity.previousLevel() 0249 onNextLevelClicked: Activity.nextLevel() 0250 onHomeClicked: activity.home() 0251 } 0252 0253 Bonus { 0254 id: bonus 0255 Component.onCompleted: win.connect(Activity.nextLevel) 0256 } 0257 0258 Score { 0259 id: score 0260 anchors { 0261 bottom: bar.top 0262 bottomMargin: 10 * ApplicationInfo.ratio 0263 right: parent.right 0264 rightMargin: 5 * ApplicationInfo.ratio 0265 top: undefined 0266 left: undefined 0267 } 0268 numberOfSubLevels: items.nbSubLevel 0269 currentSubLevel: items.currentSubLevel 0270 onStop: Activity.nextSubLevel() 0271 } 0272 } 0273 }