summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@nokia.com>2009-11-20 12:29:57 (GMT)
committerYoann Lopes <yoann.lopes@nokia.com>2009-11-20 14:19:11 (GMT)
commit0b8639aee92913cdfaa4386aa09dde0f5cb2eaee (patch)
treeb6289e83299ac217f4aacc93d53e33791b67402e
parent7871ebfc4d2adf2313c7431c9d6fa221a903b81d (diff)
downloadQt-0b8639aee92913cdfaa4386aa09dde0f5cb2eaee.zip
Qt-0b8639aee92913cdfaa4386aa09dde0f5cb2eaee.tar.gz
Qt-0b8639aee92913cdfaa4386aa09dde0f5cb2eaee.tar.bz2
Fixes painting issues when scaling a QGraphicsView.
The problem was that the 'exposed rectangle' passed to the Item's paint() function was rounded to Int values, whereas the one passed to drawBackground and drawForeground was not. Autotest included. Task-number: QTBUG-5859 Reviewed-by: bnilsen
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp2
-rw-r--r--tests/auto/qgraphicsview/tst_qgraphicsview.cpp39
2 files changed, 40 insertions, 1 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index 3f6dff2..710048e 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -1240,7 +1240,7 @@ void QGraphicsItemPrivate::initStyleOption(QStyleOptionGraphicsItem *option, con
const QTransform reverseMap = worldTransform.inverted();
const QVector<QRect> exposedRects(exposedRegion.rects());
for (int i = 0; i < exposedRects.size(); ++i) {
- option->exposedRect |= reverseMap.mapRect(exposedRects.at(i));
+ option->exposedRect |= reverseMap.mapRect(QRectF(exposedRects.at(i)));
if (option->exposedRect.contains(brect))
break;
}
diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
index 1ff06c2..797e1fb 100644
--- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
@@ -235,6 +235,7 @@ private slots:
void task259503_scrollingArtifacts();
void QTBUG_4151_clipAndIgnore_data();
void QTBUG_4151_clipAndIgnore();
+ void QTBUG_5859_exposedRect();
};
void tst_QGraphicsView::initTestCase()
@@ -3867,5 +3868,43 @@ void tst_QGraphicsView::QTBUG_4151_clipAndIgnore()
QCOMPARE(view.items(view.rect()).size(), numItems);
}
+void tst_QGraphicsView::QTBUG_5859_exposedRect()
+{
+ class CustomScene : public QGraphicsScene
+ {
+ public:
+ CustomScene(const QRectF &rect) : QGraphicsScene(rect) { }
+ void drawBackground(QPainter *painter, const QRectF &rect)
+ { lastBackgroundExposedRect = rect; }
+ QRectF lastBackgroundExposedRect;
+ };
+
+ class CustomRectItem : public QGraphicsRectItem
+ {
+ public:
+ CustomRectItem(const QRectF &rect) : QGraphicsRectItem(rect)
+ { setFlag(QGraphicsItem::ItemUsesExtendedStyleOption); }
+ void paint(QPainter * painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0)
+ { lastExposedRect = option->exposedRect; }
+ QRectF lastExposedRect;
+ };
+
+ CustomScene scene(QRectF(0,0,50,50));
+
+ CustomRectItem item(scene.sceneRect());
+
+ scene.addItem(&item);
+
+ QGraphicsView view(&scene);
+ view.scale(4.15, 4.15);
+ view.show();
+ QTest::qWaitForWindowShown(&view);
+
+ view.viewport()->repaint(10,10,20,20);
+ QApplication::processEvents();
+
+ QCOMPARE(item.lastExposedRect, scene.lastBackgroundExposedRect);
+}
+
QTEST_MAIN(tst_QGraphicsView)
#include "tst_qgraphicsview.moc"