Messagelib

csshelperbase.h
1/* -*- c++ -*-
2 csshelper.h
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#pragma once
11
12#include "messageviewer_export.h"
13
14#include <QColor>
15#include <QFont>
16
17class QString;
18class QPaintDevice;
19
20namespace MessageViewer
21{
22class HeaderStylePlugin;
23/**
24 * @brief The CSSHelperBase class
25 */
26class MESSAGEVIEWER_EXPORT CSSHelperBase
27{
28public:
29 struct MESSAGEVIEWER_EXPORT HtmlHeadSettings {
30 bool fixedFont = false;
31 bool htmlFormat = true;
32 };
33 /** Construct a CSSHelper object and set its font and color settings to
34 default values.
35 Sub-Classes should put their config loading here.
36 */
37 explicit CSSHelperBase(const QPaintDevice *pd);
38 virtual ~CSSHelperBase();
39
40 /** @return HTML head including style sheet definitions and the
41 &gt;body&lt; tag */
42 virtual QString htmlHead(const HtmlHeadSettings &) const;
43
44 /** @return The collected CSS definitions as a string */
45 [[nodiscard]] QString cssDefinitions(const HtmlHeadSettings &) const;
46
47 /** @return a &lt;div&gt; start tag with embedded style
48 information suitable for quoted text with quote level @p level */
49 [[nodiscard]] QString quoteFontTag(int level) const;
50 /** @return a &lt;div&gt; start tag with embedded style
51 information suitable for non-quoted text */
52 [[nodiscard]] QString nonQuotedFontTag() const;
53
54 [[nodiscard]] QFont bodyFont(bool fixedFont = false, bool printing = false) const;
55
56 void setBodyFont(const QFont &font);
57 void setPrintFont(const QFont &font);
58
59 /** @return the quote color for the given level, where level ranges from 0 to 2 **/
60 [[nodiscard]] QColor quoteColor(int level) const;
61 [[nodiscard]] QString quoteColorName(int level) const;
62
63 [[nodiscard]] QColor pgpWarnColor() const;
64
65 [[nodiscard]] QString addEndBlockQuote(int numberBlock) const;
66 [[nodiscard]] QString addStartBlockQuote(int numberBlock) const;
67
68 [[nodiscard]] QString extraScreenCss(const QString &headerFont) const;
69 [[nodiscard]] QString extraPrintCss(const QString &headerFont) const;
70 [[nodiscard]] QString extraCommonCss(const QString &headerFont) const;
71
72 void setHeaderPlugin(const HeaderStylePlugin *headerPlugin);
73
74 enum InlineMessageType { Positive, Information, Warning, Error, MESSAGE_TYPE_COUNT };
75
76 [[nodiscard]] const HeaderStylePlugin *headerPlugin() const;
77
78protected:
79 /** Recalculate PGP frame and body colors (should be called after changing
80 color settings) */
81 void recalculatePGPColors();
82
83protected:
84 QFont mBodyFont;
85 QFont mPrintFont;
86 QFont mFixedFont;
87 QFont mFixedPrintFont;
88 QFont mQuoteFont;
89 QColor mQuoteColor[3];
90 bool mRecycleQuoteColors = false;
91 bool mShrinkQuotes = false;
92 bool mUseBrowserColor = false;
93 QColor mForegroundColor;
94 QColor mLinkColor;
95 QColor mBackgroundColor;
96 // colors for PGP (Frame, Header, HeaderText, Body)
97 QColor cPgpOk1F;
98 QColor cPgpOk1H;
99 QColor cPgpOk1HT;
100 QColor cPgpOk1B;
101 QColor cPgpOk0F;
102 QColor cPgpOk0H;
103 QColor cPgpOk0HT;
104 QColor cPgpOk0B;
105 QColor cPgpWarnF;
106 QColor cPgpWarnH;
107 QColor cPgpWarnHT;
108 QColor cPgpWarnB;
109 QColor cPgpErrF;
110 QColor cPgpErrH;
111 QColor cPgpErrHT;
112 QColor cPgpErrB;
113 QColor cPgpEncrF;
114 QColor cPgpEncrH;
115 QColor cPgpEncrHT;
116 QColor cPgpEncrB;
117
118 // colors for inline message boxes, see KMessageWidget or Kirigami::InlineMessage
119 QColor cInlineMessage[MESSAGE_TYPE_COUNT];
120
121 QString imgShowUrl;
122 QString imgHideUrl;
123
124private:
125 [[nodiscard]] QString quoteCssDefinition() const;
126 [[nodiscard]] int fontSize(bool fixed, bool print = false) const;
127 // returns CSS rules specific to the print media type
128 [[nodiscard]] QString printCssDefinitions(const HtmlHeadSettings &) const;
129 // returns CSS rules specific to the screen media type
130 [[nodiscard]] QString screenCssDefinitions(const CSSHelperBase *helper, const HtmlHeadSettings &) const;
131 // returns CSS rules common to both screen and print media types
132 [[nodiscard]] QString commonCssDefinitions() const;
133 [[nodiscard]] QString fullAddressList() const;
134 [[nodiscard]] QString linkColorDefinition(const HtmlHeadSettings &htmlHeadSettings) const;
135 [[nodiscard]] QString defaultScreenHeaderFont() const;
136 [[nodiscard]] QString defaultPrintHeaderFont() const;
137 [[nodiscard]] bool useBrowserColor(const HtmlHeadSettings &htmlHeadSettings) const;
138
139 const QPaintDevice *mPaintDevice = nullptr;
140 const HeaderStylePlugin *mHeaderPlugin = nullptr;
141};
142}
The CSSHelperBase class.
The HeaderStylePlugin class.
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.