diff options
author | Chris Adams <chris.adams@jollamobile.com> | 2012-11-27 12:26:53 +1000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-29 11:17:18 +0100 |
commit | 3a0cec6525be6bf843c597c19693785e2c893ee9 (patch) | |
tree | ff77035bc554e29c5acd05f6977841b005efdf07 /src | |
parent | 01928c91ff0ae76cdb02f50af3c62368e28cafb6 (diff) |
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 </font> 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 <aalpert@rim.com>
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativetextlayout.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
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 <font color="">text</font> 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 <font color="">text</font> tag + // we reset the painter pen back to the default color. + currentColor = defaultColor; + painter->setPen(currentColor); } priv->extended->drawStaticTextItem(&item); |