Files
2020-09-23 18:41:12 +08:00

156 lines
6.3 KiB
C++

/**
******************************************************************************
*
* @file waypointcircle.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief A graphicsItem representing a circle connecting 2 waypoints
* @see The GNU Public License (GPL) Version 3
* @defgroup OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "waypointcircle.h"
#include <math.h>
#include "homeitem.h"
namespace mapcontrol {
/*
WayPointCircle::WayPointCircle(WayPointItem *center, WayPointItem *radius, bool clockwise, MapGraphicItem *map, QColor color, bool dashed, int width) : QGraphicsEllipseItem(map),
my_center(center), my_radius(radius), my_map(map), myColor(color), myClockWise(clockwise), dashed(dashed), width(width)
{
connect(center, SIGNAL(localPositionChanged(QPointF, WayPointItem *)), this, SLOT(refreshLocations()));
connect(radius, SIGNAL(localPositionChanged(QPointF, WayPointItem *)), this, SLOT(refreshLocations()));
connect(center, SIGNAL(aboutToBeDeleted(WayPointItem *)), this, SLOT(waypointdeleted()));
connect(radius, SIGNAL(aboutToBeDeleted(WayPointItem *)), this, SLOT(waypointdeleted()));
refreshLocations();
connect(map, SIGNAL(childSetOpacity(qreal)), this, SLOT(setOpacitySlot(qreal)));
}
WayPointCircle::WayPointCircle(HomeItem *radius, WayPointItem *center, bool clockwise, MapGraphicItem *map, QColor color, bool dashed, int width) : QGraphicsEllipseItem(map),
my_center(center), my_radius(radius), my_map(map), myColor(color), myClockWise(clockwise), dashed(dashed), width(width)
{
connect(radius, SIGNAL(homePositionChanged(internals::PointLatLng, float)), this, SLOT(refreshLocations()));
connect(center, SIGNAL(localPositionChanged(QPointF)), this, SLOT(refreshLocations()));
connect(center, SIGNAL(aboutToBeDeleted(WayPointItem *)), this, SLOT(waypointdeleted()));
refreshLocations();
connect(map, SIGNAL(childSetOpacity(qreal)), this, SLOT(setOpacitySlot(qreal)));
}
*/
WayPointCircle::WayPointCircle(WayPointItem *center, double radius, bool clockwise, MapGraphicItem *map, QColor color, bool dashed, int width) : QGraphicsEllipseItem(map),
my_center(center), my_radius(NULL), my_map(map), myColor(color), myClockWise(clockwise), dashed(dashed), width(width)
{
s_radius = radius;
connect(center, SIGNAL(localPositionChanged(QPointF, WayPointItem *)), this, SLOT(refreshLocations()));
//connect(radius, SIGNAL(localPositionChanged(QPointF, WayPointItem *)), this, SLOT(refreshLocations()));
connect(center, SIGNAL(aboutToBeDeleted(WayPointItem *)), this, SLOT(waypointdeleted()));
//connect(radius, SIGNAL(aboutToBeDeleted(WayPointItem *)), this, SLOT(waypointdeleted()));
refreshLocations();
connect(map, SIGNAL(childSetOpacity(qreal)), this, SLOT(setOpacitySlot(qreal)));
}
WayPointCircle::WayPointCircle(HomeItem *center, double radius, bool clockwise, MapGraphicItem *map, QColor color, bool dashed, int width) : QGraphicsEllipseItem(map),
my_center(center), my_radius(NULL), my_map(map), myColor(color), myClockWise(clockwise), dashed(dashed), width(width)
{
s_radius = radius;
connect(center, SIGNAL(localPositionChanged(QPointF, WayPointItem *)), this, SLOT(refreshLocations()));
//connect(radius, SIGNAL(localPositionChanged(QPointF, WayPointItem *)), this, SLOT(refreshLocations()));
connect(center, SIGNAL(aboutToBeDeleted(WayPointItem *)), this, SLOT(waypointdeleted()));
//connect(radius, SIGNAL(aboutToBeDeleted(WayPointItem *)), this, SLOT(waypointdeleted()));
refreshLocations();
connect(map, SIGNAL(childSetOpacity(qreal)), this, SLOT(setOpacitySlot(qreal)));
}
int WayPointCircle::type() const
{
// Enable the use of qgraphicsitem_cast with this item.
return Type;
}
void WayPointCircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
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 = pen();
myPen.setColor(myColor);
if (width > 0) {
myPen.setWidth(width);
}
if (dashed) {
QVector<qreal> dashes;
dashes << 4 << 8;
myPen.setDashPattern(dashes);
}
painter->setPen(myPen);
QBrush brush = painter->brush();
painter->setBrush(myColor);
double angle = 0;
if (!myClockWise) {
angle += M_PI;
}
painter->translate(-line.length(), -line.length());
painter->setBrush(brush);
painter->drawEllipse(this->rect());
}
void WayPointCircle::refreshLocations()
{
//qDebug() << my_center->pos();
internals::PointLatLng C;
C = my_map->FromLocalToLatLng(my_center->x(),my_center->y());
C.SetLat(C.Lat() + s_radius/111133.3333f);
//float R = my_center->pos().-;
/*qDebug() << my_center->pos()
<< my_map->FromLatLngToLocal(C).X()
<< my_map->FromLatLngToLocal(C).Y()
<< C.Lat()
<< C.Lng();
*/
line = QLineF(my_center->pos().x(),my_center->pos().y(),my_center->pos().x(),my_map->FromLatLngToLocal(C).Y());
this->setRect(my_center->pos().x(), my_center->pos().y(), 2 * line.length(), 2 * line.length());
this->update();
}
void WayPointCircle::waypointdeleted()
{
this->deleteLater();
}
void WayPointCircle::setOpacitySlot(qreal opacity)
{
setOpacity(opacity);
}
}