qwt_dial_needle.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. \sa QwtDial, QwtCompass
  20. */
  21. class QWT_EXPORT QwtDialNeedle
  22. {
  23. public:
  24. QwtDialNeedle();
  25. virtual ~QwtDialNeedle();
  26. virtual void setPalette( const QPalette & );
  27. const QPalette &palette() const;
  28. virtual void draw( QPainter *painter, const QPointF &center,
  29. double length, double direction,
  30. QPalette::ColorGroup = QPalette::Active ) const;
  31. protected:
  32. /*!
  33. \brief Draw the needle
  34. The origin of the needle is at position (0.0, 0.0 )
  35. pointing in direction 0.0 ( = east ).
  36. The painter is already initialized with translation and
  37. rotation.
  38. \param painter Painter
  39. \param length Length of the needle
  40. \param colorGroup Color group, used for painting
  41. \sa setPalette(), palette()
  42. */
  43. virtual void drawNeedle( QPainter *painter,
  44. double length, QPalette::ColorGroup colorGroup ) const = 0;
  45. virtual void drawKnob( QPainter *, double width,
  46. const QBrush &, bool sunken ) const;
  47. private:
  48. QPalette d_palette;
  49. };
  50. /*!
  51. \brief A needle for dial widgets
  52. The following colors are used:
  53. - QPalette::Mid\n
  54. Pointer
  55. - QPalette::Base\n
  56. Knob
  57. \sa QwtDial, QwtCompass
  58. */
  59. class QWT_EXPORT QwtDialSimpleNeedle: public QwtDialNeedle
  60. {
  61. public:
  62. //! Style of the needle
  63. enum Style
  64. {
  65. //! Arrow
  66. Arrow,
  67. //! A straight line from the center
  68. Ray
  69. };
  70. QwtDialSimpleNeedle( Style, bool hasKnob = true,
  71. const QColor &mid = Qt::gray, const QColor &base = Qt::darkGray );
  72. void setWidth( double width );
  73. double width() const;
  74. protected:
  75. virtual void drawNeedle( QPainter *, double length,
  76. QPalette::ColorGroup ) const;
  77. private:
  78. Style d_style;
  79. bool d_hasKnob;
  80. double d_width;
  81. };
  82. /*!
  83. \brief A magnet needle for compass widgets
  84. A magnet needle points to two opposite directions indicating
  85. north and south.
  86. The following colors are used:
  87. - QPalette::Light\n
  88. Used for pointing south
  89. - QPalette::Dark\n
  90. Used for pointing north
  91. - QPalette::Base\n
  92. Knob (ThinStyle only)
  93. \sa QwtDial, QwtCompass
  94. */
  95. class QWT_EXPORT QwtCompassMagnetNeedle: public QwtDialNeedle
  96. {
  97. public:
  98. //! Style of the needle
  99. enum Style
  100. {
  101. //! A needle with a triangular shape
  102. TriangleStyle,
  103. //! A thin needle
  104. ThinStyle
  105. };
  106. QwtCompassMagnetNeedle( Style = TriangleStyle,
  107. const QColor &light = Qt::white, const QColor &dark = Qt::red );
  108. protected:
  109. virtual void drawNeedle( QPainter *,
  110. double length, QPalette::ColorGroup ) const;
  111. private:
  112. Style d_style;
  113. };
  114. /*!
  115. \brief An indicator for the wind direction
  116. QwtCompassWindArrow shows the direction where the wind comes from.
  117. - QPalette::Light\n
  118. Used for Style1, or the light half of Style2
  119. - QPalette::Dark\n
  120. Used for the dark half of Style2
  121. \sa QwtDial, QwtCompass
  122. */
  123. class QWT_EXPORT QwtCompassWindArrow: public QwtDialNeedle
  124. {
  125. public:
  126. //! Style of the arrow
  127. enum Style
  128. {
  129. //! A needle pointing to the center
  130. Style1,
  131. //! A needle pointing to the center
  132. Style2
  133. };
  134. QwtCompassWindArrow( Style, const QColor &light = Qt::white,
  135. const QColor &dark = Qt::gray );
  136. protected:
  137. virtual void drawNeedle( QPainter *,
  138. double length, QPalette::ColorGroup ) const;
  139. private:
  140. Style d_style;
  141. };
  142. #endif