Show current subwindow title in main window title

Mon, 27 Jun 2022 15:55:27 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Mon, 27 Jun 2022 15:55:27 +0300
changeset 274
1331aba5d36b
parent 273
57952c5ca59b
child 275
dc1b8094c210

Show current subwindow title in main window title

src/main.cpp file | annotate | diff | comparison | revisions
--- a/src/main.cpp	Mon Jun 27 15:50:21 2022 +0300
+++ b/src/main.cpp	Mon Jun 27 15:55:27 2022 +0300
@@ -214,9 +214,16 @@
 	}
 }
 
-static QString title()
+static QString title(Ui_MainWindow* ui)
 {
-	return fullVersionString();
+	QMdiSubWindow* subWindow = ui->mdiArea->activeSubWindow();
+	QString titlestring;
+	if (subWindow != nullptr) {
+		return QObject::tr("%1 - %2").arg(subWindow->windowTitle(), fullVersionString());
+	}
+	else {
+		return fullVersionString();
+	}
 }
 
 static ColorTable loadColors(const LibrariesModel* libraries)
@@ -395,6 +402,9 @@
 		.circleToolOptions = new CircleToolOptionsWidget{&mainWindow},
 		.objectEditor = new ObjectEditor{&mainWindow},
 	};
+	const auto updateTitle = [&ui, &mainWindow]{
+		mainWindow.setWindowTitle(title(&ui));
+	};
 	const uiutilities::KeySequenceMap defaultKeyboardShortcuts =
 		uiutilities::makeKeySequenceMap(uiutilities::collectActions(&mainWindow));
 	const auto saveSettings = [&]{
@@ -687,6 +697,7 @@
 				}
 			}
 		}
+		updateTitle();
 	});
 	ui.messageLog->setModel(&messageLog);
 	QObject::connect(ui.actionAboutQt, &QAction::triggered, &app, &QApplication::aboutQt);
@@ -735,8 +746,8 @@
 	}
 	restoreSettings();
 	updateRenderPreferences(&ui, &renderPreferences, &documents);
-	mainWindow.setWindowTitle(title());
 	ui.actionAbout->setText(ui.actionAbout->text().arg(APPNAME));
+	updateTitle();
 	mainWindow.show();
 	const int result = app.exec();
 	saveSettings();

mercurial