qml: seedkeyboard padding, explicit keycode, backspace next to spacebar
This commit is contained in:
@@ -8,34 +8,29 @@ Item {
|
|||||||
|
|
||||||
signal keyEvent(keycode: int, text: string)
|
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 keyheight: (root.height - 2 * padding) / 4 - keyvspacing
|
||||||
property int keyhspacing: 4
|
property int keyhspacing: 4
|
||||||
property int keyvspacing: 5
|
property int keyvspacing: 5
|
||||||
|
|
||||||
function emitKeyEvent(key) {
|
function emitKeyEvent(key, keycode) {
|
||||||
var keycode
|
|
||||||
if (key == '<=') {
|
|
||||||
keycode = Qt.Key_Backspace
|
|
||||||
} else {
|
|
||||||
keycode = parseInt(key, 36) - 9 + 0x40 // map char to key code
|
|
||||||
}
|
|
||||||
keyEvent(keycode, key)
|
keyEvent(keycode, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: rootLayout
|
id: rootLayout
|
||||||
x: padding
|
x: hpadding
|
||||||
y: padding
|
y: vpadding
|
||||||
width: parent.width - 2*padding
|
width: parent.width - 2*hpadding
|
||||||
spacing: keyvspacing
|
spacing: keyvspacing
|
||||||
RowLayout {
|
RowLayout {
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
spacing: keyhspacing
|
spacing: keyhspacing
|
||||||
Repeater {
|
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 {
|
delegate: SeedKeyboardKey {
|
||||||
key: modelData
|
key: modelData
|
||||||
kbd: root
|
kbd: root
|
||||||
@@ -78,10 +73,18 @@ Item {
|
|||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
SeedKeyboardKey {
|
SeedKeyboardKey {
|
||||||
key: ' '
|
key: ' '
|
||||||
|
keycode: Qt.Key_Space
|
||||||
kbd: root
|
kbd: root
|
||||||
implicitWidth: keywidth * 5
|
implicitWidth: keywidth * 5
|
||||||
implicitHeight: keyheight
|
implicitHeight: keyheight
|
||||||
}
|
}
|
||||||
|
SeedKeyboardKey {
|
||||||
|
key: '<'
|
||||||
|
keycode: Qt.Key_Backspace
|
||||||
|
kbd: root
|
||||||
|
implicitWidth: keywidth
|
||||||
|
implicitHeight: keyheight
|
||||||
|
}
|
||||||
// spacer
|
// spacer
|
||||||
Item { Layout.preferredHeight: 1; Layout.preferredWidth: keywidth / 2 }
|
Item { Layout.preferredHeight: 1; Layout.preferredWidth: keywidth / 2 }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,18 @@ Pane {
|
|||||||
id: root
|
id: root
|
||||||
|
|
||||||
property string key
|
property string key
|
||||||
|
property int keycode: -1
|
||||||
|
|
||||||
property QtObject kbd
|
property QtObject kbd
|
||||||
padding: 1
|
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 {
|
FlatButton {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
@@ -23,12 +32,12 @@ Pane {
|
|||||||
font.pixelSize: Math.max(root.height * 1/3, constants.fontSizeSmall)
|
font.pixelSize: Math.max(root.height * 1/3, constants.fontSizeSmall)
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
kbd.emitKeyEvent(key)
|
emitKeyEvent()
|
||||||
}
|
}
|
||||||
|
|
||||||
// send keyevent again, otherwise it is ignored
|
// send keyevent again, otherwise it is ignored
|
||||||
onDoubleClicked: {
|
onDoubleClicked: {
|
||||||
kbd.emitKeyEvent(key)
|
emitKeyEvent()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user