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

0001 /* GCompris - Leftright.qml
0002  *
0003  * SPDX-FileCopyrightText: 2014 Bruno Coudoin <bruno.coudoin@gcompris.net>
0004  *
0005  * Authors:
0006  *   Pascal Georges <pascal.georges1@free.fr> (GTK+ version)
0007  *   Bruno Coudoin <bruno.coudoin@gcompris.net> (Qt Quick port)
0008  *
0009  *   SPDX-License-Identifier: GPL-3.0-or-later
0010  */
0011 import QtQuick 2.12
0012 import GCompris 1.0
0013 import "../../core"
0014 import "leftright.js" as Activity
0015 
0016 ActivityBase {
0017     id: activity
0018 
0019     onStart: focus = true;
0020 
0021     pageComponent: Rectangle {
0022         id: background
0023         color: "#abcdef"
0024         focus: true
0025         signal start
0026         signal stop
0027 
0028         QtObject {
0029             id: items
0030             property int currentLevel: activity.currentLevel
0031             property alias bonus: bonus
0032             property GCSfx audioEffects: activity.audioEffects
0033             property alias imageAnimOff: imageAnimOff
0034             property alias leftButton: leftButton
0035             property alias rightButton: rightButton
0036             property alias score: score
0037             property bool buttonsBlocked: false
0038         }
0039 
0040         Keys.onLeftPressed: Activity.leftClickPressed()
0041         Keys.onRightPressed: Activity.rightClickPressed()
0042         Keys.enabled: !items.buttonsBlocked
0043 
0044         Component.onCompleted: {
0045             activity.start.connect(start)
0046             activity.stop.connect(stop)
0047         }
0048         onStart: { Activity.start(items) }
0049         onStop: { Activity.stop() }
0050 
0051         Item {
0052             id: layoutArea
0053             width: parent.width
0054             height: parent.height - bar.height * 1.5 - score.height * 1.3
0055             anchors.top: score.bottom
0056             anchors.left: parent.left
0057         }
0058 
0059         Image {
0060             id: blackBoard
0061             anchors.horizontalCenter: layoutArea.horizontalCenter
0062             anchors.verticalCenter: layoutArea.verticalCenter
0063             anchors.verticalCenterOffset: -leftButton.height * 0.5
0064             fillMode: Image.PreserveAspectFit
0065             height: (layoutArea.height - 10) * 0.85
0066             width: layoutArea.width
0067             sourceSize.height: height
0068             sourceSize.width: width
0069             source: "qrc:/gcompris/src/activities/leftright/resource/blackboard.svg"
0070 
0071             Image {
0072                 id: lightImage
0073                 source: "qrc:/gcompris/src/activities/leftright/resource/light.svg"
0074                 fillMode: Image.PreserveAspectFit
0075                 sourceSize.width: parent.paintedWidth
0076                 sourceSize.height: parent.paintedHeight
0077                 anchors.centerIn: parent
0078                 anchors.topMargin: 40
0079                 opacity: 0
0080             }
0081 
0082             Image {
0083                 id: handImage
0084                 anchors.horizontalCenter: parent.horizontalCenter
0085                 anchors.verticalCenter: parent.verticalCenter
0086                 fillMode: Image.PreserveAspectFit
0087                 width: blackBoard.paintedHeight * 0.7
0088                 height: width
0089                 opacity: 0
0090             }
0091 
0092             ParallelAnimation {
0093                 id: imageAnimOff
0094                 onRunningChanged: {
0095                     if (!imageAnimOff.running) {
0096                         handImage.source = Activity.getCurrentHandImage()
0097                         handImage.rotation = Activity.getCurrentHandRotation()
0098 
0099                         imageAnimOn.start()
0100                     }
0101                 }
0102                 NumberAnimation {
0103                     target: handImage
0104                     property: "opacity"
0105                     from: 1; to: 0
0106                     duration: 300
0107                     easing.type: Easing.InOutQuad
0108                 }
0109                 NumberAnimation {
0110                     target: lightImage
0111                     property: "opacity"
0112                     from: 1; to: 0
0113                     duration: 300
0114                     easing.type: Easing.InOutQuad
0115                 }
0116             }
0117             ParallelAnimation {
0118                 id: imageAnimOn
0119                 onStopped: bonus.isPlaying ? items.buttonsBlocked = true : items.buttonsBlocked = false
0120                 NumberAnimation {
0121                     target: handImage
0122                     property: "opacity"
0123                     from: 0; to: 1.0
0124                     duration: 300
0125                     easing.type: Easing.InOutQuad
0126                 }
0127                 NumberAnimation {
0128                     target: lightImage
0129                     property: "opacity"
0130                     from: 0; to: 1
0131                     duration: 300
0132                     easing.type: Easing.InOutQuad
0133                 }
0134             }
0135 
0136             AnswerButton {
0137                 id: leftButton
0138                 width: blackBoard.paintedWidth * 0.45
0139                 height: (layoutArea.height - 10) * 0.15
0140                 anchors.right: blackBoard.horizontalCenter
0141                 anchors.rightMargin: blackBoard.paintedWidth * 0.04
0142                 anchors.top: blackBoard.verticalCenter
0143                 anchors.topMargin: blackBoard.paintedHeight * 0.5 + 10
0144                 textLabel: qsTr("Left hand")
0145                 audioEffects: activity.audioEffects
0146                 onPressed: {
0147                     items.buttonsBlocked = true
0148                     if(isCorrectAnswer)
0149                         Activity.goodAnswerPressed()
0150                 }
0151                 blockAllButtonClicks: items.buttonsBlocked
0152                 onIncorrectlyPressed: items.buttonsBlocked = false
0153             }
0154 
0155             AnswerButton {
0156                 id: rightButton
0157                 width: leftButton.width
0158                 height: leftButton.height
0159                 anchors.left: blackBoard.horizontalCenter
0160                 anchors.leftMargin: leftButton.anchors.rightMargin
0161                 anchors.top: blackBoard.verticalCenter
0162                 anchors.topMargin: leftButton.anchors.topMargin
0163                 audioEffects: activity.audioEffects
0164                 textLabel: qsTr("Right hand")
0165                 onPressed: {
0166                     items.buttonsBlocked = true
0167                     if(isCorrectAnswer)
0168                         Activity.goodAnswerPressed()
0169                 }
0170                 blockAllButtonClicks: items.buttonsBlocked
0171                 onIncorrectlyPressed: items.buttonsBlocked = false
0172             }
0173         }
0174 
0175         DialogHelp {
0176             id: dialogHelpLeftRight
0177             onClose: home()
0178         }
0179 
0180         Bar {
0181             id: bar
0182             level: items.currentLevel + 1
0183             content: BarEnumContent { value: help | home | level }
0184             onHelpClicked: {
0185                 displayDialog(dialogHelpLeftRight)
0186             }
0187             onPreviousLevelClicked: Activity.previousLevel()
0188             onNextLevelClicked: Activity.nextLevel()
0189             onHomeClicked: home()
0190         }
0191 
0192         Bonus {
0193             id: bonus
0194             onStop: {
0195                 Activity.nextLevel();
0196             }
0197         }
0198 
0199         Score {
0200             id: score
0201             anchors.top: background.top
0202             anchors.topMargin: parent.height * 0.01
0203             anchors.bottom: undefined
0204             onStop: Activity.displayNextHand()
0205         }
0206     }
0207 }