From 3a0cec6525be6bf843c597c19693785e2c893ee9 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 27 Nov 2012 12:26:53 +1000 Subject: Ensure QDeclarativeTextLayout uses the correct pen When a styled text specifies a font region with some color set, QDeclarativeTextLayout used to revert to using a default-constructed (black-colored) pen for text occurring after the tag, rather than the "default" (property-defined) color. This commit ensures that the correct pen is used, by setting the pen of the "inert" painter to be an invalid color rather than a default constructed pen. It then detects when the current pen transitions back to this invalid pen, and switches back to using the default color. Task-number: QTBUG-28135 Change-Id: I6bcc43fbcf7fb2c680959d27b1422364ebb473ae Reviewed-by: Alan Alpert Reviewed-by: Robin Burchell --- src/declarative/graphicsitems/qdeclarativetextlayout.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/declarative/graphicsitems') diff --git a/src/declarative/graphicsitems/qdeclarativetextlayout.cpp b/src/declarative/graphicsitems/qdeclarativetextlayout.cpp index 14a41c05..1eea36eb 100644 --- a/src/declarative/graphicsitems/qdeclarativetextlayout.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextlayout.cpp @@ -237,7 +237,10 @@ class DrawTextItemDevice: public QPaintDevice struct InertTextPainter { InertTextPainter() - : device(true, true), painter(&device) {} + : device(true, true), painter(&device) + { + painter.setPen(QPen(QColor())); // explicitly invalid color. + } DrawTextItemDevice device; QPainter painter; @@ -373,11 +376,19 @@ void QDeclarativeTextLayout::draw(QPainter *painter, const QPointF &p) QPen oldPen = priv->state->pen; QColor currentColor = oldPen.color(); + QColor defaultColor = currentColor; for (int ii = 0; ii < itemCount; ++ii) { QStaticTextItem &item = d->items[ii]; if (item.color.isValid() && currentColor != item.color) { + // up-edge of a text tag + // we set the painter pen to the text item's specified color. painter->setPen(item.color); currentColor = item.color; + } else if (!item.color.isValid() && currentColor != defaultColor) { + // down-edge of a text tag + // we reset the painter pen back to the default color. + currentColor = defaultColor; + painter->setPen(currentColor); } priv->extended->drawStaticTextItem(&item); -- cgit v1.2.3