32 #include <messagecore/settings/globalsettings.h>
35 #include <KColorScheme>
38 #include <KGlobalSettings>
40 #include <QApplication>
41 #include <QPaintDevice>
43 namespace MessageViewer {
47 inline QColor darker(
const QColor & c ) {
49 c.getHsv( &h, &s, &v );
50 return QColor::fromHsv( h, s, v*4/5 );
53 inline QColor desaturate(
const QColor & c ) {
55 c.getHsv( &h, &s, &v );
56 return QColor::fromHsv( h, s/8, v );
59 inline QColor fixValue(
const QColor & c,
int newV ) {
61 c.getHsv( &h, &s, &v );
62 return QColor::fromHsv( h, s, newV );
65 inline int getValueOf(
const QColor & c ) {
67 c.getHsv( &h, &s, &v );
73 mShrinkQuotes( false ),
78 mLinkColor = KColorScheme( QPalette::Active, KColorScheme::View ).foreground( KColorScheme::LinkText ).color();
79 mVisitedLinkColor = KColorScheme( QPalette::Active, KColorScheme::View ).foreground( KColorScheme::VisitedText ).color();
84 cPgpOk1H = QColor( 0x40, 0xFF, 0x40 );
85 cPgpOk0H = QColor( 0xFF, 0xFF, 0x40 );
89 if(MessageCore::GlobalSettings::self()->useDefaultColors()) {
90 for (
int i = 0 ; i < 3 ; ++i ) {
91 mQuoteColor[i] = QColor( 0x00, 0x80 - i * 0x10, 0x00 );
94 mQuoteColor[0] = MessageCore::GlobalSettings::self()->quotedText1();
95 mQuoteColor[1] = MessageCore::GlobalSettings::self()->quotedText2();
96 mQuoteColor[2] = MessageCore::GlobalSettings::self()->quotedText3();
100 QFont defaultFont = KGlobalSettings::generalFont();
101 QFont defaultFixedFont = KGlobalSettings::fixedFont();
102 mBodyFont = MessageCore::GlobalSettings::self()->useDefaultFonts() ? defaultFont: MessageCore::GlobalSettings::self()->bodyFont();
103 mPrintFont = MessageCore::GlobalSettings::self()->useDefaultFonts() ? defaultFont : MessageCore::GlobalSettings::self()->printFont();
105 defaultFont.setItalic(
true );
106 for (
int i = 0 ; i < 3 ; ++i )
127 const bool lightBG = vBG >= 128;
167 commonCssDefinitions()
169 QLatin1String(
"@media screen {\n\n")
171 screenCssDefinitions(
this, fixed )
174 "@media print {\n\n")
176 printCssDefinitions( fixed )
183 QLatin1String(
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
184 "<html><head><title></title></head>\n"
193 ? level % numQuoteLevels + 1
194 : qMin( level + 1, numQuoteLevels ) ;
195 if ( level >= numQuoteLevels )
196 return QString::fromLatin1(
"<div class=\"deepquotelevel%1\">" ).arg( effectiveLevel );
198 return QString::fromLatin1(
"<div class=\"quotelevel%1\">" ).arg( effectiveLevel );
202 return QLatin1String(
"<div class=\"noquote\">");
210 int CSSHelperBase::fontSize(
bool fixed,
bool print )
const {
211 return bodyFont( fixed, print ).pointSize();
216 int pointsToPixel(
const QPaintDevice *pd,
int pointSize ) {
217 return ( pointSize * pd->logicalDpiY() + 36 ) / 72 ;
223 QString CSSHelperBase::printCssDefinitions(
bool fixed )
const {
224 const QString headerFont = QString::fromLatin1(
" font-family: \"%1\" ! important;\n"
225 " font-size: %2pt ! important;\n" )
228 const QPalette &pal = QApplication::palette();
230 const QFont printFont =
bodyFont( fixed,
true );
232 if ( printFont.italic() )
233 quoteCSS += QLatin1String(
" font-style: italic ! important;\n");
234 if ( printFont.bold() )
235 quoteCSS += QLatin1String(
" font-weight: bold ! important;\n");
236 if ( !quoteCSS.isEmpty() )
237 quoteCSS = QLatin1String(
"div.noquote {\n") + quoteCSS + QLatin1String(
"}\n\n");
240 QString::fromLatin1(
"body {\n"
241 " font-family: \"%1\" ! important;\n"
242 " font-size: %2pt ! important;\n"
243 " color: #000000 ! important;\n"
244 " background-color: #ffffff ! important\n"
246 .arg( printFont.family(),
247 QString::number( printFont.pointSize() ) )
249 QString::fromLatin1(
"tr.textAtmH,\n"
250 "tr.signInProgressH,\n"
254 "tr.signOkKeyBadH,\n"
261 "div.fancy.header > div {\n"
262 " background-color: %2 ! important;\n"
263 " color: %3 ! important;\n"
264 " padding: 4px ! important;\n"
265 " border: solid %3 1px ! important;\n"
266 " line-height: normal;\n"
269 "div.fancy.header > div a[href] { color: %3 ! important; }\n\n"
271 "div.fancy.header > table.outer{\n"
272 " background-color: %2 ! important;\n"
273 " color: %3 ! important;\n"
274 " border-bottom: solid %3 1px ! important;\n"
275 " border-left: solid %3 1px ! important;\n"
276 " border-right: solid %3 1px ! important;\n"
280 " display:none ! important;\n"
284 " border: 2px solid #ffffff ! important;\n"
285 " line-height: normal;\n"
289 " font-size:0.8em ! important;\n"
290 " border:1px solid black ! important;\n"
291 " background-color:%2 ! important;\n"
294 "div.senderstatus{\n"
295 " text-align:center ! important;\n"
299 " display:none ! important;\n"
303 pal.color( QPalette::Background ).name(),
304 pal.color( QPalette::Foreground ).name() )
308 QString CSSHelperBase::screenCssDefinitions(
const CSSHelperBase * helper,
bool fixed )
const {
312 const QString headerFont = QString::fromLatin1(
" font-family: \"%1\" ! important;\n"
313 " font-size: %2px ! important;\n")
315 .arg( pointsToPixel( helper->mPaintDevice,
mBodyFont.pointSize() ) );
317 ? QString::fromLatin1(
" background-image:url(file:///%1) ! important;\n" )
319 : QString::fromLatin1(
" background-color: %1 ! important;\n" )
321 const QString bodyFontSize = QString::number( pointsToPixel( helper->mPaintDevice, fontSize( fixed ) ) ) + QLatin1String(
"px");
322 const QPalette & pal = QApplication::palette();
326 quoteCSS += QLatin1String(
" font-style: italic ! important;\n");
328 quoteCSS += QLatin1String(
" font-weight: bold ! important;\n");
329 if ( !quoteCSS.isEmpty() )
330 quoteCSS = QLatin1String(
"div.noquote {\n") + quoteCSS + QLatin1String(
"}\n\n");
333 for (
int i = 0 ; i < 3 ; ++i ) {
334 quoteCSS += QString::fromLatin1(
"div.quotelevel%1 {\n"
335 " color: %2 ! important;\n" )
336 .arg( QString::number(i+1),
mQuoteColor[i].name() );
338 quoteCSS += QLatin1String(
" font-style: italic ! important;\n");
340 quoteCSS += QLatin1String(
" font-weight: bold ! important;\n");
342 quoteCSS += QLatin1String(
" font-size: ") + QString::fromLatin1(
quoteFontSizes[i] )
343 + QLatin1String(
"% ! important;\n");
344 quoteCSS += QLatin1String(
"}\n\n");
348 for (
int i = 0 ; i < 3 ; ++i ) {
349 quoteCSS += QString::fromLatin1(
"div.deepquotelevel%1 {\n"
350 " color: %2 ! important;\n" )
351 .arg( QString::number(i+1),
mQuoteColor[i].name() );
353 quoteCSS += QLatin1String(
" font-style: italic ! important;\n");
355 quoteCSS += QLatin1String(
" font-weight: bold ! important;\n");
357 quoteCSS += QLatin1String(
" font-size: 70% ! important;\n");
358 quoteCSS += QLatin1String(
"}\n\n");
362 QString::fromLatin1(
"body {\n"
363 " font-family: \"%1\" ! important;\n"
364 " font-size: %2 ! important;\n"
365 " color: %3 ! important;\n"
383 QString::fromLatin1(
"a {\n"
384 " color: %1 ! important;\n"
385 " text-decoration: none ! important;\n"
389 " color: white ! important;\n"
393 " color: black ! important;\n"
396 "table.textAtm { background-color: %2 ! important; }\n\n"
399 " background-color: %3 ! important;\n"
404 " background-color: %3 ! important;\n"
407 "table.signInProgress,\n"
409 " background-color: %3 ! important;\n"
412 "tr.signInProgressH,\n"
416 .arg( linkColor, fgColor, bgColor, headerFont )
418 QString::fromLatin1(
"table.encr {\n"
419 " background-color: %1 ! important;\n"
423 " background-color: %2 ! important;\n"
427 "tr.encrB { background-color: %4 ! important; }\n\n" )
433 QString::fromLatin1(
"table.signOkKeyOk {\n"
434 " background-color: %1 ! important;\n"
437 "tr.signOkKeyOkH {\n"
438 " background-color: %2 ! important;\n"
442 "tr.signOkKeyOkB { background-color: %4 ! important; }\n\n" )
448 QString::fromLatin1(
"table.signOkKeyBad {\n"
449 " background-color: %1 ! important;\n"
452 "tr.signOkKeyBadH {\n"
453 " background-color: %2 ! important;\n"
457 "tr.signOkKeyBadB { background-color: %4 ! important; }\n\n" )
463 QString::fromLatin1(
"table.signWarn {\n"
464 " background-color: %1 ! important;\n"
468 " background-color: %2 ! important;\n"
472 "tr.signWarnB { background-color: %4 ! important; }\n\n" )
478 QString::fromLatin1(
"table.signErr {\n"
479 " background-color: %1 ! important;\n"
483 " background-color: %2 ! important;\n"
487 "tr.signErrB { background-color: %4 ! important; }\n\n" )
493 QString::fromLatin1(
"div.htmlWarn {\n"
494 " border: 2px solid %1 ! important;\n"
495 " line-height: normal;\n"
499 QString::fromLatin1(
"div.header {\n"
503 "div.fancy.header > div {\n"
504 " background-color: %2 ! important;\n"
505 " color: %3 ! important;\n"
506 " border: solid %4 1px ! important;\n"
507 " line-height: normal;\n"
510 "div.fancy.header > div a[href] { color: %3 ! important; }\n\n"
512 "div.fancy.header > div a[href]:hover { text-decoration: underline ! important; }\n\n"
514 "div.fancy.header > div.spamheader {\n"
515 " background-color: #cdcdcd ! important;\n"
516 " border-top: 0px ! important;\n"
517 " padding: 3px ! important;\n"
518 " color: black ! important;\n"
519 " font-weight: bold ! important;\n"
520 " font-size: smaller ! important;\n"
523 "div.fancy.header > table.outer {\n"
524 " background-color: %5 ! important;\n"
525 " color: %4 ! important;\n"
526 " border-bottom: solid %4 1px ! important;\n"
527 " border-left: solid %4 1px ! important;\n"
528 " border-right: solid %4 1px ! important;\n"
532 " padding: 0px ! important;\n"
533 " font-size:0.8em ! important;\n"
534 " border:1px solid %6 ! important;\n"
537 " background-color:%5 ! important;\n"
540 "div.senderstatus{\n"
541 " text-align:center ! important;\n"
546 .arg( pal.color( QPalette::Highlight ).name(),
547 pal.color( QPalette::HighlightedText ).name(),
548 pal.color( QPalette::Foreground ).name(),
549 pal.color( QPalette::Background ).name() )
550 .arg( pal.color( QPalette::Mid ).name() )
554 QString CSSHelperBase::commonCssDefinitions()
const {
555 const QPalette & pal = QApplication::palette();
556 const QString headerFont = QString::fromLatin1(
"font-family: \"%1\" ! important;\n"
557 " font-size: %2px ! important;\n")
559 .arg( pointsToPixel( this->mPaintDevice,
mBodyFont.pointSize() ) );
562 QString::fromLatin1(
"div.header {\n"
563 " margin-bottom: 10pt ! important;\n"
567 " margin-top: 10pt ! important;\n"
568 " margin-bottom: 10pt ! important;\n"
574 " font-weight: normal ! important;\n"
577 "tr.signInProgressH,\n"
581 "tr.signOkKeyBadH,\n"
584 " font-weight: bold ! important;\n"
589 " padding: 3px ! important;\n"
593 " width: 100% ! important;\n"
594 " border: solid 1px black ! important;\n"
595 " margin-top: 10pt ! important;\n"
596 " margin-bottom: 10pt ! important;\n"
603 "table.signOkKeyBad,\n"
604 "table.signOkKeyOk,\n"
605 "table.signInProgress,\n"
606 "div.fancy.header table {\n"
607 " width: 100% ! important;\n"
608 " border-width: 0px ! important;\n"
609 " line-height: normal;\n"
613 " margin: 0px 5% ! important;\n"
614 " padding: 10px ! important;\n"
615 " text-align: left ! important;\n"
616 " line-height: normal;\n"
619 "div.fancy.header > div {\n"
620 " font-weight: bold ! important;\n"
621 " padding: 4px ! important;\n"
622 " line-height: normal;\n"
625 "div.fancy.header table {\n"
626 " padding: 2px ! important;\n"
627 " text-align: left ! important;\n"
628 " border-collapse: separate ! important;\n"
631 "div.fancy.header table th {\n"
633 " padding: 0px ! important;\n"
634 " white-space: nowrap ! important;\n"
635 " border-spacing: 0px ! important;\n"
636 " text-align: left ! important;\n"
637 " vertical-align: top ! important;\n"
638 " background-color: %1 ! important;\n"
639 " color: %2 ! important;\n"
640 " border: 1px ! important;\n"
644 "div.fancy.header table td {\n"
646 " padding: 0px ! important;\n"
647 " border-spacing: 0px ! important;\n"
648 " text-align: left ! important;\n"
649 " vertical-align: top ! important;\n"
650 " width: 100% ! important;\n"
651 " background-color: %1 ! important;\n"
652 " color: %2 ! important;\n"
653 " border: 1px ! important;\n"
657 "div.fancy.header table a:hover {\n"
658 " background-color: transparent ! important;\n"
661 "span.pimsmileytext {\n"
662 " position: absolute;\n"
665 " visibility: hidden;\n"
668 "img.pimsmileyimg {\n"
671 "div.quotelevelmark {\n"
672 " position: absolute;\n"
673 " margin-left:-10px;\n"
674 "}\n\n").arg( pal.color( QPalette::Background ).name() ).arg(pal.color( QPalette::Foreground ).name()).arg(headerFont)
691 const int actualLevel = qMin( qMax( level, 0 ), 2 );
QString nonQuotedFontTag() const
void recalculatePGPColors()
Recalculate PGP frame and body colors (should be called after changing color settings) ...
void setPrintFont(const QFont &font)
QFont bodyFont(bool fixedFont=false, bool printing=false) const
void setBodyFont(const QFont &font)
QString cssDefinitions(bool fixedFont=false) const
QString quoteFontTag(int level) const
QString mBackingPixmapStr
QColor pgpWarnColor() const
QColor quoteColor(int level)
QString htmlHead(bool fixedFont=false) const
CSSHelperBase(const QPaintDevice *pd)
Construct a CSSHelper object and set its font and color settings to default values.
static const char *const quoteFontSizes[]