Merge branch 'crosshair2'
[situare] / src / ui / mapviewscreen.cpp
index 06c7d80..2a0cc16 100644 (file)
 */
 
 #include "mapviewscreen.h"
-#include "../map/mapview.h"
-#include "../map/mapengine.h"
+#include "map/mapview.h"
 #include "panelcommon.h"
 #include "panelsidebar.h"
 
 MapViewScreen::MapViewScreen(QWidget *parent)
-   : QWidget(parent),
-     m_autoCenteringEnabled(false)
+   : QWidget(parent)
 {
     MapView *mapView = new MapView(this);
     m_mapEngine = new MapEngine(this);
@@ -39,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)));
@@ -49,29 +49,35 @@ MapViewScreen::MapViewScreen(QWidget *parent)
             mapView, SLOT(setZoomLevel(int)));
     connect(mapView, SIGNAL(viewResized(QSize)),
             m_mapEngine, SLOT(viewResized(QSize)));
-    connect(mapView, SIGNAL(viewContentChanged(QPoint)),
-            m_mapEngine, SLOT(alignImmovableItems(QPoint)));
+    connect(mapView, SIGNAL(updateViewContent(QRect)),
+            m_mapEngine, SLOT(receiveViewSceneRect(QRect)));
     connect(mapView, SIGNAL(viewZoomFinished()),
             m_mapEngine, SLOT(viewZoomFinished()));
 
     connect(this, SIGNAL(zoomInKeyPressed()),
-            mapEngine, SLOT(zoomIn()));
+            m_mapEngine, SLOT(zoomIn()));
     connect(this, SIGNAL(zoomOutKeyPressed()),
-            mapEngine, SLOT(zoomOut()));
+            m_mapEngine, SLOT(zoomOut()));
 
-    connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
+    connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
             this, SLOT(drawOsmLicense(int, int)));
-    connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
-            m_friendsListPanel, SLOT(reDrawFriendsPanel(int,int)));
-    connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
-            m_userPanel, SLOT(reDrawUserPanel(int,int)));
-    connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
-            friendsListPanelSidebar, SLOT(reDrawSidebar(int,int)));
-
-    connect(m_zoomButtonPanel->m_zoomInBtn, SIGNAL(clicked()),
+    connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
+            m_friendsListPanel, SLOT(reDrawFriendsPanel(int, int)));
+    connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
+            m_userPanel, SLOT(reDrawUserPanel(int, int)));
+    connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
+            friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
+
+    connect(m_zoomButtonPanel->m_zoomInButton, SIGNAL(clicked()),
             m_mapEngine, SLOT(zoomIn()));
-    connect(m_zoomButtonPanel->m_zoomOutBtn, SIGNAL(clicked()),
+    connect(m_zoomButtonPanel->m_zoomOutButton, SIGNAL(clicked()),
             m_mapEngine, SLOT(zoomOut()));
+    connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
+            m_zoomButtonPanel, SLOT(resetButtons()));
+    connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
+            m_zoomButtonPanel, SLOT(disableZoomInButton()));
+    connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
+            m_zoomButtonPanel, SLOT(disableZoomOutButton()));
 
     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
             m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
@@ -83,15 +89,37 @@ MapViewScreen::MapViewScreen(QWidget *parent)
     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);
     m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
     m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
-    m_osmLicense->setText("<font color='black'>"+OSM_LICENSE+"</font>");
+    m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
     m_osmLicense->setFont(QFont("Nokia Sans", 9));
     m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
                          m_osmLicense->fontMetrics().height());
@@ -120,26 +148,41 @@ void MapViewScreen::drawOsmLicense(int width, int height)
                         height - m_osmLicense->fontMetrics().height());
 }
 
-void MapViewScreen::locationChanged()
+
+void MapViewScreen::drawOwnLocationCrosshair(int width, int height)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (m_autoCenteringEnabled)
-        emit mapLocationChanged();
+    if (m_drawOwnLocationCrosshair) {
+        m_ownLocationCrosshair->move(width/2 - m_ownLocationCrosshair->pixmap()->width()/2,
+                            height/2 - m_ownLocationCrosshair->pixmap()->height()/2);
+    }
 }
 
-void MapViewScreen::positionReceived(QPointF position, qreal accuracy)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if (m_autoCenteringEnabled)
-        m_mapEngine->setViewLocation(position);
+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::enableAutoCentering(bool enabled)
+void MapViewScreen::setViewPortSize(int width, int height)
 {
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_autoCenteringEnabled = enabled;
-    m_mapEngine->setAutoCentering(enabled);
+    m_viewPortWidth = width;
+    m_viewPortHeight = height;
 }