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

0001 /* GCompris - Left_right_click.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 "left_right_click.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         anchors.fill: parent
0025         source: "qrc:/gcompris/src/activities/canal_lock/resource/sky.svg"
0026         sourceSize.height: height
0027         sourceSize.width: width
0028         signal start
0029         signal stop
0030 
0031         Component.onCompleted: {
0032             activity.start.connect(start)
0033             activity.stop.connect(stop)
0034         }
0035 
0036         // Add here the QML items you need to access in javascript
0037         QtObject {
0038             id: items
0039             property Item main: activity.main
0040             property alias background: background
0041             property int currentLevel: activity.currentLevel
0042             property alias bonus: bonus
0043             property GCSfx audioEffects: activity.audioEffects
0044             property alias animalListModel: animalListModel
0045             property alias animalCardsArea: animalCardsArea
0046             property double animalWidth: animalCardsArea.animalCardSize
0047             property double animalHeight: animalCardsArea.animalCardSize
0048             property alias leftArea: leftAreaTarget
0049             property alias rightArea: rightAreaTarget
0050             property alias displayMouse: displayMouse
0051             property alias leftClickDisplayMouse: leftClickDisplayMouse
0052             property alias rightClickDisplayMouse: rightClickDisplayMouse
0053             property alias cross: cross
0054             property int animalCount
0055         }
0056 
0057         onStart: { Activity.start(items) }
0058         onStop: { Activity.stop() }
0059 
0060         Image {
0061             id: hillArea
0062             source: "qrc:/gcompris/src/activities/left_right_click/resource/hill.svg"
0063             width: background.width
0064             height: background.height - leftAreaTarget.height * 0.5
0065             anchors.bottom: background.bottom
0066             sourceSize.width: width
0067             sourceSize.height: height
0068         }
0069 
0070         Item {
0071             id: layoutArea
0072             anchors.top: parent.top
0073             anchors.bottom: bar.top
0074             anchors.bottomMargin: bar.height * 0.2
0075             anchors.left: parent.left
0076             anchors.right: parent.right
0077         }
0078 
0079         Image {
0080             id: leftAreaTarget
0081             parent: layoutArea
0082             width: layoutArea.width * 0.3
0083             height: layoutArea.height * 0.5
0084             sourceSize.height: Math.min(width, height)
0085             anchors.left: layoutArea.left
0086             fillMode: Image.PreserveAspectFit
0087             source: "qrc:/gcompris/src/activities/left_right_click/resource/pond.svg"
0088         }
0089 
0090         Image {
0091             id: rightAreaTarget
0092             parent: layoutArea
0093             width: leftAreaTarget.width
0094             height: leftAreaTarget.height
0095             sourceSize.height: leftAreaTarget.sourceSize.height
0096             anchors.right: layoutArea.right
0097             fillMode: Image.PreserveAspectFit
0098             source: "qrc:/gcompris/src/activities/left_right_click/resource/tree.svg"
0099         }
0100 
0101         ListModel {
0102             id: animalListModel
0103         }
0104 
0105         Item {
0106             id: animalCardsArea
0107             parent: layoutArea
0108             width: layoutArea.width
0109             height: leftAreaTarget.height
0110             anchors.top: leftAreaTarget.bottom
0111             property double animalCardSize: Core.fitItems(animalCardsArea.width,animalCardsArea.height,items.animalCount)
0112 
0113             GridView {
0114                 id: container
0115                 height: parent.height
0116                 width: parent.width
0117                 anchors.centerIn: parent
0118                 interactive: false
0119                 cellHeight: animalCardsArea.animalCardSize
0120                 cellWidth: animalCardsArea.animalCardSize
0121                 model: animalListModel
0122                 delegate: Animal {
0123                     height: items.animalHeight
0124                     width: items.animalWidth
0125                 }
0126             }
0127         }
0128 
0129         Item {
0130             id: mouseDisplayContainer
0131             parent: layoutArea
0132             anchors.top: layoutArea.top
0133             anchors.bottom: animalCardsArea.top
0134             anchors.left: leftAreaTarget.right
0135             anchors.right: rightAreaTarget.left
0136 
0137             Image {
0138                 id: displayMouse
0139                 source: "qrc:/gcompris/src/activities/left_right_click/resource/mouse.svg"
0140                 width: Math.min(parent.width, parent.height)
0141                 height: width
0142                 sourceSize.width: width
0143                 anchors.centerIn: parent
0144                 fillMode: Image.PreserveAspectFit
0145 
0146                 MouseButton {
0147                     id: leftClickDisplayMouse
0148                 }
0149 
0150                 MouseButton {
0151                     id: rightClickDisplayMouse
0152                     isRightButton: true
0153                 }
0154 
0155                 Image {
0156                     id: cross
0157                     height: parent.width * 0.5
0158                     width: height
0159                     sourceSize.height: height
0160                     anchors.horizontalCenter: parent.horizontalCenter
0161                     anchors.bottom: parent.bottom
0162                     source: "qrc:/gcompris/src/core/resource/cancel.svg"
0163                     visible: false // only visible when a wrong click is pressed
0164                 }
0165             }
0166         }
0167 
0168         // for left click of the mouse
0169         signal leftClickTrigger
0170         onLeftClickTrigger: {
0171             leftClickDisplayMouse.clickTrigger()
0172         }
0173 
0174         // for the right click of the mouse
0175         signal rightClickTrigger
0176         onRightClickTrigger: {
0177             rightClickDisplayMouse.clickTrigger()
0178         }
0179 
0180         //for the cross to hide
0181         signal wrongClick
0182         onWrongClick: {
0183             cross.visible = true
0184             hideCross.running = true
0185             Activity.playWrongClickSound()
0186         }
0187 
0188         PropertyAnimation {
0189             id: hideCross
0190             target: cross
0191             property: "visible"
0192             to: false
0193             duration: 500
0194         }
0195 
0196         DialogHelp {
0197             id: dialogHelp
0198             onClose: home()
0199         }
0200 
0201         Bar {
0202             id: bar
0203             level: items.currentLevel + 1
0204             content: BarEnumContent { value: help | home | level | reload }
0205             onHelpClicked: {
0206                 displayDialog(dialogHelp)
0207             }
0208             onPreviousLevelClicked: Activity.previousLevel()
0209             onNextLevelClicked: Activity.nextLevel()
0210             onHomeClicked: activity.home()
0211             onReloadClicked: {
0212                 Activity.start(items)
0213             }
0214         }
0215 
0216         Bonus {
0217             id: bonus
0218             Component.onCompleted: win.connect(Activity.nextLevel)
0219         }
0220     }
0221 }