forked from OlivierDelbeke/MapGraphics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapGraphicsObject.h
More file actions
170 lines (129 loc) · 4.66 KB
/
Copy pathMapGraphicsObject.h
File metadata and controls
170 lines (129 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#ifndef MAPGRAPHICSOBJECT_H
#define MAPGRAPHICSOBJECT_H
#include <QObject>
#include <QPointF>
#include <QRectF>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QGraphicsSceneContextMenuEvent>
#include <QGraphicsItem>
#include <QString>
#include "MapGraphics_global.h"
class MAPGRAPHICSSHARED_EXPORT MapGraphicsObject : public QObject
{
Q_OBJECT
public:
enum MapGraphicsObjectFlag
{
ObjectIsMovable = 0x01,
ObjectIsSelectable = 0x02,
ObjectIsFocusable = 0x04
};
Q_DECLARE_FLAGS(MapGraphicsObjectFlags,MapGraphicsObjectFlag)
//PrivateQGraphicsObject will call some of our protected event handlers that nobody else needs to touch
friend class PrivateQGraphicsObject;
public:
explicit MapGraphicsObject(bool sizeIsZoomInvariant=false,MapGraphicsObject *parent = 0);
virtual ~MapGraphicsObject();
bool sizeIsZoomInvariant() const;
/*!
\brief You need to implement this. If sizeIsZoomInvariant() is true, this should return the size of the
rectangle you want in PIXELS. If false, this should return the size of the rectangle in METERS. The
rectangle should be centered at (0,0) regardless.
\return QRectF
*/
virtual QRectF boundingRect() const=0;
/*!
\brief You can reimplement this if you want. Given a point in geographic coordinates (lat/lon),
return true if the object contains that point. Return false otherwise. The default implementation just uses
boundingRect() to decide.
\param geoPos
\return bool
*/
virtual bool contains(const QPointF& geoPos) const;
/**
* @brief Paints the contents of the Object in ENU coordinates if the object is not zoom invariant.
* If it is zoom invariant, the units are pixels. That is, this painter should operate in the same
* units as returned by boundingRect().
* You must implement this.
*
* @param painter
* @param option
* @param widget
*/
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget=0)=0;
bool enabled() const;
void setEnabled(bool);
qreal opacity() const;
void setOpacity(qreal);
MapGraphicsObject * parent() const;
void setParent(MapGraphicsObject *);
const QPointF& pos() const;
virtual void setPos(const QPointF&);
qreal rotation() const;
void setRotation(qreal);
bool visible() const;
void setVisible(bool);
qreal longitude() const;
void setLongitude(qreal);
qreal latitude() const;
void setLatitude(qreal);
qreal zValue() const;
void setZValue(qreal);
bool isSelected() const;
void setSelected(bool);
QString toolTip() const;
void setToolTip(const QString& toolTip);
void setFlag(MapGraphicsObjectFlag, bool enabled=true);
void setFlags(MapGraphicsObject::MapGraphicsObjectFlags);
MapGraphicsObject::MapGraphicsObjectFlags flags() const;
protected:
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent * event);
virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant& value);
virtual void keyPressEvent(QKeyEvent * event);
virtual void keyReleaseEvent(QKeyEvent * event);
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
virtual void mousePressEvent(QGraphicsSceneMouseEvent * event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
virtual void wheelEvent(QGraphicsSceneWheelEvent * event);
signals:
void enabledChanged();
void opacityChanged();
void parentChanged();
void posChanged();
void rotationChanged();
void visibleChanged();
void zValueChanged();
void toolTipChanged(const QString& toolTip);
void flagsChanged();
//Please do not use this for now. It should only be used internally for now. Ugly, I know.
void selectedChanged();
void newObjectGenerated(MapGraphicsObject *);
/*!
\brief Emitted when we'd like to be redrawn
*/
void redrawRequested();
/*!
\brief Emitted when this MapGraphicsObject wants keyboard focus. (to receive keyboard events)
*/
void keyFocusRequested();
public slots:
private slots:
void setConstructed();
private:
bool _sizeIsZoomInvariant;
bool _enabled;
qreal _opacity;
MapGraphicsObject * _parent;
QPointF _pos;
qreal _rotation;
bool _visible;
qreal _zValue;
bool _selected;
QString _toolTip;
MapGraphicsObject::MapGraphicsObjectFlags _flags;
bool _constructed;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(MapGraphicsObject::MapGraphicsObjectFlags)
#endif // MAPGRAPHICSOBJECT_H