# HG changeset patch # User Teemu Piippo # Date 1580569811 -7200 # Node ID caac957e9834b5d98767c9775662662b33e12f0c # Parent bb60dda3093f8e3681be77414fadc1bebc181c0f Main color is now configurable diff -r bb60dda3093f -r caac957e9834 CMakeLists.txt --- a/CMakeLists.txt Sat Feb 01 15:49:28 2020 +0200 +++ b/CMakeLists.txt Sat Feb 01 17:10:11 2020 +0200 @@ -49,6 +49,7 @@ src/settingseditor/librarieseditor.cpp src/settingseditor/settingseditor.cpp src/types/boundingbox.cpp + src/widgets/colorbutton.cpp ) set (LDFORGE_HEADERS src/basics.h @@ -84,6 +85,7 @@ src/settingseditor/librarieseditor.h src/settingseditor/settingseditor.h src/types/boundingbox.h + src/widgets/colorbutton.h ) set (LDFORGE_FORMS src/document.ui @@ -98,18 +100,18 @@ ) set(LDFORGE_RESOURCES ldforge.qrc) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +include_directories("${PROJECT_BINARY_DIR}") +include_directories("${PROJECT_BINARY_DIR}/src") +include_directories("${PROJECT_SOURCE_DIR}/src") # Translations qt5_create_translation(QM_FILES ${LDFORGE_SOURCES} ${LDFORGE_HEADERS} ${LDFORGE_FORMS} ${LDFORGE_LOCALES}) add_custom_target(translations ALL DEPENDS ${QM_FILES}) add_custom_target(resources ALL DEPENDS ${LDFORGE_RESOURCES}) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) -include_directories("${PROJECT_BINARY_DIR}") -include_directories("${PROJECT_BINARY_DIR}/src") -include_directories("${PROJECT_SOURCE_DIR}/src") if (NOT MSVC) if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG") diff -r bb60dda3093f -r caac957e9834 locale/fi.ts --- a/locale/fi.ts Sat Feb 01 15:49:28 2020 +0200 +++ b/locale/fi.ts Sat Feb 01 17:10:11 2020 +0200 @@ -181,27 +181,27 @@ Satunnaiset värit - + Open model Avaa malli - + LDraw models (*.ldr *.dat) LDraw-mallit (*.ldr *.dat) - + Problem loading references Ongelma viitteiden lataamisessa - + Problem opening file Ongelma tiedoston avaamisessa - + Could not open %1: %2 Ei voitu avata %1: %2 @@ -228,27 +228,42 @@ + Interface + + + + Language: Kieli: - - + + System language Järjestelmän kieli - + English Englanti - + + Rendering + + + + + Main color: + + + + LDraw parts libraries LDraw-osakirjastot - + Keyboard shortcuts Näppäinyhdistelmät diff -r bb60dda3093f -r caac957e9834 locale/sv.ts --- a/locale/sv.ts Sat Feb 01 15:49:28 2020 +0200 +++ b/locale/sv.ts Sat Feb 01 17:10:11 2020 +0200 @@ -266,6 +266,18 @@ Keyboard shortcuts Tangentbordsgenvägar + + Interface + + + + Rendering + + + + Main color: + + gl::Compiler diff -r bb60dda3093f -r caac957e9834 src/document.cpp --- a/src/document.cpp Sat Feb 01 15:49:28 2020 +0200 +++ b/src/document.cpp Sat Feb 01 17:10:11 2020 +0200 @@ -55,7 +55,7 @@ this->ui.splitter->restoreState(state); } -void Document::setRenderStyle(gl::RenderStyle newRenderStyle) +void Document::setRenderPreferences(const gl::RenderPreferences& newPreferences) { - this->renderer->setRenderStyle(newRenderStyle); + this->renderer->setRenderPreferences(newPreferences); } diff -r bb60dda3093f -r caac957e9834 src/document.h --- a/src/document.h Sat Feb 01 15:49:28 2020 +0200 +++ b/src/document.h Sat Feb 01 17:10:11 2020 +0200 @@ -40,7 +40,7 @@ ~Document(); QByteArray saveSplitterState() const; void restoreSplitterState(const QByteArray& state); - void setRenderStyle(gl::RenderStyle newRenderStyle); + void setRenderPreferences(const gl::RenderPreferences& newPreferences); signals: void splitterChanged(); private: diff -r bb60dda3093f -r caac957e9834 src/gl/common.h --- a/src/gl/common.h Sat Feb 01 15:49:28 2020 +0200 +++ b/src/gl/common.h Sat Feb 01 17:10:11 2020 +0200 @@ -150,4 +150,12 @@ BfcRed = 2, RandomColors = 3, }; + + // User options for rendering + struct RenderPreferences + { + gl::RenderStyle style = gl::RenderStyle::Normal; + QColor mainColor{255, 255, 64}; + float lineThickness = 2.0f; + }; } diff -r bb60dda3093f -r caac957e9834 src/gl/compiler.cpp --- a/src/gl/compiler.cpp Sat Feb 01 15:49:28 2020 +0200 +++ b/src/gl/compiler.cpp Sat Feb 01 17:10:11 2020 +0200 @@ -143,14 +143,14 @@ } } -void gl::Compiler::build(Model* model, DocumentManager* context) +void gl::Compiler::build(Model* model, DocumentManager* context, const gl::RenderPreferences& preferences) { this->boundingBox = {}; std::vector vboData[gl::NUM_ARRAY_CLASSES]; const std::vector polygons = model->getPolygons(context); for (const gl::Polygon& polygon : polygons) { - this->buildPolygon(polygon, vboData); + this->buildPolygon(polygon, vboData, preferences); } for (int arrayId = 0; arrayId < gl::NUM_ARRAY_CLASSES; arrayId += 1) { @@ -190,13 +190,16 @@ return {r, g, b}; } -void gl::Compiler::buildPolygon(gl::Polygon polygon, std::vector* vboData) +void gl::Compiler::buildPolygon( + gl::Polygon polygon, + std::vector* vboData, + const gl::RenderPreferences& preferences) { const gl::ArrayClass vboClass = classifyPolygon(polygon); std::vector& vertexBuffer = vboData[static_cast(vboClass)]; auto vertexRing = iter::ring(polygon.vertices, polygon.numPolygonVertices()); reserveMore(vertexBuffer, polygon.numPolygonVertices()); - const QColor color = this->getColorForPolygon(polygon); + const QColor color = this->getColorForPolygon(polygon, preferences); for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) { const glm::vec3& v1 = vertexRing[i - 1]; @@ -210,13 +213,13 @@ } } -QColor gl::Compiler::getColorForPolygon(const gl::Polygon& polygon) +QColor gl::Compiler::getColorForPolygon(const gl::Polygon& polygon, const gl::RenderPreferences& preferences) { QColor color; // For normal colors, use the polygon's color. if (polygon.color == ldraw::mainColor) { - color = {255, 255, 64}; // mainColorRepresentation(); + color = preferences.mainColor; } else if (polygon.color == ldraw::edgeColor) { diff -r bb60dda3093f -r caac957e9834 src/gl/compiler.h --- a/src/gl/compiler.h Sat Feb 01 15:49:28 2020 +0200 +++ b/src/gl/compiler.h Sat Feb 01 17:10:11 2020 +0200 @@ -48,10 +48,10 @@ public: Compiler(const ldraw::ColorTable& colorTable, QObject* parent); ~Compiler(); - void build(Model* model, DocumentManager* context); - void buildPolygon(Polygon polygon, std::vector* vboData); + void build(Model* model, DocumentManager* context, const RenderPreferences& preferences); + void buildPolygon(Polygon polygon, std::vector* vboData, const gl::RenderPreferences& preferences); std::size_t vertexCount(gl::ArrayClass arrayClass) const; - QColor getColorForPolygon(const gl::Polygon& polygon); + QColor getColorForPolygon(const gl::Polygon& polygon, const RenderPreferences& preferences); glm::vec3 modelCenter() const; double modelDistance() const; void initialize(); diff -r bb60dda3093f -r caac957e9834 src/gl/partrenderer.cpp --- a/src/gl/partrenderer.cpp Sat Feb 01 15:49:28 2020 +0200 +++ b/src/gl/partrenderer.cpp Sat Feb 01 17:10:11 2020 +0200 @@ -49,7 +49,7 @@ abort(); } this->compiler->initialize(); - this->compiler->build(this->model, this->documents); + this->compiler->build(this->model, this->documents, this->renderPreferences); this->initialized = true; this->modelQuaternion = glm::angleAxis(glm::radians(30.0f), glm::vec3{-1, 0, 0}); this->modelQuaternion *= glm::angleAxis(glm::radians(225.0f), glm::vec3{-0, 1, 0}); @@ -105,7 +105,7 @@ glEnable(GL_DEPTH_TEST); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0f, 1.0f); - switch (this->renderStyle) + switch (this->renderPreferences.style) { case gl::RenderStyle::Normal: this->setFragmentStyle(gl::FragmentStyle::Normal); @@ -224,9 +224,14 @@ * @brief Changes the way the scene is rendered * @param newStyle new render style to use */ -void PartRenderer::setRenderStyle(const gl::RenderStyle newStyle) +void PartRenderer::setRenderPreferences(const gl::RenderPreferences& newPreferences) { - this->renderStyle = newStyle; + bool mainColorChanged = this->renderPreferences.mainColor != newPreferences.mainColor; + this->renderPreferences = newPreferences; + if (mainColorChanged) + { + this->compiler->build(this->model, this->documents, this->renderPreferences); + } this->update(); } diff -r bb60dda3093f -r caac957e9834 src/gl/partrenderer.h --- a/src/gl/partrenderer.h Sat Feb 01 15:49:28 2020 +0200 +++ b/src/gl/partrenderer.h Sat Feb 01 17:10:11 2020 +0200 @@ -21,7 +21,7 @@ const ldraw::ColorTable& colorTable, QWidget* parent = nullptr); ~PartRenderer() override; - void setRenderStyle(const gl::RenderStyle newStyle); + void setRenderPreferences(const gl::RenderPreferences& newPreferences); protected: void initializeGL() override; void resizeGL(int width, int height) override; @@ -38,7 +38,7 @@ const ldraw::ColorTable& colorTable; QPointF lastMousePosition; gl::Compiler* compiler; - gl::RenderStyle renderStyle = gl::RenderStyle::Normal; + gl::RenderPreferences renderPreferences; glm::mat4 projectionMatrix; glm::mat4 viewMatrix; glm::quat modelQuaternion; diff -r bb60dda3093f -r caac957e9834 src/mainwindow.cpp --- a/src/mainwindow.cpp Sat Feb 01 15:49:28 2020 +0200 +++ b/src/mainwindow.cpp Sat Feb 01 17:10:11 2020 +0200 @@ -68,10 +68,13 @@ } this->updateTitle(); this->restoreSettings(); - this->updateRenderStyles(); + this->updateRenderPreferences(); this->newModel(); } +// MainWindow needs a destructor even if it is empty because otherwise the destructor of the +// std::unique_ptr is resolved in the header file, where it will complain about Ui_MainWindow +// being incomplete. MainWindow::~MainWindow() { } @@ -162,7 +165,7 @@ void MainWindow::openModelForEditing(const QString& modelName) { Document* document = new Document{this->documents.findModelByName(modelName), &this->documents, this->colorTable}; - document->setRenderStyle(this->renderStyle); + document->setRenderPreferences(this->renderPreferences); this->ui->tabs->addTab(document, modelName); this->ui->tabs->setCurrentWidget(document); document->restoreSplitterState(this->documentSplitterState); @@ -221,9 +224,9 @@ void MainWindow::setRenderStyle(gl::RenderStyle renderStyle) { - this->renderStyle = renderStyle; + this->renderPreferences.style = renderStyle; this->saveSettings(); - this->updateRenderStyles(); + this->updateRenderPreferences(); } void MainWindow::changeEvent(QEvent* event) @@ -264,20 +267,20 @@ setWindowTitle(title); } -void MainWindow::updateRenderStyles() +void MainWindow::updateRenderPreferences() { 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); + document->setRenderPreferences(this->renderPreferences); } } for (auto data : ::renderStyleButtons) { QAction* action = data.memberInstance(this->ui.get()); - action->setChecked(this->renderStyle == data.payload); + action->setChecked(this->renderPreferences.style == data.payload); } } @@ -289,7 +292,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->settings.setValue("MainWindow/RenderStyle", static_cast(this->renderPreferences.style)); this->libraries.storeToSettings(&this->settings); } @@ -301,13 +304,15 @@ 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()); + this->renderPreferences.style = static_cast(this->settings.value("Render/Style").toInt()); + this->renderPreferences.mainColor = this->settings.value("Render/MainColor").toString(); const QString systemLocale = QLocale::system().name(); const QVariant defaultLocale = this->settings.value("locale", systemLocale); changeLanguage(defaultLocale.toString()); this->libraries.restoreFromSettings(&this->settings); this->updateRecentlyOpenedDocumentsMenu(); this->loadColors(); + this->updateRenderPreferences(); } QString MainWindow::pathToTranslation(const QString& localeCode) diff -r bb60dda3093f -r caac957e9834 src/mainwindow.h --- a/src/mainwindow.h Sat Feb 01 15:49:28 2020 +0200 +++ b/src/mainwindow.h Sat Feb 01 17:10:11 2020 +0200 @@ -30,7 +30,7 @@ Q_OBJECT public: MainWindow(QWidget *parent = nullptr); - ~MainWindow(); + ~MainWindow() override; private slots: void newModel(); void openModel(); @@ -56,9 +56,9 @@ static constexpr int maxRecentlyOpenedFiles = 10; QStringList recentlyOpenedFiles; ldraw::ColorTable colorTable; - gl::RenderStyle renderStyle; + gl::RenderPreferences renderPreferences; void updateTitle(); - void updateRenderStyles(); + void updateRenderPreferences(); void saveSettings(); void restoreSettings(); void changeLanguage(QString localeCode); diff -r bb60dda3093f -r caac957e9834 src/settingseditor/settingseditor.cpp --- a/src/settingseditor/settingseditor.cpp Sat Feb 01 15:49:28 2020 +0200 +++ b/src/settingseditor/settingseditor.cpp Sat Feb 01 17:10:11 2020 +0200 @@ -37,6 +37,7 @@ void SettingsEditor::handleAccepted() { this->settings->setValue("locale", this->ui.language->currentData().toString()); + this->settings->setValue("Render/MainColor", this->ui.mainColorButton->selectedColor().name()); this->librariesEditor.saveSettings(this->settings); } @@ -65,6 +66,7 @@ void SettingsEditor::setDefaults() { this->setCurrentLanguage(this->settings->value("locale", QLocale::system().name()).toString()); + this->ui.mainColorButton->setSelectedColor(this->settings->value("Render/MainColor").toString()); } void SettingsEditor::setCurrentLanguage(const QString& localeCode) diff -r bb60dda3093f -r caac957e9834 src/settingseditor/settingseditor.ui --- a/src/settingseditor/settingseditor.ui Sat Feb 01 15:49:28 2020 +0200 +++ b/src/settingseditor/settingseditor.ui Sat Feb 01 17:10:11 2020 +0200 @@ -17,34 +17,113 @@ - 2 + 0 General - - - - - Language: + + + + + Interface + + + + + Language: + + + + + + + + + + System language + + + + + English + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + - - - - - System language - - - - - English - - + + + + Rendering + + + + + + Main color: + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -76,6 +155,13 @@ + + + ColorButton + QPushButton +
widgets/colorbutton.h
+
+
diff -r bb60dda3093f -r caac957e9834 src/widgets/colorbutton.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/widgets/colorbutton.cpp Sat Feb 01 17:10:11 2020 +0200 @@ -0,0 +1,34 @@ +#include +#include "colorbutton.h" + +ColorButton::ColorButton(const QColor& color, QWidget* parent) : + ColorButton{parent} +{ + this->setSelectedColor(color); +} + +ColorButton::ColorButton(QWidget* parent) : + QPushButton{parent} +{ + connect(this, &QPushButton::clicked, [&]() + { + const QColor color = QColorDialog::getColor(this->storedSelectedColor, this->parentWidget()); + if (color.isValid()) + { + this->setSelectedColor(color); + } + }); +} + +QColor ColorButton::selectedColor() const +{ + return this->storedSelectedColor; +} + +void ColorButton::setSelectedColor(const QColor& newSelectedColor) +{ + this->storedSelectedColor = newSelectedColor; + this->setStyleSheet(QString{"background-color: %1"}.arg(newSelectedColor.name())); + this->setText(newSelectedColor.name()); +} + diff -r bb60dda3093f -r caac957e9834 src/widgets/colorbutton.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/widgets/colorbutton.h Sat Feb 01 17:10:11 2020 +0200 @@ -0,0 +1,16 @@ +#pragma once +#include + +/** + * @brief A button that can be used to select a color + */ +class ColorButton : public QPushButton +{ +public: + ColorButton(const QColor& color = {}, QWidget* parent = nullptr); + ColorButton(QWidget* parent = nullptr); + QColor selectedColor() const; + void setSelectedColor(const QColor& newSelectedColor); +private: + QColor storedSelectedColor; +};