Files
gcs-nf/opmap/mapwidget/geoFenceitemline.cpp
T
2022-05-11 15:12:08 +08:00

107 lines
2.3 KiB
C++

#include "geoFenceitemline.h"
#include <math.h>
namespace mapcontrol {
geoFenceitemline::geoFenceitemline(geoFenceitem *from, geoFenceitem *to, MapGraphicItem *map, QColor color, bool dashed, int width ) : QGraphicsLineItem(map),
source(from), destination(to), my_map(map), myColor(color), dashed(dashed), lineWidth(width)
{
this->setLine(from->pos().x(), from->pos().y(), to->pos().x(), to->pos().y());
connect(from, SIGNAL(localPositionChanged(QPointF, geoFenceitem *)), this, SLOT(refreshLocations()));
connect(to, SIGNAL(localPositionChanged(QPointF, geoFenceitem *)), this, SLOT(refreshLocations()));
connect(from, SIGNAL(aboutToBeDeleted(geoFenceitem *)), this, SLOT(waypointdeleted()));
connect(to, SIGNAL(aboutToBeDeleted(geoFenceitem *)), this, SLOT(waypointdeleted()));
this->setZValue(3);
connect(map, SIGNAL(childSetOpacity(qreal)), this, SLOT(setOpacitySlot(qreal)));
isEdit = true;
}
int geoFenceitemline::type() const
{
// Enable the use of qgraphicsitem_cast with this item.
return Type;
}
QPainterPath geoFenceitemline::shape() const
{
QPainterPath path = QGraphicsLineItem::shape();
path.addPolygon(arrowHead);
return path;
}
void geoFenceitemline::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
QPen myPen = pen();
myPen.setColor(myColor);
painter->setPen(myPen);
double angle = ::acos(line().dx() / line().length());
if (line().dy() >= 0) {
angle = (M_PI * 2) - angle;
}
if (dashed) {
QVector<qreal> dashes;
dashes << 4 << 8;
myPen.setDashPattern(dashes);
}
myPen.setWidth(lineWidth);
painter->setPen(myPen);
painter->drawLine(line());
}
void geoFenceitemline::setEdit(bool value)
{
isEdit = value;
}
void geoFenceitemline::refreshLocations()
{
//qDebug() << "reflush location";
this->setLine(source->pos().x(), source->pos().y(),
destination->pos().x(), destination->pos().y());
}
void geoFenceitemline::waypointdeleted()
{
this->deleteLater();
}
void geoFenceitemline::WPLinedelete(geoFenceitem *from, geoFenceitem *to)
{
Q_UNUSED(from)
Q_UNUSED(to)
this->deleteLater();
}
void geoFenceitemline::setOpacitySlot(qreal opacity)
{
setOpacity(opacity);
}
}