Sat, 08 Apr 2023 16:59:55 +0300
Move the about dialog to MainWindow. The hack to retrieve GL extensions is made a bit cleaner
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> |
354
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
7 | |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
8 | 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
|
9 | { 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
|
10 | { 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
|
11 | { 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
|
12 | { 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
|
13 | }; |
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 | 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
|
16 | : QMainWindow{parent} |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
17 | { |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
18 | 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
|
19 | 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
|
20 | { |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
21 | 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
|
22 | 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
|
23 | 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
|
24 | 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
|
25 | 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
|
26 | }); |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
27 | } |
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
|
28 | this->connect(this->actionAbout, &QAction::triggered, this, &MainWindow::showAboutDialog); |
354
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
29 | } |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
30 | |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
31 | 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
|
32 | { |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
33 | 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
|
34 | { |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
35 | 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
|
36 | 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
|
37 | 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
|
38 | } |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
39 | } |
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
|
40 | |
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
|
41 | 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
|
42 | { |
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
|
43 | // 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
|
44 | // 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
|
45 | // 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
|
46 | // 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
|
47 | 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
|
48 | 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
|
49 | 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
|
50 | 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
|
51 | 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
|
52 | 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
|
53 | 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
|
54 | 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
|
55 | 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
|
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 | 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
|
58 | 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
|
59 | } |
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 | |
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 | 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
|
62 | { |
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 | 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
|
64 | 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
|
65 | 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
|
66 | 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
|
67 | 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
|
68 | 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
|
69 | 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
|
70 | 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
|
71 | .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
|
72 | .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
|
73 | .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
|
74 | .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
|
75 | .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
|
76 | .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
|
77 | .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
|
78 | .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
|
79 | .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
|
80 | .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
|
81 | .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
|
82 | .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
|
83 | .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
|
84 | .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
|
85 | ); |
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 | } |
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 | 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
|
88 | 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
|
89 | } |