qwt_counter.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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_COUNTER_H
  10. #define QWT_COUNTER_H
  11. #include "qwt_global.h"
  12. #include <qwidget.h>
  13. /*!
  14. \brief The Counter Widget
  15. A Counter consists of a label displaying a number and
  16. one ore more (up to three) push buttons on each side
  17. of the label which can be used to increment or decrement
  18. the counter's value.
  19. A counter has a range from a minimum value to a maximum value
  20. and a step size. When the wrapping property is set
  21. the counter is circular.
  22. The number of steps by which a button increments or decrements the value
  23. can be specified using setIncSteps(). The number of buttons can be
  24. changed with setNumButtons().
  25. Example:
  26. \code
  27. #include <qwt_counter.h>
  28. QwtCounter *counter = new QwtCounter(parent);
  29. counter->setRange(0.0, 100.0); // From 0.0 to 100
  30. counter->setSingleStep( 1.0 ); // Step size 1.0
  31. counter->setNumButtons(2); // Two buttons each side
  32. counter->setIncSteps(QwtCounter::Button1, 1); // Button 1 increments 1 step
  33. counter->setIncSteps(QwtCounter::Button2, 20); // Button 2 increments 20 steps
  34. connect(counter, SIGNAL(valueChanged(double)), myClass, SLOT(newValue(double)));
  35. \endcode
  36. */
  37. class QWT_EXPORT QwtCounter : public QWidget
  38. {
  39. Q_OBJECT
  40. Q_PROPERTY( double value READ value WRITE setValue )
  41. Q_PROPERTY( double minimum READ minimum WRITE setMinimum )
  42. Q_PROPERTY( double maximum READ maximum WRITE setMaximum )
  43. Q_PROPERTY( double singleStep READ singleStep WRITE setSingleStep )
  44. Q_PROPERTY( int numButtons READ numButtons WRITE setNumButtons )
  45. Q_PROPERTY( int stepButton1 READ stepButton1 WRITE setStepButton1 )
  46. Q_PROPERTY( int stepButton2 READ stepButton2 WRITE setStepButton2 )
  47. Q_PROPERTY( int stepButton3 READ stepButton3 WRITE setStepButton3 )
  48. Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
  49. Q_PROPERTY( bool wrapping READ wrapping WRITE setWrapping )
  50. public:
  51. //! Button index
  52. enum Button
  53. {
  54. //! Button intended for minor steps
  55. Button1,
  56. //! Button intended for medium steps
  57. Button2,
  58. //! Button intended for large steps
  59. Button3,
  60. //! Number of buttons
  61. ButtonCnt
  62. };
  63. explicit QwtCounter( QWidget *parent = NULL );
  64. virtual ~QwtCounter();
  65. void setValid( bool );
  66. bool isValid() const;
  67. void setWrapping( bool );
  68. bool wrapping() const;
  69. bool isReadOnly() const;
  70. void setReadOnly( bool );
  71. void setNumButtons( int );
  72. int numButtons() const;
  73. void setIncSteps( QwtCounter::Button, int numSteps );
  74. int incSteps( QwtCounter::Button ) const;
  75. virtual QSize sizeHint() const;
  76. double singleStep() const;
  77. void setSingleStep( double stepSize );
  78. void setRange( double min, double max );
  79. double minimum() const;
  80. void setMinimum( double );
  81. double maximum() const;
  82. void setMaximum( double );
  83. void setStepButton1( int nSteps );
  84. int stepButton1() const;
  85. void setStepButton2( int nSteps );
  86. int stepButton2() const;
  87. void setStepButton3( int nSteps );
  88. int stepButton3() const;
  89. double value() const;
  90. public Q_SLOTS:
  91. void setValue( double );
  92. Q_SIGNALS:
  93. /*!
  94. This signal is emitted when a button has been released
  95. \param value The new value
  96. */
  97. void buttonReleased ( double value );
  98. /*!
  99. This signal is emitted when the counter's value has changed
  100. \param value The new value
  101. */
  102. void valueChanged ( double value );
  103. protected:
  104. virtual bool event( QEvent * );
  105. virtual void wheelEvent( QWheelEvent * );
  106. virtual void keyPressEvent( QKeyEvent * );
  107. private Q_SLOTS:
  108. void btnReleased();
  109. void btnClicked();
  110. void textChanged();
  111. private:
  112. void incrementValue( int numSteps );
  113. void initCounter();
  114. void updateButtons();
  115. void showNumber( double );
  116. class PrivateData;
  117. PrivateData *d_data;
  118. };
  119. #endif