/* * 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 . */ #include "settingswidget.h" #include #include #include #include #include #include #include #include #include #include #include "../widgets/coloredit.h" #include "../utils.h" #include "../iconsmanager.h" SettingsWidget::SettingsWidget(const QString &name, const QString &group, QWidget *parent): QWidget(parent), mSettingsChanged(false), mName(name), mGroup(group) { } void SettingsWidget::init() { connect(pIconsManager,&IconsManager::actionIconsUpdated, this, &SettingsWidget::onUpdateIcons); onUpdateIcons(); load(); connectInputs(); } void SettingsWidget::load() { try { doLoad(); clearSettingsChanged(); } catch (FileError & e) { QMessageBox::warning(nullptr, tr("Load Error"), e.reason()); } } void SettingsWidget::save() { try { doSave(); clearSettingsChanged(); } catch (FileError & e) { QMessageBox::warning(nullptr, tr("Save Error"), e.reason()); } } 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); } void SettingsWidget::updateIcons(const QSize &) { } void SettingsWidget::connectInputs() { for (QLineEdit* p:findChildren()) { connect(p, &QLineEdit::textChanged, this, &SettingsWidget::setSettingsChanged); } for (QCheckBox* p:findChildren()) { connect(p, &QCheckBox::toggled, this, &SettingsWidget::setSettingsChanged); } for (QRadioButton* p:findChildren()) { connect(p, &QRadioButton::toggled, this, &SettingsWidget::setSettingsChanged); } for (QPlainTextEdit* p:findChildren()) { connect(p, &QPlainTextEdit::textChanged, this, &SettingsWidget::setSettingsChanged); } for (QSpinBox* p:findChildren()) { connect(p, QOverload::of(&QSpinBox::valueChanged), this, &SettingsWidget::setSettingsChanged); } for (ColorEdit* p:findChildren()) { connect(p, &ColorEdit::colorChanged, this, &SettingsWidget::setSettingsChanged); } for (QComboBox* p: findChildren()) { connect(p, QOverload::of(&QComboBox::currentIndexChanged) ,this, &SettingsWidget::setSettingsChanged); } for (QAbstractItemView* p: findChildren()) { connectAbstractItemView(p); } for (QGroupBox* p: findChildren()) { connect(p, &QGroupBox::toggled,this, &SettingsWidget::setSettingsChanged); } } void SettingsWidget::disconnectInputs() { for (QLineEdit* p:findChildren()) { disconnect(p, &QLineEdit::textChanged, this, &SettingsWidget::setSettingsChanged); } for (QCheckBox* p:findChildren()) { disconnect(p, &QCheckBox::stateChanged, this, &SettingsWidget::setSettingsChanged); } for (QPlainTextEdit* p:findChildren()) { disconnect(p, &QPlainTextEdit::textChanged, this, &SettingsWidget::setSettingsChanged); } for (QComboBox* p: findChildren()) { disconnect(p, QOverload::of(&QComboBox::currentIndexChanged) ,this, &SettingsWidget::setSettingsChanged); } for (QAbstractItemView* p: findChildren()) { disconnectAbstractItemView(p); } } const QString &SettingsWidget::group() { return mGroup; } const QString &SettingsWidget::name() { return mName; } bool SettingsWidget::isSettingsChanged() { return mSettingsChanged; } void SettingsWidget::setSettingsChanged() { mSettingsChanged = true; emit settingsChanged(true); } void SettingsWidget::clearSettingsChanged() { mSettingsChanged = false; emit settingsChanged(false); } void SettingsWidget::onUpdateIcons() { updateIcons(pIconsManager->actionIconSize()); }