qwt_dial_needle.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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_DIAL_NEEDLE_H
  10. #define QWT_DIAL_NEEDLE_H 1
  11. #include "qwt_global.h"
  12. #include <qpalette.h>
  13. class QPainter;
  14. class QPoint;
  15. /*!
  16. \brief Base class for needles that can be used in a QwtDial.
  17. QwtDialNeedle is a pointer that indicates a value by pointing
  18. to a specific direction.
  19. Qwt is missing a set of good looking needles.
  20. Contributions are very welcome.
  21. \sa QwtDial, QwtCompass
  22. */
  23. class QWT_EXPORT QwtDialNeedle
  24. {
  25. public:
  26. QwtDialNeedle();
  27. virtual ~QwtDialNeedle();
  28. /*!
  29. Draw the needle
  30. \param painter Painter
  31. \param center Center of the dial, start position for the needle
  32. \param length Length of the needle
  33. \param direction Direction of the needle, in degrees counter clockwise
  34. \param colorGroup Color group, used for painting
  35. */
  36. virtual void draw( QPainter *painter, const QPoint &center,
  37. int length, double direction,
  38. QPalette::ColorGroup colorGroup = QPalette::Active ) const = 0;
  39. virtual void setPalette( const QPalette & );
  40. const QPalette &palette() const;
  41. protected:
  42. static void drawKnob( QPainter *, const QPoint &pos,
  43. int width, const QBrush &, bool sunken );
  44. private:
  45. QPalette d_palette;
  46. };
  47. /*!
  48. \brief A needle for dial widgets
  49. The following colors are used:
  50. - QPalette::Mid\n
  51. Pointer
  52. - QPalette::Base\n
  53. Knob
  54. \sa QwtDial, QwtCompass
  55. */
  56. class QWT_EXPORT QwtDialSimpleNeedle: public QwtDialNeedle
  57. {
  58. public:
  59. //! Style of the needle
  60. enum Style
  61. {
  62. Arrow,
  63. Ray
  64. };
  65. QwtDialSimpleNeedle( Style, bool hasKnob = true,
  66. const QColor &mid = Qt::gray, const QColor &base = Qt::darkGray );
  67. virtual void draw( QPainter *, const QPoint &, int length,
  68. double direction, QPalette::ColorGroup = QPalette::Active ) const;
  69. static void drawArrowNeedle( QPainter *, const QPalette &, QPalette::ColorGroup,
  70. const QPoint &, int length, int width, double direction, bool hasKnob );
  71. static void drawRayNeedle( QPainter *, const QPalette &, QPalette::ColorGroup,
  72. const QPoint &, int length, int width, double direction, bool hasKnob );
  73. void setWidth( int width );
  74. int width() const;
  75. private:
  76. Style d_style;
  77. bool d_hasKnob;
  78. int d_width;
  79. };
  80. /*!
  81. \brief A magnet needle for compass widgets
  82. A magnet needle points to two opposite directions indicating
  83. north and south.
  84. The following colors are used:
  85. - QPalette::Light\n
  86. Used for pointing south
  87. - QPalette::Dark\n
  88. Used for pointing north
  89. - QPalette::Base\n
  90. Knob (ThinStyle only)
  91. \sa QwtDial, QwtCompass
  92. */
  93. class QWT_EXPORT QwtCompassMagnetNeedle: public QwtDialNeedle
  94. {
  95. public:
  96. //! Style of the needle
  97. enum Style
  98. {
  99. TriangleStyle,
  100. ThinStyle
  101. };
  102. QwtCompassMagnetNeedle( Style = TriangleStyle,
  103. const QColor &light = Qt::white, const QColor &dark = Qt::red );
  104. virtual void draw( QPainter *, const QPoint &, int length,
  105. double direction, QPalette::ColorGroup = QPalette::Active ) const;
  106. static void drawTriangleNeedle( QPainter *,
  107. const QPalette &, QPalette::ColorGroup,
  108. const QPoint &, int length, double direction );
  109. static void drawThinNeedle( QPainter *,
  110. const QPalette &, QPalette::ColorGroup,
  111. const QPoint &, int length, double direction );
  112. protected:
  113. static void drawPointer( QPainter *painter, const QBrush &brush,
  114. int colorOffset, const QPoint &center,
  115. int length, int width, double direction );
  116. private:
  117. Style d_style;
  118. };
  119. /*!
  120. \brief An indicator for the wind direction
  121. QwtCompassWindArrow shows the direction where the wind comes from.
  122. - QPalette::Light\n
  123. Used for Style1, or the light half of Style2
  124. - QPalette::Dark\n
  125. Used for the dark half of Style2
  126. \sa QwtDial, QwtCompass
  127. */
  128. class QWT_EXPORT QwtCompassWindArrow: public QwtDialNeedle
  129. {
  130. public:
  131. //! Style of the arrow
  132. enum Style
  133. {
  134. Style1,
  135. Style2
  136. };
  137. QwtCompassWindArrow( Style, const QColor &light = Qt::white,
  138. const QColor &dark = Qt::gray );
  139. virtual void draw( QPainter *, const QPoint &, int length,
  140. double direction, QPalette::ColorGroup = QPalette::Active ) const;
  141. static void drawStyle1Needle( QPainter *,
  142. const QPalette &, QPalette::ColorGroup,
  143. const QPoint &, int length, double direction );
  144. static void drawStyle2Needle( QPainter *,
  145. const QPalette &, QPalette::ColorGroup,
  146. const QPoint &, int length, double direction );
  147. private:
  148. Style d_style;
  149. };
  150. #endif