From 442844d3f1df44e66e22fffa71e95111d1cdb5e6 Mon Sep 17 00:00:00 2001 From: niakouu Date: Sun, 15 Oct 2023 15:22:32 -0400 Subject: [PATCH 1/4] Add reset to default button --- src/tiled/preferencesdialog.cpp | 28 +++++++++ src/tiled/preferencesdialog.h | 2 + src/tiled/preferencesdialog.ui | 104 +++++++++++++++++++++++++++++++- 3 files changed, 133 insertions(+), 1 deletion(-) diff --git a/src/tiled/preferencesdialog.cpp b/src/tiled/preferencesdialog.cpp index 426e68dec3..c9d1f6fb57 100644 --- a/src/tiled/preferencesdialog.cpp +++ b/src/tiled/preferencesdialog.cpp @@ -35,6 +35,8 @@ #include #include +#include + using namespace Tiled; PreferencesDialog::PreferencesDialog(QWidget *parent) @@ -176,6 +178,21 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) }); resize(sizeHint()); + + connect(mUi->defaultGeneral, &QPushButton::clicked, this, [=] { + this->restoreToDefault(QString::fromUtf8("(Export|Storage|Startup)/")); + }); + + connect(mUi->defaultInterface, &QPushButton::clicked, this, [=] { + this->restoreToDefault(QString::fromUtf8( + "Interface/(?!(ApplicationStyle|BaseColor|SelectionColor|UseCustomFont|CustomFont))")); + this->restoreToDefault(QString::fromUtf8("Install/(DisplayNews|CheckForUpdates)")); + }); + + connect(mUi->defaultTheme, &QPushButton::clicked, this, [=] { + this->restoreToDefault(QString::fromUtf8( + "Interface/(ApplicationStyle|BaseColor|SelectionColor|UseCustomFont|CustomFont)")); + }); } PreferencesDialog::~PreferencesDialog() @@ -294,4 +311,15 @@ void PreferencesDialog::styleComboChanged() mUi->selectionColorLabel->setEnabled(!systemStyle); } +void PreferencesDialog::restoreToDefault(QString regexKey) +{ + Preferences *prefs = Preferences::instance(); + QStringList generalKeys = prefs->allKeys().filter(QRegularExpression(regexKey)); + for ( const auto& key : generalKeys) + { + prefs->remove(key); + } + this->fromPreferences(); +} + #include "moc_preferencesdialog.cpp" diff --git a/src/tiled/preferencesdialog.h b/src/tiled/preferencesdialog.h index 7962cf6618..94189ce9c4 100644 --- a/src/tiled/preferencesdialog.h +++ b/src/tiled/preferencesdialog.h @@ -54,6 +54,8 @@ class PreferencesDialog : public QDialog void styleComboChanged(); + void restoreToDefault(QString regexKey); + Ui::PreferencesDialog *mUi; QStringList mLanguages; }; diff --git a/src/tiled/preferencesdialog.ui b/src/tiled/preferencesdialog.ui index 27c83fbcd0..e345ab15b6 100644 --- a/src/tiled/preferencesdialog.ui +++ b/src/tiled/preferencesdialog.ui @@ -20,7 +20,7 @@ - 0 + 3 @@ -165,6 +165,45 @@ + + + + QLayout::SetMinimumSize + + + + + + 120 + 25 + + + + Restore to default + + + + 16 + 16 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -398,6 +437,36 @@ + + + + + + + 120 + 25 + + + + Restore to default + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -555,6 +624,39 @@ + + + + + + + 120 + 25 + + + + Restore to default + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + From 84384b165f0729f11bb8c30056f69f6f33084622 Mon Sep 17 00:00:00 2001 From: niakouu Date: Sun, 15 Oct 2023 15:27:34 -0400 Subject: [PATCH 2/4] Fixed format --- src/tiled/preferencesdialog.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tiled/preferencesdialog.cpp b/src/tiled/preferencesdialog.cpp index c9d1f6fb57..4a9de93555 100644 --- a/src/tiled/preferencesdialog.cpp +++ b/src/tiled/preferencesdialog.cpp @@ -316,9 +316,8 @@ void PreferencesDialog::restoreToDefault(QString regexKey) Preferences *prefs = Preferences::instance(); QStringList generalKeys = prefs->allKeys().filter(QRegularExpression(regexKey)); for ( const auto& key : generalKeys) - { prefs->remove(key); - } + this->fromPreferences(); } From 05ae823ab3eb79c04345ed8fc871a9e0a5754912 Mon Sep 17 00:00:00 2001 From: niakouu Date: Sun, 15 Oct 2023 16:06:38 -0400 Subject: [PATCH 3/4] Fixed the changing font on the preferencesdialog ui --- src/tiled/preferencesdialog.cpp | 4 +++- src/tiled/preferencesdialog.ui | 26 +++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/tiled/preferencesdialog.cpp b/src/tiled/preferencesdialog.cpp index 4a9de93555..ccb5c1a496 100644 --- a/src/tiled/preferencesdialog.cpp +++ b/src/tiled/preferencesdialog.cpp @@ -187,11 +187,13 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) this->restoreToDefault(QString::fromUtf8( "Interface/(?!(ApplicationStyle|BaseColor|SelectionColor|UseCustomFont|CustomFont))")); this->restoreToDefault(QString::fromUtf8("Install/(DisplayNews|CheckForUpdates)")); + this->restoreToDefault(QString::fromUtf8("AbstractObjectTool/")); }); - connect(mUi->defaultTheme, &QPushButton::clicked, this, [=] { + connect(mUi->defaultTheme, &QPushButton::clicked, preferences, [preferences, this] { this->restoreToDefault(QString::fromUtf8( "Interface/(ApplicationStyle|BaseColor|SelectionColor|UseCustomFont|CustomFont)")); + mUi->fontComboBox->setCurrentFont(preferences->customFont()); }); } diff --git a/src/tiled/preferencesdialog.ui b/src/tiled/preferencesdialog.ui index e345ab15b6..61eaea1687 100644 --- a/src/tiled/preferencesdialog.ui +++ b/src/tiled/preferencesdialog.ui @@ -20,7 +20,13 @@ - 3 + 0 + + + false + + + false @@ -172,6 +178,12 @@ + + + 0 + 0 + + 120 @@ -187,6 +199,12 @@ 16 + + false + + + false + @@ -628,6 +646,12 @@ + + + 0 + 0 + + 120 From c89125b303152641906d3162a0fa66f0685b8a3e Mon Sep 17 00:00:00 2001 From: niakouu Date: Sun, 15 Oct 2023 17:57:08 -0400 Subject: [PATCH 4/4] Renamed the buttons from 'Restore to default' to 'Reset to default' --- src/tiled/preferencesdialog.cpp | 5 ++++- src/tiled/preferencesdialog.ui | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/tiled/preferencesdialog.cpp b/src/tiled/preferencesdialog.cpp index ccb5c1a496..adeebc8be0 100644 --- a/src/tiled/preferencesdialog.cpp +++ b/src/tiled/preferencesdialog.cpp @@ -193,7 +193,10 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) connect(mUi->defaultTheme, &QPushButton::clicked, preferences, [preferences, this] { this->restoreToDefault(QString::fromUtf8( "Interface/(ApplicationStyle|BaseColor|SelectionColor|UseCustomFont|CustomFont)")); - mUi->fontComboBox->setCurrentFont(preferences->customFont()); + + QFont customFont = preferences->customFont(); + mUi->fontComboBox->setCurrentFont(customFont); + mUi->fontSize->setValue(customFont.pointSize()); }); } diff --git a/src/tiled/preferencesdialog.ui b/src/tiled/preferencesdialog.ui index 61eaea1687..5ae95abb21 100644 --- a/src/tiled/preferencesdialog.ui +++ b/src/tiled/preferencesdialog.ui @@ -7,7 +7,7 @@ 0 0 544 - 595 + 626 @@ -20,7 +20,7 @@ - 0 + 3 false @@ -191,7 +191,7 @@ - Restore to default + Reset to default @@ -466,7 +466,7 @@ - Restore to default + Reset to default @@ -659,7 +659,7 @@ - Restore to default + Reset to default