Skip to content
qwt_counter.h 4.24 KiB
Newer Older
pixhawk's avatar
pixhawk committed
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
pixhawk's avatar
pixhawk committed
 * 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
#include <qwidget.h>
pixhawk's avatar
pixhawk committed

/*!
  \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
  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

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

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

Bryant's avatar
Bryant committed
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

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

Bryant's avatar
Bryant committed
class QWT_EXPORT QwtCounter : public QWidget
pixhawk's avatar
pixhawk committed
{
    Q_OBJECT

Bryant's avatar
Bryant committed
    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
    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
    Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
    Q_PROPERTY( bool wrapping READ wrapping WRITE setWrapping )
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
public:
    //! Button index
    enum Button
    {
        //! Button intended for minor steps
Bryant's avatar
Bryant committed

        //! Button intended for medium steps
Bryant's avatar
Bryant committed

        //! Button intended for large steps
Bryant's avatar
Bryant committed

        //! Number of buttons
pixhawk's avatar
pixhawk committed
    };

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

Bryant's avatar
Bryant committed
    void setValid( bool );
    bool isValid() const;
Bryant's avatar
Bryant committed
    void setWrapping( bool );
    bool wrapping() const;

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

    void setNumButtons( int n );
pixhawk's avatar
pixhawk committed
    int numButtons() const;
Bryant's avatar
Bryant committed
    void setIncSteps( QwtCounter::Button btn, int nSteps );
    int incSteps( QwtCounter::Button btn ) const;
pixhawk's avatar
pixhawk committed

    virtual QSize sizeHint() const;

Bryant's avatar
Bryant committed
    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

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

Bryant's avatar
Bryant committed
    void setStepButton1( int nSteps );
pixhawk's avatar
pixhawk committed
    int stepButton1() const;
Bryant's avatar
Bryant committed

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

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

Bryant's avatar
Bryant committed
    double value() const;

public Q_SLOTS:
    void setValue( double );


Q_SIGNALS:
pixhawk's avatar
pixhawk committed
    /*!
        This signal is emitted when a button has been released
        \param value The new value
    */
Bryant's avatar
Bryant committed
    void buttonReleased ( double value );
pixhawk's avatar
pixhawk committed

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

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

Bryant's avatar
Bryant committed
private Q_SLOTS:
pixhawk's avatar
pixhawk committed
    void btnReleased();
    void btnClicked();
    void textChanged();

private:
Bryant's avatar
Bryant committed
    void incrementValue( int numSteps );
pixhawk's avatar
pixhawk committed
    void initCounter();
    void updateButtons();
Bryant's avatar
Bryant committed
    void showNumber( double );
pixhawk's avatar
pixhawk committed
    class PrivateData;
    PrivateData *d_data;
};

#endif