Replaced floating point coordinates with integer ones where possible
authorSami Rämö <sami.ramo@ixonos.com>
Thu, 15 Apr 2010 09:37:21 +0000 (12:37 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Thu, 15 Apr 2010 09:37:21 +0000 (12:37 +0300)
Also removed some old stuff from self made scolling.

src/map/mapengine.cpp
src/map/mapengine.h
src/map/mapview.cpp
src/map/mapview.h
src/ui/mapviewscreen.cpp

index 5dbdcdc..177f930 100644 (file)
@@ -53,6 +53,7 @@ void MapEngine::init()
 {
     emit zoomLevelChanged(m_zoomLevel);
     setViewLocation(QPointF(25.5000, 65.0000));
+    emit locationChanged(m_sceneCoordinate);
 
 //    // Fetch some map tiles for demo purposes
 //    for (int x=9351; x<=9354; x++) {
@@ -67,6 +68,7 @@ void MapEngine::setViewLocation(QPointF latLonCoordinate)
 {
     qDebug() << __PRETTY_FUNCTION__;
     setLocation(convertLatLonToSceneCoordinate(latLonCoordinate));
+    emit locationChanged(m_sceneCoordinate);
 }
 
 QUrl MapEngine::buildURL(int zoomLevel, QPoint tileNumbers)
@@ -123,7 +125,7 @@ int MapEngine::tileMaxValue(int zoomLevel)
     return (1 << zoomLevel) - 1;
 }
 
-QRect MapEngine::calculateGrid(QPointF sceneCoordinate)
+QRect MapEngine::calculateGrid(QPoint sceneCoordinate)
 {
     QPoint tileCoordinate = convertSceneCoordinateToTileNumber(m_zoomLevel, sceneCoordinate);
 
@@ -136,10 +138,9 @@ QRect MapEngine::calculateGrid(QPointF sceneCoordinate)
     return QRect(topLeftX, topLeftY, gridWidth, gridHeight);
 }
 
-void MapEngine::setLocation(QPointF sceneCoordinate)
+void MapEngine::setLocation(QPoint sceneCoordinate)
 {
     m_sceneCoordinate = sceneCoordinate;
-    emit locationChanged(m_sceneCoordinate);
 
     if (centerTileChanged(sceneCoordinate)) {
         calculateTileGrid(sceneCoordinate);
@@ -147,7 +148,7 @@ void MapEngine::setLocation(QPointF sceneCoordinate)
     }
 }
 
-bool MapEngine::centerTileChanged(QPointF sceneCoordinate)
+bool MapEngine::centerTileChanged(QPoint sceneCoordinate)
 {
     QPoint centerTile = convertSceneCoordinateToTileNumber(m_zoomLevel, sceneCoordinate);
     QPoint temp = m_centerTile;
@@ -156,7 +157,7 @@ bool MapEngine::centerTileChanged(QPointF sceneCoordinate)
     return (centerTile != temp);
 }
 
-void MapEngine::calculateTileGrid(QPointF sceneCoordinate)
+void MapEngine::calculateTileGrid(QPoint sceneCoordinate)
 {
     //qDebug() << __PRETTY_FUNCTION__;
 
@@ -201,8 +202,8 @@ void MapEngine::removeTilesOutOfBounds()
 
     int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - m_zoomLevel);
 
-    QPointF topLeft = convertTileNumberToSceneCoordinate(m_zoomLevel, viewGrid.topLeft());
-    QPointF bottomRight = convertTileNumberToSceneCoordinate(m_zoomLevel, viewGrid.bottomRight() + QPoint(1, 1));
+    QPoint topLeft = convertTileNumberToSceneCoordinate(m_zoomLevel, viewGrid.topLeft());
+    QPoint bottomRight = convertTileNumberToSceneCoordinate(m_zoomLevel, viewGrid.bottomRight() + QPoint(1, 1));
     qreal width = bottomRight.x() - topLeft.x();
     qreal height = bottomRight.y() - topLeft.y();
 
@@ -262,16 +263,6 @@ void MapEngine::zoomOut()
     calculateTileGrid(m_sceneCoordinate);
 }
 
