summaryrefslogtreecommitdiff
path: root/src/settings/settingswidget.cpp
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-08-24 16:38:49 +0300
committeraqua <aqua@iserlohn-fortress.net>2022-08-28 09:49:20 +0300
commitc5ed279da0e74adb79c6c2a3e485cb9668b1c130 (patch)
tree4271dcd3530bec7df25b01190317bee56533df94 /src/settings/settingswidget.cpp
parentLoad plugins from AppLocalDataLocation by default (diff)
downloadrekonq-c5ed279da0e74adb79c6c2a3e485cb9668b1c130.tar.xz
SettingsDialog: save settings when changed
- connect Restore Defaults button
Diffstat (limited to 'src/settings/settingswidget.cpp')
-rw-r--r--src/settings/settingswidget.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/settings/settingswidget.cpp b/src/settings/settingswidget.cpp
new file mode 100644
index 00000000..b5a2432c
--- /dev/null
+++ b/src/settings/settingswidget.cpp
@@ -0,0 +1,81 @@
+#include "settingswidgets.hpp"
+
+#include <QCheckBox>
+#include <QFontComboBox>
+#include <QKeySequenceEdit>
+#include <QLineEdit>
+#include <QSpinBox>
+
+void SettingsWidget::save()
+{
+ if (objectName() != QLatin1String("General")) m_settings->beginGroup(objectName());
+
+ // Int
+ for (const auto *spinbox : findChildren<QSpinBox *>(QString(), Qt::FindDirectChildrenOnly)) {
+ m_settings->setValue(spinbox->objectName(), spinbox->value());
+ }
+
+ // Bool
+ for (const auto *checkbox : findChildren<QCheckBox *>(QString(), Qt::FindDirectChildrenOnly)) {
+ m_settings->setValue(checkbox->objectName(), checkbox->isChecked());
+ }
+
+ // String
+ for (const auto *lineedit : findChildren<QLineEdit *>(QString(), Qt::FindDirectChildrenOnly)) {
+ m_settings->setValue(lineedit->objectName(), lineedit->text());
+ }
+
+ // Font
+ for (const auto *font : findChildren<QFontComboBox *>(QString(), Qt::FindDirectChildrenOnly)) {
+ m_settings->setValue(font->objectName(), font->currentFont().family());
+ }
+
+ // Shortcut
+ for (const auto *shortcut : findChildren<QKeySequenceEdit *>(QString(), Qt::FindDirectChildrenOnly)) {
+ m_settings->setValue(shortcut->objectName(), shortcut->keySequence());
+ }
+
+ if (objectName() != QLatin1String("General")) m_settings->endGroup();
+}
+
+void SettingsWidget::reset()
+{
+ if (objectName() != QLatin1String("General")) m_settings->beginGroup(objectName());
+
+ // Int
+ for (auto *spinbox : findChildren<QSpinBox *>(QString(), Qt::FindDirectChildrenOnly)) {
+ const auto value = spinbox->property("defaultValue");
+ spinbox->setValue(value.toInt());
+ m_settings->setValue(spinbox->objectName(), value);
+ }
+
+ // Bool
+ for (auto *checkbox : findChildren<QCheckBox *>(QString(), Qt::FindDirectChildrenOnly)) {
+ const auto value = checkbox->property("defaultValue");
+ checkbox->setChecked(value.toBool());
+ m_settings->setValue(checkbox->objectName(), value);
+ }
+
+ // String
+ for (auto *lineedit : findChildren<QLineEdit *>(QString(), Qt::FindDirectChildrenOnly)) {
+ const auto value = lineedit->property("defaultValue");
+ lineedit->setText(value.toString());
+ m_settings->setValue(lineedit->objectName(), value);
+ }
+
+ // Font
+ for (auto *font : findChildren<QFontComboBox *>(QString(), Qt::FindDirectChildrenOnly)) {
+ const auto value = font->property("defaultValue");
+ font->setFont(QFont(value.toString()));
+ m_settings->setValue(font->objectName(), value);
+ }
+
+ // Shortcut
+ for (auto *shortcut : findChildren<QKeySequenceEdit *>(QString(), Qt::FindDirectChildrenOnly)) {
+ const auto value = shortcut->property("defaultValue");
+ shortcut->setKeySequence(value.toString());
+ m_settings->setValue(shortcut->objectName(), value);
+ }
+
+ if (objectName() != QLatin1String("General")) m_settings->endGroup();
+} \ No newline at end of file