You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.6 KiB
92 lines
2.6 KiB
14 years ago
|
#include "waypointlineitem.h"
|
||
|
|
||
14 years ago
|
namespace mapcontrol
|
||
14 years ago
|
{
|
||
14 years ago
|
WaypointLineItem::WaypointLineItem(WayPointItem* wp1, WayPointItem* wp2, QColor color, mapcontrol::MapGraphicItem* map) :
|
||
14 years ago
|
QGraphicsLineItem(map),
|
||
14 years ago
|
wp1(wp1),
|
||
|
wp2(wp2),
|
||
|
map(map)
|
||
|
{
|
||
14 years ago
|
// Make sure this stick to the map
|
||
14 years ago
|
//this->setFlag(QGraphicsItem::Item,true);
|
||
14 years ago
|
setParentItem(map);
|
||
14 years ago
|
|
||
14 years ago
|
// Set up the pen for this icon with the UAV color
|
||
14 years ago
|
QPen pen(color);
|
||
|
pen.setWidth(2);
|
||
|
setPen(pen);
|
||
|
|
||
14 years ago
|
point1 = wp1->Coord();
|
||
|
point2 = wp2->Coord();
|
||
|
|
||
14 years ago
|
// Pixel coordinates of the local points
|
||
|
core::Point localPoint1 = map->FromLatLngToLocal(wp1->Coord());
|
||
|
core::Point localPoint2 = map->FromLatLngToLocal(wp2->Coord());
|
||
|
// Draw line
|
||
14 years ago
|
setLine(localPoint1.X(), localPoint1.Y(), localPoint2.X(), localPoint2.Y());
|
||
|
|
||
14 years ago
|
// Connect updates
|
||
14 years ago
|
// Update line from both waypoints
|
||
|
connect(wp1, SIGNAL(WPValuesChanged(WayPointItem*)), this, SLOT(updateWPValues(WayPointItem*)));
|
||
|
connect(wp2, SIGNAL(WPValuesChanged(WayPointItem*)), this, SLOT(updateWPValues(WayPointItem*)));
|
||
|
// Delete line if one of the waypoints get deleted
|
||
|
connect(wp1, SIGNAL(destroyed()), this, SLOT(deleteLater()));
|
||
|
connect(wp2, SIGNAL(destroyed()), this, SLOT(deleteLater()));
|
||
14 years ago
|
|
||
|
// Map Zoom and move
|
||
14 years ago
|
connect(map, SIGNAL(mapChanged()), this, SLOT(updateWPValues()));
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
void WaypointLineItem::RefreshPos()
|
||
|
{
|
||
|
// Delete if either waypoint got deleted
|
||
|
if (!wp1 || !wp2)
|
||
|
{
|
||
|
this->deleteLater();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// Set new pixel coordinates based on new global coordinates
|
||
14 years ago
|
//QTimer::singleShot(0, this, SLOT(updateWPValues()));
|
||
|
core::Point localPoint1 = map->FromLatLngToLocal(point1);
|
||
|
core::Point localPoint2 = map->FromLatLngToLocal(point2);
|
||
|
if (!localPoint1.IsEmpty() && !localPoint2.IsEmpty())
|
||
|
{
|
||
|
setLine(localPoint1.X(), localPoint1.Y(), localPoint2.X(), localPoint2.Y());
|
||
|
}
|
||
14 years ago
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void WaypointLineItem::updateWPValues(WayPointItem* waypoint)
|
||
|
{
|
||
|
Q_UNUSED(waypoint);
|
||
14 years ago
|
// Delete if either waypoint got deleted
|
||
14 years ago
|
if (!wp1 || !wp2)
|
||
|
{
|
||
|
this->deleteLater();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
14 years ago
|
// Set new pixel coordinates based on new global coordinates
|
||
14 years ago
|
point1 = wp1->Coord();
|
||
|
point2 = wp2->Coord();
|
||
14 years ago
|
core::Point localPoint1 = map->FromLatLngToLocal(wp1->Coord());
|
||
|
core::Point localPoint2 = map->FromLatLngToLocal(wp2->Coord());
|
||
|
|
||
|
setLine(localPoint1.X(), localPoint1.Y(), localPoint2.X(), localPoint2.Y());
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void WaypointLineItem::updateWPValues()
|
||
|
{
|
||
|
updateWPValues(NULL);
|
||
|
}
|
||
|
|
||
14 years ago
|
int WaypointLineItem::type()const
|
||
|
{
|
||
|
return Type;
|
||
|
}
|
||
|
|
||
14 years ago
|
}
|