From 1b6d41deebdd8103e2d8abb53bd2bb1dd26bd0ae Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Tue, 1 Jun 2010 10:50:30 +0200 Subject: Fix bug in QGraphicsItem::scroll() when called with no QRectF argument. With a null rect argument, QGraphicsItem::scroll() is supposed to scroll the whole item. When using ItemCoordinateCache, currently the only supported mode for scroll optimization, we simple scrolled the whole cache pixmap. Problem: The cache pixmap has a border of 2 pixels. So we scroll the contents _and_ the border. This leaves white/transparent horizontal and vertical line artifacts when scrolling. This change unifies the two cases - partial and full scrolling - into one (shorter) approach that works without scrolling the margin as well. Reviewed-by: Alexis Menard --- src/gui/graphicsview/qgraphicsitem.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index d284a29..9d7354a 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -5695,19 +5695,12 @@ void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect) } QPixmapCache::remove(cache->key); + QRect scrollRect = (rect.isNull() ? boundingRect() : rect).toAlignedRect(); + if (!scrollRect.intersects(cache->boundingRect)) + return; // Nothing to scroll. + QRegion exposed; - const bool scrollEntirePixmap = rect.isNull(); - if (scrollEntirePixmap) { - // Scroll entire pixmap. - cachedPixmap.scroll(dx, dy, cachedPixmap.rect(), &exposed); - } else { - if (!rect.intersects(cache->boundingRect)) - return; // Nothing to scroll. - // Scroll sub-rect of pixmap. The rect is in item coordinates - // so we have to translate it to pixmap coordinates. - QRect scrollRect = rect.toAlignedRect(); - cachedPixmap.scroll(dx, dy, scrollRect.translated(-cache->boundingRect.topLeft()), &exposed); - } + cachedPixmap.scroll(dx, dy, scrollRect.translated(-cache->boundingRect.topLeft()), &exposed); // Reinsert into cache. cache->key = QPixmapCache::insert(cachedPixmap); @@ -5715,7 +5708,7 @@ void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect) // Translate the existing expose. for (int i = 0; i < cache->exposed.size(); ++i) { QRectF &e = cache->exposed[i]; - if (!scrollEntirePixmap && !e.intersects(rect)) + if (!rect.isNull() && !e.intersects(rect)) continue; e.translate(dx, dy); } -- cgit v0.12