qwt_counter.h 4.24 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
5
 *
pixhawk's avatar
pixhawk committed
6 7 8 9 10 11 12 13
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#ifndef QWT_COUNTER_H
#define QWT_COUNTER_H

#include "qwt_global.h"
Bryant's avatar
Bryant committed
14
#include <qwidget.h>
pixhawk's avatar
pixhawk committed
15 16 17 18 19 20 21 22 23

/*!
  \brief The Counter Widget

  A Counter consists of a label displaying a number and
  one ore more (up to three) push buttons on each side
  of the label which can be used to increment or decrement
  the counter's value.

Bryant's avatar
Bryant committed
24 25 26 27 28 29 30
  A counter has a range from a minimum value to a maximum value
  and a step size. When the wrapping property is set
  the counter is circular.
 
  The number of steps by which a button increments or decrements the value 
  can be specified using setIncSteps(). The number of buttons can be 
  changed with setNumButtons().
pixhawk's avatar
pixhawk committed
31 32 33

  Example:
\code
Bryant's avatar
Bryant committed
34
#include <qwt_counter.h>
pixhawk's avatar
pixhawk committed
35

Bryant's avatar
Bryant committed
36
QwtCounter *counter = new QwtCounter(parent);
pixhawk's avatar
pixhawk committed
37

Bryant's avatar
Bryant committed
38 39 40 41 42
counter->setRange(0.0, 100.0);                  // From 0.0 to 100
counter->setSingleStep( 1.0 );                  // Step size 1.0
counter->setNumButtons(2);                      // Two buttons each side
counter->setIncSteps(QwtCounter::Button1, 1);   // Button 1 increments 1 step
counter->setIncSteps(QwtCounter::Button2, 20);  // Button 2 increments 20 steps
pixhawk's avatar
pixhawk committed
43

Bryant's avatar
Bryant committed
44
connect(counter, SIGNAL(valueChanged(double)), myClass, SLOT(newValue(double)));
pixhawk's avatar
pixhawk committed
45 46 47
\endcode
 */

Bryant's avatar
Bryant committed
48
class QWT_EXPORT QwtCounter : public QWidget
pixhawk's avatar
pixhawk committed
49 50 51
{
    Q_OBJECT

Bryant's avatar
Bryant committed
52 53 54 55 56
    Q_PROPERTY( double value READ value WRITE setValue )
    Q_PROPERTY( double minimum READ minimum WRITE setMinimum )
    Q_PROPERTY( double maximum READ maximum WRITE setMaximum )
    Q_PROPERTY( double singleStep READ singleStep WRITE setSingleStep )

pixhawk's avatar
pixhawk committed
57 58 59 60 61
    Q_PROPERTY( int numButtons READ numButtons WRITE setNumButtons )
    Q_PROPERTY( int stepButton1 READ stepButton1 WRITE setStepButton1 )
    Q_PROPERTY( int stepButton2 READ stepButton2 WRITE setStepButton2 )
    Q_PROPERTY( int stepButton3 READ stepButton3 WRITE setStepButton3 )

Bryant's avatar
Bryant committed
62 63
    Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
    Q_PROPERTY( bool wrapping READ wrapping WRITE setWrapping )
pixhawk's avatar
pixhawk committed
64

Bryant's avatar
Bryant committed
65 66 67 68 69
public:
    //! Button index
    enum Button
    {
        //! Button intended for minor steps
70
        Button1,
Bryant's avatar
Bryant committed
71 72

        //! Button intended for medium steps
73
        Button2,
Bryant's avatar
Bryant committed
74 75

        //! Button intended for large steps
76
        Button3,
Bryant's avatar
Bryant committed
77 78

        //! Number of buttons
79
        ButtonCnt
pixhawk's avatar
pixhawk committed
80 81
    };

Bryant's avatar
Bryant committed
82
    explicit QwtCounter( QWidget *parent = NULL );
pixhawk's avatar
pixhawk committed
83 84
    virtual ~QwtCounter();

Bryant's avatar
Bryant committed
85 86
    void setValid( bool );
    bool isValid() const;
87

Bryant's avatar
Bryant committed
88 89 90 91 92 93 94
    void setWrapping( bool );
    bool wrapping() const;

    bool isReadOnly() const;
    void setReadOnly( bool );

    void setNumButtons( int n );
pixhawk's avatar
pixhawk committed
95
    int numButtons() const;
96

Bryant's avatar
Bryant committed
97 98
    void setIncSteps( QwtCounter::Button btn, int nSteps );
    int incSteps( QwtCounter::Button btn ) const;
pixhawk's avatar
pixhawk committed
99 100 101

    virtual QSize sizeHint() const;

Bryant's avatar
Bryant committed
102 103 104 105 106 107 108
    double singleStep() const;
    void setSingleStep( double s );

    void setRange( double min, double max );
    
    double minimum() const;
    void setMinimum( double min );
pixhawk's avatar
pixhawk committed
109

Bryant's avatar
Bryant committed
110 111
    double maximum() const;
    void setMaximum( double max );
pixhawk's avatar
pixhawk committed
112

Bryant's avatar
Bryant committed
113
    void setStepButton1( int nSteps );
pixhawk's avatar
pixhawk committed
114
    int stepButton1() const;
Bryant's avatar
Bryant committed
115 116

    void setStepButton2( int nSteps );
pixhawk's avatar
pixhawk committed
117
    int stepButton2() const;
Bryant's avatar
Bryant committed
118 119

    void setStepButton3( int nSteps );
pixhawk's avatar
pixhawk committed
120 121
    int stepButton3() const;

Bryant's avatar
Bryant committed
122 123 124 125 126 127 128
    double value() const;

public Q_SLOTS:
    void setValue( double );


Q_SIGNALS:
pixhawk's avatar
pixhawk committed
129 130 131 132
    /*!
        This signal is emitted when a button has been released
        \param value The new value
    */
Bryant's avatar
Bryant committed
133
    void buttonReleased ( double value );
pixhawk's avatar
pixhawk committed
134 135 136 137 138

    /*!
        This signal is emitted when the counter's value has changed
        \param value The new value
    */
Bryant's avatar
Bryant committed
139
    void valueChanged ( double value );
pixhawk's avatar
pixhawk committed
140 141

protected:
Bryant's avatar
Bryant committed
142 143 144
    virtual bool event( QEvent * );
    virtual void wheelEvent( QWheelEvent * );
    virtual void keyPressEvent( QKeyEvent * );
pixhawk's avatar
pixhawk committed
145

Bryant's avatar
Bryant committed
146
private Q_SLOTS:
pixhawk's avatar
pixhawk committed
147 148 149 150 151
    void btnReleased();
    void btnClicked();
    void textChanged();

private:
Bryant's avatar
Bryant committed
152
    void incrementValue( int numSteps );
pixhawk's avatar
pixhawk committed
153 154
    void initCounter();
    void updateButtons();
Bryant's avatar
Bryant committed
155
    void showNumber( double );
156

pixhawk's avatar
pixhawk committed
157 158 159 160 161
    class PrivateData;
    PrivateData *d_data;
};

#endif