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

0001 /* GCompris - tens_complement_find.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 import GCompris 1.0
0011 import "../../core"
0012 import "tens_complement_find.js" as Activity
0013 import "qrc:/gcompris/src/core/core.js" as Core
0014 
0015 ActivityBase {
0016     id: activity
0017 
0018     onStart: focus = true
0019     onStop: {}
0020 
0021     pageComponent: Image {
0022         id: background
0023         source: "qrc:/gcompris/src/activities/chess/resource/background-wood.svg"
0024         anchors.fill: parent
0025         fillMode: Image.PreserveAspectCrop
0026         sourceSize.height: height
0027         signal start
0028         signal stop
0029 
0030         property int layoutMargins: 10 * ApplicationInfo.ratio
0031 
0032         Component.onCompleted: {
0033             activity.start.connect(start)
0034             activity.stop.connect(stop)
0035         }
0036 
0037         // Add here the QML items you need to access in javascript
0038         QtObject {
0039             id: items
0040             property Item main: activity.main
0041             property alias background: background
0042             property GCSfx audioEffects: activity.audioEffects
0043             property int currentLevel: activity.currentLevel
0044             property alias bonus: bonus
0045             property alias cardListModel: cardListModel
0046             property alias holderListModel: holderListModel
0047             property int selectedIndex: -1
0048             readonly property var levels: activity.datasetLoader.data
0049             property alias okButton: okButton
0050             property alias score: score
0051             property double cardSize: Core.fitItems(numberContainerArea.width, numberContainerArea.height, 6)
0052             property bool isHorizontal: background.width >= background.height
0053             property bool buttonsBlocked: false
0054         }
0055 
0056         onStart: { Activity.start(items) }
0057         onStop: { Activity.stop() }
0058 
0059         Item {
0060             id: layoutArea
0061             anchors {
0062                 top: parent.top
0063                 bottom: bar.top
0064                 bottomMargin: bar.height * 0.2
0065                 left: parent.left
0066                 right: parent.right
0067             }
0068         }
0069 
0070         ListModel {
0071             id: cardListModel
0072         }
0073 
0074         Item {
0075             id: numberContainerArea
0076             height: width * 0.67
0077             width: (layoutArea.width - background.layoutMargins * 3) * 0.32
0078             anchors.left: layoutArea.left
0079             anchors.verticalCenter: answerHolderArea.verticalCenter
0080             anchors.leftMargin: background.layoutMargins
0081         }
0082 
0083         Rectangle {
0084             id: numberContainer
0085             width: items.cardSize * 3
0086             height: items.cardSize * Math.ceil(cardListModel.count / 3)
0087             anchors.verticalCenter: numberContainerArea.verticalCenter
0088             anchors.left: numberContainerArea.left
0089             color: "#80FFFFFF"
0090             radius: 15
0091 
0092             GridView {
0093                 id: container
0094                 height: parent.height
0095                 width: parent.width
0096                 interactive: false
0097                 anchors.centerIn: parent
0098                 cellHeight: items.cardSize
0099                 cellWidth: items.cardSize
0100                 model: cardListModel
0101                 delegate: NumberQuestionCard {
0102                     height: items.cardSize
0103                     width: items.cardSize
0104                     selected: index == items.selectedIndex
0105                     onClicked: {
0106                         items.selectedIndex = index;
0107                     }
0108                 }
0109             }
0110         }
0111 
0112         ListModel {
0113             id: holderListModel
0114         }
0115 
0116         Item {
0117             id: answerHolderArea
0118             anchors {
0119                 left: numberContainer.right
0120                 top: layoutArea.top
0121                 bottom: score.top
0122                 right: score.left
0123                 margins: background.layoutMargins
0124             }
0125 
0126             ListView {
0127                 height: Math.min(items.cardSize * holderListModel.count, answerHolderArea.height)
0128                 width: Math.min(items.cardSize * 6, parent.width) // 6 as addition contains 6 cards + validation image
0129                 interactive: false
0130                 anchors.centerIn: parent
0131                 model: holderListModel
0132                 delegate: AnswerContainer {
0133                     readonly property int minHeight: holderListModel.count == 0 ? items.cardSize : answerHolderArea.height / holderListModel.count
0134                     height: Math.min(items.cardSize, minHeight)
0135                     width: Math.min(height * 6, ListView.view.width)
0136                 }
0137             }
0138         }
0139 
0140         BarButton {
0141             id: okButton
0142             visible: false
0143             z: 2
0144             source: "qrc:/gcompris/src/core/resource/bar_ok.svg"
0145             anchors {
0146                 bottom: score.top
0147                 bottomMargin: background.layoutMargins
0148                 horizontalCenter: score.horizontalCenter
0149             }
0150             sourceSize.width: 60 * ApplicationInfo.ratio
0151             enabled: !bonus.isPlaying
0152             onClicked: Activity.checkAnswer()
0153         }
0154 
0155         Score {
0156             id: score
0157             anchors {
0158                 right: layoutArea.right
0159                 bottom: layoutArea.bottom
0160                 rightMargin: background.layoutMargins
0161                 bottomMargin: background.layoutMargins
0162             }
0163             onStop: Activity.nextSubLevel()
0164         }
0165 
0166         states: [
0167             State {
0168                 name: "horizontalLayout"
0169                 when: items.isHorizontal
0170                 AnchorChanges {
0171                     target: numberContainerArea
0172                     anchors {
0173                         left: parent.left
0174                         verticalCenter: answerHolderArea.verticalCenter
0175                         horizontalCenter: undefined
0176                         bottom: undefined
0177                     }
0178                 }
0179                 PropertyChanges {
0180                     target: numberContainerArea
0181                     anchors {
0182                         leftMargin: background.layoutMargins
0183                         bottomMargin: 0
0184                     }
0185                     height: width * 0.67
0186                     width: (layoutArea.width - background.layoutMargins * 3) * 0.32
0187                 }
0188                 AnchorChanges {
0189                     target: numberContainer
0190                     anchors {
0191                         verticalCenter: numberContainerArea.verticalCenter
0192                         left: numberContainerArea.left
0193                         horizontalCenter: undefined
0194                     }
0195                 }
0196                 AnchorChanges {
0197                     target: answerHolderArea
0198                     anchors {
0199                         left: numberContainer.right
0200                         top: parent.top
0201                         bottom: score.top
0202                         right: score.left
0203                     }
0204                 }
0205             },
0206             State {
0207                 name: "verticalLayout"
0208                 when: !items.isHorizontal
0209                 AnchorChanges {
0210                     target: numberContainerArea
0211                     anchors {
0212                         left: undefined
0213                         verticalCenter: undefined
0214                         horizontalCenter: layoutArea.horizontalCenter
0215                         bottom: score.top
0216                     }
0217                 }
0218                 PropertyChanges {
0219                     target: numberContainerArea
0220                     anchors {
0221                         leftMargin: 0
0222                         bottomMargin: background.layoutMargins
0223                     }
0224                     width: Math.min(layoutArea.width - score.width * 2 - background.layoutMargins * 4,
0225                                     layoutArea.height * 0.5)
0226                     height: width * 0.67
0227                 }
0228                 AnchorChanges {
0229                     target: numberContainer
0230                     anchors {
0231                         verticalCenter: numberContainerArea.verticalCenter
0232                         left: undefined
0233                         horizontalCenter: numberContainerArea.horizontalCenter
0234                     }
0235                 }
0236                 AnchorChanges {
0237                     target: answerHolderArea
0238                     anchors {
0239                         left: layoutArea.left
0240                         top: parent.top
0241                         bottom: numberContainerArea.top
0242                         right: layoutArea.right
0243                     }
0244                 }
0245             }
0246         ]
0247 
0248         MouseArea {
0249             id: clickMask
0250             anchors.fill: layoutArea
0251             enabled: items.buttonsBlocked
0252         }
0253 
0254         DialogChooseLevel {
0255             id: dialogActivityConfig
0256             currentActivity: activity.activityInfo
0257 
0258             onSaveData: {
0259                 levelFolder = dialogActivityConfig.chosenLevels
0260                 currentActivity.currentLevels = dialogActivityConfig.chosenLevels
0261                 ApplicationSettings.setCurrentLevels(currentActivity.name, dialogActivityConfig.chosenLevels)
0262                 // restart activity on saving
0263                 background.start()
0264             }
0265             onClose: {
0266                 home()
0267             }
0268             onStartActivity: {
0269                 background.start()
0270             }
0271         }
0272 
0273         DialogHelp {
0274             id: dialogHelp
0275             onClose: home()
0276         }
0277 
0278         Bar {
0279             id: bar
0280             level: items.currentLevel + 1
0281             content: BarEnumContent { value: help | home | level | activityConfig }
0282             onHelpClicked: {
0283                 displayDialog(dialogHelp)
0284             }
0285             onPreviousLevelClicked: Activity.previousLevel()
0286             onNextLevelClicked: Activity.nextLevel()
0287             onHomeClicked: activity.home()
0288             onActivityConfigClicked: {
0289                 displayDialog(dialogActivityConfig)
0290             }
0291         }
0292 
0293         Bonus {
0294             id: bonus
0295             Component.onCompleted: win.connect(Activity.nextLevel)
0296         }
0297     }
0298 
0299 }