From 2d4766c79951df32793eb2c314f6aa7b65380c8b Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Tue, 28 Jul 2020 13:09:12 -0700 Subject: [PATCH] Support stacked component dialogs --- qgroundcontrol.qrc | 1 + src/QmlControls/QGCViewDialog.qml | 2 + src/QmlControls/QGCViewDialogContainer.qml | 34 +++++++++++---- src/ui/MainRootWindow.qml | 50 ++++------------------ 4 files changed, 37 insertions(+), 50 deletions(-) diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index 6136453f7..ecbcc0964 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -162,6 +162,7 @@ src/QmlControls/QGCToolBarButton.qml src/QmlControls/QGCToolInsets.qml src/QmlControls/QGCViewDialog.qml + src/QmlControls/QGCViewDialogContainer.qml src/QmlControls/QGCViewMessage.qml src/QmlControls/QGroundControl/Controls/qmldir src/PlanView/RallyPointEditorHeader.qml diff --git a/src/QmlControls/QGCViewDialog.qml b/src/QmlControls/QGCViewDialog.qml index f593c60db..b2878aa9d 100644 --- a/src/QmlControls/QGCViewDialog.qml +++ b/src/QmlControls/QGCViewDialog.qml @@ -9,6 +9,7 @@ import QtQuick 2.3 import QtQuick.Controls 1.2 +import QtQuick.Dialogs 1.3 import QGroundControl.Controls 1.0 import QGroundControl.Palette 1.0 @@ -17,6 +18,7 @@ import QGroundControl.FactControls 1.0 import QGroundControl.ScreenTools 1.0 Item { + property var buttons: StandardButton.NoButton signal hideDialog diff --git a/src/QmlControls/QGCViewDialogContainer.qml b/src/QmlControls/QGCViewDialogContainer.qml index bad30fcc0..a2b205aa8 100644 --- a/src/QmlControls/QGCViewDialogContainer.qml +++ b/src/QmlControls/QGCViewDialogContainer.qml @@ -15,16 +15,20 @@ import QGroundControl.Controls 1.0 import QGroundControl.Palette 1.0 import QGroundControl.ScreenTools 1.0 -Item { - anchors.fill: parent +Drawer { + edge: Qt.RightEdge + interactive: false + + property var dialogComponent + property string dialogTitle + property var dialogButtons: StandardButton.NoButton property real _defaultTextHeight: _textMeasure.contentHeight property real _defaultTextWidth: _textMeasure.contentWidth - function setupDialogButtons() { + function setupDialogButtons(buttons) { _acceptButton.visible = false _rejectButton.visible = false - var buttons = mainWindowDialog.dialogButtons // Accept role buttons if (buttons & StandardButton.Ok) { _acceptButton.text = qsTr("Ok") @@ -81,18 +85,33 @@ Item { _rejectButton.text = qsTr("Abort") _rejectButton.visible = true } + + if (buttons & StandardButton.Cancel || buttons & StandardButton.Close || buttons & StandardButton.Discard || buttons & StandardButton.Abort || buttons & StandardButton.Ignore) { + closePolicy = Popup.NoAutoClose; + interactive = false; + } else { + closePolicy = Popup.CloseOnEscape | Popup.CloseOnPressOutside; + interactive = true; + } } Connections { target: _dialogComponentLoader.item onHideDialog: { Qt.inputMethod.hide() - mainWindowDialog.close() + close() } } + Component.onCompleted: setupDialogButtons(dialogButtons) + QGCLabel { id: _textMeasure; text: "X"; visible: false } + + background: Rectangle { + color: qgcPal.windowShadeDark + } + // This is the main dialog panel Item { id: _dialogPanel @@ -103,9 +122,8 @@ Item { height: _acceptButton.visible ? _acceptButton.height : _rejectButton.height color: qgcPal.windowShade QGCLabel { - id: titleLabel x: _defaultTextWidth - text: mainWindowDialog.dialogTitle + text: dialogTitle height: parent.height verticalAlignment: Text.AlignVCenter } @@ -136,7 +154,7 @@ Item { anchors.right: parent.right anchors.top: _spacer.bottom anchors.bottom: parent.bottom - sourceComponent: mainWindowDialog.dialogComponent + sourceComponent: dialogComponent focus: true property bool acceptAllowed: _acceptButton.visible property bool rejectAllowed: _rejectButton.visible diff --git a/src/ui/MainRootWindow.qml b/src/ui/MainRootWindow.qml index 96010ba3f..bf305fe64 100644 --- a/src/ui/MainRootWindow.qml +++ b/src/ui/MainRootWindow.qml @@ -196,52 +196,18 @@ ApplicationWindow { readonly property int showDialogDefaultWidth: 40 ///< Use for default dialog width function showComponentDialog(component, title, charWidth, buttons) { - if (mainWindowDialog.visible) { - console.warn(("showComponentDialog called while dialog is already visible")) - return - } var dialogWidth = charWidth === showDialogFullWidth ? mainWindow.width : ScreenTools.defaultFontPixelWidth * charWidth - mainWindowDialog.width = dialogWidth - mainWindowDialog.dialogComponent = component - mainWindowDialog.dialogTitle = title - mainWindowDialog.dialogButtons = buttons + var dialog = dialogDrawerComponent.createObject(mainWindow, { width: dialogWidth, dialogComponent: component, dialogTitle: title, dialogButtons: buttons }) mainWindow.pushPreventViewSwitch() - mainWindowDialog.open() - if (buttons & StandardButton.Cancel || buttons & StandardButton.Close || buttons & StandardButton.Discard || buttons & StandardButton.Abort || buttons & StandardButton.Ignore) { - mainWindowDialog.closePolicy = Popup.NoAutoClose; - mainWindowDialog.interactive = false; - } else { - mainWindowDialog.closePolicy = Popup.CloseOnEscape | Popup.CloseOnPressOutside; - mainWindowDialog.interactive = true; - } + dialog.open() } - Drawer { - id: mainWindowDialog - y: mainWindow.header.height - height: mainWindow.height - mainWindow.header.height - edge: Qt.RightEdge - interactive: false - background: Rectangle { - color: qgcPal.windowShadeDark - } - property var dialogComponent: null - property var dialogButtons: null - property string dialogTitle: "" - Loader { - id: dlgLoader - anchors.fill: parent - onLoaded: { - item.setupDialogButtons() - } - } - onOpened: { - dlgLoader.source = "QGCViewDialogContainer.qml" - } - onClosed: { - //console.log("View switch ok") - mainWindow.popPreventViewSwitch() - dlgLoader.source = "" + Component { + id: dialogDrawerComponent + QGCViewDialogContainer { + y: mainWindow.header.height + height: mainWindow.height - mainWindow.header.height + onClosed: mainWindow.popPreventViewSwitch() } } -- 2.22.0