From 4ab76b1d76d88fac54a7b7408503beccc992e2bb Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Sat, 1 Jun 2019 22:42:53 +0930 Subject: [PATCH] Add preferences setting and change the behavior of shift key on scale radius --- docs/shortcuts.rst | 4 +- dust3d.pro | 7 ++- src/advancesettingwidget.cpp | 22 --------- src/advancesettingwidget.h | 17 ------- src/document.cpp | 23 ++++++++- src/document.h | 5 +- src/documentwindow.cpp | 34 ++++++------- src/documentwindow.h | 10 ++-- src/partwidget.cpp | 4 +- src/preferences.cpp | 89 ++++++++++++++++++++++++++++++++++ src/preferences.h | 34 +++++++++++++ src/preferenceswidget.cpp | 89 ++++++++++++++++++++++++++++++++++ src/preferenceswidget.h | 17 +++++++ src/skeletondocument.h | 3 +- src/skeletongraphicswidget.cpp | 2 +- 15 files changed, 288 insertions(+), 72 deletions(-) delete mode 100644 src/advancesettingwidget.cpp delete mode 100644 src/advancesettingwidget.h create mode 100644 src/preferences.cpp create mode 100644 src/preferences.h create mode 100644 src/preferenceswidget.cpp create mode 100644 src/preferenceswidget.h diff --git a/docs/shortcuts.rst b/docs/shortcuts.rst index 9e477701..e42b9f13 100644 --- a/docs/shortcuts.rst +++ b/docs/shortcuts.rst @@ -92,9 +92,9 @@ Mouse +----------------------------+--------------------------------------------------------------------------+ | WHEEL | Increase/Decrease Radius | +----------------------------+--------------------------------------------------------------------------+ -| SHIFT + WHEEL | Increase/Decrease Radius (Reduced Scroll Scale) | +| SHIFT + WHEEL | Increase/Decrease Radius (Fast Scroll) | +----------------------------+--------------------------------------------------------------------------+ | CTRL + WHEEL | Increase/Decrease Size | +----------------------------+--------------------------------------------------------------------------+ -| CTRL + SHIFT + WHEEL | Increase/Decrease Size (Reduced Scroll Scale) | +| CTRL + SHIFT + WHEEL | Increase/Decrease Size (Fast Scroll Scale) | +----------------------------+--------------------------------------------------------------------------+ diff --git a/dust3d.pro b/dust3d.pro index ffe75c53..667821db 100644 --- a/dust3d.pro +++ b/dust3d.pro @@ -193,8 +193,8 @@ HEADERS += src/posepreviewsgenerator.h SOURCES += src/posewidget.cpp HEADERS += src/posewidget.h -SOURCES += src/advancesettingwidget.cpp -HEADERS += src/advancesettingwidget.h +SOURCES += src/preferenceswidget.cpp +HEADERS += src/preferenceswidget.h SOURCES += src/motioneditwidget.cpp HEADERS += src/motioneditwidget.h @@ -313,6 +313,9 @@ HEADERS += src/remoteioserver.h SOURCES += src/remoteioconnection.cpp HEADERS += src/remoteioconnection.h +SOURCES += src/preferences.cpp +HEADERS += src/preferences.h + SOURCES += src/main.cpp HEADERS += src/version.h diff --git a/src/advancesettingwidget.cpp b/src/advancesettingwidget.cpp deleted file mode 100644 index 95ac627f..00000000 --- a/src/advancesettingwidget.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include "advancesettingwidget.h" -#include "util.h" - -AdvanceSettingWidget::AdvanceSettingWidget(const Document *document, QWidget *parent) : - QDialog(parent), - m_document(document) -{ - QCheckBox *enableWeldBox = new QCheckBox(); - enableWeldBox->setChecked(document->weldEnabled); - connect(enableWeldBox, &QCheckBox::stateChanged, this, [=]() { - emit enableWeld(enableWeldBox->isChecked()); - }); - - QFormLayout *formLayout = new QFormLayout; - formLayout->addRow(tr("Weld"), enableWeldBox); - - setLayout(formLayout); - - connect(this, &AdvanceSettingWidget::enableWeld, document, &Document::enableWeld); -} diff --git a/src/advancesettingwidget.h b/src/advancesettingwidget.h deleted file mode 100644 index 48d3bd89..00000000 --- a/src/advancesettingwidget.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef DUST3D_ADVANCE_SETTING_WIDGET_H -#define DUST3D_ADVANCE_SETTING_WIDGET_H -#include -#include "document.h" - -class AdvanceSettingWidget : public QDialog -{ - Q_OBJECT -signals: - void enableWeld(bool enabled); -public: - AdvanceSettingWidget(const Document *document, QWidget *parent=nullptr); -private: - const Document *m_document = nullptr; -}; - -#endif diff --git a/src/document.cpp b/src/document.cpp index 7f9b8d1a..b03df74c 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -47,7 +47,7 @@ Document::Document() : m_textureImageUpdateVersion(0), m_sharedContextWidget(nullptr), m_allPositionRelatedLocksEnabled(true), - m_smoothNormal(true), + m_smoothNormal(!Preferences::instance().flatShading()), m_rigGenerator(nullptr), m_resultRigWeightMesh(nullptr), m_resultRigBones(nullptr), @@ -59,6 +59,25 @@ Document::Document() : m_materialPreviewsGenerator(nullptr), m_motionsGenerator(nullptr) { + connect(&Preferences::instance(), &Preferences::partColorChanged, this, &Document::applyPreferencePartColorChange); + connect(&Preferences::instance(), &Preferences::flatShadingChanged, this, &Document::applyPreferenceFlatShadingChange); +} + +void Document::applyPreferencePartColorChange() +{ + for (auto &it: partMap) { + if (it.second.hasColor) + continue; + it.second.color = Preferences::instance().partColor(); + it.second.dirty = true; + } + emit skeletonChanged(); +} + +void Document::applyPreferenceFlatShadingChange() +{ + m_smoothNormal = !Preferences::instance().flatShading(); + regenerateMesh(); } Document::~Document() @@ -913,7 +932,7 @@ void Document::toSnapshot(Snapshot *snapshot, const std::set &limitNodeId } } part["dirty"] = partIt.second.dirty ? "true" : "false"; - if (partIt.second.hasColor) + //if (partIt.second.hasColor) part["color"] = partIt.second.color.name(); if (partIt.second.colorSolubilityAdjusted()) part["colorSolubility"] = QString::number(partIt.second.colorSolubility); diff --git a/src/document.h b/src/document.h index 0a58f03e..4459c9ee 100644 --- a/src/document.h +++ b/src/document.h @@ -25,6 +25,7 @@ #include "jointnodetree.h" #include "skeletondocument.h" #include "combinemode.h" +#include "preferences.h" class MaterialPreviewsGenerator; class MotionsGenerator; @@ -56,7 +57,7 @@ public: QUuid linkToPartId; QUuid parentId; bool expanded = true; - CombineMode combineMode = CombineMode::Normal; + CombineMode combineMode = Preferences::instance().componentCombineMode(); bool dirty = true; float smoothAll = 0.0; float smoothSeam = 0.0; @@ -624,6 +625,8 @@ public slots: void removeMaterial(QUuid materialId); void setMaterialLayers(QUuid materialId, std::vector layers); void renameMaterial(QUuid materialId, QString name); + void applyPreferencePartColorChange(); + void applyPreferenceFlatShadingChange(); private: void splitPartByNode(std::vector> *groups, QUuid nodeId); void joinNodeAndNeiborsToGroup(std::vector *group, QUuid nodeId, std::set *visitMap, QUuid noUseEdgeId=QUuid()); diff --git a/src/documentwindow.cpp b/src/documentwindow.cpp index f08abc8a..8adf4ae1 100644 --- a/src/documentwindow.cpp +++ b/src/documentwindow.cpp @@ -114,7 +114,7 @@ DocumentWindow::DocumentWindow() : m_firstShow(true), m_documentSaved(true), m_exportPreviewWidget(nullptr), - m_advanceSettingWidget(nullptr), + m_preferencesWidget(nullptr), m_isLastMeshGenerationSucceed(true) { if (!g_logBrowser) { @@ -371,6 +371,12 @@ DocumentWindow::DocumentWindow() : connect(m_saveAllAction, &QAction::triggered, this, &DocumentWindow::saveAll, Qt::QueuedConnection); m_fileMenu->addAction(m_saveAllAction); + m_fileMenu->addSeparator(); + + m_showPreferencesAction = new QAction(tr("Preferences..."), this); + connect(m_showPreferencesAction, &QAction::triggered, this, &DocumentWindow::showPreferences); + m_fileMenu->addAction(m_showPreferencesAction); + m_fileMenu->addSeparator(); //m_exportMenu = m_fileMenu->addMenu(tr("Export")); @@ -580,11 +586,11 @@ DocumentWindow::DocumentWindow() : }); m_viewMenu->addAction(m_toggleWireframeAction); - m_toggleSmoothNormalAction = new QAction(tr("Toggle Smooth"), this); - connect(m_toggleSmoothNormalAction, &QAction::triggered, [=]() { - m_document->toggleSmoothNormal(); - }); - m_viewMenu->addAction(m_toggleSmoothNormalAction); + //m_toggleSmoothNormalAction = new QAction(tr("Toggle Smooth"), this); + //connect(m_toggleSmoothNormalAction, &QAction::triggered, [=]() { + // m_document->toggleSmoothNormal(); + //}); + //m_viewMenu->addAction(m_toggleSmoothNormalAction); connect(m_viewMenu, &QMenu::aboutToShow, [=]() { m_resetModelWidgetPosAction->setEnabled(!isModelSitInVisibleArea(m_modelRenderWidget)); @@ -647,12 +653,6 @@ DocumentWindow::DocumentWindow() : m_showDebugDialogAction = new QAction(tr("Debug"), this); connect(m_showDebugDialogAction, &QAction::triggered, g_logBrowser, &LogBrowser::showDialog); m_windowMenu->addAction(m_showDebugDialogAction); - - m_showAdvanceSettingAction = new QAction(tr("Advance"), this); - connect(m_showAdvanceSettingAction, &QAction::triggered, this, &DocumentWindow::showAdvanceSetting); -#ifndef NDEBUG - m_windowMenu->addAction(m_showAdvanceSettingAction); -#endif m_helpMenu = menuBar()->addMenu(tr("Help")); @@ -1326,13 +1326,13 @@ void DocumentWindow::open() setCurrentFilename(filename); } -void DocumentWindow::showAdvanceSetting() +void DocumentWindow::showPreferences() { - if (nullptr == m_advanceSettingWidget) { - m_advanceSettingWidget = new AdvanceSettingWidget(m_document, this); + if (nullptr == m_preferencesWidget) { + m_preferencesWidget = new PreferencesWidget(m_document, this); } - m_advanceSettingWidget->show(); - m_advanceSettingWidget->raise(); + m_preferencesWidget->show(); + m_preferencesWidget->raise(); } void DocumentWindow::exportObjResult() diff --git a/src/documentwindow.h b/src/documentwindow.h index 327aa77d..24941126 100644 --- a/src/documentwindow.h +++ b/src/documentwindow.h @@ -14,7 +14,7 @@ #include "rigwidget.h" #include "bonemark.h" #include "posemanagewidget.h" -#include "advancesettingwidget.h" +#include "preferenceswidget.h" class SkeletonGraphicsWidget; @@ -66,7 +66,7 @@ public slots: void updateRigWeightRenderWidget(); void registerDialog(QWidget *widget); void unregisterDialog(QWidget *widget); - void showAdvanceSetting(); + void showPreferences(); private: void initLockButton(QPushButton *button); void setCurrentFilename(const QString &filename); @@ -76,7 +76,7 @@ private: bool m_firstShow; bool m_documentSaved; ExportPreviewWidget *m_exportPreviewWidget; - AdvanceSettingWidget *m_advanceSettingWidget; + PreferencesWidget *m_preferencesWidget; std::vector m_dialogs; bool m_isLastMeshGenerationSucceed; private: @@ -94,6 +94,7 @@ private: QAction *m_saveAction; QAction *m_saveAsAction; QAction *m_saveAllAction; + QAction *m_showPreferencesAction; QMenu *m_exportMenu; QAction *m_changeTurnaroundAction; @@ -137,7 +138,7 @@ private: QMenu *m_viewMenu; QAction *m_resetModelWidgetPosAction; QAction *m_toggleWireframeAction; - QAction *m_toggleSmoothNormalAction; + //QAction *m_toggleSmoothNormalAction; QAction *m_showMotionsListAction; QMenu *m_windowMenu; @@ -147,7 +148,6 @@ private: QAction *m_showRigAction; QAction *m_showPosesAction; QAction *m_showMotionsAction; - QAction *m_showAdvanceSettingAction; QMenu *m_helpMenu; QAction *m_gotoHomepageAction; diff --git a/src/partwidget.cpp b/src/partwidget.cpp index b93f96b3..f30cb69c 100644 --- a/src/partwidget.cpp +++ b/src/partwidget.cpp @@ -351,7 +351,7 @@ void PartWidget::showColorSettingPopup(const QPoint &pos) QPushButton *pickButton = new QPushButton(); initToolButtonWithoutFont(pickButton); QPalette palette = pickButton->palette(); - QColor choosenColor = part->hasColor ? part->color : Qt::white; + QColor choosenColor = part->color; palette.setColor(QPalette::Window, choosenColor); palette.setColor(QPalette::Button, choosenColor); pickButton->setPalette(palette); @@ -370,7 +370,7 @@ void PartWidget::showColorSettingPopup(const QPoint &pos) emit disableBackgroundBlur(); QColor color = QColorDialog::getColor(part->color, this); emit enableBackgroundBlur(); - if(color.isValid()) { + if (color.isValid()) { emit setPartColorState(m_partId, true, color); emit groupOperationAdded(); } diff --git a/src/preferences.cpp b/src/preferences.cpp new file mode 100644 index 00000000..a7b7962f --- /dev/null +++ b/src/preferences.cpp @@ -0,0 +1,89 @@ +#include "preferences.h" +#include "util.h" + +Preferences &Preferences::instance() +{ + static Preferences *s_preferences = nullptr; + if (nullptr == s_preferences) { + s_preferences = new Preferences; + } + return *s_preferences; +} + +void Preferences::loadDefault() +{ + m_componentCombineMode = CombineMode::Normal; + m_partColor = Qt::white; + m_flatShading = false; +} + +Preferences::Preferences() +{ + loadDefault(); + { + QString value = m_settings.value("componentCombineMode").toString(); + if (!value.isEmpty()) + m_componentCombineMode = CombineModeFromString(value.toUtf8().constData()); + } + { + QString value = m_settings.value("partColor").toString(); + if (!value.isEmpty()) + m_partColor = QColor(value); + } + { + QString value = m_settings.value("flatShading").toString(); + if (!value.isEmpty()) + m_flatShading = isTrueValueString(value); + } +} + +CombineMode Preferences::componentCombineMode() const +{ + return m_componentCombineMode; +} + +const QColor &Preferences::partColor() const +{ + return m_partColor; +} + +bool Preferences::flatShading() const +{ + return m_flatShading; +} + +void Preferences::setComponentCombineMode(CombineMode mode) +{ + if (m_componentCombineMode == mode) + return; + m_componentCombineMode = mode; + m_settings.setValue("componentCombineMode", CombineModeToString(m_componentCombineMode)); + emit componentCombineModeChanged(); +} + +void Preferences::setPartColor(const QColor &color) +{ + if (m_partColor == color) + return; + m_partColor = color; + m_settings.setValue("partColor", color.name()); + emit partColorChanged(); +} + +void Preferences::setFlatShading(bool flatShading) +{ + if (m_flatShading == flatShading) + return; + m_flatShading = flatShading; + m_settings.setValue("flatShading", flatShading ? "true" : "false"); + emit flatShadingChanged(); +} + +void Preferences::reset() +{ + m_settings.clear(); + loadDefault(); + emit componentCombineModeChanged(); + emit partColorChanged(); + emit flatShadingChanged(); +} diff --git a/src/preferences.h b/src/preferences.h new file mode 100644 index 00000000..697c6226 --- /dev/null +++ b/src/preferences.h @@ -0,0 +1,34 @@ +#ifndef PREFERENCES_H +#define PREFERENCES_H +#include +#include +#include "combinemode.h" + +class Preferences : public QObject +{ + Q_OBJECT +public: + static Preferences &instance(); + Preferences(); + CombineMode componentCombineMode() const; + const QColor &partColor() const; + bool flatShading() const; +signals: + void componentCombineModeChanged(); + void partColorChanged(); + void flatShadingChanged(); +public slots: + void setComponentCombineMode(CombineMode mode); + void setPartColor(const QColor &color); + void setFlatShading(bool flatShading); + void reset(); +private: + CombineMode m_componentCombineMode = CombineMode::Normal; + QColor m_partColor; + bool m_flatShading; + QSettings m_settings; +private: + void loadDefault(); +}; + +#endif diff --git a/src/preferenceswidget.cpp b/src/preferenceswidget.cpp new file mode 100644 index 00000000..accf578f --- /dev/null +++ b/src/preferenceswidget.cpp @@ -0,0 +1,89 @@ +#include +#include +#include +#include +#include +#include "preferenceswidget.h" +#include "util.h" +#include "preferences.h" +#include "theme.h" + +PreferencesWidget::PreferencesWidget(const Document *document, QWidget *parent) : + QDialog(parent), + m_document(document) +{ + QPushButton *colorEraser = new QPushButton(QChar(fa::eraser)); + Theme::initAwesomeToolButton(colorEraser); + + QPushButton *pickButton = new QPushButton(); + Theme::initAwesomeToolButtonWithoutFont(pickButton); + + QHBoxLayout *colorLayout = new QHBoxLayout; + colorLayout->addWidget(colorEraser); + colorLayout->addWidget(pickButton); + colorLayout->addStretch(); + + connect(colorEraser, &QPushButton::clicked, [=]() { + Preferences::instance().setPartColor(Qt::white); + }); + + auto updatePickButtonColor = [=]() { + QPalette palette = pickButton->palette(); + QColor choosenColor = Preferences::instance().partColor(); + palette.setColor(QPalette::Window, choosenColor); + palette.setColor(QPalette::Button, choosenColor); + pickButton->setPalette(palette); + pickButton->update(); + }; + + connect(pickButton, &QPushButton::clicked, [=]() { + QColor color = QColorDialog::getColor(Preferences::instance().partColor(), this); + if (color.isValid()) { + Preferences::instance().setPartColor(color); + updatePickButtonColor(); + raise(); + } + }); + + QComboBox *combineModeSelectBox = new QComboBox; + for (size_t i = 0; i < (size_t)CombineMode::Count; ++i) { + CombineMode mode = (CombineMode)i; + combineModeSelectBox->addItem(CombineModeToDispName(mode)); + } + connect(combineModeSelectBox, static_cast(&QComboBox::currentIndexChanged), this, [=](int index) { + Preferences::instance().setComponentCombineMode((CombineMode)index); + }); + + QCheckBox *flatShadingBox = new QCheckBox(); + connect(flatShadingBox, &QCheckBox::stateChanged, this, [=]() { + Preferences::instance().setFlatShading(flatShadingBox->isChecked()); + }); + + QFormLayout *formLayout = new QFormLayout; + formLayout->addRow(tr("Part color:"), colorLayout); + formLayout->addRow(tr("Combine mode:"), combineModeSelectBox); + formLayout->addRow(tr("Flat shading:"), flatShadingBox); + + auto loadFromPreferences = [=]() { + updatePickButtonColor(); + combineModeSelectBox->setCurrentIndex((int)Preferences::instance().componentCombineMode()); + flatShadingBox->setChecked(Preferences::instance().flatShading()); + }; + + loadFromPreferences(); + + QPushButton *resetButton = new QPushButton(tr("Reset")); + connect(resetButton, &QPushButton::clicked, this, [=]() { + Preferences::instance().reset(); + loadFromPreferences(); + }); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(formLayout); + mainLayout->addSpacing(20); + mainLayout->addWidget(resetButton); + + setLayout(mainLayout); + + setWindowTitle(unifiedWindowTitle(tr("Preferences"))); +} diff --git a/src/preferenceswidget.h b/src/preferenceswidget.h new file mode 100644 index 00000000..b2230245 --- /dev/null +++ b/src/preferenceswidget.h @@ -0,0 +1,17 @@ +#ifndef DUST3D_PREFERENCES_WIDGET_H +#define DUST3D_PREFERENCES_WIDGET_H +#include +#include "document.h" + +class PreferencesWidget : public QDialog +{ + Q_OBJECT +signals: + void enableWeld(bool enabled); +public: + PreferencesWidget(const Document *document, QWidget *parent=nullptr); +private: + const Document *m_document = nullptr; +}; + +#endif diff --git a/src/skeletondocument.h b/src/skeletondocument.h index c6774b82..e69d1c18 100644 --- a/src/skeletondocument.h +++ b/src/skeletondocument.h @@ -12,6 +12,7 @@ #include "cutface.h" #include "parttarget.h" #include "partbase.h" +#include "preferences.h" class SkeletonNode { @@ -106,7 +107,7 @@ public: deformWidth(1.0), rounded(false), chamfered(false), - color(Qt::white), + color(Preferences::instance().partColor()), hasColor(false), dirty(true), cutRotation(0.0), diff --git a/src/skeletongraphicswidget.cpp b/src/skeletongraphicswidget.cpp index 11df0eaa..748c35b3 100644 --- a/src/skeletongraphicswidget.cpp +++ b/src/skeletongraphicswidget.cpp @@ -1054,7 +1054,7 @@ void SkeletonGraphicsWidget::scaleSelected(float delta) bool SkeletonGraphicsWidget::wheel(QWheelEvent *event) { qreal delta = event->delta() / 10; - if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) { + if (!QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) { if (delta > 0) delta = 1; else