Merge branch 'master' into settings_auto_update
[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 #include <QDebug>
23 #include <QGraphicsPixmapItem>
24
25 #include "../gps/gpscommon.h"
26 #include "mapcommon.h"
27
28 #include "gpslocationitem.h"
29
30 GPSLocationItem::GPSLocationItem()
31     : m_currentAccuracy(NOT_SET)
32 {
33     qDebug() << __PRETTY_FUNCTION__;
34     m_accuratePixmap = QPixmap(":/res/images/gps_pos_accurate.png");
35     m_coarsePixmap = QPixmap(":/res/images/gps_pos_coarse.png");
36
37     setPos(QPoint(UNDEFINED, UNDEFINED));
38     setZValue(OWN_LOCATION_ICON_Z_LEVEL);
39     setOffset(-m_accuratePixmap.width() / 2, -m_accuratePixmap.height() / 2);
40     setFlag(QGraphicsItem::ItemIgnoresTransformations);
41 }
42
43 void GPSLocationItem::setEnabled(bool enable)
44 {
45     qDebug() << __PRETTY_FUNCTION__;
46
47     if (enable) {
48         show();
49     }
50     else {
51         m_currentAccuracy = NOT_SET;
52         hide();
53         setPixmap(QPixmap());
54     }
55
56 }
57
58 void GPSLocationItem::updatePosition(QPoint scenePosition, qreal accuracy)
59 {
60     qDebug() << __PRETTY_FUNCTION__;
61
62     setPos(scenePosition);
63
64     if (accuracy == GPS_ACCURACY_UNDEFINED) { // fix is NOT accurate
65         if (m_currentAccuracy != COARSE) { // coarse pixmap not yet set
66             setPixmap(m_coarsePixmap);
67             m_currentAccuracy = COARSE;
68         }
69     }
70     else { // fix is accurate
71         if (m_currentAccuracy != ACCURATE) { // accurate pixmap not yet set
72             setPixmap(m_accuratePixmap);
73             m_currentAccuracy = ACCURATE;
74         }
75     }
76 }