Merge branch 'master' of https://vcs.maemo.org/git/situare
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 9 Jun 2010 12:20:24 +0000 (15:20 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 9 Jun 2010 12:20:24 +0000 (15:20 +0300)
Conflicts:
doc/testing/functionality-tests.doc

23 files changed:
res/languages/situare_fi.ts
src/common.h
src/engine/engine.cpp
src/facebookservice/facebookauthentication.cpp
src/images.qrc [deleted file]
src/main.cpp
src/map/friendgroupitem.cpp
src/map/mapcommon.h
src/map/mapengine.cpp
src/map/mapengine.h
src/map/mapview.cpp
src/map/mapview.h
src/src.pro
src/ui/mainwindow.cpp
src/ui/mainwindow.h
src/ui/mapscale.cpp [new file with mode: 0644]
src/ui/mapscale.h [new file with mode: 0644]
src/ui/panelsidebar.cpp
src/ui/panelsidebar.h
src/ui/settingsdialog.cpp
src/ui/settingsdialog.h
src/ui/zoombutton.h
src/ui/zoombuttonpanel.h

index a1632f6..13307f8 100644 (file)
@@ -4,17 +4,31 @@
 <context>
     <name>FriendListPanel</name>
     <message>
-        <location filename="../../src/ui/friendlistpanel.cpp" line="34"/>
+        <location filename="../../src/ui/friendlistpanel.cpp" line="44"/>
         <source>Show all</source>
-        <translation type="unfinished">Näytä kaikki</translation>
+        <translation>Näytä kaikki</translation>
+    </message>
+    <message>
+        <location filename="../../src/ui/friendlistpanel.cpp" line="108"/>
+        <source>Selected: %1</source>
+        <translation>Valittu: %1</translation>
     </message>
 </context>
 <context>
     <name>GPSPositionPrivate</name>
     <message>
         <location filename="../../src/gps/gpspositionprivate.cpp" line="56"/>
+        <location filename="../../src/gps/gpspositionprivateliblocation.cpp" line="59"/>
         <source>Unable to use GPS</source>
-        <translation type="unfinished">GPS ei käytössä</translation>
+        <translation>GPS ei käytössä</translation>
+    </message>
+</context>
+<context>
+    <name>LiblocationWrapper</name>
+    <message>
+        <location filename="../../src/gps/liblocationwrapper.cpp" line="105"/>
+        <source>Error in GPS</source>
+        <translation>GPS virhe</translation>
     </message>
 </context>
 <context>
@@ -22,7 +36,7 @@
     <message>
         <location filename="../../src/ui/logindialog.cpp" line="32"/>
         <source>Login to Situare with Facebook account</source>
-        <translation type="unfinished">Kirjaudu Situareen Facebook tunnuksilla</translation>
+        <translation>Kirjaudu Situareen Facebook tunnuksilla</translation>
     </message>
     <message>
         <source>Connect</source>
     <message>
         <location filename="../../src/ui/logindialog.cpp" line="42"/>
         <source>Login</source>
-        <translation type="unfinished">Kirjaudu</translation>
+        <translation>Kirjaudu</translation>
     </message>
     <message>
         <location filename="../../src/ui/logindialog.cpp" line="45"/>
         <source>E-mail:</source>
-        <translation type="unfinished">Sähköposti:</translation>
+        <translation>Sähköposti:</translation>
     </message>
     <message>
         <location filename="../../src/ui/logindialog.cpp" line="46"/>
         <source>Password:</source>
-        <translation type="unfinished">Salasana:</translation>
+        <translation>Salasana:</translation>
     </message>
 </context>
 <context>
     <name>MainWindow</name>
     <message>
-        <location filename="../../src/ui/mainwindow.cpp" line="84"/>
-        <location filename="../../src/ui/mainwindow.cpp" line="647"/>
+        <location filename="../../src/ui/mainwindow.cpp" line="88"/>
         <source>Situare</source>
-        <translation type="unfinished">Situare</translation>
+        <translation>Situare</translation>
     </message>
     <message>
-        <location filename="../../src/ui/mainwindow.cpp" line="310"/>
-        <location filename="../../src/ui/mainwindow.cpp" line="504"/>
+        <location filename="../../src/ui/mainwindow.cpp" line="375"/>
+        <location filename="../../src/ui/mainwindow.cpp" line="634"/>
         <source>Login</source>
-        <translation type="unfinished">Kirjaudu</translation>
+        <translation>Kirjaudu</translation>
     </message>
     <message>
-        <location filename="../../src/ui/mainwindow.cpp" line="315"/>
+        <location filename="../../src/ui/mainwindow.cpp" line="380"/>
         <source>Settings</source>
-        <translation type="unfinished">Asetukset</translation>
+        <translation>Asetukset</translation>
     </message>
     <message>
-        <location filename="../../src/ui/mainwindow.cpp" line="320"/>
+        <location filename="../../src/ui/mainwindow.cpp" line="385"/>
         <source>GPS</source>
-        <translation type="unfinished">GPS</translation>
+        <translation>GPS</translation>
     </message>
     <message>
-        <location filename="../../src/ui/mainwindow.cpp" line="327"/>
+        <location filename="../../src/ui/mainwindow.cpp" line="392"/>
         <source>Auto centering</source>
-        <translation type="unfinished">Automaattinen keskitys</translation>
+        <translation>Automaattinen keskitys</translation>
     </message>
     <message>
-        <location filename="../../src/ui/mainwindow.cpp" line="333"/>
+        <location filename="../../src/ui/mainwindow.cpp" line="398"/>
         <source>Main</source>
-        <translation type="unfinished">Päävalikko</translation>
+        <translation>Päävalikko</translation>
     </message>
     <message>
-        <location filename="../../src/ui/mainwindow.cpp" line="338"/>
+        <location filename="../../src/ui/mainwindow.cpp" line="403"/>
         <source>Menu</source>
-        <translation type="unfinished">Valikko</translation>
+        <translation>Valikko</translation>
     </message>
     <message>
-        <location filename="../../src/ui/mainwindow.cpp" line="375"/>
+        <location filename="../../src/ui/mainwindow.cpp" line="506"/>
         <source>GPS timeout</source>
-        <translation type="unfinished"></translation>
+        <translation>GPS pyyntö aikakatkaistiin</translation>
     </message>
     <message>
-        <location filename="../../src/ui/mainwindow.cpp" line="497"/>
+        <location filename="../../src/ui/mainwindow.cpp" line="628"/>
         <source>Logout</source>
-        <translation type="unfinished">Kirjaudu ulos</translation>
+        <translation>Kirjaudu ulos</translation>
     </message>
 </context>
 <context>
     <message>
         <location filename="../../src/ui/settingsdialog.cpp" line="44"/>
         <source>Settings</source>
-        <translation type="unfinished">Asetukset</translation>
+        <translation>Asetukset</translation>
     </message>
     <message>
         <location filename="../../src/ui/settingsdialog.cpp" line="50"/>
         <source>Use automatic location update</source>
-        <translation type="unfinished">Sijainnin automaattinen päivitys</translation>
+        <translation>Sijainnin automaattinen päivitys</translation>
     </message>
     <message>
         <location filename="../../src/ui/settingsdialog.cpp" line="57"/>
         <location filename="../../src/ui/settingsdialog.cpp" line="89"/>
         <source>Update interval</source>
-        <translation type="unfinished">Päivitysväli</translation>
+        <translation>Päivitysväli</translation>
     </message>
     <message>
         <location filename="../../src/ui/settingsdialog.cpp" line="138"/>
         <source>%1 min</source>
-        <translation type="unfinished">%1 min</translation>
+        <translation>%1 min</translation>
     </message>
 </context>
 <context>
     <message>
         <location filename="../../src/engine/engine.cpp" line="136"/>
         <source>Auto centering disabled</source>
-        <translation type="unfinished">Automaattinen keskitys pois päältä</translation>
+        <translation>Automaattinen keskitys pois päältä</translation>
     </message>
     <message>
-        <location filename="../../src/engine/engine.cpp" line="219"/>
-        <location filename="../../src/engine/engine.cpp" line="226"/>
+        <location filename="../../src/engine/engine.cpp" line="220"/>
+        <location filename="../../src/engine/engine.cpp" line="228"/>
         <source>GPS enabled</source>
-        <translation type="unfinished">GPS päällä</translation>
+        <translation>GPS päällä</translation>
     </message>
     <message>
-        <location filename="../../src/engine/engine.cpp" line="220"/>
-        <location filename="../../src/engine/engine.cpp" line="229"/>
+        <location filename="../../src/engine/engine.cpp" line="221"/>
+        <location filename="../../src/engine/engine.cpp" line="231"/>
         <source>Auto centering enabled</source>
-        <translation type="unfinished">Automaattinen keskitys päällä</translation>
+        <translation>Automaattinen keskitys päällä</translation>
     </message>
 </context>
 <context>
     <name>UpdateLocationDialog</name>
     <message>
-        <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="30"/>
+        <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="31"/>
         <source>Update Location</source>
-        <translation type="unfinished">Päivitä sijainti</translation>
+        <translation>Päivitä sijainti</translation>
     </message>
     <message>
-        <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="39"/>
+        <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="43"/>
         <source>Publish on Facebook</source>
-        <translation type="unfinished">Julkaise Facebookissa</translation>
+        <translation>Julkaise Facebookissa</translation>
     </message>
     <message>
-        <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="44"/>
+        <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="49"/>
         <source>Send</source>
-        <translation type="unfinished">Lähetä</translation>
+        <translation>Lähetä</translation>
     </message>
     <message>
-        <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="47"/>
+        <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="52"/>
         <source>Location:</source>
-        <translation type="unfinished">Sijainti:</translation>
+        <translation>Sijainti:</translation>
     </message>
     <message>
-        <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="48"/>
+        <location filename="../../src/ui/updatelocation/updatelocationdialog.cpp" line="53"/>
         <source>Message:</source>
-        <translation type="unfinished">Viesti:</translation>
+        <translation>Viesti:</translation>
+    </message>
+</context>
+<context>
+    <name>UserInfo</name>
+    <message>
+        <location filename="../../src/ui/userinfo.cpp" line="342"/>
+        <source>Location update failed
+
+Your message is saved to textbox until sending will succeed</source>
+        <translatorcomment>Do \n&apos;s work properly?</translatorcomment>
+        <translation>Sijainnin päivitys epäonnistui\n\nVistisi on tallennettu kunnes pävitys on onnistunut</translation>
     </message>
 </context>
 </TS>
index 26fbb04..66d3b47 100644 (file)
@@ -33,6 +33,8 @@ const QString FILE_NAME = "Situare";
 // QSettings common values
 const QString COOKIES = "cookies";
 const QString EMPTY = "";
+const QString SETTINGS_AUTOMATIC_UPDATE_ENABLED = "SETTINGS_AUTOMATIC_UPDATE_ENABLED";
+const QString SETTINGS_AUTOMATIC_UPDATE_INTERVAL = "SETTINGS_AUTOMATIC_UPDATE_INTERVAL";
 
 const QColor COLOR_GRAY = QColor(152, 152, 152);                           ///< Gray color
 const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal);    ///< Normal font
