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