Warning, /education/gcompris/src/activities/fractions_create/FractionsCreate.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - FractionsCreate.qml
0002 *
0003 * SPDX-FileCopyrightText: 2022 Johnny Jazeix <jazeix@gmail.com>
0004 * SPDX-FileCopyrightText: 2022 Timothée Giet <animtim@gmail.com>
0005 * SPDX-License-Identifier: GPL-3.0-or-later
0006 */
0007 import QtQuick 2.12
0008 import GCompris 1.0
0009
0010 import "../../core"
0011 import "fractions_create.js" as Activity
0012
0013 ActivityBase {
0014 id: activity
0015
0016 onStart: focus = true
0017 onStop: {}
0018
0019 property string mode: "selectPie" // or "findFraction" in fractions_find activity
0020 pageComponent: Image {
0021 id: background
0022 anchors.fill: parent
0023 source: "qrc:/gcompris/src/activities/magic-hat-minus/resource/background.svg"
0024 sourceSize.width: width
0025 sourceSize.height: height
0026 fillMode: Image.PreserveAspectCrop
0027 signal start
0028 signal stop
0029
0030 Component.onCompleted: {
0031 dialogActivityConfig.initialize()
0032 activity.start.connect(start)
0033 activity.stop.connect(stop)
0034 }
0035
0036 // Add here the QML items you need to access in javascript
0037 QtObject {
0038 id: items
0039 property Item main: activity.main
0040 property alias background: background
0041 property GCSfx audioEffects: activity.audioEffects
0042 property int currentLevel: activity.currentLevel
0043 property alias bonus: bonus
0044 property alias errorRectangle: errorRectangle
0045 property alias numberOfSubLevels: score.numberOfSubLevels
0046 property alias score: score
0047 property alias instructionText: instructionTxt.text
0048 property alias chartItem: chartDisplay
0049 property alias numeratorValue: numeratorText.value
0050 property alias denominatorValue: denominatorText.value
0051 readonly property bool horizontalLayout: background.width >= background.height
0052 readonly property string mode: activity.mode
0053 property int numeratorToFind: 0
0054 property int denominatorToFind: 0
0055 readonly property var levels: activity.datasetLoader.data
0056 property string chartType: "pie"
0057 property bool fixedNumerator: true
0058 property bool fixedDenominator: true
0059 property bool buttonsBlocked: false
0060 }
0061
0062 onStart: {
0063 Activity.start(items, activity.mode);
0064 }
0065 onStop: { Activity.stop() }
0066
0067 Keys.enabled: !items.buttonsBlocked
0068
0069 Keys.onPressed: {
0070 if([Qt.Key_Enter, Qt.Key_Return].indexOf(event.key) != -1 && items.itemIndex !== -1) {
0071 okButton.clicked();
0072 }
0073 }
0074
0075 //instruction rectangle
0076 Rectangle {
0077 id: instruction
0078 anchors.centerIn: instructionTxt
0079 width: instructionTxt.width + 20
0080 height: instructionTxt.height
0081 opacity: 0.8
0082 radius: 10
0083 border.width: 2
0084 z: 10
0085 border.color: "#DDD"
0086 color: "#373737"
0087 }
0088 //instruction for playing the game
0089 GCText {
0090 id: instructionTxt
0091 anchors {
0092 top: parent.top
0093 topMargin: 10
0094 horizontalCenter: parent.horizontalCenter
0095 }
0096 opacity: instruction.opacity
0097 z: instruction.z
0098 fontSize: regularSize
0099 color: "white"
0100 horizontalAlignment: Text.AlignHCenter
0101 width: Math.max(Math.min(parent.width * 0.9, text.length * 8), parent.width * 0.5)
0102 wrapMode: TextEdit.WordWrap
0103 }
0104
0105 Item {
0106 id: layoutArea
0107 width: parent.width - 20
0108 height: parent.height - instructionTxt.height - bar.height * 1.2 - 30
0109 anchors.top: instruction.bottom
0110 anchors.topMargin: 10
0111 anchors.horizontalCenter: parent.horizontalCenter
0112 }
0113
0114 Item {
0115 id: chartLayoutArea
0116 width: layoutArea.width - okButton.width - 10 * ApplicationInfo.ratio
0117 height: layoutArea.height
0118 anchors {
0119 top: layoutArea.top
0120 left: layoutArea.left
0121 }
0122 }
0123
0124 Item {
0125 id: rightLayoutArea
0126 width: layoutArea.width - chartLayoutArea.width
0127 height: layoutArea.height
0128 anchors.top: layoutArea.top
0129 anchors.right: layoutArea.right
0130 }
0131
0132 ChartDisplay {
0133 id: chartDisplay
0134 layoutWidth: chartLayoutArea.width
0135 layoutHeight: chartLayoutArea.height
0136 anchors.centerIn: chartLayoutArea
0137 }
0138
0139 Item {
0140 id: fractionTextDisplay
0141 width: rightLayoutArea.width
0142 anchors.top: rightLayoutArea.top
0143 anchors.bottom: okButton.top
0144 anchors.bottomMargin: 10 * ApplicationInfo.ratio
0145
0146 FractionNumber {
0147 id: numeratorText
0148 value: 0
0149 width: parent.width
0150 height: 30 * ApplicationInfo.ratio
0151 anchors.horizontalCenter: parent.horizontalCenter
0152 anchors.bottom: fractionBar.bottom
0153 anchors.bottomMargin: 10
0154 interactive: activity.mode === "findFraction" && !items.fixedNumerator
0155 onLeftClicked: {
0156 if(items.numeratorValue > 0) {
0157 items.numeratorValue --;
0158 }
0159 }
0160 onRightClicked: {
0161 items.numeratorValue ++;
0162 }
0163 }
0164 Rectangle {
0165 id: fractionBar
0166 width: parent.width
0167 height: 5
0168 anchors.horizontalCenter: parent.horizontalCenter
0169 anchors.verticalCenter: parent.verticalCenter
0170 color: "white"
0171 }
0172 FractionNumber {
0173 id: denominatorText
0174 value: 0
0175 width: parent.width
0176 height: numeratorText.height
0177 anchors.horizontalCenter: parent.horizontalCenter
0178 anchors.top: fractionBar.bottom
0179 anchors.topMargin: 10
0180 interactive: activity.mode === "findFraction" && !items.fixedDenominator
0181 onLeftClicked: {
0182 if(items.denominatorValue > 0) {
0183 items.denominatorValue --;
0184 }
0185 }
0186 onRightClicked: {
0187 items.denominatorValue ++;
0188 }
0189 }
0190 }
0191
0192 ErrorRectangle {
0193 id: errorRectangle
0194 anchors.fill: activity.mode === "findFraction" ? fractionTextDisplay : chartDisplay
0195 radius: activity.mode === "findFraction" ? 10 * ApplicationInfo.ratio : (items.chartType === "pie" ? Math.min(width, height) : 0)
0196 imageSize: okButton.width
0197 function releaseControls() {
0198 items.buttonsBlocked = false;
0199 }
0200 }
0201
0202 BarButton {
0203 id: okButton
0204 enabled: !items.buttonsBlocked
0205 anchors {
0206 bottom: score.top
0207 bottomMargin: 10 * ApplicationInfo.ratio
0208 horizontalCenter: rightLayoutArea.horizontalCenter
0209 }
0210 source: "qrc:/gcompris/src/core/resource/bar_ok.svg"
0211 sourceSize.width: 60 * ApplicationInfo.ratio
0212
0213 onClicked: {
0214 chartDisplay.checkAnswer();
0215 }
0216 }
0217
0218 Score {
0219 id: score
0220 anchors {
0221 top: undefined
0222 bottom: rightLayoutArea.bottom
0223 horizontalCenter: rightLayoutArea.horizontalCenter
0224 }
0225 onStop: {
0226 Activity.nextSubLevel();
0227 }
0228 }
0229
0230 states: [
0231 State {
0232 name: "horizontalState"
0233 when: items.horizontalLayout
0234 AnchorChanges {
0235 target: fractionTextDisplay
0236 anchors.left: chartDisplay.right
0237 }
0238 },
0239 State {
0240 name: "verticalState"
0241 when: !items.horizontalLayout
0242 AnchorChanges {
0243 target: fractionTextDisplay
0244 anchors.left: rightLayoutArea.left
0245 }
0246 }
0247 ]
0248
0249 DialogChooseLevel {
0250 id: dialogActivityConfig
0251 currentActivity: activity.activityInfo
0252
0253 onSaveData: {
0254 levelFolder = dialogActivityConfig.chosenLevels
0255 currentActivity.currentLevels = dialogActivityConfig.chosenLevels
0256 ApplicationSettings.setCurrentLevels(currentActivity.name, dialogActivityConfig.chosenLevels)
0257 }
0258 onClose: {
0259 home()
0260 }
0261 onStartActivity: {
0262 background.stop()
0263 background.start()
0264 }
0265 }
0266
0267 DialogHelp {
0268 id: dialogHelp
0269 onClose: home()
0270 }
0271
0272 Bar {
0273 id: bar
0274 level: items.currentLevel + 1
0275 content: BarEnumContent { value: help | home | level | activityConfig }
0276 onHelpClicked: {
0277 displayDialog(dialogHelp)
0278 }
0279 onActivityConfigClicked: {
0280 displayDialog(dialogActivityConfig)
0281 }
0282 onPreviousLevelClicked: Activity.previousLevel()
0283 onNextLevelClicked: Activity.nextLevel()
0284 onHomeClicked: activity.home()
0285 }
0286
0287 Bonus {
0288 id: bonus
0289 Component.onCompleted: win.connect(Activity.nextLevel)
0290 }
0291 }
0292
0293 }