Unverified Commit ac51a6d2 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #8945 from DonLakeFlyer/StackedDialog

Support stacked component dialogs
parents 4157b334 deba8a2e
......@@ -77,7 +77,6 @@
<file alias="PX4FlowSensor.qml">src/VehicleSetup/PX4FlowSensor.qml</file>
<file alias="QGCInstrumentWidget.qml">src/FlightMap/Widgets/QGCInstrumentWidget.qml</file>
<file alias="QGCInstrumentWidgetAlternate.qml">src/FlightMap/Widgets/QGCInstrumentWidgetAlternate.qml</file>
<file alias="QGCViewDialogContainer.qml">src/QmlControls/QGCViewDialogContainer.qml</file>
<file alias="QGroundControl/Controls/AnalyzePage.qml">src/AnalyzeView/AnalyzePage.qml</file>
<file alias="QGroundControl/Controls/AppMessages.qml">src/QmlControls/AppMessages.qml</file>
<file alias="QGroundControl/Controls/AxisMonitor.qml">src/QmlControls/AxisMonitor.qml</file>
......@@ -162,6 +161,7 @@
<file alias="QGroundControl/Controls/QGCToolBarButton.qml">src/QmlControls/QGCToolBarButton.qml</file>
<file alias="QGroundControl/Controls/QGCToolInsets.qml">src/QmlControls/QGCToolInsets.qml</file>
<file alias="QGroundControl/Controls/QGCViewDialog.qml">src/QmlControls/QGCViewDialog.qml</file>
<file alias="QGroundControl/Controls/QGCViewDialogContainer.qml">src/QmlControls/QGCViewDialogContainer.qml</file>
<file alias="QGroundControl/Controls/QGCViewMessage.qml">src/QmlControls/QGCViewMessage.qml</file>
<file alias="QGroundControl/Controls/qmldir">src/QmlControls/QGroundControl/Controls/qmldir</file>
<file alias="QGroundControl/Controls/RallyPointEditorHeader.qml">src/PlanView/RallyPointEditorHeader.qml</file>
......
......@@ -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
......
......@@ -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
......
......@@ -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()
}
}
......
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