Commit eb1c4c8d authored by Don Gagne's avatar Don Gagne

Esc/Enter key support in QGCView dialogs

Total hack but it seems to work
parent 5399a291
...@@ -31,18 +31,18 @@ import QGroundControl.FactSystem 1.0 ...@@ -31,18 +31,18 @@ import QGroundControl.FactSystem 1.0
import QGroundControl.Controls 1.0 import QGroundControl.Controls 1.0
import QGroundControl.Palette 1.0 import QGroundControl.Palette 1.0
Rectangle { FocusScope {
color: qgcPal.window property alias color: rectangle.color
QGCPalette { id: qgcPal; colorGroupEnabled: enabled } property string __missingParams: ""
property string __errorMsg: ""
property string __missingParams: "" QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
property string __errorMsg: ""
function showMissingParameterOverlay(missingParamName) { function showMissingParameterOverlay(missingParamName) {
if (__missingParams.length != 0) { if (__missingParams.length != 0) {
__missingParams = __missingParams.concat(", ") __missingParams = __missingParams.concat(", ")
} }
__missingParams = __missingParams.concat(missingParamName) __missingParams = __missingParams.concat(missingParamName)
__missingParamsOverlay.visible = true __missingParamsOverlay.visible = true
} }
...@@ -53,17 +53,22 @@ Rectangle { ...@@ -53,17 +53,22 @@ Rectangle {
} }
Rectangle { Rectangle {
id: __missingParamsOverlay id: rectangle
anchors.fill: parent color: qgcPal.window
z: 9999
visible: false Rectangle {
color: qgcPal.window id: __missingParamsOverlay
opacity: 0.85
QGCLabel {
anchors.fill: parent anchors.fill: parent
wrapMode: Text.WordWrap z: 9999
text: __errorMsg.length ? __errorMsg : "Parameters(s) missing: " + __missingParams visible: false
color: qgcPal.window
opacity: 0.85
QGCLabel {
anchors.fill: parent
wrapMode: Text.WordWrap
text: __errorMsg.length ? __errorMsg : "Parameters(s) missing: " + __missingParams
}
} }
} }
} }
...@@ -58,8 +58,7 @@ QGCViewDialog { ...@@ -58,8 +58,7 @@ QGCViewDialog {
validationError.text = fact.validate(validateValue, false /* convertOnly */) validationError.text = fact.validate(validateValue, false /* convertOnly */)
forceSave.visible = true forceSave.visible = true
} }
// This was causing problems where it would never give up focus even when hidden! valueField.forceActiveFocus()
//valueField.forceActiveFocus()
} }
Column { Column {
...@@ -87,14 +86,6 @@ QGCViewDialog { ...@@ -87,14 +86,6 @@ QGCViewDialog {
// At this point all Facts are numeric // At this point all Facts are numeric
inputMethodHints: Qt.ImhFormattedNumbersOnly inputMethodHints: Qt.ImhFormattedNumbersOnly
onAccepted: accept()
Keys.onReleased: {
if (event.key == Qt.Key_Escape) {
reject()
}
}
} }
QGCLabel { text: fact.name } QGCLabel { text: fact.name }
......
...@@ -6,9 +6,17 @@ import QGroundControl.Palette 1.0 ...@@ -6,9 +6,17 @@ import QGroundControl.Palette 1.0
import QGroundControl.ScreenTools 1.0 import QGroundControl.ScreenTools 1.0
TextField { TextField {
id: root
property bool showUnits: false property bool showUnits: false
property string unitsLabel: "" property string unitsLabel: ""
Component.onCompleted: {
if (typeof qgcTextFieldforwardKeysTo !== 'undefined') {
root.Keys.forwardTo = [qgcTextFieldforwardKeysTo]
}
}
property var __qgcPal: QGCPalette { colorGroupEnabled: enabled } property var __qgcPal: QGCPalette { colorGroupEnabled: enabled }
textColor: __qgcPal.textFieldText textColor: __qgcPal.textFieldText
......
...@@ -146,6 +146,8 @@ FactPanel { ...@@ -146,6 +146,8 @@ FactPanel {
viewPanel.enabled = false viewPanel.enabled = false
__dialogOverlay.visible = true __dialogOverlay.visible = true
__dialogComponentLoader.item.forceActiveFocus()
__animateShowDialog.start() __animateShowDialog.start()
} }
...@@ -166,10 +168,13 @@ FactPanel { ...@@ -166,10 +168,13 @@ FactPanel {
viewPanel.enabled = false viewPanel.enabled = false
__dialogOverlay.visible = true __dialogOverlay.visible = true
__dialogComponentLoader.item.forceActiveFocus()
__animateShowDialog.start() __animateShowDialog.start()
} }
function hideDialog() { function hideDialog() {
__dialogComponentLoader.item.focus = false
viewPanel.enabled = true viewPanel.enabled = true
__animateHideDialog.start() __animateHideDialog.start()
} }
...@@ -336,6 +341,9 @@ FactPanel { ...@@ -336,6 +341,9 @@ FactPanel {
anchors.top: __spacer.bottom anchors.top: __spacer.bottom
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
sourceComponent: __dialogComponent sourceComponent: __dialogComponent
property bool acceptAllowed: __acceptButton.visible
property bool rejectAllowed: __rejectButton.visible
} }
} // Rectangle - Dialog panel } // Rectangle - Dialog panel
} // Item - Dialog overlay } // Item - Dialog overlay
......
...@@ -34,18 +34,34 @@ import QGroundControl.FactSystem 1.0 ...@@ -34,18 +34,34 @@ import QGroundControl.FactSystem 1.0
import QGroundControl.FactControls 1.0 import QGroundControl.FactControls 1.0
FactPanel { FactPanel {
property var qgcTextFieldforwardKeysTo: this ///< Causes all QGCTextFields to forward keys here if they have focus
QGCPalette { id: __qgcPal; colorGroupEnabled: enabled } QGCPalette { id: __qgcPal; colorGroupEnabled: enabled }
signal hideDialog signal hideDialog
Keys.onReleased: {
if (event.key == Qt.Key_Escape) {
reject()
event.accepted = true
} else if (event.key == Qt.Key_Return) {
accept()
event.accepted = true
}
}
function accept() { function accept() {
Qt.inputMethod.hide() if (acceptAllowed) {
hideDialog() Qt.inputMethod.hide()
hideDialog()
}
} }
function reject() { function reject() {
Qt.inputMethod.hide() if (rejectAllowed) {
hideDialog() Qt.inputMethod.hide()
hideDialog()
}
} }
color: __qgcPal.windowShadeDark color: __qgcPal.windowShadeDark
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment