From 7c24fa63db3aaf627dadaf344f282d65ec379b46 Mon Sep 17 00:00:00 2001 From: Gus Grubba Date: Thu, 13 Feb 2020 18:15:42 -0500 Subject: [PATCH] Expose API to prevent QGC from saving the application window size and position on close (or restoring it on open). --- src/QmlControls/MainWindowSavedState.qml | 49 +++++++++++++----------- src/api/QGCOptions.h | 3 ++ 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/QmlControls/MainWindowSavedState.qml b/src/QmlControls/MainWindowSavedState.qml index 97216d609..483e7a904 100644 --- a/src/QmlControls/MainWindowSavedState.qml +++ b/src/QmlControls/MainWindowSavedState.qml @@ -12,11 +12,14 @@ import QtQuick.Window 2.11 import QtQuick.Controls 2.4 import Qt.labs.settings 1.0 -import QGroundControl.ScreenTools 1.0 +import QGroundControl 1.0 +import QGroundControl.ScreenTools 1.0 Item { property Window window + property bool _enabled: !ScreenTools.isMobile && QGroundControl.corePlugin.options.enableSaveMainWindowPosition + Settings { id: s category: "MainWindowState" @@ -29,7 +32,7 @@ Item { } Component.onCompleted: { - if (!ScreenTools.isMobile && s.width && s.height) { + if (_enabled && s.width && s.height) { window.x = s.x; window.y = s.y; window.width = s.width; @@ -39,12 +42,12 @@ Item { } Connections { - target: ScreenTools.isMobile ? null : window - onXChanged: saveSettingsTimer.restart() - onYChanged: saveSettingsTimer.restart() - onWidthChanged: saveSettingsTimer.restart() - onHeightChanged: saveSettingsTimer.restart() - onVisibilityChanged: saveSettingsTimer.restart() + target: window + onXChanged: if(_enabled) saveSettingsTimer.restart() + onYChanged: if(_enabled) saveSettingsTimer.restart() + onWidthChanged: if(_enabled) saveSettingsTimer.restart() + onHeightChanged: if(_enabled) saveSettingsTimer.restart() + onVisibilityChanged: if(_enabled) saveSettingsTimer.restart() } Timer { @@ -55,20 +58,22 @@ Item { } function saveSettings() { - switch(window.visibility) { - case ApplicationWindow.Windowed: - s.x = window.x; - s.y = window.y; - s.width = window.width; - s.height = window.height; - s.visibility = window.visibility; - break; - case ApplicationWindow.FullScreen: - s.visibility = window.visibility; - break; - case ApplicationWindow.Maximized: - s.visibility = window.visibility; - break; + if(_enabled) { + switch(window.visibility) { + case ApplicationWindow.Windowed: + s.x = window.x; + s.y = window.y; + s.width = window.width; + s.height = window.height; + s.visibility = window.visibility; + break; + case ApplicationWindow.FullScreen: + s.visibility = window.visibility; + break; + case ApplicationWindow.Maximized: + s.visibility = window.visibility; + break; + } } } } diff --git a/src/api/QGCOptions.h b/src/api/QGCOptions.h index 9099cdd6d..ba6c56380 100644 --- a/src/api/QGCOptions.h +++ b/src/api/QGCOptions.h @@ -66,6 +66,7 @@ public: Q_PROPERTY(bool showMavlinkLogOptions READ showMavlinkLogOptions CONSTANT) Q_PROPERTY(bool enableMultiVehicleList READ enableMultiVehicleList CONSTANT) Q_PROPERTY(bool enableMapScale READ enableMapScale CONSTANT) + Q_PROPERTY(bool enableSaveMainWindowPosition READ enableSaveMainWindowPosition CONSTANT) /// Should QGC hide its settings menu and colapse it into one single menu (Settings and Vehicle Setup)? /// @return true if QGC should consolidate both menus into one. @@ -127,6 +128,8 @@ public: virtual bool showMavlinkLogOptions () const { return true; } virtual bool enableMultiVehicleList () const { return true; } virtual bool enableMapScale () const { return true; } + /// Desktop builds save the main application size and position on close (and restore it on open) + virtual bool enableSaveMainWindowPosition () const { return true; } #if defined(__mobile__) virtual bool useMobileFileDialog () const { return true;} -- 2.22.0