src/mainwindow.cpp

changeset 362
e1d646a4cbd8
parent 361
c5e8b68e34f8
equal deleted inserted replaced
361:c5e8b68e34f8 362:e1d646a4cbd8
2 #include "src/modelsubwindow.h" 2 #include "src/modelsubwindow.h"
3 #include "src/version.h" 3 #include "src/version.h"
4 #include <QTextBrowser> 4 #include <QTextBrowser>
5 #include <QOpenGLWidget> 5 #include <QOpenGLWidget>
6 #include <ui_about.h> 6 #include <ui_about.h>
7 #include "src/settings.h"
7 8
8 static constexpr MemberData<MainWindow, QAction*, gl::RenderStyle> renderStyleButtons[] = { 9 static constexpr MemberData<MainWindow, QAction*, gl::RenderStyle> renderStyleButtons[] = {
9 { offsetof(MainWindow, actionRenderStyleNormal), gl::RenderStyle::Normal }, 10 { offsetof(MainWindow, actionRenderStyleNormal), gl::RenderStyle::Normal },
10 { offsetof(MainWindow, actionRenderStyleBfc), gl::RenderStyle::BfcRedGreen }, 11 { offsetof(MainWindow, actionRenderStyleBfc), gl::RenderStyle::BfcRedGreen },
11 { offsetof(MainWindow, actionRenderStyleRandom), gl::RenderStyle::RandomColors }, 12 { offsetof(MainWindow, actionRenderStyleRandom), gl::RenderStyle::RandomColors },
24 Q_EMIT this->renderStyleSelected(newStyle); 25 Q_EMIT this->renderStyleSelected(newStyle);
25 this->setRenderStyle(newStyle); 26 this->setRenderStyle(newStyle);
26 }); 27 });
27 } 28 }
28 this->connect(this->actionAbout, &QAction::triggered, this, &MainWindow::showAboutDialog); 29 this->connect(this->actionAbout, &QAction::triggered, this, &MainWindow::showAboutDialog);
30 this->connect(this->mdiArea, &QMdiArea::subWindowActivated, this, &MainWindow::updateTitle);
31 this->gridMatrix->setValue(DEFAULT_GRID_MATRIX);
32 this->tabifyDockWidget(this->messageLogDock, this->toolOptionsDock);
33 this->restoreGeometry(setting<Setting::MainWindowGeometry>());
34 this->restoreState(setting<Setting::MainWindowState>());
35 // If a dock is made floating and the app is closed, the dock becomes invisible
36 // after the restoreState call. So we make them visible again here.
37 for (QDockWidget* dock : this->findChildren<QDockWidget*>()) {
38 dock->setVisible(true);
39 }
40 this->actionAbout->setText(this->actionAbout->text().arg(CMAKE_PROJECT_NAME));
41 this->updateTitle();
42 this->show();
29 } 43 }
30 44
31 void MainWindow::setRenderStyle(gl::RenderStyle style) 45 void MainWindow::setRenderStyle(gl::RenderStyle style)
32 { 46 {
33 for (const auto& memberData : ::renderStyleButtons) 47 for (const auto& memberData : ::renderStyleButtons)
98 connect(action, &QAction::triggered, [&, path]{ 112 connect(action, &QAction::triggered, [&, path]{
99 Q_EMIT this->recentFileSelected(path); 113 Q_EMIT this->recentFileSelected(path);
100 }); 114 });
101 } 115 }
102 } 116 }
117
118 static QString title(MainWindow* ui)
119 {
120 QMdiSubWindow* subWindow = ui->mdiArea->activeSubWindow();
121 QString titlestring;
122 const QString versionString = fullVersionString(QLocale::ShortFormat);
123 if (subWindow != nullptr) {
124 titlestring = QObject::tr("%1 - %2").arg(subWindow->windowTitle(), versionString);
125 }
126 else {
127 titlestring = versionString;
128 }
129 if (/* DISABLES CODE */ (true)
130 and std::strcmp(CMAKE_BUILD_TYPE, "Release") != 0
131 and std::strcmp(CMAKE_BUILD_TYPE, "MinSizeRel") != 0
132 ) {
133 titlestring += QObject::tr(" [%1]").arg(CMAKE_BUILD_TYPE);
134 }
135 return titlestring;
136 }
137
138 void MainWindow::updateTitle()
139 {
140 this->setWindowTitle(title(this));
141 }

mercurial