Warning, /education/gcompris/src/activities/binary_bulb/BinaryBulb.qml is written in an unsupported language. File is not indexed.

0001 /* GCompris - BinaryBulb.qml
0002  *
0003  * SPDX-FileCopyrightText: 2018 Rajat Asthana <rajatasthana4@gmail.com>
0004  *
0005  * Authors:
0006  *   RAJAT ASTHANA <rajatasthana4@gmail.com>
0007  *
0008  *   SPDX-License-Identifier: GPL-3.0-or-later
0009  */
0010 import QtQuick 2.12
0011 import GCompris 1.0
0012 
0013 import "../../core"
0014 import "binary_bulb.js" as Activity
0015 import "numbers.js" as Dataset
0016 
0017 ActivityBase {
0018     id: activity
0019 
0020     onStart: focus = true
0021     onStop: {}
0022 
0023     property var dataset: Dataset
0024 
0025     pageComponent: Image {
0026         id: background
0027         anchors.fill: parent
0028         source: "../digital_electricity/resource/texture01.webp"
0029         fillMode: Image.Tile
0030         signal start
0031         signal stop
0032 
0033         Component.onCompleted: {
0034             activity.start.connect(start)
0035             activity.stop.connect(stop)
0036         }
0037 
0038         // Add here the QML items you need to access in javascript
0039         QtObject {
0040             id: items
0041             property Item main: activity.main
0042             property alias background: background
0043             property int currentLevel: activity.currentLevel
0044             property alias bonus: bonus
0045             property alias bulbs: bulbs
0046             property int numberSoFar: 0
0047             property int numberToConvert: 0
0048             property int numberOfBulbs: 0
0049             property int currentSelectedBulb: -1
0050             property alias score: score
0051             property alias errorRectangle: errorRectangle
0052             property GCSfx audioEffects: activity.audioEffects
0053             property bool buttonsBlocked: false
0054         }
0055 
0056         onStart: { Activity.start(items, dataset) }
0057         onStop: { Activity.stop() }
0058 
0059         // Tutorial section starts
0060         Image {
0061             id: tutorialImage
0062             source: "../digital_electricity/resource/texture01.webp"
0063             anchors.fill: parent
0064             fillMode: Image.Tile
0065             z: 5
0066             visible: true
0067             Tutorial {
0068                 id: tutorialSection
0069                 tutorialDetails: Activity.tutorialInstructions
0070                 useImage: false
0071                 onSkipPressed: {
0072                     Activity.initLevel()
0073                     tutorialImage.visible = false
0074                 }
0075             }
0076         }
0077         // Tutorial section ends
0078 
0079         // Needed to get keyboard focus on Tutorial
0080         Keys.forwardTo: tutorialSection
0081 
0082         Keys.onPressed: {
0083             if(items.buttonsBlocked)
0084                 return
0085             if(event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
0086                 Activity.equalityCheck()
0087             }
0088             else if(event.key === Qt.Key_Space) {
0089                 if(items.currentSelectedBulb != -1) {
0090                     Activity.changeState(items.currentSelectedBulb)
0091                 }
0092             }
0093             else if(event.key === Qt.Key_Left) {
0094                 if(--items.currentSelectedBulb < 0) {
0095                     items.currentSelectedBulb = items.numberOfBulbs-1
0096                 }
0097             }
0098             else if(event.key === Qt.Key_Right) {
0099                 if(++items.currentSelectedBulb >= items.numberOfBulbs) {
0100                     items.currentSelectedBulb = 0
0101                 }
0102             }
0103         }
0104 
0105         Rectangle {
0106             id: questionItemBackground
0107             opacity: 0
0108             z: 10
0109             anchors {
0110                 horizontalCenter: parent.horizontalCenter
0111                 bottomMargin: 10
0112             }
0113             height: background.height / 6
0114             width: parent.width - 20 * ApplicationInfo.ratio
0115         }
0116 
0117         GCText {
0118             id: questionItem
0119             anchors.fill: questionItemBackground
0120             anchors.bottom: questionItemBackground.bottom
0121             fontSizeMode: Text.Fit
0122             wrapMode: Text.Wrap
0123             z: 4
0124             color: "white"
0125             verticalAlignment: Text.AlignVCenter
0126             horizontalAlignment: Text.AlignHCenter
0127             text: qsTr("What is the binary representation of %1?").arg(items.numberToConvert)
0128         }
0129 
0130         Row {
0131             id: bulbsRow
0132             anchors.top: questionItem.bottom
0133             anchors.topMargin: 30 * ApplicationInfo.ratio
0134             anchors.horizontalCenter: parent.horizontalCenter
0135             spacing: 10 * ApplicationInfo.ratio
0136             Repeater {
0137                 id: bulbs
0138                 model: items.numberOfBulbs
0139                 LightBulb {
0140                     height: background.height / 5
0141                     width: (background.width >= background.height) ? (background.width / 20) : ((background.width - (16 * bulbsRow.spacing)) / 8)
0142                     valueVisible: Dataset.get()[items.currentLevel].bulbValueVisible
0143                 }
0144             }
0145         }
0146 
0147         ErrorRectangle {
0148             id: errorRectangle
0149             anchors.fill: bulbsRow
0150             z: score.z
0151             imageSize: okButton.sourceSize.width
0152             function releaseControls() { items.buttonsBlocked = false; }
0153         }
0154 
0155         GCText {
0156             id: reachedSoFar
0157             anchors.horizontalCenter: bulbsRow.horizontalCenter
0158             anchors.top: bulbsRow.bottom
0159             anchors.topMargin: 30 * ApplicationInfo.ratio
0160             color: "white"
0161             fontSize: largeSize
0162             text: items.numberSoFar
0163             visible: Dataset.get()[items.currentLevel].enableHelp
0164         }
0165 
0166         BarButton {
0167             id: okButton
0168             anchors {
0169                 bottom: bar.top
0170                 right: parent.right
0171                 rightMargin: 10 * ApplicationInfo.ratio
0172                 bottomMargin: 10 * ApplicationInfo.ratio
0173             }
0174             source: "qrc:/gcompris/src/core/resource/bar_ok.svg"
0175             sourceSize.width: 60 * ApplicationInfo.ratio
0176             onClicked: Activity.equalityCheck()
0177             enabled: !items.buttonsBlocked
0178         }
0179 
0180         DialogHelp {
0181             id: dialogHelp
0182             onClose: home()
0183         }
0184 
0185         Bar {
0186             id: bar
0187             level: items.currentLevel + 1
0188             content: BarEnumContent { value: tutorialImage.visible ? (help | home) : (help | home | level) }
0189             onHelpClicked: {
0190                 displayDialog(dialogHelp)
0191             }
0192             onPreviousLevelClicked: Activity.previousLevel()
0193             onNextLevelClicked: Activity.nextLevel()
0194             onHomeClicked: home()
0195         }
0196 
0197         Score {
0198             id: score
0199             visible: !tutorialImage.visible
0200             anchors.bottom: bar.top
0201             anchors.right: bar.right
0202             anchors.left: parent.left
0203             anchors.bottomMargin: 10 * ApplicationInfo.ratio
0204             anchors.leftMargin: 10 * ApplicationInfo.ratio
0205             anchors.rightMargin: 0
0206             onStop: Activity.nextSubLevel()
0207         }
0208 
0209         Bonus {
0210             id: bonus
0211             Component.onCompleted: win.connect(Activity.nextLevel)
0212         }
0213     }
0214 }