diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-10-12 13:46:24 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-10-14 17:09:20 +0200 |
commit | 5c436365f579f820344566101e746e244672995a (patch) | |
tree | 38fd5c22de7d6474ae000d3983616aa1fb3d9246 /src | |
parent | f83a3c4b6e703d3d6b48f2f8d2f71ab69c084b8f (diff) |
Support background-color CSS styling on <hr/>
[ChangeLog][QtGui][CSS] The background-color style can now be applied to
<hr/> to set the rule color.
Task-number: QTBUG-74342
Change-Id: Ib960ce4d38caa225f258b6d228fb794cef43e1b7
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 12 | ||||
-rw-r--r-- | src/gui/text/qtextdocumentlayout.cpp | 9 | ||||
-rw-r--r-- | src/gui/text/qtexthtmlparser.cpp | 2 |
3 files changed, 19 insertions, 4 deletions
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>") + title + QString::fromLatin1("</title>"); html += QLatin1String("<style type=\"text/css\">\n"); html += QLatin1String("p, li { white-space: pre-wrap; }\n"); + html += QLatin1String("hr { height: 1px; border-width: 0; }\n"); html += QLatin1String("</style>"); html += QLatin1String("</head><body"); @@ -3047,8 +3048,15 @@ void QTextHtmlExporter::emitBlock(const QTextBlock &block) QTextLength width = blockFormat.lengthProperty(QTextFormat::BlockTrailingHorizontalRulerWidth); if (width.type() != QTextLength::VariableLength) emitTextLength("width", width); - else - html += QLatin1Char(' '); + html += QLatin1Char(' '); + + if (blockFormat.hasProperty(QTextFormat::BackgroundBrush)) { + html += QLatin1String("style=\""); + html += QLatin1String("background-color:"); + html += colorValue(qvariant_cast<QBrush>(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 <hr>, 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<QTextLayout::FormatRange> 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<QBrush>(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<QCss::Declaration> &d applyBackgroundImage(bgImage, resourceProvider); } else if (bgBrush.style() != Qt::NoBrush) { charFormat.setBackground(bgBrush); + if (id == Html_hr) + blockFormat.setProperty(QTextFormat::BackgroundBrush, bgBrush); } } } |