KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
/*
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2020 Ismael Asensio <isma.af@gmail.com>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
|
|
*/
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
|
|
|
|
import QtQuick 2.14
|
|
|
|
import QtQuick.Layouts 1.14
|
|
|
|
import QtQuick.Controls 2.14 as QQC2
|
|
|
|
|
|
|
|
import org.kde.kirigami 2.10 as Kirigami
|
|
|
|
|
|
|
|
|
|
|
|
QQC2.ComboBox {
|
|
|
|
id: optionsCombo
|
|
|
|
|
|
|
|
textRole: "display"
|
2020-04-23 20:43:37 +00:00
|
|
|
valueRole: "value"
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
|
|
|
|
property bool multipleChoice: false
|
2020-12-26 18:24:34 +00:00
|
|
|
// If `useFlagsValue` is true, `selectionMask` will be composed using the item values.
|
|
|
|
// Otherwise, it will use the item indexes.
|
|
|
|
property bool useFlagsValue: false
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
property int selectionMask: 0
|
|
|
|
|
|
|
|
currentIndex: multipleChoice ? -1 : model.selectedIndex
|
|
|
|
|
|
|
|
displayText: {
|
|
|
|
if (!multipleChoice) {
|
|
|
|
return currentText;
|
|
|
|
}
|
|
|
|
var selectionCount = selectionMask.toString(2).replace(/0/g, '').length;
|
|
|
|
switch (selectionCount) {
|
|
|
|
case 0:
|
|
|
|
return i18n("None selected");
|
|
|
|
case 1:
|
2020-12-26 18:24:34 +00:00
|
|
|
let selectedBit = selectionMask.toString(2).length - 1;
|
|
|
|
let selectedIndex = (useFlagsValue) ? model.indexOf(selectedBit) : selectedBit
|
|
|
|
return model.data(model.index(selectedIndex, 0), Qt.DisplayRole);
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
case count:
|
|
|
|
return i18n("All selected");
|
|
|
|
}
|
|
|
|
return i18np("%1 selected", "%1 selected", selectionCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
delegate: QQC2.ItemDelegate {
|
|
|
|
highlighted: optionsCombo.highlightedIndex == index
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
contentItem: RowLayout {
|
|
|
|
QQC2.CheckBox {
|
|
|
|
id: itemSelection
|
|
|
|
visible: multipleChoice
|
2020-12-26 18:24:34 +00:00
|
|
|
readonly property int bit: (useFlagsValue) ? value : index
|
|
|
|
checked: (selectionMask & (1 << bit))
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
onToggled: {
|
2020-12-26 18:24:34 +00:00
|
|
|
selectionMask = (selectionMask & ~(1 << bit)) | (checked << bit);
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
activated(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Kirigami.Icon {
|
|
|
|
source: model.decoration
|
|
|
|
Layout.preferredHeight: Kirigami.Units.iconSizes.small
|
|
|
|
Layout.preferredWidth: Kirigami.Units.iconSizes.small
|
|
|
|
}
|
|
|
|
QQC2.Label {
|
|
|
|
text: model.display
|
|
|
|
color: highlighted ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
|
|
|
|
Layout.fillWidth: true
|
|
|
|
horizontalAlignment: Text.AlignLeft
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: contentItem
|
|
|
|
enabled: multipleChoice
|
|
|
|
onClicked: {
|
|
|
|
itemSelection.toggle();
|
|
|
|
itemSelection.toggled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QQC2.ToolTip {
|
|
|
|
text: model.tooltip
|
2020-05-15 09:00:09 +00:00
|
|
|
visible: hovered && (model.tooltip.length > 0)
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
//FIXME: work around bug https://bugs.kde.org/show_bug.cgi?id=403153
|
|
|
|
optionsCombo.popup.width = Math.max(implicitWidth, optionsCombo.width, optionsCombo.popup.width);
|
|
|
|
}
|
|
|
|
|
|
|
|
onActiveFocusChanged: {
|
|
|
|
if (!activeFocus) {
|
|
|
|
popup.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|