finalising this feature branch
authorVille Tiensuu <ville.tiensuu@ixonos.com>
Tue, 25 May 2010 12:12:29 +0000 (15:12 +0300)
committerVille Tiensuu <ville.tiensuu@ixonos.com>
Tue, 25 May 2010 12:12:29 +0000 (15:12 +0300)
src/engine/engine.cpp
src/engine/engine.h

index bff6d27..dd5ef99 100644 (file)
@@ -75,13 +75,13 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
             m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
 
+    initializeGpsAndAutocentering();
+
     // signals connected, now it's time to show the main window
     // but init the MapEngine before so starting location is set
     m_mapEngine->init();
     m_ui->show();
 
-    initializeGpsAndAutocentering();
-
     m_facebookAuthenticator->start();
 }
 
@@ -162,13 +162,15 @@ void SituareEngine::initializeGpsAndAutocentering()
     QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);     
 
     if (gpsEnabled.toString().isEmpty()) { // First start. Situare.conf file does not exists
+
+        connect(m_gps, SIGNAL(position(QPointF,qreal)),
+                this, SLOT(setFirstStartZoomLevel(QPointF,qreal)));
+
         changeAutoCenteringSetting(true);
         enableGPS(true);
 
         m_ui->showMaemoInformationBox(tr("GPS enabled"));
         m_ui->showMaemoInformationBox(tr("Auto centering enabled"));
-
-        m_mapEngine->setZoomLevel(DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE);
     }
 
     else { // Normal start
@@ -233,6 +235,18 @@ void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
         m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
 }
 
+void SituareEngine::setFirstStartZoomLevel(QPointF latLonCoordinate, qreal accuracy)
+{
+    Q_UNUSED(latLonCoordinate);
+    Q_UNUSED(accuracy);
+
+    if (m_autoCenteringEnabled) // autocentering is disabled when map is scrolled
+        m_mapEngine->setZoomLevel(DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE);
+
+    disconnect(m_gps, SIGNAL(position(QPointF,qreal)),
+               this, SLOT(setFirstStartZoomLevel(QPointF,qreal)));
+}
+
 void SituareEngine::signalsFromFacebookAuthenticator()
 {
     qDebug() << __PRETTY_FUNCTION__;
index 73aa802..a63da29 100644 (file)
@@ -27,6 +27,7 @@
 #define ENGINE_H
 
 #include <QObject>
+#include <QPointF>
 
 class QMainWindow;
 
@@ -124,7 +125,12 @@ public slots:
     void userDataChanged(User *user, QList<User *> &friendsList);
 
 private:
+    /**
+      * @brief Read settings and determine whether to use GPS and autocentering.
+      * When values does not found on the settings, GPS and autocentering are enabled as a default.
+      */
     void initializeGpsAndAutocentering();
+
     /**
       * @brief Connect signals coming from Facdebook authenticator
       */
@@ -155,7 +161,7 @@ private:
       */
     void signalsFromSituareService();
 
-private slots:
+private slots:    
     /**
       * @brief Set auto centering feature enabled / disabled
       */
@@ -182,6 +188,15 @@ private slots:
     */
     void enableGPS(bool enabled);
 
+    /**
+     * @brief Sets zoom level to default when first GPS location is received if autocentering
+     * is enabled.
+     *
+     * @param latLonCoordinate own location
+     * @param accuracy accuracy of GPS location
+     */
+    void setFirstStartZoomLevel(QPointF latLonCoordinate, qreal accuracy);
+
 /*******************************************************************************
  * SIGNALS
  ******************************************************************************/