Changeset View
Changeset View
Standalone View
Standalone View
kcms/keyboard/tastenbrett/doodad.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright 2019 Harald Sitter <sitter@kde.org> | ||||
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 DOODAD_H | ||||
22 | #define DOODAD_H | ||||
23 | | ||||
24 | #include <QColor> | ||||
25 | | ||||
26 | #include "xkbobject.h" | ||||
27 | | ||||
28 | class Shape; | ||||
29 | | ||||
30 | class Doodad : public XkbObject | ||||
31 | { | ||||
32 | Q_OBJECT | ||||
33 | | ||||
34 | #define D_P(type, name) \ | ||||
35 | private: \ | ||||
36 | Q_PROPERTY(type name READ auto_prop_##name CONSTANT) \ | ||||
37 | public: \ | ||||
38 | type auto_prop_##name () const { return doodad->any. name ; } | ||||
39 | | ||||
40 | D_P(unsigned char, priority) | ||||
41 | | ||||
42 | static Doodad *factorize(XkbDoodadPtr doodad, XkbDescPtr xkb, QObject *parent); | ||||
43 | | ||||
44 | XkbDoodadPtr doodad = nullptr; | ||||
45 | | ||||
46 | protected: | ||||
47 | Doodad(XkbDoodadPtr doodad_, XkbDescPtr xkb_, QObject *parent = nullptr); | ||||
48 | }; | ||||
49 | | ||||
50 | class ShapeDoodad : public Doodad | ||||
51 | { | ||||
52 | Q_OBJECT | ||||
53 | | ||||
54 | #define SD_P(type, name) \ | ||||
55 | private: \ | ||||
56 | Q_PROPERTY(type name READ auto_prop_##name CONSTANT) \ | ||||
57 | public: \ | ||||
58 | type auto_prop_##name () const { return doodad->shape. name ; } | ||||
59 | | ||||
60 | SD_P(short, top) | ||||
61 | SD_P(short, left) | ||||
62 | SD_P(short, angle) | ||||
63 | | ||||
64 | Q_PROPERTY(Shape *shape MEMBER shape CONSTANT) | ||||
65 | Q_PROPERTY(QColor color MEMBER color CONSTANT) | ||||
66 | // Whether this shape is an outline only. If it is not it's solid/filled. | ||||
67 | Q_PROPERTY(bool outlineOnly MEMBER outlineOnly CONSTANT) | ||||
68 | | ||||
69 | public: | ||||
70 | ShapeDoodad(XkbDoodadPtr doodad_, XkbDescPtr xkb_, QObject *parent = nullptr); | ||||
71 | | ||||
72 | Shape *shape = nullptr; | ||||
73 | QColor color; | ||||
74 | bool outlineOnly = false; | ||||
75 | }; | ||||
76 | | ||||
77 | class TextDoodad : public Doodad | ||||
78 | { | ||||
79 | Q_OBJECT | ||||
80 | | ||||
81 | #define TD_P(type, name) \ | ||||
82 | private: \ | ||||
83 | Q_PROPERTY(type name READ auto_prop_##name CONSTANT) \ | ||||
84 | public: \ | ||||
85 | type auto_prop_##name () const { return doodad->text. name ; } | ||||
86 | | ||||
87 | TD_P(short, top) | ||||
88 | TD_P(short, left) | ||||
89 | TD_P(short, angle) | ||||
90 | TD_P(short, width) | ||||
91 | TD_P(short, height) | ||||
92 | TD_P(QString, text) | ||||
93 | TD_P(QString, font) | ||||
94 | public: | ||||
95 | TextDoodad(XkbDoodadPtr doodad_, XkbDescPtr xkb_, QObject *parent = nullptr); | ||||
96 | | ||||
97 | Shape *shape = nullptr; | ||||
98 | }; | ||||
99 | | ||||
100 | // NB: This is technically kind of like a shape doodad, but in reality | ||||
101 | // only top/left/angle are actually equal across doodad.indicator. and doodad.shape. | ||||
102 | // As such there is no benefit in modelling the classes like there is inheritance | ||||
103 | // because there really isn't. The actual shape definition is abstracted by | ||||
104 | // Shape objects in either case. | ||||
105 | // On the GUI side this can still be rendered like a shape, since it has a Shape*, | ||||
106 | // it's just not specifically a shape doodad. | ||||
107 | class IndicatorDoodad : public Doodad | ||||
108 | { | ||||
109 | Q_OBJECT | ||||
110 | | ||||
111 | #define ID_P(type, name) \ | ||||
112 | private: \ | ||||
113 | Q_PROPERTY(type name READ auto_prop_##name CONSTANT) \ | ||||
114 | public: \ | ||||
115 | type auto_prop_##name () const { return doodad->indicator. name ; } | ||||
116 | | ||||
117 | ID_P(short, top) | ||||
118 | ID_P(short, left) | ||||
119 | ID_P(short, angle) | ||||
120 | | ||||
121 | Q_PROPERTY(Shape *shape MEMBER shape CONSTANT) | ||||
122 | Q_PROPERTY(bool on MEMBER on NOTIFY onChanged) | ||||
123 | public: | ||||
124 | IndicatorDoodad(XkbDoodadPtr doodad_, XkbDescPtr xkb_, QObject *parent = nullptr); | ||||
125 | | ||||
126 | Shape *shape = nullptr; | ||||
127 | bool on = false; | ||||
128 | | ||||
129 | signals: | ||||
130 | void onChanged(); | ||||
131 | | ||||
132 | private slots: | ||||
133 | void refreshState(); | ||||
134 | }; | ||||
135 | | ||||
136 | class LogoDoodad : public ShapeDoodad | ||||
137 | { | ||||
138 | Q_OBJECT | ||||
139 | | ||||
140 | #define LD_P(type, name) \ | ||||
141 | private: \ | ||||
142 | Q_PROPERTY(type name READ auto_prop_##name CONSTANT) \ | ||||
143 | public: \ | ||||
144 | type auto_prop_##name () const { return doodad->logo. name ; } | ||||
145 | | ||||
146 | LD_P(short, top) | ||||
147 | LD_P(short, left) | ||||
148 | LD_P(short, angle) | ||||
149 | LD_P(QString, logo_name) | ||||
150 | public: | ||||
151 | LogoDoodad(XkbDoodadPtr doodad_, XkbDescPtr xkb_, QObject *parent = nullptr); | ||||
152 | | ||||
153 | Shape *shape = nullptr; | ||||
154 | }; | ||||
155 | | ||||
156 | #endif // DOODAD_H |