mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-06 02:16:04 +08:00
Ref T220, save/store main window geometry/state
This commit is contained in:
@@ -45,6 +45,7 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
#include <QSettings>
|
||||||
#include <QSplashScreen>
|
#include <QSplashScreen>
|
||||||
#include <QStyleFactory>
|
#include <QStyleFactory>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
@@ -238,6 +239,32 @@ namespace BlackGui
|
|||||||
qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
|
qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CGuiApplication::isUsingHighDpiScreenSupport()
|
||||||
|
{
|
||||||
|
const QByteArray v = qgetenv("QT_AUTO_SCREEN_SCALE_FACTOR");
|
||||||
|
return !v.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CGuiApplication::saveWindowGeometryAndState(const QMainWindow *window) const
|
||||||
|
{
|
||||||
|
if (!window) { return false; }
|
||||||
|
QSettings settings("swift-project.org", this->getApplicationName());
|
||||||
|
settings.setValue("geometry", window->saveGeometry());
|
||||||
|
settings.setValue("windowState", window->saveState());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CGuiApplication::restoreWindowGeometryAndState(QMainWindow *window)
|
||||||
|
{
|
||||||
|
if (!window) { return false; }
|
||||||
|
const QSettings settings("swift-project.org", this->getApplicationName());
|
||||||
|
const QByteArray g = settings.value("geometry").toByteArray();
|
||||||
|
const QByteArray s = settings.value("windowState").toByteArray();
|
||||||
|
window->restoreGeometry(g);
|
||||||
|
window->restoreState(s);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void CGuiApplication::onStartUpCompleted()
|
void CGuiApplication::onStartUpCompleted()
|
||||||
{
|
{
|
||||||
CApplication::onStartUpCompleted();
|
CApplication::onStartUpCompleted();
|
||||||
@@ -248,10 +275,15 @@ namespace BlackGui
|
|||||||
m_splashScreen.reset();
|
m_splashScreen.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_minWidthChars > 0 || m_minHeightChars > 0)
|
// window size
|
||||||
|
if (m_saveMainWidgetState)
|
||||||
|
{
|
||||||
|
this->restoreWindowGeometryAndState();
|
||||||
|
}
|
||||||
|
else if (m_minWidthChars > 0 || m_minHeightChars > 0)
|
||||||
{
|
{
|
||||||
const QSize s = CGuiUtility::fontMetricsEstimateSize(m_minWidthChars, m_minHeightChars);
|
const QSize s = CGuiUtility::fontMetricsEstimateSize(m_minWidthChars, m_minHeightChars);
|
||||||
QWidget *mw = CGuiUtility::mainApplicationWindow();
|
QWidget *mw = CGuiUtility::mainApplicationWidget();
|
||||||
if (mw)
|
if (mw)
|
||||||
{
|
{
|
||||||
QSize cs = mw->size();
|
QSize cs = mw->size();
|
||||||
@@ -812,6 +844,15 @@ namespace BlackGui
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CGuiApplication::gracefulShutdown()
|
||||||
|
{
|
||||||
|
if (m_saveMainWidgetState)
|
||||||
|
{
|
||||||
|
this->saveWindowGeometryAndState();
|
||||||
|
}
|
||||||
|
CApplication::gracefulShutdown();
|
||||||
|
}
|
||||||
|
|
||||||
void CGuiApplication::settingsChanged()
|
void CGuiApplication::settingsChanged()
|
||||||
{
|
{
|
||||||
// changing widget style is slow, so I try to prevent setting it when nothing changed
|
// changing widget style is slow, so I try to prevent setting it when nothing changed
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ namespace BlackGui
|
|||||||
bool resetFont();
|
bool resetFont();
|
||||||
|
|
||||||
//! Set minimum width/height in characters
|
//! Set minimum width/height in characters
|
||||||
|
//! \deprecated kept for experimental tests
|
||||||
void setMinimumSizeInCharacters(int widthChars, int heightChars);
|
void setMinimumSizeInCharacters(int widthChars, int heightChars);
|
||||||
|
|
||||||
//! Wait for setup, in case it fails display a dialog how to continue
|
//! Wait for setup, in case it fails display a dialog how to continue
|
||||||
@@ -190,6 +191,18 @@ namespace BlackGui
|
|||||||
//! Trigger new version check
|
//! Trigger new version check
|
||||||
void triggerNewVersionCheck(int delayedMs);
|
void triggerNewVersionCheck(int delayedMs);
|
||||||
|
|
||||||
|
//! \copydoc BlackCore::CApplication::gracefulShutdown
|
||||||
|
virtual void gracefulShutdown() override;
|
||||||
|
|
||||||
|
//! Save the main widget state?
|
||||||
|
void setSaveMainWidgetState(bool save) { m_saveMainWidgetState = save; }
|
||||||
|
|
||||||
|
//! Save widget's geometry and state
|
||||||
|
bool saveWindowGeometryAndState(const QMainWindow *window = CGuiApplication::mainApplicationWindow()) const;
|
||||||
|
|
||||||
|
//! Restore widget's geometry and state
|
||||||
|
bool restoreWindowGeometryAndState(QMainWindow *window = CGuiApplication::mainApplicationWindow());
|
||||||
|
|
||||||
//! Set icon
|
//! Set icon
|
||||||
//! \note Pixmap requires a valid QApplication, so it cannot be passed as constructor parameter
|
//! \note Pixmap requires a valid QApplication, so it cannot be passed as constructor parameter
|
||||||
static void setWindowIcon(const QPixmap &icon);
|
static void setWindowIcon(const QPixmap &icon);
|
||||||
@@ -210,6 +223,9 @@ namespace BlackGui
|
|||||||
//! \note Needs to be at the beginning of main
|
//! \note Needs to be at the beginning of main
|
||||||
static void highDpiScreenSupport();
|
static void highDpiScreenSupport();
|
||||||
|
|
||||||
|
//! Uses the high DPI support?
|
||||||
|
static bool isUsingHighDpiScreenSupport();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//! Style sheet changed
|
//! Style sheet changed
|
||||||
void styleSheetsChanged();
|
void styleSheetsChanged();
|
||||||
@@ -246,18 +262,19 @@ namespace BlackGui
|
|||||||
static void registerMetadata();
|
static void registerMetadata();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPixmap m_windowIcon;
|
QPixmap m_windowIcon; //!< the window icon
|
||||||
QString m_fontFamily; //!< current font family
|
QString m_fontFamily; //!< current font family
|
||||||
int m_fontPointSize; //!< current font size
|
int m_fontPointSize; //!< current font size
|
||||||
int m_minWidthChars = -1; //!< min. width characters (based on current font metrics)
|
int m_minWidthChars = -1; //!< min. width characters (based on current font metrics)
|
||||||
int m_minHeightChars = -1; //!< min. height characters (based on current font metrics)
|
int m_minHeightChars = -1; //!< min. height characters (based on current font metrics)
|
||||||
QCommandLineOption m_cmdWindowStateMinimized { "empty" }; //!< window state (minimized)
|
QCommandLineOption m_cmdWindowStateMinimized { "empty" }; //!< window state (minimized)
|
||||||
QCommandLineOption m_cmdWindowMode { "empty" }; //!< window mode (flags: frameless ...)
|
QCommandLineOption m_cmdWindowMode { "empty" }; //!< window mode (flags: frameless ...)
|
||||||
CStyleSheetUtility m_styleSheetUtility {{}, this}; //!< style sheet utility
|
CStyleSheetUtility m_styleSheetUtility {{}, this}; //!< style sheet utility
|
||||||
bool m_uiSetupCompleted = false; //!< ui setup completed
|
bool m_uiSetupCompleted = false; //!< ui setup completed
|
||||||
|
bool m_saveMainWidgetState = true; //!< save/restore main widget's state
|
||||||
QScopedPointer<QSplashScreen> m_splashScreen; //!< splash screen
|
QScopedPointer<QSplashScreen> m_splashScreen; //!< splash screen
|
||||||
Components::CUpdateInfoDialog *m_updateDialog = nullptr; //!< software installation dialog
|
Components::CUpdateInfoDialog *m_updateDialog = nullptr; //!< software installation dialog
|
||||||
Components::CApplicationCloseDialog *m_closeDialog = nullptr; //!< close dialog (no QScopedPointer because I need to set parent)
|
Components::CApplicationCloseDialog *m_closeDialog = nullptr; //!< close dialog (no QScopedPointer because I need to set parent)
|
||||||
BlackMisc::CSettingReadOnly<Settings::TGeneralGui> m_guiSettings { this, &CGuiApplication::settingsChanged };
|
BlackMisc::CSettingReadOnly<Settings::TGeneralGui> m_guiSettings { this, &CGuiApplication::settingsChanged };
|
||||||
BlackMisc::CSettingReadOnly<Settings::TUpdateNotificationSettings> m_updateSetting { this }; //!< update notification settings
|
BlackMisc::CSettingReadOnly<Settings::TUpdateNotificationSettings> m_updateSetting { this }; //!< update notification settings
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ int main(int argc, char *argv[])
|
|||||||
CSwiftGuiStdApplication a; // application with contexts
|
CSwiftGuiStdApplication a; // application with contexts
|
||||||
a.setSignalStartupAutomatically(false); // application will signal startup on its own
|
a.setSignalStartupAutomatically(false); // application will signal startup on its own
|
||||||
a.splashScreen(CIcons::swift256());
|
a.splashScreen(CIcons::swift256());
|
||||||
|
a.setSaveMainWidgetState(true);
|
||||||
|
// a.setMinimumSizeInCharacters(80, 60); // experimental
|
||||||
if (!a.parseAndSynchronizeSetup()) { return EXIT_FAILURE; }
|
if (!a.parseAndSynchronizeSetup()) { return EXIT_FAILURE; }
|
||||||
if (!a.hasSetupReader() || !a.start())
|
if (!a.hasSetupReader() || !a.start())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user