Rev 305 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 305 | Rev 395 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * |
2 | * |
3 | * This file is part of QMapControl, |
3 | * This file is part of QMapControl, |
4 | * an open-source cross-platform map widget |
4 | * an open-source cross-platform map widget |
5 | * |
5 | * |
6 | * Copyright (C) 2007 - 2008 Kai Winter |
6 | * Copyright (C) 2007 - 2008 Kai Winter |
7 | * |
7 | * |
8 | * This program is free software: you can redistribute it and/or modify |
8 | * This program is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU Lesser General Public License as published by |
9 | * it under the terms of the GNU Lesser General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU Lesser General Public License for more details. |
16 | * GNU Lesser General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU Lesser General Public License |
18 | * You should have received a copy of the GNU Lesser General Public License |
19 | * along with QMapControl. If not, see <http://www.gnu.org/licenses/>. |
19 | * along with QMapControl. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * Contact e-mail: kaiwinter@gmx.de |
21 | * Contact e-mail: kaiwinter@gmx.de |
22 | * Program URL : http://qmapcontrol.sourceforge.net/ |
22 | * Program URL : http://qmapcontrol.sourceforge.net/ |
23 | * |
23 | * |
24 | */ |
24 | */ |
25 | 25 | ||
26 | #ifndef POINT_H |
26 | #ifndef POINT_H |
27 | #define POINT_H |
27 | #define POINT_H |
28 | #include <QWidget> |
28 | #include <QWidget> |
29 | 29 | ||
30 | #include "geometry.h" |
30 | #include "geometry.h" |
31 | 31 | ||
32 | namespace qmapcontrol |
32 | namespace qmapcontrol |
33 | { |
33 | { |
34 | //! A geometric point to draw objects into maps |
34 | //! A geometric point to draw objects into maps |
35 | /*! |
35 | /*! |
36 | * This class can be used to draw your custom QPixmap or other QWidgets into maps. |
36 | * This class can be used to draw your custom QPixmap or other QWidgets into maps. |
37 | * You can instantiate a Point with any Pixmap you want. The objects cares about collision detection (for clickable objects) |
37 | * You can instantiate a Point with any Pixmap you want. The objects cares about collision detection (for clickable objects) |
38 | * |
38 | * |
39 | * When drawing a pixmap, take care you are adding the point to a GeometryLayer. |
39 | * When drawing a pixmap, take care you are adding the point to a GeometryLayer. |
40 | * 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. |
40 | * 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. |
41 | * (GeometryLayers are assured to be repainted on any changes at the point. MapLayers only gets repainted, if a new |
41 | * (GeometryLayers are assured to be repainted on any changes at the point. MapLayers only gets repainted, if a new |
42 | * offscreenImage is painter. This is a performance issue.) |
42 | * offscreenImage is painter. This is a performance issue.) |
43 | * |
43 | * |
44 | * Points emit click events, if the containing layer receives clickevents (the default) |
44 | * Points emit click events, if the containing layer receives clickevents (the default) |
45 | * |
45 | * |
46 | * You can also add a widget into maps. But keep in mind, that widgets always are drawn on top of all layers. |
46 | * You can also add a widget into maps. But keep in mind, that widgets always are drawn on top of all layers. |
47 | * You also have to handle click events yourself. |
47 | * You also have to handle click events yourself. |
48 | * |
48 | * |
49 | * To create "zoomable objects" (objects that increases size on zooming), a base level have to be set. |
49 | * To create "zoomable objects" (objects that increases size on zooming), a base level have to be set. |
50 | * The base level is the zoom level on which the point´s pixmap gets displayed on full size. |
50 | * The base level is the zoom level on which the point´s pixmap gets displayed on full size. |
51 | * On lower zoom levels it gets displayed smaller and on higher zoom levels larger. |
51 | * On lower zoom levels it gets displayed smaller and on higher zoom levels larger. |
52 | * A minimal size can be set as well as a maximum size. |
52 | * A minimal size can be set as well as a maximum size. |
53 | * @see setBaselevel, setMinsize, setMaxsize |
53 | * @see setBaselevel, setMinsize, setMaxsize |
54 | * |
54 | * |
55 | * @author Kai Winter <kaiwinter@gmx.de> |
55 | * @author Kai Winter <kaiwinter@gmx.de> |
56 | */ |
56 | */ |
57 | class Point : public Geometry |
57 | class Point : public Geometry |
58 | { |
58 | { |
59 | Q_OBJECT |
59 | Q_OBJECT |
60 | 60 | ||
61 | public: |
61 | public: |
62 | friend class Layer; |
62 | friend class Layer; |
63 | friend class LineString; |
63 | friend class LineString; |
64 | 64 | ||
65 | //! sets where the point should be aligned |
65 | //! sets where the point should be aligned |
66 | enum Alignment |
66 | enum Alignment |
67 | { |
67 | { |
68 | TopLeft, /*!< Align on TopLeft*/ |
68 | TopLeft, /*!< Align on TopLeft*/ |
69 | TopRight, /*!< Align on TopRight*/ |
69 | TopRight, /*!< Align on TopRight*/ |
70 | BottomLeft, /*!< Align on BottomLeft*/ |
70 | BottomLeft, /*!< Align on BottomLeft*/ |
71 | BottomRight,/*!< Align on BottomRight*/ |
71 | BottomRight,/*!< Align on BottomRight*/ |
72 | Middle /*!< Align on Middle*/ |
72 | Middle /*!< Align on Middle*/ |
73 | }; |
73 | }; |
74 | 74 | ||
75 | Point(); |
75 | Point(); |
76 | explicit Point(const Point&); |
76 | explicit Point(const Point&); |
77 | //! Copy Constructor |
77 | //! Copy Constructor |
78 | /*! |
78 | /*! |
79 | * This constructor creates a Point with no image or widget. |
79 | * This constructor creates a Point with no image or widget. |
80 | * @param x longitude |
80 | * @param x longitude |
81 | * @param y latitude |
81 | * @param y latitude |
82 | * @param name name of the point |
82 | * @param name name of the point |
83 | * @param alignment allignment of the point (Middle or TopLeft) |
83 | * @param alignment allignment of the point (Middle or TopLeft) |
84 | */ |
84 | */ |
85 | Point(qreal x, qreal y, QString name = QString(), enum Alignment alignment=Middle); |
85 | Point(qreal x, qreal y, QString name = QString(), enum Alignment alignment=Middle); |
86 | 86 | ||
87 | //! Constructor |
87 | //! Constructor |
88 | /*! |
88 | /*! |
89 | * This constructor creates a point which will display the given widget. |
89 | * This constructor creates a point which will display the given widget. |
90 | * You can set an alignment on which corner the widget should be aligned to the coordinate. |
90 | * You can set an alignment on which corner the widget should be aligned to the coordinate. |
91 | * You have to set the size of the widget, before adding it to |
91 | * You have to set the size of the widget, before adding it to |
92 | * IMPORTANT: You have to set the QMapControl as parent for the widget! |
92 | * IMPORTANT: You have to set the QMapControl as parent for the widget! |
93 | * @param x longitude |
93 | * @param x longitude |
94 | * @param y latitude |
94 | * @param y latitude |
95 | * @param widget the widget which should be displayed by this point |
95 | * @param widget the widget which should be displayed by this point |
96 | * @param name name of the point |
96 | * @param name name of the point |
97 | * @param alignment allignment of the point (Middle or TopLeft) |
97 | * @param alignment allignment of the point (Middle or TopLeft) |
98 | */ |
98 | */ |
99 | Point(qreal x, qreal y, QWidget* widget, QString name = QString(), enum Alignment alignment = Middle); |
99 | Point(qreal x, qreal y, QWidget* widget, QString name = QString(), enum Alignment alignment = Middle); |
100 | 100 | ||
101 | //! Constructor |
101 | //! Constructor |
102 | /*! |
102 | /*! |
103 | * This constructor creates a point which will display the give pixmap. |
103 | * This constructor creates a point which will display the give pixmap. |
104 | * You can set an alignment on which corner the pixmap should be aligned to the coordinate. |
104 | * You can set an alignment on which corner the pixmap should be aligned to the coordinate. |
105 | * @param x longitude |
105 | * @param x longitude |
106 | * @param y latitude |
106 | * @param y latitude |
107 | * @param pixmap the pixmap which should be displayed by this point |
107 | * @param pixmap the pixmap which should be displayed by this point |
108 | * @param name name of the point |
108 | * @param name name of the point |
109 | * @param alignment allignment of the point (Middle or TopLeft) |
109 | * @param alignment allignment of the point (Middle or TopLeft) |
110 | */ |
110 | */ |
111 | Point(qreal x, qreal y, QPixmap* pixmap, QString name = QString(), enum Alignment alignment = Middle); |
111 | Point(qreal x, qreal y, QPixmap* pixmap, QString name = QString(), enum Alignment alignment = Middle); |
112 | virtual ~Point(); |
112 | virtual ~Point(); |
113 | 113 | ||
114 | //! returns the bounding box of the point |
114 | //! returns the bounding box of the point |
115 | /*! |
115 | /*! |
116 | * The Bounding contains the coordinate of the point and its size. |
116 | * The Bounding contains the coordinate of the point and its size. |
117 | * The size is set, if the point contains a pixmap or a widget |
117 | * The size is set, if the point contains a pixmap or a widget |
118 | * @return the bounding box of the point |
118 | * @return the bounding box of the point |
119 | */ |
119 | */ |
120 | virtual QRectF boundingBox(); |
120 | virtual QRectF boundingBox(); |
121 | 121 | ||
122 | //! returns the longitude of the point |
122 | //! returns the longitude of the point |
123 | /*! |
123 | /*! |
124 | * @return the longitude of the point |
124 | * @return the longitude of the point |
125 | */ |
125 | */ |
126 | qreal longitude() const; |
126 | qreal longitude() const; |
127 | 127 | ||
128 | //! returns the latitude of the point |
128 | //! returns the latitude of the point |
129 | /*! |
129 | /*! |
130 | * @return the latitude of the point |
130 | * @return the latitude of the point |
131 | */ |
131 | */ |
132 | qreal latitude() const; |
132 | qreal latitude() const; |
133 | 133 | ||
134 | //! returns the coordinate of the point |
134 | //! returns the coordinate of the point |
135 | /*! |
135 | /*! |
136 | * The x component of the returned QPointF is the longitude value, |
136 | * The x component of the returned QPointF is the longitude value, |
137 | * the y component the latitude |
137 | * the y component the latitude |
138 | * @return the coordinate of a point |
138 | * @return the coordinate of a point |
139 | */ |
139 | */ |
140 | QPointF coordinate() const; |
140 | QPointF coordinate() const; |
141 | 141 | ||
142 | virtual QList<Point*> points(); |
142 | virtual QList<Point*> points(); |
143 | 143 | ||
144 | /*! \brief returns the widget of the point |
144 | /*! \brief returns the widget of the point |
145 | @return the widget of the point |
145 | @return the widget of the point |
146 | */ |
146 | */ |
147 | QWidget* widget(); |
147 | QWidget* widget(); |
148 | 148 | ||
149 | //! returns the pixmap of the point |
149 | //! returns the pixmap of the point |
150 | /*! |
150 | /*! |
151 | * @return the pixmap of the point |
151 | * @return the pixmap of the point |
152 | */ |
152 | */ |
153 | QPixmap* pixmap(); |
153 | QPixmap* pixmap(); |
154 | 154 | ||
155 | //! Sets the zoom level on which the point´s pixmap gets displayed on full size |
155 | //! Sets the zoom level on which the point�s pixmap gets displayed on full size |
156 | /*! |
156 | /*! |
157 | * Use this method to set a zoom level on which the pixmap gets displayed with its real size. |
157 | * Use this method to set a zoom level on which the pixmap gets displayed with its real size. |
158 | * On zoomlevels below it will be displayed smaller, and on zoom levels thereover it will be displayed larger |
158 | * On zoomlevels below it will be displayed smaller, and on zoom levels thereover it will be displayed larger |
159 | * @see setMinsize, setMaxsize |
159 | * @see setMinsize, setMaxsize |
160 | * @param zoomlevel the zoomlevel on which the point will be displayed on full size |
160 | * @param zoomlevel the zoomlevel on which the point will be displayed on full size |
161 | */ |
161 | */ |
162 | void setBaselevel(int zoomlevel); |
162 | void setBaselevel(int zoomlevel); |
163 | 163 | ||
164 | //! sets a minimal size for the pixmap |
164 | //! sets a minimal size for the pixmap |
165 | /*! |
165 | /*! |
166 | * When the point´s pixmap should change its size on zooming, this method sets the minimal size. |
166 | * When the point's pixmap should change its size on zooming, this method sets the minimal size. |
167 | * @see setBaselevel |
167 | * @see setBaselevel |
168 | * @param minsize the minimal size which the pixmap should have |
168 | * @param minsize the minimal size which the pixmap should have |
169 | */ |
169 | */ |
170 | void setMinsize(QSize minsize); |
170 | void setMinsize(QSize minsize); |
171 | 171 | ||
172 | //! sets a maximal size for the pixmap |
172 | //! sets a maximal size for the pixmap |
173 | /*! |
173 | /*! |
174 | * When the point´s pixmap should change its size on zooming, this method sets the maximal size. |
174 | * When the point´s pixmap should change its size on zooming, this method sets the maximal size. |
175 | * @see setBaselevel |
175 | * @see setBaselevel |
176 | * @param maxsize the maximal size which the pixmap should have |
176 | * @param maxsize the maximal size which the pixmap should have |
177 | */ |
177 | */ |
178 | void setMaxsize(QSize maxsize); |
178 | void setMaxsize(QSize maxsize); |
179 | 179 | ||
180 | Point::Alignment alignment() const; |
180 | Point::Alignment alignment() const; |
181 | 181 | ||
182 | protected: |
182 | protected: |
183 | qreal X; |
183 | qreal X; |
184 | qreal Y; |
184 | qreal Y; |
185 | QSize size; |
185 | QSize size; |
186 | 186 | ||
187 | QWidget* mywidget; |
187 | QWidget* mywidget; |
188 | QPixmap* mypixmap; |
188 | QPixmap* mypixmap; |
189 | Alignment myalignment; |
189 | Alignment myalignment; |
190 | int homelevel; |
190 | int homelevel; |
191 | QSize displaysize; |
191 | QSize displaysize; |
192 | QSize minsize; |
192 | QSize minsize; |
193 | QSize maxsize; |
193 | QSize maxsize; |
194 | 194 | ||
195 | 195 | ||
196 | void drawWidget(const MapAdapter* mapadapter, const QPoint offset); |
196 | void drawWidget(const MapAdapter* mapadapter, const QPoint offset); |
197 | // void drawPixmap(QPainter* painter, const MapAdapter* mapadapter, const QRect &viewport, const QPoint versch); |
197 | // void drawPixmap(QPainter* painter, const MapAdapter* mapadapter, const QRect &viewport, const QPoint versch); |
198 | virtual void draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &viewport, const QPoint offset); |
198 | virtual void draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &viewport, const QPoint offset); |
199 | QPoint alignedPoint(const QPoint point) const; |
199 | QPoint alignedPoint(const QPoint point) const; |
200 | 200 | ||
201 | //! returns true if the given Point touches this Point |
201 | //! returns true if the given Point touches this Point |
202 | /*! |
202 | /*! |
203 | * The collision detection checks for the bounding rectangulars. |
203 | * The collision detection checks for the bounding rectangulars. |
204 | * @param geom the other point which should be tested on collision |
204 | * @param geom the other point which should be tested on collision |
205 | * @param mapadapter the mapadapter which is used for calculations |
205 | * @param mapadapter the mapadapter which is used for calculations |
206 | * @return |
206 | * @return |
207 | */ |
207 | */ |
208 | virtual bool Touches(Point* geom, const MapAdapter* mapadapter); |
208 | virtual bool Touches(Point* geom, const MapAdapter* mapadapter); |
209 | 209 | ||
210 | public slots: |
210 | public slots: |
211 | void setCoordinate(QPointF point); |
211 | void setCoordinate(QPointF point); |
212 | virtual void setVisible(bool visible); |
212 | virtual void setVisible(bool visible); |
213 | }; |
213 | }; |
214 | } |
214 | } |
215 | #endif |
215 | #endif |
216 | 216 |