From 93ecbcb0446a1691a91678b9611d47c1dbdd7447 Mon Sep 17 00:00:00 2001 From: Jon Beverley Date: Wed, 6 Aug 2014 09:49:22 +0100 Subject: [PATCH 1/4] Reopen window in maximised state (windows) --- src/MainWindow.cpp | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 27abc9c1f..9f82362b1 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -185,21 +185,35 @@ MainWindow::MainWindow(const QDir &home) } else { QRect appsize = geom.toRect(); +#ifdef Q_OS_WIN + //Check if the window is the same size as the available area + //if it is them it was maximised when geom was saved + //Not sure about Mac so have made it windows only. + if ((appsize.width()+appsize.x()==screenSize.width()) && + (appsize.height()+appsize.y()==screenSize.height())) { + setWindowState(Qt::WindowMaximized); + } else { + setGeometry(appsize); + } +#else setGeometry(appsize); +#endif } - // just check the geometry is ok, otherwise just make - // it slightly smaller than the screensize - if (geometry().x() < 0 || geometry().y() < 0 || - (geometry().y()+geometry().height()) > screenSize.height() || (geometry().x()+geometry().width()) > screenSize.width()) { - setGeometry(screenSize.x()+50,screenSize.y()+50,screenSize.width()-150,screenSize.height()-150); + // if the window is not maximised + if (!isMaximized()) { + // just check the geometry is ok, otherwise just make + // it slightly smaller than the screensize + if (geometry().x() < 0 || geometry().y() < 0 || + (geometry().y()+geometry().height()) > screenSize.height() || (geometry().x()+geometry().width()) > screenSize.width()) { + setGeometry(screenSize.x()+50,screenSize.y()+50,screenSize.width()-150,screenSize.height()-150); + } + + // always attempt to center on the available screen (minus toolbar/sidebar) + move(((screenSize.width()-screenSize.x())/2) - (geometry().width()/2), + ((screenSize.height()-screenSize.y())/2) - (geometry().height()/2)); } - // always attempt to center on the available screen (minus toolbar/sidebar) - move(((screenSize.width()-screenSize.x())/2) - (geometry().width()/2), - ((screenSize.height()-screenSize.y())/2) - (geometry().height()/2)); - - /*---------------------------------------------------------------------- * ScopeBar *--------------------------------------------------------------------*/ From 734842214cadd76cdf4c136b0d9cca9ec4bff088 Mon Sep 17 00:00:00 2001 From: Jon Beverley Date: Thu, 7 Aug 2014 14:51:27 +0100 Subject: [PATCH 2/4] Ignore --- .gitignore | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f8fa22122..fb00e2509 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,16 @@ obj/ lib/ bin/ plugins/ -resources/ +resources/ +qwt/src/debug/ +qwt/src/release/ +src/Makefile.Debug +src/Makefile.Release +src/object_script.GoldenCheetah.Debug +src/object_script.GoldenCheetah.Release +qwt/src/object_script.libqwt.Release +qwt/src/object_script.libqwtd.Debug +qwt/src/Makefile.Release +qwt/src/Makefile.Debug + +build.pro.user \ No newline at end of file From d1aa0913926bc080a5d85a541d3e53c685550302 Mon Sep 17 00:00:00 2001 From: Jon Beverley Date: Fri, 8 Aug 2014 11:13:48 +0100 Subject: [PATCH 3/4] Revert "Ignore" This reverts commit 7e3d8dcaaf5cd517f37e4686adfd34c10a74229d. --- .gitignore | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index fb00e2509..f8fa22122 100644 --- a/.gitignore +++ b/.gitignore @@ -13,16 +13,4 @@ obj/ lib/ bin/ plugins/ -resources/ -qwt/src/debug/ -qwt/src/release/ -src/Makefile.Debug -src/Makefile.Release -src/object_script.GoldenCheetah.Debug -src/object_script.GoldenCheetah.Release -qwt/src/object_script.libqwt.Release -qwt/src/object_script.libqwtd.Debug -qwt/src/Makefile.Release -qwt/src/Makefile.Debug - -build.pro.user \ No newline at end of file +resources/ From 50e7237c27260cef0efc914e698627f8f8b0a4a5 Mon Sep 17 00:00:00 2001 From: Jon Beverley Date: Fri, 8 Aug 2014 11:16:04 +0100 Subject: [PATCH 4/4] Change to use Qt saveState & restoreState Should work on Win, Mac & Linux. --- src/MainWindow.cpp | 94 ++++++++++++++++------------------------------ src/MainWindow.h | 4 +- src/Settings.h | 1 + 3 files changed, 35 insertions(+), 64 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 9f82362b1..293cf4127 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -157,62 +157,30 @@ MainWindow::MainWindow(const QDir &home) /*---------------------------------------------------------------------- * GUI setup *--------------------------------------------------------------------*/ - // need to restore geometry before setUnifiedToolBar.. on Mac - QRect screenSize = desktop->availableGeometry(); - appsettings->setValue(GC_SETTINGS_LAST, context->athlete->home.dirName()); - QVariant geom = appsettings->value(this, GC_SETTINGS_MAIN_GEOM, QVariant()); + if (appsettings->contains(GC_SETTINGS_MAIN_GEOM)) { + restoreGeometry(appsettings->value(this, GC_SETTINGS_MAIN_GEOM).toByteArray()); + restoreState(appsettings->value(this, GC_SETTINGS_MAIN_STATE).toByteArray()); + } else { + QRect screenSize = desktop->availableGeometry(); + // first run -- lets set some sensible defaults... + // lets put it in the middle of screen 1 + struct SizeSettings app = GCColor::defaultSizes(screenSize.height(), screenSize.width()); - if (geom == QVariant()) { + // center on the available screen (minus toolbar/sidebar) + move((screenSize.width()-screenSize.x())/2 - app.width/2, + (screenSize.height()-screenSize.y())/2 - app.height/2); - // first run -- lets set some sensible defaults... - // lets put it in the middle of screen 1 - struct SizeSettings app = GCColor::defaultSizes(screenSize.height(), screenSize.width()); + // set to the right default + resize(app.width, app.height); - // center on the available screen (minus toolbar/sidebar) - move((screenSize.width()-screenSize.x())/2 - app.width/2, - (screenSize.height()-screenSize.y())/2 - app.height/2); + // set all the default font sizes + appsettings->setValue(GC_FONT_DEFAULT_SIZE, app.defaultFont); + appsettings->setValue(GC_FONT_TITLES_SIZE, app.titleFont); + appsettings->setValue(GC_FONT_CHARTMARKERS_SIZE, app.markerFont); + appsettings->setValue(GC_FONT_CHARTLABELS_SIZE, app.labelFont); + appsettings->setValue(GC_FONT_CALENDAR_SIZE, app.calendarFont); - // set to the right default - resize(app.width, app.height); - - // set all the default font sizes - appsettings->setValue(GC_FONT_DEFAULT_SIZE, app.defaultFont); - appsettings->setValue(GC_FONT_TITLES_SIZE, app.titleFont); - appsettings->setValue(GC_FONT_CHARTMARKERS_SIZE, app.markerFont); - appsettings->setValue(GC_FONT_CHARTLABELS_SIZE, app.labelFont); - appsettings->setValue(GC_FONT_CALENDAR_SIZE, app.calendarFont); - - } else { - - QRect appsize = geom.toRect(); -#ifdef Q_OS_WIN - //Check if the window is the same size as the available area - //if it is them it was maximised when geom was saved - //Not sure about Mac so have made it windows only. - if ((appsize.width()+appsize.x()==screenSize.width()) && - (appsize.height()+appsize.y()==screenSize.height())) { - setWindowState(Qt::WindowMaximized); - } else { - setGeometry(appsize); - } -#else - setGeometry(appsize); -#endif - } - - // if the window is not maximised - if (!isMaximized()) { - // just check the geometry is ok, otherwise just make - // it slightly smaller than the screensize - if (geometry().x() < 0 || geometry().y() < 0 || - (geometry().y()+geometry().height()) > screenSize.height() || (geometry().x()+geometry().width()) > screenSize.width()) { - setGeometry(screenSize.x()+50,screenSize.y()+50,screenSize.width()-150,screenSize.height()-150); - } - - // always attempt to center on the available screen (minus toolbar/sidebar) - move(((screenSize.width()-screenSize.x())/2) - (geometry().width()/2), - ((screenSize.height()-screenSize.y())/2) - (geometry().height()/2)); - } + } /*---------------------------------------------------------------------- * ScopeBar @@ -717,7 +685,7 @@ MainWindow::MainWindow(const QDir &home) //connect(this, SIGNAL(rideDirty()), this, SLOT(enableSaveButton())); //connect(this, SIGNAL(rideClean()), this, SLOT(enableSaveButton())); - saveState(currentTab->context); // set to whatever we started with + saveGCState(currentTab->context); // set to whatever we started with selectAnalysis(); //grab focus @@ -937,7 +905,8 @@ MainWindow::resizeEvent(QResizeEvent*) repaint(); } #endif - appsettings->setValue(GC_SETTINGS_MAIN_GEOM, geometry()); + appsettings->setValue(GC_SETTINGS_MAIN_GEOM, saveGeometry()); + appsettings->setValue(GC_SETTINGS_MAIN_STATE, saveState()); } void @@ -953,7 +922,7 @@ MainWindow::showOptions() void MainWindow::moveEvent(QMoveEvent*) { - appsettings->setValue(GC_SETTINGS_MAIN_GEOM, geometry()); + appsettings->setValue(GC_SETTINGS_MAIN_GEOM, saveGeometry()); } void @@ -994,7 +963,8 @@ MainWindow::closeEvent(QCloseEvent* event) } #endif } - appsettings->setValue(GC_SETTINGS_MAIN_GEOM, geometry()); + appsettings->setValue(GC_SETTINGS_MAIN_GEOM, saveGeometry()); + appsettings->setValue(GC_SETTINGS_MAIN_STATE, saveState()); } MainWindow::~MainWindow() @@ -1445,8 +1415,8 @@ MainWindow::openTab(QString name) selectAnalysis(); // sets scope bar .. // now apply current - saveState(currentTab->context); - restoreState(currentTab->context); + saveGCState(currentTab->context); + restoreGCState(currentTab->context); // show the tabbar if we're gonna open tabs -- but wait till the last second // to show it to avoid crappy paint artefacts @@ -1607,7 +1577,7 @@ MainWindow::setOpenTabMenu() } void -MainWindow::saveState(Context *context) +MainWindow::saveGCState(Context *context) { // save all the current state to the supplied context context->showSidebar = showhideSidebar->isChecked(); @@ -1625,7 +1595,7 @@ MainWindow::saveState(Context *context) } void -MainWindow::restoreState(Context *context) +MainWindow::restoreGCState(Context *context) { // restore window state from the supplied context showSidebar(context->showSidebar); @@ -1661,13 +1631,13 @@ MainWindow::switchTab(int index) #endif // save how we are - saveState(currentTab->context); + saveGCState(currentTab->context); currentTab = tabList[index]; tabStack->setCurrentIndex(index); // restore back - restoreState(currentTab->context); + restoreGCState(currentTab->context); setWindowTitle(currentTab->context->athlete->home.dirName()); diff --git a/src/MainWindow.h b/src/MainWindow.h index 3341c8465..0879a1f3c 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -189,8 +189,8 @@ class MainWindow : public QMainWindow bool saveRideExitDialog(Context *); // save dirty rides on exit dialog // save and restore state to context - void saveState(Context *); - void restoreState(Context *); + void saveGCState(Context *); + void restoreGCState(Context *); void configChanged(); diff --git a/src/Settings.h b/src/Settings.h index e3df32d70..79db875b9 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -32,6 +32,7 @@ #define GC_SETTINGS_MAIN_X "mainwindow/x" #define GC_SETTINGS_MAIN_Y "mainwindow/y" #define GC_SETTINGS_MAIN_GEOM "mainwindow/geometry" +#define GC_SETTINGS_MAIN_STATE "mainwindow/state" #define GC_SETTINGS_SPLITTER_SIZES "mainwindow/splitterSizes" #define GC_SETTINGS_CALENDAR_SIZES "mainwindow/calendarSizes" #define GC_TABS_TO_HIDE "mainwindow/tabsToHide"