aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktextnodeengine.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2021-05-06 17:43:32 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2021-05-07 19:58:09 +0200
commit1d44ddf57671399a9fa3a7dadab8d448ce7b52e7 (patch)
treeebbf405791fe02eb72695920883ef4a120b46501 /src/quick/items/qquicktextnodeengine.cpp
parenta0f0f4fa54fe8e9fa6526ef6ccde5eb5cbc73450 (diff)
Add support for QTextCharFormat::underlineColor in highlighers and CSS
When a QSyntaxHighlighter calls setUnderlineColor(), TextEdit will use that color for underline, overline and strikeout rendering. Likewise when Text has textFormat: Text.RichText and the HTML contains CSS styling specifying text-decoration-color, it will be applied (depending on the css support in QTextHtmlParser to call setUnderlineColor()). Added a manual test. [ChangeLog][QtQuick][TextEdit] When a QSyntaxHighlighter calls QTextFormat::setUnderlineColor(), or CSS style contains text-decoration-color, Text and TextEdit will now use that color for underline, overline and strikeout rendering. Task-number: QTBUG-87260 Task-number: QTBUG-74572 Task-number: QTBUG-39617 Change-Id: Ia2b564d5366ff67bb5df4f6c9e68ff5773ca5d6a Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/items/qquicktextnodeengine.cpp')
-rw-r--r--src/quick/items/qquicktextnodeengine.cpp39
1 files changed, 32 insertions, 7 deletions
diff --git a/src/quick/items/qquicktextnodeengine.cpp b/src/quick/items/qquicktextnodeengine.cpp
index dd666416e8..5c25ecf429 100644
--- a/src/quick/items/qquicktextnodeengine.cpp
+++ b/src/quick/items/qquicktextnodeengine.cpp
@@ -71,7 +71,7 @@ QQuickTextNodeEngine::BinaryTreeNode::BinaryTreeNode(const QGlyphRun &g,
const QRectF &brect,
const Decorations &decs,
const QColor &c,
- const QColor &bc,
+ const QColor &bc, const QColor &dc,
const QPointF &pos, qreal a)
: glyphRun(g)
, boundingRect(brect)
@@ -80,6 +80,7 @@ QQuickTextNodeEngine::BinaryTreeNode::BinaryTreeNode(const QGlyphRun &g,
, decorations(decs)
, color(c)
, backgroundColor(bc)
+ , decorationColor(dc)
, position(pos)
, ascent(a)
, leftChildIndex(-1)
@@ -92,7 +93,7 @@ QQuickTextNodeEngine::BinaryTreeNode::BinaryTreeNode(const QGlyphRun &g,
void QQuickTextNodeEngine::BinaryTreeNode::insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const QGlyphRun &glyphRun, SelectionState selectionState,
Decorations decorations, const QColor &textColor,
- const QColor &backgroundColor, const QPointF &position)
+ const QColor &backgroundColor, const QColor &decorationColor, const QPointF &position)
{
QRectF searchRect = glyphRun.boundingRect();
searchRect.translate(position);
@@ -112,6 +113,7 @@ void QQuickTextNodeEngine::BinaryTreeNode::insert(QVarLengthArray<BinaryTreeNode
decorations,
textColor,
backgroundColor,
+ decorationColor,
position,
ascent));
}
@@ -252,6 +254,7 @@ void QQuickTextNodeEngine::processCurrentLine()
QColor lastColor;
QColor lastBackgroundColor;
+ QColor lastDecorationColor;
QVarLengthArray<TextDecoration> pendingUnderlines;
QVarLengthArray<TextDecoration> pendingOverlines;
@@ -280,6 +283,12 @@ void QQuickTextNodeEngine::processCurrentLine()
decorationRect.setRight(node->boundingRect.left());
TextDecoration textDecoration(currentSelectionState, decorationRect, lastColor);
+ if (lastDecorationColor.isValid() &&
+ (currentDecorations.testFlag(Decoration::Underline) ||
+ currentDecorations.testFlag(Decoration::Overline) ||
+ currentDecorations.testFlag(Decoration::StrikeOut)))
+ textDecoration.color = lastDecorationColor;
+
if (currentDecorations & Decoration::Underline)
pendingUnderlines.append(textDecoration);
@@ -398,6 +407,7 @@ void QQuickTextNodeEngine::processCurrentLine()
currentDecorations = node->decorations;
lastColor = node->color;
lastBackgroundColor = node->backgroundColor;
+ lastDecorationColor = node->decorationColor;
m_processedNodes.append(*node);
}
}
@@ -511,6 +521,7 @@ void QQuickTextNodeEngine::addUnselectedGlyphs(const QGlyphRun &glyphRun)
Decoration::NoDecoration,
m_textColor,
m_backgroundColor,
+ m_decorationColor,
m_position);
}
@@ -523,6 +534,7 @@ void QQuickTextNodeEngine::addSelectedGlyphs(const QGlyphRun &glyphRun)
Decoration::NoDecoration,
m_textColor,
m_backgroundColor,
+ m_decorationColor,
m_position);
m_hasSelection = m_hasSelection || m_currentLineTree.size() > currentSize;
}
@@ -540,7 +552,7 @@ void QQuickTextNodeEngine::addGlyphsForRanges(const QVarLengthArray<QTextLayout:
if (range.start > currentPosition) {
addGlyphsInRange(currentPosition, range.start - currentPosition,
- QColor(), QColor(), selectionStart, selectionEnd);
+ QColor(), QColor(), QColor(), selectionStart, selectionEnd);
}
int rangeEnd = qMin(range.start + range.length, currentPosition + remainingLength);
QColor rangeColor;
@@ -552,8 +564,12 @@ void QQuickTextNodeEngine::addGlyphsForRanges(const QVarLengthArray<QTextLayout:
? range.format.background().color()
: QColor();
+ QColor rangeDecorationColor = range.format.hasProperty(QTextFormat::TextUnderlineColor)
+ ? range.format.underlineColor()
+ : QColor();
+
addGlyphsInRange(range.start, rangeEnd - range.start,
- rangeColor, rangeBackgroundColor,
+ rangeColor, rangeBackgroundColor, rangeDecorationColor,
selectionStart, selectionEnd);
currentPosition = range.start + range.length;
@@ -565,14 +581,14 @@ void QQuickTextNodeEngine::addGlyphsForRanges(const QVarLengthArray<QTextLayout:
}
if (remainingLength > 0) {
- addGlyphsInRange(currentPosition, remainingLength, QColor(), QColor(),
+ addGlyphsInRange(currentPosition, remainingLength, QColor(), QColor(), QColor(),
selectionStart, selectionEnd);
}
}
void QQuickTextNodeEngine::addGlyphsInRange(int rangeStart, int rangeLength,
- const QColor &color, const QColor &backgroundColor,
+ const QColor &color, const QColor &backgroundColor, const QColor &decorationColor,
int selectionStart, int selectionEnd)
{
QColor oldColor;
@@ -587,6 +603,12 @@ void QQuickTextNodeEngine::addGlyphsInRange(int rangeStart, int rangeLength,
m_backgroundColor = backgroundColor;
}
+ QColor oldDecorationColor = m_decorationColor;
+ if (decorationColor.isValid()) {
+ oldDecorationColor = m_decorationColor;
+ m_decorationColor = decorationColor;
+ }
+
bool hasSelection = selectionEnd >= 0
&& selectionStart <= selectionEnd;
@@ -630,6 +652,9 @@ void QQuickTextNodeEngine::addGlyphsInRange(int rangeStart, int rangeLength,
}
}
+ if (decorationColor.isValid())
+ m_decorationColor = oldDecorationColor;
+
if (backgroundColor.isValid())
m_backgroundColor = oldBackgroundColor;
@@ -1100,7 +1125,7 @@ void QQuickTextNodeEngine::addTextBlock(QTextDocument *textDocument, const QText
fragmentEnd += preeditLength;
}
#endif
- if (charFormat.background().style() != Qt::NoBrush) {
+ if (charFormat.background().style() != Qt::NoBrush || charFormat.hasProperty(QTextFormat::TextUnderlineColor)) {
QTextLayout::FormatRange additionalFormat;
additionalFormat.start = textPos - block.position();
additionalFormat.length = fragmentEnd - textPos;