Merge branch 'crosshair2'
authorVille Tiensuu <ville.tiensuu@ixonos.com>
Tue, 18 May 2010 05:06:43 +0000 (08:06 +0300)
committerVille Tiensuu <ville.tiensuu@ixonos.com>
Tue, 18 May 2010 05:06:43 +0000 (08:06 +0300)
Conflicts:
images.qrc
src/engine/engine.h
src/map/mapengine.cpp
src/map/mapview.cpp
src/map/mapview.h
src/ui/mainwindow.cpp
src/ui/mapviewscreen.cpp
src/ui/mapviewscreen.h

1  2 
images.qrc
src/engine/engine.h
src/map/mapengine.cpp
src/map/mapengine.h
src/map/mapview.cpp
src/map/mapview.h
src/ui/mainwindow.cpp
src/ui/mapviewscreen.cpp
src/ui/mapviewscreen.h

diff --cc images.qrc
@@@ -25,8 -26,6 +25,9 @@@
          <file>res/images/list_item_bottom.png</file>
          <file>res/images/list_item_middle.png</file>
          <file>res/images/list_item_top.png</file>
 +        <file>res/images/gps_pos_accurate.png</file>
 +        <file>res/images/gps_pos_coarse.png</file>
 +        <file>res/images/friend_group.png</file>
+               <file>res/images/sight.png</file>
      </qresource>
  </RCC>
@@@ -133,13 -139,6 +139,7 @@@ public slots
   * SIGNALS
   ******************************************************************************/
  signals:
-     /**
-     * @brief Signals when new user data is ready
-     *
-     * @param user Instance of User
-     */
-     void userLocationReady(User *user);
 +
      /**
      * @brief Signals when new friends data is ready
      *
@@@ -374,7 -361,36 +374,42 @@@ void MapEngine::setAutoCentering(bool e
      m_autoCenteringEnabled = enabled;
  }
  
++
 +void MapEngine::gpsEnabled(bool enabled)
 +{
 +    m_gpsLocationItem->setEnabled(enabled);
 +}
++
+ QPointF MapEngine::convertSceneCoordinateToLatLon(int zoomLevel, QPoint sceneCoordinate)
+ {   
+     qDebug() << __PRETTY_FUNCTION__;
+     double tileFactor = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
+     double xFactor = (sceneCoordinate.x() / (TILE_SIZE_X*tileFactor));
+     double yFactor = (sceneCoordinate.y() / (TILE_SIZE_Y*tileFactor));
+     tileFactor = 1 << zoomLevel;
+     double longitude = xFactor / tileFactor * 360.0 - 180;
+     double n = M_PI - 2.0 * M_PI * yFactor / tileFactor;
+     double latitude = 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n)));
+     return QPointF(longitude, latitude);
+ }
+ void MapEngine::ownLocation()
+ {
+      qDebug() << __PRETTY_FUNCTION__;    
+     emit requestToGetViewPortContents();
+     QPointF ownLatitudeLongitudeLocation =
+             convertSceneCoordinateToLatLon(m_zoomLevel, m_viewArea.center());    
+     emit ownLocation(ownLatitudeLongitudeLocation);
+ }
+ void MapEngine::receiveViewSceneRect(QRect viewSceneRect)
+ {
+     qDebug() << __PRETTY_FUNCTION__;
+     m_viewArea = viewSceneRect;
+ }
@@@ -115,8 -121,23 +115,16 @@@ public
      */
      static QString tilePath(int zoomLevel, int x, int y);
  
