From a9dd15991fe324dec74c05505ee31fd0dec75833 Mon Sep 17 00:00:00 2001 From: Jeremy HU Date: Fri, 14 Oct 2022 19:21:20 +1100 Subject: [PATCH] Add command line option: -toggle-color --- application/sources/document_window.cc | 31 ++++++++++++++------------ application/sources/document_window.h | 1 + application/sources/main.cc | 11 +++++++++ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/application/sources/document_window.cc b/application/sources/document_window.cc index 03b02acb..0a051a8f 100644 --- a/application/sources/document_window.cc +++ b/application/sources/document_window.cc @@ -420,20 +420,7 @@ DocumentWindow::DocumentWindow() m_viewMenu->addAction(m_toggleRotationAction); m_toggleColorAction = new QAction(tr("Toggle Color"), this); - connect(m_toggleColorAction, &QAction::triggered, [&]() { - m_modelRemoveColor = !m_modelRemoveColor; - ModelMesh *mesh = nullptr; - if (m_document->isMeshGenerating() || - m_document->isPostProcessing() || - m_document->isTextureGenerating()) { - mesh = m_document->takeResultMesh(); - } else { - mesh = m_document->takeResultTextureMesh(); - } - if (m_modelRemoveColor && mesh) - mesh->removeColor(); - m_modelRenderWidget->updateMesh(mesh); - }); + connect(m_toggleColorAction, &QAction::triggered, this, &DocumentWindow::toggleRenderColor); m_viewMenu->addAction(m_toggleColorAction); m_windowMenu = menuBar()->addMenu(tr("&Window")); @@ -1410,3 +1397,19 @@ bool DocumentWindow::isWorking() { return nullptr == m_inprogressIndicator || m_inprogressIndicator->isSpinning(); } + +void DocumentWindow::toggleRenderColor() +{ + m_modelRemoveColor = !m_modelRemoveColor; + ModelMesh *mesh = nullptr; + if (m_document->isMeshGenerating() || + m_document->isPostProcessing() || + m_document->isTextureGenerating()) { + mesh = m_document->takeResultMesh(); + } else { + mesh = m_document->takeResultTextureMesh(); + } + if (m_modelRemoveColor && mesh) + mesh->removeColor(); + m_modelRenderWidget->updateMesh(mesh); +} diff --git a/application/sources/document_window.h b/application/sources/document_window.h index d6ca8d03..55ec00f2 100644 --- a/application/sources/document_window.h +++ b/application/sources/document_window.h @@ -91,6 +91,7 @@ public slots: void updateInprogressIndicator(); void openRecentFile(); void updateRecentFileActions(); + void toggleRenderColor(); private: void setCurrentFilename(const QString &filename); void updateTitle(); diff --git a/application/sources/main.cc b/application/sources/main.cc index 8abd9fca..9f8ddfbd 100644 --- a/application/sources/main.cc +++ b/application/sources/main.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include "document_window.h" #include "document.h" #include "theme.h" @@ -30,6 +31,7 @@ int main(int argc, char *argv[]) QStringList openFileList; QStringList waitingExportList; + bool toggleColor = false; for (int i = 1; i < argc; ++i) { if ('-' == argv[i][0]) { if (0 == strcmp(argv[i], "-output") || @@ -38,6 +40,11 @@ int main(int argc, char *argv[]) if (i < argc) waitingExportList.append(argv[i]); continue; + } else if (0 == strcmp(argv[i], "-toggle-color")) { + ++i; + if (i < argc) + toggleColor = dust3d::String::isTrue(argv[i]); + continue; } qDebug() << "Unknown option:" << argv[i]; continue; @@ -68,6 +75,10 @@ int main(int argc, char *argv[]) for (int i = 1; i < openFileList.size(); ++i) { windowList.push_back(DocumentWindow::createDocumentWindow()); } + if (toggleColor) { + for (auto &it: windowList) + it->toggleRenderColor(); + } if (!waitingExportList.empty() && openFileList.size() == 1) { totalExportFileNum = openFileList.size() * waitingExportList.size();