Classes | Public Types | Public Member Functions | Protected Member Functions | Properties

QwtKnob Class Reference

The Knob Widget. More...

#include <qwt_knob.h>

Inheritance diagram for QwtKnob:
Inheritance graph
[legend]
Collaboration diagram for QwtKnob:
Collaboration graph
[legend]

List of all members.

Classes

class  PrivateData

Public Types

enum  Symbol { Line, Dot }

Public Member Functions

 QwtKnob (QWidget *parent=NULL)
 QwtKnob (QWidget *parent, const char *name)
virtual ~QwtKnob ()
 Destructor.
void setKnobWidth (int w)
 Change the knob's width.
int knobWidth () const
void setTotalAngle (double angle)
 Set the total angle by which the knob can be turned.
double totalAngle () const
void setBorderWidth (int bw)
 Set the knob's border width.
int borderWidth () const
void setSymbol (Symbol)
 Set the symbol of the knob.
Symbol symbol () const
virtual QSize sizeHint () const
virtual QSize minimumSizeHint () const
 Return a minimum size hint.
void setScaleDraw (QwtRoundScaleDraw *)
const QwtRoundScaleDrawscaleDraw () const
QwtRoundScaleDrawscaleDraw ()

Protected Member Functions

virtual void paintEvent (QPaintEvent *e)
virtual void resizeEvent (QResizeEvent *e)
void draw (QPainter *p, const QRect &ur)
void drawKnob (QPainter *p, const QRect &r)
 Draw the knob.
void drawMarker (QPainter *p, double arc, const QColor &c)
 Draw the marker at the knob's front.

Properties

int knobWidth
 Return the width of the knob.
int borderWidth
 Return the border width.
double totalAngle
 Return the total angle.
Symbol symbol

Detailed Description

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.

knob.png
See also:
QwtAbstractSlider and QwtAbstractScale for the descriptions of the inherited members.

Definition at line 34 of file qwt_knob.h.


Member Enumeration Documentation

Symbol

See also:
QwtKnob::QwtKnob()
Enumerator:
Line 
Dot 

Definition at line 49 of file qwt_knob.h.

{ Line, Dot };

Constructor & Destructor Documentation

QwtKnob::QwtKnob ( QWidget *  parent = NULL ) [explicit]

Constructor

Parameters:
parentParent widget

Definition at line 56 of file qwt_knob.cpp.

                               : 
    QwtAbstractSlider(Qt::Horizontal, parent)
{
    initKnob();
}
QwtKnob::QwtKnob ( QWidget *  parent,
const char *  name 
) [explicit]

Constructor

Parameters:
parentParent widget
nameObject name

Definition at line 68 of file qwt_knob.cpp.

                                                 : 
    QwtAbstractSlider(Qt::Horizontal, parent)
{
    setName(name);
    initKnob();
}
QwtKnob::~QwtKnob (  ) [virtual]

Destructor.

Definition at line 96 of file qwt_knob.cpp.

{
    delete d_data;
}

Member Function Documentation

int QwtKnob::borderWidth (  ) const
void QwtKnob::draw ( QPainter *  painter,
const QRect &  rect 
) [protected]

Repaint the knob

Parameters:
painterPainter
rectUpdate rectangle

Definition at line 387 of file qwt_knob.cpp.

References QwtAbstractScaleDraw::draw(), QwtPainter::drawFocusRect(), drawKnob(), QwtKnob::PrivateData::knobRect, and scaleDraw().

Referenced by paintEvent().

{
    if ( !d_data->knobRect.contains( rect ) ) // event from valueChange()
    {
#if QT_VERSION < 0x040000
        scaleDraw()->draw( painter, colorGroup() );
#else
        scaleDraw()->draw( painter, palette() );
#endif
    }

    drawKnob( painter, d_data->knobRect );

    if ( hasFocus() )
        QwtPainter::drawFocusRect(painter, this);
}
void QwtKnob::drawKnob ( QPainter *  painter,
const QRect &  r 
) [protected]

Draw the knob.

Parameters:
painterpainter
rBounding rectangle of the knob (without scale)

Definition at line 187 of file qwt_knob.cpp.

References QwtKnob::PrivateData::angle, QwtKnob::PrivateData::borderWidth, drawMarker(), QwtAbstractSlider::isValid(), and qwtMin.

Referenced by draw().

