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