mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 02:35:33 +08:00
Ref T220, save/store main window geometry/state
This commit is contained in:
@@ -45,6 +45,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
#include <QRegularExpression>
|
||||
#include <QSettings>
|
||||
#include <QSplashScreen>
|
||||
#include <QStyleFactory>
|
||||
#include <QStringList>
|
||||
@@ -238,6 +239,32 @@ namespace BlackGui
|
||||
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()
|
||||
{
|
||||
CApplication::onStartUpCompleted();
|
||||
@@ -248,10 +275,15 @@ namespace BlackGui
|
||||
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);
|
||||
QWidget *mw = CGuiUtility::mainApplicationWindow();
|
||||
QWidget *mw = CGuiUtility::mainApplicationWidget();
|
||||
if (mw)
|
||||
{
|
||||
QSize cs = mw->size();
|
||||
@@ -812,6 +844,15 @@ namespace BlackGui
|
||||
});
|
||||
}
|
||||
|
||||
void CGuiApplication::gracefulShutdown()
|
||||
{
|
||||
if (m_saveMainWidgetState)
|
||||
{
|
||||
this->saveWindowGeometryAndState();
|
||||
}
|
||||
CApplication::gracefulShutdown();
|
||||
}
|
||||
|
||||
void CGuiApplication::settingsChanged()
|
||||
{
|
||||
// changing widget style is slow, so I try to prevent setting it when nothing changed
|
||||
|
||||
@@ -174,6 +174,7 @@ namespace BlackGui
|
||||
bool resetFont();
|
||||
|
||||
//! Set minimum width/height in characters
|
||||
//! \deprecated kept for experimental tests
|
||||
void setMinimumSizeInCharacters(int widthChars, int heightChars);
|
||||
|
||||
//! Wait for setup, in case it fails display a dialog how to continue
|
||||
@@ -190,6 +191,18 @@ namespace BlackGui
|
||||
//! Trigger new version check
|
||||
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
|
||||
//! \note Pixmap requires a valid QApplication, so it cannot be passed as constructor parameter
|
||||
static void setWindowIcon(const QPixmap &icon);
|
||||
@@ -210,6 +223,9 @@ namespace BlackGui
|
||||
//! \note Needs to be at the beginning of main
|
||||
static void highDpiScreenSupport();
|
||||
|
||||
//! Uses the high DPI support?
|
||||
static bool isUsingHighDpiScreenSupport();
|
||||
|
||||
signals:
|
||||
//! Style sheet changed
|
||||
void styleSheetsChanged();
|
||||
@@ -246,18 +262,19 @@ namespace BlackGui
|
||||
static void registerMetadata();
|
||||
|
||||
private:
|
||||
QPixmap m_windowIcon;
|
||||
QPixmap m_windowIcon; //!< the window icon
|
||||
QString m_fontFamily; //!< current font family
|
||||
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)
|
||||
QCommandLineOption m_cmdWindowStateMinimized { "empty" }; //!< window state (minimized)
|
||||
QCommandLineOption m_cmdWindowMode { "empty" }; //!< window mode (flags: frameless ...)
|
||||
CStyleSheetUtility m_styleSheetUtility {{}, this}; //!< style sheet utility
|
||||
bool m_uiSetupCompleted = false; //!< ui setup completed
|
||||
bool m_saveMainWidgetState = true; //!< save/restore main widget's state
|
||||
QScopedPointer<QSplashScreen> m_splashScreen; //!< splash screen
|
||||
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::TUpdateNotificationSettings> m_updateSetting { this }; //!< update notification settings
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ int main(int argc, char *argv[])
|
||||
CSwiftGuiStdApplication a; // application with contexts
|
||||
a.setSignalStartupAutomatically(false); // application will signal startup on its own
|
||||
a.splashScreen(CIcons::swift256());
|
||||
a.setSaveMainWidgetState(true);
|
||||
// a.setMinimumSizeInCharacters(80, 60); // experimental
|
||||
if (!a.parseAndSynchronizeSetup()) { return EXIT_FAILURE; }
|
||||
if (!a.hasSetupReader() || !a.start())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user