Merge branch 'crosshair2'
authorVille Tiensuu <ville.tiensuu@ixonos.com>
Tue, 18 May 2010 05:06:43 +0000 (08:06 +0300)
committerVille Tiensuu <ville.tiensuu@ixonos.com>
Tue, 18 May 2010 05:06:43 +0000 (08:06 +0300)
Conflicts:
images.qrc
src/engine/engine.h
src/map/mapengine.cpp
src/map/mapview.cpp
src/map/mapview.h
src/ui/mainwindow.cpp
src/ui/mapviewscreen.cpp
src/ui/mapviewscreen.h

26 files changed:
doc/test_cases/functionality-tests.doc
images.qrc
res/images/friend_group.png
src/common.h
src/engine/engine.h
src/gps/gpscommon.h [new file with mode: 0644]
src/gps/gpsposition.cpp
src/gps/gpsposition.h
src/map/friendgroupitem.cpp
src/map/gpslocationitem.cpp [new file with mode: 0644]
src/map/gpslocationitem.h [new file with mode: 0644]
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/avatarimage.cpp
src/ui/friendlistitem.cpp
src/ui/mainwindow.cpp
src/ui/mapviewscreen.cpp
src/ui/mapviewscreen.h
src/ui/zoombuttonpanel.cpp
src/ui/zoombuttonpanel.h
tests/map/gpslocationitem/testgpslocationitem.cpp [new file with mode: 0644]
tests/map/gpslocationitem/testgpslocationitem.pro [new file with mode: 0644]

index 1a19405..4507308 100644 (file)
Binary files a/doc/test_cases/functionality-tests.doc and b/doc/test_cases/functionality-tests.doc differ
index 6d41324..9be0c76 100644 (file)
         <file>res/images/sliding_bar_right.png</file>
         <file>res/images/led_red.png</file>
         <file>res/images/led_red_s.png</file>
-        <file>res/images/friend_group.png</file>
         <file>res/images/list_item.png</file>
         <file>res/images/list_item_bottom.png</file>
         <file>res/images/list_item_middle.png</file>
         <file>res/images/list_item_top.png</file>
+        <file>res/images/gps_pos_accurate.png</file>
+        <file>res/images/gps_pos_coarse.png</file>
+        <file>res/images/friend_group.png</file>
                <file>res/images/sight.png</file>
     </qresource>
 </RCC>
index 9b8aec7..3d555c6 100644 (file)
Binary files a/res/images/friend_group.png and b/res/images/friend_group.png differ
index 89b7ea0..9c295f1 100644 (file)
 #define COMMON_H
 
 #include <QString>
+#include <QColor>
+#include <QFont>
 
 // QSettings identifiers
 const QString DIRECTORY_NAME = "Ixonos";
 const QString FILE_NAME = "Situare";
 
+const QColor COLOR_GRAY = QColor(152, 152, 152);                           ///< Gray color
+const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal);    ///< Normal font
+const QFont NOKIA_FONT_SMALL = QFont("Nokia Sans", 13, QFont::Normal);     ///< Small font
+
 #endif // COMMON_H
index 426d1a5..3e7df39 100644 (file)
@@ -139,6 +139,7 @@ public slots:
  * SIGNALS
  ******************************************************************************/
 signals:
