qwt_dial.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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_H
  10. #define QWT_DIAL_H 1
  11. #include "qwt_global.h"
  12. #include "qwt_abstract_slider.h"
  13. #include "qwt_round_scale_draw.h"
  14. #include <qframe.h>
  15. #include <qpalette.h>
  16. class QwtDialNeedle;
  17. class QwtDial;
  18. /*!
  19. \brief A special scale draw made for QwtDial
  20. \sa QwtDial, QwtCompass
  21. */
  22. class QWT_EXPORT QwtDialScaleDraw: public QwtRoundScaleDraw
  23. {
  24. public:
  25. explicit QwtDialScaleDraw( QwtDial * );
  26. virtual QwtText label( double value ) const;
  27. void setPenWidth( double );
  28. double penWidth() const;
  29. private:
  30. QwtDial *d_parent;
  31. double d_penWidth;
  32. };
  33. /*!
  34. \brief QwtDial class provides a rounded range control.
  35. QwtDial is intended as base class for dial widgets like
  36. speedometers, compass widgets, clocks ...
  37. \image html dials2.png
  38. A dial contains a scale and a needle indicating the current value
  39. of the dial. Depending on Mode one of them is fixed and the
  40. other is rotating. If not isReadOnly() the
  41. dial can be rotated by dragging the mouse or using keyboard inputs
  42. (see keyPressEvent()). A dial might be wrapping, what means
  43. a rotation below/above one limit continues on the other limit (f.e compass).
  44. The scale might cover any arc of the dial, its values are related to
  45. the origin() of the dial.
  46. Qwt is missing a set of good looking needles (QwtDialNeedle).
  47. Contributions are very welcome.
  48. \sa QwtCompass, QwtAnalogClock, QwtDialNeedle
  49. \note The examples/dials example shows different types of dials.
  50. */
  51. class QWT_EXPORT QwtDial: public QwtAbstractSlider
  52. {
  53. Q_OBJECT
  54. Q_ENUMS( Shadow )
  55. Q_ENUMS( Mode )
  56. Q_ENUMS( Direction )
  57. Q_PROPERTY( bool visibleBackground READ hasVisibleBackground WRITE showBackground )
  58. Q_PROPERTY( int lineWidth READ lineWidth WRITE setLineWidth )
  59. Q_PROPERTY( Shadow frameShadow READ frameShadow WRITE setFrameShadow )
  60. Q_PROPERTY( Mode mode READ mode WRITE setMode )
  61. Q_PROPERTY( double origin READ origin WRITE setOrigin )
  62. Q_PROPERTY( bool wrapping READ wrapping WRITE setWrapping )
  63. Q_PROPERTY( Direction direction READ direction WRITE setDirection )
  64. friend class QwtDialScaleDraw;
  65. public:
  66. /*!
  67. \brief Frame shadow
  68. Unfortunately it is not possible to use QFrame::Shadow
  69. as a property of a widget that is not derived from QFrame.
  70. The following enum is made for the designer only. It is safe
  71. to use QFrame::Shadow instead.
  72. */
  73. enum Shadow
  74. {
  75. Plain = QFrame::Plain,
  76. Raised = QFrame::Raised,
  77. Sunken = QFrame::Sunken
  78. };
  79. //! see QwtDial::setScaleOptions
  80. enum ScaleOptions
  81. {
  82. ScaleBackbone = 1,
  83. ScaleTicks = 2,
  84. ScaleLabel = 4
  85. };
  86. /*!
  87. In case of RotateNeedle the needle is rotating, in case of
  88. RotateScale, the needle points to origin()
  89. and the scale is rotating.
  90. */
  91. enum Mode
  92. {
  93. RotateNeedle,
  94. RotateScale
  95. };
  96. /*!
  97. Direction of the dial
  98. */
  99. enum Direction
  100. {
  101. Clockwise,
  102. CounterClockwise
  103. };
  104. explicit QwtDial( QWidget *parent = NULL );
  105. virtual ~QwtDial();
  106. void setFrameShadow( Shadow );
  107. Shadow frameShadow() const;
  108. bool hasVisibleBackground() const;
  109. void showBackground( bool );
  110. void setLineWidth( int );
  111. int lineWidth() const;
  112. void setMode( Mode );
  113. Mode mode() const;
  114. virtual void setWrapping( bool );
  115. bool wrapping() const;
  116. virtual void setScale( int maxMajIntv, int maxMinIntv, double step = 0.0 );
  117. void setScaleArc( double min, double max );
  118. void setScaleOptions( int );
  119. void setScaleTicks( int minLen, int medLen, int majLen, int penWidth = 1 );
  120. double minScaleArc() const;
  121. double maxScaleArc() const;
  122. virtual void setOrigin( double );
  123. double origin() const;
  124. void setDirection( Direction );
  125. Direction direction() const;
  126. virtual void setNeedle( QwtDialNeedle * );
  127. const QwtDialNeedle *needle() const;
  128. QwtDialNeedle *needle();
  129. QRect boundingRect() const;
  130. QRect contentsRect() const;
  131. virtual QRect scaleContentsRect() const;
  132. virtual QSize sizeHint() const;
  133. virtual QSize minimumSizeHint() const;
  134. virtual void setScaleDraw( QwtDialScaleDraw * );
  135. QwtDialScaleDraw *scaleDraw();
  136. const QwtDialScaleDraw *scaleDraw() const;
  137. protected:
  138. virtual void paintEvent( QPaintEvent * );
  139. virtual void resizeEvent( QResizeEvent * );
  140. virtual void keyPressEvent( QKeyEvent * );
  141. virtual void updateMask();
  142. virtual void drawFrame( QPainter *p );
  143. virtual void drawContents( QPainter * ) const;
  144. virtual void drawFocusIndicator( QPainter * ) const;
  145. virtual void drawScale( QPainter *, const QPoint &center,
  146. int radius, double origin, double arcMin, double arcMax ) const;
  147. /*!
  148. Draw the contents inside the scale
  149. Paints nothing.
  150. \param painter Painter
  151. \param center Center of the contents circle
  152. \param radius Radius of the contents circle
  153. */
  154. virtual void drawScaleContents( QPainter *painter,
  155. const QPoint &center, int radius ) const;
  156. virtual void drawNeedle( QPainter *, const QPoint &,
  157. int radius, double direction, QPalette::ColorGroup ) const;
  158. virtual QwtText scaleLabel( double ) const;
  159. void updateScale();
  160. virtual void rangeChange();
  161. virtual void valueChange();
  162. virtual double getValue( const QPoint & );
  163. virtual void getScrollMode( const QPoint &,
  164. int &scrollMode, int &direction );
  165. private:
  166. void initDial();
  167. class PrivateData;
  168. PrivateData *d_data;
  169. };
  170. #endif