00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef MAPENGINE_H
00027 #define MAPENGINE_H
00028
00029 #include <QtCore>
00030
00031 #include "routing/route.h"
00032 #include "coordinates/geocoordinate.h"
00033 #include "coordinates/scenecoordinate.h"
00034
00035 class QGraphicsScene;
00036
00037 class FriendItemsHandler;
00038 class GPSLocationItem;
00039 class MapFetcher;
00040 class MapRouteItem;
00041 class MapScene;
00042 class MapScroller;
00043 class MapTile;
00044 class OwnLocationItem;
00045 class User;
00046
00060 class MapEngine : public QObject
00061 {
00062 Q_OBJECT
00063
00064 public:
00070 MapEngine(QObject *parent = 0);
00071
00076 ~MapEngine();
00077
00078
00079
00080
00081 public:
00087 GeoCoordinate centerGeoCoordinate();
00088
00096 static QPoint convertSceneCoordinateToTileNumber(int zoomLevel, SceneCoordinate coordinate);
00097
00105 void init();
00106
00118 static int normalize(int value, int min, int max);
00119
00125 QGraphicsScene* scene();
00126
00132 void setZoomLevel(const int newZoomLevel);
00133
00134 public slots:
00140 void centerToCoordinates(GeoCoordinate coordinate);
00141
00147 void receiveOwnLocation(User *user);
00148
00154 void setAutoCentering(bool enabled);
00155
00163 void setGPSEnabled(bool enabled);
00164
00170 void viewResized(const QSize &size);
00171
00172 private:
00181 QRect calculateTileGrid(SceneCoordinate coordinate);
00182
00192 void centerAndZoomTo(QRect rect, bool useMargins = true);
00193
00199 QRectF currentViewSceneRect() const;
00200
00206 void disableAutoCenteringIfRequired(SceneCoordinate coordinate);
00207
00215 void getTiles(SceneCoordinate coordinate);
00216
00222 bool isAutoCenteringEnabled();
00223
00230 bool isCenterTileChanged(SceneCoordinate coordinate);
00231
00237 void setTilesGridSize(const QSize &viewSize);
00238
00244 void updateDirectionIndicator();
00245
00252 void updateViewTilesSceneRect();
00253
00259 qreal viewResolution();
00260
00266 void zoomed();
00267
00268 private slots:
00272 void clearRoute();
00273
00279 void friendsPositionsUpdated();
00280
00290 void gpsPositionUpdate(GeoCoordinate position, qreal accuracy);
00291
00305 void mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image);
00306
00315 void scrollerStateChanged(QAbstractAnimation::State newState);
00316
00322 void scrollToPosition(SceneCoordinate coordinate);
00323
00330 void setCenterPosition(SceneCoordinate coordinate);
00331
00337 void setRoute(Route &route);
00338
00346 void showMapArea(const GeoCoordinate &swBound, const GeoCoordinate &neBound);
00347
00353 void viewZoomFinished();
00354
00358 void zoomIn();
00359
00363 void zoomOut();
00364
00365
00366
00367
00368 signals:
00377 void directionIndicatorValuesUpdate(qreal direction, qreal distance, bool draw);
00378
00385 void error(const int context, const int error);
00386
00394 void fetchImage(int zoomLevel, int x, int y);
00395
00401 void friendImageReady(User *user);
00402
00408 void friendsLocationsReady(QList<User *> &friendsList);
00409
00415 void locationChanged(SceneCoordinate coordinate);
00416
00422 void locationItemClicked(const QList<QString> &userIDs);
00423
00427 void mapScrolledManually();
00428
00432 void maxZoomLevelReached();
00433
00437 void minZoomLevelReached();
00438
00442 void newMapResolution(qreal scale);
00443
00449 void zoomLevelChanged(int newZoomLevel);
00450
00451
00452
00453
00454 private:
00455 bool m_autoCenteringEnabled;
00456 bool m_scrollStartedByGps;
00457 bool m_smoothScrollRunning;
00458 bool m_zoomedIn;
00459
00460 int m_zoomLevel;
00461
00462 QPoint m_centerTile;
00463 SceneCoordinate m_lastAutomaticPosition;
00464 SceneCoordinate m_sceneCoordinate;
00465
00466 QRect m_viewTilesGrid;
00467
00468 QSize m_tilesGridSize;
00469 QSize m_viewSize;
00470
00471 FriendItemsHandler *m_friendItemsHandler;
00472 GeoCoordinate m_gpsPosition;
00473 GPSLocationItem *m_gpsLocationItem;
00474 MapFetcher *m_mapFetcher;
00475 MapRouteItem *m_mapRouteItem;
00476 MapScene *m_mapScene;
00477 MapScroller *m_scroller;
00478 OwnLocationItem *m_ownLocation;
00479 };
00480
00481 #endif // MAPENGINE_H