index 5adbcaf..0b749bf 100644 (file)
@@ -180,32 +180,28 @@ void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateInterv
 
     m_automaticUpdateEnabled = enabled;
 
+    //Show automatic update confirmation dialog
     if (m_automaticUpdateFirstStart && m_gps->isRunning() && m_automaticUpdateEnabled) {
-        accepted = m_ui->showEnableAutomaticUpdateLocationDialog(
+        m_ui->showEnableAutomaticUpdateLocationDialog(
                 tr("Do you want to enable automatic location update with %1 min update interval?")
                 .arg(updateIntervalMsecs/1000/60));
         m_automaticUpdateFirstStart = false;
-        m_ui->automaticLocationUpdateEnabled(accepted);
-
-        if (accepted && !m_gps->isRunning()) {
-            enableGPS(true);
-            m_ui->buildInformationBox(tr("GPS enabled"));
-        }
     }
+    else {
+        if (!m_automaticUpdateFirstStart && m_automaticUpdateEnabled && accepted)
+            m_ui->buildInformationBox(tr("Automatic location update enabled"));
 
-    if (!m_automaticUpdateFirstStart && m_automaticUpdateEnabled && accepted)
-        m_ui->buildInformationBox(tr("Automatic location update enabled"));
-
-    if (accepted && m_gps->isRunning() && m_automaticUpdateEnabled) {
-        if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
-            m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
-        else
-            m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
+        if (accepted && m_gps->isRunning() && m_automaticUpdateEnabled) {
+            if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
+                m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
+            else
+                m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
 
-        m_automaticUpdateIntervalTimer->start();
+            m_automaticUpdateIntervalTimer->start();
 
-    } else {
-        m_automaticUpdateIntervalTimer->stop();
+        } else {
+            m_automaticUpdateIntervalTimer->stop();
+        }
     }
 }
 
@@ -283,7 +279,7 @@ void SituareEngine::loginActionPressed()
 
 void SituareEngine::loginOk()
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qWarning() << __PRETTY_FUNCTION__;
 
     m_loggedIn = true;
     m_ui->loggedIn(m_loggedIn);
@@ -506,6 +502,9 @@ void SituareEngine::signalsFromMapEngine()
 
     connect(m_mapEngine, SIGNAL(locationItemClicked(QList<QString>)),
             m_ui, SIGNAL(locationItemClicked(QList<QString>)));
+
+    connect(m_mapEngine, SIGNAL(newMapResolution(qreal)),
+            m_ui, SIGNAL(newMapResolution(qreal)));
 }
 
 void SituareEngine::signalsFromSituareService()
