Add Improved Window Management Support

When we click into the CheckBox the following effects are being enabled:

*kwin4_effect_desktopgrid
*kwin4_effect_presntwindows
*kwin4_effect_dialogparent

If one of the above effects gets disabled, then the checkbox is unchecked.
Our CheckBox can detect if our effects are enable at the start time.
This commit is contained in:
Antonis Tsiapaliokas 2013-08-22 13:31:01 +03:00 committed by Martin Gräßlin
parent cc375dab36
commit ed2cf5a8b5
4 changed files with 130 additions and 65 deletions

View file

@ -134,6 +134,11 @@ bool EffectModel::setData(const QModelIndex& index, const QVariant& value, int r
} }
emit dataChanged(index, index); emit dataChanged(index, index);
return true; return true;
} else if (role == EffectModel::WindowManagementRole) {
bool enabled = value.toBool();
handleWindowManagement(index.row(), enabled);
emit dataChanged(index, index);
return true;
} }
return QAbstractItemModel::setData(index, value, role); return QAbstractItemModel::setData(index, value, role);
@ -196,6 +201,18 @@ void EffectModel::handleDesktopSwitching(int row) {
} }
} }
void EffectModel::handleWindowManagement(int row, bool enabled) {
m_effectsList[row].effectStatus = enabled;
}
int EffectModel::findRowByServiceName(const QString &serviceName) {
for (int it=0; m_effectsList.size(); it++) {
if (m_effectsList.at(it).serviceName == serviceName) {
return it;
}
}
return -1;
}
bool EffectModel::effectListContains(const QString &effectFilter, int source_row) { bool EffectModel::effectListContains(const QString &effectFilter, int source_row) {
EffectData effect; EffectData effect;
@ -217,7 +234,7 @@ void EffectModel::reload() {
} }
void EffectModel::effectStatus(const QModelIndex &index, bool effectState) { void EffectModel::effectStatus(const QModelIndex &index, bool effectState) {
setData(index, effectState, EffectStatusRole); setData(index, effectState, EffectModel::EffectStatusRole);
} }
void EffectModel::syncConfig() { void EffectModel::syncConfig() {
@ -237,6 +254,20 @@ void EffectModel::syncConfig() {
kwinConfig.sync(); kwinConfig.sync();
} }
void EffectModel::enableWidnowManagement(bool enabled) {
int desktopGridRow = findRowByServiceName("kwin4_effect_desktopgrid");
const QModelIndex desktopGridIndex = createIndex(desktopGridRow, 0);
setData(desktopGridIndex, enabled, EffectModel::WindowManagementRole);
int dialogParentRow = findRowByServiceName("kwin4_effect_dialogparent");
const QModelIndex dialogParentIndex = createIndex(dialogParentRow, 0);
setData(dialogParentIndex, enabled, EffectModel::WindowManagementRole);
int presentWindowsRow = findRowByServiceName("kwin4_effect_presentwindows");
const QModelIndex presentWindowsIndex = createIndex(presentWindowsRow, 0);
setData(presentWindowsIndex, enabled, EffectModel::WindowManagementRole);
}
EffectFilterModel::EffectFilterModel(QObject *parent) EffectFilterModel::EffectFilterModel(QObject *parent)
:QSortFilterProxyModel(parent), :QSortFilterProxyModel(parent),
m_effectModel(0) m_effectModel(0)

View file

@ -57,7 +57,8 @@ public:
VersionRole, VersionRole,
CategoryRole, CategoryRole,
ServiceNameRole, ServiceNameRole,
EffectStatusRole EffectStatusRole,
WindowManagementRole
}; };
explicit EffectModel(QObject *parent = 0); explicit EffectModel(QObject *parent = 0);
@ -75,10 +76,13 @@ public:
Q_INVOKABLE QString findImage(const QString &imagePath, int size = 128); Q_INVOKABLE QString findImage(const QString &imagePath, int size = 128);
Q_INVOKABLE void reload(); Q_INVOKABLE void reload();
Q_INVOKABLE void syncConfig(); Q_INVOKABLE void syncConfig();
Q_INVOKABLE void enableWidnowManagement(bool enabled);
private: private:
void loadEffects(); void loadEffects();
void handleDesktopSwitching(int row); void handleDesktopSwitching(int row);
void handleWindowManagement(int row, bool enabled);
int findRowByServiceName(const QString &serviceName);
QList<EffectData> m_effectsList; QList<EffectData> m_effectsList;
}; };

