qwt_knob.h 2.78 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
 *
 * 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_KNOB_H
#define QWT_KNOB_H

#include "qwt_global.h"
#include "qwt_abstract_slider.h"
#include "qwt_abstract_scale.h"

class QwtRoundScaleDraw;

/*!
  \brief The Knob Widget

  The QwtKnob widget imitates look and behaviour of a volume knob on a radio.
  It contains a scale around the knob which is set up automatically or can
  be configured manually (see QwtAbstractScale).
  Automatic scrolling is enabled when the user presses a mouse
  button on the scale. For a description of signals, slots and other
  members, see QwtAbstractSlider.

  \image html knob.png
  \sa   QwtAbstractSlider and QwtAbstractScale for the descriptions
    of the inherited members.
*/

class QWT_EXPORT QwtKnob : public QwtAbstractSlider, public QwtAbstractScale
{
36
    Q_OBJECT
pixhawk's avatar
pixhawk committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    Q_ENUMS (Symbol)
    Q_PROPERTY( int knobWidth READ knobWidth WRITE setKnobWidth )
    Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth )
    Q_PROPERTY( double totalAngle READ totalAngle WRITE setTotalAngle )
    Q_PROPERTY( Symbol symbol READ symbol WRITE setSymbol )

public:
    /*!
        Symbol
        \sa QwtKnob::QwtKnob()
    */

    enum Symbol { Line, Dot };

    explicit QwtKnob(QWidget* parent = NULL);
#if QT_VERSION < 0x040000
    explicit QwtKnob(QWidget* parent, const char *name);
#endif
    virtual ~QwtKnob();

    void setKnobWidth(int w);
    int knobWidth() const;

    void setTotalAngle (double angle);
    double totalAngle() const;

    void setBorderWidth(int bw);
    int borderWidth() const;

    void setSymbol(Symbol);
    Symbol symbol() const;

    virtual QSize sizeHint() const;
    virtual QSize minimumSizeHint() const;
71

pixhawk's avatar
pixhawk committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    void setScaleDraw(QwtRoundScaleDraw *);
    const QwtRoundScaleDraw *scaleDraw() const;
    QwtRoundScaleDraw *scaleDraw();

protected:
    virtual void paintEvent(QPaintEvent *e);
    virtual void resizeEvent(QResizeEvent *e);

    void draw(QPainter *p, const QRect& ur);
    void drawKnob(QPainter *p, const QRect &r);
    void drawMarker(QPainter *p, double arc, const QColor &c);

private:
    void initKnob();
    void layoutKnob( bool update = true );
    double getValue(const QPoint &p);
    void getScrollMode( const QPoint &p, int &scrollMode, int &direction );
    void recalcAngle();
90

pixhawk's avatar
pixhawk committed
91 92 93 94 95 96 97 98 99 100
    virtual void valueChange();
    virtual void rangeChange();
    virtual void scaleChange();
    virtual void fontChange(const QFont &oldFont);

    class PrivateData;
    PrivateData *d_data;
};

#endif