index 9501944..f529bd5 100644 (file)
@@ -51,8 +51,11 @@ void FacebookAuthentication::clearAccountInformation(bool keepUsername)
     m_loginCredentials.clearCredentials();
     QSettings settings(DIRECTORY_NAME, FILE_NAME);
 
-    if(!keepUsername)
+    if(!keepUsername) {
         settings.remove(USERNAME);
+        settings.remove(SETTINGS_AUTOMATIC_UPDATE_ENABLED);
+        settings.remove(SETTINGS_AUTOMATIC_UPDATE_INTERVAL);
+    }
 
     settings.remove(COOKIES);
 }
diff --git a/src/images.qrc b/src/images.qrc
deleted file mode 100644 (file)
index 8059edc..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-<RCC>
-    <qresource prefix="/">
-        <file>resources/arrow_left.png</file>
-        <file>resources/arrow_right.png</file>
-        <file>resources/bkg_grid.png</file>
-        <file>resources/led_red_g.png</file>
-        <file>resources/led_red_h.png</file>
-        <file>resources/led_red_s.png</file>
-        <file>resources/list_item.png</file>
-        <file>resources/side_bar_left.png</file>
-        <file>resources/side_bar_right.png</file>
-        <file>resources/sliding_bar_left.png</file>
-        <file>resources/sliding_bar_right.png</file>
-        <file>resources/zoom_in.png</file>
-        <file>resources/zoom_out.png</file>
-        <file>resources/clock.png</file>
-        <file>resources/compass.png</file>
-        <file>resources/envelope.png</file>
-        <file>resources/profile_pic_border.png</file>
-        <file>resources/send_position.png</file>
-        <file>resources/personal_info_bckgrnd.png</file>
-        <file>resources/refresh.png</file>
-    </qresource>
-</RCC>
index 3ec7c56..ae229df 100644 (file)
@@ -29,12 +29,11 @@ int main(int argc, char *argv[])
 {
     QApplication a(argc, argv);
 
-    QTranslator translator;
-    bool loaded = translator.load(":/res/languages/situare_" + QLocale::system().name());
-    a.installTranslator(&translator);
-
-    QString locale = QLocale::system().name();
-    qDebug() << "Localization" << locale << "loaded:" << loaded;
+//    QTranslator translator;
+//    bool loaded = translator.load(":/res/languages/situare_" + QLocale::system().name());
+//    a.installTranslator(&translator);
+//    QString locale = QLocale::system().name();
+//    qDebug() << "Localization" << locale << "loaded:" << loaded;
 
     SituareEngine engine;
     int appRet = a.exec();
index 4611bca..e7acab4 100644 (file)
@@ -127,6 +127,8 @@ void FriendGroupItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
 
 void FriendGroupItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
 {
+    Q_UNUSED(event);
+
     qDebug() << __PRETTY_FUNCTION__;
 
     if (m_clickEvent) {
index 65ed145..2a2f070 100644 (file)
@@ -73,6 +73,8 @@ const int DEFAULT_ZOOM_LEVEL = 14;       ///< Default zoom level
 const qreal DEFAULT_LONGITUDE = 0.0000;  ///< Default longitude value
 const qreal DEFAULT_LATITUDE = 0.0000; ///< Default latitude value
 
+const qreal EARTH_RADIUS = 6371.01;         ///< Earth radius in km
+
 const int GRID_PADDING = 1;  ///< Grid padding used in tile grid calculation
 
 const QString OSM_LICENSE = QString::fromUtf8("© OpenStreetMap contributors, CC-BY-SA");
index ea55393..140e250 100644 (file)
@@ -278,6 +278,21 @@ bool MapEngine::isCenterTileChanged(QPoint sceneCoordinate)
     return (centerTile != temp);
 }
 
+qreal MapEngine::sceneResolution()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    const int SHIFT = 200;
+    const int KM_TO_M = 1000;
+    qreal scale = (1 << (MAX_MAP_ZOOM_LEVEL - m_zoomLevel));
+    QPointF centerCoordinate = centerGeoCoordinate();
+    QPoint shiftedSceneCoordinate = QPoint(m_sceneCoordinate.x() + SHIFT*scale
+                                           , m_sceneCoordinate.y());
+    QPointF shiftedCoordinate = convertSceneCoordinateToLatLon(m_zoomLevel, shiftedSceneCoordinate);
+    qreal dist = greatCircleDistance(centerCoordinate, shiftedCoordinate) * KM_TO_M;
+    return (dist / SHIFT);
+}
+
 void MapEngine::mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -296,6 +311,21 @@ void MapEngine::mapImageReceived(int zoomLevel, int x, int y, const QPixmap &ima
    }
 }
 
+qreal MapEngine::greatCircleDistance(QPointF firstLocation, QPointF secondLocation)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    const qreal TORAD = (M_PI/180);
+
+    qreal dLat = (secondLocation.y() - firstLocation.y())*TORAD;
+    qreal dLon = (secondLocation.x() - firstLocation.x())*TORAD;
+    qreal a = pow(sin(dLat/2),2) + cos(firstLocation.y()*TORAD) * cos(secondLocation.y()*TORAD)
+              * pow(sin(dLon/2),2);
+    qreal c = 2 * atan2(sqrt(a), sqrt(1-a));
+
+    return (EARTH_RADIUS * c);
+}
+
 void MapEngine::receiveOwnLocation(User *user)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -345,6 +375,8 @@ void MapEngine::setLocation(QPoint sceneCoordinate)
         getTiles(sceneCoordinate);
         m_mapScene->removeOutOfViewTiles();
     }
+
+    emit newMapResolution(sceneResolution());
 }
 
 void MapEngine::setZoomLevel(int newZoomLevel)
@@ -424,6 +456,8 @@ void MapEngine::viewZoomFinished()
         emit maxZoomLevelReached();
     else if (m_zoomLevel == MIN_VIEW_ZOOM_LEVEL)
         emit minZoomLevelReached();
+
+    emit newMapResolution(sceneResolution());
 }
 
 void MapEngine::zoomIn()
