Drawing of GPS accuracy ring with hardcoded radius
authorSami Rämö <sami.ramo@ixonos.com>
Thu, 29 Jul 2010 14:03:29 +0000 (17:03 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Thu, 29 Jul 2010 14:03:29 +0000 (17:03 +0300)
 - Drawing is done outside the items bounding box, so there is
   some drawing artifacts

 - Changed GPSLocationItem to use the red "led" image and removed
   old green and yellow "led" images

12 files changed:
images.qrc
res/images/gps_pos_accurate.png [deleted file]
res/images/gps_pos_accurate_s.png [deleted file]
res/images/gps_pos_coarse.png [deleted file]
res/images/gps_pos_coarse_s.png [deleted file]
res/images/gps_position.png [new file with mode: 0644]
res/images/gps_position_s.png [new file with mode: 0644]
res/images/led_red.png [deleted file]
res/images/led_red_s.png [deleted file]
src/map/gpslocationitem.cpp
src/map/gpslocationitem.h
src/ui/indicatorbutton.cpp

index 122510e..fee7479 100644 (file)
@@ -1,6 +1,6 @@
 <RCC>
     <qresource prefix="/">
-        <file>res/images/aeroplane_icon_gray.png</file>        
+        <file>res/images/aeroplane_icon_gray.png</file>
         <file>res/images/arrow_left.png</file>
         <file>res/images/arrow_right.png</file>
         <file>res/images/car_icon_gray.png</file>
@@ -8,13 +8,11 @@
         <file>res/images/compass.png</file>
         <file>res/images/envelope.png</file>
         <file>res/images/friend_group.png</file>
-        <file>res/images/gps_pos_accurate.png</file>
-        <file>res/images/gps_pos_coarse.png</file>
         <file>res/images/large_profile_pic_border_left.png</file>
         <file>res/images/large_profile_pic_border_middle.png</file>
         <file>res/images/large_profile_pic_border_right.png</file>
-        <file>res/images/led_red.png</file>
-        <file>res/images/led_red_s.png</file>
+        <file>res/images/gps_position.png</file>
+        <file>res/images/gps_position_s.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>
diff --git a/res/images/gps_pos_accurate.png b/res/images/gps_pos_accurate.png
deleted file mode 100644 (file)
index 69c9773..0000000
Binary files a/res/images/gps_pos_accurate.png and /dev/null differ
diff --git a/res/images/gps_pos_accurate_s.png b/res/images/gps_pos_accurate_s.png
deleted file mode 100644 (file)
index f1cb266..0000000
Binary files a/res/images/gps_pos_accurate_s.png and /dev/null differ
diff --git a/res/images/gps_pos_coarse.png b/res/images/gps_pos_coarse.png
deleted file mode 100644 (file)
index 11a6cae..0000000
Binary files a/res/images/gps_pos_coarse.png and /dev/null differ
diff --git a/res/images/gps_pos_coarse_s.png b/res/images/gps_pos_coarse_s.png
deleted file mode 100644 (file)
index 8710da9..0000000
Binary files a/res/images/gps_pos_coarse_s.png and /dev/null differ
diff --git a/res/images/gps_position.png b/res/images/gps_position.png
new file mode 100644 (file)
index 0000000..8a2776a
Binary files /dev/null and b/res/images/gps_position.png differ
diff --git a/res/images/gps_position_s.png b/res/images/gps_position_s.png
new file mode 100644 (file)
index 0000000..604b44c
Binary files /dev/null and b/res/images/gps_position_s.png differ
diff --git a/res/images/led_red.png b/res/images/led_red.png
deleted file mode 100644 (file)
index 8a2776a..0000000
Binary files a/res/images/led_red.png and /dev/null differ
diff --git a/res/images/led_red_s.png b/res/images/led_red_s.png
deleted file mode 100644 (file)
index 604b44c..0000000
Binary files a/res/images/led_red_s.png and /dev/null differ
index 73010f2..b10ed45 100644 (file)
 
 #include <QDebug>
 #include <QGraphicsPixmapItem>
+#include <QPainter>
 
 #include "coordinates/scenecoordinate.h"
-#include "../gps/gpscommon.h"
-#include "mapcommon.h"
+#include "gps/gpscommon.h"
+#include "map/mapcommon.h"
 
 #include "gpslocationitem.h"
 
 GPSLocationItem::GPSLocationItem()
-    : m_currentAccuracy(NOT_SET)
+    : m_showOnNextUpdate(true)
 {
     qDebug() << __PRETTY_FUNCTION__;
-    m_accuratePixmap = QPixmap(":/res/images/gps_pos_accurate.png");
-    m_coarsePixmap = QPixmap(":/res/images/gps_pos_coarse.png");
+
+    setPixmap(QPixmap(":/res/images/gps_position.png"));
 
     setPos(QPoint(UNDEFINED, UNDEFINED));
     setZValue(OWN_LOCATION_ICON_Z_LEVEL);
-    setOffset(-m_accuratePixmap.width() / 2, -m_accuratePixmap.height() / 2);
+    setOffset(-pixmap().width() / 2, -pixmap().height() / 2);
     setFlag(QGraphicsItem::ItemIgnoresTransformations);
 }
 
+void GPSLocationItem::paint(QPainter *painter,
+                            const QStyleOptionGraphicsItem *option,
+                            QWidget *widget)
+{
+    QGraphicsPixmapItem::paint(painter, option, widget);
+
+    QColor color = QColor(Qt::red);
+
+    const int OUTLINE_ALPHA = 96;
+    const int FILL_ALPHA = 48;
+
+    color.setAlpha(OUTLINE_ALPHA);
+    painter->setPen(color);
+
+    color.setAlpha(FILL_ALPHA);
+    painter->setBrush(color);
+
+    painter->setRenderHint(QPainter::Antialiasing);
+
+    QPointF center = QPointF();
+    qreal radius = 30;
+    painter->drawEllipse(center, radius, radius);
+}
+
 void GPSLocationItem::setEnabled(bool enable)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     if (enable) {
-        show();
+        m_showOnNextUpdate = true;
     }
     else {
-        m_currentAccuracy = NOT_SET;
+        m_showOnNextUpdate = false;
         hide();
-        setPixmap(QPixmap());
     }
 
 }
