Fri, 31 Jan 2020 00:25:35 +0200
added render style storage
locale/fi.ts | file | annotate | diff | comparison | revisions | |
locale/sv.ts | file | annotate | diff | comparison | revisions | |
src/document.cpp | file | annotate | diff | comparison | revisions | |
src/document.h | file | annotate | diff | comparison | revisions | |
src/gl/partrenderer.h | file | annotate | diff | comparison | revisions | |
src/main.cpp | file | annotate | diff | comparison | revisions | |
src/mainwindow.cpp | file | annotate | diff | comparison | revisions | |
src/mainwindow.h | file | annotate | diff | comparison | revisions | |
src/mainwindow.ui | file | annotate | diff | comparison | revisions |
--- 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 @@ <translation type="unfinished"></translation> </message> <message> - <location filename="../src/mainwindow.ui" line="54"/> + <location filename="../src/mainwindow.ui" line="51"/> + <source>View</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/mainwindow.ui" line="63"/> <source>Quit</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/mainwindow.ui" line="59"/> + <location filename="../src/mainwindow.ui" line="68"/> <source>Open…</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/mainwindow.ui" line="62"/> + <location filename="../src/mainwindow.ui" line="71"/> <source>Ctrl+O</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/mainwindow.ui" line="67"/> + <location filename="../src/mainwindow.ui" line="76"/> <source>New</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/mainwindow.ui" line="70"/> + <location filename="../src/mainwindow.ui" line="79"/> <source>Ctrl+N</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/mainwindow.ui" line="75"/> + <location filename="../src/mainwindow.ui" line="84"/> <source>Preferences…</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/mainwindow.cpp" line="62"/> + <location filename="../src/mainwindow.ui" line="92"/> + <source>Normal colours</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/mainwindow.ui" line="100"/> + <source>BFC color coding</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/mainwindow.ui" line="108"/> + <source>Random colours</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/mainwindow.cpp" line="88"/> <source>Open model</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/mainwindow.cpp" line="64"/> + <location filename="../src/mainwindow.cpp" line="90"/> <source>LDraw models (*.ldr *.dat)</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/mainwindow.cpp" line="83"/> + <location filename="../src/mainwindow.cpp" line="109"/> <source>Problem loading references</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/mainwindow.cpp" line="93"/> + <location filename="../src/mainwindow.cpp" line="119"/> <source>Problem opening file</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/mainwindow.cpp" line="95"/> + <location filename="../src/mainwindow.cpp" line="121"/> <source>Could not open %1: %2</source> <translation type="unfinished"></translation> </message>
--- 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 @@ <source>Problem loading references</source> <translation type="unfinished"></translation> </message> + <message> + <source>View</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Normal colours</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>BFC color coding</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Random colours</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>PartRenderer</name>
--- 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); +}
--- 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:
--- 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();
--- 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");
--- 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<typename BaseType, typename MemberType, typename DataType> +struct MemberData +{ + std::size_t member; + DataType payload; + constexpr MemberType memberInstance(BaseType* instance) const + { + return *reinterpret_cast<MemberType*>(reinterpret_cast<char*>(instance) + this->member); + } +}; + +static constexpr MemberData<Ui_MainWindow, QAction*, gl::RenderStyle> 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<Ui_MainWindow>()}, @@ -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<Document*>(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<int>(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<gl::RenderStyle>(this->settings.value("MainWindow/RenderStyle").toInt()); const QString systemLocale = QLocale::system().name(); const QVariant defaultLocale = this->settings.value("locale", systemLocale); changeLanguage(defaultLocale.toString());
--- 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);
--- 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 @@ <x>0</x> <y>0</y> <width>800</width> - <height>27</height> + <height>22</height> </rect> </property> <widget class="QMenu" name="menuFile"> @@ -46,7 +46,16 @@ <addaction name="separator"/> <addaction name="actionQuit"/> </widget> + <widget class="QMenu" name="menuView"> + <property name="title"> + <string>View</string> + </property> + <addaction name="actionRenderStyleNormal"/> + <addaction name="actionRenderStyleBfc"/> + <addaction name="actionRenderStyleRandom"/> + </widget> <addaction name="menuFile"/> + <addaction name="menuView"/> </widget> <widget class="QStatusBar" name="statusbar"/> <action name="actionQuit"> @@ -75,6 +84,30 @@ <string>Preferences…</string> </property> </action> + <action name="actionRenderStyleNormal"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="text"> + <string>Normal colours</string> + </property> + </action> + <action name="actionRenderStyleBfc"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="text"> + <string>BFC color coding</string> + </property> + </action> + <action name="actionRenderStyleRandom"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="text"> + <string>Random colours</string> + </property> + </action> </widget> <resources/> <connections/>