29 #include <QGraphicsSceneMouseEvent>
33 WayPointItem::WayPointItem(
const internals::PointLatLng &coord,
int const& altitude, MapGraphicItem *map,wptype type) :
41 this->altitude = altitude;
47 picture.load(QString::fromUtf8(
":/markers/images/marker.png"));
48 number=WayPointItem::snumber;
49 ++WayPointItem::snumber;
50 this->setFlag(QGraphicsItem::ItemIsMovable,
true);
51 this->setFlag(QGraphicsItem::ItemIgnoresTransformations,
true);
52 this->setFlag(QGraphicsItem::ItemIsSelectable,
true);
53 SetShowNumber(shownumber);
58 foreach(QGraphicsItem * obj,list)
60 HomeItem*
h=qgraphicsitem_cast <HomeItem*>(obj);
67 map->Projection()->offSetFromLatLngs(myHome->Coord(),coord,relativeCoord.distance,relativeCoord.bearing);
70 connect(
this,SIGNAL(waypointdoubleclick(WayPointItem*)),map,SIGNAL(wpdoubleclicked(WayPointItem*)));
71 emit manualCoordChange(
this);
72 connect(map,SIGNAL(childRefreshPosition()),
this,SLOT(RefreshPos()));
73 connect(map,SIGNAL(childSetOpacity(qreal)),
this,SLOT(
setOpacitySlot(qreal)));
76 WayPointItem::WayPointItem(MapGraphicItem *map,
bool magicwaypoint):
89 picture.load(QString::fromUtf8(
":/opmap/images/waypoint_marker3.png"));
95 number=WayPointItem::snumber;
96 ++WayPointItem::snumber;
100 this->setFlag(QGraphicsItem::ItemIsMovable,
true);
101 this->setFlag(QGraphicsItem::ItemIgnoresTransformations,
true);
102 this->setFlag(QGraphicsItem::ItemIsSelectable,
true);
103 SetShowNumber(shownumber);
108 foreach(QGraphicsItem * obj,list)
110 HomeItem* h=qgraphicsitem_cast <HomeItem*>(obj);
117 coord=map->Projection()->translate(myHome->Coord(),relativeCoord.distance,relativeCoord.bearing);
120 connect(
this,SIGNAL(waypointdoubleclick(WayPointItem*)),map,SIGNAL(wpdoubleclicked(WayPointItem*)));
121 emit manualCoordChange(
this);
122 connect(map,SIGNAL(childRefreshPosition()),
this,SLOT(RefreshPos()));
123 connect(map,SIGNAL(childSetOpacity(qreal)),
this,SLOT(
setOpacitySlot(qreal)));
126 WayPointItem::WayPointItem(
const internals::PointLatLng &coord,
int const& altitude,
const QString &description, MapGraphicItem *map,wptype type):
134 this->altitude = altitude;
135 this->description = description;
140 picture.load(QString::fromUtf8(
":/markers/images/marker.png"));
141 number=WayPointItem::snumber;
142 ++WayPointItem::snumber;
143 this->setFlag(QGraphicsItem::ItemIsMovable,
true);
144 this->setFlag(QGraphicsItem::ItemIgnoresTransformations,
true);
145 this->setFlag(QGraphicsItem::ItemIsSelectable,
true);
146 SetShowNumber(shownumber);
151 foreach(QGraphicsItem * obj,list)
153 HomeItem* h=qgraphicsitem_cast <HomeItem*>(obj);
159 map->Projection()->offSetFromLatLngs(myHome->Coord(),coord,relativeCoord.distance,relativeCoord.bearing);
162 connect(
this,SIGNAL(waypointdoubleclick(WayPointItem*)),map,SIGNAL(wpdoubleclicked(WayPointItem*)));
163 emit manualCoordChange(
this);
164 connect(map,SIGNAL(childRefreshPosition()),
this,SLOT(RefreshPos()));
165 connect(map,SIGNAL(childSetOpacity(qreal)),
this,SLOT(
setOpacitySlot(qreal)));
168 WayPointItem::WayPointItem(
const distBearingAltitude &relativeCoordinates,
const QString &description, MapGraphicItem *map):
174 this->relativeCoord = relativeCoordinates;
175 this->altitude = altitude;
176 this->description = description;
180 foreach(QGraphicsItem * obj,list)
182 HomeItem* h=qgraphicsitem_cast <HomeItem*>(obj);
189 coord=map->Projection()->translate(myHome->Coord(),relativeCoord.distance,relativeCoord.bearing);
195 picture.load(QString::fromUtf8(
":/markers/images/marker.png"));
196 number=WayPointItem::snumber;
197 ++WayPointItem::snumber;
198 this->setFlag(QGraphicsItem::ItemIsMovable,
true);
199 this->setFlag(QGraphicsItem::ItemIgnoresTransformations,
true);
200 this->setFlag(QGraphicsItem::ItemIsSelectable,
true);
201 SetShowNumber(shownumber);
204 connect(
this,SIGNAL(waypointdoubleclick(WayPointItem*)),map,SIGNAL(wpdoubleclicked(WayPointItem*)));
205 emit manualCoordChange(
this);
206 connect(map,SIGNAL(childRefreshPosition()),
this,SLOT(RefreshPos()));
207 connect(map,SIGNAL(childSetOpacity(qreal)),
this,SLOT(
setOpacitySlot(qreal)));
210 void WayPointItem::setWPType(wptype type)
219 QRectF WayPointItem::boundingRect()
const
221 return QRectF(-picture.width()/2,-picture.height(),picture.width(),picture.height());
223 void WayPointItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
227 painter->drawPixmap(-picture.width()/2,-picture.height(),picture);
228 painter->setPen(Qt::green);
229 if(this->isSelected())
230 painter->drawRect(QRectF(-picture.width()/2,-picture.height(),picture.width()-1,picture.height()-1));
234 if(event->button()==Qt::LeftButton)
242 if(event->button()==Qt::LeftButton)
244 text=
new QGraphicsSimpleTextItem(
this);
245 textBG=
new QGraphicsRectItem(
this);
247 textBG->setBrush(Qt::yellow);
249 text->setPen(QPen(Qt::red));
250 text->setPos(10,-picture.height());
251 textBG->setPos(10,-picture.height());
256 QGraphicsItem::mousePressEvent(event);
260 QGraphicsItem::mouseReleaseEvent(event);
261 if(event->button()==Qt::LeftButton &&
262 event->buttonDownScenePos(Qt::LeftButton) !=
event->lastScenePos())
274 coord=map->FromLocalToLatLng(this->pos().
x(),this->pos().
y());
282 }
else if(event->button()==Qt::LeftButton) {
293 coord=map->FromLocalToLatLng(this->pos().
x(),this->pos().
y());
304 coord=map->FromLocalToLatLng(this->pos().
x(),this->pos().
y());
305 QString coord_str =
" " + QString::number(coord.
Lat(),
'f', 6) +
" " + QString::number(coord.
Lng(),
'f', 6);
311 text->setText(coord_str+
"\n"+relativeCoord_str);
312 textBG->setRect(text->boundingRect());
316 QGraphicsItem::mouseMoveEvent(event);
318 void WayPointItem::SetAltitude(
const float &value)
328 void WayPointItem::setRelativeCoord(distBearingAltitude value)
350 map->Projection()->offSetFromLatLngs(myHome->Coord(),Coord(),back.distance,back.bearing);
360 void WayPointItem::SetDescription(
const QString &value)
362 if(description==value)
369 void WayPointItem::SetNumber(
const int &value)
371 int oldnumber=number;
374 numberI->setText(QString::number(numberAdjusted()));
375 numberIBG->setRect(numberI->boundingRect().adjusted(-2,0,1,0));
379 void WayPointItem::SetReached(
const bool &value)
384 picture.load(QString::fromUtf8(
":/markers/images/bigMarkerGreen.png"));
389 if(this->flags() & QGraphicsItem::ItemIsMovable)
390 picture.load(QString::fromUtf8(
":/markers/images/marker.png"));
392 picture.load(QString::fromUtf8(
":/markers/images/waypoint_marker2.png"));
396 picture.load(QString::fromUtf8(
":/opmap/images/waypoint_marker3.png"));
402 void WayPointItem::SetShowNumber(
const bool &value)
405 if((numberI==
nullptr) && value)
407 numberI=
new QGraphicsSimpleTextItem(
this);
408 numberIBG=
new QGraphicsRectItem(
this);
409 numberIBG->setBrush(Qt::white);
410 numberIBG->setOpacity(0.5);
411 numberI->setZValue(3);
412 numberI->setPen(QPen(Qt::blue));
413 numberI->setPos(0,-13-picture.height());
414 numberIBG->setPos(0,-13-picture.height());
415 numberI->setText(QString::number(numberAdjusted()));
416 numberIBG->setRect(numberI->boundingRect().adjusted(-2,0,1,0));
418 else if (!value && numberI)
429 if(number>onumber) SetNumber(--n);
438 if(onumber<=number) SetNumber(++number);
444 Q_UNUSED(homeAltitude);
468 if(((oldnumber>number) && (newnumber<=number)))
472 else if (((oldnumber<number) && (newnumber>number)))
476 else if (newnumber==number)
482 int WayPointItem::type()
const
488 WayPointItem::~WayPointItem()
491 --WayPointItem::snumber;
496 this->setPos(point.
X(),point.
Y());
509 void WayPointItem::RefreshToolTip()
511 QString coord_str =
" " + QString::number(coord.
Lat(),
'f', 6) +
" " + QString::number(coord.
Lng(),
'f', 6);
514 setToolTip(QString(
"WayPoint Number:%1\nDescription:%2\nCoordinate:%4\nFrom Home:%5\nAltitude:%6\n%7").arg(QString::number(numberAdjusted())).arg(description).arg(coord_str).arg(relativeCoord_str).arg(QString::number(altitude)).arg(myCustomString));
516 setToolTip(QString(
"Magic WayPoint\nCoordinate:%1\nFrom Home:%2\nAltitude:%3\n\n%4").arg(coord_str).arg(relativeCoord_str).arg(QString::number(altitude)).arg(myCustomString));
519 void WayPointItem::setFlag(QGraphicsItem::GraphicsItemFlag flag,
bool enabled)
523 QGraphicsItem::setFlag(flag,enabled);
526 else if(flag==QGraphicsItem::ItemIsMovable)
529 picture.load(QString::fromUtf8(
":/markers/images/marker.png"));
531 picture.load(QString::fromUtf8(
":/markers/images/waypoint_marker2.png"));
533 QGraphicsItem::setFlag(flag,enabled);
536 int WayPointItem::snumber=0;
A graphicsItem representing a WayPoint.
A graphicsItem representing a Home Location.
A QGraphicsItem representing a WayPoint.