qwt_abstract_slider.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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_ABSTRACT_SLIDER_H
  10. #define QWT_ABSTRACT_SLIDER_H
  11. #include "qwt_global.h"
  12. #include "qwt_abstract_scale.h"
  13. /*!
  14. \brief An abstract base class for slider widgets with a scale
  15. A slider widget displays a value according to a scale.
  16. The class is designed as a common super class for widgets like
  17. QwtKnob, QwtDial and QwtSlider.
  18. When the slider is nor readOnly() its value can be modified
  19. by keyboard, mouse and wheel inputs.
  20. The range of the slider is divided into a number of steps from
  21. which the value increments according to user inputs depend.
  22. Only for linear scales the number of steps correspond with
  23. a fixed step size.
  24. */
  25. class QWT_EXPORT QwtAbstractSlider: public QwtAbstractScale
  26. {
  27. Q_OBJECT
  28. Q_PROPERTY( double value READ value WRITE setValue )
  29. Q_PROPERTY( uint totalSteps READ totalSteps WRITE setTotalSteps )
  30. Q_PROPERTY( uint singleSteps READ singleSteps WRITE setSingleSteps )
  31. Q_PROPERTY( uint pageSteps READ pageSteps WRITE setPageSteps )
  32. Q_PROPERTY( bool stepAlignment READ stepAlignment WRITE setStepAlignment )
  33. Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
  34. Q_PROPERTY( bool tracking READ isTracking WRITE setTracking )
  35. Q_PROPERTY( bool wrapping READ wrapping WRITE setWrapping )
  36. Q_PROPERTY( bool invertedControls READ invertedControls WRITE setInvertedControls )
  37. public:
  38. explicit QwtAbstractSlider( QWidget *parent = NULL );
  39. virtual ~QwtAbstractSlider();
  40. void setValid( bool );
  41. bool isValid() const;
  42. double value() const;
  43. void setWrapping( bool );
  44. bool wrapping() const;
  45. void setTotalSteps( uint );
  46. uint totalSteps() const;
  47. void setSingleSteps( uint );
  48. uint singleSteps() const;
  49. void setPageSteps( uint );
  50. uint pageSteps() const;
  51. void setStepAlignment( bool );
  52. bool stepAlignment() const;
  53. void setTracking( bool );
  54. bool isTracking() const;
  55. void setReadOnly( bool );
  56. bool isReadOnly() const;
  57. void setInvertedControls( bool );
  58. bool invertedControls() const;
  59. public Q_SLOTS:
  60. void setValue( double value );
  61. Q_SIGNALS:
  62. /*!
  63. \brief Notify a change of value.
  64. When tracking is enabled (default setting),
  65. this signal will be emitted every time the value changes.
  66. \param value New value
  67. \sa setTracking(), sliderMoved()
  68. */
  69. void valueChanged( double value );
  70. /*!
  71. This signal is emitted when the user presses the
  72. movable part of the slider.
  73. */
  74. void sliderPressed();
  75. /*!
  76. This signal is emitted when the user releases the
  77. movable part of the slider.
  78. */
  79. void sliderReleased();
  80. /*!
  81. This signal is emitted when the user moves the
  82. slider with the mouse.
  83. \param value New value
  84. \sa valueChanged()
  85. */
  86. void sliderMoved( double value );
  87. protected:
  88. virtual void mousePressEvent( QMouseEvent * );
  89. virtual void mouseReleaseEvent( QMouseEvent * );
  90. virtual void mouseMoveEvent( QMouseEvent * );
  91. virtual void keyPressEvent( QKeyEvent * );
  92. virtual void wheelEvent( QWheelEvent * );
  93. /*!
  94. \brief Determine what to do when the user presses a mouse button.
  95. \param pos Mouse position
  96. \retval True, when pos is a valid scroll position
  97. \sa scrolledTo()
  98. */
  99. virtual bool isScrollPosition( const QPoint &pos ) const = 0;
  100. /*!
  101. \brief Determine the value for a new position of the
  102. movable part of the slider
  103. \param pos Mouse position
  104. \return Value for the mouse position
  105. \sa isScrollPosition()
  106. */
  107. virtual double scrolledTo( const QPoint &pos ) const = 0;
  108. void incrementValue( int stepCount );
  109. virtual void scaleChange();
  110. protected:
  111. virtual void sliderChange();
  112. double incrementedValue(
  113. double value, int stepCount ) const;
  114. private:
  115. double alignedValue( double ) const;
  116. double boundedValue( double ) const;
  117. class PrivateData;
  118. PrivateData *d_data;
  119. };
  120. #endif