Also removed some old stuff from self made scolling.
{
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++) {
{
qDebug() << __PRETTY_FUNCTION__;
setLocation(convertLatLonToSceneCoordinate(latLonCoordinate));
+ emit locationChanged(m_sceneCoordinate);
}
QUrl MapEngine::buildURL(int zoomLevel, QPoint tileNumbers)
return (1 << zoomLevel) - 1;
}
-QRect MapEngine::calculateGrid(QPointF sceneCoordinate)
+QRect MapEngine::calculateGrid(QPoint sceneCoordinate)
{
QPoint tileCoordinate = convertSceneCoordinateToTileNumber(m_zoomLevel, 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);
}
}
-bool MapEngine::centerTileChanged(QPointF sceneCoordinate)
+bool MapEngine::centerTileChanged(QPoint sceneCoordinate)
{
QPoint centerTile = convertSceneCoordinateToTileNumber(m_zoomLevel, sceneCoordinate);
QPoint temp = m_centerTile;
return (centerTile != temp);
}
-void MapEngine::calculateTileGrid(QPointF sceneCoordinate)
+void MapEngine::calculateTileGrid(QPoint sceneCoordinate)
{
//qDebug() << __PRETTY_FUNCTION__;
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();
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;
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));
* @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__;
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:
/**
* Emits locationChanged signal.
* @param sceneCoordinate Scene coordinates for new position
*/
- void setLocation(QPointF sceneCoordinate);
+ void setLocation(QPoint sceneCoordinate);
void viewResized(const QSize &size);
*
* @param sceneCoordinate New scene coordinates
*/
- void locationChanged(QPointF sceneCoordinate);
+ void locationChanged(QPoint sceneCoordinate);
/**
* @brief Signal for zoom level change
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;
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);
}
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:
/**
* @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);
*
* @param sceneCoordinate Scene coordinates of the new center point
*/
- void centerToSceneCoordinates(QPointF sceneCoordinate);
+ void centerToSceneCoordinates(QPoint sceneCoordinate);
/**
* @brief Set zoom level of the view
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:
- 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
};
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)));
qDebug() << lat << "," << lon;
mapEngine->setViewLocation(QPointF(lon, lat));
-}
\ No newline at end of file
+}