Warning, /education/gcompris/src/activities/analog_electricity/AnalogElectricity.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - AnalogElectricity.qml
0002 *
0003 * SPDX-FileCopyrightText: 2020 Aiswarya Kaitheri Kandoth <aiswaryakk29@gmail.com>
0004 *
0005 * Authors:
0006 * Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version)
0007 * Pulkit Gupta <pulkitnsit@gmail.com> (DigitalElectricity code)
0008 * Rudra Nil Basu <rudra.nil.basu.1996@gmail.com> (DigitalElectricity code)
0009 * Timothée Giet <animtim@gmail.com> (mouse drag refactoring)
0010 * Aiswarya Kaitheri Kandoth <aiswaryakk29@gmail.com> (Qt Quick port of AnalogElectricity)
0011 *
0012 * SPDX-License-Identifier: GPL-3.0-or-later
0013 */
0014 import QtQuick 2.12
0015 import GCompris 1.0
0016
0017 import "../../core"
0018 import "analog_electricity.js" as Activity
0019
0020 ActivityBase {
0021 id: activity
0022
0023 onStart: focus = true
0024 onStop: {}
0025
0026 pageComponent: Image {
0027 id: background
0028 anchors.fill: parent
0029 source: Activity.urlDigital + "texture02.webp"
0030 fillMode: Image.Tile
0031 signal start
0032 signal stop
0033
0034 onWidthChanged: resizeTimer.restart();
0035 onHeightChanged: resizeTimer.restart();
0036
0037 Timer {
0038 id: resizeTimer
0039 interval: 200
0040 repeat: false
0041 running: false
0042 triggeredOnStart: false
0043 onTriggered: Activity.updateWiresOnResize();
0044 }
0045
0046 Timer {
0047 id: netlistTimer
0048 interval: 500
0049 repeat: false
0050 running: false
0051 triggeredOnStart: false
0052 onTriggered: Activity.createNetlist();
0053 }
0054
0055 property bool hori: background.width >= background.height
0056
0057 Component.onCompleted: {
0058 dialogActivityConfig.initialize();
0059 activity.start.connect(start);
0060 activity.stop.connect(stop);
0061 }
0062
0063 // Needed to get keyboard focus on IntroMessage
0064 Keys.forwardTo: tutorialInstruction
0065
0066 Keys.onPressed: {
0067 if ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter) && okButton.enabled) {
0068 Activity.checkAnswer()
0069 }
0070 if (event.key === Qt.Key_Plus) {
0071 Activity.zoomIn();
0072 }
0073 if (event.key === Qt.Key_Minus) {
0074 Activity.zoomOut();
0075 }
0076 if (event.key === Qt.Key_Right) {
0077 playArea.x -= 200;
0078 }
0079 if (event.key === Qt.Key_Left) {
0080 playArea.x += 200;
0081 }
0082 if (event.key === Qt.Key_Up) {
0083 playArea.y += 200;
0084 }
0085 if (event.key === Qt.Key_Down) {
0086 playArea.y -= 200;
0087 }
0088 if (playArea.x >= mousePan.drag.maximumX) {
0089 playArea.x = mousePan.drag.maximumX;
0090 }
0091 if (playArea.y >= mousePan.drag.maximumY) {
0092 playArea.y = mousePan.drag.maximumY;
0093 }
0094 if (playArea.x <= mousePan.drag.minimumX) {
0095 playArea.x = mousePan.drag.minimumX;
0096 }
0097 if (playArea.y <= mousePan.drag.minimumY) {
0098 playArea.y = mousePan.drag.minimumY;
0099 }
0100 }
0101
0102 // Add here the QML items you need to access in javascript
0103 QtObject {
0104 id: items
0105 property Item main: activity.main
0106 property alias background: background
0107 property int currentLevel: activity.currentLevel
0108 property alias bonus: bonus
0109 property alias playArea: playArea
0110 property alias mousePan: mousePan
0111 property alias availablePieces: availablePieces
0112 property alias tutorialDataset: tutorialDataset
0113 property alias toolTip: toolTip
0114 property alias infoTxt: infoTxt
0115 property alias infoImage: infoImage
0116 property alias dataset: dataset
0117 property alias netlistTimer: netlistTimer
0118 property real toolsMargin: 90 * ApplicationInfo.ratio
0119 property real zoomLvl: 0.25
0120 property string mode: "tutorial"
0121 property bool isTutorialMode: mode == "tutorial" ? true : false
0122 property alias tutorialInstruction: tutorialInstruction
0123
0124 }
0125
0126 Loader {
0127 id: dataset
0128 asynchronous: false
0129 }
0130
0131 TutorialDataset {
0132 id: tutorialDataset
0133 }
0134
0135 IntroMessage {
0136 id: tutorialInstruction
0137 intro: []
0138 textContainerWidth: background.hori ? parent.width - inputComponentsContainer.width - items.toolsMargin : 0.9 * background.width
0139 textContainerHeight: background.hori ? 0.5 * parent.height : parent.height - inputComponentsContainer.height - (bar.height * 2) - items.toolsMargin
0140 anchors {
0141 fill: undefined
0142 top: background.hori ? parent.top : inputComponentsContainer.bottom
0143 topMargin: 10
0144 right: parent.right
0145 rightMargin: 5
0146 left: background.hori ? inputComponentsContainer.right : parent.left
0147 leftMargin: 5
0148 }
0149 z: 5
0150 }
0151
0152 onStart: Activity.start(items);
0153 onStop: {
0154 resizeTimer.stop();
0155 netlistTimer.stop();
0156 Activity.stop();
0157 }
0158
0159 Rectangle {
0160 id: visibleArea
0161 color: "#00000000"
0162 width:background.width - items.toolsMargin - 10
0163 height: background.height - bar.height - items.toolsMargin - 10
0164 anchors {
0165 fill: undefined
0166 top: parent.top
0167 topMargin: 5
0168 right: parent.right
0169 rightMargin: 5
0170 left: inputComponentsContainer.right
0171 leftMargin: 5
0172 bottom: bar.top
0173 bottomMargin: 20
0174 }
0175 z: 6
0176
0177 GCText {
0178 id: infoTxt
0179 anchors {
0180 horizontalCenter: parent.horizontalCenter
0181 top: parent.top
0182 topMargin: 2
0183 }
0184 fontSizeMode: Text.Fit
0185 minimumPixelSize: 10
0186 font.pixelSize: 150
0187 color: "white"
0188 horizontalAlignment: Text.AlignHLeft
0189 width: Math.min(implicitWidth, 0.90 * parent.width)
0190 height: Math.min(implicitHeight, 0.7 * parent.height)
0191 wrapMode: TextEdit.WordWrap
0192 visible: false
0193 z: 4
0194 }
0195
0196 Rectangle {
0197 id: infoTxtContainer
0198 anchors.fill: parent
0199 opacity: 1
0200 radius: 10
0201 color: "#373737"
0202 border.width: 2
0203 border.color: "#F2F2F2"
0204 visible: infoTxt.visible
0205 MouseArea {
0206 anchors.fill: parent
0207 onClicked: infoTxt.visible = false
0208 }
0209 z: 3
0210 }
0211
0212 Image {
0213 id: infoImage
0214 property bool imgVisible: false
0215 height: source == "" ? 0 : parent.height * 0.3 - 10
0216 width: source == "" ? 0 : parent.width - 10
0217 fillMode: Image.PreserveAspectFit
0218 visible: infoTxt.visible && imgVisible
0219 anchors {
0220 top: infoTxt.bottom
0221 horizontalCenter: infoTxtContainer.horizontalCenter
0222 }
0223 z: 5
0224 }
0225 }
0226
0227 Rectangle {
0228 id: playArea
0229 color: "#10000000"
0230 x: items.toolsMargin
0231 y: 0
0232 width: background.width * 4 - items.toolsMargin
0233 height: background.height * 4 - (bar.height * 1.1)
0234
0235 property double sizeMultiplier:
0236 playArea.width > playArea.height ? playArea.width : playArea.height
0237
0238 PinchArea {
0239 id: pinchZoom
0240 anchors.fill: parent
0241 onPinchFinished: {
0242 if (pinch.scale < 1) {
0243 Activity.zoomOut();
0244 }
0245 if (pinch.scale > 1) {
0246 Activity.zoomIn();
0247 }
0248 }
0249 MouseArea {
0250 id: mousePan
0251 anchors.fill: parent
0252 scrollGestureEnabled: false //needed for pinchZoom
0253 drag.target: playArea
0254 drag.axis: Drag.XandYAxis
0255 drag.minimumX: - playArea.width * items.zoomLvl
0256 drag.maximumX: items.toolsMargin
0257 drag.minimumY: - playArea.height * items.zoomLvl
0258 drag.maximumY: 0
0259 onClicked: {
0260 Activity.disableToolDelete();
0261 Activity.deselect();
0262 availablePieces.hideToolbar();
0263 }
0264 }
0265 }
0266 }
0267
0268 Rectangle {
0269 id: inputComponentsContainer
0270 width: items.toolsMargin
0271 height: background.height
0272 color: "#4A3823"
0273 anchors.left: parent.left
0274 Image {
0275 id: containerTexture
0276 anchors.fill: parent
0277 anchors.rightMargin: 3 * ApplicationInfo.ratio
0278 anchors.bottomMargin: 0
0279 source: Activity.urlDigital + "texture01.webp"
0280 fillMode: Image.Tile
0281 ListWidget {
0282 id: availablePieces
0283 hori: background.hori
0284 }
0285 }
0286 z: 10
0287 }
0288
0289 Rectangle {
0290 id: toolTip
0291 anchors {
0292 bottom: bar.top
0293 bottomMargin: 10
0294 left: inputComponentsContainer.left
0295 leftMargin: 5
0296 }
0297 width: toolTipTxt.width + 10
0298 height: toolTipTxt.height + 5
0299 color: "#373737"
0300 opacity: 0
0301 radius: 10
0302 z: 100
0303 border.width: 2
0304 border.color: "#F2F2F2"
0305 property alias text: toolTipTxt.text
0306 Behavior on opacity { NumberAnimation { duration: 120 } }
0307
0308 function show(newText) {
0309 if(newText) {
0310 text = newText;
0311 opacity = 1;
0312 } else {
0313 opacity = 0;
0314 }
0315 }
0316
0317 GCText {
0318 id: toolTipTxt
0319 anchors.centerIn: parent
0320 fontSize: regularSize
0321 color: "white"
0322 horizontalAlignment: Text.AlignHCenter
0323 wrapMode: TextEdit.WordWrap
0324 }
0325 }
0326
0327 DialogChooseLevel {
0328 id: dialogActivityConfig
0329 currentActivity: activity.activityInfo
0330 onClose: {
0331 home();
0332 }
0333 onLoadData: {
0334 if(activityData && activityData["mode"]) {
0335 items.mode = activityData["mode"];
0336 }
0337 }
0338 }
0339
0340 DialogHelp {
0341 id: dialogHelp
0342 onClose: home();
0343 }
0344
0345 BarButton {
0346 id: okButton
0347 visible: items.isTutorialMode
0348 anchors {
0349 bottom: bar.top
0350 right: parent.right
0351 rightMargin: 10 * ApplicationInfo.ratio
0352 bottomMargin: height * 0.5
0353 }
0354 source: "qrc:/gcompris/src/core/resource/bar_ok.svg"
0355 sourceSize.width: 60 * ApplicationInfo.ratio
0356 enabled: !tutorialInstruction.visible && !bonus.isPlaying
0357 onClicked: Activity.checkAnswer();
0358 }
0359
0360 Bar {
0361 id: bar
0362 level: items.currentLevel + 1
0363 content: BarEnumContent { value: help | home | (items.isTutorialMode ? level : 0) | reload | activityConfig }
0364 onHelpClicked: displayDialog(dialogHelp);
0365 onPreviousLevelClicked: Activity.previousLevel();
0366 onNextLevelClicked: Activity.nextLevel();
0367 onHomeClicked: home();
0368 onReloadClicked: Activity.reset();
0369 onActivityConfigClicked: {
0370 displayDialog(dialogActivityConfig);
0371 }
0372 }
0373
0374 Bonus {
0375 id: bonus
0376 Component.onCompleted: win.connect(Activity.nextLevel);
0377 }
0378
0379 states: [
0380 State {
0381 id: "horizontalView"
0382 when: background.hori
0383 PropertyChanges {
0384 target: visibleArea
0385 width: background.width - items.toolsMargin - 10
0386 height: background.height - bar.height - items.toolsMargin - 10
0387 }
0388 AnchorChanges {
0389 target: visibleArea
0390 anchors.top: parent.top
0391 anchors.left: inputComponentsContainer.right
0392 }
0393 PropertyChanges {
0394 target: playArea
0395 x: items.toolsMargin
0396 y: 0
0397 width: background.width * 4 - items.toolsMargin
0398 height: background.height * 4 - (bar.height * 1.1)
0399 }
0400 PropertyChanges {
0401 target: mousePan
0402 drag.maximumX: items.toolsMargin
0403 drag.maximumY: 0
0404 }
0405 PropertyChanges {
0406 target: inputComponentsContainer
0407 width: items.toolsMargin
0408 height: background.height
0409 }
0410 PropertyChanges {
0411 target: containerTexture
0412 anchors.rightMargin: 3 * ApplicationInfo.ratio
0413 anchors.bottomMargin: 0
0414 }
0415 },
0416 State {
0417 id: "verticalView"
0418 when: !background.hori
0419 PropertyChanges {
0420 target: visibleArea
0421 width: background.width - 10
0422 height: background.height - bar.height - 10
0423 }
0424 AnchorChanges {
0425 target: visibleArea
0426 anchors.top: inputComponentsContainer.bottom
0427 anchors.left: parent.left
0428 }
0429 PropertyChanges {
0430 target: playArea
0431 x: 0
0432 y: items.toolsMargin
0433 width: background.width * 4
0434 height: background.height * 4 - (bar.height * 1.1) - items.toolsMargin
0435 }
0436 PropertyChanges {
0437 target: mousePan
0438 drag.maximumX: 0
0439 drag.maximumY: items.toolsMargin
0440 }
0441 PropertyChanges {
0442 target: inputComponentsContainer
0443 width: background.width
0444 height: items.toolsMargin
0445 }
0446 PropertyChanges {
0447 target: containerTexture
0448 anchors.rightMargin: 0
0449 anchors.bottomMargin: 3 * ApplicationInfo.ratio
0450 }
0451 }
0452 ]
0453 }
0454 }