Browse Source

qml: add SeedKeyboard for seed entry without using system virtual keyboard

master
Sander van Grieken 3 years ago
parent
commit
9ac83f6d9f
  1. 90
      electrum/gui/qml/components/controls/SeedKeyboard.qml
  2. 34
      electrum/gui/qml/components/controls/SeedKeyboardKey.qml
  3. 18
      electrum/gui/qml/components/controls/SeedTextArea.qml

90
electrum/gui/qml/components/controls/SeedKeyboard.qml

@ -0,0 +1,90 @@
import QtQuick 2.15
import QtQuick.Layouts 1.0
import QtQuick.Controls 2.15
import QtQuick.Controls.Material 2.0
Item {
id: root
signal keyEvent(keycode: int, text: string)
property int padding: 15
property int keywidth: (root.width - 2 * padding) / 11 - 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
}
keyEvent(keycode, key)
}
ColumnLayout {
id: rootLayout
x: padding
y: padding
width: parent.width - 2*padding
spacing: keyvspacing
RowLayout {
Layout.alignment: Qt.AlignHCenter
spacing: keyhspacing
Repeater {
model: ['q','w','e','r','t','y','u','i','o','p','<=']
delegate: SeedKeyboardKey {
key: modelData
kbd: root
implicitWidth: keywidth
implicitHeight: keyheight
}
}
}
RowLayout {
Layout.alignment: Qt.AlignHCenter
spacing: keyhspacing
Repeater {
model: ['a','s','d','f','g','h','j','k','l']
delegate: SeedKeyboardKey {
key: modelData
kbd: root
implicitWidth: keywidth
implicitHeight: keyheight
}
}
// spacer
Item { Layout.preferredHeight: 1; Layout.preferredWidth: keywidth / 2 }
}
RowLayout {
Layout.alignment: Qt.AlignHCenter
spacing: keyhspacing
Repeater {
model: ['z','x','c','v','b','n','m']
delegate: SeedKeyboardKey {
key: modelData
kbd: root
implicitWidth: keywidth
implicitHeight: keyheight
}
}
// spacer
Item { Layout.preferredHeight: 1; Layout.preferredWidth: keywidth }
}
RowLayout {
Layout.alignment: Qt.AlignHCenter
SeedKeyboardKey {
key: ' '
kbd: root
implicitWidth: keywidth * 5
implicitHeight: keyheight
}
// spacer
Item { Layout.preferredHeight: 1; Layout.preferredWidth: keywidth / 2 }
}
}
}

34
electrum/gui/qml/components/controls/SeedKeyboardKey.qml

@ -0,0 +1,34 @@
import QtQuick 2.15
import QtQuick.Layouts 1.0
import QtQuick.Controls 2.15
import QtQuick.Controls.Material 2.0
Pane {
id: root
property string key
property QtObject kbd
padding: 1
FlatButton {
anchors.fill: parent
focusPolicy: Qt.NoFocus
autoRepeat: true
autoRepeatDelay: 750
text: key
padding: 0
font.pixelSize: Math.max(root.height * 1/3, constants.fontSizeSmall)
onClicked: {
kbd.emitKeyEvent(key)
}
// send keyevent again, otherwise it is ignored
onDoubleClicked: {
kbd.emitKeyEvent(key)
}
}
}

18
electrum/gui/qml/components/controls/SeedTextArea.qml

@ -11,7 +11,7 @@ Pane {
padding: 0
property string text
property alias readOnly: seedtextarea.readOnly
property bool readOnly: false
property alias placeholderText: seedtextarea.placeholderText
property var _suggestions: []
@ -83,6 +83,7 @@ Pane {
font.pixelSize: constants.fontSizeLarge
font.family: FixedFont
inputMethodHints: Qt.ImhSensitiveData | Qt.ImhLowercaseOnly | Qt.ImhNoPredictiveText
readOnly: true
background: Rectangle {
color: constants.darkerBackground
@ -100,6 +101,21 @@ Pane {
cursorPosition = text.length
}
}
SeedKeyboard {
id: kbd
Layout.fillWidth: true
Layout.preferredHeight: kbd.width / 2
visible: !root.readOnly
onKeyEvent: {
if (keycode == Qt.Key_Backspace) {
if (seedtextarea.text.length > 0)
seedtextarea.text = seedtextarea.text.substring(0, seedtextarea.text.length-1)
} else {
seedtextarea.text = seedtextarea.text + text
}
}
}
}
FontMetrics {

Loading…
Cancel
Save