+     /**
+     * @brief converts scene coordinates to latitude and longitude
+     *
+     * @param current zoom level
+     * @param sceneCoordinate that will be converted
+     */
+     QPointF convertSceneCoordinateToLatLon(int zoomLevel, QPoint sceneCoordinate);
  public slots:
      /**
 -    * @brief Slot for immovable scene items position correction
 -    *
 -    * @param viewTopLeft Scene coordinate of the viewport top left corner
 -    */
 -    void alignImmovableItems(QPoint viewTopLeft);
 -
 -    /**
      * @brief Slot for setting current view location
      *
      * Emits locationChanged signal.
@@@ -293,19 -300,21 +314,31 @@@ signals
      /**
      * @brief Signal to notify map scrolling.
      */
 -    void mapScrolled();
 +    void mapScrolledManually();
 +
 +    /**
 +    * @brief Signal to notify when map is zoomed in to the maxmimum.
 +    */
 +    void maxZoomLevelReached();
 +
 +    /**
 +    * @brief Signal to notify when map is zoomed out to the minimum.
 +    */
 +    void minZoomLevelReached();
  
      /**
+     * @brief Signal request mapView to update view port contents
+     */
+     void requestToGetViewPortContents();
+     /**
+     * @brief Signal sends location of crosshair
+     *
+     * @param ownLocation location of crosshair (Latitude, Longitude)
+     */
+     void ownLocation(const QPointF ownLocation);
+     /**
      * @brief Signal for zoom level change
      *
      * @param newZoomLevel New zoom level
@@@ -105,4 -106,32 +105,24 @@@ void MapView::resizeEvent(QResizeEvent 
  
      emit viewResized(event->size());
      emit viewResizedNewSize(viewport()->width(), viewport()->height());
 -    //emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
  }
 -void MapView::showEvent(QShowEvent *event)
 -{
 -    qDebug() << __PRETTY_FUNCTION__;
 -
 -    QGraphicsView::showEvent(event);
 -    //emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
 -}
+ void MapView::updateViewPortContent()
+ {
+     qDebug() << __PRETTY_FUNCTION__;
+     QPoint topLeft = mapToScene(viewport()->contentsRect().topLeft()).toPoint();
+     QPoint bottomRight = mapToScene(viewport()->contentsRect().bottomRight()).toPoint();
+     //emit viewContentChanged(QRect(topLeft, bottomRight));
+ }
+ QRect MapView::viewportContent()
+ {
+     QPoint topLeft = mapToScene(viewport()->contentsRect().topLeft()).toPoint();
+     QPoint bottomRight = mapToScene(viewport()->contentsRect().bottomRight()).toPoint();   
+     emit updateViewContent(QRect(topLeft, bottomRight));
+     return QRect(topLeft, bottomRight);
+ }
Simple merge
Simple merge
@@@ -85,16 -84,24 +89,31 @@@ MapViewScreen::MapViewScreen(QWidget *p
      connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
              m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
  
 -    connect(m_mapEngine, SIGNAL(mapScrolled()),
 -            this, SLOT(locationChanged()));
 +    connect(m_mapEngine, SIGNAL(mapScrolledManually()),
 +            this, SIGNAL(mapLocationChanged()));
 +
 +    connect(this, SIGNAL(positionReceived(QPointF,qreal)),
 +            m_mapEngine, SLOT(gpsPositionUpdate(QPointF,qreal)));
 +    connect(this, SIGNAL(enableAutoCentering(bool)),
 +            m_mapEngine, SLOT(setAutoCentering(bool)));
 +    connect(this, SIGNAL(gpsEnabled(bool)),
 +            m_mapEngine, SLOT(gpsEnabled(bool)));
  
+     connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
+             this, SLOT(drawOwnLocationCrosshair(int, int)));
+     connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
+              this, SLOT(setViewPortSize(int, int)));
+     connect(m_mapEngine, SIGNAL(requestToGetViewPortContents()),
+             mapView, SLOT(viewportContent()));
+     connect(mapView, SIGNAL(updateViewContent(QRect)),
+             m_mapEngine, SLOT(receiveViewSceneRect(QRect)));
+     connect(this, SIGNAL(requestOwnLocation()),
+             m_mapEngine, SLOT(ownLocation()));
+     connect(m_mapEngine, SIGNAL(ownLocation(QPointF)),
+             this, SIGNAL(ownLocation(QPointF)));
      QHBoxLayout *mapViewLayout = new QHBoxLayout;
  
      m_osmLicense = new QLabel(this);
@@@ -129,3 -136,64 +148,41 @@@ void MapViewScreen::drawOsmLicense(int 
                          height - m_osmLicense->fontMetrics().height());
  }
  
 -void MapViewScreen::locationChanged()
 -{
 -    qDebug() << __PRETTY_FUNCTION__;
 -
 -    if (m_autoCenteringEnabled)
 -        emit mapLocationChanged();
 -}
 -
 -void MapViewScreen::positionReceived(QPointF position, qreal accuracy)
 -{
 -    qDebug() << __PRETTY_FUNCTION__;
 -
 -    if (m_autoCenteringEnabled)
 -        m_mapEngine->setViewLocation(position);
 -}
 -
 -void MapViewScreen::enableAutoCentering(bool enabled)
 -{
 -    qDebug() << __PRETTY_FUNCTION__;
 -
 -    m_autoCenteringEnabled = enabled;
 -    m_mapEngine->setAutoCentering(enabled);
 -}
+ void MapViewScreen::drawOwnLocationCrosshair(int width, int height)
+ {
+     qDebug() << __PRETTY_FUNCTION__;
+     if (m_drawOwnLocationCrosshair) {
+         m_ownLocationCrosshair->move(width/2 - m_ownLocationCrosshair->pixmap()->width()/2,
+                             height/2 - m_ownLocationCrosshair->pixmap()->height()/2);
+     }
+ }
+ void MapViewScreen::setOwnLocationCrosshairVisibility(bool visibility)
+ {   
+     if (visibility == false) {
+         if (m_ownLocationCrosshair == 0) {
+             m_ownLocationCrosshair = new QLabel(this);
+             QPixmap crosshairImage(":/res/images/sight.png");
+             m_ownLocationCrosshair->setPixmap(crosshairImage);
+             m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
+         }
+         m_ownLocationCrosshair->show();
+         m_drawOwnLocationCrosshair = true;
+         drawOwnLocationCrosshair(m_viewPortWidth, m_viewPortHeight);
+     }
+     else {
+         m_ownLocationCrosshair->hide();
+         m_drawOwnLocationCrosshair = false;
+     }
+ }
+ void MapViewScreen::setViewPortSize(int width, int height)
+ {
+     m_viewPortWidth = width;
+     m_viewPortHeight = height;
+ }
@@@ -48,8 -50,23 +48,16 @@@ public
  /*******************************************************************************
   * MEMBER FUNCTIONS AND SLOTS
   ******************************************************************************/
