31 #include <QGraphicsSceneMouseEvent>
35 HomeItem::HomeItem(MapGraphicItem* map, TLMapWidget* parent):
47 pic.load(QString::fromUtf8(
":/markers/images/home2.svg"));
48 pic=pic.scaled(30,30,Qt::IgnoreAspectRatio);
49 this->setFlag(QGraphicsItem::ItemIgnoresTransformations,
true);
50 this->setFlag(QGraphicsItem::ItemIsMovable,
false);
51 this->setFlag(QGraphicsItem::ItemIsSelectable,
false);
53 this->setPos(localposition.
X(),localposition.
Y());
57 setCacheMode(QGraphicsItem::DeviceCoordinateCache);
58 connect(map,SIGNAL(childRefreshPosition()),
this,SLOT(
RefreshPos()));
59 connect(map,SIGNAL(childSetOpacity(qreal)),
this,SLOT(
setOpacitySlot(qreal)));
62 void HomeItem::RefreshToolTip()
64 QString coord_str =
" " + QString::number(
coord.
Lat(),
'f', 6) +
" " + QString::number(
coord.
Lng(),
'f', 6);
66 setToolTip(QString(
"Waypoint: Home\nCoordinate:%1\nAltitude:%2\n").arg(coord_str).arg(QString::number(
altitude)));
70 void HomeItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
74 painter->drawPixmap(-pic.width()/2,-pic.height()/2,pic);
78 painter->setPen(Qt::green);
80 painter->setPen(Qt::red);
81 painter->drawRect(QRectF(-localsafearea,-localsafearea,localsafearea*2,localsafearea*2));
85 QRectF HomeItem::boundingRect()
const
87 if(pic.width()>localsafearea*2 && !toggleRefresh)
88 return QRectF(-pic.width()/2,-pic.height()/2,pic.width(),pic.height());
90 return QRectF(-localsafearea,-localsafearea,localsafearea*2,localsafearea*2);
94 int HomeItem::type()
const
101 prepareGeometryChange();
102 localposition=map->FromLatLngToLocal(
coord);
103 this->setPos(localposition.
X(),localposition.
Y());
105 localsafearea=safearea/map->Projection()->GetGroundResolution(map->ZoomTotal(),
coord.
Lat());
121 if(event->button()==Qt::LeftButton)
125 QGraphicsItem::mousePressEvent(event);
130 if(event->button()==Qt::LeftButton)
132 coord=map->FromLocalToLatLng(this->pos().
x(),this->pos().
y());
137 QGraphicsItem::mouseReleaseEvent(event);
143 if(event->button()==Qt::LeftButton)
153 coord=map->FromLocalToLatLng(this->pos().
x(),this->pos().
y());
156 QGraphicsItem::mouseMoveEvent(event);
A graphicsItem representing a Home Location.