diff -r c229d38f04c6 -r 91053052bb28 src/mainwindow.cpp --- a/src/mainwindow.cpp Sat Apr 08 16:12:12 2023 +0300 +++ b/src/mainwindow.cpp Sat Apr 08 16:41:40 2023 +0300 @@ -1,17 +1,33 @@ -/* - * LDForge: LDraw parts authoring CAD - * Copyright (C) 2013 - 2020 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ +#include "mainwindow.h" + +static constexpr MemberData renderStyleButtons[] = { + { offsetof(MainWindow, actionRenderStyleNormal), gl::RenderStyle::Normal }, + { offsetof(MainWindow, actionRenderStyleBfc), gl::RenderStyle::BfcRedGreen }, + { offsetof(MainWindow, actionRenderStyleRandom), gl::RenderStyle::RandomColors }, + { offsetof(MainWindow, actionRenderStylePickScene), gl::RenderStyle::PickScene }, +}; + +MainWindow::MainWindow(QWidget *parent) +: QMainWindow{parent} +{ + this->setupUi(this); + for (const auto& memberData : ::renderStyleButtons) + { + QAction* action = memberData.memberInstance(this); + const gl::RenderStyle newStyle = memberData.payload; + QObject::connect(action, &QAction::triggered, [this, newStyle]{ + Q_EMIT this->renderStyleSelected(newStyle); + this->setRenderStyle(newStyle); + }); + } +} + +void MainWindow::setRenderStyle(gl::RenderStyle style) +{ + for (const auto& memberData : ::renderStyleButtons) + { + QAction* const action = memberData.memberInstance(this); + const gl::RenderStyle buttonRenderStyle = memberData.payload; + action->setChecked(style == buttonRenderStyle); + } +}