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

0001 /* GCompris - colormix.qml
0002 *
0003 * SPDX-FileCopyrightText: 2014 Stephane Mankowski <stephane@mankowski.fr>
0004 *
0005 * Authors:
0006 *   Matilda Bernard <serah4291@gmail.com> (GTK+ version)
0007 *   Stephane Mankowski <stephane@mankowski.fr> (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 
0014 import "../../core"
0015 import "colormix.js" as Activity
0016 
0017 ActivityBase {
0018     id: activity
0019 
0020     property bool modeRGB: false
0021 
0022     onStart: focus = true
0023     onStop: {
0024 
0025     }
0026 
0027     pageComponent: Image {
0028         id: background
0029         source: Activity.url + (modeRGB ? "background.svg" : "background2.svg")
0030         sourceSize.width: width
0031         sourceSize.height: height
0032         anchors.fill: parent
0033         fillMode: Image.PreserveAspectCrop
0034 
0035         signal start
0036         signal stop
0037 
0038         Component.onCompleted: {
0039             activity.start.connect(start)
0040             activity.stop.connect(stop)
0041         }
0042 
0043         // Add here the QML items you need to access in javascript
0044         QtObject {
0045             id: items
0046             property Item main: activity.main
0047             property alias background: background
0048             property int currentLevel: activity.currentLevel
0049             property alias bonus: bonus
0050             property alias score: score
0051             property bool buttonsBlocked: false
0052             property int maxSteps: 1
0053             property int targetColor1: 0
0054             property int targetColor2: 0
0055             property int targetColor3: 0
0056             property alias currentColor1: color1.currentStep
0057             property alias currentColor2: color2.currentStep
0058             property alias currentColor3: color3.currentStep
0059             property int margins: 20
0060             property int chooserHeight: Math.min(background.height * 0.2,
0061                                                  background.width * 0.2)
0062         }
0063 
0064         onStart: {
0065             Activity.start(items)
0066         }
0067         onStop: {
0068             Activity.stop()
0069         }
0070 
0071         Rectangle {
0072             id: target
0073             height: width / 2.5
0074             width: parent.width / 5
0075             radius: height / 10
0076             anchors {
0077                 top: parent.top
0078                 topMargin: items.margins
0079                 horizontalCenter: parent.horizontalCenter
0080             }
0081             border.color: "#2a2a2a"
0082             border.width: 0
0083             color: Activity.getColor(items.targetColor1, items.targetColor2,
0084                                      items.targetColor3)
0085         }
0086 
0087         GCText {
0088             text: qsTr("Match the color")
0089             color: "#2a2a2a"
0090             horizontalAlignment: Text.AlignRight
0091             wrapMode: Text.WordWrap
0092             fontSizeMode: Text.Fit
0093             anchors {
0094                 top: target.top
0095                 right: target.left
0096                 left: parent.left
0097                 rightMargin: items.margins
0098             }
0099         }
0100 
0101         GCText {
0102             id: helpMessage
0103             text: ""
0104             fontSizeMode: Text.Fit
0105             horizontalAlignment: Text.AlignLeft
0106             wrapMode: Text.WordWrap
0107             anchors {
0108                 top: target.top
0109                 left: target.right
0110                 right: parent.right
0111                 leftMargin: items.margins
0112                 bottom: result.top
0113             }
0114         }
0115         Rectangle {
0116             id: result
0117             height: width
0118             width: Math.min(target.width * 0.75, 90 * ApplicationInfo.ratio)
0119             radius: height / 2
0120 
0121             anchors {
0122                 horizontalCenter: parent.horizontalCenter
0123                 top: target.bottom
0124                 topMargin: (background.height - items.chooserHeight * 4) / 3
0125             }
0126             border.color: "#2a2a2a"
0127             border.width: 0
0128             color: Activity.getColor(items.currentColor1, items.currentColor2,
0129                                      items.currentColor3)
0130         }
0131 
0132         ColorChooser {
0133             id: color1
0134             brushHue: activity.modeRGB ? "-r" : "-m" /* red / magenta */
0135             source: Activity.url + (activity.modeRGB ? "flashlight-red.svg" : "tube-magenta.svg")
0136             sourceSize.height: items.chooserHeight
0137             maxSteps: items.maxSteps
0138             anchors {
0139                 right: result.left
0140                 rightMargin: items.margins
0141                 verticalCenter: result.verticalCenter
0142             }
0143         }
0144 
0145         ColorChooser {
0146             id: color2
0147             brushHue: activity.modeRGB ? "-g" : "-y" /* green / yellow */
0148             source: Activity.url + (activity.modeRGB ? "flashlight-green.svg" : "tube-yellow.svg")
0149             sourceSize.height: items.chooserHeight
0150             maxSteps: items.maxSteps
0151             anchors {
0152                 horizontalCenter: result.horizontalCenter
0153                 top: result.bottom
0154                 topMargin: items.margins + width / 2 - height / 2
0155             }
0156             rotation: -90
0157         }
0158 
0159         ColorChooser {
0160             id: color3
0161             brushHue: activity.modeRGB ? "-b" : "-c" /* blue / cyan */
0162             source: Activity.url + (activity.modeRGB ? "flashlight-blue.svg" : "tube-cyan.svg")
0163             sourceSize.height: items.chooserHeight
0164             maxSteps: items.maxSteps
0165             anchors {
0166                 left: result.right
0167                 leftMargin: items.margins
0168                 verticalCenter: result.verticalCenter
0169             }
0170             rotation: 180
0171         }
0172 
0173         Score {
0174             id: score
0175             y: parent.height * 0.65
0176             anchors.left: parent.left
0177             anchors.right: undefined
0178             anchors.bottom: undefined
0179             currentSubLevel: 0
0180             numberOfSubLevels: 10
0181             onStop: Activity.nextSubLevel()
0182         }
0183 
0184         BarButton {
0185             id: validate
0186             source: "qrc:/gcompris/src/core/resource/bar_ok.svg"
0187             sourceSize.width: 66 * bar.barZoom
0188             visible: true
0189             enabled: !items.buttonsBlocked
0190             anchors {
0191                 right: parent.right
0192                 rightMargin: items.margins
0193                 top: color3.bottom
0194                 topMargin: items.margins
0195             }
0196             onClicked: {
0197                 var message = ""
0198                 if (activity.modeRGB) {
0199                     /* check RGB */
0200                     if (items.currentColor1 < items.targetColor1)
0201                         message += qsTr("Not enough red") + "\n"
0202                     else if (items.currentColor1 > items.targetColor1)
0203                         message += qsTr("Too much red") + "\n"
0204 
0205                     if (items.currentColor2 < items.targetColor2)
0206                         message += qsTr("Not enough green") + "\n"
0207                     else if (items.currentColor2 > items.targetColor2)
0208                         message += qsTr("Too much green") + "\n"
0209 
0210                     if (items.currentColor3 < items.targetColor3)
0211                         message += qsTr("Not enough blue") + "\n"
0212                     else if (items.currentColor3 > items.targetColor3)
0213                         message += qsTr("Too much blue") + "\n"
0214                 } else {
0215                     /* check MCY */
0216                     if (items.currentColor1 < items.targetColor1)
0217                         message += qsTr("Not enough magenta") + "\n"
0218                     else if (items.currentColor1 > items.targetColor1)
0219                         message += qsTr("Too much magenta") + "\n"
0220 
0221                     if (items.currentColor2 < items.targetColor2)
0222                         message += qsTr("Not enough yellow") + "\n"
0223                     else if (items.currentColor2 > items.targetColor2)
0224                         message += qsTr("Too much yellow") + "\n"
0225 
0226                     if (items.currentColor3 < items.targetColor3)
0227                         message += qsTr("Not enough cyan") + "\n"
0228                     else if (items.currentColor3 > items.targetColor3)
0229                         message += qsTr("Too much cyan") + "\n"
0230                 }
0231                 helpMessage.text = message
0232 
0233                 if (message === "") {
0234                     items.buttonsBlocked = true
0235                     items.score.currentSubLevel += 1
0236                     items.score.playWinAnimation()
0237                     activity.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/completetask.wav")
0238                     helpMessage.text = ""
0239                 }
0240             }
0241         }
0242 
0243         DialogHelp {
0244             id: dialogHelp
0245             onClose: home()
0246         }
0247 
0248         Bar {
0249             id: bar
0250             level: items.currentLevel + 1
0251             content: BarEnumContent {
0252                 value: help | home | level
0253             }
0254             onHelpClicked: {
0255                 displayDialog(dialogHelp)
0256             }
0257             onPreviousLevelClicked: Activity.previousLevel()
0258             onNextLevelClicked: Activity.nextLevel()
0259             onHomeClicked: activity.home()
0260         }
0261 
0262         Bonus {
0263             id: bonus
0264             Component.onCompleted: win.connect(Activity.nextLevel)
0265         }
0266     }
0267 }