Subversion Repositories Projects

Rev

Rev 398 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
305 KeyOz 1
/*
2
*
3
* This file is part of QMapControl,
4
* an open-source cross-platform map widget
5
*
6
* Copyright (C) 2007 - 2008 Kai Winter
7
*
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
10
* the Free Software Foundation, either version 3 of the License, or
11
* (at your option) any later version.
12
*
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
* GNU Lesser General Public License for more details.
17
*
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/>.
20
*
21
* Contact e-mail: kaiwinter@gmx.de
22
* Program URL   : http://qmapcontrol.sourceforge.net/
23
*
24
*/
25
 
26
#ifndef POINT_H
27
#define POINT_H
28
#include <QWidget>
29
 
30
#include "geometry.h"
31
 
32
namespace qmapcontrol
33
{
34
    //! A geometric point to draw objects into maps
35
    /*!
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)
38
     *
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.
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.)
43
     *
44
     * Points emit click events, if the containing layer receives clickevents (the default)
45
     *
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.
48
     *
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.
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.
53
     * @see setBaselevel, setMinsize, setMaxsize
54
     *
55
     * @author Kai Winter <kaiwinter@gmx.de>
56
     */
57
    class Point : public Geometry
58
    {
59
        Q_OBJECT
60
 
61
    public:
62
        friend class Layer;
63
        friend class LineString;
64
 
65
        //! sets where the point should be aligned
66
        enum Alignment
67
        {
68
            TopLeft, /*!< Align on TopLeft*/
69
            TopRight, /*!< Align on TopRight*/
70
            BottomLeft, /*!< Align on BottomLeft*/
71
            BottomRight,/*!< Align on BottomRight*/
72
            Middle /*!< Align on Middle*/
73
        };
74
 
75
        Point();
76
        explicit Point(const Point&);
77
        //! Copy Constructor
78
        /*!
79
         * This constructor creates a Point with no image or widget.
80
         * @param x longitude
81
         * @param y latitude
82
         * @param name name of the point
83
         * @param alignment allignment of the point (Middle or TopLeft)
84
         */
85
        Point(qreal x, qreal y, QString name = QString(), enum Alignment alignment=Middle);
86
 
87
        //! Constructor
88
        /*!
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.
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!
93
         * @param x longitude
94
         * @param y latitude
95
         * @param widget the widget which should be displayed by this point
96
         * @param name name of the point
97
         * @param alignment allignment of the point (Middle or TopLeft)
98
         */
99
        Point(qreal x, qreal y, QWidget* widget, QString name = QString(), enum Alignment alignment = Middle);
100
 
101
        //! Constructor
102
        /*!
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.
105
         * @param x longitude
106
         * @param y latitude
107
         * @param pixmap the pixmap which should be displayed by this point
108
         * @param name name of the point
109
         * @param alignment allignment of the point (Middle or TopLeft)
110
         */
111
        Point(qreal x, qreal y, QPixmap* pixmap, QString name = QString(), enum Alignment alignment = Middle);
112
        virtual ~Point();
113
 
114
        //! returns the bounding box of the point
115
        /*!
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
118
         * @return the bounding box of the point
119
         */
120
        virtual QRectF boundingBox();
121
 
122
        //! returns the longitude of the point
123
        /*!
124
         * @return the longitude of the point
125
         */
126
        qreal longitude() const;
127
 
128
        //! returns the latitude of the point
129
        /*!
130
         * @return the latitude of the point
131
         */
398 Brean 132
        qreal latitude() const;
305 KeyOz 133
 
134
        //! returns the coordinate of the point
135
        /*!
136
         * The x component of the returned QPointF is the longitude value,
137
         * the y component the latitude
138
         * @return the coordinate of a point
139
         */
398 Brean 140
        QPointF coordinate() const;
305 KeyOz 141
 
142
        virtual QList<Point*> points();
143
 
144
        /*! \brief returns the widget of the point
145
        @return the widget of the point
146
         */
147
        QWidget* widget();
148
 
149
        //! returns the pixmap of the point
150
        /*!
151
         * @return the pixmap of the point
152
         */
153
        QPixmap* pixmap();
154
 
398 Brean 155
        //! Sets the zoom level on which the point�s pixmap gets displayed on full size
305 KeyOz 156
        /*!
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
159
         * @see setMinsize, setMaxsize
160
         * @param zoomlevel the zoomlevel on which the point will be displayed on full size
161
         */
162
        void setBaselevel(int zoomlevel);
163
 
164
        //! sets a minimal size for the pixmap
165
        /*!
398 Brean 166
         * When the point's pixmap should change its size on zooming, this method sets the minimal size.
305 KeyOz 167
         * @see setBaselevel
168
         * @param minsize the minimal size which the pixmap should have
169
         */
170
        void setMinsize(QSize minsize);
171
 
172
        //! sets a maximal size for the pixmap
173
        /*!
174
         * When the point´s pixmap should change its size on zooming, this method sets the maximal size.
175
         * @see setBaselevel
176
         * @param maxsize the maximal size which the pixmap should have
177
         */
178
        void setMaxsize(QSize maxsize);
179
 
180
        Point::Alignment alignment() const;
181
 
182
    protected:
183
        qreal X;
184
        qreal Y;
185
        QSize size;
186
 
187
        QWidget* mywidget;
188
        QPixmap* mypixmap;
189
        Alignment myalignment;
190
        int homelevel;
191
        QSize displaysize;
192
        QSize minsize;
193
        QSize maxsize;
194
 
195
 
196
        void drawWidget(const MapAdapter* mapadapter, const QPoint offset);
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);
199
        QPoint alignedPoint(const QPoint point) const;
200
 
201
        //! returns true if the given Point touches this Point
202
        /*!
203
         * The collision detection checks for the bounding rectangulars.
204
         * @param geom the other point which should be tested on collision
205
         * @param mapadapter the mapadapter which is used for calculations
206
         * @return
207
         */
208
        virtual bool Touches(Point* geom, const MapAdapter* mapadapter);
209
 
210
    public slots:
211
        void setCoordinate(QPointF point);
212
        virtual void setVisible(bool visible);
213
    };
214
}
215
#endif