Messagelib

colorutil.cpp
1 /*
2  * SPDX-FileCopyrightText: 2015 Daniel Vr├ítil <[email protected]>
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 
13 using namespace MessageCore;
14 
15 static bool isLightTheme()
16 {
17  return qApp->palette().color(QPalette::Window).value() >= 128;
18 }
19 
21 
22 ColorUtil *ColorUtil::self()
23 {
24  return s_self;
25 }
26 
27 ColorUtil::ColorUtil()
28 {
29  initializeColors();
30 }
31 
32 void ColorUtil::updateColors()
33 {
34  initializeColors();
35 }
36 
37 void 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 
68 QColor ColorUtil::misspelledDefaultTextColor() const
69 {
70  return mMisspelledDefaultTextColor;
71 }
72 
73 QColor ColorUtil::quoteLevel1DefaultTextColor() const
74 {
75  return mQuoteLevel1DefaultTextColor;
76 }
77 
78 QColor ColorUtil::quoteLevel2DefaultTextColor() const
79 {
80  return mQuoteLevel2DefaultTextColor;
81 }
82 
83 QColor ColorUtil::quoteLevel3DefaultTextColor() const
84 {
85  return mQuoteLevel3DefaultTextColor;
86 }
87 
88 QColor ColorUtil::pgpSignedTrustedMessageColor() const
89 {
90  return mPgpSignedTrustedMessageColor;
91 }
92 
93 QColor ColorUtil::pgpSignedTrustedTextColor() const
94 {
95  return mPgpSignedTrustedTextColor;
96 }
97 
98 QColor ColorUtil::pgpSignedUntrustedMessageColor() const
99 {
100  return mPgpSignedUntrustedMessageColor;
101 }
102 
103 QColor ColorUtil::pgpSignedUntrustedTextColor() const
104 {
105  return mPgpSignedUntrustedTextColor;
106 }
107 
108 QColor ColorUtil::pgpSignedBadMessageColor() const
109 {
110  return mPgpSignedBadMessageColor;
111 }
112 
113 QColor ColorUtil::pgpSignedBadTextColor() const
114 {
115  return mPgpSignedBadTextColor;
116 }
117 
118 QColor ColorUtil::pgpEncryptedMessageColor() const
119 {
120  return mPgpEncryptedMessageColor;
121 }
122 
123 QColor ColorUtil::pgpEncryptedTextColor() const
124 {
125  return mPgpEncryptedTextColor;
126 }
127 
128 QColor ColorUtil::linkColor() const
129 {
130  return mLinkColor;
131 }
QColor darker(int factor) const const
The ColorUtil class.
Definition: colorutil.h:19
Q_GLOBAL_STATIC(Internal::StaticControl, s_instance) class ControlPrivate
QColor lighter(int factor) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Dec 2 2021 23:06:07 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.