Shifting the center position on scrolling
authorSami Rämö <sami.ramo@ixonos.com>
Mon, 23 Aug 2010 10:00:09 +0000 (13:00 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Mon, 23 Aug 2010 10:00:09 +0000 (13:00 +0300)
 - Center position is shifted only when panel is open

 - Map jumps when starting a drag

 - Does not update the view when shifting is enabled / disabled

src/map/mapview.cpp
src/map/mapview.h
src/ui/mainwindow.cpp

index c86b93a..e059a8e 100644 (file)
@@ -45,7 +45,8 @@ const qreal ZOOM_TIME_MS = 350; ///< Length of the zoom effect (ms)
 
 MapView::MapView(QWidget *parent)
     : QGraphicsView(parent),
-      m_doubleTapZoomRunning(false)
+      m_doubleTapZoomRunning(false),
+      m_panelIsOpen(false)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -66,11 +67,27 @@ MapView::MapView(QWidget *parent)
             this, SLOT(doubleTapZoomFinished()));
 }
 
-void MapView::centerToSceneCoordinates(const SceneCoordinate &coordinate)
+void MapView::centerToSceneCoordinates(const SceneCoordinate &coordinate, bool isUserAction)
 {
     qDebug() << __PRETTY_FUNCTION__ << "coordinate" << coordinate;
 
-    centerOn(coordinate.toPointF());
+    QPointF target = coordinate.toPointF();
+
+    if (!isUserAction) {
+        target += m_centerHorizontalShift;
+    }
+
+    centerOn(target);
+}
+
+void MapView::disableCenterShift()
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    m_panelIsOpen = false;
+    updateCenterShift();
+
+    ///< @todo Update center position
 }
 
 void MapView::doubleTapZoomFinished()
@@ -81,6 +98,16 @@ void MapView::doubleTapZoomFinished()
     emit zoomIn();
 }
 
+void MapView::enableCenterShift()
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    m_panelIsOpen = true;
+    updateCenterShift();
+
+    ///< @todo Update center position
+}
+
 void MapView::mouseDoubleClickEvent(QMouseEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -207,6 +234,8 @@ void MapView::resizeEvent(QResizeEvent *event)
     m_kineticMaxViewDistance = qMax(width(), height()) * KINETIC_MAX_VIEW_DISTANCE_FACTOR;
 
     emit viewResized(event->size());
+
+    updateCenterShift();
 }
 
 void MapView::setViewScale(qreal viewScale)
@@ -233,6 +262,20 @@ void MapView::setZoomLevel(int zoomLevel)
 
         m_zoomAnimation->start();
     }
+
+    updateCenterShift();
+}
+
+void MapView::updateCenterShift()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    int shift = 0;
+
+    if (m_panelIsOpen)
+        shift = 200;
+
+    m_centerHorizontalShift = QPointF(shift * (1 << (OSM_MAX_ZOOM_LEVEL - m_zoomLevel)), 0);
 }
 
 qreal MapView::viewScale()
index cd1cc7b..ac6797f 100644 (file)
@@ -134,7 +134,7 @@ public slots:
     *
     * @param coordinate Scene coordinates of the new center point
     */
-    void centerToSceneCoordinates(const SceneCoordinate &coordinate);
+    void centerToSceneCoordinates(const SceneCoordinate &coordinate, bool isUserAction = false);
 
     /**
     * @brief Set zoom level of the view
@@ -144,6 +144,8 @@ public slots:
     void setZoomLevel(int zoomLevel);
 
 private slots:
+    void disableCenterShift();
+
     /**
     * @brief Double tap zoom finished.
     *
@@ -151,6 +153,8 @@ private slots:
     */
     void doubleTapZoomFinished();
 
+    void enableCenterShift();
+
 private:
     /**
     * @brief Set new view scale
@@ -159,6 +163,8 @@ private:
     */
     void setViewScale(qreal viewScale);
 
+    void updateCenterShift();
+
     /**
     * @brief Get current view scale
     *
@@ -201,6 +207,7 @@ signals:
  ******************************************************************************/
 private:
     bool m_doubleTapZoomRunning;         ///< Double tap zoom running flag
+    bool m_panelIsOpen;
 
     int m_dragTime[VALUES];               ///< Table of mouse event durations
     int m_index;                          ///< Index of mouse event values tables
@@ -213,6 +220,8 @@ private:
     QPoint m_mouseLastViewPosition;       ///< Previous mouse event position in the view
     QPoint m_scenePosition;               ///< New center position
 
+    QPointF m_centerHorizontalShift;
+
     QParallelAnimationGroup *m_scrollAndZoomAnimation;  ///< Double click zoom animation
     QPropertyAnimation *m_zoomAnimation;  ///< Zoom animation
 
index 18c5f85..59a9282 100644 (file)
@@ -339,6 +339,12 @@ void MainWindow::buildPanels()
 
     connect(m_tabbedPanel, SIGNAL(panelClosed()),
             m_routingPanel, SLOT(clearListsSelections()));
+
+    connect(m_tabbedPanel, SIGNAL(panelClosed()),
+            m_mapView, SLOT(disableCenterShift()));
+
+    connect(m_tabbedPanel, SIGNAL(panelOpened()),
+            m_mapView, SLOT(enableCenterShift()));
 }
 
 void MainWindow::buildRoutingPanel()