From ed2cf5a8b5d4ee6c45b26f8f3001ed8bcfa6be52 Mon Sep 17 00:00:00 2001 From: Antonis Tsiapaliokas Date: Thu, 22 Aug 2013 13:31:01 +0300 Subject: [PATCH] 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. --- kcmkwin/kwincompositing/model.cpp | 33 ++++- kcmkwin/kwincompositing/model.h | 6 +- kcmkwin/kwincompositing/qml/Effect.qml | 16 +++ kcmkwin/kwincompositing/qml/EffectView.qml | 140 +++++++++++---------- 4 files changed, 130 insertions(+), 65 deletions(-) diff --git a/kcmkwin/kwincompositing/model.cpp b/kcmkwin/kwincompositing/model.cpp index a2181b07af..eb987178c3 100644 --- a/kcmkwin/kwincompositing/model.cpp +++ b/kcmkwin/kwincompositing/model.cpp @@ -134,6 +134,11 @@ bool EffectModel::setData(const QModelIndex& index, const QVariant& value, int r } emit dataChanged(index, index); 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); @@ -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) { EffectData effect; @@ -217,7 +234,7 @@ void EffectModel::reload() { } void EffectModel::effectStatus(const QModelIndex &index, bool effectState) { - setData(index, effectState, EffectStatusRole); + setData(index, effectState, EffectModel::EffectStatusRole); } void EffectModel::syncConfig() { @@ -237,6 +254,20 @@ void EffectModel::syncConfig() { 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) :QSortFilterProxyModel(parent), m_effectModel(0) diff --git a/kcmkwin/kwincompositing/model.h b/kcmkwin/kwincompositing/model.h index 9c18e9b4ac..7bb6768dd2 100644 --- a/kcmkwin/kwincompositing/model.h +++ b/kcmkwin/kwincompositing/model.h @@ -57,7 +57,8 @@ public: VersionRole, CategoryRole, ServiceNameRole, - EffectStatusRole + EffectStatusRole, + WindowManagementRole }; explicit EffectModel(QObject *parent = 0); @@ -75,10 +76,13 @@ public: Q_INVOKABLE QString findImage(const QString &imagePath, int size = 128); Q_INVOKABLE void reload(); Q_INVOKABLE void syncConfig(); + Q_INVOKABLE void enableWidnowManagement(bool enabled); private: void loadEffects(); void handleDesktopSwitching(int row); + void handleWindowManagement(int row, bool enabled); + int findRowByServiceName(const QString &serviceName); QList m_effectsList; }; diff --git a/kcmkwin/kwincompositing/qml/Effect.qml b/kcmkwin/kwincompositing/qml/Effect.qml index 31de665011..94995635b7 100644 --- a/kcmkwin/kwincompositing/qml/Effect.qml +++ b/kcmkwin/kwincompositing/qml/Effect.qml @@ -49,7 +49,22 @@ Component { 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 + property bool windowManagementEnabled; checked: model.EffectStatusRole exclusiveGroup: isDesktopSwitching() ? desktopSwitching : null onClicked: { @@ -58,6 +73,7 @@ Component { onCheckedChanged: { configureButton.enabled = myCheckBox.checked; + windowManagement.checked = isWindowManagementEnabled(); effectModel.effectStatus(effectView.model.modelIndex(index),checked); } } diff --git a/kcmkwin/kwincompositing/qml/EffectView.qml b/kcmkwin/kwincompositing/qml/EffectView.qml index 56bae23182..4ff9e5414b 100644 --- a/kcmkwin/kwincompositing/qml/EffectView.qml +++ b/kcmkwin/kwincompositing/qml/EffectView.qml @@ -40,77 +40,91 @@ Item { } } } - - ColumnLayout { - id: col + RowLayout { + id: row + width: parent.width height: parent.height - anchors { - top: parent.top - left: parent.left - right: parent.right + CheckBox { + id: windowManagement + text: "Improved Window Management" + checked: false + anchors.left: col.right + anchors.top: parent.top + anchors.topMargin: col.height/2 + onClicked: effectModel.enableWidnowManagement(windowManagement.checked) } - TextField { - id: searchField - Layout.fillWidth: true - height: 20 + + ColumnLayout { + id: col + height: parent.height + anchors { 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 - right: parent.right - bottom: apply.top } - ListView { - id: effectView + TextField { + id: searchField Layout.fillWidth: true - anchors.fill: parent - model: VisualDataModel{ - model: searchModel - delegate: Effect{} + height: 20 + anchors { + top: parent.top + } + 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" - 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 + onClicked: { + effectModel.syncConfig(); + effectModel.reload(); + apply.enabled = false; + } } - onClicked: { - effectModel.syncConfig(); - effectModel.reload(); - apply.enabled = false; - } - } - } -} + }//End ColumnLayout + }//End RowLayout +}//End item