From 48fa322b08ffa774ec807657b1eef373000e74cc Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Thu, 12 Dec 2019 08:22:26 +0300 Subject: [PATCH] View switch prevention support --- src/QmlControls/QGCToolBarButton.qml | 9 +++++-- src/ui/AppSettings.qml | 5 +++- src/ui/MainRootWindow.qml | 7 +++++- src/ui/toolbar/MainToolBar.qml | 36 ++++++++++++++++++++++++---- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/QmlControls/QGCToolBarButton.qml b/src/QmlControls/QGCToolBarButton.qml index cf9003913..b2892de84 100644 --- a/src/QmlControls/QGCToolBarButton.qml +++ b/src/QmlControls/QGCToolBarButton.qml @@ -14,20 +14,25 @@ import QGroundControl.Controls 1.0 import QGroundControl.Palette 1.0 import QGroundControl.ScreenTools 1.0 +// Important Note: Toolbar buttons must manage their checked state manually in order to support +// view switch prevention. This means they can't be checkable or autoExclusive. + Button { id: button height: ScreenTools.defaultFontPixelHeight * 3 leftPadding: _horizontalMargin rightPadding: _horizontalMargin - autoExclusive: true + checkable: false property bool logo: false property real _horizontalMargin: ScreenTools.defaultFontPixelWidth + onCheckedChanged: checkable = false + background: Rectangle { anchors.fill: parent - color: logo ? qgcPal.brandingPurple : (checked ? qgcPal.buttonHighlight : Qt.rgba(0,0,0,0)) + color: logo ? qgcPal.brandingPurple : (button.checked ? qgcPal.buttonHighlight : Qt.rgba(0,0,0,0)) } contentItem: Row { diff --git a/src/ui/AppSettings.qml b/src/ui/AppSettings.qml index 3f1f533e3..ec41b2786 100644 --- a/src/ui/AppSettings.qml +++ b/src/ui/AppSettings.qml @@ -74,7 +74,10 @@ Rectangle { Layout.fillWidth: true onClicked: { - if(__rightPanel.source !== modelData.url) { + if (mainWindow.preventViewSwitch) { + return + } + if (__rightPanel.source !== modelData.url) { __rightPanel.source = modelData.url } checked = true diff --git a/src/ui/MainRootWindow.qml b/src/ui/MainRootWindow.qml index 16466a3b2..ff8e280c5 100644 --- a/src/ui/MainRootWindow.qml +++ b/src/ui/MainRootWindow.qml @@ -49,6 +49,7 @@ ApplicationWindow { property bool communicationLost: activeVehicle ? activeVehicle.connectionLost : false property string formatedMessage: activeVehicle ? activeVehicle.formatedMessage : "" property real availableHeight: mainWindow.height - mainWindow.header.height - mainWindow.footer.height + property bool preventViewSwitch: false property var currentPlanMissionItem: planMasterControllerPlan ? planMasterControllerPlan.missionController.currentPlanViewItem : null property var planMasterControllerPlan: null @@ -151,8 +152,10 @@ ApplicationWindow { mainWindowDialog.dialogComponent = component mainWindowDialog.dialogTitle = title mainWindowDialog.dialogButtons = buttons + console.log("Prevent view switch") + mainWindow.preventViewSwitch = true mainWindowDialog.open() - if(buttons & StandardButton.Cancel || buttons & StandardButton.Close || buttons & StandardButton.Discard || buttons & StandardButton.Abort || buttons & StandardButton.Ignore) { + if (buttons & StandardButton.Cancel || buttons & StandardButton.Close || buttons & StandardButton.Discard || buttons & StandardButton.Abort || buttons & StandardButton.Ignore) { mainWindowDialog.closePolicy = Popup.NoAutoClose; mainWindowDialog.interactive = false; } else { @@ -184,6 +187,8 @@ ApplicationWindow { dlgLoader.source = "QGCViewDialogContainer.qml" } onClosed: { + console.log("View switch ok") + mainWindow.preventViewSwitch = false dlgLoader.source = "" } } diff --git a/src/ui/toolbar/MainToolBar.qml b/src/ui/toolbar/MainToolBar.qml index cefa4caf0..ba99ad25e 100644 --- a/src/ui/toolbar/MainToolBar.qml +++ b/src/ui/toolbar/MainToolBar.qml @@ -98,17 +98,25 @@ Item { anchors.bottom: parent.bottom spacing: ScreenTools.defaultFontPixelWidth / 2 - ButtonGroup { - buttons: viewRow.children - } + // Important Note: Toolbar buttons must manage their checked state manually in order to support + // view switch prevention. There doesn't seem to be a way to make this work if they are in a + // ButtonGroup. //--------------------------------------------- // Toolbar Row RowLayout { - id: viewRow + id: buttonRow Layout.fillHeight: true spacing: 0 + function clearAllChecks() { + for (var i=0; i