Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/kwinrules/optionsmodel.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (c) 2020 Ismael Asensio <isma.af@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #ifndef KWIN_OPTIONS_MODEL_H | ||||
22 | #define KWIN_OPTIONS_MODEL_H | ||||
23 | | ||||
24 | #include <rules.h> | ||||
25 | | ||||
26 | #include <QAbstractListModel> | ||||
27 | #include <QIcon> | ||||
28 | #include <QVariant> | ||||
29 | | ||||
30 | | ||||
31 | namespace KWin { | ||||
32 | | ||||
33 | class OptionsModel : public QAbstractListModel | ||||
34 | { | ||||
35 | Q_OBJECT | ||||
36 | Q_PROPERTY(int selectedIndex READ selectedIndex NOTIFY selectedIndexChanged) | ||||
37 | | ||||
38 | public: | ||||
39 | struct Data { | ||||
40 | Data(const QVariant &value, const QString &text, const QIcon &icon = {}, const QString &description = {}) | ||||
41 | : value(value) | ||||
42 | , text(text) | ||||
43 | , icon(icon) | ||||
44 | , description(description) | ||||
45 | {} | ||||
46 | Data(const QVariant &value, const QString &text, const QString &description) | ||||
47 | : value(value) | ||||
48 | , text(text) | ||||
49 | , description(description) | ||||
50 | {} | ||||
51 | | ||||
52 | QVariant value; | ||||
53 | QString text; | ||||
54 | QIcon icon; | ||||
55 | QString description; | ||||
56 | }; | ||||
57 | | ||||
58 | public: | ||||
59 | OptionsModel() : QAbstractListModel(), m_data(), m_index(0) {}; | ||||
60 | OptionsModel(const QList<Data> &data) : QAbstractListModel(), m_data(data), m_index(0) {}; | ||||
61 | | ||||
62 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||||
63 | QHash<int, QByteArray> roleNames() const override; | ||||
64 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||||
65 | | ||||
66 | QVariant value() const; | ||||
67 | void setValue(QVariant value); | ||||
68 | void resetValue(); | ||||
69 | | ||||
70 | void updateModelData(const QList<Data> &data); | ||||
71 | | ||||
72 | int selectedIndex() const; | ||||
73 | | ||||
74 | signals: | ||||
75 | void selectedIndexChanged(int index); | ||||
76 | | ||||
77 | public: | ||||
78 | QList<Data> m_data; | ||||
79 | | ||||
80 | protected: | ||||
81 | int m_index = 0; | ||||
82 | }; | ||||
83 | | ||||
84 | class RulePolicy : public OptionsModel | ||||
85 | { | ||||
86 | public: | ||||
87 | enum Type { | ||||
88 | NoPolicy, | ||||
89 | StringMatch, | ||||
90 | SetRule, | ||||
91 | ForceRule | ||||
92 | }; | ||||
93 | | ||||
94 | public: | ||||
95 | RulePolicy(Type type) | ||||
96 | : OptionsModel(policyOptions(type)) | ||||
97 | , m_type(type) | ||||
98 | {}; | ||||
99 | | ||||
100 | Type type() const; | ||||
101 | int value() const; | ||||
102 | QString policyKey(const QString &key) const; | ||||
103 | | ||||
104 | private: | ||||
105 | static QList<Data> policyOptions(RulePolicy::Type type); | ||||
106 | | ||||
107 | private: | ||||
108 | Type m_type; | ||||
109 | }; | ||||
110 | | ||||
111 | } //namespace | ||||
112 | | ||||
113 | #endif //KWIN_OPTIONS_MODEL_H |