+
     /**
     * @brief Signals when new friends data is ready
     *
diff --git a/src/gps/gpscommon.h b/src/gps/gpscommon.h
new file mode 100644 (file)
index 0000000..a7380cc
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Sami Rämö - sami.ramo@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 GPSCOMMON_H
+#define GPSCOMMON_H
+
+const int GPS_ACCURACY_UNDEFINED = -1; ///< Value used when accuracy is undefined
+
+#endif // GPSCOMMON_H
index e286cbb..d4c46e7 100644 (file)
@@ -27,6 +27,7 @@
 #include <QDebug>
 #include <QTimer>
 
+#include "gpscommon.h"
 #include "gpsposition.h"
 #include "gpspositioninterface.h"
 
@@ -119,8 +120,8 @@ void GPSPosition::requestLastPosition()
     QGeoCoordinate coordinate = m_gpsSource->lastKnownPosition().coordinate();
 
     if (coordinate.isValid()) {
-        qreal accuracy = biggerAccuracy(m_gpsSource->lastKnownPosition());
-        emit position(QPointF(coordinate.longitude(), coordinate.latitude()), accuracy);
+        emit position(QPointF(coordinate.longitude(), coordinate.latitude()),
+                      accuracy(m_gpsSource->lastKnownPosition()));
     }
 }
 
@@ -128,13 +129,10 @@ void GPSPosition::positionUpdated(QGeoPositionInfo positionInfo)
 {
     qDebug() << __PRETTY_FUNCTION__ << positionInfo;
 
-    if (positionInfo.coordinate().isValid()) {
-
-        qreal accuracy = biggerAccuracy(positionInfo);
-
+    if (positionInfo.coordinate().isValid())
         emit position(QPointF(positionInfo.coordinate().longitude(),
-                          positionInfo.coordinate().latitude()), accuracy);
-    }
+                              positionInfo.coordinate().latitude()),
+                      accuracy(positionInfo));
 }
 
 void GPSPosition::updateTimeout()
@@ -154,23 +152,15 @@ void GPSPosition::setUpdateInterval(int interval)
     }
 }
 
-qreal GPSPosition::biggerAccuracy(QGeoPositionInfo positionInfo)
+qreal GPSPosition::accuracy(QGeoPositionInfo positionInfo)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    qreal horizontalAccuracy = ACCURACY_UNDEFINED;
-    qreal verticalAccuracy = ACCURACY_UNDEFINED;
+    if (!positionInfo.dateTime().isValid())
+        return GPS_ACCURACY_UNDEFINED;
 
     if (positionInfo.hasAttribute(QGeoPositionInfo::HorizontalAccuracy))
-        horizontalAccuracy = positionInfo.attribute(QGeoPositionInfo::HorizontalAccuracy);
-
-    if (positionInfo.hasAttribute(QGeoPositionInfo::VerticalAccuracy))
-        verticalAccuracy = positionInfo.attribute(QGeoPositionInfo::VerticalAccuracy);
-
-    int accuracy = verticalAccuracy;
-
-    if (horizontalAccuracy > accuracy)
-        accuracy = horizontalAccuracy;
-
-    return accuracy;
+        return positionInfo.attribute(QGeoPositionInfo::HorizontalAccuracy);
+    else
+        return GPS_ACCURACY_UNDEFINED;
 }
index 56a124e..8e370d2 100644 (file)
@@ -102,12 +102,13 @@ public:
 
 private:
     /**
-    * @brief Return bigger accuracy value from latitude and longitude values.
+    * @brief Return horizontal accuracy
     *
     * @param positionInfo geo position info
-    * @return bigger accuracy value, -1 if undefined
+    * @return accuracy value, -1 if undefined. Returns -1 also is timestamp is not valid
+    *         (when using network positioning)
     */
-    qreal biggerAccuracy(QGeoPositionInfo positionInfo);
+    qreal accuracy(QGeoPositionInfo positionInfo);
 
 private slots:
 
@@ -130,16 +131,15 @@ private slots:
     */
     void updateTimeout();
 
-/******************************************************************************
-* DATA MEMBERS
-******************************************************************************/
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
 private:
     QGeoPositionInfoSource *m_gpsSource;        ///< GPS position info source
     bool m_running;                             ///< GPS is running
     int m_updateInterval;                       ///< GPS update interval
 };
 
-const int ACCURACY_UNDEFINED = -1;               ///< Undefined accuracy
 const int DEFAULT_UPDATE_INTERVAL = 5000;       ///< Default update interval
 
 #endif // GPSPOSITION_H
index d64558d..bdc3a96 100644 (file)
@@ -26,8 +26,8 @@
 
 #include "friendlocationitem.h"
 #include "mapcommon.h"
-
 #include "friendgroupitem.h"
+#include "common.h"
 
 FriendGroupItem::FriendGroupItem(FriendLocationItem *item)
 {
@@ -97,8 +97,9 @@ void FriendGroupItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
 
     BaseLocationItem::paint(painter, option, widget);
 
-    QFont font = painter->font();
-    font.setPointSize(painter->font().pointSize() * 2); // double default font size
-    painter->setFont(font);
-    painter->drawText(boundingRect(), Qt::AlignCenter, QString::number(m_friends.count()));
+    painter->setPen(Qt::black);
+    painter->setFont(NOKIA_FONT_SMALL);
+    painter->drawText(QRect(GROUP_ITEM_FRIENDS_COUNT_X, GROUP_ITEM_FRIENDS_COUNT_Y,
+                            GROUP_ITEM_FRIENDS_COUNT_WIDTH, GROUP_ITEM_FRIENDS_COUNT_HEIGHT),
+                      Qt::AlignCenter, QString::number(m_friends.count()));
 }
