src/mainwindow.cpp

changeset 354
91053052bb28
parent 201
5d201ee4a9c3
child 355
e81f4ad53efd
equal deleted inserted replaced
353:c229d38f04c6 354:91053052bb28
1 /* 1 #include "mainwindow.h"
2 * LDForge: LDraw parts authoring CAD 2
3 * Copyright (C) 2013 - 2020 Teemu Piippo 3 static constexpr MemberData<MainWindow, QAction*, gl::RenderStyle> renderStyleButtons[] = {
4 * 4 { offsetof(MainWindow, actionRenderStyleNormal), gl::RenderStyle::Normal },
5 * This program is free software: you can redistribute it and/or modify 5 { offsetof(MainWindow, actionRenderStyleBfc), gl::RenderStyle::BfcRedGreen },
6 * it under the terms of the GNU General Public License as published by 6 { offsetof(MainWindow, actionRenderStyleRandom), gl::RenderStyle::RandomColors },
7 * the Free Software Foundation, either version 3 of the License, or 7 { offsetof(MainWindow, actionRenderStylePickScene), gl::RenderStyle::PickScene },
8 * (at your option) any later version. 8 };
9 * 9
10 * This program is distributed in the hope that it will be useful, 10 MainWindow::MainWindow(QWidget *parent)
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : QMainWindow{parent}
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 {
13 * GNU General Public License for more details. 13 this->setupUi(this);
14 * 14 for (const auto& memberData : ::renderStyleButtons)
15 * You should have received a copy of the GNU General Public License 15 {
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 QAction* action = memberData.memberInstance(this);
17 */ 17 const gl::RenderStyle newStyle = memberData.payload;
18 QObject::connect(action, &QAction::triggered, [this, newStyle]{
19 Q_EMIT this->renderStyleSelected(newStyle);
20 this->setRenderStyle(newStyle);
21 });
22 }
23 }
24
25 void MainWindow::setRenderStyle(gl::RenderStyle style)
26 {
27 for (const auto& memberData : ::renderStyleButtons)
28 {
29 QAction* const action = memberData.memberInstance(this);
30 const gl::RenderStyle buttonRenderStyle = memberData.payload;
31 action->setChecked(style == buttonRenderStyle);
32 }
33 }

mercurial