Add preferences setting and change the behavior of shift key on scale radius

master
Jeremy Hu 2019-06-01 22:42:53 +09:30
parent 7eef3f9455
commit 4ab76b1d76
15 changed files with 288 additions and 72 deletions

View File

@ -92,9 +92,9 @@ Mouse
+----------------------------+--------------------------------------------------------------------------+ +----------------------------+--------------------------------------------------------------------------+
| WHEEL | Increase/Decrease Radius | | 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 + WHEEL | Increase/Decrease Size |
+----------------------------+--------------------------------------------------------------------------+ +----------------------------+--------------------------------------------------------------------------+
| CTRL + SHIFT + WHEEL | Increase/Decrease Size (Reduced Scroll Scale) | | CTRL + SHIFT + WHEEL | Increase/Decrease Size (Fast Scroll Scale) |
+----------------------------+--------------------------------------------------------------------------+ +----------------------------+--------------------------------------------------------------------------+

View File

@ -193,8 +193,8 @@ HEADERS += src/posepreviewsgenerator.h
SOURCES += src/posewidget.cpp SOURCES += src/posewidget.cpp
HEADERS += src/posewidget.h HEADERS += src/posewidget.h
SOURCES += src/advancesettingwidget.cpp SOURCES += src/preferenceswidget.cpp
HEADERS += src/advancesettingwidget.h HEADERS += src/preferenceswidget.h
SOURCES += src/motioneditwidget.cpp SOURCES += src/motioneditwidget.cpp
HEADERS += src/motioneditwidget.h HEADERS += src/motioneditwidget.h
@ -313,6 +313,9 @@ HEADERS += src/remoteioserver.h
SOURCES += src/remoteioconnection.cpp SOURCES += src/remoteioconnection.cpp
HEADERS += src/remoteioconnection.h HEADERS += src/remoteioconnection.h
SOURCES += src/preferences.cpp
HEADERS += src/preferences.h
SOURCES += src/main.cpp SOURCES += src/main.cpp
HEADERS += src/version.h HEADERS += src/version.h

View File

@ -1,22 +0,0 @@
#include <QFormLayout>
#include <QCheckBox>
#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);
}

View File

@ -1,17 +0,0 @@
#ifndef DUST3D_ADVANCE_SETTING_WIDGET_H
#define DUST3D_ADVANCE_SETTING_WIDGET_H
#include <QDialog>
#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

View File

@ -47,7 +47,7 @@ Document::Document() :
m_textureImageUpdateVersion(0), m_textureImageUpdateVersion(0),
m_sharedContextWidget(nullptr), m_sharedContextWidget(nullptr),
m_allPositionRelatedLocksEnabled(true), m_allPositionRelatedLocksEnabled(true),
m_smoothNormal(true), m_smoothNormal(!Preferences::instance().flatShading()),
m_rigGenerator(nullptr), m_rigGenerator(nullptr),
m_resultRigWeightMesh(nullptr), m_resultRigWeightMesh(nullptr),
m_resultRigBones(nullptr), m_resultRigBones(nullptr),
@ -59,6 +59,25 @@ Document::Document() :
m_materialPreviewsGenerator(nullptr), m_materialPreviewsGenerator(nullptr),
m_motionsGenerator(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() Document::~Document()
@ -913,7 +932,7 @@ void Document::toSnapshot(Snapshot *snapshot, const std::set<QUuid> &limitNodeId
} }
} }
part["dirty"] = partIt.second.dirty ? "true" : "false"; part["dirty"] = partIt.second.dirty ? "true" : "false";
if (partIt.second.hasColor) //if (partIt.second.hasColor)
part["color"] = partIt.second.color.name(); part["color"] = partIt.second.color.name();
if (partIt.second.colorSolubilityAdjusted()) if (partIt.second.colorSolubilityAdjusted())
part["colorSolubility"] = QString::number(partIt.second.colorSolubility); part["colorSolubility"] = QString::number(partIt.second.colorSolubility);

View File

