src/mainwindow.cpp

changeset 362
e1d646a4cbd8
parent 361
c5e8b68e34f8
--- a/src/mainwindow.cpp	Sun Apr 09 13:28:36 2023 +0300
+++ b/src/mainwindow.cpp	Sun Apr 09 15:59:08 2023 +0300
@@ -4,6 +4,7 @@
 #include <QTextBrowser>
 #include <QOpenGLWidget>
 #include <ui_about.h>
+#include "src/settings.h"
 
 static constexpr MemberData<MainWindow, QAction*, gl::RenderStyle> renderStyleButtons[] = {
 	{ offsetof(MainWindow, actionRenderStyleNormal), gl::RenderStyle::Normal },
@@ -26,6 +27,19 @@
 		});
 	}
 	this->connect(this->actionAbout, &QAction::triggered, this, &MainWindow::showAboutDialog);
+	this->connect(this->mdiArea, &QMdiArea::subWindowActivated, this, &MainWindow::updateTitle);
+	this->gridMatrix->setValue(DEFAULT_GRID_MATRIX);
+	this->tabifyDockWidget(this->messageLogDock, this->toolOptionsDock);
+	this->restoreGeometry(setting<Setting::MainWindowGeometry>());
+	this->restoreState(setting<Setting::MainWindowState>());
+	// If a dock is made floating and the app is closed, the dock becomes invisible
+	// after the restoreState call. So we make them visible again here.
+	for (QDockWidget* dock : this->findChildren<QDockWidget*>()) {
+		dock->setVisible(true);
+	}
+	this->actionAbout->setText(this->actionAbout->text().arg(CMAKE_PROJECT_NAME));
+	this->updateTitle();
+	this->show();
 }
 
 void MainWindow::setRenderStyle(gl::RenderStyle style)
@@ -100,3 +114,28 @@
 		});
 	}
 }
+
+static QString title(MainWindow* ui)
+{
+	QMdiSubWindow* subWindow = ui->mdiArea->activeSubWindow();
+	QString titlestring;
+	const QString versionString = fullVersionString(QLocale::ShortFormat);
+	if (subWindow != nullptr) {
+		titlestring = QObject::tr("%1 - %2").arg(subWindow->windowTitle(), versionString);
+	}
+	else {
+		titlestring = versionString;
+	}
+	if (/* DISABLES CODE */ (true)
+		and std::strcmp(CMAKE_BUILD_TYPE, "Release") != 0
+		and std::strcmp(CMAKE_BUILD_TYPE, "MinSizeRel") != 0
+	) {
+		titlestring += QObject::tr(" [%1]").arg(CMAKE_BUILD_TYPE);
+	}
+	return titlestring;
+}
+
+void MainWindow::updateTitle()
+{
+	this->setWindowTitle(title(this));
+}

mercurial