removeStackedTiles() was disabled because it breaks zoom in.
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
{
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)
mapTilesInScene.insert(tilePath(zoom, x, y), mapTile);
m_mapScene->addMapTile(mapTile);
- removeStackedTiles(mapTile);
+// removeStackedTiles(mapTile);
}
}
//qDebug() << __PRETTY_FUNCTION__;
m_sceneCoordinate = sceneCoordinate;
+ emit locationChanged(m_sceneCoordinate);
if (centerTileChanged(sceneCoordinate)) {
calculateNewTiles(sceneCoordinate);
emit zoomLevelChanged(m_zoomLevel);
setZValues();
+
+ calculateNewTiles(m_sceneCoordinate);
+ removeOldTiles();
}
void MapEngine::zoomOut()
emit zoomLevelChanged(m_zoomLevel);
setZValues();
+
+ calculateNewTiles(m_sceneCoordinate);
}
void MapEngine::setZValues()
#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"
* 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);
}
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;
/**
* @brief Map view widget
*
-* QAbstractKineticScroller is enabled when built for Maemo5.
* @author Sami Rämö - sami.ramo (at) ixonos.com
*/
class MapView : public QGraphicsView
*/
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:
//
/**
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
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
};
Q_OBJECT
private slots:
void convertTileNumberToSceneCoordinate();
-// void setViewLocation();
void convertLatLonToSceneCoordinate_data();
void convertLatLonToSceneCoordinate();
void setLocationNewTilesCount();
}
/**
-* @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()
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);
}
/**