Update direction indicator after zooming, re-factoring
authorSami Rämö <sami.ramo@ixonos.com>
Wed, 28 Jul 2010 13:53:00 +0000 (16:53 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Wed, 28 Jul 2010 13:55:09 +0000 (16:55 +0300)
 - Re-factored MapScene::spanItems() to use the new
   MapEngine::currentViewSceneRect() method

 - Direction indicator is now updated also after zooming

src/map/mapengine.cpp
src/map/mapscene.cpp
src/map/mapscene.h
src/map/osm.h
src/ui/indicatorbutton.cpp

index da7f919..50b4381 100644 (file)
@@ -225,7 +225,7 @@ void MapEngine::friendsPositionsUpdated()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
+    m_mapScene->spanItems(currentViewSceneRect());
 }
 
 void MapEngine::getTiles(SceneCoordinate coordinate)
@@ -261,7 +261,7 @@ void MapEngine::gpsPositionUpdate(GeoCoordinate position, qreal accuracy)
 
     m_gpsLocationItem->updatePosition(SceneCoordinate(position), accuracy);
     m_gpsPosition = position;
-    m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
+    m_mapScene->spanItems(currentViewSceneRect());
 
     if (m_autoCenteringEnabled) {
         m_lastAutomaticPosition = SceneCoordinate(position);
@@ -395,7 +395,7 @@ void MapEngine::receiveOwnLocation(User *user)
         m_ownLocation->hide();
     }
 
-    m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
+    m_mapScene->spanItems(currentViewSceneRect());
 }
 
 QGraphicsScene* MapEngine::scene()
@@ -464,7 +464,7 @@ void MapEngine::setCenterPosition(SceneCoordinate coordinate)
         m_mapScene->removeOutOfViewTiles(m_viewTilesGrid, m_zoomLevel);
     }
 
-    m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
+    m_mapScene->spanItems(currentViewSceneRect());
     emit newMapResolution(sceneResolution());
 
     updateDirectionIndicator();
@@ -619,6 +619,8 @@ void MapEngine::viewZoomFinished()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    updateDirectionIndicator();
+
     if (m_zoomedIn) {
         m_zoomedIn = false;
         m_mapScene->removeOutOfViewTiles(m_viewTilesGrid, m_zoomLevel);
@@ -637,7 +639,7 @@ void MapEngine::zoomed()
     m_mapScene->setZoomLevel(m_zoomLevel);
     getTiles(m_sceneCoordinate);
     m_mapScene->setSceneVerticalOverlap(m_viewSize.height(), m_zoomLevel);
-    m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
+    m_mapScene->spanItems(currentViewSceneRect());
     emit newMapResolution(sceneResolution());
 }
 
index 90007b7..5c5c00a 100644 (file)
@@ -246,7 +246,7 @@ void MapScene::setZoomLevel(int zoomLevel)
     m_zoomLevel = zoomLevel;
 }
 
-void MapScene::spanItems(int zoomLevel, SceneCoordinate coordinate, QSize viewSize)
+void MapScene::spanItems(QRectF viewSceneRect)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -256,17 +256,12 @@ void MapScene::spanItems(int zoomLevel, SceneCoordinate coordinate, QSize viewSi
     leftRect.setBottom(OSM_MAP_MAX_PIXEL_Y);
     QRect rightRect = leftRect;
 
-    // calculate current horizontal area shown on the view
-    int viewSceneWidth = (1 << (OSM_MAX_ZOOM_LEVEL - zoomLevel)) * viewSize.width();
-    int viewSceneLeft = coordinate.x() - viewSceneWidth / 2;
-    int viewSceneRight = coordinate.x() + viewSceneWidth / 2;
-
     // limit rects to include only area which really must be moved
-    leftRect.setRight(-1 - (OSM_MAP_PIXELS_X - 1 - viewSceneRight));
-    rightRect.setLeft(OSM_MAP_PIXELS_X + viewSceneLeft);
+    leftRect.setRight(-1 - (OSM_MAP_PIXELS_X - 1 - viewSceneRect.right()));
+    rightRect.setLeft(OSM_MAP_PIXELS_X + viewSceneRect.left());
 
-    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");
+    Q_ASSERT_X(leftRect.right() < viewSceneRect.left(), "spanning rect right value", "move rect is in the view area");
+    Q_ASSERT_X(rightRect.left() > viewSceneRect.right(), "spanning rect left value", "move rect is in the view area");
 
     // move all items which intersects the rects
     if (leftRect.left() < leftRect.right())
index 95ee0cf..5da0245 100644 (file)
@@ -148,11 +148,9 @@ public:
     /**
       * @brief Span items (others than MapTile) to opposite side of the scene
       *
-      * @param zoomLevel Current zoom level
-      * @param coordinate Scene coordinates of the current center point
-      * @param viewSize Current size of the view
+      * @param viewSceneRect Scene area which is currently drawn on the view
       */
-    void spanItems(int zoomLevel, SceneCoordinate coordinate, QSize viewSize);
+    void spanItems(QRectF viewSceneRect);
 
     /**
     * @brief Save new tiles scene rect
index c465306..a06b739 100644 (file)
@@ -42,7 +42,7 @@ const double OSM_MIN_LATITUDE = -OSM_MAX_LATITUDE;          ///< Minimum latitud
 
 // MAP PIXELS
 /**
-* @var OMS_MAP_PIXELS_X
+* @var OSM_MAP_PIXELS_X
 * @brief Amount of horizontal pixels in map
 */
 const int OSM_MAP_PIXELS_X = OSM_TILES_PER_SIDE * OSM_TILE_SIZE_X;
index 1f2c8e8..0467645 100644 (file)
@@ -297,4 +297,6 @@ void IndicatorButton::updateValues(qreal direction, qreal distance, bool draw)
 
     m_direction = direction;
     m_drawTriangle = draw;
+
+    update();
 }