src/mainwindow.cpp

Sun, 09 Apr 2023 16:30:33 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sun, 09 Apr 2023 16:30:33 +0300
changeset 367
df61cd3d5ab4
parent 362
e1d646a4cbd8
permissions
-rw-r--r--

Also connect up the "Delete" action

355
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
1 #include "src/mainwindow.h"
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
2 #include "src/modelsubwindow.h"
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
3 #include "src/version.h"
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
4 #include <QTextBrowser>
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
5 #include <QOpenGLWidget>
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
6 #include <ui_about.h>
362
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
7 #include "src/settings.h"
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
8
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
9 static constexpr MemberData<MainWindow, QAction*, gl::RenderStyle> renderStyleButtons[] = {
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
10 { offsetof(MainWindow, actionRenderStyleNormal), gl::RenderStyle::Normal },
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
11 { offsetof(MainWindow, actionRenderStyleBfc), gl::RenderStyle::BfcRedGreen },
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
12 { offsetof(MainWindow, actionRenderStyleRandom), gl::RenderStyle::RandomColors },
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
13 { offsetof(MainWindow, actionRenderStylePickScene), gl::RenderStyle::PickScene },
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
14 };
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
15
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
16 MainWindow::MainWindow(QWidget *parent)
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
17 : QMainWindow{parent}
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
18 {
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
19 this->setupUi(this);
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
20 for (const auto& memberData : ::renderStyleButtons)
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
21 {
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
22 QAction* action = memberData.memberInstance(this);
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
23 const gl::RenderStyle newStyle = memberData.payload;
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
24 QObject::connect(action, &QAction::triggered, [this, newStyle]{
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
25 Q_EMIT this->renderStyleSelected(newStyle);
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
26 this->setRenderStyle(newStyle);
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
27 });
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
28 }
355
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
29 this->connect(this->actionAbout, &QAction::triggered, this, &MainWindow::showAboutDialog);
362
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
30 this->connect(this->mdiArea, &QMdiArea::subWindowActivated, this, &MainWindow::updateTitle);
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
31 this->gridMatrix->setValue(DEFAULT_GRID_MATRIX);
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
32 this->tabifyDockWidget(this->messageLogDock, this->toolOptionsDock);
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
33 this->restoreGeometry(setting<Setting::MainWindowGeometry>());
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
34 this->restoreState(setting<Setting::MainWindowState>());
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
35 // If a dock is made floating and the app is closed, the dock becomes invisible
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
36 // after the restoreState call. So we make them visible again here.
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
37 for (QDockWidget* dock : this->findChildren<QDockWidget*>()) {
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
38 dock->setVisible(true);
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
39 }
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
40 this->actionAbout->setText(this->actionAbout->text().arg(CMAKE_PROJECT_NAME));
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
41 this->updateTitle();
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
42 this->show();
354
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
43 }
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
44
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
45 void MainWindow::setRenderStyle(gl::RenderStyle style)
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
46 {
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
47 for (const auto& memberData : ::renderStyleButtons)
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
48 {
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
49 QAction* const action = memberData.memberInstance(this);
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
50 const gl::RenderStyle buttonRenderStyle = memberData.payload;
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
51 action->setChecked(style == buttonRenderStyle);
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
52 }
91053052bb28 Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 201
diff changeset
53 }
355
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
54
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
55 static QStringList getGLExtensions(QWidget* parent)
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
56 {
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
57 // We need to have GL activated at least once in order to able to retrieve
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
58 // GL extensions properly. To make sure this is the case, we create a
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
59 // temporary, plain OpenGL widget. While it is active, we call glewInit().
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
60 // If this is not done, this function will crash.
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
61 QOpenGLWidget glWidget{parent};
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
62 glWidget.show();
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
63 glewInit();
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
64 GLint numExtensions;
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
65 glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
66 QStringList extensionsList;
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
67 for (GLint i = 0; i < numExtensions; i++) {
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
68 const GLubyte* ext = glGetStringi(GL_EXTENSIONS, i);
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
69 extensionsList.push_back(reinterpret_cast<const char*>(ext));
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
70 }
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
71 glWidget.hide();
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
72 return extensionsList;
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
73 }
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
74
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
75 void MainWindow::showAboutDialog()
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
76 {
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
77 QDialog dialog{this};
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
78 Ui_About ui;
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
79 ui.setupUi(&dialog);
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
80 const char* glVersion = reinterpret_cast<const char*>(glGetString(GL_VERSION));
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
81 const QString extensions = getGLExtensions(this).join(" ");
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
82 for (QTextBrowser* browser : dialog.findChildren<QTextBrowser*>()) {
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
83 browser->setHtml(
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
84 browser->toHtml()
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
85 .replace("%APPNAME%", CMAKE_PROJECT_NAME)
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
86 .replace("%COPYRIGHT%", COPYRIGHT)
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
87 .replace("%QTVERSION%", qVersion())
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
88 .replace("%VERSION%", detailedVersionString(QLocale::LongFormat))
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
89 .replace("%REVDATE%", revisionDateString(QLocale::LongFormat))
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
90 .replace("%BUILDTYPE%", CMAKE_BUILD_TYPE)
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
91 .replace("%COMPILER_ID%", CMAKE_CXX_COMPILER_ID)
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
92 .replace("%COMPILER_VERSION%", CMAKE_CXX_COMPILER_VERSION)
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
93 .replace("%COMPILER_FLAGS%", CMAKE_CXX_FLAGS)
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
94 .replace("%COMPILER_CPU%", CMAKE_SYSTEM_PROCESSOR)
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
95 .replace("%COMPILER_SYSTEM%", CMAKE_SYSTEM)
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
96 .replace("%GLMVERSIONSTRING%", GLM_VERSION_MESSAGE)
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
97 .replace("%GL_VERSION%", glVersion)
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
98 .replace("%GL_EXTENSIONS%", extensions)
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
99 );
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
100 }
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
101 dialog.setWindowTitle(QObject::tr("About %1").arg(CMAKE_PROJECT_NAME));
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
102 dialog.exec();
e81f4ad53efd Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 354
diff changeset
103 }
361
c5e8b68e34f8 Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
104
c5e8b68e34f8 Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
105 void MainWindow::rebuildRecentFilesMenu(const QStringList& strings)
c5e8b68e34f8 Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
106 {
c5e8b68e34f8 Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
107 this->menuRecentFiles->clear();
c5e8b68e34f8 Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
108 for (const QString& path : strings)
c5e8b68e34f8 Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
109 {
c5e8b68e34f8 Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
110 QAction* action = new QAction{path, this};
c5e8b68e34f8 Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
111 this->menuRecentFiles->addAction(action);
c5e8b68e34f8 Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
112 connect(action, &QAction::triggered, [&, path]{
c5e8b68e34f8 Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
113 Q_EMIT this->recentFileSelected(path);
c5e8b68e34f8 Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
114 });
c5e8b68e34f8 Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
115 }
c5e8b68e34f8 Move some recent file handling to MainWindow
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 355
diff changeset
116 }
362
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
117
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
118 static QString title(MainWindow* ui)
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
119 {
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
120 QMdiSubWindow* subWindow = ui->mdiArea->activeSubWindow();
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
121 QString titlestring;
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
122 const QString versionString = fullVersionString(QLocale::ShortFormat);
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
123 if (subWindow != nullptr) {
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
124 titlestring = QObject::tr("%1 - %2").arg(subWindow->windowTitle(), versionString);
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
125 }
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
126 else {
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
127 titlestring = versionString;
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
128 }
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
129 if (/* DISABLES CODE */ (true)
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
130 and std::strcmp(CMAKE_BUILD_TYPE, "Release") != 0
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
131 and std::strcmp(CMAKE_BUILD_TYPE, "MinSizeRel") != 0
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
132 ) {
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
133 titlestring += QObject::tr(" [%1]").arg(CMAKE_BUILD_TYPE);
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
134 }
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
135 return titlestring;
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
136 }
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
137
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
138 void MainWindow::updateTitle()
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
139 {
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
140 this->setWindowTitle(title(this));
e1d646a4cbd8 Extracted the state of the program into a MainState structure, and extracted local functions of main() into static functions.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 361
diff changeset
141 }

mercurial