summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextlayout.cpp15
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextlayout_p.h2
-rw-r--r--src/gui/text/qstatictext.cpp10
-rw-r--r--tests/auto/qstatictext/tst_qstatictext.cpp40
4 files changed, 57 insertions, 10 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetextlayout.cpp b/src/declarative/graphicsitems/qdeclarativetextlayout.cpp
index cf2ef26..9aef504 100644
--- a/src/declarative/graphicsitems/qdeclarativetextlayout.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextlayout.cpp
@@ -72,14 +72,17 @@ class DrawTextItemRecorder: public QPaintEngine
public:
DrawTextItemRecorder(bool untransformedCoordinates, bool useBackendOptimizations)
: m_inertText(0), m_dirtyPen(false), m_useBackendOptimizations(useBackendOptimizations),
- m_untransformedCoordinates(untransformedCoordinates)
+ m_untransformedCoordinates(untransformedCoordinates), m_currentColor(Qt::black)
{
}
virtual void updateState(const QPaintEngineState &newState)
{
- if (newState.state() & QPaintEngine::DirtyPen)
+ if (newState.state() & QPaintEngine::DirtyPen
+ && newState.pen().color() != m_currentColor) {
m_dirtyPen = true;
+ m_currentColor = newState.pen().color();
+ }
}
virtual void drawTextItem(const QPointF &position, const QTextItem &textItem)
@@ -115,7 +118,7 @@ class DrawTextItemRecorder: public QPaintEngine
currentItem.positionOffset = positionOffset;
currentItem.useBackendOptimizations = m_useBackendOptimizations;
if (m_dirtyPen)
- currentItem.color = state->pen().color();
+ currentItem.color = m_currentColor;
m_inertText->items.append(currentItem);
}
@@ -172,6 +175,7 @@ class DrawTextItemRecorder: public QPaintEngine
bool m_dirtyPen;
bool m_useBackendOptimizations;
bool m_untransformedCoordinates;
+ QColor m_currentColor;
};
class DrawTextItemDevice: public QPaintDevice
@@ -299,7 +303,7 @@ void QDeclarativeTextLayout::clearLayout()
QTextLayout::clearLayout();
}
-void QDeclarativeTextLayout::prepare(QPainter *painter)
+void QDeclarativeTextLayout::prepare()
{
if (!d || !d->cached) {
@@ -308,7 +312,6 @@ void QDeclarativeTextLayout::prepare(QPainter *painter)
InertTextPainter *itp = inertTextPainter();
itp->device.begin(d);
- itp->painter.setPen(painter->pen());
QTextLayout::draw(&itp->painter, QPointF(0, 0));
glyph_t *glyphPool = d->glyphs.data();
@@ -347,7 +350,7 @@ void QDeclarativeTextLayout::draw(QPainter *painter, const QPointF &p)
return;
}
- prepare(painter);
+ prepare();
int itemCount = d->items.count();
diff --git a/src/declarative/graphicsitems/qdeclarativetextlayout_p.h b/src/declarative/graphicsitems/qdeclarativetextlayout_p.h
index 85d333e..d83ce7e 100644
--- a/src/declarative/graphicsitems/qdeclarativetextlayout_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextlayout_p.h
@@ -61,7 +61,7 @@ public:
void beginLayout();
void clearLayout();
- void prepare(QPainter *);
+ void prepare();
void draw(QPainter *, const QPointF & = QPointF());
private:
diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp
index 414de51..73a871b 100644
--- a/src/gui/text/qstatictext.cpp
+++ b/src/gui/text/qstatictext.cpp
@@ -430,14 +430,17 @@ namespace {
public:
DrawTextItemRecorder(bool untransformedCoordinates, bool useBackendOptimizations)
: m_dirtyPen(false), m_useBackendOptimizations(useBackendOptimizations),
- m_untransformedCoordinates(untransformedCoordinates)
+ m_untransformedCoordinates(untransformedCoordinates), m_currentColor(Qt::black)
{
}
virtual void updateState(const QPaintEngineState &newState)
{
- if (newState.state() & QPaintEngine::DirtyPen)
+ if (newState.state() & QPaintEngine::DirtyPen
+ && newState.pen().color() != m_currentColor) {
m_dirtyPen = true;
+ m_currentColor = newState.pen().color();
+ }
}
virtual void drawTextItem(const QPointF &position, const QTextItem &textItem)
@@ -453,7 +456,7 @@ namespace {
currentItem.positionOffset = m_glyphs.size(); // Offset into position pool
currentItem.useBackendOptimizations = m_useBackendOptimizations;
if (m_dirtyPen)
- currentItem.color = state->pen().color();
+ currentItem.color = m_currentColor;
QTransform matrix = m_untransformedCoordinates ? QTransform() : state->transform();
matrix.translate(position.x(), position.y());
@@ -524,6 +527,7 @@ namespace {
bool m_dirtyPen;
bool m_useBackendOptimizations;
bool m_untransformedCoordinates;
+ QColor m_currentColor;
};
class DrawTextItemDevice: public QPaintDevice
diff --git a/tests/auto/qstatictext/tst_qstatictext.cpp b/tests/auto/qstatictext/tst_qstatictext.cpp
index b6f06d3..66a2dd4 100644
--- a/tests/auto/qstatictext/tst_qstatictext.cpp
+++ b/tests/auto/qstatictext/tst_qstatictext.cpp
@@ -93,6 +93,9 @@ private slots:
void drawUnderlinedText();
void unprintableCharacter_qtbug12614();
+
+ void underlinedColor_qtbug20159();
+ void textDocumentColor();
};
void tst_QStaticText::init()
@@ -764,5 +767,42 @@ void tst_QStaticText::unprintableCharacter_qtbug12614()
QVERIFY(staticText.size().isValid()); // Force layout. Should not crash.
}
+void tst_QStaticText::underlinedColor_qtbug20159()
+{
+ QString multiScriptText;
+ multiScriptText += QChar(0x0410); // Cyrillic 'A'
+ multiScriptText += QLatin1Char('A');
+
+ QStaticText staticText(multiScriptText);
+
+ QFont font;
+ font.setUnderline(true);
+
+ staticText.prepare(QTransform(), font);
+
+ QStaticTextPrivate *d = QStaticTextPrivate::get(&staticText);
+ QCOMPARE(d->itemCount, 2);
+
+ // The pen should not be marked as dirty when drawing the underline
+ QVERIFY(!d->items[0].color.isValid());
+ QVERIFY(!d->items[1].color.isValid());
+}
+
+void tst_QStaticText::textDocumentColor()
+{
+ QStaticText staticText("A<font color=\"red\">B</font>");
+ staticText.setTextFormat(Qt::RichText);
+ staticText.prepare();
+
+ QStaticTextPrivate *d = QStaticTextPrivate::get(&staticText);
+ QCOMPARE(d->itemCount, 2);
+
+ // The pen should not be marked as dirty when drawing the underline
+ QVERIFY(!d->items[0].color.isValid());
+ QVERIFY(d->items[1].color.isValid());
+
+ QCOMPARE(d->items[1].color, QColor(Qt::red));
+}
+
QTEST_MAIN(tst_QStaticText)
#include "tst_qstatictext.moc"