Merge branch 'master' into locationlistview
[situare] / src / ui / mainwindow.cpp
index c158b9b..5a74bde 100644 (file)
@@ -36,6 +36,7 @@
 #include "indicatorbutton.h"
 #include "logindialog.h"
 #include "mapscale.h"
+#include "searchdialog.h"
 #include "settingsdialog.h"
 #include "userinfopanel.h"
 #include "zoombuttonpanel.h"
@@ -58,11 +59,11 @@ MainWindow::MainWindow(QWidget *parent)
     m_refresh(false),
     m_progressIndicatorCount(0),
     m_ownLocationCrosshair(0),
-    m_email(),    
+    m_email(),
     m_password(),
+    m_webView(0),
     m_fullScreenButton(0),
     m_indicatorButton(0),
-    m_webView(0),
     m_mapScale(0),
     m_cookieJar(0)
 {
@@ -98,7 +99,6 @@ MainWindow::MainWindow(QWidget *parent)
     m_mapScale->stackUnder(m_indicatorButton);
     m_mapView->stackUnder(m_mapScale);
 
-
     grabZoomKeys(true);
 
     // Set default screen size
@@ -171,8 +171,17 @@ void MainWindow::buildFriendListPanel()
     connect(m_mapView, SIGNAL(viewResized(QSize)),
             m_friendsListPanelSidebar, SLOT(resizeSideBar(QSize)));
 
-    connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
-            this, SIGNAL(findFriend(QPointF)));
+    connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
+            this, SIGNAL(findFriend(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&)));
 }
 
 void MainWindow::buildIndicatorButton()
@@ -181,9 +190,11 @@ void MainWindow::buildIndicatorButton()
 
     m_indicatorButton = new IndicatorButton(this);
 
-    connect(m_indicatorButton, SIGNAL(triggered(bool)),
+    connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
         this, SIGNAL(autoCenteringTriggered(bool)));
 
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+            m_indicatorButton, SLOT(screenResized(QSize)));
 }
 
 void MainWindow::buildInformationBox(const QString &message, bool modal)
@@ -246,11 +257,11 @@ void MainWindow::buildMap()
     buildIndicatorButton();
     buildMapScale();
 
-    connect(m_mapView, SIGNAL(viewScrolled(QPoint)),
-            this, SIGNAL(mapViewScrolled(QPoint)));
+    connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
+            this, SIGNAL(mapViewScrolled(SceneCoordinate)));
 
-    connect(this, SIGNAL(centerToSceneCoordinates(QPoint)),
-            m_mapView, SLOT(centerToSceneCoordinates(QPoint)));
+    connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
+            m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
 
     connect(m_mapView, SIGNAL(viewResized(QSize)),
             this, SIGNAL(mapViewResized(QSize)));
@@ -323,8 +334,8 @@ void MainWindow::buildUserInfoPanel()
     connect(m_mapView, SIGNAL(viewResized(QSize)),
             m_userPanelSidebar, SLOT(resizeSideBar(QSize)));
 
-    connect(m_userPanel, SIGNAL(findUser(QPointF)),
-            this, SIGNAL(findUser(QPointF)));
+    connect(m_userPanel, SIGNAL(findUser(GeoCoordinate)),
+            this, SIGNAL(findUser(GeoCoordinate)));
 
     connect(m_userPanel, SIGNAL(requestReverseGeo()),
             this, SIGNAL(requestReverseGeo()));
@@ -385,6 +396,7 @@ void MainWindow::buildZoomButtonPanel()
 
     connect(m_mapView, SIGNAL(viewResized(QSize)),
             m_zoomButtonPanel, SLOT(screenResized(QSize)));
+
 }
 
 void MainWindow::clearCookieJar()
@@ -426,18 +438,17 @@ void MainWindow::createMenus()
     connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
             this, SIGNAL(gpsTriggered(bool)));
 
-    // automatic centering
-//    m_autoCenteringAct = new QAction(tr("Auto centering"), this);
-//    m_autoCenteringAct->setCheckable(true);
-//    connect(m_autoCenteringAct, SIGNAL(triggered(bool)),
-//        this, SIGNAL(autoCenteringTriggered(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_autoCenteringAct);
+    m_viewMenu->addAction(m_searchLocationAct); /// @todo remove when not needed!
     m_viewMenu->setObjectName(tr("Menu"));
 }
 
@@ -447,6 +458,7 @@ void MainWindow::dialogFinished(int status)
 
     QDialog *dialog = m_queue.takeFirst();
     LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
+    SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
     if(loginDialog) {
         if(status != 0) {
             buildWebView();
@@ -468,6 +480,10 @@ void MainWindow::dialogFinished(int status)
         } else {
             emit cancelLoginProcess();
         }
+    } else if(searchDialog) {
+        if(status != 0) {
+            emit searchForLocation(searchDialog->input());
+        }
     }
 
     dialog->deleteLater();
@@ -497,27 +513,10 @@ void MainWindow::drawFullScreenButton(const QSize &size)
     }
 }
 
-void MainWindow::drawIndicatorButton(const QSize &size)
-{
-    qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
-
-    const int LEFT_SCALE_MARGIN = 10;
-    const int BOTTOM_SCALE_MARGIN = 80;
-
-    if(m_indicatorButton) {
-        if(m_loggedIn) {
-            m_indicatorButton->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
-                             size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
-
-        } else {
-            m_indicatorButton->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
-                             size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
-        }
-    }
-}
-
 void MainWindow::drawMapScale(const QSize &size)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     const int LEFT_SCALE_MARGIN = 10;
     const int BOTTOM_SCALE_MARGIN = 2;
     qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
@@ -632,7 +631,6 @@ void MainWindow::loadCookies()
 
         m_cookieJar->setAllCookies(cookieList);
         m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
-
     }
 }
 
@@ -721,7 +719,7 @@ void MainWindow::loginUsingCookies()
 
     buildWebView();
     loadCookies();
-    
+
     QStringList urlParts;
     urlParts.append(FACEBOOK_LOGINBASE);
     urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
@@ -802,13 +800,6 @@ void MainWindow::saveCookies()
     settings.setValue(COOKIES, list);
 }
 
-//void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
-//{
-//    qDebug() << __PRETTY_FUNCTION__;
-
-//    m_autoCenteringAct->setChecked(enabled);
-//}
-
 void MainWindow::setGPSButtonEnabled(bool enabled)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -816,8 +807,6 @@ void MainWindow::setGPSButtonEnabled(bool enabled)
     m_gpsToggleAct->setChecked(enabled);
 
     setOwnLocationCrosshairVisibility(!enabled);
-
-//    m_autoCenteringAct->setVisible(enabled);
 }
 
 void MainWindow::setIndicatorButtonEnabled(bool enabled)
@@ -826,8 +815,6 @@ void MainWindow::setIndicatorButtonEnabled(bool enabled)
 
     m_indicatorButton->setChecked(enabled);
 
-    connect(m_autoCenteringAct, SIGNAL(triggered(bool)),
-            this, SIGNAL(autoCenteringTriggered(bool)));
 }
 
 void MainWindow::setMapViewScene(QGraphicsScene *scene)
@@ -926,13 +913,11 @@ void MainWindow::showPanels()
     qDebug() << __PRETTY_FUNCTION__;
 
     drawFullScreenButton(m_viewPortSize);
-    drawIndicatorButton(m_viewPortSize);
 
     if(m_loggedIn) {
         if(!m_friendsListPanel->isVisible()) {
             m_friendsListPanel->show();
             m_friendsListPanelSidebar->show();
-            m_indicatorButton->show();
         }
 
         if(!m_userPanel->isVisible()) {
@@ -942,11 +927,13 @@ void MainWindow::showPanels()
     }
 }
 
-//void MainWindow::showIndicatorButton(bool gps, bool autoCentering)
-//{
-//    qDebug() << __PRETTY_FUNCTION__;
+void MainWindow::startLocationSearch()
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
-//}
+    SearchDialog *searchDialog = new SearchDialog();
+    queueDialog(searchDialog);
+}
 
 void MainWindow::startLoginProcess()
 {
@@ -987,8 +974,8 @@ void MainWindow::toggleProgressIndicator(bool value)
 void MainWindow::updateItemVisibility()
 {
     qDebug() << __PRETTY_FUNCTION__;
-    
-    if(m_loggedIn) {       
+
+    if(m_loggedIn) {
 
         if(!m_gpsToggleAct->isChecked())
             setOwnLocationCrosshairVisibility(true);
@@ -1006,7 +993,7 @@ void MainWindow::updateItemVisibility()
 const QString MainWindow::username()
 {
     qDebug() << __PRETTY_FUNCTION__;
-    
+
     return m_email;
 }
 
@@ -1021,4 +1008,3 @@ void MainWindow::webViewRequestFinished(QNetworkReply *reply)
         emit error(ErrorContext::NETWORK, reply->error());
     }
 }
-