index 034ed0b..94681a7 100644 (file)
@@ -112,6 +112,18 @@ public:
     static QPoint convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber);
 
     /**
+     * @brief Calculate great-circle distance between two geographic coordinates
+     *
+     * Calculate great-circle distance between two given geographic locations using
+     * haversine formula
+     *
+     * @param firstLocation Coordinates of the first location
+     * @param secondLocation Coordinates of the second location
+     * @return qreal Distance in kilometers
+     */
+    qreal greatCircleDistance(QPointF firstLocation, QPointF secondLocation);
+
+    /**
     * @brief MapEngine initializer
     *
     * Set initial location and zoom level for the engine. locationChanged and
@@ -145,6 +157,7 @@ public:
     static QString tilePath(int zoomLevel, int x, int y);
 
 public slots:
+
     /**
     * @brief Slot to catch user own location data
     *
@@ -235,6 +248,13 @@ private:
     bool isCenterTileChanged(QPoint sceneCoordinate);
 
     /**
+     * @brief Calculate scale at the map center of the map in meters/pixel
+     *
+     * @return qreal Scale of the map in meters/pixel
+     */
+    qreal sceneResolution();
+
+    /**
     * @brief Calculate maximum value for tile in this zoom level.
     *
     * @param zoomLevel zoom level
@@ -347,6 +367,11 @@ signals:
     void minZoomLevelReached();
 
     /**
+     * @brief Signal to pass the scale of the map to map scale
+     */
+    void newMapResolution(qreal scale);
+
+    /**
     * @brief Request view changing zoom level
     *
     * @param newZoomLevel New zoom level
index 37f8b81..1accc7f 100644 (file)
@@ -74,7 +74,6 @@ void MapView::resizeEvent(QResizeEvent *event)
     qDebug() << __PRETTY_FUNCTION__ << "Resize:" << event->size();
 
     emit viewResized(event->size());
-    emit viewResizedNewSize(viewport()->width(), viewport()->height());
 }
 
 void MapView::setViewScale(qreal viewScale)
index 786107e..855a3f7 100644 (file)
@@ -128,15 +128,6 @@ signals:
     void viewResized(const QSize &size);
 
     /**
-    * @brief Signal for drawing OSM license
-    *
-    * Signal is emitted when view is resized.
-    * @param width Viewport width
-    * @param height Viewport height
-    */
-    void viewResizedNewSize(int width, int height);
-
-    /**
     * @brief Signal for view scroll events
     *
     * Signal is emitted when view is scrolled.
index e560eb4..ca2a88d 100644 (file)
@@ -48,7 +48,8 @@ SOURCES += main.cpp \
     network/networkaccessmanager.cpp \
     network/networkhandler.cpp \
     network/networkcookiejar.cpp \
-    network/networkreply.cpp
+    network/networkreply.cpp \
+    ui/mapscale.cpp
 HEADERS += ui/mainwindow.h \
     map/mapengine.h \
     map/mapview.h \
@@ -94,7 +95,8 @@ HEADERS += ui/mainwindow.h \
     network/networkaccessmanager.h \
     network/networkhandler.h \
     network/networkcookiejar.h \
-    network/networkreply.h
+    network/networkreply.h \
+    ui/mapscale.h
 QT += network \
     webkit
 
index 16caf20..567c362 100644 (file)
@@ -35,6 +35,7 @@
 #include "settingsdialog.h"
 #include "userinfopanel.h"
 #include "zoombuttonpanel.h"
+#include "mapscale.h"
 
 #include "mainwindow.h"
 
@@ -61,6 +62,7 @@ MainWindow::MainWindow(QWidget *parent)
     m_password(),
     m_fullScreenButton(0),
     m_webView(0),
+    m_mapScale(0),
     m_cookieJar(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -90,10 +92,12 @@ MainWindow::MainWindow(QWidget *parent)
     if(m_fullScreenButton) {
         m_fullScreenButton->stackUnder(m_zoomButtonPanel);
         m_osmLicense->stackUnder(m_fullScreenButton);
-    } else
+    } else {
         m_osmLicense->stackUnder(m_zoomButtonPanel);
+    }
     m_ownLocationCrosshair->stackUnder(m_osmLicense);
-    m_mapView->stackUnder(m_ownLocationCrosshair);
+    m_mapScale->stackUnder(m_ownLocationCrosshair);
+    m_mapView->stackUnder(m_mapScale);
 
     this->toggleProgressIndicator(true);
 
@@ -119,9 +123,18 @@ MainWindow::~MainWindow()
     m_error_queue.clear();
 }
 
-void MainWindow::automaticLocationUpdateEnabled(bool enabled)
+void MainWindow::automaticUpdateDialogFinished(int result)
 {
-    m_settingsDialog->setAutomaticLocationUpdateSettings(enabled);
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (result == QMessageBox::Yes) {
+        m_settingsDialog->setAutomaticLocationUpdateSettings(true);
+        m_settingsDialog->emitAutomaticLocationUpdateSettings();
+    }
+    else {
+        m_settingsDialog->setAutomaticLocationUpdateSettings(false);
+        m_settingsDialog->emitAutomaticLocationUpdateSettings();
+    }
 }
 
 void MainWindow::buildFullScreenButton()
@@ -158,8 +171,8 @@ void MainWindow::buildFriendListPanel()
     connect(this, SIGNAL(locationItemClicked(QList<QString>)),
             m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
 
-    connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
-            m_friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+            m_friendsListPanelSidebar, SLOT(reDrawSidebar(QSize)));
 }
 
 void MainWindow::buildInformationBox(const QString &message, bool modal)
@@ -199,8 +212,8 @@ void MainWindow::buildManualLocationCrosshair()
     m_ownLocationCrosshair->hide();
     m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
 
-    connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
-            this, SLOT(drawOwnLocationCrosshair(int, int)));
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+            this, SLOT(drawOwnLocationCrosshair(QSize)));
 }
 
 void MainWindow::buildMap()
@@ -213,6 +226,7 @@ void MainWindow::buildMap()
     buildOsmLicense();
     buildManualLocationCrosshair();
     buildFullScreenButton();
+    buildMapScale();
 
     connect(m_mapView, SIGNAL(viewScrolled(QPoint)),
             this, SIGNAL(mapViewScrolled(QPoint)));
@@ -226,8 +240,11 @@ void MainWindow::buildMap()
     connect(m_mapView, SIGNAL(viewResized(QSize)),
             this, SLOT(drawFullScreenButton(QSize)));
 
-    connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
-             this, SLOT(setViewPortSize(int, int)));
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+            this, SLOT(drawMapScale(QSize)));
+
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+             this, SLOT(setViewPortSize(QSize)));
 
     connect(this, SIGNAL(zoomLevelChanged(int)),
             m_mapView, SLOT(setZoomLevel(int)));
@@ -236,6 +253,13 @@ void MainWindow::buildMap()
             this, SIGNAL(viewZoomFinished()));
 }
 
+void MainWindow::buildMapScale()
+{
+    m_mapScale = new MapScale(this);
+    connect(this, SIGNAL(newMapResolution(qreal)),
+            m_mapScale, SLOT(updateMapResolution(qreal)));
+}
+
 void MainWindow::buildOsmLicense()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -444,6 +468,16 @@ void MainWindow::drawFullScreenButton(const QSize &size)
     }
 }
 
+void MainWindow::drawMapScale(const QSize &size)
+{
+    const int LEFT_SCALE_MARGIN = 10;
+    const int BOTTOM_SCALE_MARGIN = 2;
+    qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
+
+    m_mapScale->move(PANEL_PEEK_AMOUNT + LEFT_SCALE_MARGIN,
+                     size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
+}
+
 void MainWindow::drawOsmLicense(const QSize &size)
 {
     qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
@@ -453,13 +487,13 @@ void MainWindow::drawOsmLicense(const QSize &size)
                        size.height() - m_osmLicense->fontMetrics().height());
 }
 
-void MainWindow::drawOwnLocationCrosshair(int width, int height)
+void MainWindow::drawOwnLocationCrosshair(const QSize &size)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     if (m_drawOwnLocationCrosshair && m_ownLocationCrosshair != 0) {
-        m_ownLocationCrosshair->move(width/2 - m_ownLocationCrosshair->pixmap()->width()/2,
-                            height/2 - m_ownLocationCrosshair->pixmap()->height()/2);
+        m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
+                            size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
     }
 }
 
@@ -652,6 +686,7 @@ void MainWindow::openSettingsDialog()
     qDebug() << __PRETTY_FUNCTION__;
 
     m_settingsDialog->enableSituareSettings(m_gpsToggleAct->isChecked() && m_loggedIn);
+    m_settingsDialog->readSettings();
     m_settingsDialog->show();
 }
 
@@ -734,7 +769,7 @@ void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
     if (visibility) {
         m_ownLocationCrosshair->show();
         m_drawOwnLocationCrosshair = true;
-        drawOwnLocationCrosshair(m_viewPortWidth, m_viewPortHeight);
+        drawOwnLocationCrosshair(QSize(m_viewPortWidth, m_viewPortHeight));
     } else {
         m_ownLocationCrosshair->hide();
         m_drawOwnLocationCrosshair = false;
@@ -748,24 +783,23 @@ void MainWindow::setUsername(const QString &username)
     m_email = username;
 }
 
-void MainWindow::setViewPortSize(int width, int height)
+void MainWindow::setViewPortSize(const QSize &size)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_viewPortWidth = width;
-    m_viewPortHeight = height;
+    m_viewPortWidth = size.width();
+    m_viewPortHeight = size.height();
 }
 
 bool MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
 {
-    QMessageBox msgBox(QMessageBox::Question, tr("Automatic location update"), text,
-                       QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, 0);
-    int returnValue = msgBox.exec();
-    qWarning() << __PRETTY_FUNCTION__ << returnValue;
-    if (returnValue == QMessageBox::Yes)
-        return true;
-    else
-        return false;
+    m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
+                                                      tr("Automatic location update"), text,
+                                                      QMessageBox::Yes | QMessageBox::No |
+                                                      QMessageBox::Cancel, this);
+    connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
+            this, SLOT(automaticUpdateDialogFinished(int)));
+    m_automaticUpdateLocationDialog->show();
 }
 
 void MainWindow::toggleFullScreen()
index dde8be0..2839b8e 100644 (file)
@@ -37,6 +37,7 @@ class QNetworkReply;
 
 class FacebookAuthentication;
 class FriendListPanel;
+class MapScale;
 class MapScene;
 class MapView;
 class SituareService;
@@ -45,6 +46,7 @@ class UserInfoPanel;
 class ZoomButtonPanel;
 class SettingsDialog;
 class QToolButton;
+class QMessageBox;
 
 /**
 * @brief Main Window Class
@@ -81,13 +83,6 @@ private:
  ******************************************************************************/
 public:
     /**
-    * @brief Sets automatic location update enabled from settings dialog.
-    *
-    * @param enabled true if enabled, false otherwise
-    */
-    void automaticLocationUpdateEnabled(bool enabled);
-
-    /**
     * @brief Builds information box with message.
     *
     * @param message Information message
@@ -220,6 +215,11 @@ private:
     void buildMap();
 
     /**
+     * @brief Build map scale and connect slots
+     */
+    void buildMapScale();
+
+    /**
       * @brief Build OSM license and connect slots
       */
     void buildOsmLicense();
