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

0001 /* GCompris - PianoKey.qml
0002 *
0003 * SPDX-FileCopyrightText: 2018 Aman Kumar Gupta <gupta2140@gmail.com>
0004 *
0005 * Authors:
0006 *   Beth Hadley <bethmhadley@gmail.com> (GTK+ version)
0007 *   Johnny Jazeix <jazeix@gmail.com> (Qt Quick port)
0008 *   Aman Kumar Gupta <gupta2140@gmail.com> (Qt Quick port)
0009 *
0010 *   SPDX-License-Identifier: GPL-3.0-or-later
0011 */
0012 import QtQuick 2.12
0013 import GCompris 1.0
0014 
0015 import "../../core"
0016 
0017 Rectangle {
0018     id: pianoKey
0019 
0020     property string noteColor
0021     // keyName is an array of 2 elements. The 1st index has the "actual" key name, while the 2nd index has the translated one.
0022     property var keyName
0023     property real labelSquareSize
0024     property bool labelsVisible
0025     property bool isKeyEnabled: true
0026 
0027     signal keyPressed
0028 
0029     SequentialAnimation {
0030         id: keyPressAnimation
0031         NumberAnimation {
0032             target: pianoKey
0033             property: "scale"
0034             duration: 250
0035             to: 0.9
0036         }
0037         NumberAnimation {
0038             target: pianoKey
0039             property: "scale"
0040             duration: 250
0041             to: 1
0042         }
0043     }
0044 
0045     border.color: "black"
0046     Rectangle {
0047         width: labelSquareSize
0048         height: width
0049         anchors.bottom: pianoKey.bottom
0050         anchors.horizontalCenter: pianoKey.horizontalCenter
0051         color: ((keyName[0] != undefined) && (piano.coloredKeyLabels.indexOf(keyName[0][0]) != -1)) ? (piano.labelsColor === "inbuilt" ? noteColor : labelsColor) : "white"
0052         anchors.margins: 4
0053         border.color: "black"
0054         border.width: 2
0055         radius: 5
0056         visible: labelsVisible
0057         GCText {
0058             anchors.fill: parent
0059             text: keyName[1] != undefined ? keyName[1] : ""
0060             fontSizeMode: Text.Fit
0061             horizontalAlignment: Text.AlignHCenter
0062             verticalAlignment: Text.AlignVCenter
0063         }
0064     }
0065 
0066     MouseArea {
0067         anchors.fill: parent
0068         onPressed: {
0069             if(pianoKey.isKeyEnabled) {
0070                 keyPressed()
0071                 pianoKey.scale = 0.95
0072             }
0073         }
0074         onReleased: pianoKey.scale = 1
0075     }
0076 }