@ -25,6 +25,7 @@
#include "jointnodetree.h" #include "jointnodetree.h"
#include "skeletondocument.h" #include "skeletondocument.h"
#include "combinemode.h" #include "combinemode.h"
#include "preferences.h"
class MaterialPreviewsGenerator; class MaterialPreviewsGenerator;
class MotionsGenerator; class MotionsGenerator;
@ -56,7 +57,7 @@ public:
QUuid linkToPartId; QUuid linkToPartId;
QUuid parentId; QUuid parentId;
bool expanded = true; bool expanded = true;
CombineMode combineMode = CombineMode::Normal; CombineMode combineMode = Preferences::instance().componentCombineMode();
bool dirty = true; bool dirty = true;
float smoothAll = 0.0; float smoothAll = 0.0;
float smoothSeam = 0.0; float smoothSeam = 0.0;
@ -624,6 +625,8 @@ public slots:
void removeMaterial(QUuid materialId); void removeMaterial(QUuid materialId);
void setMaterialLayers(QUuid materialId, std::vector<MaterialLayer> layers); void setMaterialLayers(QUuid materialId, std::vector<MaterialLayer> layers);
void renameMaterial(QUuid materialId, QString name); void renameMaterial(QUuid materialId, QString name);
void applyPreferencePartColorChange();
void applyPreferenceFlatShadingChange();
private: private:
void splitPartByNode(std::vector<std::vector<QUuid>> *groups, QUuid nodeId); void splitPartByNode(std::vector<std::vector<QUuid>> *groups, QUuid nodeId);
void joinNodeAndNeiborsToGroup(std::vector<QUuid> *group, QUuid nodeId, std::set<QUuid> *visitMap, QUuid noUseEdgeId=QUuid()); void joinNodeAndNeiborsToGroup(std::vector<QUuid> *group, QUuid nodeId, std::set<QUuid> *visitMap, QUuid noUseEdgeId=QUuid());

View File

