qwt_slider.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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_SLIDER_H
  10. #define QWT_SLIDER_H
  11. #include "qwt_global.h"
  12. #include "qwt_abstract_scale.h"
  13. #include "qwt_abstract_slider.h"
  14. class QwtScaleDraw;
  15. /*!
  16. \brief The Slider Widget
  17. QwtSlider is a slider widget which operates on an interval
  18. of type double. QwtSlider supports different layouts as
  19. well as a scale.
  20. \image html sliders.png
  21. \sa QwtAbstractSlider and QwtAbstractScale for the descriptions
  22. of the inherited members.
  23. */
  24. class QWT_EXPORT QwtSlider : public QwtAbstractSlider, public QwtAbstractScale
  25. {
  26. Q_OBJECT
  27. Q_ENUMS( ScalePos )
  28. Q_ENUMS( BGSTYLE )
  29. Q_PROPERTY( ScalePos scalePosition READ scalePosition
  30. WRITE setScalePosition )
  31. Q_PROPERTY( BGSTYLE bgStyle READ bgStyle WRITE setBgStyle )
  32. Q_PROPERTY( int thumbLength READ thumbLength WRITE setThumbLength )
  33. Q_PROPERTY( int thumbWidth READ thumbWidth WRITE setThumbWidth )
  34. Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth )
  35. public:
  36. /*!
  37. Scale position. QwtSlider tries to enforce valid combinations of its
  38. orientation and scale position:
  39. - Qt::Horizonal combines with NoScale, TopScale and BottomScale
  40. - Qt::Vertical combines with NoScale, LeftScale and RightScale
  41. \sa QwtSlider()
  42. */
  43. enum ScalePos
  44. {
  45. NoScale,
  46. LeftScale,
  47. RightScale,
  48. TopScale,
  49. BottomScale
  50. };
  51. /*!
  52. Background style.
  53. \sa QwtSlider()
  54. */
  55. enum BGSTYLE
  56. {
  57. BgTrough = 0x1,
  58. BgSlot = 0x2,
  59. BgBoth = BgTrough | BgSlot
  60. };
  61. explicit QwtSlider( QWidget *parent,
  62. Qt::Orientation = Qt::Horizontal,
  63. ScalePos = NoScale, BGSTYLE bgStyle = BgTrough );
  64. virtual ~QwtSlider();
  65. virtual void setOrientation( Qt::Orientation );
  66. void setBgStyle( BGSTYLE );
  67. BGSTYLE bgStyle() const;
  68. void setScalePosition( ScalePos s );
  69. ScalePos scalePosition() const;
  70. int thumbLength() const;
  71. int thumbWidth() const;
  72. int borderWidth() const;
  73. void setThumbLength( int l );
  74. void setThumbWidth( int w );
  75. void setBorderWidth( int bw );
  76. void setMargins( int x, int y );
  77. virtual QSize sizeHint() const;
  78. virtual QSize minimumSizeHint() const;
  79. void setScaleDraw( QwtScaleDraw * );
  80. const QwtScaleDraw *scaleDraw() const;
  81. protected:
  82. virtual double getValue( const QPoint &p );
  83. virtual void getScrollMode( const QPoint &p,
  84. int &scrollMode, int &direction );
  85. void draw( QPainter *p, const QRect& update_rect );
  86. virtual void drawSlider ( QPainter *p, const QRect &r );
  87. virtual void drawThumb( QPainter *p, const QRect &, int pos );
  88. virtual void resizeEvent( QResizeEvent *e );
  89. virtual void paintEvent ( QPaintEvent *e );
  90. virtual void valueChange();
  91. virtual void rangeChange();
  92. virtual void scaleChange();
  93. virtual void fontChange( const QFont &oldFont );
  94. void layoutSlider( bool update = true );
  95. int xyPosition( double v ) const;
  96. QwtScaleDraw *scaleDraw();
  97. private:
  98. void initSlider( Qt::Orientation, ScalePos scalePos, BGSTYLE bgStyle );
  99. class PrivateData;
  100. PrivateData *d_data;
  101. };
  102. #endif