From fa790f59ec52b36ef4c25905073c3b0069deb08d Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 23 Jul 2017 20:05:31 +0200 Subject: Keyboard focus handling --- components/kube/contents/ui/AddresseeListEditor.qml | 12 ++++++++++-- framework/qml/AutocompleteLineEdit.qml | 21 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/components/kube/contents/ui/AddresseeListEditor.qml b/components/kube/contents/ui/AddresseeListEditor.qml index 1f106dfd..25916315 100644 --- a/components/kube/contents/ui/AddresseeListEditor.qml +++ b/components/kube/contents/ui/AddresseeListEditor.qml @@ -24,7 +24,7 @@ import QtQuick.Layouts 1.1 import org.kube.framework 1.0 as Kube -Item { +FocusScope { id: root property variant completer property alias model: listView.model @@ -78,14 +78,16 @@ Item { } } - Item { + FocusScope { height: Kube.Units.gridUnit * Kube.Units.smallSpacing * 2 width: parent.width + focus: true Kube.TextButton { id: button text: "+ " + qsTr("Add recipient") color: Kube.Colors.highlightColor + focus: true onClicked: { lineEdit.visible = true lineEdit.forceActiveFocus() @@ -107,6 +109,12 @@ Item { root.added(text); clear() visible = false + button.forceActiveFocus() + } + onAborted: { + clear() + visible = false + button.forceActiveFocus() } } } diff --git a/framework/qml/AutocompleteLineEdit.qml b/framework/qml/AutocompleteLineEdit.qml index f963095a..1be8f7eb 100644 --- a/framework/qml/AutocompleteLineEdit.qml +++ b/framework/qml/AutocompleteLineEdit.qml @@ -30,6 +30,8 @@ Kube.TextField { property string searchTerm property variant model + signal aborted() + selectByMouse: true onTextChanged: { @@ -38,9 +40,17 @@ Kube.TextField { startCompleting() } else { searchTerm = "" - abort() + popup.close() } } + + onEditingFinished: { + console.warn("on editing finished") + accept() + } + + validator: RegExpValidator { regExp: /.+/ } + Keys.onDownPressed: { listView.incrementCurrentIndex() } @@ -58,7 +68,11 @@ Kube.TextField { } } Keys.onReturnPressed: { - accept() + if (acceptableInput) { + accept() + } else { + abort() + } } Keys.onEscapePressed: { abort() @@ -76,11 +90,12 @@ Kube.TextField { root.text = listView.currentItem.text; } popup.close() - root.accepted(); + root.accepted() } function abort() { popup.close() + root.aborted() } Controls2.Popup { -- cgit v1.2.3