MapView sends always the center point from the users view
authorSami Rämö <sami.ramo@ixonos.com>
Tue, 24 Aug 2010 11:25:37 +0000 (14:25 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Tue, 24 Aug 2010 11:25:37 +0000 (14:25 +0300)
 - Sent center point is shifted when panel is open.

src/map/mapview.cpp
src/map/mapview.h

index ccf2d54..56307da 100644 (file)
@@ -81,6 +81,11 @@ MapView::~MapView()
     delete m_scrollAndZoomAnimation;
 }
 
+QPointF MapView::center()
+{
+    return mapToScene(m_viewCenterPoint) - m_centerHorizontalShiftPoint;
+}
+
 void MapView::centerToSceneCoordinates(const SceneCoordinate &coordinate, bool isUserDragAction)
 {
     qDebug() << __PRETTY_FUNCTION__ << "coordinate" << coordinate;
@@ -88,7 +93,7 @@ void MapView::centerToSceneCoordinates(const SceneCoordinate &coordinate, bool i
     QPointF target = coordinate.toPointF();
     m_lastSetScenePosition = coordinate;
 
-    if (!isUserDragAction)
+//    if (!isUserDragAction)
         target += m_centerHorizontalShiftPoint;
 
     centerOn(target);
@@ -166,8 +171,9 @@ void MapView::mouseMoveEvent(QMouseEvent *event)
     m_time.start();
     m_index++;
 
-    emit viewScrolled(SceneCoordinate(m_internalScenePosition.x(), m_internalScenePosition.y()),
-                      true);
+    QPointF viewCenterPoint = m_internalScenePosition - m_centerHorizontalShiftPoint;
+
+    emit viewScrolled(SceneCoordinate(viewCenterPoint.x(), viewCenterPoint.y()), true);
 
     m_lastMouseEventScenePosition = mapToScene(event->pos()).toPoint();
     m_lastMouseEventViewPosition = event->pos();
@@ -235,9 +241,9 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
 
             m_scroller->setEasingCurve(QEasingCurve::OutCirc);
             m_scroller->setDuration(KINETIC_SCROLL_TIME_MS);
-            m_scroller->setStartValue(SceneCoordinate(m_internalScenePosition.x(),
-                                                      m_internalScenePosition.y()));
-            QPointF endValue = QPointF(m_internalScenePosition) + effectSceneDistance;
+            QPointF centerPoint = center();
+            m_scroller->setStartValue(SceneCoordinate(centerPoint.x(), centerPoint.y()));
+            QPointF endValue = centerPoint + effectSceneDistance;
             m_scroller->setEndValue(SceneCoordinate(endValue.x(), endValue.y()));
             m_scroller->setKineticScrollFlag(true);
             m_scroller->start();
@@ -251,12 +257,14 @@ void MapView::resizeEvent(QResizeEvent *event)
 
     m_kineticMaxViewDistance = qMax(width(), height()) * KINETIC_MAX_VIEW_DISTANCE_FACTOR;
 
+    m_viewCenterPoint.setX(event->size().width() / 2);
+    m_viewCenterPoint.setY(event->size().height() / 2);
+
     emit viewResized(event->size());
 
     if (m_centerShiftAnimation) {
         int mapVisibleWidth = event->size().width() - PANEL_WIDTH - PANEL_BAR_WIDTH;
-        int mapViewMiddle = event->size().width() / 2;
-        int shiftFromMiddle = mapViewMiddle - (mapVisibleWidth / 2);
+        int shiftFromMiddle = m_viewCenterPoint.x() - (mapVisibleWidth / 2);
         m_centerShiftAnimation->setEndValue(shiftFromMiddle);
         updateCenterShift();
     }
index 41a3a68..2cd627a 100644 (file)
@@ -174,6 +174,15 @@ private slots:
 
 private:
     /**
+    * @brief Returns the point which is considered by user as the visible center point
+    *
+    * Differs from view's center point when panel is open and view center point is shifted.
+    *
+    * @returns Center point
+    */
+    QPointF center();
+
+    /**
     * @brief Set new view scale
     *
     * @param viewScale New scaling factor
@@ -263,6 +272,7 @@ private:
     QPoint m_internalScenePosition;             ///< New center position (used for dragging)
     QPoint m_lastMouseEventScenePosition;       ///< Previous mouse event position in the scene
     QPoint m_lastMouseEventViewPosition;        ///< Previous mouse event position in the view
+    QPoint m_viewCenterPoint;                   ///< Center point of the MapView
 
     QPointF m_centerHorizontalShiftPoint;       ///< Current amount of center point shifting