Merge branch 'map' of https://vcs.maemo.org/git/situare into map
authorSami Rämö <sami.ramo@ixonos.com>
Fri, 16 Apr 2010 09:53:58 +0000 (12:53 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Fri, 16 Apr 2010 09:53:58 +0000 (12:53 +0300)
removeStackedTiles() was disabled because it breaks zoom in.

src/map/mapcommon.h
src/map/mapengine.cpp
src/map/mapview.cpp
src/map/mapview.h
tests/map/mapengine/testmapengine.cpp

index c7e3d55..ca9eb82 100644 (file)
@@ -35,8 +35,8 @@ static const int MIN_MAP_SCENE_NORMAL_LEVEL = MAX_MAP_ZOOM_LEVEL + 1;
 static const int ZOOM_FPS = 30; ///< FPS for the zoom effect
 static const qreal ZOOM_TIME = 0.25; ///< Length of the zoom effect (seconds)
 
-static const qreal MIN_LATITUDE = -85.0511; ///< Minimum latitude value
-static const qreal MAX_LATITUDE = 85.0511;  ///< Maximum latitude value
+static const qreal MAX_LATITUDE = 85.05112877980659237802;  ///< Maximum latitude value
+static const qreal MIN_LATITUDE = -MAX_LATITUDE; ///< Minimum latitude value
 static const qreal MIN_LONGITUDE = -180.0;  ///< Minimum longitude value
 static const qreal MAX_LONGITUDE = 180.0;  ///< Maximum longitude value
 
index dfab16a..8efd679 100644 (file)
@@ -51,14 +51,12 @@ void MapEngine::init()
 {
     emit zoomLevelChanged(m_zoomLevel);
     setViewLocation(QPointF(DEFAULT_LONGITUDE, DEFAULT_LATITUDE));
-    emit locationChanged(m_sceneCoordinate);
 }
 
 void MapEngine::setViewLocation(QPointF latLonCoordinate)
 {
     qDebug() << __PRETTY_FUNCTION__;
     setLocation(convertLatLonToSceneCoordinate(latLonCoordinate));
-    emit locationChanged(m_sceneCoordinate);
 }
 
 QUrl MapEngine::buildURL(int zoomLevel, QPoint tileNumbers)
@@ -105,7 +103,7 @@ void MapEngine::mapImageReceived(const QUrl &url, const QPixmap &pixmap)
         mapTilesInScene.insert(tilePath(zoom, x, y), mapTile);
         m_mapScene->addMapTile(mapTile);
 
-        removeStackedTiles(mapTile);
+//        removeStackedTiles(mapTile);
    }
 }
 
@@ -135,6 +133,7 @@ void MapEngine::setLocation(QPoint sceneCoordinate)
     //qDebug() << __PRETTY_FUNCTION__;
 
     m_sceneCoordinate = sceneCoordinate;
+    emit locationChanged(m_sceneCoordinate);
 
     if (centerTileChanged(sceneCoordinate)) {
         calculateNewTiles(sceneCoordinate);
@@ -257,6 +256,9 @@ void MapEngine::zoomIn()
     emit zoomLevelChanged(m_zoomLevel);
 
     setZValues();
+
+    calculateNewTiles(m_sceneCoordinate);
+    removeOldTiles();
 }
 
 void MapEngine::zoomOut()
@@ -270,6 +272,8 @@ void MapEngine::zoomOut()
     emit zoomLevelChanged(m_zoomLevel);
 
     setZValues();
+
+    calculateNewTiles(m_sceneCoordinate);
 }
 
 void MapEngine::setZValues()
index 827cc7c..7533ed8 100644 (file)
     #include <QGLWidget>
 #endif // Q_WS_MAEMO_5
 
-#ifdef Q_WS_MAEMO_5
-    #include <QAbstractKineticScroller>
-#endif // Q_WS_MAEMO_5
-
 #include "mapcommon.h"
 #include "mapview.h"
 
@@ -42,22 +38,9 @@ MapView::MapView(QWidget *parent) : QGraphicsView(parent)
   * OpenGL can't be used in scratchbox.
   */
 #ifndef Q_WS_MAEMO_5
-    setViewport(new QGLWidget);
+    //setViewport(new QGLWidget);
 #endif // !Q_WS_MAEMO_5
 
-/**
-  * Use kinetic scrolling for Maemo5 and QGraphicsViews drag mode
-  * ScrollHandDrag for other environments
-  */
-#ifdef Q_WS_MAEMO_5
-    QAbstractKineticScroller *scroller = property("kineticScroller")
-                                         .value<QAbstractKineticScroller *>();
-    if (scroller)
-        scroller->setEnabled(true);
-#else
-    setDragMode(QGraphicsView::ScrollHandDrag);
-#endif // Q_WS_MAEMO_5
-
     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 }
@@ -101,17 +84,23 @@ qreal MapView::currentScale()
     return currentTransform.m11();
 }
 
