From c2e0616804dddeb53a939ea90015a422e5f0b401 Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Sun, 29 Apr 2018 16:55:08 -0700 Subject: [PATCH] Work on getting keyboard focus to right place --- src/FactSystem/FactControls/FactTextField.qml | 5 ---- src/QmlControls/ParameterEditorDialog.qml | 21 +++++++------ src/QmlControls/QGCTextField.qml | 30 ++++++++----------- src/QmlControls/QGCView.qml | 1 + src/QmlControls/QGCViewDialog.qml | 2 -- src/QmlControls/QGCViewDialogContainer.qml | 8 +++-- 6 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/FactSystem/FactControls/FactTextField.qml b/src/FactSystem/FactControls/FactTextField.qml index f17ea565c..ab66d9f2d 100644 --- a/src/FactSystem/FactControls/FactTextField.qml +++ b/src/FactSystem/FactControls/FactTextField.qml @@ -20,16 +20,11 @@ QGCTextField { property string _validateString - // At this point all Facts are numeric inputMethodHints: ((fact && fact.typeIsString) || ScreenTools.isiOS) ? Qt.ImhNone : // iOS numeric keyboard has no done button, we can't use it Qt.ImhFormattedNumbersOnly // Forces use of virtual numeric keyboard onEditingFinished: { - if (ScreenTools.isMobile) { - // Toss focus on mobile after Done on virtual keyboard. Prevent strange interactions. - focus = false - } if (typeof qgcView !== 'undefined' && qgcView) { var errorString = fact.validate(text, false /* convertOnly */) if (errorString === "") { diff --git a/src/QmlControls/ParameterEditorDialog.qml b/src/QmlControls/ParameterEditorDialog.qml index 4a97a174d..404a747d6 100644 --- a/src/QmlControls/ParameterEditorDialog.qml +++ b/src/QmlControls/ParameterEditorDialog.qml @@ -20,13 +20,16 @@ import QGroundControl.FactControls 1.0 import QGroundControl.ScreenTools 1.0 QGCViewDialog { - id: root + id: root + focus: true property Fact fact property bool showRCToParam: false property bool validate: false property string validateValue + signal valueChanged + property real _editFieldWidth: ScreenTools.defaultFontPixelWidth * 20 property bool _longDescriptionAvailable: fact.longDescription != "" property bool _editingParameter: fact.componentId != 0 @@ -41,15 +44,18 @@ QGCViewDialog { if (bitmaskColumn.visible && !manualEntry.checked) { fact.value = bitmaskValue(); fact.valueChanged(fact.value) + valueChanged() hideDialog(); } else if (factCombo.visible && !manualEntry.checked) { fact.enumIndex = factCombo.currentIndex + valueChanged() hideDialog() } else { var errorString = fact.validate(valueField.text, forceSave.checked) if (errorString === "") { fact.value = valueField.text fact.valueChanged(fact.value) + valueChanged() hideDialog() } else { validationError.text = errorString @@ -85,12 +91,8 @@ QGCViewDialog { } } - // set focus to the text field when becoming visible (in case of an Enum, - // the valueField is not visible, but it's not an issue because the combo - // box cannot have a focus) - onVisibleChanged: if (visible && !ScreenTools.isMobile) valueField.forceActiveFocus() - QGCFlickable { + id: flickable anchors.fill: parent contentHeight: _column.y + _column.height flickableDirection: Flickable.VerticalFlick @@ -120,9 +122,10 @@ QGCViewDialog { unitsLabel: fact.units showUnits: fact.units != "" Layout.fillWidth: true - inputMethodHints: ScreenTools.isiOS ? - Qt.ImhNone : // iOS numeric keyboard has not done button, we can't use it - Qt.ImhFormattedNumbersOnly // Forces use of virtual numeric keyboard + focus: true + inputMethodHints: (fact.typeIsString || ScreenTools.isiOS) ? + Qt.ImhNone : // iOS numeric keyboard has no done button, we can't use it + Qt.ImhFormattedNumbersOnly // Forces use of virtual numeric keyboard } QGCButton { diff --git a/src/QmlControls/QGCTextField.qml b/src/QmlControls/QGCTextField.qml index 459a775bc..f1a78e0b0 100644 --- a/src/QmlControls/QGCTextField.qml +++ b/src/QmlControls/QGCTextField.qml @@ -7,7 +7,10 @@ import QGroundControl.Palette 1.0 import QGroundControl.ScreenTools 1.0 TextField { - id: root + id: root + textColor: qgcPal.textFieldText + implicitHeight: ScreenTools.implicitTextFieldHeight + activeFocusOnPress: true property bool showUnits: false property bool showHelp: false @@ -17,18 +20,11 @@ TextField { property real _helpLayoutWidth: 0 - Component.onCompleted: { - if (typeof qgcTextFieldforwardKeysTo !== 'undefined') { - root.Keys.forwardTo = [qgcTextFieldforwardKeysTo] - } - } + Component.onCompleted: selectAllIfActiveFocus() + onActiveFocusChanged: selectAllIfActiveFocus() QGCPalette { id: qgcPal; colorGroupEnabled: enabled } - textColor: qgcPal.textFieldText - - implicitHeight: ScreenTools.implicitTextFieldHeight - onEditingFinished: { if (ScreenTools.isMobile) { // Toss focus on mobile after Done on virtual keyboard. Prevent strange interactions. @@ -36,6 +32,12 @@ TextField { } } + function selectAllIfActiveFocus() { + if (activeFocus) { + selectAll() + } + } + QGCLabel { id: unitsLabelWidthGenerator text: unitsLabel @@ -59,7 +61,7 @@ TextField { Rectangle { anchors.fill: parent - border.color: control.activeFocus ? "#47b" : "#999" + border.color: root.activeFocus ? "#47b" : "#999" color: qgcPal.textField } @@ -114,10 +116,4 @@ TextField { padding.right: control._helpLayoutWidth //control.showUnits ? unitsLabelWidthGenerator.width : control.__contentHeight * 0.333 } - - onActiveFocusChanged: { - if (activeFocus) { - selectAll() - } - } } diff --git a/src/QmlControls/QGCView.qml b/src/QmlControls/QGCView.qml index b50ac571e..4a4c2cef3 100644 --- a/src/QmlControls/QGCView.qml +++ b/src/QmlControls/QGCView.qml @@ -68,6 +68,7 @@ FactPanel { "viewPanel": viewPanel }) dialog.setupDialogButtons(buttons) + dialog.focus = true viewPanel.enabled = false } diff --git a/src/QmlControls/QGCViewDialog.qml b/src/QmlControls/QGCViewDialog.qml index 0c1e02b1c..228432734 100644 --- a/src/QmlControls/QGCViewDialog.qml +++ b/src/QmlControls/QGCViewDialog.qml @@ -17,8 +17,6 @@ import QGroundControl.FactControls 1.0 import QGroundControl.ScreenTools 1.0 FactPanel { - property var qgcTextFieldforwardKeysTo: this ///< Causes all QGCTextFields to forward keys here if they have focus - property real defaultTextWidth: ScreenTools.defaultFontPixelWidth property real defaultTextHeight: ScreenTools.defaultFontPixelHeight diff --git a/src/QmlControls/QGCViewDialogContainer.qml b/src/QmlControls/QGCViewDialogContainer.qml index dda82095d..f22dc7a55 100644 --- a/src/QmlControls/QGCViewDialogContainer.qml +++ b/src/QmlControls/QGCViewDialogContainer.qml @@ -15,9 +15,10 @@ import QGroundControl.Controls 1.0 import QGroundControl.Palette 1.0 import QGroundControl.ScreenTools 1.0 -Item { - id: _root - z: 5000 +FocusScope { + id: _root + z: 5000 + focus: true property alias dialogWidth: _dialogPanel.width property alias dialogTitle: titleLabel.text @@ -182,6 +183,7 @@ Item { anchors.top: _spacer.bottom anchors.bottom: parent.bottom sourceComponent: _dialogComponent + focus: true property bool acceptAllowed: _acceptButton.visible property bool rejectAllowed: _rejectButton.visible -- 2.22.0