From 6bdc8428a3e7aa58002ed816d1804452fd2c1c02 Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Wed, 5 Apr 2017 14:55:29 -0700 Subject: [PATCH] Use FocusScope in all the right places --- src/PlanView/MissionItemEditor.qml | 17 +++- src/PlanView/SectionHeader.qml | 64 ++++++++------- src/QmlControls/QGCComboBox.qml | 5 +- src/QmlControls/ToolStrip.qml | 122 +++++++++++++++-------------- 4 files changed, 118 insertions(+), 90 deletions(-) diff --git a/src/PlanView/MissionItemEditor.qml b/src/PlanView/MissionItemEditor.qml index 65fb84a34..c31f24b3e 100644 --- a/src/PlanView/MissionItemEditor.qml +++ b/src/PlanView/MissionItemEditor.qml @@ -41,9 +41,17 @@ Rectangle { colorGroupEnabled: enabled } - MouseArea { + FocusScope { + id: currentItemScope anchors.fill: parent - onClicked: _root.clicked() + + MouseArea { + anchors.fill: parent + onClicked: { + currentItemScope.focus = true + _root.clicked() + } + } } QGCLabel { @@ -72,7 +80,10 @@ Rectangle { QGCMouseArea { fillItem: hamburger visible: hamburger.visible - onClicked: hamburgerMenu.popup() + onClicked: { + currentItemScope.focus = true + hamburgerMenu.popup() + } Menu { id: hamburgerMenu diff --git a/src/PlanView/SectionHeader.qml b/src/PlanView/SectionHeader.qml index f39ce133b..bcc63abe3 100644 --- a/src/PlanView/SectionHeader.qml +++ b/src/PlanView/SectionHeader.qml @@ -6,12 +6,11 @@ import QtGraphicalEffects 1.0 import QGroundControl.ScreenTools 1.0 import QGroundControl.Palette 1.0 -QGCMouseArea { +FocusScope { id: _root anchors.left: parent.left anchors.right: parent.right height: column.height - onClicked: checked = !checked property alias text: label.text property bool checked: true @@ -27,38 +26,47 @@ QGCMouseArea { QGCPalette { id: qgcPal; colorGroupEnabled: true } - ColumnLayout { - id: column - anchors.left: parent.left - anchors.right: parent.right + QGCMouseArea { + anchors.fill: parent - Item { - height: _sectionSpacer - width: 1 - visible: showSpacer + onClicked: { + _root.focus = true + checked = !checked } - QGCLabel { - id: label - Layout.fillWidth: true + ColumnLayout { + id: column + anchors.left: parent.left + anchors.right: parent.right - QGCColoredImage { - id: image - width: label.height / 2 - height: width - anchors.right: parent.right - anchors.verticalCenter: parent.verticalCenter - source: "/qmlimages/arrow-down.png" - color: qgcPal.text - visible: !_root.checked + Item { + height: _sectionSpacer + width: 1 + visible: showSpacer } - } - Rectangle { - anchors.left: parent.left - anchors.right: parent.right - height: 1 - color: qgcPal.text + QGCLabel { + id: label + Layout.fillWidth: true + + QGCColoredImage { + id: image + width: label.height / 2 + height: width + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + source: "/qmlimages/arrow-down.png" + color: qgcPal.text + visible: !_root.checked + } + } + + Rectangle { + anchors.left: parent.left + anchors.right: parent.right + height: 1 + color: qgcPal.text + } } } } diff --git a/src/QmlControls/QGCComboBox.qml b/src/QmlControls/QGCComboBox.qml index 1d30624cc..f703d6d64 100644 --- a/src/QmlControls/QGCComboBox.qml +++ b/src/QmlControls/QGCComboBox.qml @@ -68,7 +68,10 @@ Button { } } - onClicked: popup.toggleShow() + onClicked: { + combo.focus = true + popup.toggleShow() + } Component.onCompleted: { if (currentIndex === -1) { diff --git a/src/QmlControls/ToolStrip.qml b/src/QmlControls/ToolStrip.qml index c851cdb7b..9152a7f24 100644 --- a/src/QmlControls/ToolStrip.qml +++ b/src/QmlControls/ToolStrip.qml @@ -163,71 +163,77 @@ Rectangle { visible: index == 0 ? _showOptionalElements : true } - Rectangle { + FocusScope { + id: scope anchors.left: parent.left anchors.right: parent.right height: width - color: checked ? _repeaterPal.buttonHighlight : _repeaterPal.button - - QGCColoredImage { - id: button - anchors.fill: parent - source: _source - sourceSize.height: parent.height - fillMode: Image.PreserveAspectFit - mipmap: true - smooth: true - color: checked ? _repeaterPal.buttonHighlightText : _repeaterPal.buttonText - - RotationAnimation on rotation { - id: imageRotation - loops: Animation.Infinite - from: 0 - to: 360 - duration: 500 - running: false - } - NumberAnimation on opacity { - id: opacityAnimation - running: false - from: 0 - to: 1.0 - loops: Animation.Infinite - duration: 2000 + Rectangle { + anchors.fill: parent + color: checked ? _repeaterPal.buttonHighlight : _repeaterPal.button + + QGCColoredImage { + id: button + anchors.fill: parent + source: _source + sourceSize.height: parent.height + fillMode: Image.PreserveAspectFit + mipmap: true + smooth: true + color: checked ? _repeaterPal.buttonHighlightText : _repeaterPal.buttonText + + RotationAnimation on rotation { + id: imageRotation + loops: Animation.Infinite + from: 0 + to: 360 + duration: 500 + running: false + } + + NumberAnimation on opacity { + id: opacityAnimation + running: false + from: 0 + to: 1.0 + loops: Animation.Infinite + duration: 2000 + } } - } - QGCMouseArea { - // Size of mouse area is expanded to make touch easier - anchors.leftMargin: -buttonStripColumn.anchors.margins - anchors.rightMargin: -buttonStripColumn.anchors.margins - anchors.left: parent.left - anchors.right: parent.right - anchors.top: parent.top - height: parent.height + (_showOptionalElements? buttonLabel.height + buttonColumn.spacing : 0) - visible: _buttonEnabled - preventStealing: true - - onClicked: { - if (modelData.dropPanelComponent === undefined) { - dropPanel.hide() - if (modelData.toggle === true) { - checked = !checked - } else { - // dropPanel.hide above will close panel, but we need to do this to clear toggles - uncheckAll() - } - _root.clicked(index, checked) - } else { - if (checked) { - dropPanel.hide() // hide affects checked, so this needs to be duplicated inside not outside if + QGCMouseArea { + // Size of mouse area is expanded to make touch easier + anchors.leftMargin: -buttonStripColumn.anchors.margins + anchors.rightMargin: -buttonStripColumn.anchors.margins + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + height: parent.height + (_showOptionalElements? buttonLabel.height + buttonColumn.spacing : 0) + visible: _buttonEnabled + preventStealing: true + + onClicked: { + scope.focus = true + if (modelData.dropPanelComponent === undefined) { + dropPanel.hide() + if (modelData.toggle === true) { + checked = !checked + } else { + // dropPanel.hide above will close panel, but we need to do this to clear toggles + uncheckAll() + } + _root.clicked(index, checked) } else { - dropPanel.hide() // hide affects checked, so this needs to be duplicated inside not outside if - uncheckAll() - checked = true - var panelEdgeTopPoint = mapToItem(_root, width, 0) - dropPanel.show(panelEdgeTopPoint, height, modelData.dropPanelComponent) + if (checked) { + dropPanel.hide() // hide affects checked, so this needs to be duplicated inside not outside if + } else { + dropPanel.hide() // hide affects checked, so this needs to be duplicated inside not outside if + uncheckAll() + checked = true + var panelEdgeTopPoint = mapToItem(_root, width, 0) + dropPanel.show(panelEdgeTopPoint, height, modelData.dropPanelComponent) + } } } } -- 2.22.0