diff --git a/src/map/gpslocationitem.cpp b/src/map/gpslocationitem.cpp
new file mode 100644 (file)
index 0000000..2585513
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Sami Rämö - sami.ramo@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 <QDebug>
+#include <QGraphicsPixmapItem>
+
+#include "../gps/gpscommon.h"
+#include "mapcommon.h"
+
+#include "gpslocationitem.h"
+
+GPSLocationItem::GPSLocationItem()
+    : m_currentAccuracy(NOT_SET)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+    m_accuratePixmap = QPixmap(":/res/images/gps_pos_accurate.png");
+    m_coarsePixmap = QPixmap(":/res/images/gps_pos_coarse.png");
+
+    setPos(QPoint(UNDEFINED, UNDEFINED));
+    setZValue(OWN_LOCATION_ICON_Z_LEVEL);
+    setOffset(-m_accuratePixmap.width() / 2, -m_accuratePixmap.height() / 2);
+    setFlag(QGraphicsItem::ItemIgnoresTransformations);
+}
+
+void GPSLocationItem::setEnabled(bool enable)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (enable) {
+        show();
+    }
+    else {
+        m_currentAccuracy = NOT_SET;
+        hide();
+        setPixmap(QPixmap());
+    }
+
+}
+
+void GPSLocationItem::updatePosition(QPoint scenePosition, qreal accuracy)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    setPos(scenePosition);
+
+    if (accuracy == GPS_ACCURACY_UNDEFINED) { // fix is NOT accurate
+        if (m_currentAccuracy != COARSE) { // coarse pixmap not yet set
+            setPixmap(m_coarsePixmap);
+            m_currentAccuracy = COARSE;
+        }
+    }
+    else { // fix is accurate
+        if (m_currentAccuracy != ACCURATE) { // accurate pixmap not yet set
+            setPixmap(m_accuratePixmap);
+            m_currentAccuracy = ACCURATE;
+        }
+    }
+}
diff --git a/src/map/gpslocationitem.h b/src/map/gpslocationitem.h
new file mode 100644 (file)
index 0000000..d62ec11
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Sami Rämö - sami.ramo@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 GPSLOCATIONITEM_H
+#define GPSLOCATIONITEM_H
+
+#include <QGraphicsPixmapItem>
+
+/**
+  * @brief Class for indicating current position accuired from GPS on the map.
+  *
+  * Also GPS fix accuracy is indicated by using two different color indicator images
+  * based on current accuracy
+  */
+class GPSLocationItem : public QGraphicsPixmapItem
+{
+public:
+    /**
+      * @brief Constructor
+      */
+    GPSLocationItem();
+
+/*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+public:
+    /**
+      * @brief Enable / disable item
+      *
+      * @param enable True if item should be enabled, otherwise false
+      */
+    void setEnabled(bool enable);
+
+    /**
+      * @brief Update position item
+      *
+      * Use yellow led image when using network positioning and green led image when using GPS.
+      *
+      * @param scenePosition Scene coordinate
+      * @param accuracy Accuracy of the GPS fix
+      */
+    void updatePosition(QPoint scenePosition, qreal accuracy);
+
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
+private:
+    /**
+      * @brief Enum for current pixmap state
+      */
+    enum Accuracy { NOT_SET, ACCURATE, COARSE };
+
+    QPixmap m_accuratePixmap; ///< pixmap used when GPS fix is accurate
+    QPixmap m_coarsePixmap; ///< pixmap used when GPS fix is coarse
+    Accuracy m_currentAccuracy; ///< current accuracy
+};
+
+#endif // GPSLOCATIONITEM_H
index b8349cb..06f26f7 100644 (file)
@@ -39,6 +39,11 @@ const int MIN_MAP_SCENE_NORMAL_LEVEL = MAX_MAP_ZOOM_LEVEL + 1;
 */
 const int FRIEND_LOCATION_ICON_Z_LEVEL = MIN_MAP_SCENE_NORMAL_LEVEL + MAX_MAP_ZOOM_LEVEL + 1;
 
