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

KDE's Doxygen guidelines are available online.