MainWindow now stores its state in the config file so its state and geometry is preserved across instances

Sat, 24 Mar 2018 15:54:41 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 24 Mar 2018 15:54:41 +0200
changeset 1335
5530161fcd47
parent 1334
3ab821604a70
child 1336
299d90af2fc3

MainWindow now stores its state in the config file so its state and geometry is preserved across instances

src/configurationoptions.txt file | annotate | diff | comparison | revisions
src/mainwindow.cpp file | annotate | diff | comparison | revisions
src/mainwindow.h file | annotate | diff | comparison | revisions
--- a/src/configurationoptions.txt	Sat Mar 24 13:55:08 2018 +0200
+++ b/src/configurationoptions.txt	Sat Mar 24 15:54:41 2018 +0200
@@ -24,7 +24,6 @@
 option ColorizeObjectsList = true
 option QuickColorToolbar = "4:25:14:27:2:3:11:1:22:|:0:72:71:15"
 option ListImplicitFiles = false
-option HiddenToolbars = QStringList {}
 option RecentFiles = QStringList {}
 option TryDownloadMissingFiles = false
 option DefaultName = ""
@@ -69,6 +68,8 @@
 option Lighting = true
 option DrawLineLengths = true
 option DrawAngles = false
+option MainWindowState = QByteArray {}
+option MainWindowGeometry = QByteArray {}
 
 # File management options
 option Libraries = QVector<Library> {}
--- a/src/mainwindow.cpp	Sat Mar 24 13:55:08 2018 +0200
+++ b/src/mainwindow.cpp	Sat Mar 24 15:54:41 2018 +0200
@@ -61,6 +61,8 @@
 {
 	m_messageLog = new MessageManager {this};
 	ui.setupUi (this);
+	this->restoreGeometry(config::mainWindowGeometry());
+	this->restoreState(config::mainWindowState());
 	m_updatingTabs = false;
 	m_tabs = new QTabBar;
 	m_tabs->setTabsClosable (true);
@@ -137,14 +139,6 @@
 		}
 	}
 
-	for (QVariant const& toolbarname : config::hiddenToolbars())
-	{
-		QToolBar* toolbar = findChild<QToolBar*> (toolbarname.toString());
-
-		if (toolbar)
-			toolbar->hide();
-	}
-
 	// If this is the first start, get the user to configuration. Especially point
 	// them to the profile tab, it's the most important form to fill in.
 	if (config::firstStart())
@@ -418,28 +412,21 @@
 
 // ---------------------------------------------------------------------------------------------------------------------
 //
-void MainWindow::closeEvent (QCloseEvent* ev)
+void MainWindow::closeEvent(QCloseEvent* event)
 {
 	// Check whether it's safe to close all files.
-	if (not m_documents->isSafeToCloseAll())
+	if (m_documents->isSafeToCloseAll())
 	{
-		ev->ignore();
-		return;
+		// Store the state of the main window before closing.
+		config::setMainWindowGeometry(this->saveGeometry());
+		config::setMainWindowState(this->saveState());
+		settingsObject().sync();
+		event->accept();
 	}
-
-	// Save the toolbar set
-	QStringList hiddenToolbars;
-
-	for (QToolBar* toolbar : findChildren<QToolBar*>())
+	else
 	{
-		if (toolbar->isHidden())
-			hiddenToolbars << toolbar->objectName();
+		event->ignore();
 	}
-
-	// Save the configuration before leaving.
-	config::setHiddenToolbars (hiddenToolbars);
-	settingsObject().sync();
-	ev->accept();
 }
 
 // ---------------------------------------------------------------------------------------------------------------------
--- a/src/mainwindow.h	Sat Mar 24 13:55:08 2018 +0200
+++ b/src/mainwindow.h	Sat Mar 24 15:54:41 2018 +0200
@@ -131,7 +131,7 @@
 	void updateTitle();
 
 protected:
-	void closeEvent (QCloseEvent* ev);
+	void closeEvent (QCloseEvent* event);
 
 private:
 	struct ToolInfo;

mercurial