+ public slots:    
+     /**
+     * @brief Slot for setting own location crosshair visibility
+     *
+     * @param visibility false <-> show, true <-> hide
+     */
+     void setOwnLocationCrosshairVisibility(bool visibility);
  private slots:
      /**
 -    * @brief Slot for enabling auto centering.
 -    *
 -    * @param enabled true if map should center to GPS position, false otherwise
 -    */
 -    void enableAutoCentering(bool enabled);
 -
 -    /**
      * @brief Slot for drawing the Open Street Map license text
      *
      * @param width Width of the viewport
      */
      void drawOsmLicense(int width, int height);
  
+     /**
+     * @brief Slot for drawing the own location crosshair
+     *
+     * @param width Width of the viewport
+     * @param height Height of the viewport
+     */
+     void drawOwnLocationCrosshair(int width, int height);
 -    /**
 -    * @brief Slot for map location change.
 -    */
 -    void locationChanged();
++//    /**
++//    * @brief Slot for map location change.
++//    */
++//    void locationChanged();
+     /**
+     * @brief Set correnct view port size to datamembers
+     *
+     * @param width Width of the viewport
+     * @param height Height of the viewport
+     */
+     void setViewPortSize(const int width, const int height);
 -    /**
 -    * @brief Slot for GPS position.
 -    *
 -    * @param position latitude and longitude values
 -    * @param accuracy coordinate accuracy in metres
 -    */
 -    void positionReceived(QPointF position, qreal accuracy);
 -
  /*******************************************************************************
   * SIGNALS
   ******************************************************************************/
@@@ -90,14 -122,16 +119,24 @@@ signals
      void mapLocationChanged();
  
      /**
 +    * @brief Slot for GPS position.
 +    *
 +    * @param position latitude and longitude values
 +    * @param accuracy coordinate accuracy in metres
 +    */
 +    void positionReceived(QPointF position, qreal accuracy);
 +
 +    /**
+     * @brief Signal from MapEngine to SituareEngine is travelling here
+     */
+     void ownLocation(QPointF ownLatitudeLongitudeLocation);
+     /**
+     * @brief Signal from SituareEngine to MapEngine is travelling here
+     */
+     void requestOwnLocation();
+     /**
      * @brief Signal when user location is fetched
      *
      * @param user User data
   * DATA MEMBERS
   ******************************************************************************/
  private:
-     FriendListPanel *m_friendsListPanel; ///< Instance of friends list panel
-     MapEngine *m_mapEngine;              ///< MapEngine
-     QLabel *m_osmLicense;                ///< Label for Open Street Map license
-     UserInfoPanel *m_userPanel;          ///< Instance of the user information panel
-     ZoomButtonPanel *m_zoomButtonPanel;  ///< Instance of zoom button panel
 -    MapEngine *m_mapEngine;                 ///< MapEngine
 -    UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
 -    FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
 -    ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
 -    QLabel *m_osmLicense;                   ///< Label for Open Street Map license
 -    bool m_autoCenteringEnabled;            ///< Enable
 -    QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
 -    bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
 -    int m_viewPortWidth;                    ///< Width of view port
 -    int m_viewPortHeight;                   ///< Height of view port
++      bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
++      FriendListPanel *m_friendsListPanel; ///< Instance of friends list panel
++      MapEngine *m_mapEngine;              ///< MapEngine
++      QLabel *m_osmLicense;                ///< Label for Open Street Map license
++      QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair    
++      UserInfoPanel *m_userPanel;          ///< Instance of the user information panel
++      int m_viewPortHeight;   ///< Height of view port
++      int m_viewPortWidth;                    ///< Width of view port
++      ZoomButtonPanel *m_zoomButtonPanel;  ///< Instance of zoom button panel
  };
  
  #endif // MAPVIEWTAB_H