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

KDE's Doxygen guidelines are available online.