dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
mapcircle.cpp
Go to the documentation of this file.
1 
13 /*
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, see <http://www.gnu.org/licenses/>
26 */
27 #include "mapcircle.h"
28 #include <math.h>
29 #include "homeitem.h"
30 #include "mappointitem.h"
31 
32 namespace mapcontrol
33 {
34 MapCircle::MapCircle(MapPointItem *center, MapPointItem *radius, bool clockwise, MapGraphicItem *map, QColor color) :
35  QGraphicsEllipseItem(map), my_center(center), my_radius(radius),
36  my_map(map), myColor(color), myClockWise(clockwise)
37 {
38  connect(center, SIGNAL(relativePositionChanged(QPointF, WayPointItem*)), this, SLOT(refreshLocations()));
39  connect(radius, SIGNAL(relativePositionChanged(QPointF, WayPointItem*)), this, SLOT(refreshLocations()));
40  connect(center, SIGNAL(aboutToBeDeleted(MapPointItem*)), this, SLOT(pointdeleted()));
41  connect(radius, SIGNAL(aboutToBeDeleted(MapPointItem*)), this, SLOT(pointdeleted()));
42  refreshLocations();
43  connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal)));
44 }
45 
46 MapCircle::MapCircle(HomeItem *center, MapPointItem *radius, bool clockwise, MapGraphicItem *map, QColor color) :
47  QGraphicsEllipseItem(map), my_center(center), my_radius(radius),
48  my_map(map), myColor(color), myClockWise(clockwise)
49 {
50  connect(center, SIGNAL(absolutePositionChanged(internals::PointLatLng, float)), this, SLOT(refreshLocations()));
51  connect(radius, SIGNAL(relativePositionChanged(QPointF)), this, SLOT(refreshLocations()));
52  connect(radius, SIGNAL(aboutToBeDeleted(MapPointItem*)), this, SLOT(pointdeleted()));
53  refreshLocations();
54  connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal)));
55 }
56 
57 int MapCircle::type() const
58 {
59  // Enable the use of qgraphicsitem_cast with this item.
60  return Type;
61 }
62 
63 void MapCircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
64 {
65  Q_UNUSED(option);
66  Q_UNUSED(widget);
67 
68  QPointF p1;
69  QPointF p2;
70  p1=QPointF(line.p1().x(),line.p1().y()+line.length());
71  p2=QPointF(line.p1().x(),line.p1().y()-line.length());
72  QPen myPen = pen();
73  myPen.setColor(myColor);
74  qreal arrowSize = 10;
75  painter->setPen(myPen);
76  QBrush brush=painter->brush();
77  painter->setBrush(myColor);
78  double angle =0;
79  if(!myClockWise)
80  angle+=M_PI;
81 
82  QPointF arrowP1 = p1 + QPointF(sin(angle + M_PI / 3) * arrowSize,
83  cos(angle + M_PI / 3) * arrowSize);
84  QPointF arrowP2 = p1 + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize,
85  cos(angle + M_PI - M_PI / 3) * arrowSize);
86 
87  QPointF arrowP21 = p2 + QPointF(sin(angle + M_PI + M_PI / 3) * arrowSize,
88  cos(angle + M_PI + M_PI / 3) * arrowSize);
89  QPointF arrowP22 = p2 + QPointF(sin(angle + M_PI + M_PI - M_PI / 3) * arrowSize,
90  cos(angle + M_PI + M_PI - M_PI / 3) * arrowSize);
91 
92  arrowHead.clear();
93  arrowHead << p1 << arrowP1 << arrowP2;
94  painter->drawPolygon(arrowHead);
95  arrowHead.clear();
96  arrowHead << p2 << arrowP21 << arrowP22;
97  painter->drawPolygon(arrowHead);
98  painter->translate(-line.length(),-line.length());
99  painter->setBrush(brush);
100  painter->drawEllipse(this->rect());
101 
102 }
103 
105 {
106  line=QLineF(my_center->pos(),my_radius->pos());
107  this->setRect(my_center->pos().x(),my_center->pos().y(),2*line.length(),2*line.length());
108  this->update();
109 }
110 
112 {
113  this->deleteLater();
114 }
115 
116 void MapCircle::setOpacitySlot(qreal opacity)
117 {
118  setOpacity(opacity);
119 }
120 
121 }
void relativePositionChanged(QPointF point, MapPointItem *mappoint)
void absolutePositionChanged(internals::PointLatLng coord, float altitude)
void setOpacitySlot(qreal opacity)
Definition: mapcircle.cpp:116
void aboutToBeDeleted(MapPointItem *)
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Definition: mapcircle.cpp:63
A graphicsItem representing a MapPointItem.
A graphicsItem representing a Home Location.
void setOpacitySlot(qreal opacity)
Definition: homeitem.cpp:114
A graphicsItem representing a circle connecting 2 map point.