~ubuntu-branches/ubuntu/saucy/merkaartor/saucy

« back to all changes in this revision

Viewing changes to QMapControl/point.h

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz
  • Date: 2009-09-13 00:52:12 UTC
  • mto: (1.2.7 upstream) (0.1.3 upstream) (3.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090913005212-pjecal8zxm07x0fj
Import upstream version 0.14+svnfixes~20090912

Show diffs side-by-side

added added

removed removed

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