33 MapLine::MapLine(MapPointItem *from, MapPointItem *to, MapGraphicItem *map, QColor color) :
34 QGraphicsLineItem(map), source(from), destination(to), my_map(map), myColor(color)
36 this->setLine(to->pos().x(),to->pos().y(),from->pos().x(),from->pos().y());
37 connect(from, SIGNAL(relativePositionChanged(QPointF, MapPointItem*)),
this, SLOT(refreshLocations()));
38 connect(to, SIGNAL(relativePositionChanged(QPointF, MapPointItem*)),
this, SLOT(refreshLocations()));
39 connect(from, SIGNAL(aboutToBeDeleted(MapPointItem*)),
this, SLOT(pointdeleted()));
40 connect(to, SIGNAL(aboutToBeDeleted(MapPointItem*)),
this, SLOT(pointdeleted()));
41 if(myColor==Qt::green)
43 else if(myColor==Qt::yellow)
45 else if(myColor==Qt::red)
47 connect(map,SIGNAL(
childSetOpacity(qreal)),
this,SLOT(setOpacitySlot(qreal)));
50 MapLine::MapLine(HomeItem *from, MapPointItem *to, MapGraphicItem *map, QColor color) :
51 QGraphicsLineItem(map), source(from), destination(to), my_map(map), myColor(color)
53 this->setLine(to->pos().x(),to->pos().y(),from->pos().x(),from->pos().y());
54 connect(from, SIGNAL(absolutePositionChanged(
internals::PointLatLng,
float)),
this, SLOT(refreshLocations()));
55 connect(to, SIGNAL(relativePositionChanged(QPointF, MapPointItem*)),
this, SLOT(refreshLocations()));
56 connect(to, SIGNAL(aboutToBeDeleted(MapPointItem*)),
this, SLOT(pointdeleted()));
57 if(myColor==Qt::green)
59 else if(myColor==Qt::yellow)
61 else if(myColor==Qt::red)
63 connect(map,SIGNAL(
childSetOpacity(qreal)),
this,SLOT(setOpacitySlot(qreal)));
66 int MapLine::type()
const
72 QPainterPath MapLine::shape()
const
74 QPainterPath path = QGraphicsLineItem::shape();
75 path.addPolygon(arrowHead);
79 void MapLine::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
85 myPen.setColor(myColor);
87 painter->setPen(myPen);
88 painter->setBrush(myColor);
91 double angle = (fabs(line().length()) < 1
e-3) ? 0 : ::acos(line().dx() / line().length());
94 angle = (M_PI * 2) - angle;
96 QPointF arrowP1 = line().pointAt(0.5) + QPointF(sin(angle + M_PI / 3) * arrowSize,
97 cos(angle + M_PI / 3) * arrowSize);
98 QPointF arrowP2 = line().pointAt(0.5) + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize,
99 cos(angle + M_PI - M_PI / 3) * arrowSize);
101 arrowHead << line().pointAt(0.5) << arrowP1 << arrowP2;
103 painter->drawPolygon(arrowHead);
106 else if(myColor==Qt::yellow)
108 else if(myColor==Qt::green)
110 painter->setPen(myPen);
111 painter->drawLine(line());
116 this->setLine(destination->pos().x(),destination->pos().y(),source->pos().x(),source->pos().y());
A graphicsItem representing a line connecting 2 map points.
A graphicsItem representing a Home Location.