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 {
75 Positive,
76 Information,
77 Warning,
78 Error,
79 MESSAGE_TYPE_COUNT
80 };
81
82 [[nodiscard]] const HeaderStylePlugin *headerPlugin() const;
83
84protected:
85 /** Recalculate PGP frame and body colors (should be called after changing
86 color settings) */
87 void recalculatePGPColors();
88
89protected:
90 QFont mBodyFont;
91 QFont mPrintFont;
92 QFont mFixedFont;
93 QFont mFixedPrintFont;
94 QFont mQuoteFont;
95 QColor mQuoteColor[3];
96 bool mRecycleQuoteColors = false;
97 bool mShrinkQuotes = false;
98 bool mUseBrowserColor = false;
99 QColor mForegroundColor;
100 QColor mLinkColor;
101 QColor mBackgroundColor;
102 // colors for PGP (Frame, Header, HeaderText, Body)
103 QColor cPgpOk1F;
104 QColor cPgpOk1H;
105 QColor cPgpOk1HT;
106 QColor cPgpOk1B;
107 QColor cPgpOk0F;
108 QColor cPgpOk0H;
109 QColor cPgpOk0HT;
110 QColor cPgpOk0B;
111 QColor cPgpWarnF;
112 QColor cPgpWarnH;
113 QColor cPgpWarnHT;
114 QColor cPgpWarnB;
115 QColor cPgpErrF;
116 QColor cPgpErrH;
117 QColor cPgpErrHT;
118 QColor cPgpErrB;
119 QColor cPgpEncrF;
120 QColor cPgpEncrH;
121 QColor cPgpEncrHT;
122 QColor cPgpEncrB;
123
124 // colors for inline message boxes, see KMessageWidget or Kirigami::InlineMessage
125 QColor cInlineMessage[MESSAGE_TYPE_COUNT];
126
127 QString imgShowUrl;
128 QString imgHideUrl;
129
130private:
131 [[nodiscard]] QString quoteCssDefinition() const;
132 [[nodiscard]] int fontSize(bool fixed, bool print = false) const;
133 // returns CSS rules specific to the print media type
134 [[nodiscard]] QString printCssDefinitions(const HtmlHeadSettings &) const;
135 // returns CSS rules specific to the screen media type
136 [[nodiscard]] QString screenCssDefinitions(const CSSHelperBase *helper, const HtmlHeadSettings &) const;
137 // returns CSS rules common to both screen and print media types
138 [[nodiscard]] QString commonCssDefinitions() const;
139 [[nodiscard]] QString fullAddressList() const;
140 [[nodiscard]] QString linkColorDefinition(const HtmlHeadSettings &htmlHeadSettings) const;
141 [[nodiscard]] QString defaultScreenHeaderFont() const;
142 [[nodiscard]] QString defaultPrintHeaderFont() const;
143 [[nodiscard]] bool useBrowserColor(const HtmlHeadSettings &htmlHeadSettings) const;
144
145 const QPaintDevice *mPaintDevice = nullptr;
146 const HeaderStylePlugin *mHeaderPlugin = nullptr;
147};
148}
The CSSHelperBase class.
The HeaderStylePlugin class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.