+const int GROUP_ITEM_FRIENDS_COUNT_X = 13;  ///< Group item friends count x value
+const int GROUP_ITEM_FRIENDS_COUNT_Y = 13;  ///< Group item friends count y value
+const int GROUP_ITEM_FRIENDS_COUNT_WIDTH = 17;  ///< Group item friends count width value
+const int GROUP_ITEM_FRIENDS_COUNT_HEIGHT = 17; ///< Group item friends count height value
+
 /**
 * @var OWN_LOCATION_ICON_Z_LEVEL
 * @brief layer of own location icon
index 03fc198..098874b 100644 (file)
@@ -32,6 +32,7 @@
 #include <QRect>
 
 #include "frienditemshandler.h"
+#include "gpslocationitem.h"
 #include "mapcommon.h"
 #include "mapengine.h"
 #include "maptile.h"
@@ -59,9 +60,13 @@ MapEngine::MapEngine(QObject *parent)
     m_ownLocation->hide(); // hide until first location info is received
     m_mapScene->addItem(m_ownLocation);
 
+    m_gpsLocationItem = new GPSLocationItem();
+    m_mapScene->addItem(m_gpsLocationItem);
+
     m_friendItemsHandler = new FriendItemsHandler(m_mapScene, this);
     connect(this, SIGNAL(zoomLevelChanged(int)),
             m_friendItemsHandler, SLOT(refactorFriendItems(int)));
+
     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
             m_friendItemsHandler, SLOT(friendListUpdated(QList<User*>&)));
 }
@@ -132,17 +137,12 @@ QRect MapEngine::calculateTileGrid(QPoint sceneCoordinate)
     return QRect(topLeftX, topLeftY, gridWidth, gridHeight);
 }
 
-void MapEngine::alignImmovableItems(QPoint viewTopLeft)
-{
-    qDebug() << __PRETTY_FUNCTION__ << "viewTopLeft:" << viewTopLeft;
-}
-
 void MapEngine::setLocation(QPoint sceneCoordinate)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     if (disableAutoCentering(sceneCoordinate))
-        emit mapScrolled();
+        emit mapScrolledManually();
 
     m_sceneCoordinate = sceneCoordinate;
     emit locationChanged(m_sceneCoordinate);
@@ -234,6 +234,11 @@ void MapEngine::viewZoomFinished()
         m_zoomedIn = false;
         m_mapScene->removeOutOfViewTiles();
     }
+
+    if (m_zoomLevel == MAX_MAP_ZOOM_LEVEL)
+        emit maxZoomLevelReached();
+    else if (m_zoomLevel == MIN_VIEW_ZOOM_LEVEL)
+        emit minZoomLevelReached();
 }
 
 void MapEngine::zoomIn()
@@ -332,6 +337,14 @@ void MapEngine::receiveOwnLocation(User *user)
         m_ownLocation->show();
 }
 
+void MapEngine::gpsPositionUpdate(QPointF position, qreal accuracy)
+{
+    m_gpsLocationItem->updatePosition(convertLatLonToSceneCoordinate(position), accuracy);
+
+    if (m_autoCenteringEnabled)
+        setViewLocation(position);
+}
+
 bool MapEngine::disableAutoCentering(QPoint sceneCoordinate)
 {
     if (isAutoCenteringEnabled()) {
@@ -361,6 +374,12 @@ void MapEngine::setAutoCentering(bool enabled)
     m_autoCenteringEnabled = enabled;
 }
 
+
+void MapEngine::gpsEnabled(bool enabled)
+{
+    m_gpsLocationItem->setEnabled(enabled);
+}
+
 QPointF MapEngine::convertSceneCoordinateToLatLon(int zoomLevel, QPoint sceneCoordinate)
 {   
     qDebug() << __PRETTY_FUNCTION__;
index 98516a7..5067057 100644 (file)
@@ -34,6 +34,7 @@
 #include "user/user.h"
 
 class FriendItemsHandler;
+class GPSLocationItem;
 
 /**
 * @brief Map engine
@@ -105,13 +106,6 @@ public:
     QGraphicsScene* scene();
 
     /**
-    * @brief Set auto centering.
-    *
-    * @param enabled true if enabled, false otherwise
-    */
-    void setAutoCentering(bool enabled);
-
-    /**
     * @brief Return tile path created from tile values.
     *
     * @param zoomLevel tile's zoom level
@@ -131,13 +125,6 @@ public:
 
 public slots:
     /**
-    * @brief Slot for immovable scene items position correction
-    *
-    * @param viewTopLeft Scene coordinate of the viewport top left corner
-    */
-    void alignImmovableItems(QPoint viewTopLeft);
-
-    /**
     * @brief Slot for setting current view location
     *
     * Emits locationChanged signal.
@@ -241,6 +228,26 @@ private:
 
 private slots:
     /**
+      * @brief Slot for enabling / disabling GPS
+      *
+      * GPS location item is disabled or enabled based on GPS state
+      *
+      * @param enabled True is GPS is enabled, otherwise false
+      */
+    void gpsEnabled(bool enabled);
+
+    /**
+      * @brief Slot for GPS position updates
+      *
+      * GPS location item is updated and map centered to new location (if automatic
+      * centering is enabled).
+      *
+      * @param position New coordinates from GPS
+      * @param accuracy Accuracy of the GPS fix
+      */
+    void gpsPositionUpdate(QPointF position, qreal accuracy);
+
+    /**
     * @brief Slot for received map tile images
     *
     * Does add MapTile objects to MapScene.
@@ -252,6 +259,13 @@ private slots:
     void mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image);
 
     /**
+    * @brief Set auto centering.
+    *
+    * @param enabled true if enabled, false otherwise
+    */
+    void setAutoCentering(bool enabled);
+
+    /**
     * @brief Slot for actions after view zoom is finished
     *
     * Does run removeOutOfViewTiles
@@ -300,7 +314,17 @@ signals:
     /**
     * @brief Signal to notify map scrolling.
     */
