9e6cc98930c205dc015f73bafc7774c9e4b2a0ec
[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::setEnabled(bool enable)
46 {
47     qDebug() << __PRETTY_FUNCTION__;
48
49     if (enable) {
50         show();
51     }
52     else {
53         m_currentAccuracy = NOT_SET;
54         hide();
55         setPixmap(QPixmap());
56     }
57
58 }
59
60 void GPSLocationItem::updatePosition(QPoint scenePosition, qreal accuracy)
61 {
62     qDebug() << __PRETTY_FUNCTION__;
63
64     setPos(scenePosition);
65
66     if (accuracy != GPS_ACCURACY_UNDEFINED  // accuracy must be defined
67         && accuracy <= ACCURATE_LIMIT       // and smaller than limit
68         && m_currentAccuracy != ACCURATE) { // and accurate pixmap not yet set
69             setPixmap(m_accuratePixmap);
70             m_currentAccuracy = ACCURATE;
71     }
72     else if (m_currentAccuracy != COARSE) { // coarse pixmap not yet set
73         setPixmap(m_coarsePixmap);
74         m_currentAccuracy = COARSE;
75     }
76 }