aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktextnodeengine.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2021-10-12 11:33:20 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2021-10-14 20:55:59 +0200
commiteca6bd485436f9ddf16036b98c993b7ffeb7e6c4 (patch)
treedac540971fa9c6e5e1156846f7d37c0d2607b0f6 /src/quick/items/qquicktextnodeengine.cpp
parentd062846cb6e3fc1699b34ea4e108c77e8fc74890 (diff)
Implement horizontal rule rendering in text
The rule is just a line drawn with the same thickness as an underline: it gets thicker as DPR increases. A horizontal rule can be created via <hr/> in RichText. In markdown it's called a "thematic break," and a line with - - - is one way to create it: https://spec.commonmark.org/0.30/#thematic-breaks <hr width=70/> or <hr width=70%> set the width in pixels, and percent of the text width, respectively; the rule will be centered within the line's bounding box in that case, as in QTextEdit etc. The color can come from QTextFormat::BackgroundBrush if it's set on the QTextBlockFormat, but otherwise falls back to the text color. This can be done with CSS styling: <hr style="background-color:green;"/> [ChangeLog][QtQuick][Text] Horizontal rules (thematic breaks in markdown) are now rendered as simple horizontal lines, either in the same color as the text, or as specified via CSS background-color. Fixes: QTBUG-74342 Task-number: QTBUG-81306 Change-Id: I64f9daf28994225d1a8383d8e2e01e611a0a0237 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/quick/items/qquicktextnodeengine.cpp')
-rw-r--r--src/quick/items/qquicktextnodeengine.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/quick/items/qquicktextnodeengine.cpp b/src/quick/items/qquicktextnodeengine.cpp
index b3401200c8..4d1784a979 100644
--- a/src/quick/items/qquicktextnodeengine.cpp
+++ b/src/quick/items/qquicktextnodeengine.cpp
@@ -1154,6 +1154,17 @@ void QQuickTextNodeEngine::addTextBlock(QTextDocument *textDocument, const QText
}
#endif
+ // Add block decorations (so far only horizontal rules)
+ if (block.blockFormat().hasProperty(QTextFormat::BlockTrailingHorizontalRulerWidth)) {
+ auto ruleLength = qvariant_cast<QTextLength>(block.blockFormat().property(QTextFormat::BlockTrailingHorizontalRulerWidth));
+ QRectF ruleRect(0, 0, ruleLength.value(blockBoundingRect.width()), 1);
+ ruleRect.moveCenter(blockBoundingRect.center());
+ const QColor ruleColor = block.blockFormat().hasProperty(QTextFormat::BackgroundBrush)
+ ? qvariant_cast<QBrush>(block.blockFormat().property(QTextFormat::BackgroundBrush)).color()
+ : m_textColor;
+ m_lines.append(TextDecoration(QQuickTextNodeEngine::Unselected, ruleRect, ruleColor));
+ }
+
setCurrentLine(QTextLine()); // Reset current line because the text layout changed
m_hasContents = true;
}