From 15923cb9ab6cf0695cfd53d4bb7ca0577f43cabf Mon Sep 17 00:00:00 2001 From: Craig Drummond Date: Mon, 18 Dec 2017 19:07:46 +0000 Subject: [PATCH] Store pre-maximised state, so that when size is restored after starting maximised it is restored to the correct size. --- gui/mainwindow.cpp | 21 ++++++++++++++++----- gui/mainwindow.h | 2 ++ gui/settings.cpp | 10 ++++++++++ gui/settings.h | 2 ++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 9a1891961..8c89f39ea 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -542,14 +542,17 @@ void MainWindow::init() } else { if (expandInterfaceAction->isChecked()) { if (!expandedSize.isEmpty()) { - if (expandedSize.width()>1) { + if (!Settings::self()->maximized() && expandedSize.width()>1) { resize(expandedSize); expandOrCollapse(false); } else { - // Issue #1137 Under Windows, Cantata does not restore maximixed correctly if context is in sidebar - resize(defaultSize); + resize(expandedSize.width()>1 ? expandedSize : defaultSize); + // Issue #1137 Under Windows, Cantata does not restore maximized correctly if context is in sidebar + // ...so, set maximized after shown QTimer::singleShot(0, this, SLOT(showMaximized())); - expandedSize=defaultSize; + if (expandedSize.width()<=1) { + expandedSize=defaultSize; + } } } } else { @@ -863,8 +866,10 @@ MainWindow::~MainWindow() Settings::self()->saveShowFullScreen(fullScreenAction->isChecked()); if (!fullScreenAction->isChecked()) { if (expandInterfaceAction->isChecked()) { - Settings::self()->saveMainWindowSize(isMaximized() ? QSize(1, 1) : size()); + Settings::self()->saveMaximized(isMaximized()); + Settings::self()->saveMainWindowSize(isMaximized() ? previousSize : size()); } else { + Settings::self()->saveMaximized(false); Settings::self()->saveMainWindowSize(expandedSize); } Settings::self()->saveMainWindowCollapsedSize(expandInterfaceAction->isChecked() ? collapsedSize : size()); @@ -1048,6 +1053,12 @@ void MainWindow::closeEvent(QCloseEvent *event) } } +void MainWindow::resizeEvent(QResizeEvent *event) +{ + previousSize=event->oldSize(); + QMainWindow::resizeEvent(event); +} + void MainWindow::playQueueItemsSelected(bool s) { int rc=playQueue->model() ? playQueue->model()->rowCount() : 0; diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 210c926fc..bc067aef4 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -120,6 +120,7 @@ protected: void showEvent(QShowEvent *event); #endif void closeEvent(QCloseEvent *event); + void resizeEvent(QResizeEvent *event); private: #ifdef Q_OS_MAC @@ -319,6 +320,7 @@ private: QPoint lastPos; QSize expandedSize; QSize collapsedSize; + QSize previousSize; Song current; Page *currentPage; Action *showPlayQueueAction; diff --git a/gui/settings.cpp b/gui/settings.cpp index 8b95f4560..11c5c13a8 100644 --- a/gui/settings.cpp +++ b/gui/settings.cpp @@ -246,6 +246,11 @@ QSize Settings::mainWindowCollapsedSize() return cfg.get("mainWindowCollapsedSize", QSize()); } +bool Settings::maximized() +{ + return cfg.get("maximized", false); +} + bool Settings::useSystemTray() { return cfg.get("useSystemTray", false); @@ -740,6 +745,11 @@ void Settings::saveMainWindowSize(const QSize &v) cfg.set("mainWindowSize", v); } +void Settings::saveMaximized(bool v) +{ + cfg.set("maximized", v); +} + void Settings::saveMainWindowCollapsedSize(const QSize &v) { if (v.width()>16 && v.height()>16) { diff --git a/gui/settings.h b/gui/settings.h index 47ad7c41f..4ab12f44b 100644 --- a/gui/settings.h +++ b/gui/settings.h @@ -54,6 +54,7 @@ public: bool splitterAutoHide(); QSize mainWindowSize(); QSize mainWindowCollapsedSize(); + bool maximized(); bool useSystemTray(); bool minimiseOnClose(); bool showPopups(); @@ -154,6 +155,7 @@ public: void saveSplitterAutoHide(bool v); void saveMainWindowSize(const QSize &v); void saveMainWindowCollapsedSize(const QSize &v); + void saveMaximized(bool v); void saveUseSystemTray(bool v); void saveMinimiseOnClose(bool v); void saveShowPopups(bool v);