Add texture size preference setting

master
Jeremy Hu 2020-02-27 20:23:50 +09:30
parent c4639d77ae
commit 6e2c1286a3
7 changed files with 51 additions and 3 deletions

View File

@ -82,6 +82,7 @@ Document::Document() :
{
connect(&Preferences::instance(), &Preferences::partColorChanged, this, &Document::applyPreferencePartColorChange);
connect(&Preferences::instance(), &Preferences::flatShadingChanged, this, &Document::applyPreferenceFlatShadingChange);
connect(&Preferences::instance(), &Preferences::textureSizeChanged, this, &Document::applyPreferenceTextureSizeChange);
}
void Document::applyPreferencePartColorChange()
@ -95,6 +96,11 @@ void Document::applyPreferenceFlatShadingChange()
regenerateMesh();
}
void Document::applyPreferenceTextureSizeChange()
{
generateTexture();
}
Document::~Document()
{
delete m_resultMesh;

View File

@ -736,6 +736,7 @@ public slots:
void renameMaterial(QUuid materialId, QString name);
void applyPreferencePartColorChange();
void applyPreferenceFlatShadingChange();
void applyPreferenceTextureSizeChange();
void initScript(const QString &script);
void updateScript(const QString &script);
void runScript();

View File

@ -15,6 +15,7 @@ void Preferences::loadDefault()
m_componentCombineMode = CombineMode::Normal;
m_partColor = Qt::white;
m_flatShading = true;
m_textureSize = 1024;
}
Preferences::Preferences()
@ -37,6 +38,11 @@ Preferences::Preferences()
else
m_flatShading = isTrueValueString(value);
}
{
QString value = m_settings.value("textureSize").toString();
if (!value.isEmpty())
m_textureSize = value.toInt();
}
}
CombineMode Preferences::componentCombineMode() const
@ -54,6 +60,11 @@ bool Preferences::flatShading() const
return m_flatShading;
}
int Preferences::textureSize() const
{
return m_textureSize;
}
void Preferences::setComponentCombineMode(CombineMode mode)
{
if (m_componentCombineMode == mode)
@ -81,6 +92,15 @@ void Preferences::setFlatShading(bool flatShading)
emit flatShadingChanged();
}
void Preferences::setTextureSize(int textureSize)
{
if (m_textureSize == textureSize)
return;
m_textureSize = textureSize;
m_settings.setValue("textureSize", QString::number(m_textureSize));
emit textureSizeChanged();
}
QSize Preferences::documentWindowSize() const
{
return m_settings.value("documentWindowSize", QSize()).toSize();
@ -98,4 +118,5 @@ void Preferences::reset()
emit componentCombineModeChanged();
emit partColorChanged();
emit flatShadingChanged();
emit textureSizeChanged();
}

View File

@ -16,20 +16,24 @@ public:
bool flatShading() const;
QSize documentWindowSize() const;
void setDocumentWindowSize(const QSize&);
int textureSize() const;
signals:
void componentCombineModeChanged();
void partColorChanged();
void flatShadingChanged();
void textureSizeChanged();
public slots:
void setComponentCombineMode(CombineMode mode);
void setPartColor(const QColor &color);
void setFlatShading(bool flatShading);
void setTextureSize(int textureSize);
void reset();
private:
CombineMode m_componentCombineMode;
QColor m_partColor;
bool m_flatShading;
QSettings m_settings;
int m_textureSize;
private:
void loadDefault();
};

View File

@ -65,15 +65,28 @@ PreferencesWidget::PreferencesWidget(const Document *document, QWidget *parent)
Preferences::instance().setFlatShading(flatShadingBox->isChecked());
});
QComboBox *textureSizeSelectBox = new QComboBox;
textureSizeSelectBox->addItem("512");
textureSizeSelectBox->addItem("1024");
textureSizeSelectBox->addItem("2048");
textureSizeSelectBox->addItem("4096");
connect(textureSizeSelectBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [=](int index) {
Preferences::instance().setTextureSize(textureSizeSelectBox->itemText(index).toInt());
});
QFormLayout *formLayout = new QFormLayout;
formLayout->addRow(tr("Part color:"), colorLayout);
formLayout->addRow(tr("Combine mode:"), combineModeSelectBox);
formLayout->addRow(tr("Flat shading:"), flatShadingBox);
formLayout->addRow(tr("Texture size:"), textureSizeSelectBox);
auto loadFromPreferences = [=]() {
updatePickButtonColor();
combineModeSelectBox->setCurrentIndex((int)Preferences::instance().componentCombineMode());
flatShadingBox->setChecked(Preferences::instance().flatShading());
textureSizeSelectBox->setCurrentIndex(
textureSizeSelectBox->findText(QString::number(Preferences::instance().textureSize()))
);
};
loadFromPreferences();

View File

@ -9,8 +9,8 @@
#include "util.h"
#include "texturetype.h"
#include "material.h"
#include "preferences.h"
int TextureGenerator::m_textureSize = 1024;
QColor TextureGenerator::m_defaultTextureColor = Qt::transparent;
TextureGenerator::TextureGenerator(const Outcome &outcome, Snapshot *snapshot) :
@ -25,10 +25,13 @@ TextureGenerator::TextureGenerator(const Outcome &outcome, Snapshot *snapshot) :
m_resultTextureAmbientOcclusionImage(nullptr),
m_resultMesh(nullptr),
m_snapshot(snapshot),
m_hasTransparencySettings(false)
m_hasTransparencySettings(false),
m_textureSize(Preferences::instance().textureSize())
{
m_outcome = new Outcome();
*m_outcome = outcome;
if (m_textureSize <= 0)
m_textureSize = 1024;
}
TextureGenerator::~TextureGenerator()

View File

@ -38,7 +38,6 @@ signals:
public slots:
void process();
public:
static int m_textureSize;
static QColor m_defaultTextureColor;
private:
void prepare();
@ -62,6 +61,7 @@ private:
std::set<QUuid> m_countershadedPartIds;
Snapshot *m_snapshot;
bool m_hasTransparencySettings;
int m_textureSize;
};
#endif