return QRect(topLeft, m_tilesGridSize);
}
-void MapEngine::centerAndZoomTo(QRect rect)
+void MapEngine::centerAndZoomTo(QRect rect, bool useMargins)
{
- const int MARGIN_HORIZONTAL = 50;
- const int MARGIN_VERTICAL = 5;
+ qDebug() << __PRETTY_FUNCTION__;
+
+ int marginHorizontal = 50;
+ int marginVertical = 5;
+
+ if (!useMargins) {
+ marginHorizontal = 0;
+ marginVertical = 0;
+ }
// calculate the usable size of the view
- int viewUsableHeight = m_viewSize.height() - 2 * MARGIN_VERTICAL;
- int viewUsableWidth = m_viewSize.width() - 2 * MARGIN_HORIZONTAL;
+ int viewUsableHeight = m_viewSize.height() - 2 * marginHorizontal;
+ int viewUsableWidth = m_viewSize.width() - 2 * marginVertical;
// calculate how many levels must be zoomed out from the closest zoom level to get the rect
// fit inside the usable view area
return (centerTile != temp);
}
+void MapEngine::locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QRect area;
+ area.setTopRight(SceneCoordinate(neBound).toPointF().toPoint());
+ area.setBottomLeft(SceneCoordinate(swBound).toPointF().toPoint());
+
+ centerAndZoomTo(area, false);
+}
+
qreal MapEngine::sceneResolution()
{
qDebug() << __PRETTY_FUNCTION__;
zoomed();
}
}
-
-void MapEngine::locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- centerAndZoomTo(QRect(SceneCoordinate(swBound).toPointF().toPoint(),
- SceneCoordinate(neBound).toPointF().toPoint()));
-}
* as big as possible.
*
* @param rect Target rect
+ * @param useMargins true if margins should be added to rect, false otherwise
*/
- void centerAndZoomTo(QRect rect);
+ void centerAndZoomTo(QRect rect, bool useMargins = true);
/**
* @brief Request disabling of auto centering if centered too far from the real location.
void gpsPositionUpdate(GeoCoordinate position, qreal accuracy);
/**
+ * @brief Called when location item is clicked.
+ *
+ * Calls centerAndZoomTo() with bounds.
+ * @param swBound south-west bound of location item
+ * @param neBound north-east bound of location item
+ */
+ void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
+
+ /**
* @brief Slot for received map tile images
*
* Does receive map tile images from MapFetcher. Calls MapScene::addTile() for creating and adding
*/
void zoomOut();
- void locationItemClicked(GeoCoordinate &swBound, GeoCoordinate &neBound);
-
/*******************************************************************************
* SIGNALS
******************************************************************************/