@ -114,7 +114,7 @@ DocumentWindow::DocumentWindow() :
m_firstShow(true), m_firstShow(true),
m_documentSaved(true), m_documentSaved(true),
m_exportPreviewWidget(nullptr), m_exportPreviewWidget(nullptr),
m_advanceSettingWidget(nullptr), m_preferencesWidget(nullptr),
m_isLastMeshGenerationSucceed(true) m_isLastMeshGenerationSucceed(true)
{ {
if (!g_logBrowser) { if (!g_logBrowser) {
@ -373,6 +373,12 @@ DocumentWindow::DocumentWindow() :
m_fileMenu->addSeparator(); 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")); //m_exportMenu = m_fileMenu->addMenu(tr("Export"));
m_exportAction = new QAction(tr("Export..."), this); m_exportAction = new QAction(tr("Export..."), this);
@ -580,11 +586,11 @@ DocumentWindow::DocumentWindow() :
}); });
m_viewMenu->addAction(m_toggleWireframeAction); m_viewMenu->addAction(m_toggleWireframeAction);
m_toggleSmoothNormalAction = new QAction(tr("Toggle Smooth"), this); //m_toggleSmoothNormalAction = new QAction(tr("Toggle Smooth"), this);
connect(m_toggleSmoothNormalAction, &QAction::triggered, [=]() { //connect(m_toggleSmoothNormalAction, &QAction::triggered, [=]() {
m_document->toggleSmoothNormal(); // m_document->toggleSmoothNormal();
}); //});
m_viewMenu->addAction(m_toggleSmoothNormalAction); //m_viewMenu->addAction(m_toggleSmoothNormalAction);
connect(m_viewMenu, &QMenu::aboutToShow, [=]() { connect(m_viewMenu, &QMenu::aboutToShow, [=]() {
m_resetModelWidgetPosAction->setEnabled(!isModelSitInVisibleArea(m_modelRenderWidget)); m_resetModelWidgetPosAction->setEnabled(!isModelSitInVisibleArea(m_modelRenderWidget));
@ -648,12 +654,6 @@ DocumentWindow::DocumentWindow() :
connect(m_showDebugDialogAction, &QAction::triggered, g_logBrowser, &LogBrowser::showDialog); connect(m_showDebugDialogAction, &QAction::triggered, g_logBrowser, &LogBrowser::showDialog);
m_windowMenu->addAction(m_showDebugDialogAction); 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")); m_helpMenu = menuBar()->addMenu(tr("Help"));
m_gotoHomepageAction = new QAction(tr("Dust3D Homepage"), this); m_gotoHomepageAction = new QAction(tr("Dust3D Homepage"), this);
@ -1326,13 +1326,13 @@ void DocumentWindow::open()
setCurrentFilename(filename); setCurrentFilename(filename);
} }
void DocumentWindow::showAdvanceSetting() void DocumentWindow::showPreferences()
{ {
if (nullptr == m_advanceSettingWidget) { if (nullptr == m_preferencesWidget) {
m_advanceSettingWidget = new AdvanceSettingWidget(m_document, this); m_preferencesWidget = new PreferencesWidget(m_document, this);
} }
m_advanceSettingWidget->show(); m_preferencesWidget->show();
m_advanceSettingWidget->raise(); m_preferencesWidget->raise();
} }
void DocumentWindow::exportObjResult() void DocumentWindow::exportObjResult()

View File

@ -14,7 +14,7 @@
#include "rigwidget.h" #include "rigwidget.h"
#include "bonemark.h" #include "bonemark.h"
#include "posemanagewidget.h" #include "posemanagewidget.h"
#include "advancesettingwidget.h" #include "preferenceswidget.h"
class SkeletonGraphicsWidget; class SkeletonGraphicsWidget;
@ -66,7 +66,7 @@ public slots:
void updateRigWeightRenderWidget(); void updateRigWeightRenderWidget();
void registerDialog(QWidget *widget); void registerDialog(QWidget *widget);
void unregisterDialog(QWidget *widget); void unregisterDialog(QWidget *widget);
void showAdvanceSetting(); void showPreferences();
private: private:
void initLockButton(QPushButton *button); void initLockButton(QPushButton *button);
void setCurrentFilename(const QString &filename); void setCurrentFilename(const QString &filename);
@ -76,7 +76,7 @@ private:
bool m_firstShow; bool m_firstShow;
bool m_documentSaved; bool m_documentSaved;
ExportPreviewWidget *m_exportPreviewWidget; ExportPreviewWidget *m_exportPreviewWidget;
AdvanceSettingWidget *m_advanceSettingWidget; PreferencesWidget *m_preferencesWidget;
std::vector<QWidget *> m_dialogs; std::vector<QWidget *> m_dialogs;
bool m_isLastMeshGenerationSucceed; bool m_isLastMeshGenerationSucceed;
private: private:
@ -94,6 +94,7 @@ private:
QAction *m_saveAction; QAction *m_saveAction;
QAction *m_saveAsAction; QAction *m_saveAsAction;
QAction *m_saveAllAction; QAction *m_saveAllAction;
QAction *m_showPreferencesAction;
QMenu *m_exportMenu; QMenu *m_exportMenu;
QAction *m_changeTurnaroundAction; QAction *m_changeTurnaroundAction;
@ -137,7 +138,7 @@ private:
QMenu *m_viewMenu; QMenu *m_viewMenu;
QAction *m_resetModelWidgetPosAction; QAction *m_resetModelWidgetPosAction;
QAction *m_toggleWireframeAction; QAction *m_toggleWireframeAction;
QAction *m_toggleSmoothNormalAction; //QAction *m_toggleSmoothNormalAction;
QAction *m_showMotionsListAction; QAction *m_showMotionsListAction;
QMenu *m_windowMenu; QMenu *m_windowMenu;
@ -147,7 +148,6 @@ private:
QAction *m_showRigAction; QAction *m_showRigAction;
QAction *m_showPosesAction; QAction *m_showPosesAction;
QAction *m_showMotionsAction; QAction *m_showMotionsAction;
QAction *m_showAdvanceSettingAction;
QMenu *m_helpMenu; QMenu *m_helpMenu;
QAction *m_gotoHomepageAction; QAction *m_gotoHomepageAction;

View File

@ -351,7 +351,7 @@ void PartWidget::showColorSettingPopup(const QPoint &pos)
QPushButton *pickButton = new QPushButton(); QPushButton *pickButton = new QPushButton();
initToolButtonWithoutFont(pickButton); initToolButtonWithoutFont(pickButton);
QPalette palette = pickButton->palette(); QPalette palette = pickButton->palette();
QColor choosenColor = part->hasColor ? part->color : Qt::white; QColor choosenColor = part->color;
palette.setColor(QPalette::Window, choosenColor); palette.setColor(QPalette::Window, choosenColor);
palette.setColor(QPalette::Button, choosenColor); palette.setColor(QPalette::Button, choosenColor);
pickButton->setPalette(palette); pickButton->setPalette(palette);

89
src/preferences.cpp Normal file
View File

@ -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();
}

34
src/preferences.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef PREFERENCES_H
#define PREFERENCES_H
#include <QSettings>
#include <QColor>
#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

89
src/preferenceswidget.cpp Normal file
View File

@ -0,0 +1,89 @@
#include <QFormLayout>
#include <QVBoxLayout>
#include <QCheckBox>
#include <QComboBox>
#include <QColorDialog>
#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<void (QComboBox::*)(int)>(&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")));
}

17
src/preferenceswidget.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef DUST3D_PREFERENCES_WIDGET_H
#define DUST3D_PREFERENCES_WIDGET_H
#include <QDialog>
#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

View File

@ -12,6 +12,7 @@
#include "cutface.h" #include "cutface.h"
#include "parttarget.h" #include "parttarget.h"
#include "partbase.h" #include "partbase.h"
#include "preferences.h"
class SkeletonNode class SkeletonNode
{ {
@ -106,7 +107,7 @@ public:
deformWidth(1.0), deformWidth(1.0),
rounded(false), rounded(false),
chamfered(false), chamfered(false),
color(Qt::white), color(Preferences::instance().partColor()),
hasColor(false), hasColor(false),
dirty(true), dirty(true),
cutRotation(0.0), cutRotation(0.0),

View File

@ -1054,7 +1054,7 @@ void SkeletonGraphicsWidget::scaleSelected(float delta)
bool SkeletonGraphicsWidget::wheel(QWheelEvent *event) bool SkeletonGraphicsWidget::wheel(QWheelEvent *event)
{ {
qreal delta = event->delta() / 10; qreal delta = event->delta() / 10;
if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) { if (!QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) {
if (delta > 0) if (delta > 0)
delta = 1; delta = 1;
else else