Span only items which are coming to view
authorSami Rämö <sami.ramo@ixonos.com>
Tue, 8 Jun 2010 10:30:06 +0000 (13:30 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Tue, 8 Jun 2010 10:30:06 +0000 (13:30 +0300)
src/map/mapscene.cpp

index 2c3a945..2e16267 100644 (file)
@@ -81,13 +81,13 @@ void MapScene::moveIntersectingItemsHorizontally(QRect from, int distance)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    qWarning() << __PRETTY_FUNCTION__ << "left:" << from.left() << "right:" << from.right() << "distance:" << distance;
+//    qWarning() << __PRETTY_FUNCTION__ << "left:" << from.left() << "right:" << from.right() << "distance:" << distance;
 
     QList<QGraphicsItem *> spanItems = items(from, Qt::IntersectsItemBoundingRect);
     foreach (QGraphicsItem *item, spanItems) {
         if (dynamic_cast<MapTile *>(item))
             continue;
-        qWarning() << __PRETTY_FUNCTION__ << "moving item...";
+//        qWarning() << __PRETTY_FUNCTION__ << "moving item...";
         item->moveBy(distance, 0);
     }
 }
@@ -220,7 +220,7 @@ void MapScene::setTilesDrawingLevels(int zoomLevel)
 
 void MapScene::spanItems(ScrollDirection direction, int zoomLevel, QPoint sceneCoordinate, QSize viewSize)
 {
-    qWarning() << __PRETTY_FUNCTION__;
+//    qWarning() << __PRETTY_FUNCTION__;
 
     // create rects for left and right side
     QRect leftRect = sceneRect().toRect(); // this way we get the horizontal limits of the scene
@@ -233,14 +233,19 @@ void MapScene::spanItems(ScrollDirection direction, int zoomLevel, QPoint sceneC
     int viewSceneLeft = sceneCoordinate.x() - viewSceneWidth / 2;
     int viewSceneRight = sceneCoordinate.x() + viewSceneWidth / 2;
 
-    // limit rect widths to be out of the current view
-    leftRect.setRight(viewSceneLeft);
-    rightRect.setLeft(viewSceneRight);
+//    qWarning() << __PRETTY_FUNCTION__ << "width:" << viewSceneWidth << "left:" << viewSceneLeft << "right:" << viewSceneRight;
+
+    // limit rects to include only area which really must be moved
+    leftRect.setRight(-1 - (WORLD_PIXELS_X - 1 - viewSceneRight));
+    rightRect.setLeft(WORLD_PIXELS_X + viewSceneLeft);
+
+//    Q_ASSERT_X(leftRect.right() < viewSceneLeft, "spanning rect right value", "move rect is in the view area");
+//    Q_ASSERT_X(rightRect.left() > viewSceneRight, "spanning rect left value", "move rect is in the view area");
 
     // move all items which intersects the rects
-    if (leftRect.width() > 0)
+    if (leftRect.left() < leftRect.right())
         moveIntersectingItemsHorizontally(leftRect, WORLD_PIXELS_X);
-    if (rightRect.width() > 0)
+    if (rightRect.left() < rightRect.right())
         moveIntersectingItemsHorizontally(rightRect, -WORLD_PIXELS_X);
 
     /// @todo get small rects from boths sides of the view