Updated some changes to userinfo
[situare] / src / ui / mapviewscreen.cpp
index 7ec92ce..6e32f92 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)
+   : QWidget(parent),
+     m_autoCenteringEnabled(false)
 {
     MapView *mapView = new MapView(this);
-    mapEngine = new MapEngine(this);
-    mapView->setScene(mapEngine->scene());
+    m_mapEngine = new MapEngine(this);
+    mapView->setScene(m_mapEngine->scene());
 
-    connect(mapView, SIGNAL(viewScrolled(QPointF)), mapEngine, SLOT(setLocation(QPointF)));
-    connect(mapEngine, SIGNAL(locationChanged(QPointF)),
-           mapView, SLOT(centerToSceneCoordinates(QPointF)));
-    connect(mapEngine, SIGNAL(zoomLevelChanged(int)), mapView, SLOT(setZoomLevel(int)));
+    m_friendsListPanel = new FriendListPanel(this);
+    m_userPanel = new UserInfoPanel(this);
+    PanelSideBar *userPanelSidebar = new PanelSideBar(this, LEFT);
+    PanelSideBar *friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
+
+    m_zoomButtonPanel = new ZoomButtonPanel(this, ZOOM_BUTTON_PANEL_POSITION_X,
+                                            ZOOM_BUTTON_PANEL_POSITION_Y);
+
+    connect(mapView, SIGNAL(viewScrolled(QPoint)),
+            m_mapEngine, SLOT(setLocation(QPoint)));
+    connect(m_mapEngine, SIGNAL(locationChanged(QPoint)),
+            mapView, SLOT(centerToSceneCoordinates(QPoint)));
+    connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
+            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(viewZoomFinished()),
+            m_mapEngine, SLOT(viewZoomFinished()));
+
+    connect(this, SIGNAL(zoomInKeyPressed()),
+            m_mapEngine, SLOT(zoomIn()));
+    connect(this, SIGNAL(zoomOutKeyPressed()),
+            m_mapEngine, SLOT(zoomOut()));
+
+    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()),
+            m_mapEngine, SLOT(zoomIn()));
+    connect(m_zoomButtonPanel->m_zoomOutBtn, SIGNAL(clicked()),
+            m_mapEngine, SLOT(zoomOut()));
+
+    connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
+            m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
+    connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
+            m_mapEngine, SLOT(setViewLocation(QPointF)));
+
+    connect(this, SIGNAL(userLocationReady(User*)),
+            m_mapEngine, SLOT(receiveOwnLocation(User*)));
+    connect(this, SIGNAL(userLocationReady(User*)),
+            m_mapEngine, SLOT(receiveOwnLocation(User*)));
+    connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
+            m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
+
+    connect(m_mapEngine, SIGNAL(mapScrolled()),
+            this, SLOT(locationChanged()));
+
+    connect(this, SIGNAL(userLocationReady(User*)),
+            m_userPanel, SLOT(userDataReceived(User*)));
+
+    connect(m_userPanel, SIGNAL(requestReverseGeo()),
+            this, SIGNAL(requestReverseGeo()));
+
+    connect(this, SIGNAL(reverseGeoReady(QString)),
+            m_userPanel, SIGNAL(reverseGeoReady(QString)));
+
+    connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
+            this, SIGNAL(statusUpdate(QString,bool)));
+
+    connect(m_userPanel, SIGNAL(refreshUserData()),
+            this, SIGNAL(refreshUserData()));
 
     QHBoxLayout *mapViewLayout = new QHBoxLayout;
-    //DEBUG
-    QVBoxLayout *mapControlLayout = new QVBoxLayout;
-    QWidget *mapControl = new QWidget(this);
-    mapControl->setLayout(mapControlLayout);
-    search = new QPushButton("Search", this);
-    zoomOut = new QPushButton("-", this);
-    zoomIn = new QPushButton("+", this);
-    mapControlLayout->addWidget(&latLine);
-    mapControlLayout->addWidget(&lonLine);
-    mapControlLayout->addWidget(search);
-    mapControlLayout->addWidget(zoomIn);
-    mapControlLayout->addWidget(zoomOut);
-    mapViewLayout->addWidget(mapControl);
-    connect(search, SIGNAL(clicked()), this, SLOT(searchMap()));
-    connect(zoomIn, SIGNAL(clicked()), mapEngine, SLOT(zoomIn()));
-    connect(zoomOut, SIGNAL(clicked()), mapEngine, SLOT(zoomOut()));
-    //DEBUG
+
+    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->setFont(QFont("Nokia Sans", 9));
+    m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
+                         m_osmLicense->fontMetrics().height());
+
+    m_friendsListPanel->stackUnder(friendsListPanelSidebar);
+    userPanelSidebar->stackUnder(m_friendsListPanel);
+    m_userPanel->stackUnder(userPanelSidebar);
+    m_zoomButtonPanel->stackUnder(m_userPanel);
+    m_osmLicense->stackUnder(m_zoomButtonPanel);
+    mapView->stackUnder(m_osmLicense);
+
     mapViewLayout->addWidget(mapView);
     setLayout(mapViewLayout);
 
-    mapEngine->init();
+    mapViewLayout->setMargin(0);
+
+    m_mapEngine->init();
+
+    setObjectName("Map view");
 }
 
-void MapViewScreen::searchMap()
+void MapViewScreen::drawOsmLicense(int width, int height)
 {
-    qreal lat = latLine.text().toFloat();
-    qreal lon = lonLine.text().toFloat();
+    qDebug() << __PRETTY_FUNCTION__ << width << "x" << height;
+    m_osmLicense->move(width - m_osmLicense->fontMetrics().width(OSM_LICENSE) - PANEL_PEEK_AMOUNT,
+                        height - m_osmLicense->fontMetrics().height());
+}
 
-    qDebug() << lat << "," << lon;
+void MapViewScreen::locationChanged()
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
-    mapEngine->setViewLocation(QPointF(lon, lat));
+    if (m_autoCenteringEnabled)
+        emit mapLocationChanged();
 }
 
-void MapViewScreen::zoomInMap()
+void MapViewScreen::positionReceived(QPointF position, qreal accuracy)
 {
-    //mapEngine->zoomLevelChanged();
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (m_autoCenteringEnabled)
+        m_mapEngine->setViewLocation(position);
 }
 
-void MapViewScreen::zoomOutMap()
+void MapViewScreen::enableAutoCentering(bool enabled)
 {
-    //mapEngine->zoomLevelChanged();
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_autoCenteringEnabled = enabled;
+    m_mapEngine->setAutoCentering(enabled);
 }