summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-11-09 17:20:51 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-11-09 17:26:00 (GMT)
commit327ef9127aba3aa6bf2238c0aa779613f8edf0b1 (patch)
tree12440a99ea6b28cecb08ca7d4f9a037b0c5d12b2 /tests
parentecdecf7a628aa1c9eb953984c89fc65ffa767a24 (diff)
downloadQt-327ef9127aba3aa6bf2238c0aa779613f8edf0b1.zip
Qt-327ef9127aba3aa6bf2238c0aa779613f8edf0b1.tar.gz
Qt-327ef9127aba3aa6bf2238c0aa779613f8edf0b1.tar.bz2
QGraphicsTextItem: update when changing the color.
Task-number: QTBUG-5418 Reviewed-by: Gabriel
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index d65c6ec..27c6809 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -413,6 +413,7 @@ private slots:
void task243707_addChildBeforeParent();
void task197802_childrenVisibility();
void QTBUG_4233_updateCachedWithSceneRect();
+ void QTBUG_5418_textItemSetDefaultColor();
private:
QList<QGraphicsItem *> paintedItems;
@@ -9751,5 +9752,62 @@ void tst_QGraphicsItem::scenePosChange()
QCOMPARE(child2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0);
}
+void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor()
+{
+ struct Item : public QGraphicsTextItem
+ {
+ bool painted;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid)
+ {
+ painted = true;
+ QGraphicsTextItem::paint(painter, opt, wid);
+ }
+ };
+
+ Item *i = new Item;
+ i->painted = false;
+ i->setPlainText("I AM A TROLL");
+
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+ view.show();
+ QTest::qWaitForWindowShown(&view);
+ scene.addItem(i);
+ QApplication::processEvents();
+ QTRY_VERIFY(i->painted);
+ QApplication::processEvents();
+
+ i->painted = false;
+ QColor col(Qt::red);
+ i->setDefaultTextColor(col);
+ QApplication::processEvents();
+ QTRY_VERIFY(i->painted); //check that changing the color force an update
+
+ i->painted = false;
+ QImage image(400, 200, QImage::Format_RGB32);
+ image.fill(0);
+ QPainter painter(&image);
+ scene.render(&painter);
+ painter.end();
+ QVERIFY(i->painted);
+
+ int numRedPixel = 0;
+ QRgb rgb = col.rgb();
+ for (int y = 0; y < image.height(); ++y) {
+ for (int x = 0; x < image.width(); ++x) {
+ // Because of antialiasing we allow a certain range of errors here.
+ QRgb pixel = image.pixel(x, y);
+ if (qAbs((int)(pixel & 0xff) - (int)(rgb & 0xff)) +
+ qAbs((int)((pixel & 0xff00) >> 8) - (int)((rgb & 0xff00) >> 8)) +
+ qAbs((int)((pixel & 0xff0000) >> 16) - (int)((rgb & 0xff0000) >> 16)) <= 50) {
+ if (++numRedPixel >= 10) {
+ return;
+ }
+ }
+ }
+ }
+ QCOMPARE(numRedPixel, -1); //color not found, FAIL!
+}
+
QTEST_MAIN(tst_QGraphicsItem)
#include "tst_qgraphicsitem.moc"