Merge branch 'new_panels' into locationlistview
[situare] / src / ui / mainwindow.cpp
index 1872811..2b7acce 100644 (file)
@@ -4,9 +4,10 @@
 
       Henri Lampela - henri.lampela@ixonos.com
       Kaj Wallin - kaj.wallin@ixonos.com
-      Jussi Laitinen jussi.laitinen@ixonos.com
+      Jussi Laitinen - jussi.laitinen@ixonos.com
       Sami Rämö - sami.ramo@ixonos.com
       Ville Tiensuu - ville.tiensuu@ixonos.com
+      Katri Kaikkonen - katri.kaikkonen@ixonos.com
 
    Situare is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    USA.
 */
 
-#include <QtGui>
-#include <QtWebKit>
+#include <QAction>
+#include <QApplication>
+#include <QMenuBar>
+#include <QMessageBox>
 #include <QtAlgorithms>
+#include <QtWebKit>
 
+///< @todo sort
 #include "facebookservice/facebookauthentication.h"
 #include "map/mapcommon.h"
 #include "map/mapview.h"
 #include "common.h"
+#include "error.h"
 #include "friendlistpanel.h"
 #include "fullscreenbutton.h"
-#include "indicatorbutton.h"
+#include "indicatorbuttonpanel.h"
 #include "logindialog.h"
 #include "mapscale.h"
+#include "panelcommon.h"
+#include "routingpanel.h"
+#include "tabbedpanel.h"
 #include "searchdialog.h"
 #include "settingsdialog.h"
 #include "userinfopanel.h"
 
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent),
-    m_errorShown(false),
-    m_loggedIn(false),
-    m_refresh(false),
-    m_progressIndicatorCount(0),
-    m_ownLocationCrosshair(0),
-    m_email(),
-    m_password(),
-    m_webView(0),
-    m_fullScreenButton(0),
-    m_indicatorButton(0),
-    m_mapScale(0),
-    m_cookieJar(0)
+      m_errorShown(false),
+      m_loggedIn(false),
+      m_refresh(false),
+      m_progressIndicatorCount(0),
+      m_ownLocationCrosshair(0),
+      m_email(), ///< @todo WTF?!?!?!?
+      m_password(),
+      m_webView(0),
+      m_fullScreenButton(0),
+      m_indicatorButtonPanel(0),
+      m_mapScale(0),
+      m_cookieJar(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -79,14 +88,13 @@ MainWindow::MainWindow(QWidget *parent)
     setCentralWidget(new QWidget());
     centralWidget()->setLayout(layout);
 
-    buildFriendListPanel();
-    buildUserInfoPanel();
+    buildPanels();
 
     createMenus();
     setWindowTitle(tr("Situare"));
 
     // set stacking order of widgets
-    m_zoomButtonPanel->stackUnder(m_userPanel);
+    m_zoomButtonPanel->stackUnder(m_tabbedPanel);
     if(m_fullScreenButton) {
         m_fullScreenButton->stackUnder(m_zoomButtonPanel);
         m_osmLicense->stackUnder(m_fullScreenButton);
@@ -94,8 +102,8 @@ MainWindow::MainWindow(QWidget *parent)
         m_osmLicense->stackUnder(m_zoomButtonPanel);
     }
     m_ownLocationCrosshair->stackUnder(m_osmLicense);
-    m_indicatorButton->stackUnder(m_ownLocationCrosshair);
-    m_mapScale->stackUnder(m_indicatorButton);
+    m_indicatorButtonPanel->stackUnder(m_ownLocationCrosshair);
+    m_mapScale->stackUnder(m_indicatorButtonPanel);
     m_mapView->stackUnder(m_mapScale);
 
     grabZoomKeys(true);
@@ -141,10 +149,17 @@ void MainWindow::automaticUpdateDialogFinished(int result)
 void MainWindow::buildFullScreenButton()
 {
     qDebug() << __PRETTY_FUNCTION__;
+
 #ifdef Q_WS_MAEMO_5
     m_fullScreenButton = new FullScreenButton(this);
-    connect(m_fullScreenButton, SIGNAL(clicked()),
-            this, SLOT(toggleFullScreen()));
+
+    if (m_fullScreenButton) {
+        connect(m_fullScreenButton, SIGNAL(clicked()),
+                this, SLOT(toggleFullScreen()));
+
+        connect(qApp, SIGNAL(showFullScreenButton()),
+                m_fullScreenButton, SLOT(invoke()));
+    }
 #endif // Q_WS_MAEMO_5
 }
 
@@ -154,48 +169,38 @@ void MainWindow::buildFriendListPanel()
 
     m_friendsListPanel = new FriendListPanel(this);
 
-    m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
-
-    m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
-
     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
             m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
 
     connect(this, SIGNAL(locationItemClicked(QList<QString>)),
             m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
 
-    connect(m_mapView, SIGNAL(viewResized(QSize)),
-            m_friendsListPanel, SLOT(resizePanel(QSize)));
-
-    connect(m_mapView, SIGNAL(viewResized(QSize)),
-            m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
-
-    connect(m_friendsListPanel, SIGNAL(friendItemClicked(GeoCoordinate)),
-            this, SIGNAL(findFriend(GeoCoordinate)));
+    connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
+            this, SIGNAL(centerToCoordinates(GeoCoordinate)));
 
     connect(this, SIGNAL(friendImageReady(User*)),
             m_friendsListPanel, SLOT(friendImageReady(User*)));
 
-    connect(this, SIGNAL(locationDataParsed(QList<Location>&)),
-            m_friendsListPanel, SLOT(locationDataReady(QList<Location>&)));
-
-    connect(m_friendsListPanel, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)),
-            this, SIGNAL(locationItemClicked(GeoCoordinate&,GeoCoordinate&)));
+    connect(m_friendsListPanel, SIGNAL(routeToFriend(const GeoCoordinate&)),
+            this, SIGNAL(routeTo(const GeoCoordinate&)));
 }
 
