qwt_knob.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_KNOB_H
  10. #define QWT_KNOB_H
  11. #include "qwt_global.h"
  12. #include "qwt_abstract_slider.h"
  13. #include "qwt_abstract_scale.h"
  14. class QwtRoundScaleDraw;
  15. /*!
  16. \brief The Knob Widget
  17. The QwtKnob widget imitates look and behaviour of a volume knob on a radio.
  18. It contains a scale around the knob which is set up automatically or can
  19. be configured manually (see QwtAbstractScale).
  20. Automatic scrolling is enabled when the user presses a mouse
  21. button on the scale. For a description of signals, slots and other
  22. members, see QwtAbstractSlider.
  23. \image html knob.png
  24. \sa QwtAbstractSlider and QwtAbstractScale for the descriptions
  25. of the inherited members.
  26. */
  27. class QWT_EXPORT QwtKnob : public QwtAbstractSlider, public QwtAbstractScale
  28. {
  29. Q_OBJECT
  30. Q_ENUMS ( Symbol )
  31. Q_PROPERTY( int knobWidth READ knobWidth WRITE setKnobWidth )
  32. Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth )
  33. Q_PROPERTY( double totalAngle READ totalAngle WRITE setTotalAngle )
  34. Q_PROPERTY( Symbol symbol READ symbol WRITE setSymbol )
  35. public:
  36. /*!
  37. Symbol
  38. \sa setSymbol()
  39. */
  40. enum Symbol
  41. {
  42. Line,
  43. Dot
  44. };
  45. explicit QwtKnob( QWidget* parent = NULL );
  46. virtual ~QwtKnob();
  47. void setKnobWidth( int w );
  48. int knobWidth() const;
  49. void setTotalAngle ( double angle );
  50. double totalAngle() const;
  51. void setBorderWidth( int bw );
  52. int borderWidth() const;
  53. void setSymbol( Symbol );
  54. Symbol symbol() const;
  55. virtual QSize sizeHint() const;
  56. virtual QSize minimumSizeHint() const;
  57. void setScaleDraw( QwtRoundScaleDraw * );
  58. const QwtRoundScaleDraw *scaleDraw() const;
  59. QwtRoundScaleDraw *scaleDraw();
  60. protected:
  61. virtual void paintEvent( QPaintEvent *e );
  62. virtual void resizeEvent( QResizeEvent *e );
  63. void draw( QPainter *p, const QRect& ur );
  64. void drawKnob( QPainter *p, const QRect &r );
  65. void drawMarker( QPainter *p, double arc, const QColor &c );
  66. private:
  67. void initKnob();
  68. void layoutKnob( bool update = true );
  69. double getValue( const QPoint &p );
  70. void getScrollMode( const QPoint &p, int &scrollMode, int &direction );
  71. void recalcAngle();
  72. virtual void valueChange();
  73. virtual void rangeChange();
  74. virtual void scaleChange();
  75. virtual void fontChange( const QFont &oldFont );
  76. class PrivateData;
  77. PrivateData *d_data;
  78. };
  79. #endif