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
9 Situare is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 version 2 as published by the Free Software Foundation.
13 Situare is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Situare; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
29 #include "mapcommon.h"
30 #include "mapfetcher.h"
33 #include "mapzoompanel.h"
34 #include "ownlocationitem.h"
35 #include "friendlocationitem.h"
36 #include "user/user.h"
41 * Logic for controlling map functionality. Does also include static methods for
42 * converting coordinates.
43 * @author Sami Rämö - sami.ramo (at) ixonos.com
44 * @author Jussi Laitinen - jussi.laitinen (at) ixonos.com
45 * @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
47 class MapEngine : public QObject
55 * @param parent Parent
57 MapEngine(QObject *parent = 0);
61 /*******************************************************************************
62 * MEMBER FUNCTIONS AND SLOTS
63 ******************************************************************************/
66 * @brief Convert latitude and longitude to scene coordinates.
68 * @param latLonCoordinate latitude and longitude values
69 * @return scene coordinate
71 static QPoint convertLatLonToSceneCoordinate(QPointF latLonCoordinate);
74 * @brief Convert MapScene coordinate to tile x & y numbers.
76 * @param zoomLevel ZoomLevel
77 * @param sceneCoordinate MapScene coordinate
78 * @return QPoint tile x & y numbers
80 static QPoint convertSceneCoordinateToTileNumber(int zoomLevel, QPoint sceneCoordinate);
83 * @brief Convert tile x & y numbers to MapScene coordinates
85 * @param zoomLevel Zoom level
86 * @param tileNumber x & y numbers of the tile
87 * @return QPoint MapScene coordinate
89 static QPoint convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber);
92 * @brief MapEngine initializer
94 * Set initial location and zoom level for the engine. locationChanged and
95 * zoomLevelChanged signals are emitted, so init should be called after
96 * those signals are connected to MapView.
101 * @brief Helper for setting view location based on latitude and longitude
104 * @param latLonCoordinate Latitude & longitude coordinates for location
106 void setViewLocation(QPointF latLonCoordinate);
109 * @brief Getter for scene
111 * @return QGraphicsScene
113 QGraphicsScene* scene();
116 * @brief Return tile path created from tile values.
118 * @param zoomLevel tile's zoom level
119 * @param x tile's x value
120 * @param y tile's y value
121 * @return QString tile path
123 static QString tilePath(int zoomLevel, int x, int y);
127 * @brief Slot for immovable scene items position correction
129 * @param viewTopLeft Scene coordinate of the viewport top left corner
131 void alignImmovableItems(QPoint viewTopLeft);
134 * @brief Slot for setting current view location
136 * Emits locationChanged signal.
137 * @param sceneCoordinate Scene coordinates for new position
139 void setLocation(QPoint sceneCoordinate);
142 * @brief Slot for view resizing.
144 * @param size view size
146 void viewResized(const QSize &size);
149 * @brief Slot to catch user own location data
151 * @param user User info
153 void receiveOwnLocation(User *user);
155 * @brief Slot to catch friends location data
157 * @param friendsList QList item of friend information
159 void receiveFriendLocations(QList<User *> &friendsList);
163 * @brief Calculate grid of tile coordinates from current scene coordinate.
165 * Grid size is calculated from view size and scene's current center coordinate.
167 * @param sceneCoordinate scene's current center coordinate
168 * @return QRect grid of tile coordinates
170 QRect calculateTileGrid(QPoint sceneCoordinate);
173 * @brief Get new tiles.
175 * Calculates which tiles has to be fetched. Does emit fetchImage for tiles which
176 * aren't already in the scene.
177 * @param sceneCoordinate scene's center coordinate
179 void getTiles(QPoint sceneCoordinate);
182 * @brief Check if center tile has changed.
184 * @param sceneCoordinate scene's center coordinate
185 * @return bool true if center tile changed, false otherwise
187 bool isCenterTileChanged(QPoint sceneCoordinate);
190 * @brief Calculate maximum value for tile in this zoom level.
192 * @param zoomLevel zoom level
193 * @return int tile's maximum value
195 int tileMaxValue(int zoomLevel);
198 * @brief Updates the current view rect including margins
200 * Calculates tiles rect in scene based on m_viewTilesGrid and
201 * calls MapScene::viewRectUpdated()
203 void updateViewTilesSceneRect();
207 * @brief Slot for received map tile images
209 * Does add MapTile objects to MapScene.
210 * @param zoomLevel Zoom level
211 * @param x Tile x index
212 * @param y Tile y index
213 * @param image Received pixmap
215 void mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image);
218 * @brief Slot for actions after view zoom is finished
220 * Does run removeOutOfViewTiles
222 void viewZoomFinished();
225 * @brief Slot for zooming in
231 * @brief Slot for zooming out
236 /*******************************************************************************
238 ******************************************************************************/
241 * @brief Signal for image fetching.
243 * @param zoomLevel Zoom level
244 * @param x Tile x index
245 * @param y Tile y index
247 void fetchImage(int zoomLevel, int x, int y);
250 * @brief Signal for view location change
252 * @param sceneCoordinate New scene coordinates
254 void locationChanged(QPoint sceneCoordinate);
257 * @brief Signal for zoom level change
259 * @param newZoomLevel New zoom level
261 void zoomLevelChanged(int newZoomLevel);
263 /*******************************************************************************
265 ******************************************************************************/
267 QPoint m_centerTile; ///< Current center tile
268 MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
269 MapScene *m_mapScene; ///< Scene for map tiles
270 MapZoomPanel *m_mapZoomPanel; ///< Toolbar for zoom buttons
271 OwnLocationItem *m_ownLocation; ///< Item to show own location
272 QPoint m_sceneCoordinate; ///< Current center coordinate
273 QRect m_viewTilesGrid; ///< Current grid of tiles in view (includes margin)
274 QSize m_viewSize; ///< Current view size
275 bool m_zoomedIn; ///< Flag for checking if zoomed in when zoom is finished
276 int m_zoomLevel; ///< Current zoom level
277 QList<FriendLocationItem *> m_friendsLocations; ///< Location of friends
280 #endif // MAPENGINE_H