From 30079c06a8b01feeefd713dc18f28219bc4f4842 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Mon, 2 Jan 2023 17:00:40 +0100 Subject: [PATCH] qml: handle android back button in wizard, map to prev page action instead of closing wizard. Also add initial focus to WCHaveSeed and WCHaveMasterKey wizard components. --- .../gui/qml/components/wizard/WCHaveMasterKey.qml | 2 +- electrum/gui/qml/components/wizard/WCHaveSeed.qml | 1 + electrum/gui/qml/components/wizard/Wizard.qml | 12 ++++++++++++ .../gui/qml/components/wizard/WizardComponent.qml | 5 +++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/electrum/gui/qml/components/wizard/WCHaveMasterKey.qml b/electrum/gui/qml/components/wizard/WCHaveMasterKey.qml index 1689d7e13..4cfa74f98 100644 --- a/electrum/gui/qml/components/wizard/WCHaveMasterKey.qml +++ b/electrum/gui/qml/components/wizard/WCHaveMasterKey.qml @@ -114,7 +114,6 @@ WizardComponent { Layout.fillWidth: true Layout.minimumHeight: 80 font.family: FixedFont - focus: true wrapMode: TextEdit.WrapAnywhere onTextChanged: { if (activeFocus) @@ -194,5 +193,6 @@ WizardComponent { cosigner = wizard_data['multisig_current_cosigner'] participants = wizard_data['multisig_participants'] } + Qt.callLater(masterkey_ta.forceActiveFocus) } } diff --git a/electrum/gui/qml/components/wizard/WCHaveSeed.qml b/electrum/gui/qml/components/wizard/WCHaveSeed.qml index 59342242a..ca08de3e2 100644 --- a/electrum/gui/qml/components/wizard/WCHaveSeed.qml +++ b/electrum/gui/qml/components/wizard/WCHaveSeed.qml @@ -241,6 +241,7 @@ WizardComponent { cosigner = wizard_data['multisig_current_cosigner'] } setSeedTypeHelpText() + Qt.callLater(seedtext.forceActiveFocus) } } diff --git a/electrum/gui/qml/components/wizard/Wizard.qml b/electrum/gui/qml/components/wizard/Wizard.qml index fc16422df..4597e903b 100644 --- a/electrum/gui/qml/components/wizard/Wizard.qml +++ b/electrum/gui/qml/components/wizard/Wizard.qml @@ -15,6 +15,10 @@ ElDialog { title: wizardTitle + (pages.currentItem.title ? ' - ' + pages.currentItem.title : '') iconSource: '../../../icons/electrum.png' + // android back button triggers close() on Popups. Disabling close here, + // we handle that via Keys.onReleased event handler in the root layout. + closePolicy: Popup.NoAutoClose + property string wizardTitle property var wizard_data @@ -86,6 +90,14 @@ ElDialog { anchors.fill: parent spacing: 0 + // root Item in Wizard, capture back button here and delegate to main + Keys.onReleased: { + if (event.key == Qt.Key_Back) { + console.log("Back button within wizard") + app.close() // this handles unwind of dialogs/stack + } + } + SwipeView { id: pages Layout.fillWidth: true diff --git a/electrum/gui/qml/components/wizard/WizardComponent.qml b/electrum/gui/qml/components/wizard/WizardComponent.qml index 5a04bba3d..3f841f8cb 100644 --- a/electrum/gui/qml/components/wizard/WizardComponent.qml +++ b/electrum/gui/qml/components/wizard/WizardComponent.qml @@ -1,6 +1,7 @@ import QtQuick 2.0 Item { + id: root signal next signal prev signal accept @@ -28,6 +29,10 @@ Item { // wizard_data keys if apply() depends on variables set in descendant // Component.onCompleted handler. Qt.callLater(checkIsLast) + + // move focus to root of WizardComponent, otherwise Android back button + // might be missed in Wizard root Item. + root.forceActiveFocus() } }