<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>
<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>
#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());
}
}
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();
}
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:
/**
* @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
*/
* 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