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,
32 class FriendItemsHandler;
33 class GPSLocationItem;
37 class OwnLocationItem;
43 * Logic for controlling map functionality. Does also include static methods for
44 * converting coordinates.
46 * @author Sami Rämö - sami.ramo (at) ixonos.com
47 * @author Jussi Laitinen - jussi.laitinen (at) ixonos.com
48 * @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
49 * @author Ville Tiensuu - ville.tiensuu (at) ixonos.com
51 class MapEngine : public QObject
59 * @param parent Parent
61 MapEngine(QObject *parent = 0);
65 * Saves view of the map to settings file
69 /*******************************************************************************
70 * MEMBER FUNCTIONS AND SLOTS
71 ******************************************************************************/
74 * @brief Coordinates of the current center point
76 * @return Current coordinates (latitude & longitude)
78 QPointF centerGeoCoordinate();
81 * @brief Convert latitude and longitude to scene coordinates.
83 * @param latLonCoordinate latitude and longitude values
84 * @return scene coordinate
86 static QPoint convertLatLonToSceneCoordinate(QPointF latLonCoordinate);
89 * @brief converts scene coordinates to latitude and longitude
91 * @param zoomLevel current zoom level
92 * @param sceneCoordinate that will be converted
94 QPointF convertSceneCoordinateToLatLon(int zoomLevel, QPoint sceneCoordinate);
97 * @brief Convert MapScene coordinate to tile x & y numbers.
99 * @param zoomLevel ZoomLevel
100 * @param sceneCoordinate MapScene coordinate
101 * @return QPoint tile x & y numbers
103 static QPoint convertSceneCoordinateToTileNumber(int zoomLevel, QPoint sceneCoordinate);
106 * @brief Convert tile x & y numbers to MapScene coordinates
108 * @param zoomLevel Zoom level
109 * @param tileNumber x & y numbers of the tile
110 * @return QPoint MapScene coordinate
112 static QPoint convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber);
115 * @brief Calculate great-circle distance between two geographic coordinates
117 * Calculate great-circle distance between two given geographic locations using
120 * @param firstLocation Coordinates of the first location
121 * @param secondLocation Coordinates of the second location
122 * @return qreal Distance in kilometers
124 qreal greatCircleDistance(QPointF firstLocation, QPointF secondLocation);
127 * @brief MapEngine initializer
129 * Set initial location and zoom level for the engine. locationChanged and
130 * zoomLevelChanged signals are emitted, so init should be called after
131 * those signals are connected to MapView.
136 * @brief Getter for scene
138 * @return QGraphicsScene
140 QGraphicsScene* scene();
143 * @brief Sets new zoom level
145 * @return newZoomLevel value that is set to new zoom level
147 void setZoomLevel(const int newZoomLevel);
150 * @brief Return tile path created from tile values.
152 * @param zoomLevel tile's zoom level
153 * @param x tile's x value
154 * @param y tile's y value
155 * @return QString tile path
157 static QString tilePath(int zoomLevel, int x, int y);
162 * @brief Slot to catch user own location data
164 * @param user User info
166 void receiveOwnLocation(User *user);
169 * @brief Set auto centering.
171 * @param enabled true if enabled, false otherwise
173 void setAutoCentering(bool enabled);
176 * @brief Slot for enabling / disabling GPS
178 * GPS location item is disabled or enabled based on GPS state
180 * @param enabled True is GPS is enabled, otherwise false
182 void setGPSEnabled(bool enabled);
185 * @brief Slot for setting current view location
187 * Emits locationChanged signal.
188 * @param sceneCoordinate Scene coordinates for new position
190 void setLocation(QPoint sceneCoordinate);
193 * @brief Helper for setting view location based on latitude and longitude
196 * @param latLonCoordinate Latitude & longitude coordinates for location
198 void setViewLocation(QPointF latLonCoordinate);
201 * @brief Slot for view resizing.
203 * @param size view size
205 void viewResized(const QSize &size);
209 * @brief Calculate grid of tile coordinates from current scene coordinate.
211 * Grid size is calculated from view size and scene's current center coordinate.
213 * @param sceneCoordinate scene's current center coordinate
214 * @return QRect grid of tile coordinates
216 QRect calculateTileGrid(QPoint sceneCoordinate);
219 * @brief Check if auto centering should be disabled.
221 * @param sceneCoordinate scene's center coordinate
222 * @return bool true if auto centering should be disabled
224 bool disableAutoCentering(QPoint sceneCoordinate);
227 * @brief Get new tiles.
229 * Calculates which tiles has to be fetched. Does emit fetchImage for tiles which
230 * aren't already in the scene.
231 * @param sceneCoordinate scene's center coordinate
233 void getTiles(QPoint sceneCoordinate);
236 * @brief Check if auto centering is enabled
238 * @return true if enabled, false otherwise
240 bool isAutoCenteringEnabled();
243 * @brief Check if center tile has changed.
245 * @param sceneCoordinate scene's center coordinate
246 * @return bool true if center tile changed, false otherwise
248 bool isCenterTileChanged(QPoint sceneCoordinate);
251 * @brief Calculate scale at the map center of the map in meters/pixel
253 * @return qreal Scale of the map in meters/pixel
255 qreal sceneResolution();
258 * @brief Calculate maximum value for tile in this zoom level.
260 * @param zoomLevel zoom level
261 * @return int tile's maximum value
263 int tileMaxValue(int zoomLevel);
266 * @brief Updates the current view rect including margins
268 * Calculates tiles rect in scene based on m_viewTilesGrid and
269 * calls MapScene::viewRectUpdated()
271 void updateViewTilesSceneRect();
275 * @brief Slot for GPS position updates
277 * GPS location item is updated and map centered to new location (if automatic
278 * centering is enabled).
280 * @param position New coordinates from GPS
281 * @param accuracy Accuracy of the GPS fix
283 void gpsPositionUpdate(QPointF position, qreal accuracy);
286 * @brief Slot for received map tile images
288 * Does add MapTile objects to MapScene.
289 * @param zoomLevel Zoom level
290 * @param x Tile x index
291 * @param y Tile y index
292 * @param image Received pixmap
294 void mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image);
297 * @brief Slot for actions after view zoom is finished
299 * Does run removeOutOfViewTiles
301 void viewZoomFinished();
304 * @brief Slot for zooming in
309 * @brief Slot for zooming out
313 /*******************************************************************************
315 ******************************************************************************/
318 * @brief Signals error
320 * @param error error code
322 void error(const int error);
325 * @brief Signal for image fetching.
327 * @param zoomLevel Zoom level
328 * @param x Tile x index
329 * @param y Tile y index
331 void fetchImage(int zoomLevel, int x, int y);
334 * @brief Signal when friend list locations are fetched
336 * @param friendsList Friends list data
338 void friendsLocationsReady(QList<User *> &friendsList);
341 * @brief Request view centering to new locaiton
343 * @param sceneCoordinate New scene coordinates
345 void locationChanged(QPoint sceneCoordinate);
348 * @brief Signal is emitted when location item is clicked.
350 * @param userIDs list of friends user IDs in the group
352 void locationItemClicked(const QList<QString> &userIDs);
355 * @brief Signal to notify map scrolling.
357 void mapScrolledManually();
360 * @brief Signal to notify when map is zoomed in to the maxmimum.
362 void maxZoomLevelReached();
365 * @brief Signal to notify when map is zoomed out to the minimum.
367 void minZoomLevelReached();
370 * @brief Signal to pass the scale of the map to map scale
372 void newMapResolution(qreal scale);
375 * @brief Request view changing zoom level
377 * @param newZoomLevel New zoom level
379 void zoomLevelChanged(int newZoomLevel);
381 /*******************************************************************************
383 ******************************************************************************/
385 bool m_autoCenteringEnabled; ///< Auto centering enabled
386 bool m_zoomedIn; ///< Flag for checking if zoomed in when zoom is finished
388 int m_zoomLevel; ///< Current zoom level
390 QPoint m_centerTile; ///< Current center tile
391 QPoint m_lastManualPosition; ///< Last manually set position in scene coordinate
392 QPoint m_sceneCoordinate; ///< Current center coordinate
394 QRect m_viewTilesGrid; ///< Current grid of tiles in view (includes margin)
396 QSize m_viewSize; ///< Current view size
398 FriendItemsHandler *m_friendItemsHandler; ///< Handler for friend and group items
399 GPSLocationItem *m_gpsLocationItem; ///< Item pointing current location from GPS
400 MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
401 MapScene *m_mapScene; ///< Scene for map tiles
402 OwnLocationItem *m_ownLocation; ///< Item to show own location
405 #endif // MAPENGINE_H