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

0001 /* GCompris - GridPath.qml
0002  *
0003  * SPDX-FileCopyrightText: 2021 Harsh Kumar <hadron43@yahoo.com>
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 import QtQuick 2.12
0007 import GCompris 1.0
0008 
0009 import "../../core"
0010 import "path.js" as Activity
0011 
0012 ActivityBase {
0013     id: activity
0014     // mode : encode | decode
0015     property string mode
0016 
0017     // movement : absolute | relative
0018     property string movement
0019 
0020     onStart: focus = true
0021     onStop: {}
0022 
0023     pageComponent: Rectangle {
0024         id: background
0025         color: "#42993E"
0026         anchors.fill: parent
0027         signal start
0028         signal stop
0029 
0030         Component.onCompleted: {
0031             activity.start.connect(start)
0032             activity.stop.connect(stop)
0033         }
0034 
0035         // Add here the QML items you need to access in javascript
0036         QtObject {
0037             id: items
0038             property Item main: activity.main
0039             property GCSfx audioEffects: activity.audioEffects
0040             readonly property string resourceUrl: activity.resourceUrl
0041             readonly property string mode: activity.mode
0042             readonly property string movement: activity.movement
0043             property int rows: 1
0044             property int cols: 1
0045             property int errorsCount
0046             readonly property var levels: activity.datasetLoader.data
0047             property alias mapView: mapView
0048             property alias tux: tux
0049             property alias movesGridView: moveBar.movesGridView
0050             property alias mapListModel: mapListModel
0051             property alias movesListModel: movesListModel
0052             property alias background: background
0053             property int currentLevel: activity.currentLevel
0054             property alias bonus: bonus
0055         }
0056 
0057         onWidthChanged: {
0058             sizeChangedTimer.restart()
0059         }
0060 
0061         onHeightChanged: {
0062             sizeChangedTimer.restart()
0063         }
0064 
0065         Timer {
0066             id: sizeChangedTimer
0067             interval: 100
0068             onTriggered: {
0069                 mapView.init()
0070 
0071                 tux.animationEnabled = false
0072                 Activity.moveTuxToBlock()
0073                 tux.animationEnabled = true
0074             }
0075         }
0076 
0077         onStart: { Activity.start(items) }
0078         onStop: {
0079             sizeChangedTimer.stop()
0080             Activity.stop()
0081         }
0082 
0083         ListModel {
0084             id: mapListModel
0085         }
0086 
0087         Item {
0088             id: layoutArea
0089             anchors.top: parent.top
0090             anchors.bottom: bar.top
0091             anchors.left: parent.left
0092             anchors.right: parent.right
0093             anchors.bottomMargin: bar.height * 0.5
0094             anchors.topMargin: 10 * ApplicationInfo.ratio
0095             anchors.leftMargin: anchors.topMargin
0096             anchors.rightMargin: anchors.topMargin
0097         }
0098 
0099         MapView {
0100             id: mapView
0101 
0102             touchEnabled: mode === 'decode'
0103 
0104             rows: items.rows
0105             cols: items.cols
0106         }
0107 
0108         Rectangle {
0109             id: errorsArea
0110             anchors.top: mapView.bottom
0111             anchors.left: mapView.left
0112             anchors.topMargin: height * 0.2
0113             width: errorsText.width * 1.2
0114             height: errorsText.height
0115             radius: height * 0.5
0116             color: "#f2f2f2"
0117             border.color: "#e74444"
0118             border.width: 4
0119         }
0120 
0121         GCText {
0122             id: errorsText
0123             fontSize: tinySize
0124             color: "#373737"
0125             text: qsTr("Errors: %1").arg(items.errorsCount.toString())
0126             anchors.centerIn: errorsArea
0127         }
0128 
0129         ListModel {
0130             id: movesListModel
0131         }
0132 
0133         MoveBar {
0134             id: moveBar
0135         }
0136 
0137         MoveButtons {
0138             id: moveButtons
0139             visible: items.mode === 'encode'
0140         }
0141 
0142         Tux {
0143             id: tux
0144             width: mapView.cellSize
0145             height: mapView.cellSize
0146         }
0147 
0148         property double maxAllowedHeight: layoutArea.height
0149         property double maxAllowedWidth: (layoutArea.width - layoutArea.anchors.bottomMargin) / 2
0150         property double size: Math.min(maxAllowedHeight / items.rows, maxAllowedWidth / items.cols)
0151 
0152         states: [
0153             State {
0154                 id: horizontalLayout
0155                 when: layoutArea.width >= layoutArea.height
0156                 PropertyChanges {
0157                     target: mapView
0158                     cellSize: size
0159                 }
0160                 PropertyChanges {
0161                     target: moveBar
0162                     width: layoutArea.width - mapView.width - layoutArea.anchors.bottomMargin
0163                     height: (moveButtons.visible) ? layoutArea.height / 2 : layoutArea.height
0164                     anchors.topMargin: errorsArea.anchors.topMargin
0165                 }
0166                 PropertyChanges {
0167                     target: moveButtons
0168                     width: moveBar.width
0169                     height: (moveButtons.visible) ? layoutArea.height / 2 : 0
0170                     anchors.topMargin: 0
0171                 }
0172                 AnchorChanges {
0173                     target: mapView
0174                     anchors.verticalCenter: layoutArea.verticalCenter
0175                     anchors.horizontalCenter: undefined
0176                     anchors.top: undefined
0177                     anchors.left: layoutArea.left
0178                 }
0179                 AnchorChanges {
0180                     target: moveBar
0181                     anchors.right: layoutArea.right
0182                     anchors.top: moveButtons.bottom
0183                 }
0184                 AnchorChanges {
0185                     target: moveButtons
0186                     anchors.right: layoutArea.right
0187                     anchors.top: layoutArea.top
0188                 }
0189             },
0190             State {
0191                 id: verticalLayout
0192                 when: layoutArea.width < layoutArea.height
0193                 PropertyChanges {
0194                     target: mapView
0195                     cellSize: Math.min((layoutArea.height * 0.7) / items.rows, layoutArea.width / items.cols)
0196                 }
0197                 PropertyChanges {
0198                     target: moveBar
0199                     width: layoutArea.width
0200                     height: (layoutArea.height - mapView.height - moveButtons.height - layoutArea.anchors.bottomMargin)
0201                     anchors.topMargin: errorsArea.anchors.topMargin
0202                 }
0203                 PropertyChanges {
0204                     target: moveButtons
0205                     width: moveBar.width
0206                     height: (moveButtons.visible) ? (layoutArea.height - mapView.height - layoutArea.anchors.bottomMargin) / 2 : 0
0207                     anchors.topMargin: layoutArea.anchors.bottomMargin
0208                 }
0209                 AnchorChanges {
0210                     target: mapView
0211                     anchors.verticalCenter: undefined
0212                     anchors.horizontalCenter: layoutArea.horizontalCenter
0213                     anchors.left: undefined
0214                     anchors.top: layoutArea.top
0215                 }
0216                 AnchorChanges {
0217                     target: moveBar
0218                     anchors.right: layoutArea.right
0219                     anchors.top: moveButtons.bottom
0220                 }
0221                 AnchorChanges {
0222                     target: moveButtons
0223                     anchors.right: layoutArea.right
0224                     anchors.top: mapView.bottom
0225                 }
0226             }
0227         ]
0228 
0229         DialogChooseLevel {
0230             id: dialogActivityConfig
0231             currentActivity: activity.activityInfo
0232 
0233             onSaveData: {
0234                 levelFolder = dialogActivityConfig.chosenLevels
0235                 currentActivity.currentLevels = dialogActivityConfig.chosenLevels
0236                 ApplicationSettings.setCurrentLevels(currentActivity.name, dialogActivityConfig.chosenLevels)
0237                 // restart activity on saving
0238                 background.start()
0239             }
0240             onClose: {
0241                 home()
0242             }
0243             onStartActivity: {
0244                 background.start()
0245             }
0246         }
0247 
0248         DialogHelp {
0249             id: dialogHelp
0250             onClose: home()
0251         }
0252 
0253         Bar {
0254             id: bar
0255             level: items.currentLevel + 1
0256             content: BarEnumContent { value: help | home | level | activityConfig }
0257             onHelpClicked: {
0258                 displayDialog(dialogHelp)
0259             }
0260             onPreviousLevelClicked: Activity.previousLevel()
0261             onNextLevelClicked: Activity.nextLevel()
0262             onHomeClicked: activity.home()
0263             onActivityConfigClicked: {
0264                 displayDialog(dialogActivityConfig)
0265             }
0266         }
0267 
0268         Bonus {
0269             id: bonus
0270             winSound: "qrc:/gcompris/src/activities/ballcatch/resource/tuxok.wav"
0271             Component.onCompleted: win.connect(Activity.nextLevel)
0272         }
0273 
0274         Keys.onLeftPressed: (items.mode === 'encode') ? Activity.moveTowards(Activity.Directions.LEFT) : null
0275         Keys.onRightPressed: (items.mode === 'encode') ? Activity.moveTowards(Activity.Directions.RIGHT) : null
0276         Keys.onUpPressed: (items.mode === 'encode') ? Activity.moveTowards(Activity.Directions.UP) : null
0277         Keys.onDownPressed: (items.mode === 'encode') ? Activity.moveTowards(Activity.Directions.DOWN) : null
0278     }
0279 }