@@ -281,6 +281,13 @@ private:
 
 private slots:
     /**
+    * @brief Slot for automatic update dialog finished.
+    *
+    * @result result code
+    */
+    void automaticUpdateDialogFinished(int result);
+
+    /**
     * @brief Slot to intercept signal when dialog/information note is processed
     *
     * @param status Status of the dialog
@@ -295,6 +302,13 @@ private slots:
     void drawFullScreenButton(const QSize &size);
 
     /**
+    * @brief Slot for drawing the map distance scale
+    *
+    * @param size Size of the screen
+    */
+    void drawMapScale(const QSize &size);
+
+    /**
     * @brief Slot for drawing the Open Street Map license text
     *
     * @param size Size of the screen
@@ -304,10 +318,9 @@ private slots:
     /**
     * @brief Slot for drawing the own location crosshair
     *
-    * @param width Width of the viewport
-    * @param height Height of the viewport
+    * @param size Size of the screen
     */
-    void drawOwnLocationCrosshair(int width, int height);
+    void drawOwnLocationCrosshair(const QSize &size);
 
     /**
     * @brief Slot to intercept signal when error dialog/information note is processed
@@ -345,10 +358,9 @@ private slots:
     /**
     * @brief Set correnct view port size to datamembers
     *
-    * @param width Width of the viewport
-    * @param height Height of the viewport
+    * @param size Size of the screen
     */
-    void setViewPortSize(const int width, const int height);
+    void setViewPortSize(const QSize &size);
 
     /**
     * @brief Toggle between fullscreen and normal window mode
@@ -480,6 +492,11 @@ signals:
     void notificateUpdateFailing(const QString &message);
 
     /**
+     * @brief Forwarding signal from MapEngine to MapScale
+     */
+    void newMapResolution(qreal scale);
+
+    /**
     * @brief Signal for refreshing user data.
     *
     */
@@ -586,6 +603,7 @@ private:
     QWebView *m_webView;                    ///< Shows facebook login page
 
     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
+    MapScale *m_mapScale;                   ///< Instance of the map scale
     MapView *m_mapView;                     ///< Instance of the map view
     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
     PanelSideBar *m_userPanelSidebar;       ///< User panel side bar
@@ -595,6 +613,7 @@ private:
 
     SettingsDialog *m_settingsDialog;       ///< Settings dialog
 
+    QMessageBox *m_automaticUpdateLocationDialog;
 };
 
 #endif // MAINWINDOW_H
diff --git a/src/ui/mapscale.cpp b/src/ui/mapscale.cpp
new file mode 100644 (file)
index 0000000..1ea485a
--- /dev/null
@@ -0,0 +1,150 @@
+ /*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Kaj Wallin - kaj.wallin@ixonos.com
+
+    Situare is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    version 2 as published by the Free Software Foundation.
+
+    Situare is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Situare; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+    USA.
+ */
+
+#include <QPainter>
+#include <QPen>
+#include <QLine>
+#include <QDebug>
+#include "mapscale.h"
+#include <math.h>
+
+const int TARGET_WIDTH = 140;                   ///< Target width of the scale in pixels
+const qreal M_TO_FT = 3.2808399;                ///< Meter to feet conversion value
+const qreal FT_TO_MI = 5280;                    ///< Feet to mile conversion
+const qreal M_TO_KM = 1000;                     ///< Meters to kilometers conversion
+const int MAPSCALE_HEIGHT = 31;                 ///< Height of the the map scale
+const int CENTERLINE_Y = MAPSCALE_HEIGHT / 2;   ///< Y position of the centerline
+const int MAPSCALE_STOP_HEIGHT = 7;             ///< Height of each perpendicular stop on the scale
+const int SCALE_TEXT_X = 3;                     ///< X coordinate for the scale texts
+
+MapScale::MapScale(QWidget *parent) :
+    QWidget(parent),
+    m_centerLineImperial(0),
+    m_centerLineMetric(0),
+    m_imperialText(""),
+    m_metricText("")
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+//    updateMapScale(10.0);
+    setAttribute(Qt::WA_TransparentForMouseEvents, true);
+}
+
+void MapScale::paintEvent(QPaintEvent *event)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    Q_UNUSED(event);
+
+    resize(ceil(fmax(m_centerLineMetric,m_centerLineImperial)) + 1, MAPSCALE_HEIGHT);
+
+    QLineF centerLine(0, CENTERLINE_Y, fmax(m_centerLineMetric, m_centerLineImperial), CENTERLINE_Y);
+    QLineF startKm(1, CENTERLINE_Y, 1, CENTERLINE_Y - MAPSCALE_STOP_HEIGHT);
+    QLineF stopKm(m_centerLineMetric, CENTERLINE_Y,
+                  m_centerLineMetric, CENTERLINE_Y - MAPSCALE_STOP_HEIGHT);
+
+    QLineF startMi(1, CENTERLINE_Y, 1, CENTERLINE_Y + MAPSCALE_STOP_HEIGHT);
+    QLineF stopMi(m_centerLineImperial, CENTERLINE_Y,
+                  m_centerLineImperial, CENTERLINE_Y + MAPSCALE_STOP_HEIGHT);
+
+    QPainter painter(this);
+    QPen pen(Qt::black, 2);
+
+    painter.setFont(QFont("Nokia Sans", 13, QFont::Normal));
+    painter.setPen(pen);
+    painter.drawLine(centerLine);
+    painter.drawLine(startKm);
+    painter.drawLine(stopKm);
+    painter.drawText(SCALE_TEXT_X, MAPSCALE_HEIGHT / 2 - 2, m_metricText);
+
+    painter.drawLine(startMi);
+    painter.drawLine(stopMi);
+    painter.drawText(SCALE_TEXT_X, MAPSCALE_HEIGHT, m_imperialText);
+}
+
+qreal MapScale::roundToBaseScale(qreal value)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    int scale = 0;
+    qreal baseLine;
+    while(value > 1){
+        value = value/10;
+        scale++;
+    }
+    if(value < 0.15)
+        baseLine = 1;
+    else if (value < 0.35)
+        baseLine = 2;
+    else if (value < 0.75)
+        baseLine = 5;
+    else
+        baseLine = 10;
+    baseLine = baseLine * (pow(10,scale-1));
+    return baseLine;
+}
+
+void MapScale::updateMapResolution(const qreal &resolution)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    //Calculate distance scale in metric units
+    qreal genericMetricScale = TARGET_WIDTH * resolution;
+    qreal baseMetricScale = roundToBaseScale(genericMetricScale);
+    if(resolution != 0)
+        m_centerLineMetric = baseMetricScale / resolution;
+    else
+        m_centerLineMetric = baseMetricScale / 0.000001;
+
+    if(baseMetricScale < M_TO_KM)
+    {
+        m_metricText.setNum(baseMetricScale);
+        m_metricText.append(" m");
+    } else {
+        m_metricText.setNum(baseMetricScale/M_TO_KM);
+        m_metricText.append(" km");
+    }
+
+    //Calculate distance scale in imperial units
+    qreal imperialScaleResolution = resolution * M_TO_FT;
+    qreal genericImperialScale = TARGET_WIDTH * imperialScaleResolution;
+    qreal baseImperialScale;
+
+    if(genericImperialScale < FT_TO_MI) {
+        baseImperialScale = roundToBaseScale(genericImperialScale);
+        if(imperialScaleResolution != 0)
+            m_centerLineImperial = baseImperialScale / imperialScaleResolution;
+        else
+            m_centerLineImperial = baseImperialScale / 0.000001;
+        m_imperialText.setNum(baseImperialScale);
+        m_imperialText.append(" ft");
+    } else {
+        baseImperialScale = roundToBaseScale(genericImperialScale / FT_TO_MI);
+        if(imperialScaleResolution != 0)
+            m_centerLineImperial = (baseImperialScale*FT_TO_MI) / imperialScaleResolution;
+        else
+            m_centerLineImperial = baseImperialScale / 0.000001;
+        m_imperialText.setNum(baseImperialScale);
+        m_imperialText.append(" mi");
+    }
+
+    update();
+}
diff --git a/src/ui/mapscale.h b/src/ui/mapscale.h
new file mode 100644 (file)
index 0000000..0d3c004
--- /dev/null
@@ -0,0 +1,89 @@
+ /*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Kaj Wallin - kaj.wallin@ixonos.com
+
+    Situare is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    version 2 as published by the Free Software Foundation.
+
+    Situare is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Situare; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+    USA.
+ */
+
+
+#ifndef MAPSCALE_H
+#define MAPSCALE_H
+
+#include <QWidget>
+
+class QLineF;
+
+/**
+ * @brief Map distance scale
+ *
+ * @author Kaj Wallin - kaj.wallin (at) ixonos.com
+ */
+class MapScale : public QWidget
+{
+    Q_OBJECT
+
+public:
+    /**
+     * @brief Constructor
+     *
+     * @param parent Parent
+     */
+    MapScale(QWidget *parent = 0);
+
+/*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
+    /**
+     * @brief Event handler for paint events
+     *
+     * Paints the scale
+     * @param event Paint event
+     */
+    void paintEvent(QPaintEvent *event);
+
+/******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+private:
+    /**
+     * @brief Rounding function for distances
+     *
+     * Rounds the given value to closest 1,2,5 or 10 in the original scale
+     * @param value Value to be rounded
+     * @return qreal Rounded value
+     */
+    qreal roundToBaseScale(qreal value);
+
+public slots:
+    /**
+     * @brief Slot to update the scale with latest resolution
+     *
+     * @param resolution Resolution of the map in meters/pixel
+     */
+    void updateMapResolution(const qreal &resolution);
+
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
+private:
+    qreal m_centerLineImperial;     ///< Length of the imperial scale
+    qreal m_centerLineMetric;       ///< Length of the metric scale
+    QString m_imperialText;         ///< Text description of the imperial scale
+    QString m_metricText;           ///< Text description of the metric scale
+};
+
+#endif // MAPSCALE_H
index 5635757..442fd40 100644 (file)
@@ -56,11 +56,10 @@ void PanelSideBar::paintEvent(QPaintEvent *)
     style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
 }
 
