forked from CCOMJHC/camp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeographicsitem.cpp
More file actions
77 lines (67 loc) · 1.8 KB
/
Copy pathgeographicsitem.cpp
File metadata and controls
77 lines (67 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "geographicsitem.h"
#include "backgroundraster.h"
#include "autonomousvehicleproject.h"
#include "missionitem.h"
#include <QGraphicsSimpleTextItem>
#include <QFont>
#include <QBrush>
#include <QPen>
#include <QDebug>
GeoGraphicsItem::GeoGraphicsItem(QGraphicsItem *parentItem): QGraphicsItem(parentItem), m_showLabelFlag(false)
{
m_label = new QGraphicsSimpleTextItem(this);
m_label->setFlag(GraphicsItemFlag::ItemIgnoresTransformations);
auto font = m_label->font();
font.setPointSize(20);
font.setBold(true);
m_label->setFont(font);
m_label->setBrush(QBrush(QColor("black")));
QPen p(QColor("white"));
p.setWidth(2);
m_label->setPen(p);
//m_label->setFlag(QGraphicsItem::ItemIsMovable); this caused other elements to move while trying to move the label!
}
QPointF GeoGraphicsItem::geoToPixel(const QGeoCoordinate &point, AutonomousVehicleProject *p) const
{
if(p)
{
BackgroundRaster *bg = p->getBackgroundRaster();
if(bg)
{
QPointF ret = bg->geoToPixel(point);
QGraphicsItem *pi = parentItem();
if(pi)
{
return ret - pi->scenePos();
}
return ret;
}
}
return QPointF();
}
void GeoGraphicsItem::prepareGeometryChange()
{
QGraphicsItem::prepareGeometryChange();
}
void GeoGraphicsItem::setLabel(const QString &label)
{
m_labelText = label;
if(m_showLabelFlag)
m_label->setText(m_labelText);
}
void GeoGraphicsItem::setLabelPosition(QPointF pos)
{
m_label->setPos(pos);
}
bool GeoGraphicsItem::showLabelFlag() const
{
return m_showLabelFlag;
}
void GeoGraphicsItem::setShowLabelFlag(bool show)
{
m_showLabelFlag = show;
if(show)
m_label->setText(m_labelText);
else
m_label->setText("");
}