Fixed signals
[situare] / src / ui / mainwindow.cpp
index c886e90..21c362c 100644 (file)
 #include "common.h"
 #include "friendlistpanel.h"
 #include "fullscreenbutton.h"
+#include "indicatorbutton.h"
 #include "logindialog.h"
 #include "mapscale.h"
+#include "searchdialog.h"
 #include "settingsdialog.h"
 #include "userinfopanel.h"
 #include "zoombuttonpanel.h"
+#include "indicatorbuttonpanel.h"
 
 #include "mainwindow.h"
 
 
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent),
-    m_drawOwnLocationCrosshair(false),
     m_errorShown(false),
     m_loggedIn(false),
     m_refresh(false),
     m_progressIndicatorCount(0),
     m_ownLocationCrosshair(0),
-    m_email(),    
+    m_email(),
     m_password(),
-    m_fullScreenButton(0),
     m_webView(0),
+    m_fullScreenButton(0),
+//    m_indicatorButton(0),
+    m_indicatorButtonPanel(0),
     m_mapScale(0),
     m_cookieJar(0)
 {
@@ -92,7 +96,8 @@ MainWindow::MainWindow(QWidget *parent)
         m_osmLicense->stackUnder(m_zoomButtonPanel);
     }
     m_ownLocationCrosshair->stackUnder(m_osmLicense);
-    m_mapScale->stackUnder(m_ownLocationCrosshair);
+    m_indicatorButtonPanel->stackUnder(m_ownLocationCrosshair);
+    m_mapScale->stackUnder(m_indicatorButtonPanel);
     m_mapView->stackUnder(m_mapScale);
 
     grabZoomKeys(true);
@@ -167,8 +172,30 @@ 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*)));
+}
+
+void MainWindow::buildIndicatorButtonPanel()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_indicatorButtonPanel = new IndicatorButtonPanel(this);
+
+    connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
+        this, SIGNAL(autoCenteringTriggered(bool)));
+
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+            m_indicatorButtonPanel, SLOT(screenResized(QSize)));
+
+    connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
+            m_indicatorButtonPanel, SIGNAL(updateValues(qreal, qreal, bool)));
+
+    connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
+            this, SIGNAL(draggingModeTriggered()));
 }
 
 void MainWindow::buildInformationBox(const QString &message, bool modal)
@@ -228,13 +255,14 @@ void MainWindow::buildMap()
     buildOsmLicense();
     buildManualLocationCrosshair();
     buildFullScreenButton();
+    buildIndicatorButtonPanel();
     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)));
@@ -301,17 +329,14 @@ void MainWindow::buildUserInfoPanel()
     connect(this, SIGNAL(clearUpdateLocationDialogData()),
             m_userPanel, SIGNAL(clearUpdateLocationDialogData()));
 
-    connect(this, SIGNAL(messageSendingFailed(int)),
-            m_userPanel, SIGNAL(messageSendingFailed(int)));
-
     connect(m_mapView, SIGNAL(viewResized(QSize)),
             m_userPanel, SLOT(resizePanel(QSize)));
 
     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()));
@@ -372,6 +397,9 @@ void MainWindow::buildZoomButtonPanel()
 
     connect(m_mapView, SIGNAL(viewResized(QSize)),
             m_zoomButtonPanel, SLOT(screenResized(QSize)));
+
+    connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
+            this, SIGNAL(draggingModeTriggered()));
 }
 
 void MainWindow::clearCookieJar()
@@ -413,18 +441,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"));
 }
 
@@ -434,6 +461,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();
@@ -455,6 +483,10 @@ void MainWindow::dialogFinished(int status)
         } else {
             emit cancelLoginProcess();
         }
+    } else if(searchDialog) {
+        if(status != 0) {
+            emit searchForLocation(searchDialog->input());
+        }
     }
 
     dialog->deleteLater();
@@ -486,6 +518,8 @@ void MainWindow::drawFullScreenButton(const QSize &size)
 
 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();
@@ -507,7 +541,7 @@ void MainWindow::drawOwnLocationCrosshair(const QSize &size)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (m_drawOwnLocationCrosshair && m_ownLocationCrosshair != 0) {
+    if (m_ownLocationCrosshair != 0) {
         m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
                             size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
     }
@@ -600,7 +634,6 @@ void MainWindow::loadCookies()
 
         m_cookieJar->setAllCookies(cookieList);
         m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
-
     }
 }
 
@@ -689,7 +722,7 @@ void MainWindow::loginUsingCookies()
 
     buildWebView();
     loadCookies();
-    
+
     QStringList urlParts;
     urlParts.append(FACEBOOK_LOGINBASE);
     urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
@@ -770,22 +803,19 @@ void MainWindow::saveCookies()
     settings.setValue(COOKIES, list);
 }
 
-void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
+void MainWindow::setGPSButtonEnabled(bool enabled)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_autoCenteringAct->setChecked(enabled);
+    m_gpsToggleAct->setChecked(enabled);
 }
 
-void MainWindow::setGPSButtonEnabled(bool enabled)
+void MainWindow::setIndicatorButtonEnabled(bool enabled)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_gpsToggleAct->setChecked(enabled);
-
-    setOwnLocationCrosshairVisibility(!enabled);
+//    m_indicatorButton->setChecked(enabled);
 
-    m_autoCenteringAct->setVisible(enabled);
 }
 
 void MainWindow::setMapViewScene(QGraphicsScene *scene)
@@ -799,13 +829,11 @@ void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (visibility && m_loggedIn) {
+    if (visibility) {
         m_ownLocationCrosshair->show();
-        m_drawOwnLocationCrosshair = true;
         drawOwnLocationCrosshair(m_viewPortSize);
     } else {
         m_ownLocationCrosshair->hide();
-        m_drawOwnLocationCrosshair = false;
     }
 }
 
@@ -898,6 +926,14 @@ void MainWindow::showPanels()
     }
 }
 
+void MainWindow::startLocationSearch()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    SearchDialog *searchDialog = new SearchDialog();
+    queueDialog(searchDialog);
+}
+
 void MainWindow::startLoginProcess()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -937,26 +973,21 @@ void MainWindow::toggleProgressIndicator(bool value)
 void MainWindow::updateItemVisibility()
 {
     qDebug() << __PRETTY_FUNCTION__;
-    
-    if(m_loggedIn) {       
 
-        if(!m_gpsToggleAct->isChecked())
-            setOwnLocationCrosshairVisibility(true);
-    } else {
+    if(!m_loggedIn) {
         m_friendsListPanel->closePanel();
         m_friendsListPanel->hide();
         m_friendsListPanelSidebar->hide();
         m_userPanel->closePanel();
         m_userPanel->hide();
         m_userPanelSidebar->hide();
-        setOwnLocationCrosshairVisibility(false);
     }
 }
 
 const QString MainWindow::username()
 {
     qDebug() << __PRETTY_FUNCTION__;
-    
+
     return m_email;
 }
 
@@ -971,4 +1002,3 @@ void MainWindow::webViewRequestFinished(QNetworkReply *reply)
         emit error(ErrorContext::NETWORK, reply->error());
     }
 }
-