qwt_abstract_slider.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_double_range.h"
  13. #include <qwidget.h>
  14. /*!
  15. \brief An abstract base class for slider widgets
  16. QwtAbstractSlider is a base class for
  17. slider widgets. It handles mouse events
  18. and updates the slider's value accordingly. Derived classes
  19. only have to implement the getValue() and
  20. getScrollMode() members, and should react to a
  21. valueChange(), which normally requires repainting.
  22. */
  23. class QWT_EXPORT QwtAbstractSlider : public QWidget, public QwtDoubleRange
  24. {
  25. Q_OBJECT
  26. Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
  27. Q_PROPERTY( bool valid READ isValid WRITE setValid )
  28. Q_PROPERTY( double mass READ mass WRITE setMass )
  29. Q_PROPERTY( Qt::Orientation orientation
  30. READ orientation WRITE setOrientation )
  31. public:
  32. /*!
  33. Scroll mode
  34. \sa getScrollMode()
  35. */
  36. enum ScrollMode
  37. {
  38. ScrNone,
  39. ScrMouse,
  40. ScrTimer,
  41. ScrDirect,
  42. ScrPage
  43. };
  44. explicit QwtAbstractSlider( Qt::Orientation, QWidget *parent = NULL );
  45. virtual ~QwtAbstractSlider();
  46. void setUpdateTime( int t );
  47. void stopMoving();
  48. void setTracking( bool enable );
  49. virtual void setMass( double val );
  50. virtual double mass() const;
  51. virtual void setOrientation( Qt::Orientation o );
  52. Qt::Orientation orientation() const;
  53. bool isReadOnly() const;
  54. /*
  55. Wrappers for QwtDblRange::isValid/QwtDblRange::setValid made
  56. to be available as Q_PROPERTY in the designer.
  57. */
  58. /*!
  59. \sa QwtDblRange::isValid()
  60. */
  61. bool isValid() const
  62. {
  63. return QwtDoubleRange::isValid();
  64. }
  65. /*!
  66. \param valid true/false
  67. \sa QwtDblRange::isValid()
  68. */
  69. void setValid( bool valid )
  70. {
  71. QwtDoubleRange::setValid( valid );
  72. }
  73. public Q_SLOTS:
  74. virtual void setValue( double val );
  75. virtual void fitValue( double val );
  76. virtual void incValue( int steps );
  77. virtual void setReadOnly( bool );
  78. Q_SIGNALS:
  79. /*!
  80. \brief Notify a change of value.
  81. In the default setting
  82. (tracking enabled), this signal will be emitted every
  83. time the value changes ( see setTracking() ).
  84. \param value new value
  85. */
  86. void valueChanged( double value );
  87. /*!
  88. This signal is emitted when the user presses the
  89. movable part of the slider (start ScrMouse Mode).
  90. */
  91. void sliderPressed();
  92. /*!
  93. This signal is emitted when the user releases the
  94. movable part of the slider.
  95. */
  96. void sliderReleased();
  97. /*!
  98. This signal is emitted when the user moves the
  99. slider with the mouse.
  100. \param value new value
  101. */
  102. void sliderMoved( double value );
  103. protected:
  104. virtual void setPosition( const QPoint & );
  105. virtual void valueChange();
  106. virtual void timerEvent( QTimerEvent *e );
  107. virtual void mousePressEvent( QMouseEvent *e );
  108. virtual void mouseReleaseEvent( QMouseEvent *e );
  109. virtual void mouseMoveEvent( QMouseEvent *e );
  110. virtual void keyPressEvent( QKeyEvent *e );
  111. virtual void wheelEvent( QWheelEvent *e );
  112. /*!
  113. \brief Determine the value corresponding to a specified poind
  114. This is an abstract virtual function which is called when
  115. the user presses or releases a mouse button or moves the
  116. mouse. It has to be implemented by the derived class.
  117. \param p point
  118. */
  119. virtual double getValue( const QPoint & p ) = 0;
  120. /*!
  121. \brief Determine what to do when the user presses a mouse button.
  122. This function is abstract and has to be implemented by derived classes.
  123. It is called on a mousePress event. The derived class can determine
  124. what should happen next in dependence of the position where the mouse
  125. was pressed by returning scrolling mode and direction. QwtAbstractSlider
  126. knows the following modes:
  127. - ScrNone\n
  128. Scrolling switched off. Don't change the value.
  129. - ScrMouse
  130. Change the value while the user keeps the
  131. button pressed and moves the mouse.
  132. - ScrTimer
  133. Automatic scrolling. Increment the value in the specified direction
  134. as long as the user keeps the button pressed.
  135. - ScrPage
  136. Automatic scrolling. Same as ScrTimer, but increment by page size.
  137. \param p point where the mouse was pressed
  138. \retval scrollMode The scrolling mode
  139. \retval direction direction: 1, 0, or -1.
  140. */
  141. virtual void getScrollMode( const QPoint &p,
  142. int &scrollMode, int &direction ) = 0;
  143. void setMouseOffset( double );
  144. double mouseOffset() const;
  145. int scrollMode() const;
  146. private:
  147. void buttonReleased();
  148. class PrivateData;
  149. PrivateData *d_data;
  150. };
  151. #endif