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

0001 /* GCompris - tens_complement_swap.qml
0002  *
0003  * SPDX-FileCopyrightText: 2022 Samarth Raj <mailforsamarth@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 QtQml.Models 2.12
0009 import QtQuick.Controls 2.12
0010 
0011 import GCompris 1.0
0012 import "../../core"
0013 import "tens_complement_swap.js" as Activity
0014 import "qrc:/gcompris/src/core/core.js" as Core
0015 
0016 ActivityBase {
0017     id: activity
0018 
0019     onStart: focus = true
0020     onStop: {}
0021 
0022     pageComponent: Image {
0023         id: background
0024         source: "qrc:/gcompris/src/activities/chess/resource/background-wood.svg"
0025         anchors.fill: parent
0026         fillMode: Image.PreserveAspectCrop
0027         sourceSize.height: height
0028         signal start
0029         signal stop
0030 
0031         property int layoutMargins: 10 * ApplicationInfo.ratio
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 GCSfx audioEffects: activity.audioEffects
0044             property int currentLevel: activity.currentLevel
0045             property alias bonus: bonus
0046             property alias equations: equations
0047             readonly property var levels: activity.datasetLoader.data
0048             property bool isHorizontal: background.width >= background.height
0049         }
0050 
0051         onStart: { Activity.start(items) }
0052         onStop: { Activity.stop() }
0053 
0054         Keys.enabled: okButton.enabled
0055         Keys.onPressed: {
0056             if(event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
0057                 okButton.clicked();
0058             }
0059         }
0060 
0061         Item {
0062             id: layoutArea
0063             anchors.top: parent.top
0064             anchors.bottom: bar.top
0065             anchors.bottomMargin: bar.height * 0.2
0066             anchors.left: parent.left
0067             anchors.right: parent.right
0068 
0069             ListModel {
0070                 id: equations
0071             }
0072 
0073             Item {
0074                 id: containerHolder
0075                 height: layoutArea.height - okButton.height * 2 - background.layoutMargins
0076                 width: layoutArea.width - (background.layoutMargins * 2)
0077                 anchors.top: parent.top
0078                 anchors.topMargin: background.layoutMargins
0079                 anchors.horizontalCenter: parent.horizontalCenter
0080                 Column {
0081                     Repeater {
0082                         model: items.equations
0083                         delegate: CardContainer {
0084                             height: Math.min(containerHolder.height / items.equations.count,
0085                                              okButton.height * 2)
0086                             width: items.isHorizontal ? containerHolder.width - height :
0087                                                             containerHolder.width
0088                         }
0089                     }
0090                 }
0091             }
0092 
0093             Item {
0094                 id: okButtonArea
0095                 anchors.top: containerHolder.bottom
0096                 anchors.bottom: layoutArea.bottom
0097                 anchors.left: layoutArea.left
0098                 anchors.right: layoutArea.right
0099             }
0100 
0101             BarButton {
0102                 id: okButton
0103                 sourceSize.width: 60 * ApplicationInfo.ratio
0104                 source: "qrc:/gcompris/src/core/resource/bar_ok.svg"
0105                 anchors {
0106                     horizontalCenter: okButtonArea.horizontalCenter
0107                     verticalCenter: okButtonArea.verticalCenter
0108                 }
0109                 enabled: !bonus.isPlaying
0110                 onClicked: Activity.checkAnswer()
0111             }
0112 
0113         }
0114 
0115         MouseArea {
0116             id: clickMask
0117             anchors.fill: layoutArea
0118             enabled: bonus.isPlaying
0119         }
0120 
0121         DialogChooseLevel {
0122             id: dialogActivityConfig
0123             currentActivity: activity.activityInfo
0124 
0125             onSaveData: {
0126                 levelFolder = dialogActivityConfig.chosenLevels
0127                 currentActivity.currentLevels = dialogActivityConfig.chosenLevels
0128                 ApplicationSettings.setCurrentLevels(currentActivity.name, dialogActivityConfig.chosenLevels)
0129                 // restart activity on saving
0130                 background.start()
0131             }
0132             onClose: {
0133                 home()
0134             }
0135             onStartActivity: {
0136                 background.start()
0137             }
0138         }
0139 
0140         DialogHelp {
0141             id: dialogHelp
0142             onClose: home()
0143         }
0144 
0145         Bar {
0146             id: bar
0147             level: items.currentLevel + 1
0148             content: BarEnumContent { value: help | home | level | activityConfig }
0149             onHelpClicked: {
0150                 displayDialog(dialogHelp)
0151             }
0152             onPreviousLevelClicked: Activity.previousLevel()
0153             onNextLevelClicked: Activity.nextLevel()
0154             onHomeClicked: activity.home()
0155             onActivityConfigClicked: {
0156                 displayDialog(dialogActivityConfig)
0157             }
0158         }
0159 
0160         Bonus {
0161             id: bonus
0162             Component.onCompleted: win.connect(Activity.nextLevel)
0163         }
0164     }
0165 
0166 }