@@ -61,17 +85,12 @@ void GPSLocationItem::updatePosition(SceneCoordinate coordinate, qreal accuracy)
     qDebug() << __PRETTY_FUNCTION__;
 
     setPos(coordinate.toPointF());
+    m_accuracy = accuracy;
 
-    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;
-        }
+    if (m_showOnNextUpdate) {
+        show();
+        m_showOnNextUpdate = false;
     }
+
+    update();
 }
index c3bf316..53813b4 100644 (file)
@@ -41,6 +41,15 @@ public:
     GPSLocationItem();
 
 /*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
+public:
+    /**
+    * @brief Reimplementing the painter from QGraphicsPixmapItem
+    */
+    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+
+/*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
 public:
@@ -54,8 +63,6 @@ public:
     /**
       * @brief Update position item
       *
-      * Use yellow led image when using network positioning and green led image when using GPS.
-      *
       * @param coordinate Scene coordinate
       * @param accuracy Accuracy of the GPS fix
       */
@@ -65,14 +72,9 @@ public:
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    /**
-      * @brief Enum for current pixmap state
-      */
-    enum Accuracy { NOT_SET, ACCURATE, COARSE };
+    bool m_showOnNextUpdate;    ///< should the item be shown when next update arrives
 
-    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
+    qreal m_accuracy;           ///< current accuracy
 };
 
 #endif // GPSLOCATIONITEM_H
index d6b1a9d..bb1079e 100644 (file)
@@ -43,8 +43,8 @@ IndicatorButton::IndicatorButton(QWidget *parent)
     : QToolButton(parent),
       m_isDraggable(false)
 {
-    m_indicatorLeds[OFF].load(":res/images/led_red.png");
-    m_indicatorLeds[ON].load(":res/images/led_red_s.png");
+    m_indicatorLeds[OFF].load(":res/images/gps_position.png");
+    m_indicatorLeds[ON].load(":res/images/gps_position_s.png");
     setFixedSize(BUTTON_WIDTH, BUTTON_HEIGHT);
 
     QSettings settings(DIRECTORY_NAME, FILE_NAME);