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

12 files changed:
images.qrc
res/images/sight.png [new file with mode: 0755]
src/engine/engine.cpp
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/mainwindow.h
src/ui/mapviewscreen.cpp
src/ui/mapviewscreen.h

index 70a1658..9be0c76 100644 (file)
@@ -28,5 +28,6 @@
         <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>
diff --git a/res/images/sight.png b/res/images/sight.png
new file mode 100755 (executable)
index 0000000..40a1587
Binary files /dev/null and b/res/images/sight.png differ
index a3dd8d9..6cfa817 100644 (file)
@@ -38,7 +38,8 @@ const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";
 SituareEngine::SituareEngine(QMainWindow *parent)
     : QObject(parent),
       m_autoCenteringEnabled(false),
-      m_gpsEnabled(false)
+      m_gpsEnabled(false),
+      m_latestLocation()
 {
     qDebug() << __PRETTY_FUNCTION__;
     m_ui = new MainWindow;
@@ -106,6 +107,11 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     enableGPS(gpsEnabled.toBool());
     enableAutoCentering(autoCenteringEnabled.toBool());
 
+    connect(this, SIGNAL(requestOwnLocation()),
+            m_ui, SIGNAL(requestOwnLocation()));
+    connect(m_ui, SIGNAL(ownLocation(QPointF)),
+            this, SLOT(receiveOwnLocation(QPointF)));
+
      m_facebookAuthenticator->start();
 }
 
@@ -149,14 +155,14 @@ void SituareEngine::requestAddress()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QPointF coordinates;
-
-    if (m_gpsEnabled)
-        coordinates = m_gps->lastPosition();
-    else
-        coordinates = QPointF(0, 0);    //Manual position from map
-
-    m_situareService->reverseGeo(coordinates);
+    if (m_gpsEnabled) {
+        m_latestLocation = m_gps->lastPosition();
+        m_situareService->reverseGeo(m_latestLocation);
+    }
+    else {
+        emit requestOwnLocation();
+        m_situareService->reverseGeo(m_latestLocation);
+    }
 }
 
 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
@@ -165,14 +171,14 @@ void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
 
     m_ui->toggleProgressIndicator(true);
 
-    QPointF coordinates;
-
-    if (m_gpsEnabled)
-        coordinates = m_gps->lastPosition();
-    else
-        coordinates = QPointF(0, 0);    //Manual position from map
-
-    m_situareService->updateLocation(coordinates, status, publish);
+    if (m_gpsEnabled) {
+        m_latestLocation = m_gps->lastPosition();
+        m_situareService->updateLocation(m_latestLocation, status, publish);
+    }
+    else {
+        emit requestOwnLocation();
+        m_situareService->updateLocation(m_latestLocation, status, publish);
+    }
 }
 
 void SituareEngine::updateWasSuccessful()
@@ -204,6 +210,7 @@ void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
 void SituareEngine::enableGPS(bool enabled)
 {
     qDebug() << __PRETTY_FUNCTION__;
+    emit requestOwnLocation();
 
     m_gpsEnabled = enabled;
 
@@ -234,3 +241,9 @@ void SituareEngine::enableAutoCentering(bool enabled)
         m_ui->autoCenteringEnabled(false);
     }
 }
+
+void SituareEngine::receiveOwnLocation(QPointF ownLocation)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+    m_latestLocation = ownLocation;
+}
index 424b51a..3e7df39 100644 (file)
@@ -61,7 +61,6 @@ public:
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
 public slots:
-
     /**
     * @brief Slot to intercept error signal from ImageFetcher and SituareService
     *
@@ -75,6 +74,13 @@ public slots:
     void loginOk();
 
     /**
+    * @brief Slot to receive location of crosshair
+    *
+    * @param ownLocation (Latitude and Longitude)
+    */
+    void receiveOwnLocation(QPointF ownLocation);
+
+    /**
     * @brief Calls reverseGeo from SituareService to translate coordinates to street address
     *
     */
@@ -133,12 +139,6 @@ 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
@@ -147,6 +147,19 @@ signals:
     */
     void friendsLocationsReady(QList<User *> &friendList);
 
