MapView::MapView(QWidget *parent)
: QGraphicsView(parent),
- m_doubleTapZoomRunning(false)
+ m_doubleTapZoomRunning(false),
+ m_panelIsOpen(false)
{
qDebug() << __PRETTY_FUNCTION__;
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()
emit zoomIn();
}
+void MapView::enableCenterShift()
+{
+ qWarning() << __PRETTY_FUNCTION__;
+
+ m_panelIsOpen = true;
+ updateCenterShift();
+
+ ///< @todo Update center position
+}
+
void MapView::mouseDoubleClickEvent(QMouseEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
m_kineticMaxViewDistance = qMax(width(), height()) * KINETIC_MAX_VIEW_DISTANCE_FACTOR;
emit viewResized(event->size());
+
+ updateCenterShift();
}
void MapView::setViewScale(qreal viewScale)
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()
*
* @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
void setZoomLevel(int zoomLevel);
private slots:
+ void disableCenterShift();
+
/**
* @brief Double tap zoom finished.
*
*/
void doubleTapZoomFinished();
+ void enableCenterShift();
+
private:
/**
* @brief Set new view scale
*/
void setViewScale(qreal viewScale);
+ void updateCenterShift();
+
/**
* @brief Get current view scale
*
******************************************************************************/
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
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
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()