-    void mapScrolled();
+    void mapScrolledManually();
+
+    /**
+    * @brief Signal to notify when map is zoomed in to the maxmimum.
+    */
+    void maxZoomLevelReached();
+
+    /**
+    * @brief Signal to notify when map is zoomed out to the minimum.
+    */
+    void minZoomLevelReached();
 
     /**
     * @brief Signal request mapView to update view port contents
@@ -325,9 +349,10 @@ signals:
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    bool m_autoCenteringEnabled;    ///< Auto centering enabled
+    bool m_autoCenteringEnabled; ///< Auto centering enabled
     QPoint m_centerTile; ///< Current center tile
     FriendItemsHandler *m_friendItemsHandler; ///< Handler for friend and group items
+    GPSLocationItem *m_gpsLocationItem; ///< Item pointing current location from GPS
     QPoint m_lastManualPosition;  ///< Last manually set position in scene coordinate
     MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
     MapScene *m_mapScene; ///< Scene for map tiles
index f099331..745f719 100644 (file)
@@ -37,7 +37,8 @@ MapView::MapView(QWidget *parent)
     setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
     m_zoomAnimation = new QPropertyAnimation(this, "viewScale", this);
-    connect(m_zoomAnimation, SIGNAL(finished()), this, SIGNAL(viewZoomFinished()));
+    connect(m_zoomAnimation, SIGNAL(finished()),
+        this, SIGNAL(viewZoomFinished()));
 }
 
 void MapView::setZoomLevel(int zoomLevel)
@@ -68,7 +69,6 @@ void MapView::setViewScale(qreal viewScale)
     QTransform transform;
     transform.scale(viewScale, viewScale);
     setTransform(transform);
-    emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
 }
 
 void MapView::mouseMoveEvent(QMouseEvent *event)
@@ -80,7 +80,6 @@ void MapView::mouseMoveEvent(QMouseEvent *event)
     emit viewScrolled(m_scenePosition);
 
     m_mousePosition = mapToScene(event->pos()).toPoint();
-    emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
 }
 
 void MapView::mousePressEvent(QMouseEvent *event)
@@ -106,16 +105,8 @@ void MapView::resizeEvent(QResizeEvent *event)
 
     emit viewResized(event->size());
     emit viewResizedNewSize(viewport()->width(), viewport()->height());
-    //emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
 }
 
-void MapView::showEvent(QShowEvent *event)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    QGraphicsView::showEvent(event);
-    //emit viewContentChanged(mapToScene(viewport()->x(), viewport()->y()).toPoint());
-}
 
 void MapView::updateViewPortContent()
 {
index e6547d9..8f86892 100644 (file)
@@ -62,13 +62,6 @@ protected:
     */
     void resizeEvent(QResizeEvent *event);
 
-    /**
-    * @brief Called when view is displayed.
-    *
-    * @param event show event
-    */
-    void showEvent(QShowEvent *event);
-
 private:
     /**
     * @brief Event handler for mouse move events
@@ -154,7 +147,6 @@ signals:
 
     /**
     * @brief Signal for informing that zooming animation is finished
-    *
     */
     void viewZoomFinished();
 
index aeb1c24..d1140dc 100644 (file)
@@ -39,6 +39,7 @@ SOURCES += main.cpp \
     map/friendgroupitem.cpp \
     map/frienditemshandler.cpp \
     gps/gpspositioninterface.cpp \
+    map/gpslocationitem.cpp \
     ui/zoombuttonpanel.cpp
 HEADERS += ui/mainwindow.h \
     ui/mapviewscreen.h \
@@ -76,6 +77,8 @@ HEADERS += ui/mainwindow.h \
     map/friendgroupitem.h \
     map/frienditemshandler.h \
     gps/gpspositioninterface.h \
+    map/gpslocationitem.h \
+    gps/gpscommon.h \
     ui/zoombuttonpanel.h \
     common.h
 QT += network \
index 940bb49..59a4d79 100644 (file)
@@ -33,7 +33,7 @@ const int CLIP_X_OFFSET = 1;    ///< Clip
 
 QPixmap AvatarImage::create(const QPixmap &image)
 {
-    QPixmap avatarImage = QPixmap(60, 60);
+    QPixmap avatarImage = QPixmap(IMAGE_WIDTH, IMAGE_HEIGHT);
     avatarImage.fill(Qt::transparent);
     QPainter painter(&avatarImage);
 
index 7eae647..60c82e2 100644 (file)
 #include "friendlistitem.h"
 #include "../user/user.h"
 #include "imagebutton.h"
+#include "common.h"
 
 const int BACKGROUND_TOP_HEIGHT = 20;
 const int BACKGROUND_BOTTOM_HEIGHT = 15;
-const QColor COLOR_GRAY = QColor(152, 152, 152);    ///< Gray color
-const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal);    ///< Normal font
-const QFont NOKIA_FONT_SMALL = QFont("Nokia Sans", 13, QFont::Normal);     ///< Small font
 const int ICON_HEIGHT = 24;     ///< Icon height
 const int ICON_WIDTH = 24;       ///< Icon width
 const int IMAGE_HEIGHT = 60; ///< Friend image height
