qwt_symbol.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 <QPolygonF>
  13. class QPainter;
  14. class QRect;
  15. class QSize;
  16. class QBrush;
  17. class QPen;
  18. class QColor;
  19. class QPointF;
  20. //! A class for drawing symbols
  21. class QWT_EXPORT QwtSymbol
  22. {
  23. public:
  24. /*!
  25. Symbol Style
  26. - NoSymbol\n
  27. No Style. The symbol cannot be drawn.
  28. - Ellipse\n
  29. Ellipse or circle
  30. - Rect\n
  31. Rectangle
  32. - Diamond\n
  33. Diamond
  34. - Triangle\n
  35. Triangle pointing upwards
  36. - DTriangle\n
  37. Triangle pointing downwards
  38. - UTriangle\n
  39. Triangle pointing upwards
  40. - LTriangle\n
  41. Triangle pointing left
  42. - RTriangle\n
  43. Triangle pointing right
  44. - Cross\n
  45. Cross (+)
  46. - XCross\n
  47. Diagonal cross (X)
  48. - HLine\n
  49. Horizontal line
  50. - VLine\n
  51. Vertical line
  52. - Star1\n
  53. X combined with +
  54. - Star2\n
  55. Six-pointed star
  56. - Hexagon\n
  57. Hexagon
  58. - UserSymbol\n
  59. Styles >= UserSymbol are reserved for derived
  60. classes of QwtSymbol that overload drawSymbols() with
  61. additional application specific symbol types.
  62. \sa setStyle(), style()
  63. */
  64. enum Style
  65. {
  66. NoSymbol = -1,
  67. Ellipse,
  68. Rect,
  69. Diamond,
  70. Triangle,
  71. DTriangle,
  72. UTriangle,
  73. LTriangle,
  74. RTriangle,
  75. Cross,
  76. XCross,
  77. HLine,
  78. VLine,
  79. Star1,
  80. Star2,
  81. Hexagon,
  82. UserSymbol = 1000
  83. };
  84. public:
  85. QwtSymbol( Style = NoSymbol );
  86. QwtSymbol( Style, const QBrush &, const QPen &, const QSize & );
  87. QwtSymbol( const QwtSymbol & );
  88. virtual ~QwtSymbol();
  89. QwtSymbol &operator=( const QwtSymbol & );
  90. bool operator==( const QwtSymbol & ) const;
  91. bool operator!=( const QwtSymbol & ) const;
  92. void setSize( const QSize & );
  93. void setSize( int width, int height = -1 );
  94. const QSize& size() const;
  95. virtual void setColor( const QColor & );
  96. void setBrush( const QBrush& b );
  97. const QBrush& brush() const;
  98. void setPen( const QPen & );
  99. const QPen& pen() const;
  100. void setStyle( Style );
  101. Style style() const;
  102. void drawSymbol( QPainter *, const QPointF & ) const;
  103. void drawSymbols( QPainter *, const QPolygonF & ) const;
  104. virtual QSize boundingSize() const;
  105. protected:
  106. virtual void drawSymbols( QPainter *,
  107. const QPointF *, int numPoints ) const;
  108. private:
  109. class PrivateData;
  110. PrivateData *d_data;
  111. };
  112. /*!
  113. \brief Draw the symbol at a specified position
  114. \param painter Painter
  115. \param pos Position of the symbol in screen coordinates
  116. */
  117. inline void QwtSymbol::drawSymbol(
  118. QPainter *painter, const QPointF &pos ) const
  119. {
  120. drawSymbols( painter, &pos, 1 );
  121. }
  122. /*!
  123. \brief Draw symbols at the specified points
  124. \param painter Painter
  125. \param points Positions of the symbols in screen coordinates
  126. */
  127. inline void QwtSymbol::drawSymbols(
  128. QPainter *painter, const QPolygonF &points ) const
  129. {
  130. drawSymbols( painter, points.data(), points.size() );
  131. }
  132. #endif