Commit 66ee8985 authored by Ismael Asensio's avatar Ismael Asensio
Browse files

kcm/kwinrules: Allow to select multiple activities

This commit addresses the UI part

BUG: 430499
parent fc1553e8
......@@ -69,15 +69,6 @@ int OptionsModel::indexOf(QVariant value) const
return -1;
}
QString OptionsModel::textOfValue(QVariant value) const
{
int index = indexOf(value);
if (index < 0 || index >= m_data.count()) {
return QString();
}
return m_data.at(index).text;
}
QVariant OptionsModel::value() const
{
if (m_data.isEmpty()) {
......
......@@ -56,7 +56,7 @@ public:
void updateModelData(const QList<Data> &data);
Q_INVOKABLE int indexOf(QVariant value) const;
Q_INVOKABLE QString textOfValue(QVariant value) const;
int selectedIndex() const;
signals:
......
......@@ -18,6 +18,9 @@ QQC2.ComboBox {
valueRole: "value"
property bool multipleChoice: false
// If `useFlagsValue` is true, `selectionMask` will be composed using the item values.
// Otherwise, it will use the item indexes.
property bool useFlagsValue: false
property int selectionMask: 0
currentIndex: multipleChoice ? -1 : model.selectedIndex
......@@ -31,8 +34,9 @@ QQC2.ComboBox {
case 0:
return i18n("None selected");
case 1:
var selectedValue = selectionMask.toString(2).length - 1;
return model.textOfValue(selectedValue);
let selectedBit = selectionMask.toString(2).length - 1;
let selectedIndex = (useFlagsValue) ? model.indexOf(selectedBit) : selectedBit
return model.data(model.index(selectedIndex, 0), Qt.DisplayRole);
case count:
return i18n("All selected");
}
......@@ -47,9 +51,10 @@ QQC2.ComboBox {
QQC2.CheckBox {
id: itemSelection
visible: multipleChoice
checked: (selectionMask & (1 << value))
readonly property int bit: (useFlagsValue) ? value : index
checked: (selectionMask & (1 << bit))
onToggled: {
selectionMask = (selectionMask & ~(1 << value)) | (checked << value);
selectionMask = (selectionMask & ~(1 << bit)) | (checked << bit);
activated(index);
}
}
......
......@@ -34,6 +34,7 @@ Loader {
case RuleItem.Point: return coordinateEditor
case RuleItem.Size: return coordinateEditor
case RuleItem.Shortcut: return shortcutEditor
case RuleItem.OptionList: return optionListEditor
default: return emptyEditor
}
}
......@@ -104,6 +105,7 @@ Loader {
flat: true
model: ruleOptions
multipleChoice: true
useFlagsValue: true
// Filter the provided value with the options mask
selectionMask: ruleValue & optionsMask
onActivated: {
......@@ -112,6 +114,33 @@ Loader {
}
}
Component {
id: optionListEditor
OptionsComboBox {
flat: true
model: ruleOptions
multipleChoice: true
selectionMask: {
let mask = 0
for (let i = 0; i < count; i++) {
if (ruleValue.includes(model.data(model.index(i,0), Qt.UserRole))) {
mask += 1 << i
}
}
return mask
}
onActivated: {
let selectionList = []
for (let i = 0; i < count; i++) {
if (selectionMask & (1 << i)) {
selectionList.push(model.data(model.index(i,0), Qt.UserRole))
}
}
valueEditor.valueEdited(selectionList);
}
}
}
Component {
id: percentageEditor
RowLayout {
......
......@@ -140,10 +140,10 @@ QVariant RuleItem::options() const
void RuleItem::setOptionsData(const QList<OptionsModel::Data> &data)
{
if (!m_options) {
if (m_type != Option && m_type != NetTypes) {
if (m_type != Option && m_type != OptionList && m_type != NetTypes) {
return;
}
if (!m_options) {
m_options = new OptionsModel();
}
m_options->updateModelData(data);
......@@ -215,6 +215,8 @@ QVariant RuleItem::typedValue(const QVariant &value) const
return value.toString().trimmed();
case Shortcut:
return value.toString();
case OptionList:
return value.toStringList();
}
return value;
}
......
......@@ -31,7 +31,8 @@ public:
Percentage,
Point,
Size,
Shortcut
Shortcut,
OptionList,
};
Q_ENUM(Type)
......
......@@ -448,8 +448,8 @@ void RulesModel::populateRuleList()
m_activities = new KActivities::Consumer(this);
auto activity = addRule(new RuleItem(QLatin1String("activity"),
RulePolicy::SetRule, RuleItem::Option,
i18n("Activity"), i18n("Size & Position"),
RulePolicy::SetRule, RuleItem::OptionList,
i18n("Activities"), i18n("Size & Position"),
QIcon::fromTheme("activities")));
activity->setOptionsData(activitiesModelData());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment