Merge branch 'master' into contact_dialog
[situare] / src / ui / mainwindow.cpp
index 85daf47..e418b85 100644 (file)
@@ -40,6 +40,7 @@
 #include "friendlistpanel.h"
 #include "fullscreenbutton.h"
 #include "indicatorbuttonpanel.h"
+#include "locationsearchpanel.h"
 #include "logindialog.h"
 #include "mapscale.h"
 #include "panelcommon.h"
 #include <QtGui/QX11Info>
 #include <X11/Xatom.h>
 #include <X11/Xlib.h>
-#include "ossoabookdialog.h"
 #endif // Q_WS_MAEMO_5
 
+#if defined(Q_WS_MAEMO_5) & defined(ARMEL)
+#include "ossoabookdialog.h"
+#endif
+
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent),
       m_errorShown(false),
@@ -92,11 +96,13 @@ MainWindow::MainWindow(QWidget *parent)
     setWindowTitle(tr("Situare"));
 
     // set stacking order of widgets (from top to bottom)
-    // if the fullscreen button exists, then it is the topmost one, otherwise the tabbed panel is
+    // m_tabbedPanel is the topmost one
     if (m_fullScreenButton) {
-        m_tabbedPanel->stackUnder(m_fullScreenButton);
+        m_fullScreenButton->stackUnder(m_tabbedPanel);
+        m_crosshair->stackUnder(m_fullScreenButton);
+    } else {
+        m_crosshair->stackUnder(m_tabbedPanel);
     }
-    m_crosshair->stackUnder(m_tabbedPanel);
     m_zoomButtonPanel->stackUnder(m_crosshair);
     m_indicatorButtonPanel->stackUnder(m_zoomButtonPanel);
     m_osmLicense->stackUnder(m_indicatorButtonPanel);
@@ -254,6 +260,31 @@ void MainWindow::buildInformationBox(const QString &message, bool modal)
     queueDialog(msgBox);
 }
 
+void MainWindow::buildLocationSearchPanel()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_locationSearchPanel = new LocationSearchPanel(this);
+
+    connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
+            m_locationSearchPanel, SLOT(populateLocationListView(const QList<Location>&)));
+
+    connect(m_locationSearchPanel, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
+            this, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
+
+    connect(m_locationSearchPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
+            this, SIGNAL(routeTo(const GeoCoordinate&)));
+
+    connect(m_locationSearchPanel, SIGNAL(requestSearchLocation()),
+            this, SLOT(startLocationSearch()));
+
+    connect(this, SIGNAL(searchForLocation(QString)),
+            m_locationSearchPanel, SLOT(prependSearchHistory(QString)));
+
+    connect(m_locationSearchPanel, SIGNAL(searchHistoryItemClicked(QString)),
+            this, SIGNAL(searchHistoryItemClicked(QString)));
+}
+
 void MainWindow::buildMap()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -324,21 +355,28 @@ void MainWindow::buildPanels()
 
     buildUserInfoPanel();
     buildFriendListPanel();
+    buildLocationSearchPanel();
     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"));
+    
+    //Save Situare related tab indexes so tabs can be enabled/disabled when logged in/out
+    m_situareTabsIndexes.append(
+            m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png")));
+    m_situareTabsIndexes.append(
+            m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png")));
+
+    m_tabbedPanel->addTab(m_locationSearchPanel, QIcon(":/res/images/location_search.png"));
     m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
 
     connect(m_mapView, SIGNAL(viewResized(QSize)),
             m_tabbedPanel, SLOT(resizePanel(QSize)));
 
-    connect(m_friendsListPanel, SIGNAL(showPanelRequested(QWidget*)),
-            m_tabbedPanel, SLOT(showPanel(QWidget*)));
+    connect(m_friendsListPanel, SIGNAL(openPanelRequested(QWidget*)),
+            m_tabbedPanel, SLOT(openPanel(QWidget*)));
 
-    connect(m_routingPanel, SIGNAL(showPanelRequested(QWidget*)),
-            m_tabbedPanel, SLOT(showPanel(QWidget*)));
+    connect(m_routingPanel, SIGNAL(openPanelRequested(QWidget*)),
+            m_tabbedPanel, SLOT(openPanel(QWidget*)));
 
     connect(m_tabbedPanel, SIGNAL(panelClosed()),
             m_friendsListPanel, SLOT(anyPanelClosed()));
@@ -354,6 +392,12 @@ void MainWindow::buildPanels()
 
     connect(m_tabbedPanel, SIGNAL(panelOpened()),
             m_mapView, SLOT(enableCenterShift()));
+
+    connect(m_tabbedPanel, SIGNAL(panelClosed()),
+            m_userInfoPanel, SIGNAL(collapse()));
+
+    connect(m_tabbedPanel, SIGNAL(currentChanged(int)),
+            m_userInfoPanel, SIGNAL(collapse()));
 }
 
 void MainWindow::buildRoutingPanel()
@@ -362,16 +406,8 @@ void MainWindow::buildRoutingPanel()
 
     m_routingPanel = new RoutingPanel(this);
 
-    connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
-            m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
-
-    connect(m_routingPanel,
-            SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
-            this,
-            SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
-
-    connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
-            this, SIGNAL(routeTo(const GeoCoordinate&)));
+    connect(m_routingPanel, SIGNAL(routeToCursor()),
+            this, SIGNAL(routeToCursor()));
 
     connect(this, SIGNAL(routeParsed(Route&)),
             m_routingPanel, SLOT(setRoute(Route&)));
@@ -379,8 +415,8 @@ void MainWindow::buildRoutingPanel()
     connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
             this, SIGNAL(centerToCoordinates(GeoCoordinate)));
 
-    connect(m_routingPanel, SIGNAL(requestSearchLocation()),
-            this, SLOT(startLocationSearch()));
+    connect(m_routingPanel, SIGNAL(clearRoute()),
+            this, SIGNAL(clearRoute()));
 }
 
 void MainWindow::buildUserInfoPanel()
@@ -911,10 +947,13 @@ void MainWindow::setUsername(const QString &username)
 
 void MainWindow::showContactDialog(const QString &guid)
 {
-    qDebug() << __PRETTY_FUNCTION__ << guid;
+    qDebug() << __PRETTY_FUNCTION__;
 
 #if defined(Q_WS_MAEMO_5) & defined(ARMEL)
     OssoABookDialog::showContactDialog(guid);
+#else
+    Q_UNUSED(guid);
+    buildInformationBox(tr("Contact dialog works only on phone!"), true);
 #endif
 }
 
@@ -957,25 +996,6 @@ void MainWindow::showInformationBox()
     }
 }
 
-void MainWindow::showPanels()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-///< @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();
-//        }
-
-//        if(!m_userPanel->isVisible()) {
-//            m_userPanel->show();
-//            m_userPanelSidebar->show();
-//        }
-//    }
-}
-
 void MainWindow::startLocationSearch()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -1034,17 +1054,7 @@ void MainWindow::updateItemVisibility()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-///< @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();
-//    }
+    m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, m_loggedIn);
 }
 
 const QString MainWindow::username()