Fixed friends collision detection with spanned items
authorSami Rämö <sami.ramo@ixonos.com>
Tue, 8 Jun 2010 12:28:36 +0000 (15:28 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Tue, 8 Jun 2010 12:28:36 +0000 (15:28 +0300)
src/map/baselocationitem.cpp
src/map/mapengine.cpp

index 92798bf..df01093 100644 (file)
@@ -37,10 +37,25 @@ BaseLocationItem::BaseLocationItem(QObject *parent)
 QRect BaseLocationItem::sceneTransformedBoundingRect(int zoomLevel) const
 {
     QRect rect = sceneBoundingRect().toRect();
+
+    // returned rect size is size of original image and not scaled to size of currently presented
+    // image because of using ItemIgnoresTransformations flag. Thus the rect must be scaled
+
     int multiplier = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
 
     int heightDelta = (rect.height() * multiplier - rect.height()) / 2;
     int widthDelta = (rect.width() * multiplier - rect.width()) / 2;
 
-    return rect.adjusted(-widthDelta, -heightDelta, widthDelta, heightDelta);
+    rect.adjust(-widthDelta, -heightDelta, widthDelta, heightDelta);
+
+    // make sure that left edge of the returned rect is always inside the world coordinates
+    // so collisions are detected even if the items are spanned around
+
+    while (rect.left() < 0)
+        rect.translate(WORLD_PIXELS_X, 0);
+
+    while (rect.left() > WORLD_PIXELS_X - 1)
+        rect.translate(-WORLD_PIXELS_X, 0);
+
+    return rect;
 }
index 4530ca8..c836b68 100644 (file)
@@ -199,7 +199,6 @@ void MapEngine::friendsPositionsUpdated()
     qDebug() << __PRETTY_FUNCTION__;
 
     m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
-    /// @todo removed m_friendItemsHandler->refactorFriendItems(m_zoomLevel);
 }
 
 void MapEngine::getTiles(QPoint sceneCoordinate)
@@ -556,7 +555,6 @@ void MapEngine::zoomed()
     m_mapScene->setTilesDrawingLevels(m_zoomLevel);
     getTiles(m_sceneCoordinate);
     m_mapScene->setSceneVerticalOverlap(m_viewSize.height(), m_zoomLevel);
-    /// @todo remove m_friendItemsHandler->refactorFriendItems(m_zoomLevel);
     m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
 }