MauiKit Terminal

customcolorscheme.cpp
1#include "customcolorscheme.h"
2#include "ColorScheme.h"
3#include <QDebug>
4#include <QCoreApplication>
5#include <QTimer>
6
7CustomColorScheme::CustomColorScheme(QObject *parent) : QObject(parent)
8 ,m_scheme(new Konsole::ColorScheme(this))
9 ,m_timer(new QTimer(this))
10{
11 m_timer->setInterval(100);
12 m_timer->setSingleShot(true);
13
14 connect(this, &CustomColorScheme::descriptionChanged, [this](QString description)
15 {
16 m_scheme->setDescription(description);
17 });
18 connect(this, &CustomColorScheme::backgroundColorChanged, [this](QColor )
19 {
20 m_timer->start();
21 });
22
23 connect(this, &CustomColorScheme::foregroundColorChanged, [this](QColor )
24 {
25 m_timer->start();
26 });
27
28 connect(this, &CustomColorScheme::color2Changed, [this](QColor )
29 {
30 m_timer->start();
31 });
32
33 connect(this, &CustomColorScheme::color3Changed, [this](QColor )
34 {
35 m_timer->start();
36 });
37
38 connect(this, &CustomColorScheme::color4Changed, [this](QColor )
39 {
40 m_timer->start();
41 });
42
43 connect(this, &CustomColorScheme::color5Changed, [this](QColor )
44 {
45 m_timer->start();
46 });
47
48 connect(this, &CustomColorScheme::color6Changed, [this](QColor )
49 {
50 m_timer->start();
51 });
52
53 connect(this, &CustomColorScheme::color7Changed, [this](QColor )
54 {
55 m_timer->start();
56 });
57
58 connect(this, &CustomColorScheme::color8Changed, [this](QColor )
59 {
60 m_timer->start();
61 });
62
63 connect(this, &CustomColorScheme::color9Changed, [this](QColor )
64 {
65 m_timer->start();
66 });
67
68 connect(m_timer, &QTimer::timeout, [this]()
69 {
70 save();
71 });
72}
73
74void CustomColorScheme::classBegin()
75{
76}
77
78void CustomColorScheme::componentComplete()
79{
80 save();
81}
82
83QString CustomColorScheme::name() const
84{
85 return m_name;
86}
87
88QString CustomColorScheme::description() const
89{
90 return m_description;
91}
92
93QColor CustomColorScheme::backgroundColor() const
94{
95 return m_backgroundColor;
96}
97
98QColor CustomColorScheme::foregroundColor() const
99{
100 return m_foregroundColor;
101}
102
103
104QColor CustomColorScheme::color2() const
105{
106 return m_color2;
107}
108
109QColor CustomColorScheme::color3() const
110{
111 return m_color3;
112}
113
114QColor CustomColorScheme::color4() const
115{
116 return m_color4;
117}
118
119QColor CustomColorScheme::color5() const
120{
121 return m_color5;
122}
123
124QColor CustomColorScheme::color6() const
125{
126 return m_color6;
127}
128
129QColor CustomColorScheme::color7() const
130{
131 return m_color7;
132}
133
134QColor CustomColorScheme::color8() const
135{
136 return m_color8;
137}
138
139QColor CustomColorScheme::color9() const
140{
141 return m_color9;
142}
143
144const Konsole::ColorScheme *CustomColorScheme::getScheme()
145{
146 return m_scheme;
147}
148
149void CustomColorScheme::setDescription(QString description)
150{
151 if (m_description == description)
152 return;
153
154 m_description = description;
155 Q_EMIT descriptionChanged(m_description);
156}
157
158void CustomColorScheme::setBackgroundColor(QColor backgroundColor)
159{
160 if (m_backgroundColor == backgroundColor)
161 return;
162
163 m_backgroundColor = backgroundColor;
164 Q_EMIT backgroundColorChanged(m_backgroundColor);
165}
166
167void CustomColorScheme::setForegroundColor(QColor foregroundColor)
168{
169 if (m_foregroundColor == foregroundColor)
170 return;
171
172 m_foregroundColor = foregroundColor;
173 Q_EMIT foregroundColorChanged(m_foregroundColor);
174}
175
176void CustomColorScheme::setColor2(QColor color2)
177{
178 if (m_color2 == color2)
179 return;
180
181 m_color2 = color2;
182 Q_EMIT color2Changed(m_color2);
183}
184
185void CustomColorScheme::setColor3(QColor color3)
186{
187 if (m_color3 == color3)
188 return;
189
190 m_color3 = color3;
191 Q_EMIT color3Changed(m_color3);
192}
193
194void CustomColorScheme::setColor4(QColor color4)
195{
196 if (m_color4 == color4)
197 return;
198
199 m_color4 = color4;
200 Q_EMIT color4Changed(m_color4);
201}
202
203void CustomColorScheme::setColor5(QColor color5)
204{
205 if (m_color5 == color5)
206 return;
207
208 m_color5 = color5;
209 Q_EMIT color5Changed(m_color5);
210}
211
212void CustomColorScheme::setColor6(QColor color6)
213{
214 if (m_color6 == color6)
215 return;
216
217 m_color6 = color6;
218 Q_EMIT color6Changed(m_color6);
219}
220
221void CustomColorScheme::setColor7(QColor color7)
222{
223 if (m_color7 == color7)
224 return;
225
226 m_color7 = color7;
227 Q_EMIT color7Changed(m_color7);
228}
229
230void CustomColorScheme::setColor8(QColor color8)
231{
232 if (m_color8 == color8)
233 return;
234
235 m_color8 = color8;
236 Q_EMIT color8Changed(m_color8);
237}
238
239void CustomColorScheme::setColor9(QColor color9)
240{
241 if (m_color9 == color9)
242 return;
243
244 m_color9 = color9;
245 Q_EMIT color9Changed(m_color9);
246}
247
248static bool isLight(const QColor &color)
249{
250 auto luma = [](const QColor &color) {
251 return (0.299 * color.red() + 0.587 * color.green() + 0.114 * color.blue()) / 255;
252 };
253
254 return luma(color) > 0.5 ? true : false;
255}
256
257void CustomColorScheme::save()
258{
259 qDebug() << "Changing color in custom intance";
260
261 const auto light = isLight(m_backgroundColor);
262
263 m_scheme->setColor(0, m_foregroundColor);
264 m_scheme->setColor(1, m_backgroundColor);
265 m_scheme->setColor(2, m_color2);
266 m_scheme->setColor(3, m_color3);
267 m_scheme->setColor(4, m_color4);
268 m_scheme->setColor(5, m_color5);
269 m_scheme->setColor(6, m_color6);
270 m_scheme->setColor(7, m_color7);
271 m_scheme->setColor(8, m_color8);
272 m_scheme->setColor(9, m_color9);
273
274 m_scheme->setColor(10, light ? QColor(m_foregroundColor).darker(120) : QColor(m_foregroundColor).lighter(120));
275 m_scheme->setColor(11, light ? QColor(m_backgroundColor).darker(120) : QColor(m_foregroundColor).lighter(120));
276
277 m_scheme->setColor(12, light ? QColor(m_color2).darker(120) : QColor(m_color2).lighter(120));
278 m_scheme->setColor(13, light ? QColor(m_color3).darker(120) : QColor(m_color3).lighter(120));
279 m_scheme->setColor(14, light ? QColor(m_color4).darker(120) : QColor(m_color4).lighter(120));
280 m_scheme->setColor(15, light ? QColor(m_color5).darker(120) : QColor(m_color5).lighter(120));
281 m_scheme->setColor(16, light ? QColor(m_color6).darker(120) : QColor(m_color6).lighter(120));
282 m_scheme->setColor(17, light ? QColor(m_color7).darker(120) : QColor(m_color7).lighter(120));
283 m_scheme->setColor(18, light ? QColor(m_color8).darker(120) : QColor(m_color8).lighter(120));
284 m_scheme->setColor(19, light ? QColor(m_color9).darker(120) : QColor(m_color9).lighter(120));
285}
286
287
Represents a color scheme for a terminal display.
Definition ColorScheme.h:56
KGUIADDONS_EXPORT qreal luma(const QColor &)
const QList< QKeySequence > & save()
int blue() const const
int green() const const
int red() const const
Q_EMITQ_EMIT
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void timeout()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.