1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
/* ============================================================
* The rekonq project
* ============================================================
* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright (C) 2008-2012 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr>
* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net>
* ============================================================
* Description: Settings Dialog
* ============================================================ */
#include "settingsdialog.h"
#include "settingswidgets.hpp"
#include "ui_settingsdialog.h"
#include <QPushButton>
SettingsDialog::SettingsDialog(RekonqSettings *settings, QWidget *parent) : QDialog(parent), ui(new Ui::SettingsDialog)
{
ui->setupUi(this);
saveBtn = ui->buttonBox->button(QDialogButtonBox::Save);
Q_CHECK_PTR(saveBtn);
restoreDefaultsBtn = ui->buttonBox->button(QDialogButtonBox::RestoreDefaults);
Q_CHECK_PTR(restoreDefaultsBtn);
if (!settings->value("FirstRun", true).toBool()) saveBtn->setEnabled(false);
addPage(new GeneralSettingsWidget(settings, this));
addPage(new AppearanceSettingsWidget(settings, this));
addPage(new NetworkSettingsWidget(settings, this));
addPage(new ShortcutsSettingsWidget(settings, this));
connect(ui->listWidget, &QListWidget::currentRowChanged, ui->stackedWidget, &QStackedWidget::setCurrentIndex);
connect(restoreDefaultsBtn, &QPushButton::clicked, this, [this]() {
for (auto *w : ui->stackedWidget->findChildren<SettingsWidget *>(QString(), Qt::FindDirectChildrenOnly)) {
w->reset();
}
});
connect(this, &QDialog::accepted, this, [this]() {
for (auto *w : ui->stackedWidget->findChildren<SettingsWidget *>(QString(), Qt::FindDirectChildrenOnly)) {
w->save();
}
});
}
SettingsDialog::~SettingsDialog() { delete ui; }
void SettingsDialog::addPage(SettingsWidget *page)
{
auto *item = new QListWidgetItem(page->objectName(), ui->listWidget);
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->stackedWidget->addWidget(page);
connect(page, &SettingsWidget::changed, this, [this]() { saveBtn->setEnabled(true); });
}
|