qwt_knob.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. class QwtRoundScaleDraw;
  14. /*!
  15. \brief The Knob Widget
  16. The QwtKnob widget imitates look and behavior of a volume knob on a radio.
  17. It looks similar to QDial - not to QwtDial.
  18. The value range of a knob might be divided into several turns.
  19. The layout of the knob depends on the knobWidth().
  20. - width > 0
  21. The diameter of the knob is fixed and the knob is aligned
  22. according to the alignment() flags inside of the contentsRect().
  23. - width <= 0
  24. The knob is extended to the minimum of width/height of the contentsRect()
  25. and aligned in the other direction according to alignment().
  26. Setting a fixed knobWidth() is helpful to align several knobs with different
  27. scale labels.
  28. \image html knob.png
  29. */
  30. class QWT_EXPORT QwtKnob: public QwtAbstractSlider
  31. {
  32. Q_OBJECT
  33. Q_ENUMS ( KnobStyle MarkerStyle )
  34. Q_PROPERTY( KnobStyle knobStyle READ knobStyle WRITE setKnobStyle )
  35. Q_PROPERTY( int knobWidth READ knobWidth WRITE setKnobWidth )
  36. Q_PROPERTY( Qt::Alignment alignment READ alignment WRITE setAlignment )
  37. Q_PROPERTY( double totalAngle READ totalAngle WRITE setTotalAngle )
  38. Q_PROPERTY( int numTurns READ numTurns WRITE setNumTurns )
  39. Q_PROPERTY( MarkerStyle markerStyle READ markerStyle WRITE setMarkerStyle )
  40. Q_PROPERTY( int markerSize READ markerSize WRITE setMarkerSize )
  41. Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth )
  42. public:
  43. /*!
  44. \brief Style of the knob surface
  45. Depending on the KnobStyle the surface of the knob is
  46. filled from the brushes of the widget palette().
  47. \sa setKnobStyle(), knobStyle()
  48. */
  49. enum KnobStyle
  50. {
  51. //! Fill the knob with a brush from QPalette::Button.
  52. Flat,
  53. //! Build a gradient from QPalette::Midlight and QPalette::Button
  54. Raised,
  55. /*!
  56. Build a gradient from QPalette::Midlight, QPalette::Button
  57. and QPalette::Midlight
  58. */
  59. Sunken,
  60. /*!
  61. Build a radial gradient from QPalette::Button
  62. like it is used for QDial in various Qt styles.
  63. */
  64. Styled
  65. };
  66. /*!
  67. \brief Marker type
  68. The marker indicates the current value on the knob
  69. The default setting is a Notch marker.
  70. \sa setMarkerStyle(), setMarkerSize()
  71. */
  72. enum MarkerStyle
  73. {
  74. //! Don't paint any marker
  75. NoMarker = -1,
  76. //! Paint a single tick in QPalette::ButtonText color
  77. Tick,
  78. //! Paint a triangle in QPalette::ButtonText color
  79. Triangle,
  80. //! Paint a circle in QPalette::ButtonText color
  81. Dot,
  82. /*!
  83. Draw a raised ellipse with a gradient build from
  84. QPalette::Light and QPalette::Mid
  85. */
  86. Nub,
  87. /*!
  88. Draw a sunken ellipse with a gradient build from
  89. QPalette::Light and QPalette::Mid
  90. */
  91. Notch
  92. };
  93. explicit QwtKnob( QWidget* parent = NULL );
  94. virtual ~QwtKnob();
  95. void setAlignment( Qt::Alignment );
  96. Qt::Alignment alignment() const;
  97. void setKnobWidth( int );
  98. int knobWidth() const;
  99. void setNumTurns( int );
  100. int numTurns() const;
  101. void setTotalAngle ( double angle );
  102. double totalAngle() const;
  103. void setKnobStyle( KnobStyle );
  104. KnobStyle knobStyle() const;
  105. void setBorderWidth( int );
  106. int borderWidth() const;
  107. void setMarkerStyle( MarkerStyle );
  108. MarkerStyle markerStyle() const;
  109. void setMarkerSize( int );
  110. int markerSize() const;
  111. virtual QSize sizeHint() const;
  112. virtual QSize minimumSizeHint() const;
  113. void setScaleDraw( QwtRoundScaleDraw * );
  114. const QwtRoundScaleDraw *scaleDraw() const;
  115. QwtRoundScaleDraw *scaleDraw();
  116. QRect knobRect() const;
  117. protected:
  118. virtual void paintEvent( QPaintEvent * );
  119. virtual void changeEvent( QEvent * );
  120. virtual void drawKnob( QPainter *, const QRectF & ) const;
  121. virtual void drawFocusIndicator( QPainter * ) const;
  122. virtual void drawMarker( QPainter *,
  123. const QRectF &, double angle ) const;
  124. virtual double scrolledTo( const QPoint & ) const;
  125. virtual bool isScrollPosition( const QPoint & ) const;
  126. private:
  127. class PrivateData;
  128. PrivateData *d_data;
  129. };
  130. #endif