1 #include "mainwindow.h" |
1 #include "src/mainwindow.h" |
|
2 #include "src/modelsubwindow.h" |
|
3 #include "src/version.h" |
|
4 #include <QTextBrowser> |
|
5 #include <QOpenGLWidget> |
|
6 #include <ui_about.h> |
2 |
7 |
3 static constexpr MemberData<MainWindow, QAction*, gl::RenderStyle> renderStyleButtons[] = { |
8 static constexpr MemberData<MainWindow, QAction*, gl::RenderStyle> renderStyleButtons[] = { |
4 { offsetof(MainWindow, actionRenderStyleNormal), gl::RenderStyle::Normal }, |
9 { offsetof(MainWindow, actionRenderStyleNormal), gl::RenderStyle::Normal }, |
5 { offsetof(MainWindow, actionRenderStyleBfc), gl::RenderStyle::BfcRedGreen }, |
10 { offsetof(MainWindow, actionRenderStyleBfc), gl::RenderStyle::BfcRedGreen }, |
6 { offsetof(MainWindow, actionRenderStyleRandom), gl::RenderStyle::RandomColors }, |
11 { offsetof(MainWindow, actionRenderStyleRandom), gl::RenderStyle::RandomColors }, |
18 QObject::connect(action, &QAction::triggered, [this, newStyle]{ |
23 QObject::connect(action, &QAction::triggered, [this, newStyle]{ |
19 Q_EMIT this->renderStyleSelected(newStyle); |
24 Q_EMIT this->renderStyleSelected(newStyle); |
20 this->setRenderStyle(newStyle); |
25 this->setRenderStyle(newStyle); |
21 }); |
26 }); |
22 } |
27 } |
|
28 this->connect(this->actionAbout, &QAction::triggered, this, &MainWindow::showAboutDialog); |
23 } |
29 } |
24 |
30 |
25 void MainWindow::setRenderStyle(gl::RenderStyle style) |
31 void MainWindow::setRenderStyle(gl::RenderStyle style) |
26 { |
32 { |
27 for (const auto& memberData : ::renderStyleButtons) |
33 for (const auto& memberData : ::renderStyleButtons) |
29 QAction* const action = memberData.memberInstance(this); |
35 QAction* const action = memberData.memberInstance(this); |
30 const gl::RenderStyle buttonRenderStyle = memberData.payload; |
36 const gl::RenderStyle buttonRenderStyle = memberData.payload; |
31 action->setChecked(style == buttonRenderStyle); |
37 action->setChecked(style == buttonRenderStyle); |
32 } |
38 } |
33 } |
39 } |
|
40 |
|
41 static QStringList getGLExtensions(QWidget* parent) |
|
42 { |
|
43 // We need to have GL activated at least once in order to able to retrieve |
|
44 // GL extensions properly. To make sure this is the case, we create a |
|
45 // temporary, plain OpenGL widget. While it is active, we call glewInit(). |
|
46 // If this is not done, this function will crash. |
|
47 QOpenGLWidget glWidget{parent}; |
|
48 glWidget.show(); |
|
49 glewInit(); |
|
50 GLint numExtensions; |
|
51 glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); |
|
52 QStringList extensionsList; |
|
53 for (GLint i = 0; i < numExtensions; i++) { |
|
54 const GLubyte* ext = glGetStringi(GL_EXTENSIONS, i); |
|
55 extensionsList.push_back(reinterpret_cast<const char*>(ext)); |
|
56 } |
|
57 glWidget.hide(); |
|
58 return extensionsList; |
|
59 } |
|
60 |
|
61 void MainWindow::showAboutDialog() |
|
62 { |
|
63 QDialog dialog{this}; |
|
64 Ui_About ui; |
|
65 ui.setupUi(&dialog); |
|
66 const char* glVersion = reinterpret_cast<const char*>(glGetString(GL_VERSION)); |
|
67 const QString extensions = getGLExtensions(this).join(" "); |
|
68 for (QTextBrowser* browser : dialog.findChildren<QTextBrowser*>()) { |
|
69 browser->setHtml( |
|
70 browser->toHtml() |
|
71 .replace("%APPNAME%", CMAKE_PROJECT_NAME) |
|
72 .replace("%COPYRIGHT%", COPYRIGHT) |
|
73 .replace("%QTVERSION%", qVersion()) |
|
74 .replace("%VERSION%", detailedVersionString(QLocale::LongFormat)) |
|
75 .replace("%REVDATE%", revisionDateString(QLocale::LongFormat)) |
|
76 .replace("%BUILDTYPE%", CMAKE_BUILD_TYPE) |
|
77 .replace("%COMPILER_ID%", CMAKE_CXX_COMPILER_ID) |
|
78 .replace("%COMPILER_VERSION%", CMAKE_CXX_COMPILER_VERSION) |
|
79 .replace("%COMPILER_FLAGS%", CMAKE_CXX_FLAGS) |
|
80 .replace("%COMPILER_CPU%", CMAKE_SYSTEM_PROCESSOR) |
|
81 .replace("%COMPILER_SYSTEM%", CMAKE_SYSTEM) |
|
82 .replace("%GLMVERSIONSTRING%", GLM_VERSION_MESSAGE) |
|
83 .replace("%GL_VERSION%", glVersion) |
|
84 .replace("%GL_EXTENSIONS%", extensions) |
|
85 ); |
|
86 } |
|
87 dialog.setWindowTitle(QObject::tr("About %1").arg(CMAKE_PROJECT_NAME)); |
|
88 dialog.exec(); |
|
89 } |