2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@ixonos.com
6 Jussi Laitinen - jussi.laitinen@ixonos.com
7 Pekka Nissinen - pekka.nissinen@ixonos.com
8 Ville Tiensuu - ville.tiensuu@ixonos.com
10 Situare is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 version 2 as published by the Free Software Foundation.
14 Situare is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Situare; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
30 #include "mapfetcher.h"
33 #include "ownlocationitem.h"
34 #include "user/user.h"
36 class FriendItemsHandler;
37 class GPSLocationItem;
42 * Logic for controlling map functionality. Does also include static methods for
43 * converting coordinates.
45 * @author Sami Rämö - sami.ramo (at) ixonos.com
46 * @author Jussi Laitinen - jussi.laitinen (at) ixonos.com
47 * @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
48 * @author Ville Tiensuu - ville.tiensuu (at) ixonos.com
50 class MapEngine : public QObject
58 * @param parent Parent
60 MapEngine(QObject *parent = 0);
62 /*******************************************************************************
63 * MEMBER FUNCTIONS AND SLOTS
64 ******************************************************************************/
67 * @brief Convert latitude and longitude to scene coordinates.
69 * @param latLonCoordinate latitude and longitude values
70 * @return scene coordinate
72 static QPoint convertLatLonToSceneCoordinate(QPointF latLonCoordinate);
75 * @brief Convert MapScene coordinate to tile x & y numbers.
77 * @param zoomLevel ZoomLevel
78 * @param sceneCoordinate MapScene coordinate
79 * @return QPoint tile x & y numbers
81 static QPoint convertSceneCoordinateToTileNumber(int zoomLevel, QPoint sceneCoordinate);
84 * @brief Convert tile x & y numbers to MapScene coordinates
86 * @param zoomLevel Zoom level
87 * @param tileNumber x & y numbers of the tile
88 * @return QPoint MapScene coordinate
90 static QPoint convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber);
93 * @brief MapEngine initializer
95 * Set initial location and zoom level for the engine. locationChanged and
96 * zoomLevelChanged signals are emitted, so init should be called after
97 * those signals are connected to MapView.
102 * @brief Getter for scene
104 * @return QGraphicsScene
106 QGraphicsScene* scene();
109 * @brief Return tile path created from tile values.
111 * @param zoomLevel tile's zoom level
112 * @param x tile's x value
113 * @param y tile's y value
114 * @return QString tile path
116 static QString tilePath(int zoomLevel, int x, int y);
119 * @brief converts scene coordinates to latitude and longitude
121 * @param current zoom level
122 * @param sceneCoordinate that will be converted
124 QPointF convertSceneCoordinateToLatLon(int zoomLevel, QPoint sceneCoordinate);
128 * @brief Slot for setting current view location
130 * Emits locationChanged signal.
131 * @param sceneCoordinate Scene coordinates for new position
133 void setLocation(QPoint sceneCoordinate);
136 * @brief Helper for setting view location based on latitude and longitude
139 * @param latLonCoordinate Latitude & longitude coordinates for location
141 void setViewLocation(QPointF latLonCoordinate);
144 * @brief Slot for view resizing.
146 * @param size view size
148 void viewResized(const QSize &size);
151 * @brief Returns own location crosshair's latitude and longitude coordinates
157 * @brief Slot to catch user own location data
159 * @param user User info
161 void receiveOwnLocation(User *user);
164 * @brief Slot to receive visible area of map scene
166 * @param visible area of map scene
168 void receiveViewSceneRect(QRect viewSceneRect);
172 * @brief Calculate grid of tile coordinates from current scene coordinate.
174 * Grid size is calculated from view size and scene's current center coordinate.
176 * @param sceneCoordinate scene's current center coordinate
177 * @return QRect grid of tile coordinates
179 QRect calculateTileGrid(QPoint sceneCoordinate);
182 * @brief Get new tiles.
184 * Calculates which tiles has to be fetched. Does emit fetchImage for tiles which
185 * aren't already in the scene.
186 * @param sceneCoordinate scene's center coordinate
188 void getTiles(QPoint sceneCoordinate);
191 * @brief Check if auto centering is enabled
193 * @return true if enabled, false otherwise
195 bool isAutoCenteringEnabled();
198 * @brief Check if center tile has changed.
200 * @param sceneCoordinate scene's center coordinate
201 * @return bool true if center tile changed, false otherwise
203 bool isCenterTileChanged(QPoint sceneCoordinate);
206 * @brief Check if auto centering should be disabled.
208 * @param sceneCoordinate scene's center coordinate
209 * @return bool true if auto centering should be disabled
211 bool disableAutoCentering(QPoint sceneCoordinate);
214 * @brief Calculate maximum value for tile in this zoom level.
216 * @param zoomLevel zoom level
217 * @return int tile's maximum value
219 int tileMaxValue(int zoomLevel);
222 * @brief Updates the current view rect including margins
224 * Calculates tiles rect in scene based on m_viewTilesGrid and
225 * calls MapScene::viewRectUpdated()
227 void updateViewTilesSceneRect();
231 * @brief Slot for enabling / disabling GPS
233 * GPS location item is disabled or enabled based on GPS state
235 * @param enabled True is GPS is enabled, otherwise false
237 void gpsEnabled(bool enabled);
240 * @brief Slot for GPS position updates
242 * GPS location item is updated and map centered to new location (if automatic
243 * centering is enabled).
245 * @param position New coordinates from GPS
246 * @param accuracy Accuracy of the GPS fix
248 void gpsPositionUpdate(QPointF position, qreal accuracy);
251 * @brief Slot for received map tile images
253 * Does add MapTile objects to MapScene.
254 * @param zoomLevel Zoom level
255 * @param x Tile x index
256 * @param y Tile y index
257 * @param image Received pixmap
259 void mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image);
262 * @brief Set auto centering.
264 * @param enabled true if enabled, false otherwise
266 void setAutoCentering(bool enabled);
269 * @brief Slot for actions after view zoom is finished
271 * Does run removeOutOfViewTiles
273 void viewZoomFinished();
276 * @brief Slot for zooming in
282 * @brief Slot for zooming out
287 /*******************************************************************************
289 ******************************************************************************/
292 * @brief Signal for image fetching.
294 * @param zoomLevel Zoom level
295 * @param x Tile x index
296 * @param y Tile y index
298 void fetchImage(int zoomLevel, int x, int y);
301 * @brief Signal when friend list locations are fetched
303 * @param friendsList Friends list data
305 void friendsLocationsReady(QList<User *> &friendsList);
308 * @brief Signal for view location change
310 * @param sceneCoordinate New scene coordinates
312 void locationChanged(QPoint sceneCoordinate);
315 * @brief Signal to notify map scrolling.
317 void mapScrolledManually();
320 * @brief Signal to notify when map is zoomed in to the maxmimum.
322 void maxZoomLevelReached();
325 * @brief Signal to notify when map is zoomed out to the minimum.
327 void minZoomLevelReached();
330 * @brief Signal request mapView to update view port contents
332 void requestToGetViewPortContents();
335 * @brief Signal sends location of crosshair
337 * @param ownLocation location of crosshair (Latitude, Longitude)
339 void ownLocation(const QPointF ownLocation);
342 * @brief Signal for zoom level change
344 * @param newZoomLevel New zoom level
346 void zoomLevelChanged(int newZoomLevel);
348 /*******************************************************************************
350 ******************************************************************************/
352 bool m_autoCenteringEnabled; ///< Auto centering enabled
353 QPoint m_centerTile; ///< Current center tile
354 FriendItemsHandler *m_friendItemsHandler; ///< Handler for friend and group items
355 GPSLocationItem *m_gpsLocationItem; ///< Item pointing current location from GPS
356 QPoint m_lastManualPosition; ///< Last manually set position in scene coordinate
357 MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
358 MapScene *m_mapScene; ///< Scene for map tiles
359 OwnLocationItem *m_ownLocation; ///< Item to show own location
360 QPoint m_sceneCoordinate; ///< Current center coordinate
361 QRect m_viewTilesGrid; ///< Current grid of tiles in view (includes margin)
362 QSize m_viewSize; ///< Current view size
363 bool m_zoomedIn; ///< Flag for checking if zoomed in when zoom is finished
364 int m_zoomLevel; ///< Current zoom level
365 QRect m_viewArea; ///< Visible area of map scene
368 #endif // MAPENGINE_H