Moving crosshair to show shifted map center point
authorSami Rämö <sami.ramo@ixonos.com>
Mon, 23 Aug 2010 13:22:31 +0000 (16:22 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Mon, 23 Aug 2010 13:22:31 +0000 (16:22 +0300)
 - Re-factored crosshair naming

 - Some alphabetising in MainWindow

src/engine/engine.cpp
src/map/mapview.cpp
src/map/mapview.h
src/ui/mainwindow.cpp
src/ui/mainwindow.h

index 7c2c77c..3df27a3 100644 (file)
@@ -502,7 +502,7 @@ void SituareEngine::setAutoCentering(bool enabled)
 
     m_ui->setIndicatorButtonEnabled(enabled);
     m_mapEngine->setAutoCentering(enabled);
-    m_ui->setOwnLocationCrosshairVisibility(!enabled);
+    m_ui->setCrosshairVisibility(!enabled);
 
     if (enabled) {
         setGPS(true);
index 400b878..8df461c 100644 (file)
@@ -275,6 +275,7 @@ void MapView::setViewShift(qreal viewShift)
     qDebug() << __PRETTY_FUNCTION__;
 
     m_centerHorizontalShiftViewPixels = viewShift;
+    emit horizontalShiftingChanged(m_centerHorizontalShiftViewPixels);
 
     updateCenterShift();
 }
index cc93931..91c9e36 100644 (file)
@@ -218,6 +218,13 @@ private:
  ******************************************************************************/
 signals:
     /**
+    * @brief Emitted when map center point shiftin is changed
+    *
+    * @param shifting New shifting value
+    */
+    void horizontalShiftingChanged(int shifting);
+
+    /**
     * @brief Signal for view resize events.
     *
     * Signal is emitted when view has been resized.
index c9e32e0..daa00c2 100644 (file)
@@ -65,8 +65,9 @@ MainWindow::MainWindow(QWidget *parent)
       m_errorShown(false),
       m_loggedIn(false),
       m_refresh(false),
+      m_mapCenterHorizontalShifting(0),
       m_progressIndicatorCount(0),
-      m_ownLocationCrosshair(0),
+      m_crosshair(0),
       m_email(), ///< @todo WTF?!?!?!?
       m_password(),
       m_webView(0),
@@ -93,8 +94,8 @@ MainWindow::MainWindow(QWidget *parent)
     if (m_fullScreenButton) {
         m_tabbedPanel->stackUnder(m_fullScreenButton);
     }
-    m_ownLocationCrosshair->stackUnder(m_tabbedPanel);
-    m_zoomButtonPanel->stackUnder(m_ownLocationCrosshair);
+    m_crosshair->stackUnder(m_tabbedPanel);
+    m_zoomButtonPanel->stackUnder(m_crosshair);
     m_indicatorButtonPanel->stackUnder(m_zoomButtonPanel);
     m_osmLicense->stackUnder(m_indicatorButtonPanel);
     m_mapScale->stackUnder(m_osmLicense);
@@ -140,21 +141,22 @@ void MainWindow::automaticUpdateDialogFinished(int result)
     m_automaticUpdateLocationDialog->deleteLater();
 }
 
-void MainWindow::buildFullScreenButton()
+void MainWindow::buildCrosshair()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-#ifdef Q_WS_MAEMO_5
-    m_fullScreenButton = new FullScreenButton(this);
+    m_crosshair = new QLabel(this);
+    QPixmap crosshairImage(":/res/images/sight.png");
+    m_crosshair->setPixmap(crosshairImage);
+    m_crosshair->setFixedSize(crosshairImage.size());
+    m_crosshair->hide();
+    m_crosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
 
-    if (m_fullScreenButton) {
-        connect(m_fullScreenButton, SIGNAL(clicked()),
-                this, SLOT(toggleFullScreen()));
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+            this, SLOT(moveCrosshair()));
 
-        connect(qApp, SIGNAL(showFullScreenButton()),
-                m_fullScreenButton, SLOT(invoke()));
-    }
-#endif // Q_WS_MAEMO_5
+    connect(m_mapView, SIGNAL(horizontalShiftingChanged(int)),
+            this, SLOT(mapCenterHorizontalShiftingChanged(int)));
 }
 
 void MainWindow::buildFriendListPanel()
@@ -179,6 +181,23 @@ void MainWindow::buildFriendListPanel()
             this, SIGNAL(routeTo(const GeoCoordinate&)));
 }
 
+void MainWindow::buildFullScreenButton()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+#ifdef Q_WS_MAEMO_5
+    m_fullScreenButton = new FullScreenButton(this);
+
+    if (m_fullScreenButton) {
+        connect(m_fullScreenButton, SIGNAL(clicked()),
+                this, SLOT(toggleFullScreen()));
+
+        connect(qApp, SIGNAL(showFullScreenButton()),
+                m_fullScreenButton, SLOT(invoke()));
+    }
+#endif // Q_WS_MAEMO_5
+}
+
 void MainWindow::buildIndicatorButtonPanel()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -230,21 +249,6 @@ void MainWindow::buildInformationBox(const QString &message, bool modal)
     queueDialog(msgBox);
 }
 
-void MainWindow::buildManualLocationCrosshair()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_ownLocationCrosshair = new QLabel(this);
-    QPixmap crosshairImage(":/res/images/sight.png");
-    m_ownLocationCrosshair->setPixmap(crosshairImage);
-    m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
-    m_ownLocationCrosshair->hide();
-    m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
-
-    connect(m_mapView, SIGNAL(viewResized(QSize)),
-            this, SLOT(drawOwnLocationCrosshair(QSize)));
-}
-
 void MainWindow::buildMap()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -253,7 +257,7 @@ void MainWindow::buildMap()
 
     buildZoomButtonPanel();
     buildOsmLicense();
-    buildManualLocationCrosshair();
+    buildCrosshair();
     buildFullScreenButton();
     buildIndicatorButtonPanel();
     buildMapScale();
@@ -578,16 +582,6 @@ void MainWindow::drawOsmLicense(const QSize &size)
                        size.height() - m_osmLicense->fontMetrics().height());
 }
 
-void MainWindow::drawOwnLocationCrosshair(const QSize &size)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if (m_ownLocationCrosshair != 0) {
-        m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
-                            size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
-    }
-}
-
 void MainWindow::errorDialogFinished(int status)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -777,32 +771,34 @@ void MainWindow::loginUsingCookies()
 
 }
 
-void MainWindow::openSettingsDialog()
+void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    m_mapCenterHorizontalShifting = shifting;
+    moveCrosshair();
+}
 
-    SettingsDialog *settingsDialog = new SettingsDialog(this);
-    settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
-    connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
+void MainWindow::moveCrosshair()
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
-    settingsDialog->show();
+    if (m_crosshair) {
+        int mapHeight = m_mapView->size().height();
+        int mapWidth = m_mapView->size().width();
+        m_crosshair->move(mapWidth / 2 - m_crosshair->pixmap()->width() / 2
+                          - m_mapCenterHorizontalShifting,
+                          mapHeight / 2 - m_crosshair->pixmap()->height() / 2);
+    }
 }
 
-void MainWindow::readAutomaticLocationUpdateSettings()
+void MainWindow::openSettingsDialog()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
-    bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
-    QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
-                                      .toTime();
+    SettingsDialog *settingsDialog = new SettingsDialog(this);
+    settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
+    connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
 
-    if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
-        QTime time;
-        emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
-    } else {
-        emit enableAutomaticLocationUpdate(false);
-    }
+    settingsDialog->show();
 }
 
 void MainWindow::queueDialog(QDialog *dialog)
@@ -823,6 +819,23 @@ void MainWindow::queueDialog(QDialog *dialog)
         showInformationBox();
 }
 
+void MainWindow::readAutomaticLocationUpdateSettings()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QSettings settings(DIRECTORY_NAME, FILE_NAME);
+    bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
+    QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
+                                      .toTime();
+
+    if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
+        QTime time;
+        emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
+    } else {
+        emit enableAutomaticLocationUpdate(false);
+    }
+}
+
 void MainWindow::saveCookies()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -844,6 +857,18 @@ void MainWindow::saveCookies()
     settings.setValue(COOKIES, list);
 }
 
+void MainWindow::setCrosshairVisibility(bool visibility)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (visibility) {
+        m_crosshair->show();
+        moveCrosshair();
+    } else {
+        m_crosshair->hide();
+    }
+}
+
 void MainWindow::setGPSButtonEnabled(bool enabled)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -865,18 +890,6 @@ void MainWindow::setMapViewScene(QGraphicsScene *scene)
     m_mapView->setScene(scene);
 }
 
-void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if (visibility) {
-        m_ownLocationCrosshair->show();
-        drawOwnLocationCrosshair(m_viewPortSize);
-    } else {
-        m_ownLocationCrosshair->hide();
-    }
-}
-
 void MainWindow::settingsDialogAccepted()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -912,16 +925,6 @@ void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
     m_automaticUpdateLocationDialog->show();
 }
 
-void MainWindow::toggleFullScreen()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if(windowState() == Qt::WindowNoState)
-        showFullScreen();
-    else
-        showNormal();
-}
-
 void MainWindow::showErrorInformationBox()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -990,6 +993,16 @@ void MainWindow::startLoginProcess()
     queueDialog(loginDialog);
 }
 
+void MainWindow::toggleFullScreen()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if(windowState() == Qt::WindowNoState)
+        showFullScreen();
+    else
+        showNormal();
+}
+
 void MainWindow::toggleProgressIndicator(bool value)
 {
     qDebug() << __PRETTY_FUNCTION__;
index 6644d58..64d5630 100644 (file)
@@ -188,7 +188,7 @@ public slots:
      *
      * @param visible
      */
-    void setOwnLocationCrosshairVisibility(bool visible);
+    void setCrosshairVisibility(bool visible);
 
     /**
      * @brief Sets username to member variable for login dialog
@@ -223,9 +223,9 @@ public slots:
 
 private:
     /**
-     * @brief Build fullscreen toggle button and connect slots
+     * @brief Build manual location setting cross hair and connect slots
      */
-    void buildFullScreenButton();
+    void buildCrosshair();
 
     /**
      * @brief Build friend list panel and connect slots
@@ -233,9 +233,9 @@ private:
     void buildFriendListPanel();
 
     /**
-     * @brief Build manual location setting cross hair and connect slots
+     * @brief Build fullscreen toggle button and connect slots
      */
-    void buildManualLocationCrosshair();
+    void buildFullScreenButton();
 
     /**
      * @brief Build map and connect slots
@@ -346,13 +346,6 @@ private slots:
     void drawOsmLicense(const QSize &size);
 
     /**
-     * @brief Slot for drawing the own location crosshair
-     *
-     * @param size Size of the screen
-     */
-    void drawOwnLocationCrosshair(const QSize &size);
-
-    /**
      * @brief Slot to intercept signal when error dialog/information note is processed
      *
      * @param status Status of the dialog
@@ -379,6 +372,18 @@ private slots:
     void loadDone(bool done);
 
     /**
+    * @brief Called when map center point horizontal shifting is changed
+    *
+    * @param shifting New shifting value
+    */
+    void mapCenterHorizontalShiftingChanged(int shifting);
+
+    /**
+     * @brief Move the crosshair
+     */
+    void moveCrosshair();
+
+    /**
      * @brief Slot to save cookies to settings
      */
     void saveCookies();
@@ -663,14 +668,15 @@ private:
     bool m_loggedIn;                        ///< Indicates login state
     bool m_refresh;                         ///< Indicates when webpage is refreshed
 
+    int m_mapCenterHorizontalShifting;      ///< Amount of map center point horizontal shifting
     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
 
     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
     QAction *m_loginAct;                    ///< Action to Login/Logout
     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
 
+    QLabel *m_crosshair;                    ///< Label for center point crosshair
     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
-    QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
 
     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
     QList<QDialog *> m_queue;               ///< QList type dialog queue