View file

@ -49,7 +49,22 @@ Component {
return false; return false;
} }
} }
function isWindowManagementEnabled() {
if (model.ServiceNameRole == "kwin4_effect_dialogparent") {
windowManagementEnabled = myCheckBox.checked;
return windowManagementEnabled = myCheckBox.checked && windowManagementEnabled;
} else if (model.ServiceNameRole == "kwin4_effect_desktopgrid") {
windowManagementEnabled = myCheckBox.checked;
return windowManagementEnabled = myCheckBox.checked && windowManagementEnabled;
} else if (model.ServiceNameRole == "kwin4_effect_presentwindows") {
windowManagementEnabled = myCheckBox.checked;
return windowManagementEnabled = myCheckBox.checked && windowManagementEnabled;
}
return windowManagementEnabled;
}
id: myCheckBox id: myCheckBox
property bool windowManagementEnabled;
checked: model.EffectStatusRole checked: model.EffectStatusRole
exclusiveGroup: isDesktopSwitching() ? desktopSwitching : null exclusiveGroup: isDesktopSwitching() ? desktopSwitching : null
onClicked: { onClicked: {
@ -58,6 +73,7 @@ Component {
onCheckedChanged: { onCheckedChanged: {
configureButton.enabled = myCheckBox.checked; configureButton.enabled = myCheckBox.checked;
windowManagement.checked = isWindowManagementEnabled();
effectModel.effectStatus(effectView.model.modelIndex(index),checked); effectModel.effectStatus(effectView.model.modelIndex(index),checked);
} }
} }

View file

@ -40,77 +40,91 @@ Item {
} }
} }
} }
RowLayout {
ColumnLayout { id: row
id: col width: parent.width
height: parent.height height: parent.height
anchors { CheckBox {
top: parent.top id: windowManagement
left: parent.left text: "Improved Window Management"
right: parent.right checked: false
anchors.left: col.right
anchors.top: parent.top
anchors.topMargin: col.height/2
onClicked: effectModel.enableWidnowManagement(windowManagement.checked)
} }
TextField {
id: searchField ColumnLayout {
Layout.fillWidth: true id: col
height: 20 height: parent.height
anchors { anchors {
top: parent.top top: parent.top
}
focus: true
}
EffectFilterModel {
id:searchModel
filter: searchField.text
effectModel: EffectModel {
id: effectModel
}
}
ScrollView {
id: scroll
highlightOnFocus: true
Layout.fillWidth: true
anchors {
top: searchField.bottom
left: parent.left left: parent.left
right: parent.right
bottom: apply.top
} }
ListView { TextField {
id: effectView id: searchField
Layout.fillWidth: true Layout.fillWidth: true
anchors.fill: parent height: 20
model: VisualDataModel{ anchors {
model: searchModel top: parent.top
delegate: Effect{} }
focus: true
}
EffectFilterModel {
id:searchModel
filter: searchField.text
effectModel: EffectModel {
id: effectModel
}
}
ScrollView {
id: scroll
highlightOnFocus: true
Layout.fillWidth: true
Layout.fillHeight: true
anchors {
top: searchField.bottom
left: parent.left
bottom: apply.top
}
ListView {
id: effectView
Layout.fillWidth: true
anchors.fill: parent
model: VisualDataModel{
model: searchModel
delegate: Effect{}
}
section.property: "CategoryRole"
section.delegate: sectionHeading
}
}
ExclusiveGroup {
id: desktopSwitching
//Our ExclusiveGroup must me outside of the
//ListView, otherwise it will not work
}
Button {
id: apply
text: "Apply"
enabled: false
anchors {
bottom: parent.bottom
} }
section.property: "CategoryRole" onClicked: {
section.delegate: sectionHeading effectModel.syncConfig();
} effectModel.reload();
} apply.enabled = false;
}
ExclusiveGroup {
id: desktopSwitching
//Our ExclusiveGroup must me outside of the
//ListView, otherwise it will not work
}
Button {
id: apply
text: "Apply"
enabled: false
anchors {
bottom: parent.bottom
} }
onClicked: { }//End ColumnLayout
effectModel.syncConfig(); }//End RowLayout
effectModel.reload(); }//End item
apply.enabled = false;
}
}
}
}