110 lines
2.6 KiB
C++
110 lines
2.6 KiB
C++
#include "geoFencecircle.h"
|
|
#include <QDateTime>
|
|
namespace mapcontrol {
|
|
/*
|
|
geoFencecircle::geoFencecircle(int group, bool inclusion, int version, geoFenceitem *center, double radius, QBrush color, MapGraphicItem *map, bool dashed, int width) :
|
|
QGraphicsEllipseItem(map),m_center(center), coord(center->coord), m_brush(color), m_map(map),dashed(dashed),lineWidth(width)
|
|
*/
|
|
|
|
geoFencecircle::geoFencecircle(int group, bool inclusion, int version, internals::PointLatLng const ¢er, double radius, QBrush color, MapGraphicItem *map, bool dashed, int width) :
|
|
QGraphicsEllipseItem(map),m_center(center), coord(center), m_brush(color), m_map(map),dashed(dashed),lineWidth(width)
|
|
|
|
{
|
|
|
|
this->setZValue(3);
|
|
|
|
m_version = version;
|
|
m_inclusion = inclusion;
|
|
m_radius = radius;
|
|
m_group = group; //2
|
|
m_latitude = coord.Lat();//5
|
|
m_longitide = coord.Lng();//6
|
|
|
|
connect(map, SIGNAL(childRefreshPosition()), this, SLOT(refreshLocations()));
|
|
refreshLocations();
|
|
}
|
|
|
|
|
|
int geoFencecircle::type() const
|
|
{
|
|
return Type;
|
|
}
|
|
|
|
void geoFencecircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
{
|
|
Q_UNUSED(option);
|
|
Q_UNUSED(widget);
|
|
|
|
painter->setOpacity(0.4);
|
|
|
|
QPointF p1;
|
|
QPointF p2;
|
|
p1 = QPointF(line.p1().x(), line.p1().y() + line.length());
|
|
p2 = QPointF(line.p1().x(), line.p1().y() - line.length());
|
|
QPen myPen = painter->pen();
|
|
myPen.setWidth(lineWidth);
|
|
myPen.setColor(m_brush.color());
|
|
painter->setPen(myPen);
|
|
|
|
|
|
if (dashed) {
|
|
QVector<qreal> dashes;
|
|
dashes << 4 << 8;
|
|
myPen.setDashPattern(dashes);
|
|
}
|
|
|
|
|
|
//painter->translate(-line.length(), -line.length());
|
|
|
|
|
|
if(m_inclusion)
|
|
{
|
|
painter->setBrush(m_brush);
|
|
}
|
|
else
|
|
{
|
|
painter->setBrush(Qt::NoBrush);
|
|
}
|
|
|
|
painter->drawPoint(0, 0);
|
|
//painter->drawEllipse(QPointF(0,0),line.length(),line.length());
|
|
painter->drawEllipse(rectangle);
|
|
|
|
}
|
|
|
|
void geoFencecircle::refreshLocations()
|
|
{
|
|
QPointF p(m_map->FromLatLngToLocal(this->coord).X(),
|
|
m_map->FromLatLngToLocal(this->coord).Y());
|
|
|
|
internals::PointLatLng C;
|
|
C = coord;
|
|
C.SetLat(coord.Lat() + m_radius/111133.3333f);
|
|
|
|
line = QLineF(p.x(),p.y(),p.x(),m_map->FromLatLngToLocal(C).Y());
|
|
|
|
rectangle.setRect(-line.length(),-line.length(), 2 * line.length(), 2 * line.length());
|
|
|
|
qDebug() << line << rectangle << C.Lat() << C.Lng() << m_radius;
|
|
|
|
setPos(p);
|
|
update();
|
|
}
|
|
|
|
void geoFencecircle::waypointdeleted()
|
|
{
|
|
this->deleteLater();
|
|
}
|
|
|
|
void geoFencecircle::setOpacitySlot(qreal opacity)
|
|
{
|
|
setOpacity(opacity);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|