Modified GPS & map related signals and slots
[situare] / src / map / gpslocationitem.cpp
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Sami Rämö - sami.ramo@ixonos.com
6
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.
10
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.
15
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,
19     USA.
20 */
21
22 const int ACCURATE_LIMIT = 250; // this and lower values (in meters) are considered as accurate
23
24 #include <QDebug>
25 #include <QGraphicsPixmapItem>
26
27 #include "../gps/gpscommon.h"
28 #include "mapcommon.h"
29
30 #include "gpslocationitem.h"
31
32 GPSLocationItem::GPSLocationItem()
33     : m_currentAccuracy(NOT_SET)
34 {
35     qDebug() << __PRETTY_FUNCTION__;
36     m_accuratePixmap = QPixmap(":/res/images/gps_pos_accurate.png");
37     m_coarsePixmap = QPixmap(":/res/images/gps_pos_coarse.png");
38
39     setPos(QPoint(UNDEFINED, UNDEFINED));
40     setZValue(OWN_LOCATION_ICON_Z_LEVEL);
41     setOffset(-m_accuratePixmap.width() / 2, -m_accuratePixmap.height() / 2);
42     setFlag(QGraphicsItem::ItemIgnoresTransformations);
43 }
44
45 void GPSLocationItem::updatePosition(QPoint scenePosition, qreal accuracy)
46 {
47     qDebug() << __PRETTY_FUNCTION__;
48
49     setPos(scenePosition);
50
51     if (accuracy != GPS_ACCURACY_UNDEFINED  // accuracy must be defined
52         && accuracy <= ACCURATE_LIMIT       // and smaller than limit
53         && m_currentAccuracy != ACCURATE) { // and accurate pixmap not yet set
54             setPixmap(m_accuratePixmap);
55             m_currentAccuracy = ACCURATE;
56     }
57     else if (m_currentAccuracy != COARSE) { // coarse pixmap not yet set
58         setPixmap(m_coarsePixmap);
59         m_currentAccuracy = COARSE;
60     }
61 }