Merge branch 'Plasma/5.19'
This commit is contained in:
commit
898bd496d8
6 changed files with 40 additions and 21 deletions
|
@ -225,7 +225,7 @@ ScrollViewKCM {
|
|||
return i18nc("Size (width, height)", "(%1, %2)", value.width, value.height);
|
||||
case RuleItem.Option:
|
||||
return options.textOfValue(value);
|
||||
case RuleItem.FlagsOption:
|
||||
case RuleItem.NetTypes:
|
||||
var selectedValue = value.toString(2).length - 1;
|
||||
return options.textOfValue(selectedValue);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ Loader {
|
|||
case RuleItem.String: return stringEditor
|
||||
case RuleItem.Integer: return integerEditor
|
||||
case RuleItem.Option: return optionEditor
|
||||
case RuleItem.FlagsOption: return flagsEditor
|
||||
case RuleItem.NetTypes: return netTypesEditor
|
||||
case RuleItem.Percentage: return percentageEditor
|
||||
case RuleItem.Point: return coordinateEditor
|
||||
case RuleItem.Size: return coordinateEditor
|
||||
|
@ -113,12 +113,13 @@ Loader {
|
|||
}
|
||||
|
||||
Component {
|
||||
id: flagsEditor
|
||||
id: netTypesEditor
|
||||
OptionsComboBox {
|
||||
flat: true
|
||||
model: ruleOptions
|
||||
multipleChoice: true
|
||||
selectionMask: ruleValue
|
||||
// Filter the provided value with the options mask
|
||||
selectionMask: ruleValue & optionsMask
|
||||
onActivated: {
|
||||
valueEditor.valueEdited(selectionMask);
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ RuleItem::RuleItem(const QString &key,
|
|||
, m_enabled(false)
|
||||
, m_policy(new RulePolicy(policyType))
|
||||
, m_options(nullptr)
|
||||
, m_optionsMask(0U - 1)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
@ -54,7 +55,7 @@ RuleItem::~RuleItem()
|
|||
void RuleItem::reset()
|
||||
{
|
||||
m_enabled = hasFlag(AlwaysEnabled) | hasFlag(StartEnabled);
|
||||
m_value = typedValue(QVariant(), m_type);
|
||||
m_value = typedValue(QVariant());
|
||||
m_suggestedValue = QVariant();
|
||||
m_policy->resetValue();
|
||||
if (m_options) {
|
||||
|
@ -130,7 +131,7 @@ void RuleItem::setValue(QVariant value)
|
|||
if (m_options && m_type == Option) {
|
||||
m_options->setValue(value);
|
||||
}
|
||||
m_value = typedValue(value, m_type);
|
||||
m_value = typedValue(value);
|
||||
}
|
||||
|
||||
QVariant RuleItem::suggestedValue() const
|
||||
|
@ -143,7 +144,7 @@ void RuleItem::setSuggestedValue(QVariant value, bool forceValue)
|
|||
if (forceValue) {
|
||||
setValue(value);
|
||||
}
|
||||
m_suggestedValue = value.isNull() ? QVariant() : typedValue(value, m_type);
|
||||
m_suggestedValue = value.isNull() ? QVariant() : typedValue(value);
|
||||
}
|
||||
|
||||
QVariant RuleItem::options() const
|
||||
|
@ -157,13 +158,25 @@ QVariant RuleItem::options() const
|
|||
void RuleItem::setOptionsData(const QList<OptionsModel::Data> &data)
|
||||
{
|
||||
if (!m_options) {
|
||||
if (m_type != Option && m_type != FlagsOption) {
|
||||
if (m_type != Option && m_type != NetTypes) {
|
||||
return;
|
||||
}
|
||||
m_options = new OptionsModel();
|
||||
}
|
||||
m_options->updateModelData(data);
|
||||
m_options->setValue(m_value);
|
||||
|
||||
if (m_type == NetTypes) {
|
||||
m_optionsMask = 0;
|
||||
for (const OptionsModel::Data &dataItem : data) {
|
||||
m_optionsMask += 1 << dataItem.value.toUInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint RuleItem::optionsMask() const
|
||||
{
|
||||
return m_optionsMask;
|
||||
}
|
||||
|
||||
int RuleItem::policy() const
|
||||
|
@ -191,9 +204,9 @@ QString RuleItem::policyKey() const
|
|||
return m_policy->policyKey(m_key);
|
||||
}
|
||||
|
||||
QVariant RuleItem::typedValue(const QVariant &value, const RuleItem::Type type)
|
||||
QVariant RuleItem::typedValue(const QVariant &value) const
|
||||
{
|
||||
switch (type) {
|
||||
switch (type()) {
|
||||
case Undefined:
|
||||
case Option:
|
||||
return value;
|
||||
|
@ -202,12 +215,13 @@ QVariant RuleItem::typedValue(const QVariant &value, const RuleItem::Type type)
|
|||
case Integer:
|
||||
case Percentage:
|
||||
return value.toInt();
|
||||
case FlagsOption:
|
||||
// HACK: Currently, the only user of this is "types" property
|
||||
if (value.toInt() == -1) { //NET:AllTypesMask
|
||||
return 0x3FF - 0x040; //All possible flags minus NET::Override (deprecated)
|
||||
case NetTypes: {
|
||||
const uint typesMask = value.toUInt() & optionsMask(); // filter by the allowed mask in the model
|
||||
if (typesMask == 0 || typesMask == optionsMask()) { // if no types or all of them are selected
|
||||
return 0U - 1; // return an all active mask (NET:AllTypesMask)
|
||||
}
|
||||
return typesMask;
|
||||
}
|
||||
return value.toInt();
|
||||
case Point:
|
||||
return value.toPoint();
|
||||
case Size:
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
String,
|
||||
Integer,
|
||||
Option,
|
||||
FlagsOption,
|
||||
NetTypes,
|
||||
Percentage,
|
||||
Point,
|
||||
Size,
|
||||
|
@ -92,6 +92,7 @@ public:
|
|||
|
||||
QVariant options() const;
|
||||
void setOptionsData(const QList<OptionsModel::Data> &data);
|
||||
uint optionsMask() const;
|
||||
|
||||
RulePolicy::Type policyType() const;
|
||||
int policy() const; // int belongs to anonymous enum in Rules::
|
||||
|
@ -99,12 +100,10 @@ public:
|
|||
QVariant policyModel() const;
|
||||
QString policyKey() const;
|
||||
|
||||
|
||||
|
||||
void reset();
|
||||
|
||||
private:
|
||||
static QVariant typedValue(const QVariant &value, const Type type);
|
||||
QVariant typedValue(const QVariant &value) const;
|
||||
|
||||
private:
|
||||
QString m_key;
|
||||
|
@ -122,6 +121,7 @@ private:
|
|||
|
||||
RulePolicy *m_policy;
|
||||
OptionsModel *m_options;
|
||||
uint m_optionsMask;
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
|
|
@ -71,6 +71,7 @@ QHash< int, QByteArray > RulesModel::roleNames() const
|
|||
{PolicyRole, QByteArrayLiteral("policy")},
|
||||
{PolicyModelRole, QByteArrayLiteral("policyModel")},
|
||||
{OptionsModelRole, QByteArrayLiteral("options")},
|
||||
{OptionsMaskRole, QByteArrayLiteral("optionsMask")},
|
||||
{SuggestedValueRole, QByteArrayLiteral("suggested")},
|
||||
};
|
||||
}
|
||||
|
@ -118,6 +119,8 @@ QVariant RulesModel::data(const QModelIndex &index, int role) const
|
|||
return rule->policyModel();
|
||||
case OptionsModelRole:
|
||||
return rule->options();
|
||||
case OptionsMaskRole:
|
||||
return rule->optionsMask();
|
||||
case SuggestedValueRole:
|
||||
return rule->suggestedValue();
|
||||
}
|
||||
|
@ -402,7 +405,7 @@ void RulesModel::populateRuleList()
|
|||
wmclasshelper->setFlag(RuleItem::SuggestionOnly);
|
||||
|
||||
auto types = addRule(new RuleItem(QLatin1String("types"),
|
||||
RulePolicy::NoPolicy, RuleItem::FlagsOption,
|
||||
RulePolicy::NoPolicy, RuleItem::NetTypes,
|
||||
i18n("Window types"), i18n("Window matching"),
|
||||
QIcon::fromTheme("window-duplicate")));
|
||||
types->setOptionsData(windowTypesModelData());
|
||||
|
@ -689,7 +692,7 @@ void RulesModel::setWindowProperties(const QVariantMap &info, bool forceValue)
|
|||
if (window_type == NET::Unknown) {
|
||||
window_type = NET::Normal;
|
||||
}
|
||||
m_rules["types"]->setSuggestedValue(1 << window_type, forceValue);
|
||||
m_rules["types"]->setSuggestedValue(1 << window_type);
|
||||
|
||||
const QString wmsimpleclass = info.value("resourceClass").toString();
|
||||
const QString wmcompleteclass = QStringLiteral("%1 %2").arg(info.value("resourceName").toString(),
|
||||
|
|
|
@ -60,6 +60,7 @@ public:
|
|||
PolicyRole,
|
||||
PolicyModelRole,
|
||||
OptionsModelRole,
|
||||
OptionsMaskRole,
|
||||
SuggestedValueRole
|
||||
};
|
||||
Q_ENUM(RulesRole)
|
||||
|
|
Loading…
Reference in a new issue