Merge branch 'crosshair2'
[situare] / src / ui / mapviewscreen.cpp
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;
+}