-void MapEngine::setZoomLevel(int zoomLevel)
-{
-    m_zoomLevel = zoomLevel;
-}
-
-int MapEngine::getZoomLevel()
-{
-    return m_zoomLevel;
-}
-
 void MapEngine::setZValues()
 {
     //qDebug() << __PRETTY_FUNCTION__ << "m_zoomLevel:" << m_zoomLevel;
index c6b6b6f..cc05ea9 100644 (file)
@@ -74,7 +74,7 @@ public:
         return QPoint(x, y);
     }
 
-    static QPoint convertSceneCoordinateToTileNumber(int zoomLevel, QPointF sceneCoordinate)
+    static QPoint convertSceneCoordinateToTileNumber(int zoomLevel, QPoint sceneCoordinate)
     {
         int pow = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
         int x = static_cast<int>(sceneCoordinate.x() / (TILE_SIZE_X*pow));
@@ -104,7 +104,7 @@ public:
     * @param latLonCoordinate latitude and longitude values
     * @return scene coordinate
     */
-    static QPointF convertLatLonToSceneCoordinate(QPointF latLonCoordinate)
+    static QPoint convertLatLonToSceneCoordinate(QPointF latLonCoordinate)
     {
         /// @todo CREATE TEST CASE & CHECK CALCULATION
         qDebug() << __PRETTY_FUNCTION__;
@@ -123,17 +123,14 @@ public:
         qreal y = static_cast<qreal>((1.0 - log(tan(latitude * M_PI / 180.0) + 1.0
                                     / cos(latitude * M_PI / 180.0)) / M_PI) / 2.0);
 
-        return QPointF(x*z*TILE_SIZE_X, y*z*TILE_SIZE_Y);
+        return QPointF(x*z*TILE_SIZE_X, y*z*TILE_SIZE_Y).toPoint();
     }
 
-    QRect calculateGrid(QPointF sceneCoordinate);
+    QRect calculateGrid(QPoint sceneCoordinate);
 
     void removeTilesOutOfBounds();
 
-    int getZoomLevel();
-    void setZoomLevel(int zoomLevel);
-
-    void calculateTileGrid(QPointF sceneCoordinate);
+    void calculateTileGrid(QPoint sceneCoordinate);
 
 public slots:
     /**
@@ -142,7 +139,7 @@ public slots:
     * Emits locationChanged signal.
     * @param sceneCoordinate Scene coordinates for new position
     */
-    void setLocation(QPointF sceneCoordinate);
+    void setLocation(QPoint sceneCoordinate);
 
     void viewResized(const QSize &size);
 
@@ -208,7 +205,7 @@ signals:
     *
     * @param sceneCoordinate New scene coordinates
     */
-    void locationChanged(QPointF sceneCoordinate);
+    void locationChanged(QPoint sceneCoordinate);
 
     /**
     * @brief Signal for zoom level change
@@ -219,18 +216,16 @@ signals:
 
     void fetchImage(const QUrl &url);
 
-    void centerToSceneCoordinates(QPointF sceneCoordinate);
-
 private:
 
-    bool centerTileChanged(QPointF sceneCoordinate);
+    bool centerTileChanged(QPoint sceneCoordinate);
 
     MapScene *m_mapScene; ///< Scene for map tiles
     MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
     int m_zoomLevel; ///< Current zoom level
     QHash<QString, MapTile *> mapTilesInScene;  ///< List of map tiles in map scene
     QSize m_viewSize;
-    QPointF m_sceneCoordinate;
+    QPoint m_sceneCoordinate;
     QQueue<QString> mapTilesInView;
     QPoint m_centerTile;
     QRect viewGrid;
index 7eb3195..db16240 100644 (file)
@@ -103,31 +103,18 @@ qreal MapView::currentScale()
 
 void MapView::scrollContentsBy (int dx, int dy)
 {
-    qDebug() << __PRETTY_FUNCTION__ << "dx:" << dx << "dy:" << dy;
+//    qDebug() << __PRETTY_FUNCTION__;
 
     QGraphicsView::scrollContentsBy(dx, dy);
+
+    QPoint centerInScene = mapToScene(frameRect().center()).toPoint();
+//    qDebug() << __PRETTY_FUNCTION__ << "centerInScene:" << centerInScene;
+    emit viewScrolled(centerInScene);
 }
 
-//void MapView::mouseMoveEvent(QMouseEvent *event)
-//{
-//    m_scenePosition += m_mousePosition - mapToScene(event->pos());
-//
-//    emit viewScrolled(m_scenePosition);
-//    //qDebug() << __PRETTY_FUNCTION__ << "m_scenePosition" << m_scenePosition;
-//
-//    m_mousePosition = mapToScene(event->pos());
-//}
-//
-//void MapView::mousePressEvent(QMouseEvent *event)
-//{
-//    m_mousePosition = mapToScene(event->pos());
-//    m_scenePosition = mapToScene(width() / 2 - 1, height() / 2 - 1);
-//}
-
-
-void MapView::centerToSceneCoordinates(QPointF sceneCoordinate)
+void MapView::centerToSceneCoordinates(QPoint sceneCoordinate)
 {
-    //qDebug() << __PRETTY_FUNCTION__ << "sceneCoordinate" << sceneCoordinate;
+//    qDebug() << __PRETTY_FUNCTION__ << "sceneCoordinate" << sceneCoordinate;
     centerOn(sceneCoordinate);
 }
 
index d92a4d2..92fed60 100644 (file)
@@ -42,6 +42,13 @@ 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:
@@ -57,10 +64,10 @@ signals:
     /**
     * @brief Signal for view scroll events
     *
-    * Signal is emitted when view scroll is requested with mouse (or finger).
-    * @param sceneCoordinate Scene coordinates of the new requested center point of the view
+    * Signal is emitted when view is scrolled.
+    * @param sceneCoordinate Scene coordinates of the new center point of the view
     */
-    void viewScrolled(QPointF sceneCoordinate);
+    void viewScrolled(QPoint sceneCoordinate);
 
     void viewResized(const QSize &size);
 
@@ -70,7 +77,7 @@ public slots:
     *
     * @param sceneCoordinate Scene coordinates of the new center point
     */
-    void centerToSceneCoordinates(QPointF sceneCoordinate);
+    void centerToSceneCoordinates(QPoint sceneCoordinate);
 
     /**
     * @brief Set zoom level of the view
@@ -84,24 +91,6 @@ 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
@@ -109,8 +98,6 @@ private slots:
     void timerEvent(QTimerEvent *event);
 
 private:
-    QPointF m_mousePosition; ///< Previous mouse event position
-    QPointF 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 978d368..a736179 100644 (file)
@@ -30,9 +30,9 @@ MapViewScreen::MapViewScreen(QWidget *parent)
     mapEngine = new MapEngine(this);
     mapView->setScene(mapEngine->scene());
 
-    connect(mapView, SIGNAL(viewScrolled(QPointF)), mapEngine, SLOT(setLocation(QPointF)));
-    connect(mapEngine, SIGNAL(locationChanged(QPointF)),
-           mapView, SLOT(centerToSceneCoordinates(QPointF)));
+    connect(mapView, SIGNAL(viewScrolled(QPoint)), mapEngine, SLOT(setLocation(QPoint)));
+    connect(mapEngine, SIGNAL(locationChanged(QPoint)),
+           mapView, SLOT(centerToSceneCoordinates(QPoint)));
     connect(mapEngine, SIGNAL(zoomLevelChanged(int)), mapView, SLOT(setZoomLevel(int)));
     connect(mapView, SIGNAL(viewResized(QSize)), mapEngine, SLOT(viewResized(QSize)));
 
@@ -68,4 +68,4 @@ void MapViewScreen::searchMap()
     qDebug() << lat << "," << lon;
 
     mapEngine->setViewLocation(QPointF(lon, lat));
-}
\ No newline at end of file
+}