Changeset View
Changeset View
Standalone View
Standalone View
kcms/keyboard/tastenbrett/doodad.cpp
- 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 | #include "doodad.h" | ||||
22 | | ||||
23 | #include <QKeyEvent> | ||||
24 | #include <QX11Info> | ||||
25 | | ||||
26 | #include "application.h" | ||||
27 | #include "shape.h" | ||||
28 | | ||||
29 | Doodad *Doodad::factorize(XkbDoodadPtr doodad, XkbDescPtr xkb, QObject *parent) | ||||
30 | { | ||||
31 | switch (doodad->any.type) { | ||||
32 | case XkbOutlineDoodad: | ||||
33 | case XkbSolidDoodad: | ||||
34 | return new ShapeDoodad(doodad, xkb, parent); | ||||
35 | case XkbTextDoodad: | ||||
36 | return new TextDoodad(doodad, xkb, parent); | ||||
37 | case XkbIndicatorDoodad: | ||||
38 | return new IndicatorDoodad(doodad, xkb, parent); | ||||
39 | case XkbLogoDoodad: | ||||
40 | return new LogoDoodad(doodad, xkb, parent); | ||||
41 | } | ||||
42 | | ||||
43 | Q_UNREACHABLE(); | ||||
44 | return nullptr; | ||||
45 | } | ||||
46 | | ||||
47 | Doodad::Doodad(XkbDoodadPtr doodad_, XkbDescPtr xkb_, QObject *parent) | ||||
48 | : XkbObject(xkb_, parent) | ||||
49 | , doodad(doodad_) | ||||
50 | { | ||||
51 | } | ||||
52 | | ||||
53 | ShapeDoodad::ShapeDoodad(XkbDoodadPtr doodad_, XkbDescPtr xkb_, QObject *parent) | ||||
54 | : Doodad(doodad_, xkb_, parent) | ||||
55 | , shape(new Shape(xkb->geom->shapes + doodad_->shape.shape_ndx, xkb, this)) | ||||
56 | , outlineOnly(doodad->any.type == XkbOutlineDoodad) | ||||
57 | { | ||||
58 | } | ||||
59 | | ||||
60 | TextDoodad::TextDoodad(XkbDoodadPtr doodad_, XkbDescPtr xkb_, QObject *parent) | ||||
61 | : Doodad(doodad_, xkb_, parent) | ||||
62 | { | ||||
63 | } | ||||
64 | | ||||
65 | IndicatorDoodad::IndicatorDoodad(XkbDoodadPtr doodad_, XkbDescPtr xkb_, QObject *parent) | ||||
66 | : Doodad(doodad_, xkb_, parent) | ||||
67 | , shape(new Shape(xkb->geom->shapes + doodad_->indicator.shape_ndx, xkb, this)) | ||||
68 | { | ||||
69 | connect(Application::instance(), &Application::keyEvent, | ||||
70 | this, &IndicatorDoodad::refreshState); | ||||
71 | refreshState(); | ||||
72 | } | ||||
73 | | ||||
74 | void IndicatorDoodad::refreshState() | ||||
75 | { | ||||
76 | int onInt = False; | ||||
77 | if (!XkbGetNamedIndicator(QX11Info::display(), | ||||
78 | doodad->indicator.name, | ||||
79 | nullptr, | ||||
80 | &onInt, | ||||
81 | nullptr, | ||||
82 | nullptr)) { | ||||
83 | on = false; | ||||
84 | } else { | ||||
85 | on = onInt == True ? true : false; | ||||
86 | } | ||||
87 | emit onChanged(); | ||||
88 | } | ||||
89 | | ||||
90 | LogoDoodad::LogoDoodad(XkbDoodadPtr doodad_, XkbDescPtr xkb_, QObject *parent) | ||||
91 | : ShapeDoodad(doodad_, xkb_, parent) | ||||
92 | { | ||||
93 | } |