Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reset to all settings to default except plugins. #3828

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/tiled/preferencesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include <QDesktopServices>
#include <QSortFilterProxyModel>

#include <QDebug>

using namespace Tiled;

PreferencesDialog::PreferencesDialog(QWidget *parent)
Expand Down Expand Up @@ -176,6 +178,26 @@ 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)"));
this->restoreToDefault(QString::fromUtf8("AbstractObjectTool/"));
});

connect(mUi->defaultTheme, &QPushButton::clicked, preferences, [preferences, this] {
this->restoreToDefault(QString::fromUtf8(
"Interface/(ApplicationStyle|BaseColor|SelectionColor|UseCustomFont|CustomFont)"));

QFont customFont = preferences->customFont();
mUi->fontComboBox->setCurrentFont(customFont);
mUi->fontSize->setValue(customFont.pointSize());
});
}

PreferencesDialog::~PreferencesDialog()
Expand Down Expand Up @@ -294,4 +316,14 @@ 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"
2 changes: 2 additions & 0 deletions src/tiled/preferencesdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class PreferencesDialog : public QDialog

void styleComboChanged();

void restoreToDefault(QString regexKey);

Ui::PreferencesDialog *mUi;
QStringList mLanguages;
};
Expand Down
130 changes: 128 additions & 2 deletions src/tiled/preferencesdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>544</width>
<height>595</height>
<height>626</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -20,7 +20,13 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<property name="documentMode">
<bool>false</bool>
</property>
<property name="movable">
<bool>false</bool>
</property>
<widget class="QWidget" name="generalTab">
<attribute name="title">
Expand Down Expand Up @@ -165,6 +171,57 @@
</property>
</spacer>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_3" rowminimumheight="0,0,0">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item row="2" column="0">
<widget class="QPushButton" name="defaultGeneral">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Reset to default</string>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRepeat">
<bool>false</bool>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="interfaceTab">
Expand Down Expand Up @@ -398,6 +455,36 @@
</layout>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_6">
<item row="1" column="0">
<widget class="QPushButton" name="defaultInterface">
<property name="minimumSize">
<size>
<width>120</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Reset to default</string>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
Expand Down Expand Up @@ -555,6 +642,45 @@
</property>
</spacer>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_7">
<item row="1" column="0">
<widget class="QPushButton" name="defaultTheme">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Reset to default</string>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="pluginsTab">
Expand Down
Loading