2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 #include "gps/gpscommon.h"
26 #include "map/mapcommon.h"
28 #include "gpslocationitem.h"
30 const qreal RING_OUTLINE_PEN_WIDTH = 1.0;
32 GPSLocationItem::GPSLocationItem()
33 : m_showOnNextUpdate(true)
35 qDebug() << __PRETTY_FUNCTION__;
37 setPos(QPoint(UNDEFINED, UNDEFINED));
38 setZValue(GPSLocationItemZValue);
40 // create a child item for the actual red position spot
41 m_pixmapItem = new QGraphicsPixmapItem(QPixmap(":/res/images/gps_position.png"));
42 m_pixmapItem->setParentItem(this);
43 m_pixmapItem->setFlag(QGraphicsItem::ItemIgnoresTransformations);
44 m_pixmapItem->setOffset(-m_pixmapItem->pixmap().width() / 2,
45 -m_pixmapItem->pixmap().height() / 2);
50 QRectF GPSLocationItem::boundingRect() const
52 qDebug() << __PRETTY_FUNCTION__;
54 return m_boundingRect;
57 void GPSLocationItem::paint(QPainter *painter,
58 const QStyleOptionGraphicsItem *option,
61 qDebug() << __PRETTY_FUNCTION__;
66 QColor color = QColor(Qt::red);
68 const int RING_OUTLINE_ALPHA = 64;
69 const int RING_FILL_ALPHA = 32;
72 color.setAlpha(RING_OUTLINE_ALPHA);
73 QPen pen = QPen(color);
74 pen.setWidthF(RING_OUTLINE_PEN_WIDTH);
75 pen.setCosmetic(true);
79 color.setAlpha(RING_FILL_ALPHA);
80 painter->setBrush(color);
82 painter->setRenderHint(QPainter::Antialiasing);
84 QPointF center = QPointF();
85 painter->drawEllipse(center, m_radius, m_radius);
88 void GPSLocationItem::setEnabled(bool enable)
90 qDebug() << __PRETTY_FUNCTION__;
93 m_showOnNextUpdate = true;
96 m_showOnNextUpdate = false;
101 void GPSLocationItem::setAccuracyRingRadius(qreal accuracy, qreal sceneResolution)
103 qDebug() << __PRETTY_FUNCTION__;
105 qreal newRadius = accuracy / sceneResolution;
107 if (m_radius != newRadius) {
108 m_radius = newRadius;
109 setBoundingRect(newRadius);
113 void GPSLocationItem::setBoundingRect(qreal radius)
115 qDebug() << __PRETTY_FUNCTION__;
117 prepareGeometryChange();
119 m_boundingRect = QRectF(-radius - RING_OUTLINE_PEN_WIDTH / 2,
120 -radius - RING_OUTLINE_PEN_WIDTH / 2,
121 2 * radius + RING_OUTLINE_PEN_WIDTH,
122 2 * radius + RING_OUTLINE_PEN_WIDTH);
125 void GPSLocationItem::updateItem(QPointF scenePosition, qreal accuracy, qreal sceneResolution)
127 qDebug() << __PRETTY_FUNCTION__;
129 setPos(scenePosition);
130 setAccuracyRingRadius(accuracy, sceneResolution);
132 if (m_showOnNextUpdate) {
134 m_showOnNextUpdate = false;