-void MainWindow::buildIndicatorButton()
+void MainWindow::buildIndicatorButtonPanel()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_indicatorButton = new IndicatorButton(this);
+    m_indicatorButtonPanel = new IndicatorButtonPanel(this);
 
-    connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
+    connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
         this, SIGNAL(autoCenteringTriggered(bool)));
 
     connect(m_mapView, SIGNAL(viewResized(QSize)),
-            m_indicatorButton, SLOT(screenResized(QSize)));
+            m_indicatorButtonPanel, SLOT(screenResized(QSize)));
 
-    connect(m_indicatorButton, SIGNAL(draggingModeTriggered()),
+    connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
+            m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
+
+    connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
             this, SIGNAL(draggingModeTriggered()));
 }
 
@@ -256,7 +261,7 @@ void MainWindow::buildMap()
     buildOsmLicense();
     buildManualLocationCrosshair();
     buildFullScreenButton();
-    buildIndicatorButton();
+    buildIndicatorButtonPanel();
     buildMapScale();
 
     connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
@@ -310,45 +315,81 @@ void MainWindow::buildOsmLicense()
             this, SLOT(drawOsmLicense(QSize)));
 }
 
-void MainWindow::buildUserInfoPanel()
+void MainWindow::buildPanels()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    buildUserInfoPanel();
+    buildFriendListPanel();
+    buildRoutingPanel();
+
+    m_tabbedPanel = new TabbedPanel(this);
+    m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
+    m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
+    m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
+
+    connect(m_tabbedPanel, SIGNAL(panelClosed()),
+            m_friendsListPanel, SLOT(clearFriendListFilter()));
+
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+            m_tabbedPanel, SLOT(resizePanel(QSize)));
+}
+
+void MainWindow::buildRoutingPanel()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_userPanel = new UserInfoPanel(this);
+    m_routingPanel = new RoutingPanel(this);
+
+    connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
+            m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
 
-    m_userPanelSidebar = new PanelSideBar(this, LEFT);
+    connect(m_routingPanel,
+            SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
+            this,
+            SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
 
-    m_userPanelSidebar->stackUnder(m_friendsListPanel);
-    m_userPanel->stackUnder(m_userPanelSidebar);
+    connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
+            this, SIGNAL(routeTo(const GeoCoordinate&)));
+
+    connect(this, SIGNAL(routeParsed(Route&)),
+            m_routingPanel, SLOT(setRoute(Route&)));
+
+    connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
+            this, SIGNAL(centerToCoordinates(GeoCoordinate)));
+
+    connect(m_routingPanel, SIGNAL(requestSearchLocation()),
+            this, SLOT(startLocationSearch()));
+}
+
+void MainWindow::buildUserInfoPanel()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_userInfoPanel = new UserInfoPanel(this);
 
     connect(this, SIGNAL(userLocationReady(User*)),
-            m_userPanel, SLOT(userDataReceived(User*)));
+            m_userInfoPanel, SLOT(userDataReceived(User*)));
 
     connect(this, SIGNAL(reverseGeoReady(QString)),
-            m_userPanel, SIGNAL(reverseGeoReady(QString)));
+            m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
 
     connect(this, SIGNAL(clearUpdateLocationDialogData()),
-            m_userPanel, SIGNAL(clearUpdateLocationDialogData()));
+            m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
 
