summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview/qgraphicsview_p.h
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2010-04-26 07:40:19 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2010-05-03 12:33:33 (GMT)
commit666cacd03d57da6a9caab5936f14c68d1c486e7e (patch)
tree4665bafee6942c454b00e9e0ea93d30fca2d129e /src/gui/graphicsview/qgraphicsview_p.h
parent28659c21d12a267b10e5b441bf4c776e04d69bdc (diff)
downloadQt-666cacd03d57da6a9caab5936f14c68d1c486e7e.zip
Qt-666cacd03d57da6a9caab5936f14c68d1c486e7e.tar.gz
Qt-666cacd03d57da6a9caab5936f14c68d1c486e7e.tar.bz2
QGraphicsView drawing artifacts due to rounding errors.
Found during investigation of QTBUG-8820, and clearly visible in examples/graphicsview/diagramscene when slowly moving an item out of the viewport (left and top edge). Caused by two problems: 1) Using QRectF::toRect() instead of QRectF::toAlignedRect(). 2) Didn't adjust the item's bounding rect properly in drawSubtree(). QRectF::toRect() is completely useless since all the coordinates are rounded to the nearest integer. E.g. QRectF(-0.4, -0.4, 10.4, 10.4).toRect() -> QRect(0, 0, 10, 10), whereas toAlignedRect() returns QRect(-1, -1, 11, 11). Then when we have a proper aligned rect, we have to adjust it by 2 pixels in all directions (or 1 pixel in case of QGraphicsView::DontAdjustForAntialiasing). At first glance this adjustment seems too much, since one would assume adjusing the QRectF by 0.5 before using toAlignedRect() would be sufficient. That's sufficient in an untransformed world with pens using BevelJoin. However, the story is completely different as soon as the world is transformed or the pens use a different join. It's basically complicated (in some cases impossible) to calculate a pixel perfect aligned QRect, so instead we adjust by the amount of pixels required in the worst case. This commit also includes some optimizations for QRegion updates (since I anyways had to change the code). There's no point in using QRegion granularity if the viewport update mode is either FullViewportUpdate or BoundingRectViewportUpdate. Auto tests adjusted and new ones included. Task-number: QTBUG-10338
Diffstat (limited to 'src/gui/graphicsview/qgraphicsview_p.h')
-rw-r--r--src/gui/graphicsview/qgraphicsview_p.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/gui/graphicsview/qgraphicsview_p.h b/src/gui/graphicsview/qgraphicsview_p.h
index 80e3ec1..aeff28a 100644
--- a/src/gui/graphicsview/qgraphicsview_p.h
+++ b/src/gui/graphicsview/qgraphicsview_p.h
@@ -192,8 +192,17 @@ public:
#endif
}
+ inline bool updateRectF(const QRectF &rect)
+ {
+ if (rect.isEmpty())
+ return false;
+ if (optimizationFlags & QGraphicsView::DontAdjustForAntialiasing)
+ return updateRect(rect.toAlignedRect().adjusted(-1, -1, 1, 1));
+ return updateRect(rect.toAlignedRect().adjusted(-2, -2, 2, 2));
+ }
+
bool updateRect(const QRect &rect);
- bool updateRegion(const QRegion &region);
+ bool updateRegion(const QRectF &rect, const QTransform &xform);
bool updateSceneSlotReimplementedChecked;
QRegion exposedRegion;