Add ExclusiveGroup support to the checkboxes of the ListView.
Only ONE of the following effects can be active at the same time. *kwin4_effect_slideEnabled *kwin4_effect_cubeslideEnabled *kwin4_effect_fadedesktopEnabledicc-effect-5.14.5
parent
3ab4e1a84a
commit
609c4c5470
|
@ -123,6 +123,15 @@ bool EffectModel::setData(const QModelIndex& index, const QVariant& value, int r
|
|||
|
||||
if (role == EffectModel::EffectStatusRole) {
|
||||
m_effectsList[index.row()].effectStatus = value.toBool();
|
||||
|
||||
const QString effectServiceName = m_effectsList[index.row()].serviceName;
|
||||
if (effectServiceName == "kwin4_effect_slide") {
|
||||
handleDesktopSwitching(index.row());
|
||||
} else if (effectServiceName == "kwin4_effect_fadedesktop") {
|
||||
handleDesktopSwitching(index.row());
|
||||
} else if (effectServiceName == "kwin4_effect_cubeslide") {
|
||||
handleDesktopSwitching(index.row());
|
||||
}
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
|
@ -146,7 +155,7 @@ void EffectModel::loadEffects() {
|
|||
effect.license = plugin.license();
|
||||
effect.version = plugin.version();
|
||||
effect.category = plugin.category();
|
||||
effect.serviceName = serviceName(effect.name);
|
||||
effect.serviceName = plugin.property("X-KDE-PluginInfo-Name").toString();
|
||||
effect.effectStatus = kwinConfig.readEntry(effect.serviceName + "Enabled", false);
|
||||
|
||||
if (effect.effectStatus) {
|
||||
|
@ -165,12 +174,27 @@ void EffectModel::loadEffects() {
|
|||
endResetModel();
|
||||
}
|
||||
|
||||
QString EffectModel::serviceName(const QString &effectName) {
|
||||
//The effect name is something like "Show Fps" and
|
||||
//we want something like "showfps"
|
||||
return "kwin4_effect_" + effectName.toLower().remove(" ");
|
||||
void EffectModel::handleDesktopSwitching(int row) {
|
||||
//Q: Why do we need the handleDesktopSwitching?
|
||||
//A: Because of the setData, when we enable the effect
|
||||
//and then we scroll, our model is being updated,
|
||||
//so the setData is being called again, and as a result
|
||||
//of that we have multiple effects enabled for the desktop switching.
|
||||
const QString currentEffect = m_effectsList[row].serviceName;
|
||||
for (int it = 0; it < m_effectsList.size(); it++) {
|
||||
EffectData effect = m_effectsList.at(it);
|
||||
|
||||
if (effect.serviceName == "kwin4_effect_slide" && currentEffect != effect.serviceName && effect.effectStatus) {
|
||||
m_effectsList[it].effectStatus = !m_effectsList[it].effectStatus;
|
||||
} else if (effect.serviceName == "kwin4_effect_cubeslide" && currentEffect != effect.serviceName && effect.effectStatus) {
|
||||
m_effectsList[it].effectStatus = !m_effectsList[it].effectStatus;
|
||||
}else if (effect.serviceName == "kwin4_effect_fadedesktop" && currentEffect != effect.serviceName && effect.effectStatus) {
|
||||
m_effectsList[it].effectStatus = !m_effectsList[it].effectStatus;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool EffectModel::effectListContains(const QString &effectFilter, int source_row) {
|
||||
EffectData effect;
|
||||
effect = m_effectsList.at(source_row);
|
||||
|
|
|
@ -78,6 +78,7 @@ public:
|
|||
|
||||
private:
|
||||
void loadEffects();
|
||||
void handleDesktopSwitching(int row);
|
||||
QList<EffectData> m_effectsList;
|
||||
};
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ Component {
|
|||
id: item
|
||||
width: parent.width
|
||||
height: 40
|
||||
|
||||
Rectangle {
|
||||
id: background
|
||||
color: item.ListView.isCurrentItem ? "#448" : index % 2 ? "#eee" : "#fff"
|
||||
|
@ -37,15 +38,27 @@ Component {
|
|||
|
||||
Row {
|
||||
CheckBox {
|
||||
function isDesktopSwitching() {
|
||||
if (model.ServiceNameRole == "kwin4_effect_slide") {
|
||||
return true;
|
||||
} else if (model.ServiceNameRole == "kwin4_effect_fadedesktop") {
|
||||
return true;
|
||||
} else if (model.ServiceNameRole == "kwin4_effect_cubeslide") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
id: myCheckBox
|
||||
checked: model.EffectStatusRole
|
||||
exclusiveGroup: isDesktopSwitching() ? desktopSwitching : null
|
||||
onClicked: {
|
||||
apply.enabled = true;
|
||||
effectModel.effectStatus(effectView.model.modelIndex(index),checked);
|
||||
}
|
||||
|
||||
onCheckedChanged: {
|
||||
configureButton.enabled = myCheckBox.checked;
|
||||
effectModel.effectStatus(effectView.model.modelIndex(index),checked);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -92,6 +92,12 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
ExclusiveGroup {
|
||||
id: desktopSwitching
|
||||
//Our ExclusiveGroup must me outside of the
|
||||
//ListView, otherwise it will not work
|
||||
}
|
||||
|
||||
Button {
|
||||
id: apply
|
||||
text: "Apply"
|
||||
|
|
|
@ -71,7 +71,6 @@ Item {
|
|||
openGLError.visible = true;
|
||||
} else {
|
||||
openGLError.visible = false;
|
||||
console.log("mesa")
|
||||
view.visible = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue