Warning, /education/gcompris/src/activities/money/MoneyCore.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - MoneyCore.qml 0002 * 0003 * SPDX-FileCopyrightText: 2014 Bruno Coudoin <bruno.coudoin@gcompris.net> 0004 * 0005 * Authors: 0006 * Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version) 0007 * Bruno Coudoin <bruno.coudoin@gcompris.net> (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 0014 import "../../core" 0015 import "money.js" as Activity 0016 import "qrc:/gcompris/src/core/core.js" as Core 0017 0018 ActivityBase { 0019 id: activity 0020 0021 onStart: focus = true 0022 onStop: {} 0023 0024 property var dataset 0025 0026 pageComponent: Image { 0027 id: background 0028 anchors.fill: parent 0029 source: "qrc:/gcompris/src/activities/family/resource/background.svg" 0030 width: parent.width 0031 height: parent.height 0032 sourceSize.width: width 0033 sourceSize.height: height 0034 fillMode: Image.PreserveAspectCrop 0035 signal start 0036 signal stop 0037 0038 Component.onCompleted: { 0039 dialogActivityConfig.initialize() 0040 activity.start.connect(start) 0041 activity.stop.connect(stop) 0042 } 0043 0044 // Add here the QML items you need to access in javascript 0045 QtObject { 0046 id: items 0047 property Item main: activity.main 0048 property alias background: background 0049 property GCSfx audioEffects: activity.audioEffects 0050 property alias answerModel: answerArea.pocketModel 0051 property alias pocketModel: pocketArea.pocketModel 0052 property alias store: store 0053 property alias instructions: instructions 0054 property alias tux: tux 0055 readonly property var levels: activity.datasetLoader.data 0056 property alias tuxMoney: tuxMoney 0057 property int currentLevel: activity.currentLevel 0058 property alias bonus: bonus 0059 property int itemIndex 0060 property int moneyCount 0061 property var selectedArea 0062 property alias pocket: pocketArea.answer 0063 property alias answer: answerArea.answer 0064 } 0065 0066 onStart: { Activity.start(items, dataset) } 0067 onStop: { Activity.stop() } 0068 0069 Column { 0070 id: columnLayout 0071 spacing: 10 0072 x: parent.width * 0.05 0073 y: parent.height * 0.05 0074 width: parent.width * 0.9 0075 0076 // === The Answer Area === 0077 MoneyArea { 0078 id: answerArea 0079 onTransaction: Activity.unpay(index) 0080 } 0081 0082 // === The Store Area === 0083 property int nbStoreColumns: activity.dataset === "BACK_WITHOUT_CENTS" || 0084 activity.dataset === "BACK_WITH_CENTS" ? store.model.length + 1 : store.model.length 0085 //tempSpace is a workaround to replace instructionsArea.realHeight that is freezing with Qt-5.9.1 0086 property int tempSpace: bar.level === 1 ? 140 + columnLayout.spacing : 0 0087 property int storeHeight: Math.min(1000, ((parent.height * 0.95 - columnLayout.spacing * 3 - bar.height * 1.5) - tempSpace) / 3) 0088 property int itemStoreSize: Core.fitItems(columnLayout.width - 20, storeHeight - 20 , nbStoreColumns) - 20 0089 0090 property int itemSize: Math.min(Core.fitItems(columnLayout.width - 10, storeHeight - 10, items.moneyCount) - 5, storeHeight * 0.5) 0091 0092 Rectangle { 0093 id: storeArea 0094 height: columnLayout.storeHeight 0095 width: columnLayout.width 0096 color: "#55333333" 0097 border.color: "black" 0098 border.width: 2 0099 radius: 5 0100 Flow { 0101 id: storeAreaFlow 0102 anchors.topMargin: 10 0103 anchors.bottomMargin: 10 0104 anchors.leftMargin: 10 0105 anchors.rightMargin: 10 0106 anchors.fill: parent 0107 spacing: 20 0108 0109 add: Transition { 0110 NumberAnimation { 0111 properties: "x" 0112 from: parent.width * 0.05 0113 duration: 300 0114 } 0115 } 0116 0117 Image { 0118 id: tux 0119 visible: activity.dataset === "BACK_WITHOUT_CENTS" || 0120 activity.dataset === "BACK_WITH_CENTS" 0121 source: "qrc:/gcompris/src/activities/mosaic/resource/tux.svg" 0122 sourceSize.height: columnLayout.itemStoreSize 0123 sourceSize.width: columnLayout.itemStoreSize 0124 0125 Repeater { 0126 id: tuxMoney 0127 Image { 0128 source: modelData.img 0129 sourceSize.height: columnLayout.itemStoreSize * 0.3 0130 x: tux.x + index * 50 0131 y: tux.y + tux.height / 2 + index * 20 0132 } 0133 } 0134 } 0135 0136 Repeater { 0137 id: store 0138 Image { 0139 source: modelData.img 0140 sourceSize.height: columnLayout.itemStoreSize 0141 sourceSize.width: columnLayout.itemStoreSize 0142 GCText { 0143 text: modelData.price 0144 height: parent.height 0145 width: parent.width 0146 fontSizeMode: Text.Fit 0147 font.weight: Font.DemiBold 0148 style: Text.Outline 0149 styleColor: "black" 0150 color: "white" 0151 anchors.horizontalCenter: parent.horizontalCenter 0152 anchors.top: parent.top 0153 anchors.topMargin: index % 2 == 0 ? 0 : parent.height - height 0154 } 0155 } 0156 } 0157 } 0158 } 0159 0160 // == The instructions Area == 0161 Rectangle { 0162 id: instructionsArea 0163 height: instructions.height 0164 width: columnLayout.width 0165 color: "#55333333" 0166 border.color: "black" 0167 border.width: 2 0168 radius: 5 0169 anchors.topMargin: 4 0170 anchors.bottomMargin: 4 0171 anchors.leftMargin: 10 0172 anchors.rightMargin: 10 0173 visible: bar.level === 1 0174 0175 property int realHeight: bar.level === 1 ? height + columnLayout.spacing : 0 0176 0177 GCText { 0178 id: instructions 0179 horizontalAlignment: Text.AlignHCenter 0180 width: columnLayout.width 0181 height: columnLayout.height / 6 0182 wrapMode: Text.WordWrap 0183 fontSizeMode: Text.Fit 0184 } 0185 } 0186 0187 // === The Pocket Area === 0188 MoneyArea { 0189 id: pocketArea 0190 onTransaction: Activity.pay(index) 0191 } 0192 } 0193 0194 Keys.enabled: !bonus.isPlaying 0195 0196 Keys.onPressed: { 0197 if(event.key === Qt.Key_Tab) { 0198 if(items.selectedArea.count !== 0 && items.itemIndex !== -1) 0199 items.selectedArea.itemAt(items.itemIndex).selected = false 0200 0201 if(items.selectedArea == items.pocket) { 0202 items.selectedArea = items.answer 0203 } 0204 else { 0205 items.selectedArea = items.pocket 0206 } 0207 items.itemIndex = 0 0208 } 0209 0210 if(items.selectedArea.count !== 0) { 0211 if(items.itemIndex >= 0) 0212 items.selectedArea.itemAt(items.itemIndex).selected = false 0213 0214 if(event.key === Qt.Key_Right) { 0215 if(items.itemIndex != (items.selectedArea.count-1)) 0216 items.itemIndex++ 0217 else 0218 items.itemIndex = 0 0219 } 0220 if(event.key === Qt.Key_Left) { 0221 if(items.itemIndex > 0) 0222 items.itemIndex-- 0223 else 0224 items.itemIndex = items.selectedArea.count-1 0225 } 0226 if([Qt.Key_Space, Qt.Key_Enter, Qt.Key_Return].indexOf(event.key) != -1 && items.itemIndex !== -1 ) { 0227 if(items.selectedArea == items.pocket) 0228 Activity.pay(items.itemIndex) 0229 else 0230 Activity.unpay(items.itemIndex) 0231 if(items.itemIndex > 0) 0232 items.itemIndex-- 0233 } 0234 } 0235 0236 if(items.selectedArea.count !== 0 && items.itemIndex !== -1) 0237 items.selectedArea.itemAt(items.itemIndex).selected = true 0238 } 0239 0240 DialogChooseLevel { 0241 id: dialogActivityConfig 0242 currentActivity: activity.activityInfo 0243 0244 onSaveData: { 0245 levelFolder = dialogActivityConfig.chosenLevels 0246 currentActivity.currentLevels = dialogActivityConfig.chosenLevels 0247 ApplicationSettings.setCurrentLevels(currentActivity.name, dialogActivityConfig.chosenLevels) 0248 } 0249 onClose: { 0250 home() 0251 } 0252 onStartActivity: { 0253 background.stop() 0254 background.start() 0255 } 0256 } 0257 0258 DialogHelp { 0259 id: dialogHelp 0260 onClose: home() 0261 } 0262 0263 Bar { 0264 id: bar 0265 level: items.currentLevel + 1 0266 content: BarEnumContent { value: help | home | level | activityConfig } 0267 onHelpClicked: { 0268 displayDialog(dialogHelp) 0269 } 0270 onActivityConfigClicked: { 0271 displayDialog(dialogActivityConfig) 0272 } 0273 onPreviousLevelClicked: Activity.previousLevel() 0274 onNextLevelClicked: Activity.nextLevel() 0275 onHomeClicked: activity.home() 0276 } 0277 0278 Bonus { 0279 id: bonus 0280 Component.onCompleted: win.connect(Activity.nextLevel) 0281 } 0282 } 0283 0284 }