Merge branch 'master' into zoom_button_drag
[situare] / src / ui / mainwindow.cpp
index a93df5d..8b58426 100644 (file)
@@ -35,7 +35,6 @@
 #include "friendlistpanel.h"
 #include "logindialog.h"
 #include "map/mapview.h"
-#include "panelsidebar.h"
 #include "settingsdialog.h"
 #include "userinfopanel.h"
 #include "zoombuttonpanel.h"
@@ -53,6 +52,7 @@ const int N900_APP_HEIGHT = 449;
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent),
     m_drawOwnLocationCrosshair(false),
+    m_loggedIn(false),
     m_refresh(false),
     m_email(),    
     m_password(),
@@ -105,9 +105,9 @@ void MainWindow::buildFriendListPanel()
     qDebug() << __PRETTY_FUNCTION__;
 
     m_friendsListPanel = new FriendListPanel(this);
-    PanelSideBar *friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
+    m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
 
-    m_friendsListPanel->stackUnder(friendsListPanelSidebar);
+    m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
 
     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
             m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
@@ -122,7 +122,7 @@ void MainWindow::buildFriendListPanel()
             m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
 
     connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
-            friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
+            m_friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
 }
 
 void MainWindow::buildManualLocationCrosshair()
@@ -173,7 +173,7 @@ void MainWindow::buildMap()
 
 void MainWindow::buildOsmLicense()
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     m_osmLicense = new QLabel(this);
     m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
@@ -192,10 +192,13 @@ void MainWindow::buildUserInfoPanel()
     qDebug() << __PRETTY_FUNCTION__;
 
     m_userPanel = new UserInfoPanel(this);
-    PanelSideBar *userPanelSidebar = new PanelSideBar(this, LEFT);
+    m_userPanelSidebar = new PanelSideBar(this, LEFT);
+
+    m_userPanelSidebar->stackUnder(m_friendsListPanel);
+    m_userPanel->stackUnder(m_userPanelSidebar);
 
-    userPanelSidebar->stackUnder(m_friendsListPanel);
-    m_userPanel->stackUnder(userPanelSidebar);
+    connect(m_userPanel, SIGNAL(findUser(QPointF)),
+            this, SIGNAL(findUser(QPointF)));
 
     connect(this, SIGNAL(userLocationReady(User*)),
             m_userPanel, SLOT(userDataReceived(User*)));
@@ -220,13 +223,12 @@ void MainWindow::buildZoomButtonPanel()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_zoomButtonPanel = new ZoomButtonPanel(this, ZOOM_BUTTON_PANEL_POSITION_X,
-                                            ZOOM_BUTTON_PANEL_POSITION_Y);
+    m_zoomButtonPanel = new ZoomButtonPanel(this);
 
-    connect(m_zoomButtonPanel->m_zoomInButton, SIGNAL(clicked()),
+    connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
             this, SIGNAL(zoomIn()));
 
-    connect(m_zoomButtonPanel->m_zoomOutButton, SIGNAL(clicked()),
+    connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
             this, SIGNAL(zoomOut()));
 
     connect(this, SIGNAL(zoomLevelChanged(int)),
@@ -237,15 +239,22 @@ void MainWindow::buildZoomButtonPanel()
 
     connect(this, SIGNAL(minZoomLevelReached()),
             m_zoomButtonPanel, SLOT(disableZoomOutButton()));
+
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+            m_zoomButtonPanel, SLOT(screenResized(QSize)));
 }
 
 void MainWindow::createMenus()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    // login/logout
+    m_loginAct = new QAction(tr("Login"), this);
+    connect(m_loginAct, SIGNAL(triggered()),
+            this, SIGNAL(loginActionPressed()));
+
     // settings
     m_toSettingsAct = new QAction(tr("Settings"), this);
-    m_toSettingsAct->setObjectName(tr("Settings"));
     connect(m_toSettingsAct, SIGNAL(triggered()),
         this, SLOT(openSettingsDialog()));
 
@@ -264,6 +273,7 @@ void MainWindow::createMenus()
 
     // build the actual menu
     m_viewMenu = menuBar()->addMenu(tr("Main"));
+    m_viewMenu->addAction(m_loginAct);
     m_viewMenu->addAction(m_toSettingsAct);
     m_viewMenu->addAction(m_gpsToggleAct);
     m_viewMenu->addAction(m_autoCenteringAct);
@@ -274,8 +284,9 @@ void MainWindow::drawOsmLicense(const QSize &size)
 {
     qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
 
-    m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE) - PANEL_PEEK_AMOUNT,
-                        size.height() - m_osmLicense->fontMetrics().height());
+    m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
+                       - PANEL_PEEK_AMOUNT,
+                       size.height() - m_osmLicense->fontMetrics().height());
 
 }
 
@@ -392,6 +403,21 @@ void MainWindow::loadDone(bool done)
     }
 }
 
+void MainWindow::loggedIn(bool logged)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_loggedIn = logged;
+
+    if(logged) {
+        m_loginAct->setText(tr("Logout"));
+    }
+    else {
+        m_loginAct->setText(tr("Login"));
+    }
+    showPanels(m_loggedIn);
+}
+
 void MainWindow::loginDialogDone(const QString &email, const QString &password)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -442,6 +468,9 @@ void MainWindow::openSettingsDialog()
     qDebug() << __PRETTY_FUNCTION__;
 
     SettingsDialog *dialog = new SettingsDialog(this);
+    if(!m_loggedIn) {
+        dialog->disableSituareSettings();
+    }
     dialog->show();
 }
 
@@ -468,12 +497,6 @@ void MainWindow::setMapViewScene(QGraphicsScene *scene)
     m_mapView->setScene(scene);
 }
 
-void MainWindow::setUsername(const QString &username)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-    m_email = username;
-}
-
 void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -489,6 +512,12 @@ void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
     }
 }
 
+void MainWindow::setUsername(const QString &username)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+    m_email = username;
+}
+
 void MainWindow::setViewPortSize(int width, int height)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -508,6 +537,25 @@ void MainWindow::showMaemoInformationBox(const QString &message)
 #endif
 }
 
+void MainWindow::showPanels(bool show)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+    if(show) {
+        m_friendsListPanel->show();
+        m_friendsListPanelSidebar->show();
+        m_userPanel->show();
+        m_userPanelSidebar->show();
+    }
+    else {
+        m_friendsListPanel->closePanel();
+        m_friendsListPanel->hide();
+        m_friendsListPanelSidebar->hide();
+        m_userPanel->closePanel();
+        m_userPanel->hide();
+        m_userPanelSidebar->hide();
+    }
+}
+
 void MainWindow::startLoginProcess(const QUrl &url)
 {
     qDebug() << __PRETTY_FUNCTION__;