+    /**
+    * @brief Signal causes mapengine to send updated location of crosshair.
+    *
+    */
+    void requestOwnLocation();
+
+    /**
+    * @brief Signals when new user data is ready
+    *
+    * @param user Instance of User
+    */
+    void userLocationReady(User *user);
+
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
@@ -157,6 +170,7 @@ private:
     GPSPositionInterface *m_gps;   ///< Instance of the gps position
     MainWindow *m_ui; ///< Instance of the MainWindow UI
     SituareService *m_situareService; ///< Instance of the situare server communication service
+    QPointF m_latestLocation; ///< Placeholder for user's latest asked location
 };
 
 #endif // ENGINE_H
index 5e6998b..098874b 100644 (file)
@@ -374,7 +374,42 @@ void MapEngine::setAutoCentering(bool enabled)
     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;
+}
index d5e5535..5067057 100644 (file)
@@ -115,6 +115,14 @@ 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 setting current view location
@@ -140,11 +148,24 @@ public slots:
     void viewResized(const QSize &size);
 
     /**
+    * @brief Returns own location crosshair's latitude and longitude coordinates
+    *
+    */
+    void ownLocation();
+
+    /**
     * @brief Slot to catch user own location data
     *
     * @param user User info
     */
-    void receiveOwnLocation(User *user);
+    void receiveOwnLocation(User *user);    
+
+    /**
+    * @brief Slot to receive visible area of map scene
+    *
+    * @param visible area of map scene
+    */
+    void receiveViewSceneRect(QRect viewSceneRect);
 
 private:
     /**
@@ -306,6 +327,18 @@ signals:
     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
@@ -329,6 +362,7 @@ private:
     QSize m_viewSize; ///< Current view size
     bool m_zoomedIn; ///< Flag for checking if zoomed in when zoom is finished
     int m_zoomLevel; ///< Current zoom level
+    QRect m_viewArea; ///< Visible area of map scene
 };
 
 #endif // MAPENGINE_H
index 2843d71..745f719 100644 (file)
@@ -106,3 +106,23 @@ void MapView::resizeEvent(QResizeEvent *event)
     emit viewResized(event->size());
     emit viewResizedNewSize(viewport()->width(), viewport()->height());
 }
+
+
+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);
+}
+
index 88f05ea..8f86892 100644 (file)
@@ -99,6 +99,17 @@ public slots:
     */
     void setZoomLevel(int zoomLevel);
 
+    /**
+    * @brief updates view ports content
+    */
+    void updateViewPortContent();
+
+    /**
+    * @brief Slot for catching request to get view port contents.
+    * implementation of this slot sends signal that includes visble area of view port.
+    */
+    QRect viewportContent();
+
 private:
     /**
     * @brief Set new view scale
@@ -140,6 +151,21 @@ signals:
     void viewZoomFinished();
 
     /**
+    * @brief Signal for updating view content
+    *
+    * Signal is emitted when view content needs an update.
+    * @param viewTopLeft Scene coordinate of the viewport top left corner
+    */
+    void viewContentChanged(QPoint viewTopLeft);
+
+    /**
+    * @brief Signal that sends visible area of map scene
+    *
+    * @param viewArea visible area of map scene
+    */
+    void updateViewContent(QRect viewArea);
+
+    /**
     * @brief Signal for drawing OSM license
     *
     * Signal is emitted when view is resized.
index 14d5cc4..8f45110 100644 (file)
@@ -51,7 +51,7 @@ MainWindow::MainWindow(QWidget *parent)
     setCentralWidget(m_mapViewScreen);
     createMenus();
     setWindowTitle(tr("Situare"));
-       show();
+    show();
 
     m_locationDialog = new UpdateLocationDialog(this);
 
@@ -77,6 +77,11 @@ MainWindow::MainWindow(QWidget *parent)
     connect(this, SIGNAL(zoomOutKeyPressed()),
             m_mapViewScreen, SIGNAL(zoomOutKeyPressed()));
 
+    connect(this, SIGNAL(requestOwnLocation()),
+            m_mapViewScreen, SIGNAL(requestOwnLocation()));
+    connect(m_mapViewScreen, SIGNAL(ownLocation(QPointF)),
+            this, SIGNAL(ownLocation(QPointF)));
+
     this->toggleProgressIndicator(true);
 
     grabZoomKeys(true);
@@ -115,6 +120,8 @@ void MainWindow::createMenus()
     m_gpsToggleAct->setChecked(true);
     connect(m_gpsToggleAct, SIGNAL(toggled(bool)),
         this, SLOT(gpsToggled(bool)));
+    connect(m_gpsToggleAct, SIGNAL(toggled(bool)),
+            m_mapViewScreen, SLOT(setOwnLocationCrosshairVisibility(bool)));
     m_autoCenteringAct = new QAction(tr("Auto centering"), this);
     m_autoCenteringAct->setCheckable(true);
     m_autoCenteringAct->setChecked(true);
@@ -126,7 +133,7 @@ void MainWindow::createMenus()
     m_viewMenu = menuBar()->addMenu(tr("Main"));
 
     m_viewMenu->addAction(m_toSettingsAct);
-       m_viewMenu->addAction(m_gpsToggleAct);
+    m_viewMenu->addAction(m_gpsToggleAct);
     m_viewMenu->addAction(m_autoCenteringAct);
     m_viewMenu->setObjectName(tr("Menu"));
 }
index d444322..c7be87f 100644 (file)
@@ -236,6 +236,11 @@ signals:
     void friendsLocationsReady(QList<User *> &friendsList);
 
     /**
+    * @brief Signal from MapEngine to SituareEngine is travelling here
+    */
+    void ownLocation(QPointF ownLatitudeLongitudeLocation);
+
+    /**
     * @brief Signal for gps position.
     *
     * @param position longitude and latitude values
@@ -250,6 +255,11 @@ signals:
     void refreshUserData();
 
     /**
+    * @brief Signal from SituareEngine to MapEngine is travelling here
+    */
+    void requestOwnLocation();
+
+    /**
     * @brief Signal for requesting reverseGeo from SituareEngine
     *
     */
