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 <mutz@kde.org>
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
24using namespace MessageViewer;
25
26static 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
34CSSHelper::CSSHelper(const QPaintDevice *pd)
35 : CSSHelperBase(pd)
36{
37 // initialize with defaults - should match the corresponding application defaults
38 updateColor();
39 mLinkColor = MessageCore::ColorUtil::self()->linkColor();
40 for (const auto &msgColor : inlineMessageColors) {
41 cInlineMessage[msgColor.type] = KColorScheme(QPalette::Active).foreground(msgColor.role).color();
42 }
43
44 cPgpEncrH = MessageCore::ColorUtil::self()->pgpEncryptedMessageColor();
45 cPgpEncrHT = MessageCore::ColorUtil::self()->pgpEncryptedTextColor();
46 cPgpOk1H = MessageCore::ColorUtil::self()->pgpSignedTrustedMessageColor();
47 cPgpOk1HT = MessageCore::ColorUtil::self()->pgpSignedTrustedTextColor();
48 cPgpOk0H = MessageCore::ColorUtil::self()->pgpSignedUntrustedMessageColor();
49 cPgpOk0HT = MessageCore::ColorUtil::self()->pgpSignedUntrustedTextColor();
50 cPgpWarnH = MessageCore::ColorUtil::self()->pgpSignedUntrustedMessageColor();
51 cPgpWarnHT = MessageCore::ColorUtil::self()->pgpSignedUntrustedTextColor();
52 cPgpErrH = MessageCore::ColorUtil::self()->pgpSignedBadMessageColor();
53 cPgpErrHT = MessageCore::ColorUtil::self()->pgpSignedBadTextColor();
54
55 mRecycleQuoteColors = false;
56
59 mBodyFont = MessageCore::MessageCoreSettings::self()->useDefaultFonts() ? defaultFont : MessageViewer ::MessageViewerSettings::self()->bodyFont();
60 mPrintFont = MessageCore::MessageCoreSettings::self()->useDefaultFonts() ? defaultFont : MessageViewer ::MessageViewerSettings::self()->printFont();
61 mFixedFont = mFixedPrintFont = defaultFixedFont;
62 defaultFont.setItalic(true);
63 mQuoteFont = defaultFont;
64
65 KConfig *config = MessageViewer::MessageViewerSettings::self()->config();
66
67 KConfigGroup reader(config, QStringLiteral("Reader"));
68 KConfigGroup fonts(config, QStringLiteral("Fonts"));
69
70 mRecycleQuoteColors = reader.readEntry("RecycleQuoteColors", false);
71
72 mForegroundColor = KColorScheme(QPalette::Active).foreground().color();
73 if (MessageCore::MessageCoreSettings::self()->useDefaultColors()) {
74 mQuoteColor[0] = MessageCore::ColorUtil::self()->quoteLevel1DefaultTextColor();
75 mQuoteColor[1] = MessageCore::ColorUtil::self()->quoteLevel2DefaultTextColor();
76 mQuoteColor[2] = MessageCore::ColorUtil::self()->quoteLevel3DefaultTextColor();
77 } else {
78 mLinkColor = reader.readEntry("LinkColor", mLinkColor);
79 cPgpEncrH = reader.readEntry("PGPMessageEncr", cPgpEncrH);
80 cPgpOk1H = reader.readEntry("PGPMessageOkKeyOk", cPgpOk1H);
81 cPgpOk0H = reader.readEntry("PGPMessageOkKeyBad", cPgpOk0H);
82 cPgpWarnH = reader.readEntry("PGPMessageWarn", cPgpWarnH);
83 cPgpErrH = reader.readEntry("PGPMessageErr", cPgpErrH);
84 mQuoteColor[0] = MessageCore::MessageCoreSettings::self()->quotedText1();
85 mQuoteColor[1] = MessageCore::MessageCoreSettings::self()->quotedText2();
86 mQuoteColor[2] = MessageCore::MessageCoreSettings::self()->quotedText3();
87 }
88
89 if (!MessageCore::MessageCoreSettings::self()->useDefaultFonts()) {
90 mBodyFont = fonts.readEntry("body-font", mBodyFont);
91 mPrintFont = fonts.readEntry("print-font", mPrintFont);
92 mFixedFont = fonts.readEntry("fixed-font", mFixedFont);
93 mFixedPrintFont = mFixedFont;
94 }
95
96 mShrinkQuotes = MessageViewer::MessageViewerSettings::self()->shrinkQuotes();
97
98 mUseBrowserColor = MessageCore::MessageCoreSettings::self()->useRealHtmlMailColor();
99 recalculatePGPColors();
100}
101
102CSSHelper::~CSSHelper() = default;
103
104void CSSHelper::updateColor()
105{
106 // KColorScheme(QPalette::Active).background().color();
107
108 mForegroundColor = KColorScheme(QPalette::Active).foreground().color(); // QApplication::palette().color(QPalette::Text);
109 mBackgroundColor = KColorScheme(QPalette::Active).background().color(); // QApplication::palette().color(QPalette::Base);
110}
111
112QString CSSHelper::htmlHead(const HtmlHeadSettings &htmlHeadSettings) const
113{
114 return QLatin1StringView(
115 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n"
116 "<html><head><title></title><style>\n")
117 + cssDefinitions(htmlHeadSettings)
119 "</style></head>\n"
120 "<body>\n");
121}
122
123QString CSSHelper::endBodyHtml() const
124{
125 return QStringLiteral("</body></html>");
126}
QBrush background(BackgroundRole=NormalBackground) const
QBrush foreground(ForegroundRole=NormalText) const
The CSSHelperBase class.
QString cssDefinitions(const HtmlHeadSettings &) const
QString htmlHead(const HtmlHeadSettings &htmlHeadSettings) const override
const QColor & color() const const
void setItalic(bool enable)
QFont systemFont(SystemFont type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:56:57 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.