[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
This commit is contained in:
Méven Car 2019-12-16 10:23:18 +01:00
parent d72e96802b
commit cc4d191a94
3 changed files with 23 additions and 0 deletions

View file

@ -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);

View file

@ -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.
*/

View file

@ -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