-void MapView::scrollContentsBy (int dx, int dy)
+void MapView::mouseMoveEvent(QMouseEvent *event)
 {
-//    qDebug() << __PRETTY_FUNCTION__;
+    m_scenePosition += m_mousePosition - mapToScene(event->pos()).toPoint();
 
-    QGraphicsView::scrollContentsBy(dx, dy);
+    emit viewScrolled(m_scenePosition);
+    //qDebug() << __PRETTY_FUNCTION__ << "m_scenePosition" << m_scenePosition;
 
-    QPoint centerInScene = mapToScene(frameRect().center()).toPoint();
-//    qDebug() << __PRETTY_FUNCTION__ << "centerInScene:" << centerInScene;
-    emit viewScrolled(centerInScene);
+    m_mousePosition = mapToScene(event->pos()).toPoint();
 }
 
+void MapView::mousePressEvent(QMouseEvent *event)
+{
+    m_mousePosition = mapToScene(event->pos()).toPoint();
+    m_scenePosition = mapToScene(width() / 2 - 1, height() / 2 - 1).toPoint();
+}
+
+
 void MapView::centerToSceneCoordinates(QPoint sceneCoordinate)
 {
 //    qDebug() << __PRETTY_FUNCTION__ << "sceneCoordinate" << sceneCoordinate;
index 92fed60..2399e8f 100644 (file)
@@ -27,7 +27,6 @@
 /**
 * @brief Map view widget
 *
-* QAbstractKineticScroller is enabled when built for Maemo5.
 * @author Sami Rämö - sami.ramo (at) ixonos.com
 */
 class MapView : public QGraphicsView
@@ -41,16 +40,6 @@ public:
     */
     MapView(QWidget *parent = 0);
 
-protected:
-    /**
-    * @brief Handler for view scrolling events
-    *
-    * Does emit viewScrolled signal
-    * @param dx
-    * @param dy
-    */
-    void scrollContentsBy(int dx, int dy);
-
 private:
     //
     /**
@@ -91,6 +80,24 @@ protected:
 
 private slots:
     /**
+    * @brief Slot for mouse move events
+    *
+    * Does calculate mouse movement delta from last event position and new view center
+    * based on that delta. Saves current event position for next round. Emits viewScrolled
+    * signal and doesn't actually scroll the view.
+    * @param event Mouse event
+    */
+    void mouseMoveEvent(QMouseEvent *event);
+
+    /**
+    * @brief Slot for mouse press events
+    *
+    * Saves inial values for mouse and scene location for dragging view.
+    * @param event Mouse event
+    */
+    void mousePressEvent(QMouseEvent *event);
+
+    /**
     * @brief Timer events for smooth zoom effect
     *
     * @param event
@@ -98,6 +105,8 @@ private slots:
     void timerEvent(QTimerEvent *event);
 
 private:
+    QPoint m_mousePosition; ///< Previous mouse event position
+    QPoint m_scenePosition; ///< New center position
     qreal m_zoomTargetScale; ///< Scaling factor of the target zoom level
     qreal m_zoomScaleDelta; ///< Scaling factor delta for smooth zoom transition effect
 };
index 3f25272..40e785e 100644 (file)
@@ -28,7 +28,6 @@ class TestMapEngine: public QObject
     Q_OBJECT
 private slots:
     void convertTileNumberToSceneCoordinate();
-//    void setViewLocation();
     void convertLatLonToSceneCoordinate_data();
     void convertLatLonToSceneCoordinate();
     void setLocationNewTilesCount();
@@ -50,17 +49,6 @@ void TestMapEngine::convertTileNumberToSceneCoordinate()
 }
 
 /**
-* @brief DUMMY TESTCASE!
-*
-* @todo Actual test should be added when there is something to be tested
-*/
-//void TestMapEngine::setViewLocation()
-//{
-//    MapEngine mapEngine;
-//    mapEngine.setViewLocation(QPointF(25.0000, 65.0000));
-//}
-
-/**
   * @brief Test data for converting latitude and longitude coordinates to scene coordinates
   */
 void TestMapEngine::convertLatLonToSceneCoordinate_data()
@@ -68,8 +56,11 @@ void TestMapEngine::convertLatLonToSceneCoordinate_data()
     QTest::addColumn<QPointF>("coordinate");
     QTest::addColumn<QPoint>("result");
 
-    QTest::newRow("top left") << QPointF(-180, 85.0511) << QPoint(0, 0);
-    QTest::newRow("bottom right") << QPointF(180, -85.0511) << QPoint(67108863, 67108863);
+    QTest::newRow("top left") << QPointF(MIN_LONGITUDE, MAX_LATITUDE) << QPoint(0, 0);
+
+    int x = (1 << MAX_MAP_ZOOM_LEVEL) * TILE_SIZE_X;
+    int y = (1 << MAX_MAP_ZOOM_LEVEL) * TILE_SIZE_Y;
+    QTest::newRow("bottom right") << QPointF(MAX_LONGITUDE, MIN_LATITUDE) << QPoint(x, y);
 }
 
 /**