# HG changeset patch # User Teemu Piippo # Date 1580423135 -7200 # Node ID bbb901b974040157b2c024292f7784a5e424104c # Parent 98906a94732f61088c37e561eac472a52c0cb155 added render style storage diff -r 98906a94732f -r bbb901b97404 locale/fi.ts --- a/locale/fi.ts Thu Jan 30 19:20:11 2020 +0200 +++ b/locale/fi.ts Fri Jan 31 00:25:35 2020 +0200 @@ -131,57 +131,77 @@ - + + View + + + + Quit - + Open… - + Ctrl+O - + New - + Ctrl+N - + Preferences… - + + Normal colours + + + + + BFC color coding + + + + + Random colours + + + + Open model - + LDraw models (*.ldr *.dat) - + Problem loading references - + Problem opening file - + Could not open %1: %2 diff -r 98906a94732f -r bbb901b97404 locale/sv.ts --- a/locale/sv.ts Thu Jan 30 19:20:11 2020 +0200 +++ b/locale/sv.ts Fri Jan 31 00:25:35 2020 +0200 @@ -208,6 +208,22 @@ Problem loading references + + View + + + + Normal colours + + + + BFC color coding + + + + Random colours + + PartRenderer diff -r 98906a94732f -r bbb901b97404 src/document.cpp --- a/src/document.cpp Thu Jan 30 19:20:11 2020 +0200 +++ b/src/document.cpp Fri Jan 31 00:25:35 2020 +0200 @@ -54,3 +54,8 @@ { this->ui.splitter->restoreState(state); } + +void Document::setRenderStyle(gl::RenderStyle newRenderStyle) +{ + this->renderer->setRenderStyle(newRenderStyle); +} diff -r 98906a94732f -r bbb901b97404 src/document.h --- a/src/document.h Thu Jan 30 19:20:11 2020 +0200 +++ b/src/document.h Fri Jan 31 00:25:35 2020 +0200 @@ -40,6 +40,7 @@ ~Document(); QByteArray saveSplitterState() const; void restoreSplitterState(const QByteArray& state); + void setRenderStyle(gl::RenderStyle newRenderStyle); signals: void splitterChanged(); private: diff -r 98906a94732f -r bbb901b97404 src/gl/partrenderer.h --- a/src/gl/partrenderer.h Thu Jan 30 19:20:11 2020 +0200 +++ b/src/gl/partrenderer.h Fri Jan 31 00:25:35 2020 +0200 @@ -21,14 +21,13 @@ const ldraw::ColorTable& colorTable, QWidget* parent = nullptr); ~PartRenderer() override; + void setRenderStyle(const gl::RenderStyle newStyle); protected: void initializeGL() override; void resizeGL(int width, int height) override; void paintGL() override; void mouseMoveEvent(QMouseEvent* event) override; void wheelEvent(QWheelEvent* event) override; -private slots: - void setRenderStyle(const gl::RenderStyle newStyle); private: void renderScene(); void updateViewMatrix(); diff -r 98906a94732f -r bbb901b97404 src/main.cpp --- a/src/main.cpp Thu Jan 30 19:20:11 2020 +0200 +++ b/src/main.cpp Fri Jan 31 00:25:35 2020 +0200 @@ -23,7 +23,6 @@ int main(int argc, char *argv[]) { - ldraw::Color color = ldraw::red; ::glutInit(&argc, argv); QCoreApplication::setApplicationName(::appName); QCoreApplication::setOrganizationName("hecknology.net"); diff -r 98906a94732f -r bbb901b97404 src/mainwindow.cpp --- a/src/mainwindow.cpp Thu Jan 30 19:20:11 2020 +0200 +++ b/src/mainwindow.cpp Fri Jan 31 00:25:35 2020 +0200 @@ -28,6 +28,23 @@ #include "document.h" #include "uiutilities.h" +template +struct MemberData +{ + std::size_t member; + DataType payload; + constexpr MemberType memberInstance(BaseType* instance) const + { + return *reinterpret_cast(reinterpret_cast(instance) + this->member); + } +}; + +static constexpr MemberData renderStyleButtons[] = { + { offsetof(Ui_MainWindow, actionRenderStyleNormal), gl::RenderStyle::Normal }, + { offsetof(Ui_MainWindow, actionRenderStyleBfc), gl::RenderStyle::BfcRedGreen }, + { offsetof(Ui_MainWindow, actionRenderStyleRandom), gl::RenderStyle::RandomColors }, +}; + MainWindow::MainWindow(QWidget *parent) : QMainWindow{parent}, ui{std::make_unique()}, @@ -41,8 +58,17 @@ connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::openModel); connect(ui->actionQuit, &QAction::triggered, this, &QMainWindow::close); connect(ui->actionSettingsEditor, &QAction::triggered, this, &MainWindow::runSettingsEditor); + for (auto data : ::renderStyleButtons) + { + QAction* action = data.memberInstance(this->ui.get()); + connect(action, &QAction::triggered, [this, data]() + { + this->setRenderStyle(data.payload); + }); + } this->updateTitle(); this->restoreSettings(); + this->updateRenderStyles(); this->newModel(); } @@ -136,6 +162,7 @@ void MainWindow::openModelForEditing(const QString& modelName) { Document* document = new Document{this->documents.findModelByName(modelName), &this->documents, this->colorTable}; + document->setRenderStyle(this->renderStyle); this->ui->tabs->addTab(document, modelName); this->ui->tabs->setCurrentWidget(document); document->restoreSplitterState(this->documentSplitterState); @@ -192,6 +219,13 @@ } } +void MainWindow::setRenderStyle(gl::RenderStyle renderStyle) +{ + this->renderStyle = renderStyle; + this->saveSettings(); + this->updateRenderStyles(); +} + void MainWindow::changeEvent(QEvent* event) { if (event != nullptr) @@ -230,6 +264,23 @@ setWindowTitle(title); } +void MainWindow::updateRenderStyles() +{ + for (int i = 0; i < this->ui->tabs->count(); i += 1) + { + Document* document = qobject_cast(this->ui->tabs->widget(i)); + if (document != nullptr) + { + document->setRenderStyle(renderStyle); + } + } + for (auto data : ::renderStyleButtons) + { + QAction* action = data.memberInstance(this->ui.get()); + action->setChecked(this->renderStyle == data.payload); + } +} + /** * @brief Stores the settings of the main window, storing geometry, etc */ @@ -238,6 +289,7 @@ this->settings.setValue("MainWindow/Geometry", this->saveGeometry()); this->settings.setValue("MainWindow/RecentlyOpened", this->recentlyOpenedFiles); this->settings.setValue("MainWindow/DocumentSplitterState", this->documentSplitterState); + this->settings.setValue("MainWindow/RenderStyle", static_cast(this->renderStyle)); this->libraries.storeToSettings(&this->settings); } @@ -249,6 +301,7 @@ this->restoreGeometry(this->settings.value("MainWindow/Geometry").toByteArray()); this->recentlyOpenedFiles = this->settings.value("MainWindow/RecentlyOpened").toStringList(); this->documentSplitterState = this->settings.value("MainWindow/DocumentSplitterState").toByteArray(); + this->renderStyle = static_cast(this->settings.value("MainWindow/RenderStyle").toInt()); const QString systemLocale = QLocale::system().name(); const QVariant defaultLocale = this->settings.value("locale", systemLocale); changeLanguage(defaultLocale.toString()); diff -r 98906a94732f -r bbb901b97404 src/mainwindow.h --- a/src/mainwindow.h Thu Jan 30 19:20:11 2020 +0200 +++ b/src/mainwindow.h Fri Jan 31 00:25:35 2020 +0200 @@ -39,6 +39,7 @@ void handleDocumentSplitterChange(); void updateRecentlyOpenedDocumentsMenu(); void openRecentFile(); + void setRenderStyle(gl::RenderStyle renderStyle); protected: void changeEvent(QEvent* event) override; void closeEvent(QCloseEvent* event) override; @@ -55,7 +56,9 @@ static constexpr int maxRecentlyOpenedFiles = 10; QStringList recentlyOpenedFiles; ldraw::ColorTable colorTable; + gl::RenderStyle renderStyle; void updateTitle(); + void updateRenderStyles(); void saveSettings(); void restoreSettings(); void changeLanguage(QString localeCode); diff -r 98906a94732f -r bbb901b97404 src/mainwindow.ui --- a/src/mainwindow.ui Thu Jan 30 19:20:11 2020 +0200 +++ b/src/mainwindow.ui Fri Jan 31 00:25:35 2020 +0200 @@ -26,7 +26,7 @@ 0 0 800 - 27 + 22 @@ -46,7 +46,16 @@ + + + View + + + + + + @@ -75,6 +84,30 @@ Preferences… + + + true + + + Normal colours + + + + + true + + + BFC color coding + + + + + true + + + Random colours + +