Sat, 08 Apr 2023 16:41:40 +0300
Readd the MainWindow class and renderstyle button handling to it
354
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
1 | #include "mainwindow.h" |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
2 | |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
3 | 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
|
4 | { 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
|
5 | { 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
|
6 | { 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
|
7 | { 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
|
8 | }; |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
9 | |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
10 | 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
|
11 | : QMainWindow{parent} |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
12 | { |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
13 | 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
|
14 | 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
|
15 | { |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
16 | 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
|
17 | 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
|
18 | 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
|
19 | 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
|
20 | 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
|
21 | }); |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
22 | } |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
23 | } |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
24 | |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
25 | 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
|
26 | { |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
27 | 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
|
28 | { |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
29 | 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
|
30 | 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
|
31 | 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
|
32 | } |
91053052bb28
Readd the MainWindow class and renderstyle button handling to it
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
201
diff
changeset
|
33 | } |