MapView::MapView(QWidget *parent)
: QGraphicsView(parent),
- m_doubleTapZoomRunning(false),
- m_panelIsOpen(false)
+ m_centerShiftEnabled(false),
+ m_doubleTapZoomRunning(false)
{
qDebug() << __PRETTY_FUNCTION__;
this, SLOT(doubleTapZoomFinished()));
}
+MapView::~MapView()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_scrollAndZoomAnimation->removeAnimation(m_scroller);
+ delete m_scrollAndZoomAnimation;
+}
+
void MapView::centerToSceneCoordinates(const SceneCoordinate &coordinate, bool isUserDragAction)
{
qDebug() << __PRETTY_FUNCTION__ << "coordinate" << coordinate;
QPointF target = coordinate.toPointF();
+ m_lastSetScenePosition = coordinate;
if (!isUserDragAction) {
target += m_centerHorizontalShift;
void MapView::disableCenterShift()
{
- qWarning() << __PRETTY_FUNCTION__;
-
- m_panelIsOpen = false;
- updateCenterShift();
+ qDebug() << __PRETTY_FUNCTION__;
- ///< @todo Update center position
+ toggleCenterShift(false);
}
void MapView::doubleTapZoomFinished()
void MapView::enableCenterShift()
{
- qWarning() << __PRETTY_FUNCTION__;
-
- m_panelIsOpen = true;
- updateCenterShift();
+ qDebug() << __PRETTY_FUNCTION__;
- ///< @todo Update center position
+ toggleCenterShift(true);
}
void MapView::mouseDoubleClickEvent(QMouseEvent *event)
m_scroller->setEasingCurve(QEasingCurve::Linear);
m_scroller->setDuration(ZOOM_TIME_MS);
- m_scroller->setStartValue(SceneCoordinate(m_scenePosition.x(), m_scenePosition.y()));
+ m_scroller->setStartValue(SceneCoordinate(m_internalScenePosition.x(),
+ m_internalScenePosition.y()));
m_scroller->setEndValue(SceneCoordinate(zoomPosition.x(), zoomPosition.y()));
m_zoomAnimation->setEasingCurve(QEasingCurve::InQuad);
if (m_doubleTapZoomRunning)
return;
- m_scenePosition += m_mouseLastScenePosition - mapToScene(event->pos()).toPoint();
+ m_internalScenePosition += m_lastMouseEventScenePosition - mapToScene(event->pos()).toPoint();
if (m_index >= VALUES)
m_index = 0;
- m_dragMovement[m_index] = m_mouseLastViewPosition - event->pos();
+ m_dragMovement[m_index] = m_lastMouseEventViewPosition - event->pos();
m_dragTime[m_index] = m_time.elapsed();
m_time.start();
m_index++;
- emit viewScrolled(SceneCoordinate(m_scenePosition.x(), m_scenePosition.y()), true);
+ emit viewScrolled(SceneCoordinate(m_internalScenePosition.x(), m_internalScenePosition.y()),
+ true);
- m_mouseLastScenePosition = mapToScene(event->pos()).toPoint();
- m_mouseLastViewPosition = event->pos();
+ m_lastMouseEventScenePosition = mapToScene(event->pos()).toPoint();
+ m_lastMouseEventViewPosition = event->pos();
}
void MapView::mousePressEvent(QMouseEvent *event)
QGraphicsView::mousePressEvent(event);
- m_mouseLastScenePosition = mapToScene(event->pos()).toPoint();
- m_mouseLastViewPosition = event->pos();
- m_scenePosition = mapToScene(width() / 2 - 1, height() / 2 - 1).toPoint();
+ m_lastMouseEventScenePosition = mapToScene(event->pos()).toPoint();
+ m_lastMouseEventViewPosition = event->pos();
+ m_internalScenePosition = mapToScene(width() / 2 - 1, height() / 2 - 1).toPoint();
for (int i = 0; i < VALUES; i++) {
m_dragMovement[i] = QPoint();
m_scroller->setEasingCurve(QEasingCurve::OutCirc);
m_scroller->setDuration(KINETIC_SCROLL_TIME_MS);
- m_scroller->setStartValue(SceneCoordinate(m_scenePosition.x(), m_scenePosition.y()));
- QPointF endValue = QPointF(m_scenePosition) + effectSceneDistance;
+ m_scroller->setStartValue(SceneCoordinate(m_internalScenePosition.x(),
+ m_internalScenePosition.y()));
+ QPointF endValue = QPointF(m_internalScenePosition) + effectSceneDistance;
m_scroller->setEndValue(SceneCoordinate(endValue.x(), endValue.y()));
m_scroller->start();
}
updateCenterShift();
}
+void MapView::toggleCenterShift(bool enabled)
+{
+ qWarning() << __PRETTY_FUNCTION__ << enabled;
+
+ m_centerShiftEnabled = enabled;
+ updateCenterShift();
+
+ centerToSceneCoordinates(m_lastSetScenePosition);
+}
+
void MapView::updateCenterShift()
{
qDebug() << __PRETTY_FUNCTION__;
int shift = 0;
- if (m_panelIsOpen)
+ if (m_centerShiftEnabled)
shift = 200;
m_centerHorizontalShift = QPointF(shift * (1 << (OSM_MAX_ZOOM_LEVEL - m_zoomLevel)), 0);
return transform().m11();
}
-
-MapView::~MapView()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_scrollAndZoomAnimation->removeAnimation(m_scroller);
- delete m_scrollAndZoomAnimation;
-}
#include <QGraphicsView>
#include <QTime>
+#include "coordinates/scenecoordinate.h"
+
class QPropertyAnimation;
class QParallelAnimationGroup;
class MapScroller;
-class SceneCoordinate;
-
#define VALUES 4
/**
*/
void setViewScale(qreal viewScale);
+ void toggleCenterShift(bool enabled);
+
void updateCenterShift();
/**
* DATA MEMBERS
******************************************************************************/
private:
+ bool m_centerShiftEnabled;
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
qreal m_kineticMaxViewDistance; ///< Maximum kinetic scroll distance in view pixels
QPoint m_dragMovement[VALUES]; ///< Table of mouse event distances
- QPoint m_mouseLastScenePosition; ///< Previous mouse event position in the scene
- QPoint m_mouseLastViewPosition; ///< Previous mouse event position in the view
- QPoint m_scenePosition; ///< New center position
+ QPoint m_internalScenePosition; ///< New center position
+ QPoint m_lastMouseEventScenePosition; ///< Previous mouse event position in the scene
+ QPoint m_lastMouseEventViewPosition; ///< Previous mouse event position in the view
QPointF m_centerHorizontalShift;
QTime m_time; ///< Elapsed times in mouse events
MapScroller *m_scroller; ///< Kinetic scroller
+ SceneCoordinate m_lastSetScenePosition;
};
#endif // MAPVIEW_H