From c928a3556fd0abfeac94b9fe0888acfc99ad7816 Mon Sep 17 00:00:00 2001 From: Henk Kalkwater Date: Mon, 18 May 2020 12:54:49 +0200 Subject: [PATCH] Added proper Virtual Keyboard support --- Main.qml | 2 +- Style.qml | 1 + components/PasswordOverlay.qml | 134 ++++++++++++++++++++++++++------- components/VirtualKeyboard.qml | 9 +++ 4 files changed, 116 insertions(+), 30 deletions(-) create mode 100644 components/VirtualKeyboard.qml diff --git a/Main.qml b/Main.qml index d527702..19555c3 100644 --- a/Main.qml +++ b/Main.qml @@ -1,5 +1,5 @@ import QtQuick 2.0 -import QtGamepad 1.0 +//import QtGamepad 1.0 import SddmComponents 2.0 import "components" diff --git a/Style.qml b/Style.qml index 5acef8f..7454c54 100644 --- a/Style.qml +++ b/Style.qml @@ -24,4 +24,5 @@ QtObject { property int fontNormalSize: 24 property string background: config.background ? config.background : Qt.resolvedUrl("bg.png") + property bool virtualKeyboard: true } diff --git a/components/PasswordOverlay.qml b/components/PasswordOverlay.qml index 3b2259e..2ec4070 100644 --- a/components/PasswordOverlay.qml +++ b/components/PasswordOverlay.qml @@ -1,6 +1,7 @@ import QtQuick 2.6 import QtQuick.Controls 2.6 + import ".." FocusScope { @@ -22,42 +23,117 @@ FocusScope { Rectangle { anchors.fill: parent color: Style.overlayColor - - TextField { - focus: true - //anchors.top: parent.top - property real _vkeyboardOffset: Qt.inputMethod.visible - ? root.height - Qt.inputMethod.keyboardRectangle.top : 0 - y: (parent.height - _vkeyboardOffset) / 2 - height / 2 - Behavior on y { NumberAnimation { duration: 100 }} - + Item { anchors.left: parent.left + anchors.top: parent.top anchors.right: parent.right - //anchors.topMargin: Style.horizontalPadding - anchors.leftMargin: Style.horizontalContentPadding - anchors.rightMargin: Style.horizontalContentPadding + anchors.bottom: virtualKeyboard.top + TextField { + id: passwordField + focus: true + //anchors.top: parent.top + /*property real _vkeyboardOffset: Qt.inputMethod.visible + ? root.height - Qt.inputMethod.keyboardRectangle.top : 0 + y: (parent.height - _vkeyboardOffset) / 2 - height / 2*/ + Behavior on y { NumberAnimation { duration: 100 }} + + anchors.left: parent.left + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + //anchors.topMargin: Style.horizontalPadding + anchors.leftMargin: Style.horizontalContentPadding + anchors.rightMargin: Style.horizontalContentPadding + + padding: Style.mediumPadding + color: Style.foregroundColor + echoMode: TextInput.Password + + placeholderText: "Enter the password for %1".arg(username) + //color: Style.foregroundColor + font.pixelSize: Style.fontTitleSize + + background: Rectangle { + color: "#00000000" + border.width: Style.highlightBorderSize + border.color: Style.backgroundColor2 + } + + Keys.onEscapePressed: cancelled() + + + onAccepted: { + passwordEntered(text) + text = "" + } + } + } + // Optional virtual keyboard + Loader { + id: virtualKeyboard + source: Qt.resolvedUrl("VirtualKeyboard.qml") + width: parent.width + anchors.bottom: parent.bottom - padding: Style.mediumPadding - color: Style.foregroundColor - echoMode: TextInput.Password - - placeholderText: "Enter the password for %1".arg(username) - //color: Style.foregroundColor - font.pixelSize: Style.fontTitleSize - - background: Rectangle { - color: "#00000000" - border.width: Style.highlightBorderSize - border.color: Style.backgroundColor2 + onLoaded: { + item.activated = Style.virtualKeyboard + Qt.inputMethod.show() + //state = "visible" } - Keys.onEscapePressed: cancelled() + //opacity: item ? item.visible ? 1 : 0 : 0 + state: item ? (item.active ? "visible" : "hidden" ) : "hidden" + states: [ + State { + name: "visible" + PropertyChanges { + target: virtualKeyboard + anchors.bottomMargin: 0 + } + }, + State { + name: "hidden" + PropertyChanges { + target: virtualKeyboard + anchors.bottomMargin: -virtualKeyboard.height + } + } + ] - onAccepted: { - passwordEntered(text) - text = "" - } + transitions: [ + Transition { + from: "visible" + to: "hidden" + + SequentialAnimation { + NumberAnimation { + target: virtualKeyboard + property: "anchors.bottomMargin" + duration: 250 + easing.type: Easing.InQuad + } + ScriptAction { + script: Qt.inputMethod.hide() + } + } + }, + Transition { + from: "hidden" + to: "visible" + + SequentialAnimation { + ScriptAction { + script: Qt.inputMethod.show() + } + NumberAnimation { + target: virtualKeyboard + property: "anchors.bottomMargin" + duration: 250 + easing.type: Easing.OutQuad + } + } + } + ] } } } diff --git a/components/VirtualKeyboard.qml b/components/VirtualKeyboard.qml new file mode 100644 index 0000000..9e4e547 --- /dev/null +++ b/components/VirtualKeyboard.qml @@ -0,0 +1,9 @@ +import QtQuick 2.6 +import QtQuick.VirtualKeyboard 2.4 + +InputPanel { + id: virtualKeyboard + property bool activated: false + active: Qt.inputMethod.visible && activated + //visible: active +}