{
#if QT_VERSION < 0x040000
    const QBrush buttonBrush = colorGroup().brush(QColorGroup::Button);
    const QColor buttonTextColor = colorGroup().buttonText();
    const QColor lightColor = colorGroup().light();
    const QColor darkColor = colorGroup().dark();
#else
    const QBrush buttonBrush = palette().brush(QPalette::Button);
    const QColor buttonTextColor = palette().color(QPalette::ButtonText);
    const QColor lightColor = palette().color(QPalette::Light);
    const QColor darkColor = palette().color(QPalette::Dark);
#endif

    const int bw2 = d_data->borderWidth / 2;

    const int radius = (qwtMin(r.width(), r.height()) - bw2) / 2;

    const QRect aRect( 
        r.center().x() - radius, r.center().y() - radius,
        2 * radius, 2 * radius);

    //
    // draw button face
    //
    painter->setBrush(buttonBrush);
    painter->drawEllipse(aRect);

    //
    // draw button shades
    //
    QPen pn;
    pn.setWidth(d_data->borderWidth);

    pn.setColor(lightColor);
    painter->setPen(pn);
    painter->drawArc(aRect, 45*16, 180*16);

    pn.setColor(darkColor);
    painter->setPen(pn);
    painter->drawArc(aRect, 225*16, 180*16);

    //
    // draw marker
    //
    if ( isValid() )
        drawMarker(painter, d_data->angle, buttonTextColor);
}
void QwtKnob::drawMarker ( QPainter *  p,
double  arc,
const QColor &  c 
) [protected]

Draw the marker at the knob's front.

Parameters:
pPainter
arcAngle of the marker
cMarker color

Definition at line 410 of file qwt_knob.cpp.

References QwtKnob::PrivateData::borderWidth, Dot, QwtKnob::PrivateData::dotWidth, QwtKnob::PrivateData::knobRect, Line, M_PI, qwtMax, and QwtKnob::PrivateData::symbol.

Referenced by drawKnob().

{
    const double rarc = arc * M_PI / 180.0;
    const double ca = cos(rarc);
    const double sa = - sin(rarc);

    int radius = d_data->knobRect.width() / 2 - d_data->borderWidth;
    if (radius < 3) 
        radius = 3; 

    const int ym = d_data->knobRect.y() + radius + d_data->borderWidth;
    const int xm = d_data->knobRect.x() + radius + d_data->borderWidth;

    switch (d_data->symbol)
    {
        case Dot:
        {
            p->setBrush(c);
            p->setPen(Qt::NoPen);

            const double rb = double(qwtMax(radius - 4 - d_data->dotWidth / 2, 0));
            p->drawEllipse(xm - qRound(sa * rb) - d_data->dotWidth / 2,
                   ym - qRound(ca * rb) - d_data->dotWidth / 2,
                   d_data->dotWidth, d_data->dotWidth);
            break;
        }
        case Line:
        {
            p->setPen(QPen(c, 2));

            const double rb = qwtMax(double((radius - 4) / 3.0), 0.0);
            const double re = qwtMax(double(radius - 4), 0.0);
            
            p->drawLine ( xm - qRound(sa * rb), ym - qRound(ca * rb),
                xm - qRound(sa * re), ym - qRound(ca * re));
            
            break;
        }
    }
}
int QwtKnob::knobWidth (  ) const
QSize QwtKnob::minimumSizeHint (  ) const [virtual]

Return a minimum size hint.

Warning:
The return value of QwtKnob::minimumSizeHint() depends on the font and the scale.

Definition at line 541 of file qwt_knob.cpp.

References QwtRoundScaleDraw::extent(), QwtKnob::PrivateData::knobWidth, QwtKnob::PrivateData::scaleDist, and scaleDraw().

Referenced by sizeHint().

{
    // Add the scale radial thickness to the knobWidth
    const int sh = scaleDraw()->extent( QPen(), font() );
    const int d = 2 * sh + 2 * d_data->scaleDist + d_data->knobWidth;

    return QSize( d, d );
}
void QwtKnob::paintEvent ( QPaintEvent *  e ) [protected, virtual]

Repaint the knob

Parameters:
ePaint event

Definition at line 365 of file qwt_knob.cpp.

References draw(), and QwtPaintBuffer::painter().