index 35d23b3..8f45110 100644 (file)
@@ -66,9 +66,9 @@ MainWindow::MainWindow(QWidget *parent)
             m_mapViewScreen, SIGNAL(friendsLocationsReady(QList<User*>&)));
 
        connect(this, SIGNAL(autoCentering(bool)),
-            m_mapViewScreen, SLOT(enableAutoCentering(bool)));
+            m_mapViewScreen, SIGNAL(enableAutoCentering(bool)));
     connect(this, SIGNAL(positionReceived(QPointF, qreal)),
-            m_mapViewScreen, SLOT(positionReceived(QPointF, qreal)));
+            m_mapViewScreen, SIGNAL(positionReceived(QPointF, qreal)));
     connect(m_mapViewScreen, SIGNAL(mapLocationChanged()),
             this, SLOT(mapLocationChanged()));
 
@@ -126,8 +126,10 @@ void MainWindow::createMenus()
     m_autoCenteringAct->setCheckable(true);
     m_autoCenteringAct->setChecked(true);
     connect(m_autoCenteringAct, SIGNAL(toggled(bool)),
-        this, SLOT(autoCenteringToggled(bool)));    
-       
+        this, SLOT(autoCenteringToggled(bool))); 
+    connect(this, SIGNAL(enableGPS(bool)),
+            m_mapViewScreen, SIGNAL(gpsEnabled(bool)));
+
     m_viewMenu = menuBar()->addMenu(tr("Main"));
 
     m_viewMenu->addAction(m_toSettingsAct);
index bfcd6e5..2a0cc16 100644 (file)
@@ -25,8 +25,7 @@
 #include "panelsidebar.h"
 
 MapViewScreen::MapViewScreen(QWidget *parent)
-   : QWidget(parent),
-     m_autoCenteringEnabled(false)
+   : QWidget(parent)
 {
     MapView *mapView = new MapView(this);
     m_mapEngine = new MapEngine(this);
@@ -69,10 +68,16 @@ MapViewScreen::MapViewScreen(QWidget *parent)
     connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
             friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
 
-    connect(m_zoomButtonPanel->m_zoomInBtn, SIGNAL(clicked()),
+    connect(m_zoomButtonPanel->m_zoomInButton, SIGNAL(clicked()),
             m_mapEngine, SLOT(zoomIn()));
-    connect(m_zoomButtonPanel->m_zoomOutBtn, SIGNAL(clicked()),
+    connect(m_zoomButtonPanel->m_zoomOutButton, SIGNAL(clicked()),
             m_mapEngine, SLOT(zoomOut()));
+    connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
+            m_zoomButtonPanel, SLOT(resetButtons()));
+    connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
+            m_zoomButtonPanel, SLOT(disableZoomInButton()));
+    connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
+            m_zoomButtonPanel, SLOT(disableZoomOutButton()));
 
     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
             m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
@@ -84,8 +89,15 @@ MapViewScreen::MapViewScreen(QWidget *parent)
     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
             m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
 
-    connect(m_mapEngine, SIGNAL(mapScrolled()),
-            this, SLOT(locationChanged()));
+    connect(m_mapEngine, SIGNAL(mapScrolledManually()),
+            this, SIGNAL(mapLocationChanged()));
+
+    connect(this, SIGNAL(positionReceived(QPointF,qreal)),
+            m_mapEngine, SLOT(gpsPositionUpdate(QPointF,qreal)));
+    connect(this, SIGNAL(enableAutoCentering(bool)),
+            m_mapEngine, SLOT(setAutoCentering(bool)));
+    connect(this, SIGNAL(gpsEnabled(bool)),
+            m_mapEngine, SLOT(gpsEnabled(bool)));
 
     connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
             this, SLOT(drawOwnLocationCrosshair(int, int)));
@@ -136,29 +148,6 @@ void MapViewScreen::drawOsmLicense(int width, int height)
                         height - m_osmLicense->fontMetrics().height());
 }
 
