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 MapEngine initializer
117 * Set initial location and zoom level for the engine. locationChanged and
118 * zoomLevelChanged signals are emitted, so init should be called after
119 * those signals are connected to MapView.
124 * @brief Getter for scene
126 * @return QGraphicsScene
128 QGraphicsScene* scene();
131 * @brief Sets new zoom level
133 * @return newZoomLevel value that is set to new zoom level
135 void setZoomLevel(const int newZoomLevel);
138 * @brief Return tile path created from tile values.
140 * @param zoomLevel tile's zoom level
141 * @param x tile's x value
142 * @param y tile's y value
143 * @return QString tile path
145 static QString tilePath(int zoomLevel, int x, int y);
149 * @brief Slot to catch user own location data
151 * @param user User info
153 void receiveOwnLocation(User *user);
156 * @brief Set auto centering.
158 * @param enabled true if enabled, false otherwise
160 void setAutoCentering(bool enabled);
163 * @brief Slot for enabling / disabling GPS
165 * GPS location item is disabled or enabled based on GPS state
167 * @param enabled True is GPS is enabled, otherwise false
169 void setGPSEnabled(bool enabled);
172 * @brief Slot for setting current view location
174 * Emits locationChanged signal.
175 * @param sceneCoordinate Scene coordinates for new position
177 void setLocation(QPoint sceneCoordinate);
180 * @brief Helper for setting view location based on latitude and longitude
183 * @param latLonCoordinate Latitude & longitude coordinates for location
185 void setViewLocation(QPointF latLonCoordinate);
188 * @brief Slot for view resizing.
190 * @param size view size
192 void viewResized(const QSize &size);
196 * @brief Calculate grid of tile coordinates from current scene coordinate.
198 * Grid size is calculated from view size and scene's current center coordinate.
200 * @param sceneCoordinate scene's current center coordinate
201 * @return QRect grid of tile coordinates
203 QRect calculateTileGrid(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 Get new tiles.
216 * Calculates which tiles has to be fetched. Does emit fetchImage for tiles which
217 * aren't already in the scene.
218 * @param sceneCoordinate scene's center coordinate
220 void getTiles(QPoint sceneCoordinate);
223 * @brief Check if auto centering is enabled
225 * @return true if enabled, false otherwise
227 bool isAutoCenteringEnabled();
230 * @brief Check if center tile has changed.
232 * @param sceneCoordinate scene's center coordinate
233 * @return bool true if center tile changed, false otherwise
235 bool isCenterTileChanged(QPoint sceneCoordinate);
238 * @brief Calculate maximum value for tile in this zoom level.
240 * @param zoomLevel zoom level
241 * @return int tile's maximum value
243 int tileMaxValue(int zoomLevel);
246 * @brief Updates the current view rect including margins
248 * Calculates tiles rect in scene based on m_viewTilesGrid and
249 * calls MapScene::viewRectUpdated()
251 void updateViewTilesSceneRect();
255 * @brief Slot for GPS position updates
257 * GPS location item is updated and map centered to new location (if automatic
258 * centering is enabled).
260 * @param position New coordinates from GPS
261 * @param accuracy Accuracy of the GPS fix
263 void gpsPositionUpdate(QPointF position, qreal accuracy);
266 * @brief Slot for received map tile images
268 * Does add MapTile objects to MapScene.
269 * @param zoomLevel Zoom level
270 * @param x Tile x index
271 * @param y Tile y index
272 * @param image Received pixmap
274 void mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image);
277 * @brief Slot for actions after view zoom is finished
279 * Does run removeOutOfViewTiles
281 void viewZoomFinished();
284 * @brief Slot for zooming in
289 * @brief Slot for zooming out
293 /*******************************************************************************
295 ******************************************************************************/
298 * @brief Signals error
300 * @param error error message
302 void error(const QString &error);
305 * @brief Signal for image fetching.
307 * @param zoomLevel Zoom level
308 * @param x Tile x index
309 * @param y Tile y index
311 void fetchImage(int zoomLevel, int x, int y);
314 * @brief Signal when friend list locations are fetched
316 * @param friendsList Friends list data
318 void friendsLocationsReady(QList<User *> &friendsList);
321 * @brief Request view centering to new locaiton
323 * @param sceneCoordinate New scene coordinates
325 void locationChanged(QPoint sceneCoordinate);
328 * @brief Signal is emitted when location item is clicked.
330 * @param userIDs list of friends user IDs in the group
332 void locationItemClicked(const QList<QString> &userIDs);
335 * @brief Signal to notify map scrolling.
337 void mapScrolledManually();
340 * @brief Signal to notify when map is zoomed in to the maxmimum.
342 void maxZoomLevelReached();
345 * @brief Signal to notify when map is zoomed out to the minimum.
347 void minZoomLevelReached();
350 * @brief Request view changing zoom level
352 * @param newZoomLevel New zoom level
354 void zoomLevelChanged(int newZoomLevel);
356 /*******************************************************************************
358 ******************************************************************************/
360 bool m_autoCenteringEnabled; ///< Auto centering enabled
361 bool m_zoomedIn; ///< Flag for checking if zoomed in when zoom is finished
363 int m_zoomLevel; ///< Current zoom level
365 QPoint m_centerTile; ///< Current center tile
366 QPoint m_lastManualPosition; ///< Last manually set position in scene coordinate
367 QPoint m_sceneCoordinate; ///< Current center coordinate
369 QRect m_viewTilesGrid; ///< Current grid of tiles in view (includes margin)
371 QSize m_viewSize; ///< Current view size
373 FriendItemsHandler *m_friendItemsHandler; ///< Handler for friend and group items
374 GPSLocationItem *m_gpsLocationItem; ///< Item pointing current location from GPS
375 MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
376 MapScene *m_mapScene; ///< Scene for map tiles
377 OwnLocationItem *m_ownLocation; ///< Item to show own location
380 #endif // MAPENGINE_H