2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-04-16 22:04:48 +08:00
|
|
|
#include "settingswidget.h"
|
|
|
|
|
2021-04-17 22:38:46 +08:00
|
|
|
#include <QAbstractItemView>
|
2021-04-16 22:04:48 +08:00
|
|
|
#include <QCheckBox>
|
2021-04-17 14:52:47 +08:00
|
|
|
#include <QComboBox>
|
2021-09-04 21:20:30 +08:00
|
|
|
#include <QGroupBox>
|
2021-04-16 22:04:48 +08:00
|
|
|
#include <QLineEdit>
|
2021-04-17 22:38:46 +08:00
|
|
|
#include <QListView>
|
2021-10-22 07:42:51 +08:00
|
|
|
#include <QMessageBox>
|
2021-04-16 22:04:48 +08:00
|
|
|
#include <QPlainTextEdit>
|
2022-01-13 16:47:48 +08:00
|
|
|
#include <QListWidget>
|
2021-08-30 19:52:38 +08:00
|
|
|
#include <QRadioButton>
|
2021-06-07 11:02:03 +08:00
|
|
|
#include <QSpinBox>
|
|
|
|
#include "../widgets/coloredit.h"
|
2021-10-22 07:42:51 +08:00
|
|
|
#include "../utils.h"
|
2021-12-23 00:24:52 +08:00
|
|
|
#include "../iconsmanager.h"
|
2021-04-16 22:04:48 +08:00
|
|
|
|
|
|
|
SettingsWidget::SettingsWidget(const QString &name, const QString &group, QWidget *parent):
|
|
|
|
QWidget(parent),
|
2021-10-23 23:10:34 +08:00
|
|
|
mSettingsChanged(false),
|
2022-07-04 11:39:06 +08:00
|
|
|
mGroup(group),
|
|
|
|
mName(name)
|
2021-04-16 22:04:48 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::init()
|
|
|
|
{
|
2021-12-23 00:24:52 +08:00
|
|
|
connect(pIconsManager,&IconsManager::actionIconsUpdated,
|
|
|
|
this, &SettingsWidget::onUpdateIcons);
|
|
|
|
onUpdateIcons();
|
2021-04-16 22:04:48 +08:00
|
|
|
load();
|
2021-04-17 22:38:46 +08:00
|
|
|
connectInputs();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::load()
|
|
|
|
{
|
2021-10-22 07:42:51 +08:00
|
|
|
try {
|
|
|
|
doLoad();
|
|
|
|
clearSettingsChanged();
|
|
|
|
} catch (FileError & e) {
|
|
|
|
QMessageBox::warning(nullptr,
|
|
|
|
tr("Load Error"),
|
|
|
|
e.reason());
|
|
|
|
}
|
2021-04-17 22:38:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::save()
|
|
|
|
{
|
2021-10-22 07:42:51 +08:00
|
|
|
try {
|
|
|
|
doSave();
|
|
|
|
clearSettingsChanged();
|
|
|
|
} catch (FileError & e) {
|
|
|
|
QMessageBox::warning(nullptr,
|
|
|
|
tr("Save Error"),
|
|
|
|
e.reason());
|
|
|
|
}
|
2021-04-18 11:25:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::connectAbstractItemView(QAbstractItemView *pView)
|
|
|
|
{
|
|
|
|
connect(pView->model(),&QAbstractItemModel::rowsInserted,this,&SettingsWidget::setSettingsChanged);
|
|
|
|
connect(pView->model(),&QAbstractItemModel::rowsMoved,this,&SettingsWidget::setSettingsChanged);
|
|
|
|
connect(pView->model(),&QAbstractItemModel::rowsRemoved,this,&SettingsWidget::setSettingsChanged);
|
|
|
|
connect(pView->model(),&QAbstractItemModel::dataChanged,this,&SettingsWidget::setSettingsChanged);
|
|
|
|
connect(pView->model(),&QAbstractItemModel::modelReset,this,&SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::disconnectAbstractItemView(QAbstractItemView *pView)
|
|
|
|
{
|
|
|
|
disconnect(pView->model(),&QAbstractItemModel::rowsInserted,this,&SettingsWidget::setSettingsChanged);
|
|
|
|
disconnect(pView->model(),&QAbstractItemModel::rowsMoved,this,&SettingsWidget::setSettingsChanged);
|
|
|
|
disconnect(pView->model(),&QAbstractItemModel::rowsRemoved,this,&SettingsWidget::setSettingsChanged);
|
|
|
|
disconnect(pView->model(),&QAbstractItemModel::dataChanged,this,&SettingsWidget::setSettingsChanged);
|
|
|
|
disconnect(pView->model(),&QAbstractItemModel::modelReset,this,&SettingsWidget::setSettingsChanged);
|
|
|
|
|
2021-04-17 22:38:46 +08:00
|
|
|
}
|
|
|
|
|
2022-10-12 19:48:35 +08:00
|
|
|
void SettingsWidget::updateIcons(const QSize & /*size*/)
|
2021-12-23 00:24:52 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-17 22:38:46 +08:00
|
|
|
void SettingsWidget::connectInputs()
|
|
|
|
{
|
2021-04-16 22:04:48 +08:00
|
|
|
for (QLineEdit* p:findChildren<QLineEdit*>()) {
|
|
|
|
connect(p, &QLineEdit::textChanged, this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
|
|
|
for (QCheckBox* p:findChildren<QCheckBox*>()) {
|
2021-08-30 19:52:38 +08:00
|
|
|
connect(p, &QCheckBox::toggled, this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
|
|
|
for (QRadioButton* p:findChildren<QRadioButton*>()) {
|
|
|
|
connect(p, &QRadioButton::toggled, this, &SettingsWidget::setSettingsChanged);
|
2021-04-16 22:04:48 +08:00
|
|
|
}
|
|
|
|
for (QPlainTextEdit* p:findChildren<QPlainTextEdit*>()) {
|
|
|
|
connect(p, &QPlainTextEdit::textChanged, this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
2021-06-07 11:02:03 +08:00
|
|
|
for (QSpinBox* p:findChildren<QSpinBox*>()) {
|
|
|
|
connect(p, QOverload<int>::of(&QSpinBox::valueChanged), this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
2022-12-20 11:01:04 +08:00
|
|
|
for (QDoubleSpinBox* p:findChildren<QDoubleSpinBox*>()) {
|
|
|
|
connect(p, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
2021-06-07 11:02:03 +08:00
|
|
|
for (ColorEdit* p:findChildren<ColorEdit*>()) {
|
|
|
|
connect(p, &ColorEdit::colorChanged, this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
2021-04-17 14:52:47 +08:00
|
|
|
for (QComboBox* p: findChildren<QComboBox*>()) {
|
|
|
|
connect(p, QOverload<int>::of(&QComboBox::currentIndexChanged) ,this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
2021-04-17 22:38:46 +08:00
|
|
|
for (QAbstractItemView* p: findChildren<QAbstractItemView*>()) {
|
2021-04-18 11:25:40 +08:00
|
|
|
connectAbstractItemView(p);
|
2021-04-17 22:38:46 +08:00
|
|
|
}
|
2022-01-13 16:47:48 +08:00
|
|
|
for (QListWidget* p:findChildren<QListWidget*>()) {
|
|
|
|
connect(p, QOverload<int>::of(&QListWidget::currentRowChanged) ,this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
2021-09-04 21:20:30 +08:00
|
|
|
for (QGroupBox* p: findChildren<QGroupBox*>()) {
|
|
|
|
connect(p, &QGroupBox::toggled,this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
2021-04-16 22:04:48 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-18 11:25:40 +08:00
|
|
|
void SettingsWidget::disconnectInputs()
|
|
|
|
{
|
|
|
|
for (QLineEdit* p:findChildren<QLineEdit*>()) {
|
|
|
|
disconnect(p, &QLineEdit::textChanged, this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
|
|
|
for (QCheckBox* p:findChildren<QCheckBox*>()) {
|
|
|
|
disconnect(p, &QCheckBox::stateChanged, this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
2022-01-13 16:47:48 +08:00
|
|
|
for (QRadioButton* p:findChildren<QRadioButton*>()) {
|
|
|
|
disconnect(p, &QRadioButton::toggled, this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
2021-04-18 11:25:40 +08:00
|
|
|
for (QPlainTextEdit* p:findChildren<QPlainTextEdit*>()) {
|
|
|
|
disconnect(p, &QPlainTextEdit::textChanged, this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
2022-01-13 16:47:48 +08:00
|
|
|
for (QSpinBox* p:findChildren<QSpinBox*>()) {
|
|
|
|
disconnect(p, QOverload<int>::of(&QSpinBox::valueChanged), this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
2022-12-20 11:01:04 +08:00
|
|
|
for (QDoubleSpinBox* p:findChildren<QDoubleSpinBox*>()) {
|
|
|
|
disconnect(p, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
|
|
|
|
2022-01-13 16:47:48 +08:00
|
|
|
for (ColorEdit* p:findChildren<ColorEdit*>()) {
|
|
|
|
disconnect(p, &ColorEdit::colorChanged, this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
|
|
|
|
2021-04-18 11:25:40 +08:00
|
|
|
for (QComboBox* p: findChildren<QComboBox*>()) {
|
|
|
|
disconnect(p, QOverload<int>::of(&QComboBox::currentIndexChanged) ,this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
|
|
|
for (QAbstractItemView* p: findChildren<QAbstractItemView*>()) {
|
|
|
|
disconnectAbstractItemView(p);
|
|
|
|
}
|
2022-01-13 16:47:48 +08:00
|
|
|
for (QListWidget* p:findChildren<QListWidget*>()) {
|
|
|
|
disconnect(p, QOverload<int>::of(&QListWidget::currentRowChanged) ,this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
|
|
|
for (QGroupBox* p: findChildren<QGroupBox*>()) {
|
|
|
|
disconnect(p, &QGroupBox::toggled,this, &SettingsWidget::setSettingsChanged);
|
|
|
|
}
|
|
|
|
|
2021-04-18 11:25:40 +08:00
|
|
|
}
|
|
|
|
|
2021-04-16 22:04:48 +08:00
|
|
|
const QString &SettingsWidget::group()
|
|
|
|
{
|
|
|
|
return mGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &SettingsWidget::name()
|
|
|
|
{
|
|
|
|
return mName;
|
|
|
|
}
|
|
|
|
|
2021-04-17 14:52:47 +08:00
|
|
|
bool SettingsWidget::isSettingsChanged()
|
2021-04-16 22:04:48 +08:00
|
|
|
{
|
|
|
|
return mSettingsChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::setSettingsChanged()
|
|
|
|
{
|
|
|
|
mSettingsChanged = true;
|
2021-04-17 14:52:47 +08:00
|
|
|
emit settingsChanged(true);
|
2021-04-16 22:04:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::clearSettingsChanged()
|
|
|
|
{
|
|
|
|
mSettingsChanged = false;
|
2021-04-17 14:52:47 +08:00
|
|
|
emit settingsChanged(false);
|
2021-04-16 22:04:48 +08:00
|
|
|
}
|
2021-12-23 00:24:52 +08:00
|
|
|
|
|
|
|
void SettingsWidget::onUpdateIcons()
|
|
|
|
{
|
|
|
|
updateIcons(pIconsManager->actionIconSize());
|
|
|
|
}
|