Newer
Older
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef POINT_H
#define POINT_H
#include <QWidget>
#include "geometry.h"
namespace qmapcontrol
{
//! A geometric point to draw objects into maps
/*!
* This class can be used to draw your custom QPixmap or other QWidgets into maps.
* You can instantiate a Point with any Pixmap you want. The objects cares about collision detection (for clickable objects)
*
* When drawing a pixmap, take care you are adding the point to a GeometryLayer.
* You can also add a point to a MapLayer, but this should only be done, if the point is not changing its position or color etc.
* (GeometryLayers are assured to be repainted on any changes at the point. MapLayers only gets repainted, if a new
* offscreenImage is painter. This is a performance issue.)
*
* Points emit click events, if the containing layer receives clickevents (the default)
*
* You can also add a widget into maps. But keep in mind, that widgets always are drawn on top of all layers.
* You also have to handle click events yourself.
*
* To create "zoomable objects" (objects that increases size on zooming), a base level have to be set.
* The base level is the zoom level on which the point´s pixmap gets displayed on full size.
* On lower zoom levels it gets displayed smaller and on higher zoom levels larger.
* A minimal size can be set as well as a maximum size.
* @see setBaselevel, setMinsize, setMaxsize
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class Point : public Geometry
{
Q_OBJECT
public:
friend class Layer;
friend class LineString;
//! sets where the point should be aligned
enum Alignment
{
TopLeft, /*!< Align on TopLeft*/
TopRight, /*!< Align on TopRight*/
BottomLeft, /*!< Align on BottomLeft*/
BottomRight,/*!< Align on BottomRight*/
Middle /*!< Align on Middle*/
};
Point();
explicit Point(const Point&);
//! Copy Constructor
/*!
* This constructor creates a Point with no image or widget.
* @param x longitude
* @param y latitude
* @param name name of the point
* @param alignment allignment of the point (Middle or TopLeft)
*/
Point(qreal x, qreal y, QString name = QString(), enum Alignment alignment=Middle);
//! Constructor
/*!
* This constructor creates a point which will display the given widget.
* You can set an alignment on which corner the widget should be aligned to the coordinate.
* You have to set the size of the widget, before adding it to
* IMPORTANT: You have to set the QMapControl as parent for the widget!
* @param x longitude
* @param y latitude
* @param widget the widget which should be displayed by this point
* @param name name of the point
* @param alignment allignment of the point (Middle or TopLeft)
*/
Point(qreal x, qreal y, QWidget* widget, QString name = QString(), enum Alignment alignment = Middle);
//! Constructor
/*!
* This constructor creates a point which will display the give pixmap.
* You can set an alignment on which corner the pixmap should be aligned to the coordinate.
* @param x longitude
* @param y latitude
* @param pixmap the pixmap which should be displayed by this point
* @param name name of the point
* @param alignment allignment of the point (Middle or TopLeft)
*/
Point(qreal x, qreal y, QPixmap* pixmap, QString name = QString(), enum Alignment alignment = Middle);
virtual ~Point();
//! returns the bounding box of the point
/*!
* The Bounding contains the coordinate of the point and its size.
* The size is set, if the point contains a pixmap or a widget
* @return the bounding box of the point
*/
virtual QRectF boundingBox();
//! returns the longitude of the point
/*!
* @return the longitude of the point
*/
qreal longitude() const;
//! returns the latitude of the point
/*!
* @return the latitude of the point
*/
qreal latitude() const;
//! returns the coordinate of the point
/*!
* The x component of the returned QPointF is the longitude value,
* the y component the latitude
* @return the coordinate of a point
*/
QPointF coordinate() const;
virtual QList<Point*> points();
/*! \brief returns the widget of the point
@return the widget of the point
*/
QWidget* widget();
//! returns the pixmap of the point
/*!
* @return the pixmap of the point
*/
QPixmap* pixmap();
//! Sets the zoom level on which the point�s pixmap gets displayed on full size
/*!
* Use this method to set a zoom level on which the pixmap gets displayed with its real size.
* On zoomlevels below it will be displayed smaller, and on zoom levels thereover it will be displayed larger
* @see setMinsize, setMaxsize
* @param zoomlevel the zoomlevel on which the point will be displayed on full size
*/
void setBaselevel(int zoomlevel);
//! sets a minimal size for the pixmap
/*!
* When the point's pixmap should change its size on zooming, this method sets the minimal size.
* @see setBaselevel
* @param minsize the minimal size which the pixmap should have
*/
void setMinsize(QSize minsize);
//! sets a maximal size for the pixmap
/*!
* When the point´s pixmap should change its size on zooming, this method sets the maximal size.
* @see setBaselevel
* @param maxsize the maximal size which the pixmap should have
*/
void setMaxsize(QSize maxsize);
Point::Alignment alignment() const;
protected:
qreal X;
qreal Y;
QSize size;
QWidget* mywidget;
QPixmap* mypixmap;
Alignment myalignment;
int homelevel;
QSize displaysize;
QSize minsize;
QSize maxsize;
void drawWidget(const MapAdapter* mapadapter, const QPoint offset);
// void drawPixmap(QPainter* painter, const MapAdapter* mapadapter, const QRect &viewport, const QPoint versch);
virtual void draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &viewport, const QPoint offset);
QPoint alignedPoint(const QPoint point) const;
//! returns true if the given Point touches this Point
/*!
* The collision detection checks for the bounding rectangulars.
* @param geom the other point which should be tested on collision
* @param mapadapter the mapadapter which is used for calculations
* @return
*/
virtual bool Touches(Point* geom, const MapAdapter* mapadapter);
public slots:
void setCoordinate(QPointF point);
virtual void setVisible(bool visible);
};
}
#endif