@@ -285,13 +295,13 @@ signals:
     void userLocationReady(User *user);
 
     /**
-      * @brief Signal for HW increase button
-      */
+    * @brief Signal for HW increase button
+    */
     void zoomInKeyPressed();
 
     /**
-      * @brief Signal for HW decrease button
-      */
+    * @brief Signal for HW decrease button
+    */
     void zoomOutKeyPressed();
 
 /*******************************************************************************
index 99dc095..2a0cc16 100644 (file)
@@ -37,7 +37,9 @@ MapViewScreen::MapViewScreen(QWidget *parent)
     PanelSideBar *friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
 
     m_zoomButtonPanel = new ZoomButtonPanel(this, ZOOM_BUTTON_PANEL_POSITION_X,
-                                            ZOOM_BUTTON_PANEL_POSITION_Y);
+                                            ZOOM_BUTTON_PANEL_POSITION_Y);   
+
+    m_ownLocationCrosshair = 0;
 
     connect(mapView, SIGNAL(viewScrolled(QPoint)),
             m_mapEngine, SLOT(setLocation(QPoint)));
@@ -47,6 +49,8 @@ MapViewScreen::MapViewScreen(QWidget *parent)
             mapView, SLOT(setZoomLevel(int)));
     connect(mapView, SIGNAL(viewResized(QSize)),
             m_mapEngine, SLOT(viewResized(QSize)));
+    connect(mapView, SIGNAL(updateViewContent(QRect)),
+            m_mapEngine, SLOT(receiveViewSceneRect(QRect)));
     connect(mapView, SIGNAL(viewZoomFinished()),
             m_mapEngine, SLOT(viewZoomFinished()));
 
@@ -95,6 +99,21 @@ MapViewScreen::MapViewScreen(QWidget *parent)
     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 +148,41 @@ void MapViewScreen::drawOsmLicense(int width, int height)
                         height - m_osmLicense->fontMetrics().height());
 }
 
+
+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;
+}
index c9e2433..bde9443 100644 (file)
@@ -48,6 +48,14 @@ 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 drawing the Open Street Map license text
@@ -57,6 +65,27 @@ private slots:
     */
     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 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);
+
 /*******************************************************************************
  * SIGNALS
  ******************************************************************************/
@@ -98,6 +127,16 @@ signals:
     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
@@ -118,11 +157,15 @@ signals:
  * 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
+       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