qwt_dial.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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_abstract_scale_draw.h"
  14. #include <qframe.h>
  15. #include <qpalette.h>
  16. class QwtDialNeedle;
  17. class QwtRoundScaleDraw;
  18. /*!
  19. \brief QwtDial class provides a rounded range control.
  20. QwtDial is intended as base class for dial widgets like
  21. speedometers, compass widgets, clocks ...
  22. \image html dials2.png
  23. A dial contains a scale and a needle indicating the current value
  24. of the dial. Depending on Mode one of them is fixed and the
  25. other is rotating. If not isReadOnly() the
  26. dial can be rotated by dragging the mouse or using keyboard inputs
  27. (see QwtAbstractSlider::keyPressEvent()). A dial might be wrapping, what means
  28. a rotation below/above one limit continues on the other limit (f.e compass).
  29. The scale might cover any arc of the dial, its values are related to
  30. the origin() of the dial.
  31. Often dials have to be updated very often according to values from external
  32. devices. For these high refresh rates QwtDial caches as much as possible.
  33. For derived classes it might be necessary to clear these caches manually
  34. according to attribute changes using invalidateCache().
  35. \sa QwtCompass, QwtAnalogClock, QwtDialNeedle
  36. \note The controls and dials examples shows different types of dials.
  37. \note QDial is more similar to QwtKnob than to QwtDial
  38. */
  39. class QWT_EXPORT QwtDial: public QwtAbstractSlider
  40. {
  41. Q_OBJECT
  42. Q_ENUMS( Shadow Mode Direction )
  43. Q_PROPERTY( int lineWidth READ lineWidth WRITE setLineWidth )
  44. Q_PROPERTY( Shadow frameShadow READ frameShadow WRITE setFrameShadow )
  45. Q_PROPERTY( Mode mode READ mode WRITE setMode )
  46. Q_PROPERTY( double origin READ origin WRITE setOrigin )
  47. Q_PROPERTY( double minScaleArc READ minScaleArc WRITE setMinScaleArc )
  48. Q_PROPERTY( double maxScaleArc READ maxScaleArc WRITE setMaxScaleArc )
  49. public:
  50. /*!
  51. \brief Frame shadow
  52. Unfortunately it is not possible to use QFrame::Shadow
  53. as a property of a widget that is not derived from QFrame.
  54. The following enum is made for the designer only. It is safe
  55. to use QFrame::Shadow instead.
  56. */
  57. enum Shadow
  58. {
  59. //! QFrame::Plain
  60. Plain = QFrame::Plain,
  61. //! QFrame::Raised
  62. Raised = QFrame::Raised,
  63. //! QFrame::Sunken
  64. Sunken = QFrame::Sunken
  65. };
  66. //! Mode controlling whether the needle or the scale is rotating
  67. enum Mode
  68. {
  69. //! The needle is rotating
  70. RotateNeedle,
  71. //! The needle is fixed, the scales are rotating
  72. RotateScale
  73. };
  74. explicit QwtDial( QWidget *parent = NULL );
  75. virtual ~QwtDial();
  76. void setFrameShadow( Shadow );
  77. Shadow frameShadow() const;
  78. void setLineWidth( int );
  79. int lineWidth() const;
  80. void setMode( Mode );
  81. Mode mode() const;
  82. void setScaleArc( double minArc, double maxArc );
  83. void setMinScaleArc( double );
  84. double minScaleArc() const;
  85. void setMaxScaleArc( double );
  86. double maxScaleArc() const;
  87. virtual void setOrigin( double );
  88. double origin() const;
  89. void setNeedle( QwtDialNeedle * );
  90. const QwtDialNeedle *needle() const;
  91. QwtDialNeedle *needle();
  92. QRect boundingRect() const;
  93. QRect innerRect() const;
  94. virtual QRect scaleInnerRect() const;
  95. virtual QSize sizeHint() const;
  96. virtual QSize minimumSizeHint() const;
  97. void setScaleDraw( QwtRoundScaleDraw * );
  98. QwtRoundScaleDraw *scaleDraw();
  99. const QwtRoundScaleDraw *scaleDraw() const;
  100. protected:
  101. virtual void wheelEvent( QWheelEvent * );
  102. virtual void paintEvent( QPaintEvent * );
  103. virtual void changeEvent( QEvent * );
  104. virtual void drawFrame( QPainter * );
  105. virtual void drawContents( QPainter * ) const;
  106. virtual void drawFocusIndicator( QPainter * ) const;
  107. void invalidateCache();
  108. virtual void drawScale( QPainter *,
  109. const QPointF &center, double radius ) const;
  110. virtual void drawScaleContents( QPainter *painter,
  111. const QPointF &center, double radius ) const;
  112. virtual void drawNeedle( QPainter *, const QPointF &,
  113. double radius, double direction, QPalette::ColorGroup ) const;
  114. virtual double scrolledTo( const QPoint & ) const;
  115. virtual bool isScrollPosition( const QPoint & ) const;
  116. virtual void sliderChange();
  117. virtual void scaleChange();
  118. private:
  119. void setAngleRange( double angle, double span );
  120. void drawNeedle( QPainter * ) const;
  121. class PrivateData;
  122. PrivateData *d_data;
  123. };
  124. #endif