File indexing completed on 2024-11-10 04:56:50
0001 /* 0002 SPDX-FileCopyrightText: 2020 Ismael Asensio <isma.af@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #pragma once 0008 0009 #include "optionsmodel.h" 0010 0011 #include <QFlag> 0012 #include <QIcon> 0013 0014 namespace KWin 0015 { 0016 0017 class RuleItem : public QObject 0018 { 0019 Q_OBJECT 0020 0021 public: 0022 enum Type { 0023 Undefined, 0024 Boolean, 0025 String, 0026 Integer, 0027 Option, 0028 NetTypes, 0029 Percentage, 0030 Point, 0031 Size, 0032 Shortcut, 0033 OptionList, 0034 }; 0035 Q_ENUM(Type) 0036 0037 enum Flags { 0038 NoFlags = 0, 0039 AlwaysEnabled = 1u << 0, 0040 StartEnabled = 1u << 1, 0041 AffectsWarning = 1u << 2, 0042 AffectsDescription = 1u << 3, 0043 SuggestionOnly = 1u << 4, 0044 AllFlags = 0b11111 0045 }; 0046 0047 public: 0048 RuleItem(){}; 0049 RuleItem(const QString &key, 0050 const RulePolicy::Type policyType, 0051 const Type type, 0052 const QString &name, 0053 const QString §ion, 0054 const QIcon &icon = QIcon::fromTheme("window"), 0055 const QString &description = QString("")); 0056 0057 QString key() const; 0058 QString name() const; 0059 QString section() const; 0060 QIcon icon() const; 0061 QString iconName() const; 0062 QString description() const; 0063 0064 bool isEnabled() const; 0065 void setEnabled(bool enabled); 0066 0067 bool hasFlag(RuleItem::Flags flag) const; 0068 void setFlag(RuleItem::Flags flag, bool active = true); 0069 0070 Type type() const; 0071 QVariant value() const; 0072 void setValue(QVariant value); 0073 QVariant suggestedValue() const; 0074 void setSuggestedValue(QVariant value); 0075 0076 QVariant options() const; 0077 void setOptionsData(const QList<OptionsModel::Data> &data); 0078 0079 RulePolicy::Type policyType() const; 0080 int policy() const; // int belongs to anonymous enum in Rules:: 0081 void setPolicy(int policy); // int belongs to anonymous enum in Rules:: 0082 QVariant policyModel() const; 0083 QString policyKey() const; 0084 0085 void reset(); 0086 0087 private: 0088 QVariant typedValue(const QVariant &value) const; 0089 0090 private: 0091 QString m_key; 0092 RuleItem::Type m_type; 0093 QString m_name; 0094 QString m_section; 0095 QIcon m_icon; 0096 QString m_description; 0097 QFlags<Flags> m_flags; 0098 0099 bool m_enabled; 0100 0101 QVariant m_value; 0102 QVariant m_suggestedValue; 0103 0104 std::unique_ptr<RulePolicy> m_policy; 0105 std::unique_ptr<OptionsModel> m_options; 0106 }; 0107 0108 } // namespace