Zoom.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 22 Jun 2010 12:38:06 +0000 (15:38 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Tue, 22 Jun 2010 12:38:06 +0000 (15:38 +0300)
src/map/mapview.cpp
src/map/mapview.h

index 471e28b..256d191 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <QDebug>
 #include <QMouseEvent>
+#include <QParallelAnimationGroup>
 
 #include "mapcommon.h"
 #include "mapscroller.h"
@@ -53,6 +54,10 @@ MapView::MapView(QWidget *parent)
     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)
@@ -62,6 +67,28 @@ 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();
@@ -161,7 +188,7 @@ void MapView::setZoomLevel(int zoomLevel)
 
     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());
index 1322663..e53c818 100644 (file)
@@ -27,6 +27,7 @@
 #include <QTime>
 
 class QPropertyAnimation;
+class QParallelAnimationGroup;
 
 class MapScroller;
 
@@ -69,6 +70,8 @@ protected:
     void resizeEvent(QResizeEvent *event);
 
 private:
+    void mouseDoubleClickEvent(QMouseEvent *event);
+
     /**
     * @brief Event handler for mouse move events
     *
@@ -178,6 +181,7 @@ private:
     QPoint m_scenePosition;               ///< New center position
 
     QPropertyAnimation *m_zoomAnimation;  ///< Zoom animation
+    QParallelAnimationGroup *m_groupAnimation;
 
     QTime m_time;                         ///< Elapsed times in mouse events