Messagelib

csshelper.cpp
1 /*
2  csshelper.cpp
3 
4  This file is part of KMail, the KDE mail client.
5  SPDX-FileCopyrightText: 2003 Marc Mutz <[email protected]>
6 
7  SPDX-License-Identifier: GPL-2.0-or-later
8 */
9 
10 #include "csshelper.h"
11 #include "settings/messageviewersettings.h"
12 
13 #include <MessageCore/ColorUtil>
14 #include <MessageCore/MessageCoreSettings>
15 
16 #include <KColorScheme>
17 #include <KConfig>
18 #include <KConfigGroup>
19 #include <QApplication>
20 
21 #include <QFont>
22 #include <QPalette>
23 
24 using namespace MessageViewer;
25 
26 static const struct {
27  CSSHelperBase::InlineMessageType type;
29 } inlineMessageColors[] = {{CSSHelperBase::Positive, KColorScheme::PositiveText},
30  {CSSHelperBase::Information, KColorScheme::ActiveText},
31  {CSSHelperBase::Warning, KColorScheme::NeutralText},
32  {CSSHelperBase::Error, KColorScheme::NegativeText}};
33 
34 CSSHelper::CSSHelper(const QPaintDevice *pd)
35  : CSSHelperBase(pd)
36 {
37  // initialize with defaults - should match the corresponding application defaults
38  mForegroundColor = QApplication::palette().color(QPalette::Text);
39  mLinkColor = MessageCore::ColorUtil::self()->linkColor();
40  mBackgroundColor = QApplication::palette().color(QPalette::Base);
41  for (const auto &msgColor : inlineMessageColors) {
42  cInlineMessage[msgColor.type] = KColorScheme(QPalette::Active).foreground(msgColor.role).color();
43  }
44 
45  cPgpEncrH = MessageCore::ColorUtil::self()->pgpEncryptedMessageColor();
46  cPgpEncrHT = MessageCore::ColorUtil::self()->pgpEncryptedTextColor();
47  cPgpOk1H = MessageCore::ColorUtil::self()->pgpSignedTrustedMessageColor();
48  cPgpOk1HT = MessageCore::ColorUtil::self()->pgpSignedTrustedTextColor();
49  cPgpOk0H = MessageCore::ColorUtil::self()->pgpSignedUntrustedMessageColor();
50  cPgpOk0HT = MessageCore::ColorUtil::self()->pgpSignedUntrustedTextColor();
51  cPgpWarnH = MessageCore::ColorUtil::self()->pgpSignedUntrustedMessageColor();
52  cPgpWarnHT = MessageCore::ColorUtil::self()->pgpSignedUntrustedTextColor();
53  cPgpErrH = MessageCore::ColorUtil::self()->pgpSignedBadMessageColor();
54  cPgpErrHT = MessageCore::ColorUtil::self()->pgpSignedBadTextColor();
55 
56  mRecycleQuoteColors = false;
57 
60  mBodyFont = MessageCore::MessageCoreSettings::self()->useDefaultFonts() ? defaultFont : MessageViewer ::MessageViewerSettings::self()->bodyFont();
61  mPrintFont = MessageCore::MessageCoreSettings::self()->useDefaultFonts() ? defaultFont : MessageViewer ::MessageViewerSettings::self()->printFont();
62  mFixedFont = mFixedPrintFont = defaultFixedFont;
63  defaultFont.setItalic(true);
64  mQuoteFont = defaultFont;
65 
66  KConfig *config = MessageViewer::MessageViewerSettings::self()->config();
67 
68  KConfigGroup reader(config, "Reader");
69  KConfigGroup fonts(config, "Fonts");
70 
71  mRecycleQuoteColors = reader.readEntry("RecycleQuoteColors", false);
72 
73  mForegroundColor = KColorScheme(QPalette::Active).foreground().color();
74  if (MessageCore::MessageCoreSettings::self()->useDefaultColors()) {
75  mQuoteColor[0] = MessageCore::ColorUtil::self()->quoteLevel1DefaultTextColor();
76  mQuoteColor[1] = MessageCore::ColorUtil::self()->quoteLevel2DefaultTextColor();
77  mQuoteColor[2] = MessageCore::ColorUtil::self()->quoteLevel3DefaultTextColor();
78  } else {
79  mLinkColor = reader.readEntry("LinkColor", mLinkColor);
80  cPgpEncrH = reader.readEntry("PGPMessageEncr", cPgpEncrH);
81  cPgpOk1H = reader.readEntry("PGPMessageOkKeyOk", cPgpOk1H);
82  cPgpOk0H = reader.readEntry("PGPMessageOkKeyBad", cPgpOk0H);
83  cPgpWarnH = reader.readEntry("PGPMessageWarn", cPgpWarnH);
84  cPgpErrH = reader.readEntry("PGPMessageErr", cPgpErrH);
85  mQuoteColor[0] = MessageCore::MessageCoreSettings::self()->quotedText1();
86  mQuoteColor[1] = MessageCore::MessageCoreSettings::self()->quotedText2();
87  mQuoteColor[2] = MessageCore::MessageCoreSettings::self()->quotedText3();
88  }
89 
90  if (!MessageCore::MessageCoreSettings::self()->useDefaultFonts()) {
91  mBodyFont = fonts.readEntry("body-font", mBodyFont);
92  mPrintFont = fonts.readEntry("print-font", mPrintFont);
93  mFixedFont = fonts.readEntry("fixed-font", mFixedFont);
94  mFixedPrintFont = mFixedFont;
95  }
96 
97  mShrinkQuotes = MessageViewer::MessageViewerSettings::self()->shrinkQuotes();
98 
99  mUseBrowserColor = MessageCore::MessageCoreSettings::self()->useRealHtmlMailColor();
100  recalculatePGPColors();
101 }
102 
103 CSSHelper::~CSSHelper() = default;
104 
105 QString CSSHelper::htmlHead(bool fixed) const
106 {
107  return QLatin1String(
108  "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n"
109  "<html><head><title></title><style>\n")
110  + cssDefinitions(fixed)
111  + QLatin1String(
112  "</style></head>\n"
113  "<body>\n");
114 }
115 
116 QString CSSHelper::endBodyHtml() const
117 {
118  return QStringLiteral("</body></html>");
119 }
const QColor & color(QPalette::ColorGroup group, QPalette::ColorRole role) const const
KSharedConfigPtr config()
const QColor & color() const const
PartitionTable::TableType type
QBrush foreground(ForegroundRole=NormalText) const
QPalette palette()
The CSSHelperBase class.
Definition: csshelperbase.h:26
void setItalic(bool enable)
QFont systemFont(QFontDatabase::SystemFont type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Nov 30 2021 23:05:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.