-void MapViewScreen::locationChanged()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if (m_autoCenteringEnabled)
-        emit mapLocationChanged();
-}
-
-void MapViewScreen::positionReceived(QPointF position, qreal accuracy)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if (m_autoCenteringEnabled)
-        m_mapEngine->setViewLocation(position);
-}
-
-void MapViewScreen::enableAutoCentering(bool enabled)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_autoCenteringEnabled = enabled;
-    m_mapEngine->setAutoCentering(enabled);
-}
 
 void MapViewScreen::drawOwnLocationCrosshair(int width, int height)
 {
index 533072d..bde9443 100644 (file)
@@ -32,8 +32,6 @@
 
 /**
 * @brief Map View class. Used to display Map
-*
-* @class MapViewScreen mainwindow.h "src/ui/mainwindow.h"
 */
 class MapViewScreen : public QWidget
 {
@@ -60,13 +58,6 @@ public slots:
 
 private slots:
     /**
-    * @brief Slot for enabling auto centering.
-    *
-    * @param enabled true if map should center to GPS position, false otherwise
-    */
-    void enableAutoCentering(bool enabled);
-
-    /**
     * @brief Slot for drawing the Open Street Map license text
     *
     * @param width Width of the viewport
@@ -82,10 +73,10 @@ private slots:
     */
     void drawOwnLocationCrosshair(int width, int height);
 
-    /**
-    * @brief Slot for map location change.
-    */
-    void locationChanged();
+//    /**
+//    * @brief Slot for map location change.
+//    */
+//    void locationChanged();
 
     /**
     * @brief Set correnct view port size to datamembers
@@ -95,19 +86,18 @@ private slots:
     */
     void setViewPortSize(const int width, const int height);
 
-    /**
-    * @brief Slot for GPS position.
-    *
-    * @param position latitude and longitude values
-    * @param accuracy coordinate accuracy in metres
-    */
-    void positionReceived(QPointF position, qreal accuracy);
-
 /*******************************************************************************
  * SIGNALS
  ******************************************************************************/
 signals:
     /**
+    * @brief Signal for enabling auto centering.
+    *
+    * @param enabled true if map should center to GPS position, false otherwise
+    */
+    void enableAutoCentering(bool enabled);
+
+    /**
     * @brief Signal when friend list locations are fetched
     *
     * Forwarded to map engine and friends list panel
@@ -116,12 +106,27 @@ signals:
     */
     void friendsLocationsReady(QList<User *> &friendsList);
 
-       /**
+    /**
+      * @brief Signal for GPS enabling / disabling
+      *
+      * @param enabled True is GPS is enabled, otherwise false
+      */
+    void gpsEnabled(bool enabled);
+
+    /**
     * @brief Signal for map location change.
     */
     void mapLocationChanged();
 
     /**
+    * @brief Slot for GPS position.
+    *
+    * @param position latitude and longitude values
+    * @param accuracy coordinate accuracy in metres
+    */
+    void positionReceived(QPointF position, qreal accuracy);
+
+    /**
     * @brief Signal from MapEngine to SituareEngine is travelling here
     */
     void ownLocation(QPointF ownLatitudeLongitudeLocation);
@@ -152,16 +157,15 @@ signals:
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    MapEngine *m_mapEngine;                 ///< MapEngine
-    UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
-    FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
-    ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
-    QLabel *m_osmLicense;                   ///< Label for Open Street Map license
-    bool m_autoCenteringEnabled;            ///< Enable
-    QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
-    bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
-    int m_viewPortWidth;                    ///< Width of view port
-    int m_viewPortHeight;                   ///< Height of view port
+       bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
+       FriendListPanel *m_friendsListPanel; ///< Instance of friends list panel
+       MapEngine *m_mapEngine;              ///< MapEngine
+       QLabel *m_osmLicense;                ///< Label for Open Street Map license
+       QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair    
+       UserInfoPanel *m_userPanel;          ///< Instance of the user information panel
+       int m_viewPortHeight;   ///< Height of view port
+       int m_viewPortWidth;                    ///< Width of view port
+       ZoomButtonPanel *m_zoomButtonPanel;  ///< Instance of zoom button panel
 };
 
 #endif // MAPVIEWTAB_H
index 59b0327..c21ceb1 100644 (file)
@@ -33,16 +33,38 @@ ZoomButtonPanel::ZoomButtonPanel(QWidget *parent, int x, int y)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_zoomInBtn = new ImageButton(this, ":/res/images/zoom_in.png");
-    m_zoomOutBtn = new ImageButton(this, ":/res/images/zoom_out.png");
+    m_zoomInButton = new ImageButton(this, ":/res/images/zoom_in.png");
+    m_zoomOutButton = new ImageButton(this, ":/res/images/zoom_out.png");
 
     m_panelLayout.setMargin(0);
     m_panelLayout.setSpacing(0);
     m_panelLayout.setVerticalSpacing(ZOOM_BUTTON_PANEL_BUTTON_SPACING);
     m_panelLayout.setSizeConstraint(QLayout::SetFixedSize);
 
-    m_panelLayout.addWidget(m_zoomInBtn, 0, 0);
-    m_panelLayout.addWidget(m_zoomOutBtn, 1, 0);
+    m_panelLayout.addWidget(m_zoomInButton, 0, 0);
+    m_panelLayout.addWidget(m_zoomOutButton, 1, 0);
 
     move(m_x, m_y);
 }
