diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-11-26 09:26:27 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-11-26 09:31:23 (GMT) |
commit | c8494e085cd5abc3b30229409c7dacac676c81b9 (patch) | |
tree | 078c20210cbc1a6e530e4447bf067be03c740ea5 | |
parent | 0f06d08a3c5eb4d0397406ed559cfaba6e137492 (diff) | |
download | Qt-c8494e085cd5abc3b30229409c7dacac676c81b9.zip Qt-c8494e085cd5abc3b30229409c7dacac676c81b9.tar.gz Qt-c8494e085cd5abc3b30229409c7dacac676c81b9.tar.bz2 |
QGraphicsTextItem::setDefaultTextColor check change before calling update()
Some applications call setDefaultTextColor in the paint event.
Task-number: QTBUG-6242
Reviewed-by: Gabriel
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 17 |
2 files changed, 14 insertions, 7 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 34f42fb..1f87cd9 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -9441,9 +9441,11 @@ void QGraphicsTextItem::setDefaultTextColor(const QColor &col) { QTextControl *c = dd->textControl(); QPalette pal = c->palette(); + QColor old = pal.color(QPalette::Text); pal.setColor(QPalette::Text, col); c->setPalette(pal); - update(); + if (old != col) + update(); } /*! diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index db80db6..565a3e7 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -9759,16 +9759,16 @@ void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() { struct Item : public QGraphicsTextItem { - bool painted; + int painted; void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid) { - painted = true; + painted++; QGraphicsTextItem::paint(painter, opt, wid); } }; Item *i = new Item; - i->painted = false; + i->painted = 0; i->setPlainText("I AM A TROLL"); QGraphicsScene scene; @@ -9780,11 +9780,11 @@ void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() QTRY_VERIFY(i->painted); QApplication::processEvents(); - i->painted = false; + i->painted = 0; QColor col(Qt::red); i->setDefaultTextColor(col); QApplication::processEvents(); - QTRY_VERIFY(i->painted); //check that changing the color force an update + QTRY_COMPARE(i->painted, 1); //check that changing the color force an update i->painted = false; QImage image(400, 200, QImage::Format_RGB32); @@ -9792,7 +9792,7 @@ void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() QPainter painter(&image); scene.render(&painter); painter.end(); - QVERIFY(i->painted); + QCOMPARE(i->painted, 1); int numRedPixel = 0; QRgb rgb = col.rgb(); @@ -9810,6 +9810,11 @@ void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() } } QCOMPARE(numRedPixel, -1); //color not found, FAIL! + + i->painted = 0; + i->setDefaultTextColor(col); + QApplication::processEvents(); + QCOMPARE(i->painted, 0); //same color as before should not trigger an update (QTBUG-6242) } QTEST_MAIN(tst_QGraphicsItem) |