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

View file

@ -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<EffectData> m_effectsList;
};

View file

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

View file

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