qwt_knob.h 4.66 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
/* -*- 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"

class QwtRoundScaleDraw;

/*!
  \brief The Knob Widget

Bryant's avatar
Bryant committed
21 22
  The QwtKnob widget imitates look and behavior of a volume knob on a radio.
  It looks similar to QDial - not to QwtDial.
pixhawk's avatar
pixhawk committed
23

Bryant's avatar
Bryant committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
  The value range of a knob might be divided into several turns.

  The layout of the knob depends on the knobWidth().

  - width > 0 
    The diameter of the knob is fixed and the knob is aligned
    according to the alignment() flags inside of the contentsRect(). 

  - width <= 0
    The knob is extended to the minimum of width/height of the contentsRect()
    and aligned in the other direction according to alignment().

  Setting a fixed knobWidth() is helpful to align several knobs with different
  scale labels.
  
pixhawk's avatar
pixhawk committed
39 40 41
  \image html knob.png
*/

Bryant's avatar
Bryant committed
42
class QWT_EXPORT QwtKnob: public QwtAbstractSlider
pixhawk's avatar
pixhawk committed
43
{
44
    Q_OBJECT
Bryant's avatar
Bryant committed
45 46 47 48

    Q_ENUMS ( KnobStyle MarkerStyle )

    Q_PROPERTY( KnobStyle knobStyle READ knobStyle WRITE setKnobStyle )
pixhawk's avatar
pixhawk committed
49
    Q_PROPERTY( int knobWidth READ knobWidth WRITE setKnobWidth )
Bryant's avatar
Bryant committed
50
    Q_PROPERTY( Qt::Alignment alignment READ alignment WRITE setAlignment )
pixhawk's avatar
pixhawk committed
51
    Q_PROPERTY( double totalAngle READ totalAngle WRITE setTotalAngle )
Bryant's avatar
Bryant committed
52 53 54 55
    Q_PROPERTY( int numTurns READ numTurns WRITE setNumTurns )
    Q_PROPERTY( MarkerStyle markerStyle READ markerStyle WRITE setMarkerStyle )
    Q_PROPERTY( int markerSize READ markerSize WRITE setMarkerSize )
    Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth )
pixhawk's avatar
pixhawk committed
56 57

public:
Bryant's avatar
Bryant committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    /*! 
       \brief Style of the knob surface

       Depending on the KnobStyle the surface of the knob is
       filled from the brushes of the widget palette().

       \sa setKnobStyle(), knobStyle()
     */
    enum KnobStyle
    {
        //! Fill the knob with a brush from QPalette::Button.
        Flat,

        //! Build a gradient from QPalette::Midlight and QPalette::Button
        Raised,

        /*! 
          Build a gradient from QPalette::Midlight, QPalette::Button
          and QPalette::Midlight
         */
        Sunken,

        /*! 
          Build a radial gradient from QPalette::Button
          like it is used for QDial in various Qt styles.
         */
        Styled
    };
pixhawk's avatar
pixhawk committed
86

Bryant's avatar
Bryant committed
87 88 89 90 91
    /*!
        \brief Marker type
 
        The marker indicates the current value on the knob
        The default setting is a Notch marker.
pixhawk's avatar
pixhawk committed
92

Bryant's avatar
Bryant committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
        \sa setMarkerStyle(), setMarkerSize()
    */
    enum MarkerStyle 
    { 
        //! Don't paint any marker
        NoMarker = -1,

        //! Paint a single tick in QPalette::ButtonText color
        Tick, 

        //! Paint a triangle in QPalette::ButtonText color
        Triangle, 

        //! Paint a circle in QPalette::ButtonText color
        Dot, 

        /*! 
          Draw a raised ellipse with a gradient build from
          QPalette::Light and QPalette::Mid
         */ 
        Nub, 

        /*! 
          Draw a sunken ellipse with a gradient build from
          QPalette::Light and QPalette::Mid
         */ 
        Notch 
    };

    explicit QwtKnob( QWidget* parent = NULL );
pixhawk's avatar
pixhawk committed
123 124
    virtual ~QwtKnob();

Bryant's avatar
Bryant committed
125 126 127 128
    void setAlignment( Qt::Alignment );
    Qt::Alignment alignment() const;

    void setKnobWidth( int );
pixhawk's avatar
pixhawk committed
129 130
    int knobWidth() const;

Bryant's avatar
Bryant committed
131 132 133 134
    void setNumTurns( int );
    int numTurns() const;

    void setTotalAngle ( double angle );
pixhawk's avatar
pixhawk committed
135 136
    double totalAngle() const;

Bryant's avatar
Bryant committed
137 138 139 140
    void setKnobStyle( KnobStyle );
    KnobStyle knobStyle() const;

    void setBorderWidth( int bw );
pixhawk's avatar
pixhawk committed
141 142
    int borderWidth() const;

Bryant's avatar
Bryant committed
143 144 145 146 147
    void setMarkerStyle( MarkerStyle );
    MarkerStyle markerStyle() const;

    void setMarkerSize( int );
    int markerSize() const;
pixhawk's avatar
pixhawk committed
148 149 150

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

Bryant's avatar
Bryant committed
152 153
    void setScaleDraw( QwtRoundScaleDraw * );

pixhawk's avatar
pixhawk committed
154 155 156
    const QwtRoundScaleDraw *scaleDraw() const;
    QwtRoundScaleDraw *scaleDraw();

Bryant's avatar
Bryant committed
157 158
    QRect knobRect() const;

pixhawk's avatar
pixhawk committed
159
protected:
Bryant's avatar
Bryant committed
160 161
    virtual void paintEvent( QPaintEvent * );
    virtual void changeEvent( QEvent * );
pixhawk's avatar
pixhawk committed
162

Bryant's avatar
Bryant committed
163
    virtual void drawKnob( QPainter *, const QRectF & ) const;
pixhawk's avatar
pixhawk committed
164

Bryant's avatar
Bryant committed
165
    virtual void drawFocusIndicator( QPainter * ) const;
166

Bryant's avatar
Bryant committed
167 168
    virtual void drawMarker( QPainter *, 
        const QRectF &, double arc ) const;
pixhawk's avatar
pixhawk committed
169

Bryant's avatar
Bryant committed
170 171 172 173
    virtual double scrolledTo( const QPoint & ) const;
    virtual bool isScrollPosition( const QPoint & ) const;

private:
pixhawk's avatar
pixhawk committed
174 175 176 177 178
    class PrivateData;
    PrivateData *d_data;
};

#endif