{
    const QRect &ur = e->rect();
    if ( ur.isValid() ) 
    {
#if QT_VERSION < 0x040000
        QwtPaintBuffer paintBuffer(this, ur);
        draw(paintBuffer.painter(), ur);
#else
        QPainter painter(this);
        painter.setRenderHint(QPainter::Antialiasing);
        draw(&painter, ur);
#endif
    }
}
void QwtKnob::resizeEvent ( QResizeEvent *  e ) [protected, virtual]

Qt Resize Event

Definition at line 329 of file qwt_knob.cpp.

{
    layoutKnob( false );
}
const QwtRoundScaleDraw * QwtKnob::scaleDraw (  ) const
Returns:
the scale draw of the knob
See also:
setScaleDraw()

Definition at line 168 of file qwt_knob.cpp.

References QwtAbstractScale::abstractScaleDraw().

Referenced by draw(), minimumSizeHint(), and setTotalAngle().

QwtRoundScaleDraw * QwtKnob::scaleDraw (  )
Returns:
the scale draw of the knob
See also:
setScaleDraw()

Definition at line 177 of file qwt_knob.cpp.

References QwtAbstractScale::abstractScaleDraw().

void QwtKnob::setBorderWidth ( int  bw )

Set the knob's border width.

Parameters:
bwnew border width

Definition at line 473 of file qwt_knob.cpp.

References QwtKnob::PrivateData::borderWidth, and qwtMax.

{
    d_data->borderWidth = qwtMax(bw, 0);
    layoutKnob();
}
void QwtKnob::setKnobWidth ( int  w )

Change the knob's width.

The specified width must be >= 5, or it will be clipped.

Parameters:
wNew width

Definition at line 457 of file qwt_knob.cpp.

References QwtKnob::PrivateData::knobWidth, and qwtMax.

{
    d_data->knobWidth = qwtMax(w,5);
    layoutKnob();
}
void QwtKnob::setScaleDraw ( QwtRoundScaleDraw scaleDraw )

Change the scale draw of the knob

For changing the labels of the scales, it is necessary to derive from QwtRoundScaleDraw and overload QwtRoundScaleDraw::label().

See also:
scaleDraw()

Definition at line 158 of file qwt_knob.cpp.

References QwtAbstractScale::setAbstractScaleDraw(), setTotalAngle(), and QwtKnob::PrivateData::totalAngle.

{
    setAbstractScaleDraw(scaleDraw);
    setTotalAngle(d_data->totalAngle);
}
void QwtKnob::setSymbol ( QwtKnob::Symbol  s )

Set the symbol of the knob.

See also:
symbol()

Definition at line 105 of file qwt_knob.cpp.

References QwtKnob::PrivateData::symbol.

{
    if ( d_data->symbol != s )
    {
        d_data->symbol = s;
        update();
    }
}
void QwtKnob::setTotalAngle ( double  angle )

Set the total angle by which the knob can be turned.

Parameters:
angleAngle in degrees.

The default angle is 270 degrees. It is possible to specify an angle of more than 360 degrees so that the knob can be turned several times around its axis.

Definition at line 131 of file qwt_knob.cpp.

References scaleDraw(), QwtRoundScaleDraw::setAngleRange(), and QwtKnob::PrivateData::totalAngle.

Referenced by setScaleDraw().

{
    if (angle < 10.0)
       d_data->totalAngle = 10.0;
    else
       d_data->totalAngle = angle;

    scaleDraw()->setAngleRange( -0.5 * d_data->totalAngle, 
        0.5 * d_data->totalAngle);
    layoutKnob();
}
QSize QwtKnob::sizeHint (  ) const [virtual]
Returns:
minimumSizeHint()

Definition at line 531 of file qwt_knob.cpp.

References minimumSizeHint().

{
    return minimumSizeHint();
}
Symbol QwtKnob::symbol (  ) const
double QwtKnob::totalAngle (  ) const

Property Documentation

int QwtKnob::borderWidth [read, write]

Return the border width.

Definition at line 39 of file qwt_knob.h.

int QwtKnob::knobWidth [read, write]

Return the width of the knob.

Definition at line 38 of file qwt_knob.h.

QwtKnob::Symbol QwtKnob::symbol [read, write]
Returns:
symbol of the knob
See also:
setSymbol()

Definition at line 41 of file qwt_knob.h.

double QwtKnob::totalAngle [read, write]

Return the total angle.

Definition at line 40 of file qwt_knob.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines