#include <QDebug>
#include <QMouseEvent>
+#include <QParallelAnimationGroup>
#include "mapcommon.h"
#include "mapscroller.h"
setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing);
m_scroller = &MapScroller::getInstance();
+
+ m_groupAnimation = new QParallelAnimationGroup(this);
+ m_groupAnimation->addAnimation(m_scroller);
+ m_groupAnimation->addAnimation(m_zoomAnimation);
}
void MapView::centerToSceneCoordinates(QPoint sceneCoordinate)
centerOn(sceneCoordinate);
}
+void MapView::mouseDoubleClickEvent(QMouseEvent *event)
+{
+ QPoint pressPos = mapToScene(event->pos()).toPoint();
+ QPoint centerPos = mapToScene(width() / 2 - 1, height() / 2 - 1).toPoint();
+ QPoint zoomPoint = centerPos - ((centerPos - pressPos) / 2);
+
+ m_groupAnimation->stop();
+
+ m_scroller->setEasingCurve(QEasingCurve::OutCirc);
+ m_scroller->setDuration(KINETIC_SCROLL_TIME_MS);
+ m_scroller->setStartValue(m_scenePosition);
+ m_scroller->setEndValue(zoomPoint);
+
+ m_zoomAnimation->setEasingCurve(QEasingCurve::OutCirc);
+ m_zoomAnimation->setDuration(KINETIC_SCROLL_TIME_MS);
+ m_zoomAnimation->setStartValue(viewScale());
+ m_zoomAnimation->setEndValue(pow(2, ++m_zoomLevel - MAX_MAP_ZOOM_LEVEL));
+
+
+ m_groupAnimation->start();
+}
+
void MapView::mouseMoveEvent(QMouseEvent *event)
{
m_scenePosition += m_mouseLastScenePosition - mapToScene(event->pos()).toPoint();
m_zoomLevel = zoomLevel;
- if (m_zoomAnimation) {
+ if (m_zoomAnimation && (m_zoomAnimation->state() != QPropertyAnimation::Running)) {
m_zoomAnimation->stop();
m_zoomAnimation->setDuration(ZOOM_TIME);
m_zoomAnimation->setStartValue(viewScale());
#include <QTime>
class QPropertyAnimation;
+class QParallelAnimationGroup;
class MapScroller;
void resizeEvent(QResizeEvent *event);
private:
+ void mouseDoubleClickEvent(QMouseEvent *event);
+
/**
* @brief Event handler for mouse move events
*
QPoint m_scenePosition; ///< New center position
QPropertyAnimation *m_zoomAnimation; ///< Zoom animation
+ QParallelAnimationGroup *m_groupAnimation;
QTime m_time; ///< Elapsed times in mouse events