-    connect(m_mapView, SIGNAL(viewResized(QSize)),
-            m_userPanel, SLOT(resizePanel(QSize)));
+    connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
+            this, SIGNAL(centerToCoordinates(GeoCoordinate)));
 
-    connect(m_mapView, SIGNAL(viewResized(QSize)),
-            m_userPanelSidebar, SLOT(resizeSideBar(QSize)));
-
-    connect(m_userPanel, SIGNAL(findUser(GeoCoordinate)),
-            this, SIGNAL(findUser(GeoCoordinate)));
-
-    connect(m_userPanel, SIGNAL(requestReverseGeo()),
+    connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
             this, SIGNAL(requestReverseGeo()));
 
-    connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
+    connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
             this, SIGNAL(statusUpdate(QString,bool)));
 
-    connect(m_userPanel, SIGNAL(refreshUserData()),
+    connect(m_userInfoPanel, SIGNAL(refreshUserData()),
             this, SIGNAL(refreshUserData()));
 
-    connect(m_userPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
+    connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
             this, SLOT(buildInformationBox(QString, bool)));
 }
 
@@ -442,17 +483,11 @@ void MainWindow::createMenus()
     connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
             this, SIGNAL(gpsTriggered(bool)));
 
-    /// @todo remove when not needed!
-    m_searchLocationAct = new QAction(tr("Location search"), this);
-    connect(m_searchLocationAct, SIGNAL(triggered()),
-            this, SLOT(startLocationSearch()));
-
     // 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_searchLocationAct); /// @todo remove when not needed!
     m_viewMenu->setObjectName(tr("Menu"));
 }
 
@@ -505,15 +540,9 @@ void MainWindow::drawFullScreenButton(const QSize &size)
 {
     qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
 
-    if(m_fullScreenButton) {
-        if(m_loggedIn) {
-            m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
-                                     - PANEL_PEEK_AMOUNT,
-                                     size.height() - m_fullScreenButton->size().height());
-        } else {
-            m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
-                                     size.height() - m_fullScreenButton->size().height());
-        }
+    if (m_fullScreenButton) {
+        m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
+                                 size.height() - m_fullScreenButton->size().height());
     }
 }
 
@@ -523,9 +552,8 @@ void MainWindow::drawMapScale(const QSize &size)
 
     const int LEFT_SCALE_MARGIN = 10;
     const int BOTTOM_SCALE_MARGIN = 2;
-    qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
 
-    m_mapScale->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
+    m_mapScale->move(LEFT_SCALE_MARGIN,
                      size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
 }
 
@@ -534,7 +562,7 @@ 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,
+                       - PANEL_BAR_WIDTH,
                        size.height() - m_osmLicense->fontMetrics().height());
 }
 
@@ -815,8 +843,7 @@ void MainWindow::setIndicatorButtonEnabled(bool enabled)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_indicatorButton->setChecked(enabled);
-
+    m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
 }
 
 void MainWindow::setMapViewScene(QGraphicsScene *scene)
@@ -912,19 +939,21 @@ void MainWindow::showPanels()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    drawFullScreenButton(m_viewPortSize);
+///< @todo check how this is called and can this method be removed
 
-    if(m_loggedIn) {
-        if(!m_friendsListPanel->isVisible()) {
-            m_friendsListPanel->show();
-            m_friendsListPanelSidebar->show();
-        }
+    drawFullScreenButton(m_viewPortSize);
 
-        if(!m_userPanel->isVisible()) {
-            m_userPanel->show();
-            m_userPanelSidebar->show();
-        }
-    }
+//    if(m_loggedIn) {
+//        if(!m_friendsListPanel->isVisible()) {
+//            m_friendsListPanel->show();
+//            m_friendsListPanelSidebar->show();
+//        }
+
+//        if(!m_userPanel->isVisible()) {
+//            m_userPanel->show();
+//            m_userPanelSidebar->show();
+//        }
+//    }
 }
 
 void MainWindow::startLocationSearch()
@@ -975,14 +1004,17 @@ void MainWindow::updateItemVisibility()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if(!m_loggedIn) {
-        m_friendsListPanel->closePanel();
-        m_friendsListPanel->hide();
-        m_friendsListPanelSidebar->hide();
-        m_userPanel->closePanel();
-        m_userPanel->hide();
-        m_userPanelSidebar->hide();
-    }
+///< @todo can this be removed?
+
+//    if(!m_loggedIn) {
+//        m_friendsListPanel->closePanel();
+//        m_friendsListPanel->hide();
+//        m_friendsListPanelSidebar->hide();
+
+//        m_userPanel->closePanel();
+//        m_userPanel->hide();
+//        m_userPanelSidebar->hide();
+//    }
 }
 
 const QString MainWindow::username()