From cc4d191a949cde6d39d881c926cebebd04484a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9ven=20Car?= Date: Mon, 16 Dec 2019 10:23:18 +0100 Subject: [PATCH] [KCM/Effects] Allow the user to know when the settings are set to default Summary: It works for the effect Test Plan: kcmshell5 kcm_kwin_effects Change some settings, the "Restore defaults" button is enabled when the state is not the default state. Open an effect configuration, the "Restore defaults" button is enabled when the settings are not default. Reviewers: #kwin, crossi, ervin, zzag Reviewed By: #kwin, zzag Subscribers: zzag, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D26040 --- kcmkwin/common/effectsmodel.cpp | 16 ++++++++++++++++ kcmkwin/common/effectsmodel.h | 5 +++++ kcmkwin/kwineffects/kcm.cpp | 2 ++ 3 files changed, 23 insertions(+) diff --git a/kcmkwin/common/effectsmodel.cpp b/kcmkwin/common/effectsmodel.cpp index a2349f6806..dce95ee4fd 100644 --- a/kcmkwin/common/effectsmodel.cpp +++ b/kcmkwin/common/effectsmodel.cpp @@ -563,6 +563,19 @@ void EffectsModel::defaults() } } +bool EffectsModel::isDefaults() const +{ + return std::all_of(m_effects.constBegin(), m_effects.constEnd(), [](const EffectData &effect) { + if (effect.enabledByDefaultFunction && effect.status != Status::EnabledUndeterminded) { + return false; + } + if ((bool)effect.status != effect.enabledByDefault) { + return false; + } + return true; + }); +} + bool EffectsModel::needsSave() const { return std::any_of(m_effects.constBegin(), m_effects.constEnd(), @@ -647,6 +660,9 @@ void EffectsModel::requestConfigure(const QModelIndex &index, QWindow *transient connect(buttons, &QDialogButtonBox::rejected, dialog, &QDialog::reject); connect(buttons->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, module, &KCModule::defaults); + connect(module, &KCModule::defaulted, this, [=](bool defaulted) { + buttons->button(QDialogButtonBox::RestoreDefaults)->setEnabled(!defaulted); + }); auto layout = new QVBoxLayout(dialog); layout->addWidget(module); diff --git a/kcmkwin/common/effectsmodel.h b/kcmkwin/common/effectsmodel.h index b40d5b30c9..b49754ac95 100644 --- a/kcmkwin/common/effectsmodel.h +++ b/kcmkwin/common/effectsmodel.h @@ -189,6 +189,11 @@ public: */ void defaults(); + /** + * Whether the status of each effect is its default state. + */ + bool isDefaults() const; + /** * Whether the model has unsaved changes. */ diff --git a/kcmkwin/kwineffects/kcm.cpp b/kcmkwin/kwineffects/kcm.cpp index d6a0e0bdcb..f9cc4370d0 100644 --- a/kcmkwin/kwineffects/kcm.cpp +++ b/kcmkwin/kwineffects/kcm.cpp @@ -52,6 +52,7 @@ DesktopEffectsKCM::DesktopEffectsKCM(QObject *parent, const QVariantList &args) setButtons(Apply | Default); connect(m_model, &EffectsModel::dataChanged, this, &DesktopEffectsKCM::updateNeedsSave); + connect(m_model, &EffectsModel::loaded, this, &DesktopEffectsKCM::updateNeedsSave); } DesktopEffectsKCM::~DesktopEffectsKCM() @@ -115,6 +116,7 @@ void DesktopEffectsKCM::configure(const QString &pluginId, QQuickItem *context) void DesktopEffectsKCM::updateNeedsSave() { setNeedsSave(m_model->needsSave()); + setRepresentsDefaults(m_model->isDefaults()); } } // namespace KWin