42 WayPointCurve::WayPointCurve(WayPointItem *start, WayPointItem *dest,
double radius,
bool clockwise, MapGraphicItem *map,QColor color) :
43 QGraphicsEllipseItem(map), m_start(start), m_dest(dest), m_radius(radius),
44 m_clockwise(clockwise), my_map(map),myColor(color)
46 connect(start, SIGNAL(relativePositionChanged(QPointF, MapPointItem*)),
this, SLOT(refreshLocations()));
47 connect(dest, SIGNAL(relativePositionChanged(QPointF, MapPointItem*)),
this, SLOT(refreshLocations()));
48 connect(start,SIGNAL(aboutToBeDeleted(MapPointItem*)),
this,SLOT(waypointdeleted()));
49 connect(dest,SIGNAL(aboutToBeDeleted(MapPointItem*)),
this,SLOT(waypointdeleted()));
51 connect(map,SIGNAL(childSetOpacity(qreal)),
this,SLOT(setOpacitySlot(qreal)));
56 int WayPointCurve::type()
const
72 myPen.setColor(myColor);
73 painter->setPen(myPen);
74 painter->setBrush(myColor);
77 QBrush brush=painter->brush();
79 QPointF arrowP1 = midpoint + QPointF(sin(midpoint_angle + M_PI / 3) * arrowSize,
80 cos(midpoint_angle + M_PI / 3) * arrowSize);
81 QPointF arrowP2 = midpoint + QPointF(sin(midpoint_angle + M_PI - M_PI / 3) * arrowSize,
82 cos(midpoint_angle + M_PI - M_PI / 3) * arrowSize);
85 arrowHead << midpoint << arrowP1 << arrowP2;
86 painter->drawPolygon(arrowHead);
87 painter->setBrush(brush);
88 painter->drawArc(this->rect(), this->startAngle(), this->spanAngle());
97 double m_n, m_e, p_n, p_e, d, center_x, center_y, midpoint_x, midpoint_y;
100 m_n = (m_start->pos().x() + m_dest->pos().x()) / 2;
101 m_e = (m_start->pos().y() + m_dest->pos().y()) / 2;
105 p_n = -(m_dest->pos().y() - m_start->pos().y());
106 p_e = (m_dest->pos().x() - m_start->pos().x());
108 p_n = (m_dest->pos().y() - m_start->pos().y());
109 p_e = -(m_dest->pos().x() - m_start->pos().x());
112 double radius_sign = (m_radius > 0) ? 1 : -1;
113 double pixels2meters = my_map->Projection()->
GetGroundResolution(my_map->ZoomTotal(), m_start->Coord().Lat());
114 double radius = fabs(m_radius / pixels2meters);
117 d = sqrt(radius * radius / (p_n * p_n + p_e * p_e) - 0.25f);
119 if ((fabs(p_n) < 1
e-3 && fabs(p_e) < 1
e-3) || ((d == d) ==
false)) {
127 center_x = m_n + p_n * d * radius_sign;
128 center_y = m_e + p_e * d * radius_sign;
130 d = sqrt(radius * radius / (p_n * p_n + p_e * p_e));
131 midpoint_x = center_x - p_n * d;
132 midpoint_y = center_y - p_e * d;
136 center.setX(center_x);
137 center.setY(center_y);
138 midpoint.setX(midpoint_x);
139 midpoint.setY(midpoint_y);
142 midpoint_angle = -atan2(m_dest->pos().y() - m_start->pos().y(), m_dest->pos().x() - m_start->pos().x());
144 double startAngle = atan2(-(m_start->pos().y() - center_y), m_start->pos().x() - center_x);
145 double endAngle = atan2(-(m_dest->pos().y() - center_y), m_dest->pos().x() - center_x);
146 double span = endAngle - startAngle;
149 span = span - 2 * M_PI;
152 span = span + 2 * M_PI;
154 setRect(center_x - radius, center_y - radius, 2 * radius, 2 * radius);
155 setStartAngle(startAngle * 180.0 / M_PI * 16.0);
156 setSpanAngle(span * 180.0 / M_PI * 16.0);
A graphicsItem representing a Home Location.
A graphicsItem representing a curve connecting 2 waypoints.