qwt_symbol.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
  2. * Qwt Widget Library
  3. * Copyright (C) 1997 Josef Wilgen
  4. * Copyright (C) 2002 Uwe Rathmann
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the Qwt License, Version 1.0
  8. *****************************************************************************/
  9. #ifndef QWT_SYMBOL_H
  10. #define QWT_SYMBOL_H
  11. #include "qwt_global.h"
  12. #include <qpolygon.h>
  13. class QPainter;
  14. class QRect;
  15. class QSize;
  16. class QBrush;
  17. class QPen;
  18. class QColor;
  19. class QPointF;
  20. class QPolygonF;
  21. class QPainterPath;
  22. class QPixmap;
  23. class QByteArray;
  24. class QwtGraphic;
  25. //! A class for drawing symbols
  26. class QWT_EXPORT QwtSymbol
  27. {
  28. public:
  29. /*!
  30. Symbol Style
  31. \sa setStyle(), style()
  32. */
  33. enum Style
  34. {
  35. //! No Style. The symbol cannot be drawn.
  36. NoSymbol = -1,
  37. //! Ellipse or circle
  38. Ellipse,
  39. //! Rectangle
  40. Rect,
  41. //! Diamond
  42. Diamond,
  43. //! Triangle pointing upwards
  44. Triangle,
  45. //! Triangle pointing downwards
  46. DTriangle,
  47. //! Triangle pointing upwards
  48. UTriangle,
  49. //! Triangle pointing left
  50. LTriangle,
  51. //! Triangle pointing right
  52. RTriangle,
  53. //! Cross (+)
  54. Cross,
  55. //! Diagonal cross (X)
  56. XCross,
  57. //! Horizontal line
  58. HLine,
  59. //! Vertical line
  60. VLine,
  61. //! X combined with +
  62. Star1,
  63. //! Six-pointed star
  64. Star2,
  65. //! Hexagon
  66. Hexagon,
  67. /*!
  68. The symbol is represented by a painter path, where the
  69. origin ( 0, 0 ) of the path coordinate system is mapped to
  70. the position of the symbol.
  71. \sa setPath(), path()
  72. */
  73. Path,
  74. /*!
  75. The symbol is represented by a pixmap. The pixmap is centered
  76. or aligned to its pin point.
  77. \sa setPinPoint()
  78. */
  79. Pixmap,
  80. /*!
  81. The symbol is represented by a graphic. The graphic is centered
  82. or aligned to its pin point.
  83. \sa setPinPoint()
  84. */
  85. Graphic,
  86. /*!
  87. The symbol is represented by a SVG graphic. The graphic is centered
  88. or aligned to its pin point.
  89. \sa setPinPoint()
  90. */
  91. SvgDocument,
  92. /*!
  93. Styles >= QwtSymbol::UserSymbol are reserved for derived
  94. classes of QwtSymbol that overload drawSymbols() with
  95. additional application specific symbol types.
  96. */
  97. UserStyle = 1000
  98. };
  99. /*!
  100. Depending on the render engine and the complexity of the
  101. symbol shape it might be faster to render the symbol
  102. to a pixmap and to paint this pixmap.
  103. F.e. the raster paint engine is a pure software renderer
  104. where in cache mode a draw operation usually ends in
  105. raster operation with the the backing store, that are usually
  106. faster, than the algorithms for rendering polygons.
  107. But the opposite can be expected for graphic pipelines
  108. that can make use of hardware acceleration.
  109. The default setting is AutoCache
  110. \sa setCachePolicy(), cachePolicy()
  111. \note The policy has no effect, when the symbol is painted
  112. to a vector graphics format ( PDF, SVG ).
  113. \warning Since Qt 4.8 raster is the default backend on X11
  114. */
  115. enum CachePolicy
  116. {
  117. //! Don't use a pixmap cache
  118. NoCache,
  119. //! Always use a pixmap cache
  120. Cache,
  121. /*!
  122. Use a cache when one of the following conditions is true:
  123. - The symbol is rendered with the software
  124. renderer ( QPaintEngine::Raster )
  125. */
  126. AutoCache
  127. };
  128. public:
  129. QwtSymbol( Style = NoSymbol );
  130. QwtSymbol( Style, const QBrush &, const QPen &, const QSize & );
  131. QwtSymbol( const QPainterPath &, const QBrush &, const QPen & );
  132. virtual ~QwtSymbol();
  133. void setCachePolicy( CachePolicy );
  134. CachePolicy cachePolicy() const;
  135. void setSize( const QSize & );
  136. void setSize( int width, int height = -1 );
  137. const QSize &size() const;
  138. void setPinPoint( const QPointF &pos, bool enable = true );
  139. QPointF pinPoint() const;
  140. void setPinPointEnabled( bool );
  141. bool isPinPointEnabled() const;
  142. virtual void setColor( const QColor & );
  143. void setBrush( const QBrush & );
  144. const QBrush &brush() const;
  145. void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
  146. void setPen( const QPen & );
  147. const QPen &pen() const;
  148. void setStyle( Style );
  149. Style style() const;
  150. void setPath( const QPainterPath & );
  151. const QPainterPath &path() const;
  152. void setPixmap( const QPixmap & );
  153. const QPixmap &pixmap() const;
  154. void setGraphic( const QwtGraphic & );
  155. const QwtGraphic &graphic() const;
  156. #ifndef QWT_NO_SVG
  157. void setSvgDocument( const QByteArray & );
  158. #endif
  159. void drawSymbol( QPainter *, const QRectF & ) const;
  160. void drawSymbol( QPainter *, const QPointF & ) const;
  161. void drawSymbols( QPainter *, const QPolygonF & ) const;
  162. void drawSymbols( QPainter *,
  163. const QPointF *, int numPoints ) const;
  164. virtual QRect boundingRect() const;
  165. void invalidateCache();
  166. protected:
  167. virtual void renderSymbols( QPainter *,
  168. const QPointF *, int numPoints ) const;
  169. private:
  170. // Disabled copy constructor and operator=
  171. QwtSymbol( const QwtSymbol & );
  172. QwtSymbol &operator=( const QwtSymbol & );
  173. class PrivateData;
  174. PrivateData *d_data;
  175. };
  176. /*!
  177. \brief Draw the symbol at a specified position
  178. \param painter Painter
  179. \param pos Position of the symbol in screen coordinates
  180. */
  181. inline void QwtSymbol::drawSymbol(
  182. QPainter *painter, const QPointF &pos ) const
  183. {
  184. drawSymbols( painter, &pos, 1 );
  185. }
  186. /*!
  187. \brief Draw symbols at the specified points
  188. \param painter Painter
  189. \param points Positions of the symbols in screen coordinates
  190. */
  191. inline void QwtSymbol::drawSymbols(
  192. QPainter *painter, const QPolygonF &points ) const
  193. {
  194. drawSymbols( painter, points.data(), points.size() );
  195. }
  196. #endif