Commit 41da849f authored by Don Gagne's avatar Don Gagne
Browse files

Fix dialog buttons stuck in disabled state

parent c75cca7d
...@@ -22,90 +22,83 @@ import QGroundControl.FactSystem 1.0 ...@@ -22,90 +22,83 @@ import QGroundControl.FactSystem 1.0
import QGroundControl.FactControls 1.0 import QGroundControl.FactControls 1.0
FactPanel { FactPanel {
id: __rootItem id: _rootItem
property var qgcView: __rootItem ///< Used by Fact controls for validation dialogs property var qgcView: _rootItem ///< Used by Fact controls for validation dialogs
property bool completedSignalled: false property bool completedSignalled: false
property real topDialogMargin: 0 ///< Set a top margin for dialog property real topDialogMargin: 0 ///< Set a top margin for dialog
property var viewPanel
property var viewPanel
/// This is signalled when the top level Item reaches Component.onCompleted. This allows /// This is signalled when the top level Item reaches Component.onCompleted. This allows
/// the view subcomponent to connect to this signal and do work once the full ui is ready /// the view subcomponent to connect to this signal and do work once the full ui is ready
/// to go. /// to go.
signal completed signal completed
function __setupDialogButtons(buttons) { function _setupDialogButtons(buttons) {
__acceptButton.visible = false _acceptButton.visible = false
__rejectButton.visible = false _rejectButton.visible = false
// Accept role buttons // Accept role buttons
if (buttons & StandardButton.Ok) { if (buttons & StandardButton.Ok) {
__acceptButton.text = qsTr("Ok") _acceptButton.text = qsTr("Ok")
__acceptButton.visible = true _acceptButton.visible = true
} else if (buttons & StandardButton.Open) { } else if (buttons & StandardButton.Open) {
__acceptButton.text = qsTr("Open") _acceptButton.text = qsTr("Open")
__acceptButton.visible = true _acceptButton.visible = true
} else if (buttons & StandardButton.Save) { } else if (buttons & StandardButton.Save) {
__acceptButton.text = qsTr("Save") _acceptButton.text = qsTr("Save")
__acceptButton.visible = true _acceptButton.visible = true
} else if (buttons & StandardButton.Apply) { } else if (buttons & StandardButton.Apply) {
__acceptButton.text = qsTr("Apply") _acceptButton.text = qsTr("Apply")
__acceptButton.visible = true _acceptButton.visible = true
} else if (buttons & StandardButton.Open) { } else if (buttons & StandardButton.Open) {
__acceptButton.text = qsTr("Open") _acceptButton.text = qsTr("Open")
__acceptButton.visible = true _acceptButton.visible = true
} else if (buttons & StandardButton.SaveAll) { } else if (buttons & StandardButton.SaveAll) {
__acceptButton.text = qsTr("Save All") _acceptButton.text = qsTr("Save All")
__acceptButton.visible = true _acceptButton.visible = true
} else if (buttons & StandardButton.Yes) { } else if (buttons & StandardButton.Yes) {
__acceptButton.text = qsTr("Yes") _acceptButton.text = qsTr("Yes")
__acceptButton.visible = true _acceptButton.visible = true
} else if (buttons & StandardButton.YesToAll) { } else if (buttons & StandardButton.YesToAll) {
__acceptButton.text = qsTr("Yes to All") _acceptButton.text = qsTr("Yes to All")
__acceptButton.visible = true _acceptButton.visible = true
} else if (buttons & StandardButton.Retry) { } else if (buttons & StandardButton.Retry) {
__acceptButton.text = qsTr("Retry") _acceptButton.text = qsTr("Retry")
__acceptButton.visible = true _acceptButton.visible = true
} else if (buttons & StandardButton.Reset) { } else if (buttons & StandardButton.Reset) {
__acceptButton.text = qsTr("Reset") _acceptButton.text = qsTr("Reset")
__acceptButton.visible = true _acceptButton.visible = true
} else if (buttons & StandardButton.RestoreToDefaults) { } else if (buttons & StandardButton.RestoreToDefaults) {
__acceptButton.text = qsTr("Restore to Defaults") _acceptButton.text = qsTr("Restore to Defaults")
__acceptButton.visible = true _acceptButton.visible = true
} else if (buttons & StandardButton.Ignore) { } else if (buttons & StandardButton.Ignore) {
__acceptButton.text = qsTr("Ignore") _acceptButton.text = qsTr("Ignore")
__acceptButton.visible = true _acceptButton.visible = true
} }
// Reject role buttons // Reject role buttons
if (buttons & StandardButton.Cancel) { if (buttons & StandardButton.Cancel) {
__rejectButton.text = qsTr("Cancel") _rejectButton.text = qsTr("Cancel")
__rejectButton.visible = true _rejectButton.visible = true
} else if (buttons & StandardButton.Close) { } else if (buttons & StandardButton.Close) {
__rejectButton.text = qsTr("Close") _rejectButton.text = qsTr("Close")
__rejectButton.visible = true _rejectButton.visible = true
} else if (buttons & StandardButton.No) { } else if (buttons & StandardButton.No) {
__rejectButton.text = qsTr("No") _rejectButton.text = qsTr("No")
__rejectButton.visible = true _rejectButton.visible = true
} else if (buttons & StandardButton.NoToAll) { } else if (buttons & StandardButton.NoToAll) {
__rejectButton.text = qsTr("No to All") _rejectButton.text = qsTr("No to All")
__rejectButton.visible = true _rejectButton.visible = true
} else if (buttons & StandardButton.Abort) { } else if (buttons & StandardButton.Abort) {
__rejectButton.text = qsTr("Abort") _rejectButton.text = qsTr("Abort")
__rejectButton.visible = true _rejectButton.visible = true
}
}
function __stopAllAnimations() {
if (__animateHideDialog.running) {
__animateHideDialog.stop()
} }
} }
function __checkForEarlyDialog(title) { function _checkForEarlyDialog(title) {
if (!completedSignalled) { if (!completedSignalled) {
console.warn(qsTr("showDialog|Message called before QGCView.completed signalled"), title) console.warn(qsTr("showDialog called before QGCView.completed signalled"), title)
} }
} }
...@@ -119,77 +112,65 @@ FactPanel { ...@@ -119,77 +112,65 @@ FactPanel {
readonly property int showDialogDefaultWidth: 40 ///< Use for default dialog width readonly property int showDialogDefaultWidth: 40 ///< Use for default dialog width
function showDialog(component, title, charWidth, buttons) { function showDialog(component, title, charWidth, buttons) {
if (__checkForEarlyDialog(title)) { if (_checkForEarlyDialog(title)) {
return return
} }
__rejectButton.enabled = true _rejectButton.enabled = true
__acceptButton.enabled = true _acceptButton.enabled = true
__stopAllAnimations() _dialogCharWidth = charWidth
_dialogTitle = title
__dialogCharWidth = charWidth _setupDialogButtons(buttons)
__dialogTitle = title
__setupDialogButtons(buttons) _dialogComponent = component
__dialogComponent = component
viewPanel.enabled = false viewPanel.enabled = false
__dialogOverlay.visible = true _dialogOverlay.visible = true
//__dialogComponentLoader.item.forceActiveFocus()
__animateShowDialog.start()
} }
function showMessage(title, message, buttons) { function showMessage(title, message, buttons) {
if (__checkForEarlyDialog(title)) { if (_checkForEarlyDialog(title)) {
return return
} }
__rejectButton.enabled = true _rejectButton.enabled = true
__acceptButton.enabled = true _acceptButton.enabled = true
__stopAllAnimations() _dialogCharWidth = showDialogDefaultWidth
_dialogTitle = title
_messageDialogText = message
__dialogCharWidth = showDialogDefaultWidth _setupDialogButtons(buttons)
__dialogTitle = title
__messageDialogText = message
__setupDialogButtons(buttons) _dialogComponent = _messageDialog
__dialogComponent = __messageDialog
viewPanel.enabled = false viewPanel.enabled = false
__dialogOverlay.visible = true _dialogOverlay.visible = true
__dialogComponentLoader.item.forceActiveFocus()
__animateShowDialog.start()
} }
function hideDialog() { function hideDialog() {
//__dialogComponentLoader.item.focus = false
viewPanel.enabled = true viewPanel.enabled = true
__animateHideDialog.start() _dialogComponent = null
_dialogOverlay.visible = false
} }
QGCPalette { id: __qgcPal; colorGroupEnabled: true } QGCPalette { id: _qgcPal; colorGroupEnabled: true }
QGCLabel { id: __textMeasure; text: "X"; visible: false } QGCLabel { id: _textMeasure; text: "X"; visible: false }
property real defaultTextHeight: __textMeasure.contentHeight property real defaultTextHeight: _textMeasure.contentHeight
property real defaultTextWidth: __textMeasure.contentWidth property real defaultTextWidth: _textMeasure.contentWidth
/// The width of the dialog panel in characters /// The width of the dialog panel in characters
property int __dialogCharWidth: 75 property int _dialogCharWidth: 75
/// The title for the dialog panel /// The title for the dialog panel
property string __dialogTitle property string _dialogTitle
property string __messageDialogText property string _messageDialogText
property Component __dialogComponent property Component _dialogComponent
function __signalCompleted() { function _signalCompleted() {
// When we use this control inside a QGCQmlWidgetHolder Component.onCompleted is signalled // When we use this control inside a QGCQmlWidgetHolder Component.onCompleted is signalled
// before the width and height are adjusted. So we need to wait for width and heigth to be // before the width and height are adjusted. So we need to wait for width and heigth to be
// set before we signal our own completed signal. // set before we signal our own completed signal.
...@@ -199,160 +180,118 @@ FactPanel { ...@@ -199,160 +180,118 @@ FactPanel {
} }
} }
Component.onCompleted: __signalCompleted() Component.onCompleted: _signalCompleted()
onWidthChanged: __signalCompleted() onWidthChanged: _signalCompleted()
onHeightChanged: __signalCompleted() onHeightChanged: _signalCompleted()
Connections { Connections {
target: __dialogComponentLoader.item target: _dialogComponentLoader.item
onHideDialog: __rootItem.hideDialog() onHideDialog: _rootItem.hideDialog()
} }
Item { Item {
id: __dialogOverlay id: _dialogOverlay
visible: false visible: false
anchors.fill: parent anchors.fill: parent
z: 5000 z: 5000
readonly property int __animationDuration: 200
ParallelAnimation {
id: __animateShowDialog
NumberAnimation {
target: __transparentSection
properties: "opacity"
from: 0.0
to: 0.8
duration: __dialogOverlay.__animationDuration
}
NumberAnimation {
target: __transparentSection
properties: "width"
from: __dialogOverlay.width
to: __dialogOverlay.width - __dialogPanel.width
duration: __dialogOverlay.__animationDuration
}
}
ParallelAnimation {
id: __animateHideDialog
NumberAnimation {
target: __transparentSection
properties: "opacity"
from: 0.8
to: 0.0
duration: __dialogOverlay.__animationDuration
}
NumberAnimation {
target: __transparentSection
properties: "width"
from: __dialogOverlay.width - __dialogPanel.width
to: __dialogOverlay.width
duration: __dialogOverlay.__animationDuration
}
onRunningChanged: {
if (!running) {
__dialogComponent = null
__dialogOverlay.visible = false
}
}
}
// This covers the parent with an transparent section // This covers the parent with an transparent section
Rectangle { Rectangle {
id: __transparentSection id: _transparentSection
height: ScreenTools.availableHeight ? ScreenTools.availableHeight : parent.height height: ScreenTools.availableHeight ? ScreenTools.availableHeight : parent.height
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.left: parent.left anchors.left: parent.left
anchors.right: __dialogPanel.left anchors.right: _dialogPanel.left
opacity: 0.0 opacity: 0.0
color: __qgcPal.window color: _qgcPal.window
} }
// This is the main dialog panel which is anchored to the right edge // This is the main dialog panel which is anchored to the right edge
Rectangle { Rectangle {
id: __dialogPanel id: _dialogPanel
width: __dialogCharWidth == showDialogFullWidth ? parent.width : defaultTextWidth * __dialogCharWidth width: _dialogCharWidth == showDialogFullWidth ? parent.width : defaultTextWidth * _dialogCharWidth
anchors.topMargin: topDialogMargin anchors.topMargin: topDialogMargin
height: ScreenTools.availableHeight ? ScreenTools.availableHeight : parent.height height: ScreenTools.availableHeight ? ScreenTools.availableHeight : parent.height
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.right: parent.right anchors.right: parent.right
color: __qgcPal.windowShadeDark color: _qgcPal.windowShadeDark
Rectangle { Rectangle {
id: __header id: _header
width: parent.width width: parent.width
height: __acceptButton.visible ? __acceptButton.height : __rejectButton.height height: _acceptButton.visible ? _acceptButton.height : _rejectButton.height
color: __qgcPal.windowShade color: _qgcPal.windowShade
function __hidePanel() { function _hidePanel() {
__fullPanel.visible = false _fullPanel.visible = false
} }
QGCLabel { QGCLabel {
x: defaultTextWidth x: defaultTextWidth
height: parent.height height: parent.height
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
text: __dialogTitle text: _dialogTitle
} }
QGCButton { QGCButton {
id: __rejectButton id: _rejectButton
anchors.right: __acceptButton.visible ? __acceptButton.left : parent.right anchors.right: _acceptButton.visible ? _acceptButton.left : parent.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
onClicked: { onClicked: {
enabled = false // prevent multiple clicks enabled = false // prevent multiple clicks
__dialogComponentLoader.item.reject() _dialogComponentLoader.item.reject()
if (!viewPanel.enabled) {
// Dialog was not closed, re-enable button
enabled = true
}
} }
} }
QGCButton { QGCButton {
id: __acceptButton id: _acceptButton
anchors.right: parent.right anchors.right: parent.right
primary: true primary: true
onClicked: { onClicked: {
enabled = false // prevent multiple clicks enabled = false // prevent multiple clicks
__dialogComponentLoader.item.accept() _dialogComponentLoader.item.accept()
if (!viewPanel.enabled) {
// Dialog was not closed, re-enable button
enabled = true
}
} }
} }
} }
Item { Item {
id: __spacer id: _spacer
width: 10 width: 10
height: 10 height: 10
anchors.top: __header.bottom anchors.top: _header.bottom
} }
Loader { Loader {
id: __dialogComponentLoader id: _dialogComponentLoader
anchors.margins: 5 anchors.margins: 5
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
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 acceptAllowed: _acceptButton.visible
property bool rejectAllowed: __rejectButton.visible property bool rejectAllowed: _rejectButton.visible
} }
} // Rectangle - Dialog panel } // Rectangle - Dialog panel
} // Item - Dialog overlay } // Item - Dialog overlay
Component { Component {
id: __messageDialog id: _messageDialog
QGCViewMessage { QGCViewMessage {
message: __messageDialogText message: _messageDialogText
} }
} }
} }
Supports Markdown
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