-
Notifications
You must be signed in to change notification settings - Fork 4
/
KeyboardKey.qml
130 lines (128 loc) · 3.81 KB
/
KeyboardKey.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// This code is by Nathaniel van Diepen and used with permission.
// under the MIT license.
// https://github.com/Eeems/oxidize/blob/master/LICENSE.md
import QtQuick 2.9
import "."
Item {
id: root
clip: true
property string text: ""
property string shifttext: text
property string alttext: text
property string ctrltext: text
property string metatext: text
property string shiftalttext: shifttext
property string shiftctrltext: shifttext
property string shiftmetatext: shifttext
property string altctrltext: alttext
property string altmetatext: alttext
property string ctrlmetatext: alttext
property string shiftaltctrltext: shiftalttext
property string shiftaltmetatext: shiftalttext
property string shiftctrlmetatext: shiftctrltext
property string shiftaltctrlmetatext: shiftalttext
property bool repeatOnHold: true
property int holdInterval: 100
property int key: 0
property string value: null
property int size: 1
property int basesize: 90
property int fontsize: 8
signal click(Item item)
signal hold(Item item)
signal release(Item item)
property bool toggle: false
width: size * basesize
height: basesize
function state() {
return button.state;
}
function getText(){
if(keyboard.hasShift && keyboard.hasAlt && keyboard.hasCtrl){
return shiftaltctrltext;
}
if(keyboard.hasShift && keyboard.hasAlt){
return shiftalttext;
}
if(keyboard.hasShift && keyboard.hasCtrl){
return shiftctrltext;
}
if(keyboard.hasAlt && keyboard.hasCtrl){
return altctrltext;
}
if(keyboard.hasShift){
return shifttext;
}
if(keyboard.hasAlt){
return alttext;
}
if(keyboard.hasCtrl){
return ctrltext;
}
return text;
}
function doClick(){
if(root.click(root) !== false){
var modifiers = Qt.NoModifier;
if(keyboard.hasShift){
modifiers = modifiers | Qt.ShiftModifier;
}
if(keyboard.hasAlt){
modifiers = modifiers | Qt.AltModifier;
}
if(keyboard.hasCtrl){
modifiers = modifiers | Qt.ControlModifier;
}
if(keyboard.hasMeta){
modifiers = modifiers | Qt.MetaModifier;
}
if(root.key > 0){
keyboard.keyPress(root.key, modifiers, root.value);
}else{
var text = root.getText();
if(text.length > 1){
keyboard.stringPress(text, modifiers, text);
}else{
keyboard.charPress(text, modifiers);
}
}
if(!root.toggle){
if (!keyboard.hasCaps) {
keyboard.hasShift = false;
}
keyboard.hasAlt = false;
keyboard.hasCtrl = false;
keyboard.hasMeta =false;
}
}
}
Button {
id: button
text: root.getText()
anchors.fill: parent
fontsize: root.fontsize
toggle: root.toggle
color: "white"
backgroundColor: "transparent"
borderColor: "transparent"
selectedColor: "black"
selectedBackgroundColor: "white"
selectedBorderColor: "white"
borderwidth: 3
onClick: root.doClick()
onHold: {
root.hold(this);
root.repeatOnHold && timer.start();
}
onRelease: {
root.release(this);
root.repeatOnHold && timer.stop();
}
}
Timer {
id: timer
repeat: true
interval: root.holdInterval
onTriggered: root.doClick()
}
}