Made a few changes that enables custom zoom buttons into map view
authorPekka Nissinen <pekka.nissinen@ixonos.com>
Wed, 21 Apr 2010 07:55:49 +0000 (10:55 +0300)
committerPekka Nissinen <pekka.nissinen@ixonos.com>
Wed, 21 Apr 2010 07:55:49 +0000 (10:55 +0300)
src/images.qrc
src/map/mapcommon.h
src/map/mapengine.cpp
src/map/mapengine.h
src/map/mapview.cpp
src/map/mapview.h
src/src.pro
src/ui/mapviewscreen.cpp

index 7095d4f..5a44cae 100644 (file)
@@ -8,5 +8,7 @@
         <file>resources/clock_small.png</file>
         <file>resources/arrow_left.png</file>
         <file>resources/arrow_right.png</file>
+        <file>resources/zoom_in.png</file>
+        <file>resources/zoom_out.png</file>
     </qresource>
 </RCC>
index 2ebb115..6435843 100644 (file)
@@ -35,6 +35,12 @@ const int MIN_MAP_SCENE_NORMAL_LEVEL = MAX_MAP_ZOOM_LEVEL + 1;
 const int ZOOM_FPS = 30; ///< FPS for the zoom effect
 const qreal ZOOM_TIME = 250; ///< Length of the zoom effect (ms)
 
+static const int MAP_ZOOM_PANEL_POSITION_X = 10; ///< Horizontal position of zoom panel
+static const int MAP_ZOOM_PANEL_POSITION_Y = 10; ///< Vertical position of zoom panel
+static const int MAP_ZOOM_PANEL_LEVEL = MIN_MAP_SCENE_NORMAL_LEVEL
+                                        + MAX_MAP_ZOOM_LEVEL + 2; ///< Zepth of zoom panel (Z-axis)
+static const int MAP_ZOOM_PANEL_BUTTON_SIZE = 48; ///< Size of a zoom panel button
+
 const qreal MAX_LATITUDE = 85.05112877980659237802;  ///< Maximum latitude value
 const qreal MIN_LATITUDE = -MAX_LATITUDE; ///< Minimum latitude value
 const qreal MIN_LONGITUDE = -180.0;  ///< Minimum longitude value
index f05a470..831f008 100644 (file)
@@ -4,6 +4,7 @@
 
        Sami Rämö - sami.ramo@ixonos.com
        Jussi Laitinen - jussi.laitinen@ixonos.com
+       Pekka Nissinen - pekka.nissinen@ixonos.com
 
    Situare is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
@@ -43,6 +44,11 @@ MapEngine::MapEngine(QObject *parent)
     connect(this, SIGNAL(fetchImage(QUrl)), m_mapFetcher, SLOT(fetchMapImage(QUrl)));
     connect(m_mapFetcher, SIGNAL(mapImageReceived(QUrl,QPixmap)), this,
             SLOT(mapImageReceived(QUrl, QPixmap)));
+
+    m_mapZoomPanel = new MapZoomPanel(NULL, MAP_ZOOM_PANEL_POSITION_X, MAP_ZOOM_PANEL_POSITION_Y);
+    m_mapScene->addItem(m_mapZoomPanel);
+    connect(m_mapZoomPanel, SIGNAL(zoomInPressed()), this, SLOT(zoomIn()));
+    connect(m_mapZoomPanel, SIGNAL(zoomOutPressed()), this, SLOT(zoomOut()));
 }
 
 void MapEngine::init()
@@ -126,9 +132,16 @@ QRect MapEngine::calculateTileGrid(QPoint sceneCoordinate)
     return QRect(topLeftX, topLeftY, gridWidth, gridHeight);
 }
 
