Messagelib

colorutil.cpp
1/*
2 * SPDX-FileCopyrightText: 2015 Daniel Vrátil <dvratil@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 *
6 */
7
8#include "colorutil.h"
9
10#include <KColorScheme>
11#include <QApplication>
12
13using namespace MessageCore;
14
15static bool isLightTheme()
16{
17 return qApp->palette().color(QPalette::Window).value() >= 128;
18}
19
20Q_GLOBAL_STATIC(ColorUtil, s_self)
21
22ColorUtil *ColorUtil::self()
23{
24 return s_self;
25}
26
27ColorUtil::ColorUtil()
28{
29 initializeColors();
30}
31
32void ColorUtil::updateColors()
33{
34 initializeColors();
35}
36
37void ColorUtil::initializeColors()
38{
40 mMisspelledDefaultTextColor = scheme.foreground(KColorScheme::NegativeText).color().lighter();
41 auto base = scheme.foreground(KColorScheme::PositiveText).color();
42 if (isLightTheme()) {
43 mQuoteLevel1DefaultTextColor = base.darker(120);
44 mQuoteLevel2DefaultTextColor = base.darker(150);
45 mQuoteLevel3DefaultTextColor = base.darker(200);
46 } else {
47 mQuoteLevel1DefaultTextColor = base.lighter(200);
48 mQuoteLevel2DefaultTextColor = base.lighter(170);
49 mQuoteLevel3DefaultTextColor = base.lighter(140);
50 }
51
52 if (isLightTheme()) {
53 mPgpEncryptedMessageColor = QColor(0x00, 0x80, 0xFF).lighter(180);
54 mPgpEncryptedTextColor = QColor(0x00, 0x80, 0xFF).darker(200);
55 } else {
56 mPgpEncryptedMessageColor = QColor(0x00, 0x80, 0xFF).darker(300);
57 mPgpEncryptedTextColor = QColor(0x00, 0x80, 0xFF).lighter(170);
58 }
59 mPgpSignedTrustedMessageColor = scheme.background(KColorScheme::PositiveBackground).color();
60 mPgpSignedTrustedTextColor = scheme.foreground(KColorScheme::PositiveText).color();
61 mPgpSignedUntrustedMessageColor = scheme.background(KColorScheme::NeutralBackground).color();
62 mPgpSignedUntrustedTextColor = scheme.foreground(KColorScheme::NeutralText).color();
63 mPgpSignedBadMessageColor = scheme.background(KColorScheme::NegativeBackground).color();
64 mPgpSignedBadTextColor = scheme.foreground(KColorScheme::NegativeText).color();
65 mLinkColor = scheme.foreground(KColorScheme::LinkText).color();
66}
67
68QColor ColorUtil::misspelledDefaultTextColor() const
69{
70 return mMisspelledDefaultTextColor;
71}
72
73QColor ColorUtil::quoteLevel1DefaultTextColor() const
74{
75 return mQuoteLevel1DefaultTextColor;
76}
77
78QColor ColorUtil::quoteLevel2DefaultTextColor() const
79{
80 return mQuoteLevel2DefaultTextColor;
81}
82
83QColor ColorUtil::quoteLevel3DefaultTextColor() const
84{
85 return mQuoteLevel3DefaultTextColor;
86}
87
88QColor ColorUtil::pgpSignedTrustedMessageColor() const
89{
90 return mPgpSignedTrustedMessageColor;
91}
92
93QColor ColorUtil::pgpSignedTrustedTextColor() const
94{
95 return mPgpSignedTrustedTextColor;
96}
97
98QColor ColorUtil::pgpSignedUntrustedMessageColor() const
99{
100 return mPgpSignedUntrustedMessageColor;
101}
102
103QColor ColorUtil::pgpSignedUntrustedTextColor() const
104{
105 return mPgpSignedUntrustedTextColor;
106}
107
108QColor ColorUtil::pgpSignedBadMessageColor() const
109{
110 return mPgpSignedBadMessageColor;
111}
112
113QColor ColorUtil::pgpSignedBadTextColor() const
114{
115 return mPgpSignedBadTextColor;
116}
117
118QColor ColorUtil::pgpEncryptedMessageColor() const
119{
120 return mPgpEncryptedMessageColor;
121}
122
123QColor ColorUtil::pgpEncryptedTextColor() const
124{
125 return mPgpEncryptedTextColor;
126}
127
128QColor ColorUtil::linkColor() const
129{
130 return mLinkColor;
131}
The ColorUtil class.
Definition colorutil.h:20
QColor darker(int factor) const const
QColor lighter(int factor) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.