Commit 0af5d5ef authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Allow to define specific css in plugin

parent 76aecf57
cmake_minimum_required(VERSION 3.0)
set(PIM_VERSION "5.9.58")
set(PIM_VERSION "5.9.59")
if (POLICY CMP0053)
cmake_policy(SET CMP0053 NEW)
......
......@@ -61,7 +61,6 @@ set(libmessageviewer_viewer_SRCS
viewer/attachmentstrategy.cpp
viewer/csshelper.cpp
viewer/csshelperbase.cpp
viewer/cssfancyhelper.cpp
viewer/editorwatcher.cpp
viewer/objecttreeemptysource.cpp
viewer/objecttreeviewersource.cpp
......@@ -290,7 +289,6 @@ ecm_generate_headers(MessageViewer_Camelcaseviewer_HEADERS
AttachmentStrategy
Viewer
CSSHelperBase
CSSFancyHelper
CSSHelper
ObjectTreeEmptySource
EditorWatcher
......
......@@ -63,11 +63,6 @@ HeaderStylePlugin *HeaderStyleInterface::headerStylePlugin() const
return mHeaderStylePlugin;
}
void HeaderStyleInterface::setViewer(QWidget *viewer)
{
mWidget = viewer;
}
void HeaderStyleInterface::slotStyleChanged()
{
Q_EMIT styleChanged(mHeaderStylePlugin);
......
......@@ -40,7 +40,6 @@ public:
virtual void createAction(KActionMenu *menu, QActionGroup *actionGroup, KActionCollection *ac) = 0;
virtual void activateAction() = 0;
Q_REQUIRED_RESULT HeaderStylePlugin *headerStylePlugin() const;
void setViewer(QWidget *viewer);
Q_SIGNALS:
void styleChanged(MessageViewer::HeaderStylePlugin *plugin);
......@@ -53,7 +52,6 @@ protected:
void addActionToMenu(KActionMenu *menu, QActionGroup *actionGroup);
QList<KToggleAction *> mAction;
HeaderStylePlugin *mHeaderStylePlugin = nullptr;
QWidget *mWidget = nullptr;
};
}
#endif // HEADERSTYLEINTERFACE_H
......@@ -49,7 +49,6 @@ public:
QActionGroup *group = nullptr;
KActionMenu *headerMenu = nullptr;
HeaderStyleMenuManager *q = nullptr;
QWidget *viewer = nullptr;
};
void HeaderStyleMenuManagerPrivate::addHelpTextAction(QAction *act, const QString &text)
......@@ -189,8 +188,3 @@ void HeaderStyleMenuManager::readConfig()
{
d->readSettings();
}
void HeaderStyleMenuManager::setViewer(QWidget *viewer)
{
d->viewer = viewer;
}
......@@ -39,7 +39,6 @@ public:
void setPluginName(const QString &pluginName);
void readConfig();
void setViewer(QWidget *viewer);
public Q_SLOTS:
void slotStyleChanged(MessageViewer::HeaderStylePlugin *plugin);
......
......@@ -77,3 +77,21 @@ void HeaderStylePlugin::showConfigureDialog(QWidget *parent)
Q_UNUSED(parent);
//Reimplement
}
QString HeaderStylePlugin::extraScreenCss(const QString &headerFont) const
{
Q_UNUSED(headerFont);
return {};
}
QString HeaderStylePlugin::extraPrintCss(const QString &headerFont) const
{
Q_UNUSED(headerFont);
return {};
}
QString HeaderStylePlugin::extraCommonCss(const QString &headerFont) const
{
Q_UNUSED(headerFont);
return {};
}
......@@ -53,6 +53,10 @@ public:
virtual void showConfigureDialog(QWidget *parent);
virtual QString extraScreenCss(const QString &headerFont) const;
virtual QString extraPrintCss(const QString &headerFont) const;
virtual QString extraCommonCss(const QString &headerFont) const;
private:
HeaderStylePluginPrivate *const d;
};
......
......@@ -27,7 +27,7 @@
using namespace MessageViewer::Test;
TestCSSHelper::TestCSSHelper(const QPaintDevice *pd)
: MessageViewer::CSSFancyHelper(pd)
: MessageViewer::CSSHelper(pd)
{
mRecycleQuoteColors = false;
mBackgroundColor = QColor(0xff, 0xff, 0xff);
......
......@@ -20,11 +20,11 @@
#ifndef MESSSAGEVIEWER_TESTCSSHELPER_H
#define MESSSAGEVIEWER_TESTCSSHELPER_H
#include <MessageViewer/CSSFancyHelper>
#include <MessageViewer/CSSHelper>
namespace MessageViewer {
namespace Test {
class TestCSSHelper : public MessageViewer::CSSFancyHelper
class TestCSSHelper : public MessageViewer::CSSHelper
{
public:
explicit TestCSSHelper(const QPaintDevice *pd);
......
......@@ -22,16 +22,16 @@
#include "interfaces/htmlwriter.h"
#include <MessageViewer/CSSHelperBase>
#include <MessageViewer/CSSFancyHelper>
#include <MessageViewer/CSSHelper>
#include <KMime/Message>
namespace MessageViewer {
namespace Test {
class CSSHelper : public MessageViewer::CSSFancyHelper
class CSSHelper : public MessageViewer::CSSHelper
{
public:
CSSHelper() : MessageViewer::CSSFancyHelper(nullptr)
CSSHelper() : MessageViewer::CSSHelper(nullptr)
{
for (int i = 0; i < 3; ++i) {
mQuoteColor[i] = QColor(0x00, 0x80 - i * 0x10, 0x00);
......
......@@ -31,6 +31,7 @@
*/
#include "csshelperbase.h"
#include "header/headerstyleplugin.h"
#include "utils/iconnamecache.h"
#include <QApplication>
......@@ -157,18 +158,36 @@ QString CSSHelperBase::addStartBlockQuote(int numberBlock) const
return blockQuote;
}
QString CSSHelperBase::extraScreenCss() const
QString CSSHelperBase::extraScreenCss(const QString &headerFont) const
{
if (mHeaderPlugin) {
return mHeaderPlugin->extraScreenCss(headerFont);
}
return {};
}
QString CSSHelperBase::extraPrintCss() const
QString CSSHelperBase::extraPrintCss(const QString &headerFont) const
{
if (mHeaderPlugin) {
return mHeaderPlugin->extraPrintCss(headerFont);
}
return {};
}
QString CSSHelperBase::extraCommonCss() const
QString CSSHelperBase::extraCommonCss(const QString &headerFont) const
{
if (mHeaderPlugin) {
QString result = mHeaderPlugin->extraCommonCss(headerFont);
if (result.isEmpty()) {
//Add default value
result = QStringLiteral("div.header table {\n"
" width: 100% ! important;\n"
" border-width: 0px ! important;\n"
" line-height: normal;\n"
"}\n\n");
}
return result;
}
return {};
}
......@@ -245,25 +264,23 @@ int CSSHelperBase::fontSize(bool fixed, bool print) const
{
return bodyFont(fixed, print).pointSize();
}
int CSSHelperBase::pointsToPixel(const QPaintDevice *pd, int pointSize) const
namespace {
int pointsToPixel(const QPaintDevice *pd, int pointSize)
{
if (pd) {
return (pointSize * pd->logicalDpiY() + 36) / 72;
} else {
//TODO
return 10;
}
}
}
void CSSHelperBase::setHeaderPlugin(const HeaderStylePlugin *headerPlugin)
{
mHeaderPlugin = headerPlugin;
}
static const char *const quoteFontSizes[] = { "85", "80", "75" };
QString CSSHelperBase::printCssDefinitions(bool fixed) const
{
const QString headerFont = QStringLiteral(" font-family: \"%1\" ! important;\n"
" font-size: %2pt ! important;\n")
.arg(mPrintFont.family())
.arg(mPrintFont.pointSize());
const QString headerFont = defaultPrintHeaderFont();
const QFont printFont = bodyFont(fixed, true /* print */);
QString quoteCSS;
......@@ -327,17 +344,36 @@ QString CSSHelperBase::printCssDefinitions(bool fixed) const
"}\n\n"
)
.arg(headerFont)
.arg(extraPrintCss())
.arg(extraPrintCss(headerFont))
+ quoteCSS + fullAddressList();
}
//#define USE_REAL_LINK 1
QString CSSHelperBase::linkColorDefinition() const
{
const QString linkColor = mLinkColor.name();
return QStringLiteral("a {\n"
" color: %1 ! important;\n"
" text-decoration: none ! important;\n"
"}\n\n").arg(linkColor);
#ifdef USE_REAL_LINK
if (true) {
#else
if (mUseBrowserColor) {
#endif
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"
"div#header a:link {\n"
" color: %1 ! important;\n"
" text-decoration: none ! important;\n"
"}\n\n").arg(linkColor);
} else {
return QStringLiteral("a {\n"
" color: %1 ! important;\n"
" text-decoration: none ! important;\n"
"}\n\n").arg(linkColor);
}
}
QString CSSHelperBase::quoteCssDefinition() const
......@@ -345,19 +381,19 @@ QString CSSHelperBase::quoteCssDefinition() const
QString quoteCSS;
QString blockQuote;
for (int i = 0; i < 9; ++i) {
blockQuote += QLatin1String("blockquote ");
quoteCSS += QString::fromLatin1("%2{\n"
blockQuote += QStringLiteral("blockquote ");
quoteCSS += QStringLiteral("%2{\n"
" margin: 4pt 0 4pt 0;\n"
" padding: 0 0 0 1em;\n"
" border-left: 2px solid %1;\n"
" unicode-bidi: -webkit-plaintext\n"
"}\n\n").arg(quoteColorName(i)).arg(blockQuote);
}
quoteCSS += QLatin1String(".quotemarks{\n"
quoteCSS += QStringLiteral(".quotemarks{\n"
" color:transparent;\n"
" font-size:0px;\n"
"}\n\n");
quoteCSS += QLatin1String(".quotemarksemptyline{\n"
quoteCSS += QStringLiteral(".quotemarksemptyline{\n"
" color:transparent;\n"
" font-size:0px;\n"
" line-height: 12pt;\n"
......@@ -365,14 +401,29 @@ QString CSSHelperBase::quoteCssDefinition() const
return quoteCSS;
}
QString CSSHelperBase::screenCssDefinitions(const CSSHelperBase *helper, bool fixed) const
QString CSSHelperBase::defaultPrintHeaderFont() const
{
const QString headerFont = QStringLiteral(" font-family: \"%1\" ! important;\n"
" font-size: %2pt ! important;\n")
.arg(mPrintFont.family())
.arg(mPrintFont.pointSize());
return headerFont;
}
QString CSSHelperBase::defaultScreenHeaderFont() const
{
const QString fgColor = mForegroundColor.name();
const QString bgColor = mBackgroundColor.name();
const QString headerFont = QStringLiteral(" font-family: \"%1\" ! important;\n"
" font-size: %2px ! important;\n")
.arg(mBodyFont.family())
.arg(pointsToPixel(helper->mPaintDevice, mBodyFont.pointSize()));
.arg(pointsToPixel(this->mPaintDevice, mBodyFont.pointSize()));
return headerFont;
}
QString CSSHelperBase::screenCssDefinitions(const CSSHelperBase *helper, bool fixed) const
{
const QString fgColor = mForegroundColor.name();
const QString bgColor = mBackgroundColor.name();
const QString headerFont = defaultScreenHeaderFont();
const QString background = QStringLiteral(" background-color: %1 ! important;\n").arg(bgColor);
const QString bodyFontSize = QString::number(pointsToPixel(helper->mPaintDevice, fontSize(
fixed))) + QLatin1String("px");
......@@ -395,16 +446,16 @@ QString CSSHelperBase::screenCssDefinitions(const CSSHelperBase *helper, bool fi
" color: %2 ! important;\n")
.arg(QString::number(i + 1), quoteColorName(i));
if (mQuoteFont.italic()) {
quoteCSS += QLatin1String(" font-style: italic ! important;\n");
quoteCSS += QStringLiteral(" font-style: italic ! important;\n");
}
if (mQuoteFont.bold()) {
quoteCSS += QLatin1String(" font-weight: bold ! important;\n");
quoteCSS += QStringLiteral(" font-weight: bold ! important;\n");
}
if (mShrinkQuotes) {
quoteCSS += QLatin1String(" font-size: ") + QString::fromLatin1(quoteFontSizes[i])
+ QLatin1String("% ! important;\n");
}
quoteCSS += QLatin1String("}\n\n");
quoteCSS += QStringLiteral("}\n\n");
}
// CSS definitions for quote levels 4+
......@@ -413,13 +464,13 @@ QString CSSHelperBase::screenCssDefinitions(const CSSHelperBase *helper, bool fi
" color: %2 ! important;\n")
.arg(QString::number(i + 1), quoteColorName(i));
if (mQuoteFont.italic()) {
quoteCSS += QLatin1String(" font-style: italic ! important;\n");
quoteCSS += QStringLiteral(" font-style: italic ! important;\n");
}
if (mQuoteFont.bold()) {
quoteCSS += QLatin1String(" font-weight: bold ! important;\n");
quoteCSS += QStringLiteral(" font-weight: bold ! important;\n");
}
if (mShrinkQuotes) {
quoteCSS += QLatin1String(" font-size: 70% ! important;\n");
quoteCSS += QStringLiteral(" font-size: 70% ! important;\n");
}
quoteCSS += QLatin1String("}\n\n");
}
......@@ -573,7 +624,7 @@ QString CSSHelperBase::screenCssDefinitions(const CSSHelperBase *helper, bool fi
)
.arg(headerFont)
.arg(extraScreenCss())
.arg(extraScreenCss(headerFont))
.arg(pal.color(QPalette::Highlight).name())
.arg(pal.color(QPalette::Background).name())
+ quoteCSS + fullAddressList();
......@@ -581,10 +632,7 @@ QString CSSHelperBase::screenCssDefinitions(const CSSHelperBase *helper, bool fi
QString CSSHelperBase::commonCssDefinitions() const
{
const QString headerFont = QStringLiteral("font-family: \"%1\" ! important;\n"
" font-size: %2px ! important;\n")
.arg(mBodyFont.family())
.arg(pointsToPixel(this->mPaintDevice, mBodyFont.pointSize()));
const QString headerFont = defaultScreenHeaderFont();
return
QStringLiteral("div.header {\n"
......@@ -645,7 +693,7 @@ QString CSSHelperBase::commonCssDefinitions() const
"div.quotelevelmark {\n"
" position: absolute;\n"
" margin-left:-10px;\n"
"}\n\n").arg(extraCommonCss());
"}\n\n").arg(extraCommonCss(headerFont));
}
void CSSHelperBase::setBodyFont(const QFont &font)
......
......@@ -43,6 +43,7 @@ class QString;
class QPaintDevice;
namespace MessageViewer {
class HeaderStylePlugin;
class MESSAGEVIEWER_EXPORT CSSHelperBase
{
public:
......@@ -81,9 +82,11 @@ public:
Q_REQUIRED_RESULT QString addEndBlockQuote(int numberBlock) const;
Q_REQUIRED_RESULT QString addStartBlockQuote(int numberBlock) const;
virtual Q_REQUIRED_RESULT QString extraScreenCss() const;
virtual Q_REQUIRED_RESULT QString extraPrintCss() const;
virtual Q_REQUIRED_RESULT QString extraCommonCss() const;
virtual Q_REQUIRED_RESULT QString extraScreenCss(const QString &headerFont) const;
virtual Q_REQUIRED_RESULT QString extraPrintCss(const QString &headerFont) const;
virtual Q_REQUIRED_RESULT QString extraCommonCss(const QString &headerFont) const;
void setHeaderPlugin(const HeaderStylePlugin *headerPlugin);
protected:
/** Recalculate PGP frame and body colors (should be called after changing
......@@ -140,11 +143,12 @@ private:
// returns CSS rules common to both screen and print media types
QString commonCssDefinitions() const;
QString fullAddressList() const;
QString linkColorDefinition() const;
protected:
int pointsToPixel(const QPaintDevice *pd, int pointSize) const;
QString linkColorDefinition() const;
QString defaultScreenHeaderFont() const;
QString defaultPrintHeaderFont() const;
private:
const QPaintDevice *mPaintDevice = nullptr;
const HeaderStylePlugin *mHeaderPlugin = nullptr;
};
}
......
......@@ -27,7 +27,7 @@
#include "viewer.h"
#include "viewer_p.h"
#include "widgets/configurewidget.h"
#include "cssfancyhelper.h"
#include "csshelper.h"
#include "settings/messageviewersettings.h"
#include "viewer/webengine/mailwebengineview.h"
#include <WebEngineViewer/WebHitTestResult>
......
......@@ -102,7 +102,6 @@
//own includes
#include "widgets/attachmentdialog.h"
#include "csshelper.h"
#include "cssfancyhelper.h"
#include "settings/messageviewersettings.h"
#include "widgets/htmlstatusbar.h"
#include "viewer/attachmentstrategy.h"
......@@ -1125,7 +1124,7 @@ void ViewerPrivate::readGravatarConfig()
void ViewerPrivate::recreateCssHelper()
{
delete mCSSHelper;
mCSSHelper = new CSSFancyHelper(mViewer);
mCSSHelper = new CSSHelper(mViewer);
}
void ViewerPrivate::slotGeneralFontChanged()
......@@ -1515,6 +1514,7 @@ void ViewerPrivate::createWidgets()
void ViewerPrivate::slotStyleChanged(MessageViewer::HeaderStylePlugin *plugin)
{
mCSSHelper->setHeaderPlugin(plugin);
mHeaderStylePlugin = plugin;
update(MimeTreeParser::Force);
}
......@@ -1528,7 +1528,6 @@ void ViewerPrivate::createActions()
{
KActionCollection *ac = mActionCollection;
mHeaderStyleMenuManager = new MessageViewer::HeaderStyleMenuManager(ac, this);
mHeaderStyleMenuManager->setViewer(mViewer);
connect(mHeaderStyleMenuManager, &MessageViewer::HeaderStyleMenuManager::styleChanged, this,
&ViewerPrivate::slotStyleChanged);
connect(mHeaderStyleMenuManager, &MessageViewer::HeaderStyleMenuManager::styleUpdated, this,
......
......@@ -42,55 +42,6 @@ table.signErr,
table.signOkKeyBad,
table.signOkKeyOk,
table.signInProgress,
div.fancy.header table {
width: 100% ! important;
border-width: 0px ! important;
line-height: normal;
}
div.fancy.header > div {
font-weight: bold ! important;
padding: 4px ! important;
line-height: normal;
}
div.fancy.header table {
padding: 2px ! important;
text-align: left ! important;
border-collapse: separate ! important;
}
div.fancy.header table th {
font-family: "Sans Serif" ! important;
font-size: 0px ! important;
padding: 0px ! important;
white-space: nowrap ! important;
border-spacing: 0px ! important;
text-align: left ! important;
vertical-align: top ! important;
background-color: #d6d2d0 ! important;
color: #221f1e ! important;
border: 1px ! important;
}
div.fancy.header table td {
font-family: "Sans Serif" ! important;
font-size: 0px ! important;
padding: 0px ! important;
border-spacing: 0px ! important;
text-align: left ! important;
vertical-align: top ! important;
width: 100% ! important;
background-color: #d6d2d0 ! important;
color: #221f1e ! important;
border: 1px ! important;
}
div.fancy.header table a:hover {
background-color: transparent ! important;
}
div.htmlWarn {
margin: 0px 5% ! important;
......@@ -224,34 +175,6 @@ div.header {
font-size: 0px ! important;
}
div.fancy.header > div {
background-color: #43ace8 ! important;
color: #ffffff ! important;
border: solid #221f1e 1px ! important;
line-height: normal;
}
div.fancy.header > div a[href] { color: #ffffff ! important; }
div.fancy.header > div a[href]:hover { text-decoration: underline ! important; }
div.fancy.header > div.spamheader {
background-color: #cdcdcd ! important;
border-top: 0px ! important;
padding: 3px ! important;
color: black ! important;
font-weight: bold ! important;
font-size: smaller ! important;
}
div.fancy.header > table.outer {
background-color: #d6d2d0 ! important;
color: #221f1e ! important;
border-bottom: solid #221f1e 1px ! important;
border-left: solid #221f1e 1px ! important;
border-right: solid #221f1e 1px ! important;
}
div.senderpic{
padding: 0px ! important;
font-size:0.8em ! important;
......@@ -407,24 +330,6 @@ div.header {
font-size: 9pt ! important;
}
div.fancy.header > div {
background-color: #d6d2d0 ! important;
color: #221f1e ! important;
padding: 4px ! important;
border: solid #221f1e 1px ! important;
line-height: normal;
}
div.fancy.header > div a[href] { color: #221f1e ! important; }
div.fancy.header > table.outer{
background-color: #d6d2d0 ! important;
color: #221f1e ! important;
border-bottom: solid #221f1e 1px ! important;
border-left: solid #221f1e 1px ! important;
border-right: solid #221f1e 1px ! important;
}
div.spamheader {
display:none ! important;
}
......