1 #ifndef WAYPOINTITEM_H 2 #define WAYPOINTITEM_H 3 4 #include "common/config.h" 5 #include <cmath> 6 #include <QGraphicsItem> 7 #include <QFont> 8 #ifdef ENABLE_TIMEZONES 9 #include <QTimeZone> 10 #endif // ENABLE_TIMEZONES 11 #include "data/waypoint.h" 12 #include "map/map.h" 13 #include "units.h" 14 #include "graphicsscene.h" 15 #include "format.h" 16 17 18 class WaypointItem : public GraphicsItem 19 { 20 public: 21 WaypointItem(const Waypoint &waypoint, Map *map, QGraphicsItem *parent = 0); 22 waypoint()23 const Waypoint &waypoint() const {return _waypoint;} 24 setMap(Map * map)25 void setMap(Map *map) {setPos(map->ll2xy(_waypoint.coordinates()));} 26 void setSize(int size); 27 void setColor(const QColor &color); 28 void showLabel(bool show); setDigitalZoom(int zoom)29 void setDigitalZoom(int zoom) {setScale(pow(2, -zoom));} 30 shape()31 QPainterPath shape() const {return _shape;} boundingRect()32 QRectF boundingRect() const {return _shape.boundingRect();} 33 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, 34 QWidget *widget); 35 36 QString info() const; 37 setUnits(Units units)38 static void setUnits(Units units) {_units = units;} setCoordinatesFormat(CoordinatesFormat format)39 static void setCoordinatesFormat(CoordinatesFormat format) 40 {_format = format;} 41 #ifdef ENABLE_TIMEZONES setTimeZone(const QTimeZone & zone)42 static void setTimeZone(const QTimeZone &zone) {_timeZone = zone;} 43 #endif // ENABLE_TIMEZONES 44 45 protected: 46 void hoverEnterEvent(QGraphicsSceneHoverEvent *event); 47 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); 48 void mousePressEvent(QGraphicsSceneMouseEvent *event); 49 50 private: 51 void updateCache(); 52 53 Waypoint _waypoint; 54 QPainterPath _shape; 55 QColor _color; 56 int _size; 57 bool _showLabel; 58 QFont _font; 59 QRect _labelBB; 60 61 static Units _units; 62 static CoordinatesFormat _format; 63 #ifdef ENABLE_TIMEZONES 64 static QTimeZone _timeZone; 65 #endif // ENABLE_TIMEZONES 66 }; 67 68 #endif // WAYPOINTITEM_H 69