-void PanelSideBar::reDrawSidebar(int width, int height)
+void PanelSideBar::reDrawSidebar(const QSize &size)
 {
-    Q_UNUSED(height);
     qDebug() << __PRETTY_FUNCTION__;
     if (objectName() == "SidePanelRight") {
-        move(width - SIDEBAR_WIDTH + MARGIN_CORRECTION2, PANEL_TOP_Y);
+        move(size.width() - SIDEBAR_WIDTH + MARGIN_CORRECTION2, PANEL_TOP_Y);
     }
 }
index c22bdac..52b92d7 100644 (file)
@@ -62,10 +62,9 @@ public slots:
     /**
     * @brief Slot to redraw the sidebar after window resize event
     *
-    * @param width Width of the window after resize
-    * @param height Height of the window after resize
+    * @param size Size of the screen
     */
-    void reDrawSidebar(int width, int height);
+    void reDrawSidebar(const QSize &size);
 };
 
 #endif // PANELSIDEBAR_H
index e9f83b1..6d8d298 100644 (file)
 #include "common.h"
 #include "settingsdialog.h"
 
-const QString SETTINGS_AUTOMATIC_UPDATE_ENABLED = "SETTINGS_AUTOMATIC_UPDATE_ENABLED";
-const QString SETTINGS_AUTOMATIC_UPDATE_INTERVAL = "SETTINGS_AUTOMATIC_UPDATE_INTERVAL";
 const int LIST_MINUTES_STEP = 5;
 const int LIST_MINUTES_MAX = 60;
 const int LIST_HOURS_MAX = 1;
 
 SettingsDialog::SettingsDialog(QWidget *parent)
-    : QDialog(parent),
-      m_automaticLocationUpdateOldValue(false),
-      m_automaticLocationUpdateIntervalOldValue(QTime(0, LIST_MINUTES_STEP))
+    : QDialog(parent)
 {
     qDebug() << __PRETTY_FUNCTION__;
     setWindowTitle(tr("Settings"));
@@ -79,7 +75,6 @@ SettingsDialog::SettingsDialog(QWidget *parent)
     connect(m_automaticLocationUpdate, SIGNAL(toggled(bool)),
             this, SLOT(toggleAutomaticLocationUpdate(bool)));
     connect(saveButton, SIGNAL(clicked()), this, SLOT(saveValues()));
-    connect(this, SIGNAL(rejected()), this, SLOT(rejectValues()));
 
     QFormLayout *form = new QFormLayout();
     form->setRowWrapPolicy(QFormLayout::WrapAllRows);
@@ -103,22 +98,17 @@ SettingsDialog::SettingsDialog(QWidget *parent)
     readSettings();
 }
 
