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);
63 /*******************************************************************************
64 * MEMBER FUNCTIONS AND SLOTS
65 ******************************************************************************/
68 * @brief Coordinates of the current center point
70 * @return Current coordinates (latitude & longitude)
72 QPointF centerGeoCoordinate();
75 * @brief Convert latitude and longitude to scene coordinates.
77 * @param latLonCoordinate latitude and longitude values
78 * @return scene coordinate
80 static QPoint convertLatLonToSceneCoordinate(QPointF latLonCoordinate);
83 * @brief converts scene coordinates to latitude and longitude
85 * @param zoomLevel current zoom level
86 * @param sceneCoordinate that will be converted
88 QPointF convertSceneCoordinateToLatLon(int zoomLevel, QPoint sceneCoordinate);
91 * @brief Convert MapScene coordinate to tile x & y numbers.
93 * @param zoomLevel ZoomLevel
94 * @param sceneCoordinate MapScene coordinate
95 * @return QPoint tile x & y numbers
97 static QPoint convertSceneCoordinateToTileNumber(int zoomLevel, QPoint sceneCoordinate);
100 * @brief Convert tile x & y numbers to MapScene coordinates
102 * @param zoomLevel Zoom level
103 * @param tileNumber x & y numbers of the tile
104 * @return QPoint MapScene coordinate
106 static QPoint convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber);
109 * @brief MapEngine initializer
111 * Set initial location and zoom level for the engine. locationChanged and
112 * zoomLevelChanged signals are emitted, so init should be called after
113 * those signals are connected to MapView.
118 * @brief Getter for scene
120 * @return QGraphicsScene
122 QGraphicsScene* scene();
125 * @brief Return tile path created from tile values.
127 * @param zoomLevel tile's zoom level
128 * @param x tile's x value
129 * @param y tile's y value
130 * @return QString tile path
132 static QString tilePath(int zoomLevel, int x, int y);
136 * @brief Slot to catch user own location data
138 * @param user User info
140 void receiveOwnLocation(User *user);
143 * @brief Set auto centering.
145 * @param enabled true if enabled, false otherwise
147 void setAutoCentering(bool enabled);
150 * @brief Slot for enabling / disabling GPS
152 * GPS location item is disabled or enabled based on GPS state
154 * @param enabled True is GPS is enabled, otherwise false
156 void setGPSEnabled(bool enabled);
159 * @brief Slot for setting current view location
161 * Emits locationChanged signal.
162 * @param sceneCoordinate Scene coordinates for new position
164 void setLocation(QPoint sceneCoordinate);
167 * @brief Helper for setting view location based on latitude and longitude
170 * @param latLonCoordinate Latitude & longitude coordinates for location
172 void setViewLocation(QPointF latLonCoordinate);
175 * @brief Slot for view resizing.
177 * @param size view size
179 void viewResized(const QSize &size);
183 * @brief Calculate grid of tile coordinates from current scene coordinate.
185 * Grid size is calculated from view size and scene's current center coordinate.
187 * @param sceneCoordinate scene's current center coordinate
188 * @return QRect grid of tile coordinates
190 QRect calculateTileGrid(QPoint sceneCoordinate);
193 * @brief Check if auto centering should be disabled.
195 * @param sceneCoordinate scene's center coordinate
196 * @return bool true if auto centering should be disabled
198 bool disableAutoCentering(QPoint sceneCoordinate);
201 * @brief Get new tiles.
203 * Calculates which tiles has to be fetched. Does emit fetchImage for tiles which
204 * aren't already in the scene.
205 * @param sceneCoordinate scene's center coordinate
207 void getTiles(QPoint sceneCoordinate);
210 * @brief Check if auto centering is enabled
212 * @return true if enabled, false otherwise
214 bool isAutoCenteringEnabled();
217 * @brief Check if center tile has changed.
219 * @param sceneCoordinate scene's center coordinate
220 * @return bool true if center tile changed, false otherwise
222 bool isCenterTileChanged(QPoint sceneCoordinate);
225 * @brief Calculate maximum value for tile in this zoom level.
227 * @param zoomLevel zoom level
228 * @return int tile's maximum value
230 int tileMaxValue(int zoomLevel);
233 * @brief Updates the current view rect including margins
235 * Calculates tiles rect in scene based on m_viewTilesGrid and
236 * calls MapScene::viewRectUpdated()
238 void updateViewTilesSceneRect();
242 * @brief Slot for GPS position updates
244 * GPS location item is updated and map centered to new location (if automatic
245 * centering is enabled).
247 * @param position New coordinates from GPS
248 * @param accuracy Accuracy of the GPS fix
250 void gpsPositionUpdate(QPointF position, qreal accuracy);
253 * @brief Slot for received map tile images
255 * Does add MapTile objects to MapScene.
256 * @param zoomLevel Zoom level
257 * @param x Tile x index
258 * @param y Tile y index
259 * @param image Received pixmap
261 void mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image);
264 * @brief Slot for actions after view zoom is finished
266 * Does run removeOutOfViewTiles
268 void viewZoomFinished();
271 * @brief Slot for zooming in
276 * @brief Slot for zooming out
280 /*******************************************************************************
282 ******************************************************************************/
285 * @brief Signal for image fetching.
287 * @param zoomLevel Zoom level
288 * @param x Tile x index
289 * @param y Tile y index
291 void fetchImage(int zoomLevel, int x, int y);
294 * @brief Signal when friend list locations are fetched
296 * @param friendsList Friends list data
298 void friendsLocationsReady(QList<User *> &friendsList);
301 * @brief Request view centering to new locaiton
303 * @param sceneCoordinate New scene coordinates
305 void locationChanged(QPoint sceneCoordinate);
308 * @brief Signal is emitted when location item is clicked.
310 * @param userIDs list of friends user IDs in the group
312 void locationItemClicked(const QList<QString> &userIDs);
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 Request view changing zoom level
332 * @param newZoomLevel New zoom level
334 void zoomLevelChanged(int newZoomLevel);
336 /*******************************************************************************
338 ******************************************************************************/
340 bool m_autoCenteringEnabled; ///< Auto centering enabled
341 bool m_zoomedIn; ///< Flag for checking if zoomed in when zoom is finished
343 int m_zoomLevel; ///< Current zoom level
345 QPoint m_centerTile; ///< Current center tile
346 QPoint m_lastManualPosition; ///< Last manually set position in scene coordinate
347 QPoint m_sceneCoordinate; ///< Current center coordinate
349 QRect m_viewTilesGrid; ///< Current grid of tiles in view (includes margin)
351 QSize m_viewSize; ///< Current view size
353 FriendItemsHandler *m_friendItemsHandler; ///< Handler for friend and group items
354 GPSLocationItem *m_gpsLocationItem; ///< Item pointing current location from GPS
355 MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
356 MapScene *m_mapScene; ///< Scene for map tiles
357 OwnLocationItem *m_ownLocation; ///< Item to show own location
360 #endif // MAPENGINE_H