diff --git a/messageviewer/src/messagepartthemes/default/autotests/testcsshelper.cpp b/messageviewer/src/messagepartthemes/default/autotests/testcsshelper.cpp --- a/messageviewer/src/messagepartthemes/default/autotests/testcsshelper.cpp +++ b/messageviewer/src/messagepartthemes/default/autotests/testcsshelper.cpp @@ -45,7 +45,11 @@ cPgpWarnHT = QColor(0xf6, 0x74, 0x00); cPgpErrHT = QColor(0xda, 0x44, 0x53); - cHtmlWarning = QColor(0xff, 0x40, 0x40); + cInlineMessage[Positive] = QColor(0, 255, 0); + cInlineMessage[Information] = QColor(0, 0, 255); + cInlineMessage[Warning] = QColor(255, 255, 0); + cInlineMessage[Error] = QColor(255, 0, 0); + for (int i = 0; i < 3; ++i) { mQuoteColor[i] = QColor(0x00, 0x80 - i * 0x10, 0x00); } diff --git a/messageviewer/src/messagepartthemes/default/templates/htmlmessagepart.html b/messageviewer/src/messagepartthemes/default/templates/htmlmessagepart.html --- a/messageviewer/src/messagepartthemes/default/templates/htmlmessagepart.html +++ b/messageviewer/src/messagepartthemes/default/templates/htmlmessagepart.html @@ -1,6 +1,6 @@ {% if not block.isPrinting %} {% if not block.htmlMail or not block.loadExternal and block.containsExternalReferences %} -
+
{% if not block.htmlMail %} {% i18n_var "Note: This is an HTML message. For security reasons, only the raw HTML code is shown. If you trust the sender of this message then you can activate formatted HTML display for this message by clicking here." as msg %} {% elif not block.loadExternal and block.containsExternalReferences %} diff --git a/messageviewer/src/viewer/csshelper.cpp b/messageviewer/src/viewer/csshelper.cpp --- a/messageviewer/src/viewer/csshelper.cpp +++ b/messageviewer/src/viewer/csshelper.cpp @@ -47,14 +47,26 @@ using namespace MessageViewer; +static const struct { + CSSHelperBase::InlineMessageType type; + KColorScheme::ForegroundRole role; +} inlineMessageColors[] = { + { CSSHelperBase::Positive, KColorScheme::PositiveText }, + { CSSHelperBase::Information, KColorScheme::ActiveText }, + { CSSHelperBase::Warning, KColorScheme::NeutralText }, + { CSSHelperBase::Error, KColorScheme::NegativeText } +}; + CSSHelper::CSSHelper(const QPaintDevice *pd) : CSSHelperBase(pd) { // initialize with defaults - should match the corresponding application defaults mForegroundColor = QApplication::palette().color(QPalette::Text); mLinkColor = MessageCore::ColorUtil::self()->linkColor(); mBackgroundColor = QApplication::palette().color(QPalette::Base); - cHtmlWarning = QColor(0xFF, 0x40, 0x40); // warning frame color: light red + for (const auto &msgColor : inlineMessageColors) { + cInlineMessage[msgColor.type] = KColorScheme(QPalette::Active).foreground(msgColor.role).color(); + } cPgpEncrH = MessageCore::ColorUtil::self()->pgpEncryptedMessageColor(); cPgpEncrHT = MessageCore::ColorUtil::self()->pgpEncryptedTextColor(); diff --git a/messageviewer/src/viewer/csshelperbase.h b/messageviewer/src/viewer/csshelperbase.h --- a/messageviewer/src/viewer/csshelperbase.h +++ b/messageviewer/src/viewer/csshelperbase.h @@ -87,6 +87,14 @@ void setHeaderPlugin(const HeaderStylePlugin *headerPlugin); + enum InlineMessageType { + Positive, + Information, + Warning, + Error, + MESSAGE_TYPE_COUNT + }; + protected: /** Recalculate PGP frame and body colors (should be called after changing color settings) */ @@ -126,8 +134,9 @@ QColor cPgpEncrH; QColor cPgpEncrHT; QColor cPgpEncrB; - // color of frame of warning preceding the source of HTML messages - QColor cHtmlWarning; + + // colors for inline message boxes, see KMessageWidget or Kirigami::InlineMessage + QColor cInlineMessage[MESSAGE_TYPE_COUNT]; QString imgShowUrl; QString imgHideUrl; diff --git a/messageviewer/src/viewer/csshelperbase.cpp b/messageviewer/src/viewer/csshelperbase.cpp --- a/messageviewer/src/viewer/csshelperbase.cpp +++ b/messageviewer/src/viewer/csshelperbase.cpp @@ -69,12 +69,22 @@ c.getHsv(&h, &s, &v); return v; } + +static const struct { + CSSHelperBase::InlineMessageType type; + const char *cssName; +} inlineMessageStyles[] = { + { CSSHelperBase::Positive, "inlineMessagePositive" }, + { CSSHelperBase::Information, "inlineMessageInformation" }, + { CSSHelperBase::Warning, "inlineMessageWarning" }, + { CSSHelperBase::Error, "inlineMessageError" } +}; + } CSSHelperBase::CSSHelperBase(const QPaintDevice *pd) : mRecycleQuoteColors(false) , mShrinkQuotes(false) - , cHtmlWarning(QColor(0xFF, 0x40, 0x40)) , mPaintDevice(pd) { recalculatePGPColors(); @@ -296,6 +306,12 @@ } quoteCSS += quoteCssDefinition(); + QStringList inlineMessageCss; + inlineMessageCss.reserve(MESSAGE_TYPE_COUNT); + for (const auto &msgStyle : inlineMessageStyles) { + inlineMessageCss.push_back(QLatin1String("div.") + QString::fromLatin1(msgStyle.cssName)); + } + return QStringLiteral("body {\n" " font-family: \"%1\" ! important;\n" @@ -325,7 +341,7 @@ " display:none ! important;\n" "}\n\n" - "div.htmlWarn {\n" + "%3 {\n" " border: 2px solid #ffffff ! important;\n" " line-height: normal;\n" "}\n\n" @@ -344,7 +360,7 @@ " display:none ! important;\n" "}\n\n" ) - .arg(headerFont, extraPrintCss(headerFont)) + .arg(headerFont, extraPrintCss(headerFont), inlineMessageCss.join(QLatin1String(", "))) + quoteCSS + fullAddressList(); } @@ -357,10 +373,6 @@ const QString background = QStringLiteral(" background: %1 ! important;\n").arg(bgColor); return QStringLiteral("div#headerbox a:link {\n" - " color: %1 ! important;\n" - " text-decoration: none ! important;\n" - "}\n\n" - "div.htmlWarn a:link {\n" " color: %1 ! important;\n" " text-decoration: none ! important;\n" "}\n\n" @@ -376,10 +388,6 @@ "}\n\n").arg(linkColor, background); #else return QStringLiteral("div#headerbox a:link {\n" - " color: %1 ! important;\n" - " text-decoration: none ! important;\n" - "}\n\n" - "div.htmlWarn a:link {\n" " color: %1 ! important;\n" " text-decoration: none ! important;\n" "}\n\n" @@ -511,6 +519,25 @@ } quoteCSS += quoteCssDefinition(); + + // CSS definitions for inline message boxes + QString inlineMessageCss; + for (const auto &msgStyle : inlineMessageStyles) { + const auto c = cInlineMessage[msgStyle.type]; + inlineMessageCss += QStringLiteral(R"( + div.%1 { + border: 1px solid rgba(%2, %3, %4) ! important; + border-radius: 2px; + box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.5); + background-color: rgba(%2, %3, %4, 0.2) ! important; + } + div.%1 a:link { + color: %5 ! important; + text-decoration: none ! important; + } + )").arg(QString::fromLatin1(msgStyle.cssName)).arg(c.red()).arg(c.green()).arg(c.blue()).arg(mLinkColor.name()); + } + return QStringLiteral("body {\n" " font-family: \"%1\" ! important;\n" @@ -634,11 +661,7 @@ headerFont, cPgpErrBColorName) + - QStringLiteral("div.htmlWarn {\n" - " border: 2px solid %1 ! important;\n" - " line-height: normal;\n" - "}\n\n") - .arg(cHtmlWarning.name()) + inlineMessageCss + QStringLiteral("div.header {\n" "%1" @@ -666,6 +689,12 @@ { const QString headerFont = defaultScreenHeaderFont(); + QStringList inlineMessageCss; + inlineMessageCss.reserve(MESSAGE_TYPE_COUNT); + for (const auto &msgStyle : inlineMessageStyles) { + inlineMessageCss.push_back(QLatin1String("div.") + QString::fromLatin1(msgStyle.cssName)); + } + return QStringLiteral("div.header {\n" " margin-bottom: 10pt ! important;\n" @@ -718,17 +747,24 @@ "%1" - "div.htmlWarn {\n" - " margin: 0px 5% ! important;\n" + "%2 {\n" + " margin: 0px 5% 10px 5% ! important;\n" " padding: 10px ! important;\n" " text-align: left ! important;\n" " line-height: normal;\n" "}\n\n" + "hr {\n" + " border: 0;\n" + " height: 0;\n" + " border-top: 1px solid rgba(%3, %4, %5, 0.3);\n" + "}\n\n" + "div.quotelevelmark {\n" " position: absolute;\n" " margin-left:-10px;\n" - "}\n\n").arg(extraCommonCss(headerFont)); + "}\n\n").arg(extraCommonCss(headerFont), inlineMessageCss.join(QLatin1String(", "))) + .arg(mForegroundColor.red()).arg(mForegroundColor.green()).arg(mForegroundColor.blue()); } void CSSHelperBase::setBodyFont(const QFont &font)