-SettingsDialog::~SettingsDialog()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
-    settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, m_automaticLocationUpdateOldValue);
-    settings.setValue(SETTINGS_AUTOMATIC_UPDATE_INTERVAL,
-                      m_automaticLocationUpdateIntervalOldValue);
-}
-
-void SettingsDialog::setAutomaticLocationUpdateSettings(bool checked)
+void SettingsDialog::emitAutomaticLocationUpdateSettings()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_automaticLocationUpdate->setChecked(checked);
-    m_automaticLocationUpdateOldValue = checked;
+    if (m_automaticLocationUpdate->isChecked()) {
+        QTime emptyTime = QTime();
+        emit enableAutomaticLocationUpdate(true, emptyTime.msecsTo(time()));
+    }
+    else {
+        emit enableAutomaticLocationUpdate(false);
+    }
 }
 
 void SettingsDialog::enableSituareSettings(bool enabled)
@@ -133,6 +123,18 @@ void SettingsDialog::enableSituareSettings(bool enabled)
         toggleAutomaticLocationUpdate(false);
 }
 
+void SettingsDialog::populateUpdateIntervalList(QStandardItemModel *model)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    for (int i = LIST_MINUTES_STEP; i <= LIST_MINUTES_MAX; i+=LIST_MINUTES_STEP) {
+        QStandardItem *item = new QStandardItem(QString(tr("%1 min")).arg(i));
+        item->setTextAlignment(Qt::AlignCenter);
+        item->setEditable(false);
+        model->appendRow(item);
+    }
+}
+
 void SettingsDialog::readSettings()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -148,54 +150,29 @@ void SettingsDialog::readSettings()
         setTime(QTime::fromString(automaticUpdateInterval, "hh:mm:ss"));
     else
         setTime(QTime(0, LIST_MINUTES_STEP));
-
-    m_automaticLocationUpdateOldValue = automaticUpdateEnabled;
-    m_automaticLocationUpdateIntervalOldValue = time();
 }
 
-void SettingsDialog::emitAutomaticLocationUpdateSettings()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if (m_automaticLocationUpdate->isChecked()) {
-        QTime emptyTime = QTime();
-        emit enableAutomaticLocationUpdate(true, emptyTime.msecsTo(time()));
-    }
-    else {
-        emit enableAutomaticLocationUpdate(false);
-    }
-}
-
-void SettingsDialog::populateUpdateIntervalList(QStandardItemModel *model)
+void SettingsDialog::saveValues()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    for (int i = LIST_MINUTES_STEP; i <= LIST_MINUTES_MAX; i+=LIST_MINUTES_STEP) {
-        QStandardItem *item = new QStandardItem(QString(tr("%1 min")).arg(i));
-        item->setTextAlignment(Qt::AlignCenter);
-        item->setEditable(false);
-        model->appendRow(item);
-    }
-}
+    QSettings settings(DIRECTORY_NAME, FILE_NAME);
+    settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, m_automaticLocationUpdate->isChecked());
+    settings.setValue(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, time());
 
-void SettingsDialog::rejectValues()
-{
-    qDebug() << __PRETTY_FUNCTION__;
+    emitAutomaticLocationUpdateSettings();
 
-    m_automaticLocationUpdate->setChecked(m_automaticLocationUpdateOldValue);
-    setTime(m_automaticLocationUpdateIntervalOldValue);
+    accept();
 }
 
-void SettingsDialog::saveValues()
+void SettingsDialog::setAutomaticLocationUpdateSettings(bool checked)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_automaticLocationUpdateOldValue = m_automaticLocationUpdate->isChecked();
-    m_automaticLocationUpdateIntervalOldValue = time();
-
-    emitAutomaticLocationUpdateSettings();
+    m_automaticLocationUpdate->setChecked(checked);
 
-    accept();
+    QSettings settings(DIRECTORY_NAME, FILE_NAME);
+    settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, m_automaticLocationUpdate->isChecked());
 }
 
 void SettingsDialog::setTime(const QTime &time)
index 17ec547..eaf8eb6 100644 (file)
@@ -54,13 +54,6 @@ public:
     */
     SettingsDialog(QWidget *parent = 0);
 
-    /**
-    * @brief Destructor.
-    *
-    * Saves automatic update interval in settings.
-    */
-    ~SettingsDialog();
-
 /*******************************************************************************
 * MEMBER FUNCTIONS AND SLOTS
 ******************************************************************************/
@@ -84,16 +77,16 @@ public:
     */
     void emitAutomaticLocationUpdateSettings();
 
-private slots:
     /**
-    * @brief Saves settings to file.
+    * @brief Read settings.
     */
-    void saveValues();
+    void readSettings();
 
+private slots:
     /**
-    * @brief Rejects changes made to settings.
+    * @brief Saves settings to file.
     */
-    void rejectValues();
+    void saveValues();
 
     /**
     * @brief Toggles automatic location update state.
@@ -113,11 +106,6 @@ private slots:
     void populateUpdateIntervalList(QStandardItemModel *model);
 
     /**
-    * @brief Read settings.
-    */
-    void readSettings();
-
-    /**
     * @brief Sets time.
     *
     * @param time time to set
@@ -145,8 +133,6 @@ signals:
  ******************************************************************************/
 private:
     QCheckBox *m_automaticLocationUpdate;           ///< Pointer to CheckBox
-    bool m_automaticLocationUpdateOldValue;         ///< Automatic location update state
-    QTime m_automaticLocationUpdateIntervalOldValue;///< Automatic location update interval value
 
 #ifdef Q_WS_MAEMO_5
     QMaemo5ValueButton *m_automaticLocationUpdateIntervalButton;    ///< Maemo 5 value button
index 745981f..4533254 100644 (file)
@@ -68,6 +68,9 @@ protected:
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
 public:
+    /**
+     * @brief Relative position of the event inside the widget
+     */
     const QPoint& eventPosition();
 
 /*******************************************************************************
index 8da59de..5d649ac 100644 (file)
@@ -44,8 +44,6 @@ public:
      * @brief Constructor
      *
      * @param parent Parent
-     * @param x Panel x coordinate
-     * @param y Panel y coordinate
      */
     ZoomButtonPanel(QWidget *parent = 0);