Skip to content

Commit

Permalink
Settings: add restore state
Browse files Browse the repository at this point in the history
Widgets need to know if update settings means load from file or set to default.
  • Loading branch information
rodlie committed Aug 29, 2023
1 parent 28065a1 commit b29d54d
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/app/GUI/Settings/canvassettingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ void CanvasSettingsWidget::applySettings() {
mSett.fCanvasRtlSupport = mRtlSupport->isChecked();
}

void CanvasSettingsWidget::updateSettings() {
void CanvasSettingsWidget::updateSettings(bool restore)
{
Q_UNUSED(restore)
mPathNodeSize->setValue(100*mSett.fPathNodeScaling);
mPathNodeColor->setColor(mSett.fPathNodeColor);
mPathNodeSelectedColor->setColor(mSett.fPathNodeSelectedColor);
Expand Down
2 changes: 1 addition & 1 deletion src/app/GUI/Settings/canvassettingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CanvasSettingsWidget : public SettingsWidget {
explicit CanvasSettingsWidget(QWidget* const parent = nullptr);

void applySettings();
void updateSettings();
void updateSettings(bool restore = false);
private:
QCheckBox* mRtlSupport = nullptr;

Expand Down
4 changes: 3 additions & 1 deletion src/app/GUI/Settings/interfacesettingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ void InterfaceSettingsWidget::applySettings() {
eSizesUI::widget.updateSize();
}

void InterfaceSettingsWidget::updateSettings() {
void InterfaceSettingsWidget::updateSettings(bool restore)
{
Q_UNUSED(restore)
mInterfaceScaling->setValue(100*mSett.fInterfaceScaling);
}
2 changes: 1 addition & 1 deletion src/app/GUI/Settings/interfacesettingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class InterfaceSettingsWidget : public SettingsWidget {
explicit InterfaceSettingsWidget(QWidget *parent);

void applySettings();
void updateSettings();
void updateSettings(bool restore = false);
private:
QSlider* mInterfaceScaling = nullptr;
};
Expand Down
4 changes: 3 additions & 1 deletion src/app/GUI/Settings/performancesettingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ void PerformanceSettingsWidget::applySettings() {
}


void PerformanceSettingsWidget::updateSettings() {
void PerformanceSettingsWidget::updateSettings(bool restore)
{
Q_UNUSED(restore)
const bool capCpu = mSett.fCpuThreadsCap > 0;
mCpuThreadsCapCheck->setChecked(capCpu);
const int nThreads = capCpu ? mSett.fCpuThreadsCap :
Expand Down
2 changes: 1 addition & 1 deletion src/app/GUI/Settings/performancesettingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PerformanceSettingsWidget : public SettingsWidget {
explicit PerformanceSettingsWidget(QWidget *parent = nullptr);

void applySettings();
void updateSettings();
void updateSettings(bool restore = false);
private:
void updateAccPreferenceDesc();

Expand Down
8 changes: 6 additions & 2 deletions src/app/GUI/Settings/pluginssettingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,15 @@ void PluginsSettingsWidget::applySettings()
disabledShaders);
}

void PluginsSettingsWidget::updateSettings()
void PluginsSettingsWidget::updateSettings(bool restore)
{
mShaderPath->setText(AppSupport::getAppShaderEffectsPath());
mShaderPath->setText(AppSupport::getAppShaderEffectsPath(restore));
mShadersDisabled = AppSupport::getSettings("settings",
"DisabledShaders").toStringList();
if (restore) {
mShadersDisabled.clear();
populateShaderTree();
}
}

void PluginsSettingsWidget::populateShaderTree()
Expand Down
2 changes: 1 addition & 1 deletion src/app/GUI/Settings/pluginssettingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PluginsSettingsWidget : public SettingsWidget
public:
explicit PluginsSettingsWidget(QWidget *parent = nullptr);
void applySettings();
void updateSettings();
void updateSettings(bool restore = false);

private:
QLineEdit *mShaderPath;
Expand Down
6 changes: 3 additions & 3 deletions src/app/GUI/Settings/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ SettingsDialog::SettingsDialog(QWidget * const parent) :

connect(restoreButton, &QPushButton::released, this, [this]() {
eSettings::sInstance->loadDefaults();
updateSettings();
updateSettings(true /* restore */);
eSizesUI::font.updateSize();
eSizesUI::widget.updateSize();
});
Expand Down Expand Up @@ -111,8 +111,8 @@ void SettingsDialog::addSettingsWidget(SettingsWidget * const widget,
mSettingWidgets << widget;
}

void SettingsDialog::updateSettings() {
void SettingsDialog::updateSettings(bool restore) {
for(const auto widget : mSettingWidgets) {
widget->updateSettings();
widget->updateSettings(restore);
}
}
2 changes: 1 addition & 1 deletion src/app/GUI/Settings/settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SettingsDialog : public QDialog {
private:
void addSettingsWidget(SettingsWidget* const widget,
const QString& name);
void updateSettings();
void updateSettings(bool restore = false);

QTabWidget* mTabWidget = nullptr;
QList<SettingsWidget*> mSettingWidgets;
Expand Down
2 changes: 1 addition & 1 deletion src/app/GUI/Settings/settingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SettingsWidget : public QWidget {
void addSeparator();

virtual void applySettings() = 0;
virtual void updateSettings() = 0;
virtual void updateSettings(bool restore = false) = 0;
protected:
eSettings& mSett;
private:
Expand Down
4 changes: 3 additions & 1 deletion src/app/GUI/Settings/timelinesettingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ void TimelineSettingsWidget::applySettings() {
mSett.fAnimationRangeColor = mAnimationRangeColor->color();
}

void TimelineSettingsWidget::updateSettings() {
void TimelineSettingsWidget::updateSettings(bool restore)
{
Q_UNUSED(restore)
mAlternateRowCheck->setChecked(mSett.fTimelineAlternateRow);
mAlternateRowColor->setColor(mSett.fTimelineAlternateRowColor);

Expand Down
2 changes: 1 addition & 1 deletion src/app/GUI/Settings/timelinesettingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TimelineSettingsWidget : public SettingsWidget {
explicit TimelineSettingsWidget(QWidget *parent = nullptr);

void applySettings();
void updateSettings();
void updateSettings(bool restore = false);
private:
QCheckBox* mAlternateRowCheck = nullptr;
ColorAnimatorButton* mAlternateRowColor = nullptr;
Expand Down
9 changes: 5 additions & 4 deletions src/core/appsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,12 @@ const QString AppSupport::getAppRasterEffectsPath()
return path;
}

const QString AppSupport::getAppShaderEffectsPath()
const QString AppSupport::getAppShaderEffectsPath(bool restore)
{
QString path = getSettings("settings",
"CustomShaderPath",
QString::fromUtf8("%1/ShaderEffects").arg(getAppConfigPath())).toString();
QString def = QString::fromUtf8("%1/ShaderEffects").arg(getAppConfigPath());
QString path = restore ? def : getSettings("settings",
"CustomShaderPath",
def).toString();
QDir dir(path);
if (!dir.exists() && path.startsWith(getAppConfigPath())) { dir.mkpath(path); }
return path;
Expand Down
2 changes: 1 addition & 1 deletion src/core/appsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CORE_EXPORT AppSupport : public QObject
static const QString getAppOutputProfilesPath();
static const QString getAppPathEffectsPath();
static const QString getAppRasterEffectsPath();
static const QString getAppShaderEffectsPath();
static const QString getAppShaderEffectsPath(bool restore = false);
static const QString getAppShaderPresetsPath();
static const QString getAppExPresetsPath();
static const QString getAppUserExPresetsPath();
Expand Down

0 comments on commit b29d54d

Please sign in to comment.