+
+void ZoomButtonPanel::disableZoomInButton()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_zoomInButton->setMode(QIcon::Disabled);
+}
+
+void ZoomButtonPanel::disableZoomOutButton()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_zoomOutButton->setMode(QIcon::Disabled);
+}
+
+void ZoomButtonPanel::resetButtons()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_zoomInButton->setMode(QIcon::Normal);
+    m_zoomOutButton->setMode(QIcon::Normal);
+}
index c55d593..0349676 100644 (file)
 #include "imagebutton.h"
 
 /**
-* @brief Panel for zoom buttons
-*
-* @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
-*/
+ * @brief Panel for zoom buttons
+ *
+ * @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
+ */
 class ZoomButtonPanel : public QWidget
 {
     Q_OBJECT
 
 public:
     /**
-    * @brief Constructor
-    *
-    * @param parent Parent
-    * @param x Panel x coordinate
-    * @param y Panel y coordinate
-    */
+     * @brief Constructor
+     *
+     * @param parent Parent
+     * @param x Panel x coordinate
+     * @param y Panel y coordinate
+     */
     ZoomButtonPanel(QWidget *parent = 0, int x = 0, int y = 0);
 
 /*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+public slots:
+    /**
+     * @brief Disables the Zoom In button
+     */
+    void disableZoomInButton();
+
+    /**
+     * @brief Disables the Zoom Out button
+     */
+    void disableZoomOutButton();
+
+    /**
+     * @brief Reset Zoom button states to normal
+     */
+    void resetButtons();
+
+/*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
 public:
-    ImageButton *m_zoomInBtn;     ///< Button for zoom in
-    ImageButton *m_zoomOutBtn;    ///< Button for zoom out
+    ImageButton *m_zoomInButton;     ///< Button for zoom in
+    ImageButton *m_zoomOutButton;    ///< Button for zoom out
 
 private:
     QGridLayout m_panelLayout;  ///< Panel layout
diff --git a/tests/map/gpslocationitem/testgpslocationitem.cpp b/tests/map/gpslocationitem/testgpslocationitem.cpp
new file mode 100644 (file)
index 0000000..0fb58e4
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Sami Rämö - sami.ramo@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 <QtTest/QtTest>
+
+#include "map/mapcommon.h"
+#include "map/gpslocationitem.h"
+
+class TestGPSLocationItem: public QObject
+{
+    Q_OBJECT
+
+private slots:
+    void constructor();
+    void enable();
+    void position();
+};
+
+void TestGPSLocationItem::constructor()
+{
+    QPixmap accurate(":/res/images/gps_pos_accurate.png");
+
+    GPSLocationItem item;
+
+    // pixmap should not be set
+    QVERIFY(item.pixmap().isNull());
+
+    // position should be UNDEFINED
+    QCOMPARE(item.pos(), QPointF(UNDEFINED, UNDEFINED));
+
+    // zValue should be set
+    QCOMPARE(item.zValue(), static_cast<qreal>(OWN_LOCATION_ICON_Z_LEVEL));
+
+    // icon offset should be set based on accurate pixmap
+    QCOMPARE(item.offset(), QPointF(-accurate.width() / 2, -accurate.height() / 2));
+
+    // ItemIgnoresTransformations flag should be set
+    QVERIFY(item.flags() & QGraphicsItem::ItemIgnoresTransformations);
+}
+
+void TestGPSLocationItem::enable()
+{
+    // create item and update it's position so pixmap is set
+    GPSLocationItem item;
+    item.updatePosition(QPoint(100, 100), 10);
+
+    // item should be visible and pixmap set
+    QCOMPARE(item.isVisible(), true);
+    QCOMPARE(item.pixmap().isNull(), false);
+
+    item.setEnabled(false);
+
+    // item should be hidden and pixmap unset
+    QCOMPARE(item.isVisible(), false);
+    QCOMPARE(item.pixmap().isNull(), true);
+
+    item.setEnabled(true);
+
+    // item should be visible, but pixmap still unset until first position update is received
+    QCOMPARE(item.isVisible(), true);
+    QCOMPARE(item.pixmap().isNull(), true);
+
+    item.updatePosition(QPoint(500, 500), 10);
+
+    // pixmam should be set after first position update
+    QCOMPARE(item.pixmap().isNull(), false);
+}
+
+void TestGPSLocationItem::position()
+{
+    GPSLocationItem item;
+    item.updatePosition(QPoint(123, 321), 10);
+
+    QCOMPARE(item.pos(), QPointF(123, 321));
+}
+
+QTEST_MAIN(TestGPSLocationItem)
+
+#include "testgpslocationitem.moc"
diff --git a/tests/map/gpslocationitem/testgpslocationitem.pro b/tests/map/gpslocationitem/testgpslocationitem.pro
new file mode 100644 (file)
index 0000000..9f0579c
--- /dev/null
@@ -0,0 +1,18 @@
+# #####################################################################
+# Automatically generated by qmake (2.01a) Fri Mar 26 15:09:16 2010
+# #####################################################################
+CONFIG += qtestlib
+QT += network
+TEMPLATE = app
+TARGET = 
+DEPENDPATH += .
+INCLUDEPATH += . \
+    ../../../src/
+
+# Input
+SOURCES += testgpslocationitem.cpp \ 
+    ../../../src/map/gpslocationitem.cpp
+HEADERS += \ 
+    ../../../src/map/gpslocationitem.h
+DEFINES += QT_NO_DEBUG_OUTPUT
+RESOURCES += ../../../images.qrc