Drawing the red location dot, documenting, clean-up
authorSami Rämö <sami.ramo@ixonos.com>
Fri, 30 Jul 2010 13:58:54 +0000 (16:58 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Fri, 30 Jul 2010 13:58:54 +0000 (16:58 +0300)
 - Implemented drawing the red location dot by using a child item.

 - Added missing documentation

 - Clean-up

src/coordinates/geocoordinate.h
src/map/gpslocationitem.cpp
src/map/gpslocationitem.h

index 008ecb5..a57bf0f 100644 (file)
@@ -158,6 +158,12 @@ private:
  * OPERATORS
  ******************************************************************************/
 public:
+    /**
+    * @brief Subtract operator
+    *
+    * @returns Returns a GeoCoordinate object that is formed by subtracting coordinate2 from
+    *          coordinate1. Each component is subtracted separately.
+    */
     friend const GeoCoordinate operator-(const GeoCoordinate &coordinate1,
                                          const GeoCoordinate &coordinate2);
 
index ccb422f..2b7f492 100644 (file)
@@ -34,16 +34,22 @@ GPSLocationItem::GPSLocationItem()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_pixmap = QPixmap(":/res/images/gps_position.png");
-
     setPos(QPoint(UNDEFINED, UNDEFINED));
     setZValue(OWN_LOCATION_ICON_Z_LEVEL);
-    //setOffset(-m_pixmap.width() / 2, -m_pixmap.height() / 2);
-//    setFlag(QGraphicsItem::ItemIgnoresTransformations);
+
+    // create a child item for the actual red position spot
+    m_pixmapItem = new QGraphicsPixmapItem(QPixmap(":/res/images/gps_position.png"));
+    m_pixmapItem->setParentItem(this);
+    m_pixmapItem->setFlag(QGraphicsItem::ItemIgnoresTransformations);
+    m_pixmapItem->setOffset(-m_pixmapItem->pixmap().width() / 2,
+                            -m_pixmapItem->pixmap().height() / 2);
+
 }
 
 QRectF GPSLocationItem::boundingRect() const
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     return m_boundingRect;
 }
 
@@ -51,6 +57,8 @@ void GPSLocationItem::paint(QPainter *painter,
                             const QStyleOptionGraphicsItem *option,
                             QWidget *widget)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     Q_UNUSED(option);
     Q_UNUSED(widget);
 
@@ -59,12 +67,14 @@ void GPSLocationItem::paint(QPainter *painter,
     const int RING_OUTLINE_ALPHA = 96;
     const int RING_FILL_ALPHA = 48;
 
+    // set outline ring
     color.setAlpha(RING_OUTLINE_ALPHA);
     QPen pen = QPen(color);
     pen.setWidthF(RING_OUTLINE_PEN_WIDTH);
     pen.setCosmetic(true);
     painter->setPen(pen);
 
+    // set ring fill
     color.setAlpha(RING_FILL_ALPHA);
     painter->setBrush(color);
 
@@ -89,6 +99,8 @@ void GPSLocationItem::setEnabled(bool enable)
 
 void GPSLocationItem::setAccuracyRingRadius(qreal accuracy, qreal sceneResolution)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     qreal newRadius = accuracy / sceneResolution;
 
     if (m_radius != newRadius) {
@@ -99,6 +111,8 @@ void GPSLocationItem::setAccuracyRingRadius(qreal accuracy, qreal sceneResolutio
 
 void GPSLocationItem::setBoundingRect(qreal radius)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     prepareGeometryChange();
 
     m_boundingRect = QRectF(-radius - RING_OUTLINE_PEN_WIDTH / 2,
index 9d91c14..0191410 100644 (file)
 #include <QGraphicsItem>
 
 /**
-  * @brief Class for indicating current position accuired from GPS on the map.
+  * @brief Class for indicating current position and accuracy accuired from GPS on the map.
   *
-  * Also the GPS fix accuracy is indicated by the radius of the circle around the position item.
+  * Actual position spot image is a child item of this class and this class handles drawing the
+  * accuracy ring. GPS fix accuracy is indicated by the radius of the circle around the position
+  * item.
   */
 class GPSLocationItem : public QGraphicsItem
 {
@@ -70,15 +72,28 @@ public:
     /**
       * @brief Update position item
       *
-      * @param coordinate Scene coordinate
+      * @param scenePosition Scene position
       * @param accuracy Accuracy of the GPS fix
       * @param sceneResolution Scene horizontal resolution at given coordinate latitude level
       */
     void updateItem(QPointF scenePosition, qreal accuracy, qreal sceneResolution);
 
 private:
+    /**
+    * @brief Set new radius for the accuracy ring
+    *
+    * Calls setBoundingRect() if the radius changes
+    *
+    * @param accuracy Accuracy (in meters)
+    * @param sceneResolution Scene resolution (meters/pixel)
+    */
     void setAccuracyRingRadius(qreal accuracy, qreal sceneResolution);
 
+    /**
+    * @brief Sets new bounding rect for this item based on the accuracy ring radius
+    *
+    * @param radius Radius of the accuracy ring
+    */
     void setBoundingRect(qreal radius);
 
 /*******************************************************************************
@@ -87,12 +102,11 @@ private:
 private:
     bool m_showOnNextUpdate;    ///< should the item be shown when next update arrives
 
-    qreal m_accuracy;           ///< current accuracy
     qreal m_radius;             ///< accuracy ring radius in scene pixels
 
-    QPixmap m_pixmap;           ///< red led pixmap
+    QGraphicsPixmapItem *m_pixmapItem;  ///< red led item
 
-    QRectF m_boundingRect;      ///< item's bounding rect
+    QRectF m_boundingRect;              ///< item's bounding rect
 };
 
 #endif // GPSLOCATIONITEM_H