+void MapEngine::alignImmovableItems(QPoint viewTopLeft)
+{
+    m_mapZoomPanel->setPos(viewTopLeft);
+
+//    qDebug() << __PRETTY_FUNCTION__ << "viewTopLeft:" << viewTopLeft;
+}
+
 void MapEngine::setLocation(QPoint sceneCoordinate)
 {
-    //qDebug() << __PRETTY_FUNCTION__;
+//    qDebug() << __PRETTY_FUNCTION__;
 
     m_sceneCoordinate = sceneCoordinate;
     emit locationChanged(m_sceneCoordinate);
@@ -187,7 +200,7 @@ void MapEngine::getTiles(QPoint sceneCoordinate)
 
 void MapEngine::removeTile(MapTile *tile)
 {
-    //qDebug() << __PRETTY_FUNCTION__;
+//    qDebug() << __PRETTY_FUNCTION__;
 
     if (tile) {
        m_mapTilesInScene.remove(tilePath(tile->zoomLevel(), tile->tileNumber().x(),
@@ -199,7 +212,7 @@ void MapEngine::removeTile(MapTile *tile)
 
 void MapEngine::removeTilesOutOfView()
 {
-    //qDebug() << __PRETTY_FUNCTION__;
+//    qDebug() << __PRETTY_FUNCTION__;
 
     QPoint topLeft = convertTileNumberToSceneCoordinate(m_zoomLevel, m_viewGrid.topLeft());
     QPoint bottomRight = convertTileNumberToSceneCoordinate(m_zoomLevel, m_viewGrid.bottomRight()
@@ -224,7 +237,7 @@ void MapEngine::removeTilesOutOfView()
 
 void MapEngine::removeStackedTiles(MapTile *newTile)
 {
-    //qDebug() << __PRETTY_FUNCTION__;
+//    qDebug() << __PRETTY_FUNCTION__;
 
     QRectF newTileSceneRect = newTile->sceneBoundingRect();
     QList<QGraphicsItem *> collidingTiles = newTile->collidingItems(Qt::IntersectsItemBoundingRect);
@@ -315,7 +328,7 @@ void MapEngine::zoomOut()
 
 void MapEngine::setTilesDrawingLevels()
 {
-    //qDebug() << __PRETTY_FUNCTION__ << "m_zoomLevel:" << m_zoomLevel;
+//    qDebug() << __PRETTY_FUNCTION__ << "m_zoomLevel:" << m_zoomLevel;
 
     QList<QGraphicsItem *> items = m_mapScene->items();
 
@@ -324,7 +337,6 @@ void MapEngine::setTilesDrawingLevels()
         if (item)
             item->setSceneLevel(m_zoomLevel);
     }
-
 }
 
 QString MapEngine::tilePath(int zoomLevel, int x, int y)
@@ -336,12 +348,6 @@ QString MapEngine::tilePath(int zoomLevel, int x, int y)
     return tilePathString;
 }
 
-void MapEngine::scalingFactorChanged(qreal scaleFactor)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-    Q_UNUSED(scaleFactor);
-}
-
 QPoint MapEngine::convertSceneCoordinateToTileNumber(int zoomLevel, QPoint sceneCoordinate)
 {
     int pow = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
index 9e202f5..9637592 100644 (file)
@@ -4,6 +4,7 @@
 
        Sami Rämö - sami.ramo@ixonos.com
        Jussi Laitinen - jussi.laitinen@ixonos.com
+       Pekka Nissinen - pekka.nissinen@ixonos.com
 
    Situare is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
@@ -29,6 +30,7 @@
 #include "mapfetcher.h"
 #include "mapscene.h"
 #include "maptile.h"
+#include "mapzoompanel.h"
 
 /**
 * @brief Map engine
@@ -37,6 +39,7 @@
 * converting coordinates.
 * @author Sami Rämö - sami.ramo (at) ixonos.com
 * @author Jussi Laitinen - jussi.laitinen (at) ixonos.com
+* @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
 */
 class MapEngine : public QObject
 {
@@ -104,6 +107,13 @@ public:
 
 public slots:
     /**
+    * @brief Slot for immovable scene items position correction
+    *
+    * @param viewTopLeft Scene coordinate of the viewport top left corner
+    */
+    void alignImmovableItems(QPoint viewTopLeft);
+
+    /**
     * @brief Slot for setting current view location
     *
     * Emits locationChanged signal.
@@ -233,15 +243,6 @@ private slots:
     void removeTilesOutOfView();
 
     /**
-    * @brief Slot for view scaling factor change events
-    *
-    * Can be used to trigger scaling of zoom buttons, friend indicators and other
-    * MapScene elements which should retain their visual size
-    * @param scaleFactor view's scale factor
-    */
-    void scalingFactorChanged(qreal scaleFactor);
-
-    /**
     * @brief Slot for zooming in
     *
     */
@@ -282,13 +283,14 @@ signals:
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    QPoint m_centerTile;    ///< Current center tile
     MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
     MapScene *m_mapScene; ///< Scene for map tiles
+    MapZoomPanel *m_mapZoomPanel; ///< Toolbar for zoom buttons
     QHash<QString, MapTile *> m_mapTilesInScene;  ///< List of map tiles in map scene
-    QPoint m_sceneCoordinate;  ///< Current center coordinate
+    QPoint m_centerTile; ///< Current center tile
+    QPoint m_sceneCoordinate; ///< Current center coordinate
     QRect m_viewGrid; ///< Current grid of tiles in view
-    QSize m_viewSize;   ///< Current view size
+    QSize m_viewSize; ///< Current view size
     int m_zoomLevel; ///< Current zoom level
 };
 
index cf8c27c..ee68274 100644 (file)
@@ -81,8 +81,8 @@ void MapView::timerEvent(QTimerEvent *event)
 
         QTransform transform;
         transform.scale(scaleFactor, scaleFactor);
-        emit scalingFactorChanged(scaleFactor);
         setTransform(transform);
+       emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
     }
 }
 
@@ -97,18 +97,20 @@ void MapView::mouseMoveEvent(QMouseEvent *event)
     m_scenePosition += m_mousePosition - mapToScene(event->pos()).toPoint();
 
     emit viewScrolled(m_scenePosition);
-    //qDebug() << __PRETTY_FUNCTION__ << "m_scenePosition" << m_scenePosition;
+//    qDebug() << __PRETTY_FUNCTION__ << "m_scenePosition:" << m_scenePosition;
 
     m_mousePosition = mapToScene(event->pos()).toPoint();
+    emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
 }
 
 void MapView::mousePressEvent(QMouseEvent *event)
 {
+    QGraphicsView::mousePressEvent(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;
@@ -117,6 +119,7 @@ void MapView::centerToSceneCoordinates(QPoint sceneCoordinate)
 
 void MapView::resizeEvent(QResizeEvent *event)
 {
-    //qDebug() << "Resize event: " << event->size();
+//    qDebug() << "Resize event: " << event->size();
     emit viewResized(event->size());
+    emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
 }
index 7ad9005..17eeb88 100644 (file)
@@ -32,6 +32,7 @@
 class MapView : public QGraphicsView
 {
     Q_OBJECT
+
 public:
     /**
     * @brief Constructor
@@ -108,15 +109,6 @@ private:
  ******************************************************************************/
 signals:
     /**
-    * @brief Signal for view scale factor change events
-    *
-    * Can be used to trigger scaling of zoom buttons, friend indicators and other
-    * MapScene elements which should retain their visual size
-    * @param scaleFactor view's scale factor
-    */
-    void scalingFactorChanged(qreal scaleFactor);
-
-    /**
     * @brief Signal for view resize events.
     *
     * Signal is emitted when view has been resized.
@@ -132,6 +124,14 @@ signals:
     */
     void viewScrolled(QPoint sceneCoordinate);
 
+    /**
+    * @brief Signal for updating view content
+    *
+    * Signal is emitted when view content needs an update.
+    * @param viewTopLeft Scene coordinate of the viewport top left corner
+    */
+    void viewContentChanged(QPoint viewTopLeft);
+
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
index 692831f..0c7b4f3 100644 (file)
@@ -17,6 +17,8 @@ SOURCES += main.cpp \
     map/mapscene.cpp \
     map/maptile.cpp \
     map/mapfetcher.cpp \
+    map/mapzoompanel.cpp \
+    map/mapbutton.cpp \
     ui/pixmap.cpp \
     ui/infotab.cpp \
     ui/updatelocation/updatelocationdialog.cpp \
@@ -30,6 +32,8 @@ HEADERS += ui/mainwindow.h \
     map/maptile.h \
     map/mapfetcher.h \
     map/mapcommon.h \
+    map/mapzoompanel.h \
+    map/mapbutton.h \
     ui/pixmap.h \
     ui/infotab.h \
     ui/updatelocation/updatelocationdialog.h \
index cc7b7da..53b7183 100644 (file)
@@ -37,8 +37,8 @@ MapViewScreen::MapViewScreen(QWidget *parent)
             mapView, SLOT(centerToSceneCoordinates(QPoint)));
     connect(mapEngine, SIGNAL(zoomLevelChanged(int)), mapView, SLOT(setZoomLevel(int)));
     connect(mapView, SIGNAL(viewResized(QSize)), mapEngine, SLOT(viewResized(QSize)));
-    connect(mapView, SIGNAL(scalingFactorChanged(qreal)),
-            mapEngine, SLOT(scalingFactorChanged(qreal)));
+    connect(mapView, SIGNAL(viewContentChanged(QPoint)),
+            mapEngine, SLOT(alignImmovableItems(QPoint)));
 
     QHBoxLayout *mapViewLayout = new QHBoxLayout;
     //DEBUG