Changeset View
Changeset View
Standalone View
Standalone View
kcms/keyboard/tastenbrett/key.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 KEY_H | ||||
22 | #define KEY_H | ||||
23 | | ||||
24 | #include "xkbobject.h" | ||||
25 | | ||||
26 | class Shape; | ||||
27 | | ||||
28 | // This is a fairly opinionated model of a key cap. We assume there won't | ||||
29 | // be any more than 4 levels. | ||||
30 | // This isn't necessarily the case since (e.g.) the NEO layout has 6 levels. | ||||
31 | // Since that is super niche and poses some complication as for how to | ||||
32 | // exactly render the levels we'll simply ignore this use case for now. | ||||
33 | // In the end the keyboard model display only needs to act as simple indicator | ||||
34 | // anyway. | ||||
35 | class KeyCap : public QObject | ||||
36 | { | ||||
37 | Q_OBJECT | ||||
38 | Q_PROPERTY(QString topLeft MEMBER topLeft CONSTANT) | ||||
39 | Q_PROPERTY(QString topRight MEMBER topRight CONSTANT) | ||||
40 | Q_PROPERTY(QString bottomLeft MEMBER bottomLeft CONSTANT) | ||||
41 | Q_PROPERTY(QString bottomRight MEMBER bottomRight CONSTANT) | ||||
42 | public: | ||||
43 | enum Level | ||||
44 | { | ||||
45 | TopLeft = 1, | ||||
46 | TopRight = 3, | ||||
47 | BottomLeft = 0, | ||||
48 | BottomRight = 2 | ||||
49 | }; | ||||
50 | Q_ENUM(Level) | ||||
51 | constexpr static int levelCount = 4; | ||||
52 | | ||||
53 | KeyCap(const QString symbols[KeyCap::levelCount], QObject *parent); | ||||
54 | | ||||
55 | QString topLeft; | ||||
56 | QString topRight; | ||||
57 | QString bottomLeft; | ||||
58 | QString bottomRight; | ||||
59 | }; | ||||
60 | | ||||
61 | class Key : public XkbObject | ||||
62 | { | ||||
63 | Q_OBJECT | ||||
64 | #define K_P(type, name) \ | ||||
65 | private: \ | ||||
66 | Q_PROPERTY(type name READ auto_prop_##name CONSTANT) \ | ||||
67 | public: \ | ||||
68 | type auto_prop_##name () const { return key-> name ; } | ||||
69 | | ||||
70 | K_P(short, gap) | ||||
71 | | ||||
72 | Q_PROPERTY(Shape *shape MEMBER shape CONSTANT) | ||||
73 | Q_PROPERTY(KeyCap *cap MEMBER cap CONSTANT) | ||||
74 | Q_PROPERTY(bool pressed MEMBER pressed NOTIFY pressedChanged) | ||||
75 | | ||||
76 | constexpr static uint INVALID_KEYCODE = static_cast<uint>(-1); | ||||
77 | | ||||
78 | public: | ||||
79 | Key(XkbKeyPtr key_, XkbDescPtr xkb_, QObject *parent = nullptr); | ||||
80 | uint nativeScanCodeFromName(const QByteArray &needle); | ||||
81 | KeyCap *resolveCap(); | ||||
82 | | ||||
83 | XkbKeyPtr key = nullptr; | ||||
84 | Shape *shape = nullptr; | ||||
85 | QByteArray name; // Internal name in the geometry. | ||||
86 | quint32 nativeScanCode = INVALID_KEYCODE; | ||||
87 | KeyCap *cap = nullptr; | ||||
88 | bool pressed = false; | ||||
89 | | ||||
90 | signals: | ||||
91 | void pressedChanged(); | ||||
92 | }; | ||||
93 | | ||||
94 | #endif // KEY_H |