File indexing completed on 2025-03-09 04:54:40
0001 /* -*- c++ -*- 0002 csshelper.h 0003 0004 This file is part of KMail, the KDE mail client. 0005 SPDX-FileCopyrightText: 2003 Marc Mutz <mutz@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #pragma once 0011 0012 #include "messageviewer_export.h" 0013 0014 #include <QColor> 0015 #include <QFont> 0016 0017 class QString; 0018 class QPaintDevice; 0019 0020 namespace MessageViewer 0021 { 0022 class HeaderStylePlugin; 0023 /** 0024 * @brief The CSSHelperBase class 0025 */ 0026 class MESSAGEVIEWER_EXPORT CSSHelperBase 0027 { 0028 public: 0029 struct MESSAGEVIEWER_EXPORT HtmlHeadSettings { 0030 bool fixedFont = false; 0031 bool htmlFormat = true; 0032 }; 0033 /** Construct a CSSHelper object and set its font and color settings to 0034 default values. 0035 Sub-Classes should put their config loading here. 0036 */ 0037 explicit CSSHelperBase(const QPaintDevice *pd); 0038 virtual ~CSSHelperBase(); 0039 0040 /** @return HTML head including style sheet definitions and the 0041 >body< tag */ 0042 virtual QString htmlHead(const HtmlHeadSettings &) const; 0043 0044 /** @return The collected CSS definitions as a string */ 0045 [[nodiscard]] QString cssDefinitions(const HtmlHeadSettings &) const; 0046 0047 /** @return a <div> start tag with embedded style 0048 information suitable for quoted text with quote level @p level */ 0049 [[nodiscard]] QString quoteFontTag(int level) const; 0050 /** @return a <div> start tag with embedded style 0051 information suitable for non-quoted text */ 0052 [[nodiscard]] QString nonQuotedFontTag() const; 0053 0054 [[nodiscard]] QFont bodyFont(bool fixedFont = false, bool printing = false) const; 0055 0056 void setBodyFont(const QFont &font); 0057 void setPrintFont(const QFont &font); 0058 0059 /** @return the quote color for the given level, where level ranges from 0 to 2 **/ 0060 [[nodiscard]] QColor quoteColor(int level) const; 0061 [[nodiscard]] QString quoteColorName(int level) const; 0062 0063 [[nodiscard]] QColor pgpWarnColor() const; 0064 0065 [[nodiscard]] QString addEndBlockQuote(int numberBlock) const; 0066 [[nodiscard]] QString addStartBlockQuote(int numberBlock) const; 0067 0068 [[nodiscard]] QString extraScreenCss(const QString &headerFont) const; 0069 [[nodiscard]] QString extraPrintCss(const QString &headerFont) const; 0070 [[nodiscard]] QString extraCommonCss(const QString &headerFont) const; 0071 0072 void setHeaderPlugin(const HeaderStylePlugin *headerPlugin); 0073 0074 enum InlineMessageType { Positive, Information, Warning, Error, MESSAGE_TYPE_COUNT }; 0075 0076 protected: 0077 /** Recalculate PGP frame and body colors (should be called after changing 0078 color settings) */ 0079 void recalculatePGPColors(); 0080 0081 protected: 0082 QFont mBodyFont; 0083 QFont mPrintFont; 0084 QFont mFixedFont; 0085 QFont mFixedPrintFont; 0086 QFont mQuoteFont; 0087 QColor mQuoteColor[3]; 0088 bool mRecycleQuoteColors = false; 0089 bool mShrinkQuotes = false; 0090 bool mUseBrowserColor = false; 0091 QColor mForegroundColor; 0092 QColor mLinkColor; 0093 QColor mBackgroundColor; 0094 // colors for PGP (Frame, Header, HeaderText, Body) 0095 QColor cPgpOk1F; 0096 QColor cPgpOk1H; 0097 QColor cPgpOk1HT; 0098 QColor cPgpOk1B; 0099 QColor cPgpOk0F; 0100 QColor cPgpOk0H; 0101 QColor cPgpOk0HT; 0102 QColor cPgpOk0B; 0103 QColor cPgpWarnF; 0104 QColor cPgpWarnH; 0105 QColor cPgpWarnHT; 0106 QColor cPgpWarnB; 0107 QColor cPgpErrF; 0108 QColor cPgpErrH; 0109 QColor cPgpErrHT; 0110 QColor cPgpErrB; 0111 QColor cPgpEncrF; 0112 QColor cPgpEncrH; 0113 QColor cPgpEncrHT; 0114 QColor cPgpEncrB; 0115 0116 // colors for inline message boxes, see KMessageWidget or Kirigami::InlineMessage 0117 QColor cInlineMessage[MESSAGE_TYPE_COUNT]; 0118 0119 QString imgShowUrl; 0120 QString imgHideUrl; 0121 0122 private: 0123 [[nodiscard]] QString quoteCssDefinition() const; 0124 [[nodiscard]] int fontSize(bool fixed, bool print = false) const; 0125 // returns CSS rules specific to the print media type 0126 [[nodiscard]] QString printCssDefinitions(const HtmlHeadSettings &) const; 0127 // returns CSS rules specific to the screen media type 0128 [[nodiscard]] QString screenCssDefinitions(const CSSHelperBase *helper, const HtmlHeadSettings &) const; 0129 // returns CSS rules common to both screen and print media types 0130 [[nodiscard]] QString commonCssDefinitions() const; 0131 [[nodiscard]] QString fullAddressList() const; 0132 [[nodiscard]] QString linkColorDefinition(const HtmlHeadSettings &htmlHeadSettings) const; 0133 [[nodiscard]] QString defaultScreenHeaderFont() const; 0134 [[nodiscard]] QString defaultPrintHeaderFont() const; 0135 [[nodiscard]] bool useBrowserColor(const HtmlHeadSettings &htmlHeadSettings) const; 0136 0137 const QPaintDevice *mPaintDevice = nullptr; 0138 const HeaderStylePlugin *mHeaderPlugin = nullptr; 0139 }; 0140 }