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 #ifndef MAPENGINE_H
00026 #define MAPENGINE_H
00027
00028 #include <QtCore>
00029
00030 class QGraphicsScene;
00031
00032 class FriendItemsHandler;
00033 class GPSLocationItem;
00034 class MapFetcher;
00035 class MapScene;
00036 class MapTile;
00037 class OwnLocationItem;
00038 class User;
00039
00051 class MapEngine : public QObject
00052 {
00053 Q_OBJECT
00054
00055 public:
00061 MapEngine(QObject *parent = 0);
00062
00067 ~MapEngine();
00068
00069
00070
00071
00072 public:
00078 QPointF centerGeoCoordinate();
00079
00086 static QPoint convertLatLonToSceneCoordinate(QPointF latLonCoordinate);
00087
00094 QPointF convertSceneCoordinateToLatLon(int zoomLevel, QPoint sceneCoordinate);
00095
00103 static QPoint convertSceneCoordinateToTileNumber(int zoomLevel, QPoint sceneCoordinate);
00104
00112 static QPoint convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber);
00113
00124 qreal greatCircleDistance(QPointF firstLocation, QPointF secondLocation);
00125
00133 void init();
00134
00140 QGraphicsScene* scene();
00141
00147 void setZoomLevel(const int newZoomLevel);
00148
00157 static QString tilePath(int zoomLevel, int x, int y);
00158
00159 public slots:
00160
00166 void receiveOwnLocation(User *user);
00167
00173 void setAutoCentering(bool enabled);
00174
00182 void setGPSEnabled(bool enabled);
00183
00190 void setLocation(QPoint sceneCoordinate);
00191
00198 void setViewLocation(QPointF latLonCoordinate);
00199
00205 void viewResized(const QSize &size);
00206
00207 private:
00216 QRect calculateTileGrid(QPoint sceneCoordinate);
00217
00224 bool disableAutoCentering(QPoint sceneCoordinate);
00225
00233 void getTiles(QPoint sceneCoordinate);
00234
00240 bool isAutoCenteringEnabled();
00241
00248 bool isCenterTileChanged(QPoint sceneCoordinate);
00249
00255 qreal sceneResolution();
00256
00263 int tileMaxValue(int zoomLevel);
00264
00271 void updateViewTilesSceneRect();
00272
00273 private slots:
00283 void gpsPositionUpdate(QPointF position, qreal accuracy);
00284
00294 void mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image);
00295
00301 void viewZoomFinished();
00302
00306 void zoomIn();
00307
00311 void zoomOut();
00312
00313
00314
00315
00316 signals:
00322 void error(const QString &error);
00323
00331 void fetchImage(int zoomLevel, int x, int y);
00332
00338 void friendsLocationsReady(QList<User *> &friendsList);
00339
00345 void locationChanged(QPoint sceneCoordinate);
00346
00352 void locationItemClicked(const QList<QString> &userIDs);
00353
00357 void mapScrolledManually();
00358
00362 void maxZoomLevelReached();
00363
00367 void minZoomLevelReached();
00368
00372 void newMapResolution(qreal scale);
00373
00379 void zoomLevelChanged(int newZoomLevel);
00380
00381
00382
00383
00384 private:
00385 bool m_autoCenteringEnabled;
00386 bool m_zoomedIn;
00387
00388 int m_zoomLevel;
00389
00390 QPoint m_centerTile;
00391 QPoint m_lastManualPosition;
00392 QPoint m_sceneCoordinate;
00393
00394 QRect m_viewTilesGrid;
00395
00396 QSize m_viewSize;
00397
00398 FriendItemsHandler *m_friendItemsHandler;
00399 GPSLocationItem *m_gpsLocationItem;
00400 MapFetcher *m_mapFetcher;
00401 MapScene *m_mapScene;
00402 OwnLocationItem *m_ownLocation;
00403 };
00404
00405 #endif // MAPENGINE_H