Debian Codegraph @

src/QML/Key.qml

raw
1 import QtQuick 2.0
2
3 Rectangle {
4 id: key
5
6 width: root.width/numkeys
7 height: root.height
8 radius: 1;
9 color: !checked ? "white" : "gray"
10 border.color: "black"
11 border.width: 1
12
13 property bool checked: false
14 property bool enabled: true
15 property bool blackKey: false
16 property int numkeys: root.numOctaves * 7 + 1
17
18 function mouseOn() {
19 if (!root.latch) {
20 key.checked = !key.checked
21 } else {
22 key.checked = key.checked
23 }
24 }
25
26 function mouseOff() {
27 if (!root.latch) {
28 key.checked = !key.checked
29 }
30 }
31
32 MouseArea {
33 id: mouseArea
34 anchors.fill: parent
35 hoverEnabled: key.enabled
36 enabled: key.enabled
37 onPressed: {
38 root.mouseHeld = true
39 mouseOn()
40 }
41 onReleased: {
42 root.mouseHeld = false
43 if (key.checked) {
44 mouseOff()
45 }
46 }
47 onEntered: {
48 // console.log("Entered")
49 if (root.mouseHeld) {
50 mouseOn()
51 }
52 }
53 onExited: {
54 if (key.checked) {
55 mouseOff()
56 }
57 }
58 }
59 onCheckedChanged: {
60 var notenum = blackKey ? index + 0.5:index
61 if (checked) {
62 root.turnon(notenum)
63 } else {
64 root.turnoff(notenum)
65 }
66 }
67 }