From 5c436365f579f820344566101e746e244672995a Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Tue, 12 Oct 2021 13:46:24 +0200 Subject: Support background-color CSS styling on
[ChangeLog][QtGui][CSS] The background-color style can now be applied to
to set the rule color. Task-number: QTBUG-74342 Change-Id: Ib960ce4d38caa225f258b6d228fb794cef43e1b7 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qtextdocument.cpp | 12 ++++++++++-- src/gui/text/qtextdocumentlayout.cpp | 9 +++++++-- src/gui/text/qtexthtmlparser.cpp | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src/gui/text') diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index d3bec57bd4..68cdbc092e 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -2359,6 +2359,7 @@ QString QTextHtmlExporter::toHtml(ExportMode mode) html += QString::fromLatin1("") + title + QString::fromLatin1(""); html += QLatin1String(""); html += QLatin1String("(blockFormat.property(QTextFormat::BackgroundBrush)).color()); + html += QLatin1Char(';'); + html += QLatin1Char('\"'); + } html += QLatin1String("/>"); return; diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index abc062bc91..77361d4608 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -2044,7 +2044,9 @@ void QTextDocumentLayoutPrivate::drawBlock(const QPointF &offset, QPainter *pain rect.setRight((fd->size.width - fd->rightMargin).toReal()); } - fillBackground(painter, rect, bg, r.topLeft()); + // in the case of
, the background-color CSS style fills only the rule's thickness instead of the whole line + if (!blockFormat.hasProperty(QTextFormat::BlockTrailingHorizontalRulerWidth)) + fillBackground(painter, rect, bg, r.topLeft()); } QList selections; @@ -2104,7 +2106,10 @@ void QTextDocumentLayoutPrivate::drawBlock(const QPointF &offset, QPainter *pain if (blockFormat.hasProperty(QTextFormat::BlockTrailingHorizontalRulerWidth)) { const qreal width = blockFormat.lengthProperty(QTextFormat::BlockTrailingHorizontalRulerWidth).value(r.width()); - painter->setPen(context.palette.color(QPalette::Dark)); + const auto color = blockFormat.hasProperty(QTextFormat::BackgroundBrush) + ? qvariant_cast(blockFormat.property(QTextFormat::BackgroundBrush)).color() + : context.palette.color(QPalette::Dark); + painter->setPen(color); qreal y = r.bottom(); if (bl.length() == 1) y = r.top() + r.height() / 2; diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp index 6a9f7d3a96..ae2550b69e 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -1453,6 +1453,8 @@ void QTextHtmlParserNode::applyCssDeclarations(const QList &d applyBackgroundImage(bgImage, resourceProvider); } else if (bgBrush.style() != Qt::NoBrush) { charFormat.setBackground(bgBrush); + if (id == Html_hr) + blockFormat.setProperty(QTextFormat::BackgroundBrush, bgBrush); } } } -- cgit v1.2.3