Move effectStatus and syncConfig from EffectView class to EffectModel
This commit is contained in:
parent
f9706e0734
commit
dac370fc61
4 changed files with 43 additions and 30 deletions
|
@ -130,6 +130,19 @@ void EffectModel::loadEffects() {
|
|||
endResetModel();
|
||||
}
|
||||
|
||||
bool EffectModel::setData(const QModelIndex& index, const QVariant& value, int role) {
|
||||
if (!index.isValid())
|
||||
return QAbstractItemModel::setData(index, value, role);
|
||||
|
||||
if (role == EffectModel::EffectStatusRole) {
|
||||
m_effectsList[index.row()].effectStatus = value.toBool();
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
|
||||
return QAbstractItemModel::setData(index, value, role);
|
||||
}
|
||||
|
||||
QString EffectModel::serviceName(const QString &effectName) {
|
||||
//The effect name is something like "Show Fps" and
|
||||
//we want something like "showfps"
|
||||
|
@ -147,6 +160,27 @@ void EffectModel::reload() {
|
|||
loadEffects();
|
||||
}
|
||||
|
||||
void EffectModel::effectStatus(const QModelIndex &index, bool effectState) {
|
||||
setData(index, effectState, EffectStatusRole);
|
||||
}
|
||||
|
||||
void EffectModel::syncConfig() {
|
||||
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins");
|
||||
|
||||
for (auto it = m_effectsList.begin(); it != m_effectsList.end(); it++) {
|
||||
EffectData effect = *(it);
|
||||
bool effectConfigStatus = kwinConfig.readEntry(effect.serviceName + "Enabled", false);
|
||||
|
||||
if (effect.effectStatus) {
|
||||
kwinConfig.writeEntry(effect.serviceName + "Enabled", effect.effectStatus);
|
||||
} else if (effect.effectStatus != effectConfigStatus) {
|
||||
kwinConfig.writeEntry(effect.serviceName + "Enabled", effect.effectStatus);
|
||||
}
|
||||
}
|
||||
|
||||
kwinConfig.sync();
|
||||
}
|
||||
|
||||
EffectView::EffectView(QWindow *parent)
|
||||
: QQuickView(parent)
|
||||
{
|
||||
|
@ -159,27 +193,8 @@ EffectView::EffectView(QWindow *parent)
|
|||
void EffectView::init() {
|
||||
QString mainFile = QStandardPaths::locate(QStandardPaths::DataLocation, "qml/main.qml", QStandardPaths::LocateFile);
|
||||
setResizeMode(QQuickView::SizeRootObjectToView);
|
||||
rootContext()->setContextProperty("engineObject", this);
|
||||
setSource(QUrl(mainFile));
|
||||
}
|
||||
|
||||
void EffectView::effectStatus(const QString &effectName, bool status) {
|
||||
m_effectStatus[effectName] = status;
|
||||
}
|
||||
|
||||
void EffectView::syncConfig() {
|
||||
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins");
|
||||
QHash<QString, bool> effectsChanged;
|
||||
|
||||
for (auto it = m_effectStatus.constBegin(); it != m_effectStatus.constEnd(); it++) {
|
||||
QVariant boolToString(it.value());
|
||||
QString effectName = it.key().toLower();
|
||||
QString effectEntry = effectName.remove(" ");
|
||||
kwinConfig.writeEntry("kwin4_effect_" + effectEntry + "Enabled", boolToString.toString());
|
||||
effectsChanged["kwin4_effect_" + effectEntry] = boolToString.toBool();
|
||||
}
|
||||
kwinConfig.sync();
|
||||
}
|
||||
|
||||
}//end namespace Compositing
|
||||
}//end namespace KWin
|
||||
|
|
|
@ -62,10 +62,13 @@ public:
|
|||
explicit EffectModel(QObject *parent = 0);
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
QString serviceName(const QString &effectName);
|
||||
|
||||
Q_INVOKABLE void effectStatus(const QModelIndex &index, bool effectState);
|
||||
Q_INVOKABLE QString findImage(const QString &imagePath, int size = 128);
|
||||
Q_INVOKABLE void reload();
|
||||
Q_INVOKABLE void syncConfig();
|
||||
|
||||
private:
|
||||
void loadEffects();
|
||||
|
@ -79,13 +82,6 @@ class EffectView : public QQuickView {
|
|||
public:
|
||||
EffectView(QWindow *parent = 0);
|
||||
void init();
|
||||
void loadKWinEffects(const QHash<QString, bool> &effectsChanged);
|
||||
|
||||
Q_INVOKABLE void effectStatus(const QString &effectName, bool status);
|
||||
Q_INVOKABLE void syncConfig();
|
||||
|
||||
private:
|
||||
QHash<QString, bool> m_effectStatus;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ Component {
|
|||
checked: model.EffectStatusRole
|
||||
onClicked: {
|
||||
apply.enabled = true;
|
||||
engineObject.effectStatus(model.NameRole, checked);
|
||||
effectModel.effectStatus(effectView.model.modelIndex(index),checked);
|
||||
}
|
||||
|
||||
onCheckedChanged: {
|
||||
|
|
|
@ -88,8 +88,10 @@ Item {
|
|||
id: effectView
|
||||
Layout.fillWidth: true
|
||||
anchors.fill: parent
|
||||
model: searchModel
|
||||
delegate: Effect {}
|
||||
model: VisualDataModel{
|
||||
model: searchModel
|
||||
delegate: Effect{}
|
||||
}
|
||||
|
||||
section.property: "CategoryRole"
|
||||
section.delegate: sectionHeading
|
||||
|
@ -105,7 +107,7 @@ Item {
|
|||
}
|
||||
|
||||
onClicked: {
|
||||
engineObject.syncConfig();
|
||||
effectModel.syncConfig();
|
||||
effectModel.reload();
|
||||
apply.enabled = false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue