1
0

qml: seedkeyboard padding, explicit keycode, backspace next to spacebar

This commit is contained in:
Sander van Grieken
2023-05-02 13:03:13 +02:00
parent 6394cdcd3b
commit b290fbd4b5
2 changed files with 27 additions and 15 deletions

View File

@@ -8,34 +8,29 @@ Item {
signal keyEvent(keycode: int, text: string)
property int padding: 15
property int hpadding: 0
property int vpadding: 15
property int keywidth: (root.width - 2 * padding) / 11 - keyhspacing
property int keywidth: (root.width - 2 * padding) / 10 - keyhspacing
property int keyheight: (root.height - 2 * padding) / 4 - keyvspacing
property int keyhspacing: 4
property int keyvspacing: 5
function emitKeyEvent(key) {
var keycode
if (key == '<=') {
keycode = Qt.Key_Backspace
} else {
keycode = parseInt(key, 36) - 9 + 0x40 // map char to key code
}
function emitKeyEvent(key, keycode) {
keyEvent(keycode, key)
}
ColumnLayout {
id: rootLayout
x: padding
y: padding
width: parent.width - 2*padding
x: hpadding
y: vpadding
width: parent.width - 2*hpadding
spacing: keyvspacing
RowLayout {
Layout.alignment: Qt.AlignHCenter
spacing: keyhspacing
Repeater {
model: ['q','w','e','r','t','y','u','i','o','p','<=']
model: ['q','w','e','r','t','y','u','i','o','p']
delegate: SeedKeyboardKey {
key: modelData
kbd: root
@@ -78,10 +73,18 @@ Item {
Layout.alignment: Qt.AlignHCenter
SeedKeyboardKey {
key: ' '
keycode: Qt.Key_Space
kbd: root
implicitWidth: keywidth * 5
implicitHeight: keyheight
}
SeedKeyboardKey {
key: '<'
keycode: Qt.Key_Backspace
kbd: root
implicitWidth: keywidth
implicitHeight: keyheight
}
// spacer
Item { Layout.preferredHeight: 1; Layout.preferredWidth: keywidth / 2 }
}

View File

@@ -7,9 +7,18 @@ Pane {
id: root
property string key
property int keycode: -1
property QtObject kbd
padding: 1
function emitKeyEvent() {
if (keycode == -1) {
keycode = parseInt(key, 36) - 9 + 0x40 // map a-z char to key code
}
kbd.keyEvent(keycode, key)
}
FlatButton {
anchors.fill: parent
@@ -23,12 +32,12 @@ Pane {
font.pixelSize: Math.max(root.height * 1/3, constants.fontSizeSmall)
onClicked: {
kbd.emitKeyEvent(key)
emitKeyEvent()
}
// send keyevent again, otherwise it is ignored
onDoubleClicked: {
kbd.emitKeyEvent(key)
emitKeyEvent()
}
}
}