2022-01-16 19:54:57 +00:00
|
|
|
#include "settings.h"
|
|
|
|
#include "ui_settings.h"
|
|
|
|
|
|
|
|
Settings::Settings(QWidget* parent):
|
|
|
|
QWidget(parent),
|
2022-01-21 19:02:50 +00:00
|
|
|
m_ui(new Ui::Settings()),
|
|
|
|
modifiedSettings()
|
2022-01-16 19:54:57 +00:00
|
|
|
{
|
|
|
|
m_ui->setupUi(this);
|
2022-01-19 20:46:42 +00:00
|
|
|
|
|
|
|
connect(m_ui->list, &QListWidget::currentItemChanged, this, &Settings::onCurrentPageChanged);
|
2022-01-21 19:02:50 +00:00
|
|
|
|
|
|
|
connect(m_ui->General, &PageGeneral::variableModified, this, &Settings::onVariableModified);
|
|
|
|
connect(m_ui->Appearance, &PageAppearance::variableModified, this, &Settings::onVariableModified);
|
|
|
|
|
|
|
|
connect(m_ui->applyButton, &QPushButton::clicked, this, &Settings::apply);
|
|
|
|
connect(m_ui->okButton, &QPushButton::clicked, this, &Settings::confirm);
|
|
|
|
connect(m_ui->cancelButton, &QPushButton::clicked, this, &Settings::close);
|
2022-01-16 19:54:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Settings::~Settings()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-01-19 20:46:42 +00:00
|
|
|
void Settings::onCurrentPageChanged(QListWidgetItem* current)
|
|
|
|
{
|
|
|
|
if (current != nullptr) {
|
|
|
|
m_ui->header->setText(current->text());
|
|
|
|
|
|
|
|
m_ui->content->setCurrentIndex(m_ui->list->currentRow());
|
|
|
|
}
|
|
|
|
}
|
2022-01-21 19:02:50 +00:00
|
|
|
|
|
|
|
void Settings::onVariableModified(const QString& key, const QVariant& value)
|
|
|
|
{
|
|
|
|
modifiedSettings[key] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::apply()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
for (const std::pair<const QString, QVariant>& pair: modifiedSettings) {
|
|
|
|
if (pair.first == "theme") {
|
|
|
|
QString theme = pair.second.toString();
|
|
|
|
if (theme.toLower() == "system") {
|
|
|
|
QApplication::setStyle(Shared::Global::getInstance()->defaultSystemStyle);
|
|
|
|
} else {
|
|
|
|
QApplication::setStyle(theme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
settings.setValue(pair.first, pair.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
modifiedSettings.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::confirm()
|
|
|
|
{
|
|
|
|
apply();
|
|
|
|
close();
|
|
|
|
}
|