1#include "customcolorscheme.h"
2#include "ColorScheme.h"
4#include <QCoreApplication>
7CustomColorScheme::CustomColorScheme(
QObject *parent) :
QObject(parent)
11 m_timer->setInterval(100);
12 m_timer->setSingleShot(
true);
14 connect(
this, &CustomColorScheme::descriptionChanged, [
this](
QString description)
16 m_scheme->setDescription(description);
18 connect(
this, &CustomColorScheme::backgroundColorChanged, [
this](
QColor )
23 connect(
this, &CustomColorScheme::foregroundColorChanged, [
this](
QColor )
28 connect(
this, &CustomColorScheme::color2Changed, [
this](
QColor )
33 connect(
this, &CustomColorScheme::color3Changed, [
this](
QColor )
38 connect(
this, &CustomColorScheme::color4Changed, [
this](
QColor )
43 connect(
this, &CustomColorScheme::color5Changed, [
this](
QColor )
48 connect(
this, &CustomColorScheme::color6Changed, [
this](
QColor )
53 connect(
this, &CustomColorScheme::color7Changed, [
this](
QColor )
58 connect(
this, &CustomColorScheme::color8Changed, [
this](
QColor )
63 connect(
this, &CustomColorScheme::color9Changed, [
this](
QColor )
74void CustomColorScheme::classBegin()
78void CustomColorScheme::componentComplete()
83QString CustomColorScheme::name()
const
88QString CustomColorScheme::description()
const
93QColor CustomColorScheme::backgroundColor()
const
95 return m_backgroundColor;
98QColor CustomColorScheme::foregroundColor()
const
100 return m_foregroundColor;
104QColor CustomColorScheme::color2()
const
109QColor CustomColorScheme::color3()
const
114QColor CustomColorScheme::color4()
const
119QColor CustomColorScheme::color5()
const
124QColor CustomColorScheme::color6()
const
129QColor CustomColorScheme::color7()
const
134QColor CustomColorScheme::color8()
const
139QColor CustomColorScheme::color9()
const
149void CustomColorScheme::setDescription(
QString description)
151 if (m_description == description)
154 m_description = description;
155 Q_EMIT descriptionChanged(m_description);
158void CustomColorScheme::setBackgroundColor(
QColor backgroundColor)
160 if (m_backgroundColor == backgroundColor)
163 m_backgroundColor = backgroundColor;
164 Q_EMIT backgroundColorChanged(m_backgroundColor);
167void CustomColorScheme::setForegroundColor(
QColor foregroundColor)
169 if (m_foregroundColor == foregroundColor)
172 m_foregroundColor = foregroundColor;
173 Q_EMIT foregroundColorChanged(m_foregroundColor);
176void CustomColorScheme::setColor2(
QColor color2)
178 if (m_color2 == color2)
182 Q_EMIT color2Changed(m_color2);
185void CustomColorScheme::setColor3(
QColor color3)
187 if (m_color3 == color3)
191 Q_EMIT color3Changed(m_color3);
194void CustomColorScheme::setColor4(
QColor color4)
196 if (m_color4 == color4)
200 Q_EMIT color4Changed(m_color4);
203void CustomColorScheme::setColor5(
QColor color5)
205 if (m_color5 == color5)
209 Q_EMIT color5Changed(m_color5);
212void CustomColorScheme::setColor6(
QColor color6)
214 if (m_color6 == color6)
218 Q_EMIT color6Changed(m_color6);
221void CustomColorScheme::setColor7(
QColor color7)
223 if (m_color7 == color7)
227 Q_EMIT color7Changed(m_color7);
230void CustomColorScheme::setColor8(
QColor color8)
232 if (m_color8 == color8)
236 Q_EMIT color8Changed(m_color8);
239void CustomColorScheme::setColor9(
QColor color9)
241 if (m_color9 == color9)
245 Q_EMIT color9Changed(m_color9);
248static bool isLight(
const QColor &color)
251 return (0.299 * color.
red() + 0.587 * color.
green() + 0.114 * color.
blue()) / 255;
254 return luma(color) > 0.5 ? true :
false;
257void CustomColorScheme::save()
259 qDebug() <<
"Changing color in custom intance";
261 const auto light = isLight(m_backgroundColor);
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);
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));
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));
Represents a color scheme for a terminal display.
KGUIADDONS_EXPORT qreal luma(const QColor &)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)