Skip to content

Latest commit

 

History

History
167 lines (138 loc) · 5.35 KB

Keyboard.qml

File metadata and controls

167 lines (138 loc) · 5.35 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
Copyright 2011-2012 Heikki Holstila <heikki.holstila@gmail.com>
This file is part of FingerTerm.
FingerTerm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
FingerTerm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FingerTerm. If not, see <http://www.gnu.org/licenses/>.
*/
20
import QtQuick 2.0
22
Item {
25
property int keyModifiers
26
27
28
property Key resetSticky
property Key currentStickyPressed
property Key currentKeyPressed
30
property string keyFgColor: "#ffffff"
31
32
33
34
property string keyBgColor: "#202020"
property string keyHilightBgColor: "#ffffff"
property string keyBorderColor: "#303030"
37
property bool active
39
property int outmargins: util.keyboardMargins
40
41
42
43
property int keyspacing: 6
property int keysPerRow: keyLoader.vkbColumns()
property real keywidth: (keyboard.width - keyspacing*keysPerRow - outmargins*2)/keysPerRow;
44
width: parent.width
45
height: keyboardLoader.height + outmargins
47
48
Component {
id: keyboardContents
53
54
x: (keyboard.width-width)/2
spacing: keyboard.keyspacing
56
57
Repeater {
id: rowRepeater
59
60
61
62
63
model: keyLoader.vkbRows()
delegate: Row {
spacing: keyboard.keyspacing
Repeater {
id: colRepeater
65
66
67
property int rowIndex: index
model: keyLoader.vkbColumns()
delegate: Key {
68
property var keydata: keyLoader.keyAt(colRepeater.rowIndex, index)
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
label: keydata[0]
code: keydata[1]
label_alt: keydata[2]
code_alt: keydata[3]
width: keyboard.keywidth * keydata[4] + ((keydata[4]-1)*keyboard.keyspacing) + 1
sticky: keydata[5]
}
}
}
}
}
}
Loader {
id: keyboardLoader
}
Component.onCompleted: {
keyboardLoader.sourceComponent = keyboardContents;
}
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
Rectangle {
// visual key press feedback...
id: visualKeyFeedbackRect
property alias label: label.text
property var _key: (currentKeyPressed
&& currentKeyPressed.currentLabel.length === 1
&& currentKeyPressed.currentLabel !== " ")
? currentKeyPressed : null
visible: _key || visualFeedbackDelay.running
radius: window.radiusSmall
color: keyFgColor
Text {
id: label
color: keyBgColor
font.pointSize: 34*window.pixelRatio
anchors.centerIn: parent
}
Timer {
id: visualFeedbackDelay
interval: feedbackDuration
}
on_KeyChanged: {
if (_key) {
visualKeyFeedbackRect.label = _key.currentLabel
visualKeyFeedbackRect.width = _key.width * 1.5
visualKeyFeedbackRect.height = _key.height * 1.5
var mappedCoord = keyboard.mapFromItem(_key, 0, 0);
visualKeyFeedbackRect.x = mappedCoord.x - (visualKeyFeedbackRect.width-_key.width)/2
visualKeyFeedbackRect.y = mappedCoord.y - _key.height*1.5
visualFeedbackDelay.restart()
}
127
128
129
130
Connections {
target: util
onKeyboardLayoutChanged: {
var ret = keyLoader.loadLayout(util.keyboardLayout)
132
133
134
135
136
137
138
showErrorMessage("There was an error loading the keyboard layout.<br>\nUsing the default one instead.");
util.keyboardLayout = "english"
ret = keyLoader.loadLayout(":/data/english.layout"); //try the default as a fallback (load from resources to ensure it will succeed)
if (!ret) {
console.log("keyboard layout fail");
Qt.quit();
}
141
142
143
// makes the keyboard component reload itself with new data
keyboardLoader.sourceComponent = undefined
keyboardLoader.sourceComponent = keyboardContents
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//borrowed from nemo-keyboard
//Parameters: (x, y) in view coordinates
function keyAt(x, y) {
var item = keyboard
x -= keyboard.x
y -= keyboard.y
while ((item = item.childAt(x, y)) != null) {
//return the first "Key" element we find
if (typeof item.currentCode !== 'undefined') {
return item
}
// Cheaper mapToItem, assuming we're not using anything fancy.
x -= item.x
y -= item.y
}
return null
}