You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
7.9 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #ifndef POINT_H
  26. #define POINT_H
  27. #include "qmapcontrol_global.h"
  28. //#include "qglobal.h"
  29. #if QT_VERSION >= 0x050000
  30. // Qt5 code
  31. //#include <QtWidgets>
  32. #else
  33. // Qt4 code
  34. #include <QtWidgets/QWidget>
  35. #endif
  36. #include "geometry.h"
  37. //! A geometric point to draw objects into maps
  38. /*!
  39. * This class can be used to draw your custom QPixmap or other QWidgets into maps.
  40. * You can instantiate a Point with any Pixmap you want. The objects cares about collision detection (for clickable objects)
  41. *
  42. * When drawing a pixmap, take care you are adding the point to a GeometryLayer.
  43. * 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.
  44. * (GeometryLayers are assured to be repainted on any changes at the point. MapLayers only gets repainted, if a new
  45. * offscreenImage is painter. This is a performance issue.)
  46. *
  47. * Points emit click events, if the containing layer receives clickevents (the default)
  48. *
  49. * You can also add a widget into maps. But keep in mind, that widgets always are drawn on top of all layers.
  50. * You also have to handle click events yourself.
  51. *
  52. * To create "zoomable objects" (objects that increases size on zooming), a base level have to be set.
  53. * The base level is the zoom level on which the point´s pixmap gets displayed on full size.
  54. * On lower zoom levels it gets displayed smaller and on higher zoom levels larger.
  55. * A minimal size can be set as well as a maximum size.
  56. * @see setBaselevel, setMinsize, setMaxsize
  57. *
  58. * @author Kai Winter <kaiwinter@gmx.de>
  59. */
  60. class mapPoint : public Geometry {
  61. //Q_OBJECT
  62. public:
  63. friend class Layer;
  64. friend class LineString;
  65. //! sets where the point should be aligned
  66. enum Alignment
  67. {
  68. TopLeft, /*!< Align on TopLeft*/
  69. TopRight, /*!< Align on TopRight*/
  70. TopMiddle, /*!< Align on TopLeft*/
  71. BottomLeft, /*!< Align on BottomLeft*/
  72. BottomRight,/*!< Align on BottomRight*/
  73. BottomMiddle, /*!< Align on BottomMiddle*/
  74. Middle /*!< Align on Middle*/
  75. };
  76. mapPoint();
  77. mapPoint(const mapPoint&);
  78. //! Copy Constructor
  79. /*!
  80. * This constructor creates a Point with no image or widget.
  81. * @param x longitude
  82. * @param y latitude
  83. * @param name name of the point
  84. * @param alignment alignment of the point (Middle or TopLeft)
  85. */
  86. mapPoint(qreal x, qreal y, QString name = QString(), enum Alignment alignment=Middle);
  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. mapPoint(qreal x, qreal y, QWidget* widget, QString name = QString(), enum Alignment alignment = Middle);
  100. //! Constructor
  101. /*!
  102. * This constructor creates a point which will display the give pixmap.
  103. * You can set an alignment on which corner the pixmap should be aligned to the coordinate.
  104. * @param x longitude
  105. * @param y latitude
  106. * @param pixmap the pixmap which should be displayed by this point
  107. * @param name name of the point
  108. * @param alignment allignment of the point (Middle or TopLeft)
  109. */
  110. mapPoint(qreal x, qreal y, QPixmap pixmap, QString name = QString(), enum Alignment alignment = Middle);
  111. virtual ~mapPoint();
  112. //! returns the bounding box of the point
  113. /*!
  114. * The Bounding contains the coordinate of the point and its size.
  115. * The size is set, if the point contains a pixmap or a widget
  116. * @return the bounding box of the point
  117. */
  118. virtual QRectF boundingBox();
  119. //! returns the longitude of the point
  120. /*!
  121. * @return the longitude of the point
  122. */
  123. qreal longitude() const;
  124. //! returns the latitude of the point
  125. /*!
  126. * @return the latitude of the point
  127. */
  128. qreal latitude() const;
  129. //! returns the coordinate of the point
  130. /*!
  131. * The x component of the returned QPointF is the longitude value,
  132. * the y component the latitude
  133. * @return the coordinate of a point
  134. */
  135. QPointF coordinate() const;
  136. virtual QList<mapPoint*> points();
  137. /*! \brief returns the widget of the point
  138. @return the widget of the point
  139. */
  140. QWidget* widget();
  141. //! returns the pixmap of the point
  142. /*!
  143. * @return the pixmap of the point
  144. */
  145. QPixmap pixmap();
  146. //! Sets the zoom level on which the points pixmap gets displayed on full size
  147. /*!
  148. * Use this method to set a zoom level on which the pixmap gets displayed with its real size.
  149. * On zoomlevels below it will be displayed smaller, and on zoom levels thereover it will be displayed larger
  150. * @see setMinsize, setMaxsize
  151. * @param zoomlevel the zoomlevel on which the point will be displayed on full size
  152. */
  153. void setBaselevel(int zoomlevel);
  154. //! sets a minimal size for the pixmap
  155. /*!
  156. * When the point's pixmap should change its size on zooming, this method sets the minimal size.
  157. * @see setBaselevel
  158. * @param minsize the minimal size which the pixmap should have
  159. */
  160. void setMinsize(QSize minsize);
  161. //! sets a maximal size for the pixmap
  162. /*!
  163. * When the point´s pixmap should change its size on zooming, this method sets the maximal size.
  164. * @see setBaselevel
  165. * @param maxsize the maximal size which the pixmap should have
  166. */
  167. void setMaxsize(QSize maxsize);
  168. mapPoint::Alignment alignment() const;
  169. virtual void setPixmap( QPixmap qPixmap );
  170. protected:
  171. qreal X;
  172. qreal Y;
  173. QSize size;
  174. QWidget* mywidget;
  175. QPixmap mypixmap;
  176. Alignment myalignment;
  177. int homelevel;
  178. QSize displaysize;
  179. QSize minsize;
  180. QSize maxsize;
  181. void drawWidget(const MapAdapter* mapadapter, const QPoint offset);
  182. // void drawPixmap(QPainter* painter, const MapAdapter* mapadapter, const QRect &viewport, const QPoint versch);
  183. virtual void draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &viewport, const QPoint offset);
  184. QPoint alignedPoint(const QPoint point) const;
  185. //! returns true if the given Point touches this Point
  186. /*!
  187. * The collision detection checks for the bounding rectangulars.
  188. * @param geom the other point which should be tested on collision
  189. * @param mapadapter the mapadapter which is used for calculations
  190. * @return
  191. */
  192. virtual bool Touches(mapPoint* p, const MapAdapter* mapadapter);
  193. public slots:
  194. void setCoordinate(QPointF point);
  195. virtual void setVisible(bool visible);
  196. };
  197. #endif