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 | #pragma message "should differentiate outline and solid shapes - outline doesn't get a fill and vice versa" | ||||
35 | return new ShapeDoodad(doodad, xkb, parent); | ||||
36 | case XkbTextDoodad: | ||||
37 | return new TextDoodad(doodad, xkb, parent); | ||||
38 | case XkbIndicatorDoodad: | ||||
39 | return new IndicatorDoodad(doodad, xkb, parent); | ||||
40 | } | ||||
41 | | ||||
42 | #pragma message "logo doodad not supported" | ||||
43 | Q_UNREACHABLE(); | ||||
44 | | ||||
45 | return nullptr; | ||||
46 | } | ||||
47 | | ||||
48 | Doodad::Doodad(XkbDoodadPtr doodad_, XkbDescPtr xkb_, QObject *parent) | ||||
49 | : XkbObject(xkb_, parent) | ||||
50 | , doodad(doodad_) | ||||
51 | { | ||||
52 | } | ||||
53 | | ||||
54 | ShapeDoodad::ShapeDoodad(XkbDoodadPtr doodad_, XkbDescPtr xkb_, QObject *parent) | ||||
55 | : Doodad(doodad_, xkb_, parent) | ||||
56 | , shape(new Shape(xkb->geom->shapes + doodad_->shape.shape_ndx, xkb, this)) | ||||
57 | , color(fromXKBColor(xkb->geom->colors[doodad->shape.color_ndx])) | ||||
58 | { | ||||
59 | } | ||||
60 | | ||||
61 | TextDoodad::TextDoodad(XkbDoodadPtr doodad_, XkbDescPtr xkb_, QObject *parent) | ||||
62 | : Doodad(doodad_, xkb_, parent) | ||||
63 | , color(fromXKBColor(xkb->geom->colors[doodad->text.color_ndx])) | ||||
64 | { | ||||
65 | } | ||||
66 | | ||||
67 | IndicatorDoodad::IndicatorDoodad(XkbDoodadPtr doodad_, XkbDescPtr xkb_, QObject *parent) | ||||
68 | : Doodad(doodad_, xkb_, parent) | ||||
69 | , shape(new Shape(xkb->geom->shapes + doodad_->indicator.shape_ndx, xkb, this)) | ||||
70 | , onColor(fromXKBColor(xkb->geom->colors[doodad->indicator.on_color_ndx])) | ||||
71 | , offColor(fromXKBColor(xkb->geom->colors[doodad->indicator.off_color_ndx])) | ||||
72 | { | ||||
73 | connect(Application::instance(), &Application::keyEvent, | ||||
74 | this, &IndicatorDoodad::refreshState); | ||||
75 | refreshState(); | ||||
76 | } | ||||
77 | | ||||
78 | void IndicatorDoodad::refreshState() | ||||
79 | { | ||||
80 | int onInt = False; | ||||
81 | if (!XkbGetNamedIndicator(QX11Info::display(), | ||||
82 | doodad->indicator.name, | ||||
83 | nullptr, | ||||
84 | &onInt, | ||||
85 | nullptr, | ||||
86 | nullptr)) { | ||||
87 | on = false; | ||||
88 | } else { | ||||
89 | on = onInt == True ? true : false; | ||||
90 | } | ||||
91 | emit onChanged(); | ||||
92 | } |