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

QwtDial Class Reference

QwtDial class provides a rounded range control. More...

#include <qwt_dial.h>

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

List of all members.

Classes

class  PrivateData

Public Types

enum  Shadow { Plain = QFrame::Plain, Raised = QFrame::Raised, Sunken = QFrame::Sunken }
 

Frame shadow.

More...
enum  ScaleOptions { ScaleBackbone = 1, ScaleTicks = 2, ScaleLabel = 4 }
 

see QwtDial::setScaleOptions

More...
enum  Mode { RotateNeedle, RotateScale }
enum  Direction { Clockwise, CounterClockwise }

Public Member Functions

 QwtDial (QWidget *parent=NULL)
 Constructor.
 QwtDial (QWidget *parent, const char *name)
 Constructor.
virtual ~QwtDial ()
 Destructor.
void setFrameShadow (Shadow)
Shadow frameShadow () const
bool hasVisibleBackground () const
void showBackground (bool)
void setLineWidth (int)
int lineWidth () const
void setMode (Mode)
 Change the mode of the meter.
Mode mode () const
virtual void setWrapping (bool)
bool wrapping () const
virtual void setScale (int maxMajIntv, int maxMinIntv, double step=0.0)
void setScaleArc (double min, double max)
void setScaleOptions (int)
void setScaleTicks (int minLen, int medLen, int majLen, int penWidth=1)
double minScaleArc () const
double maxScaleArc () const
virtual void setOrigin (double)
 Change the origin.
double origin () const
void setDirection (Direction)
Direction direction () const
virtual void setNeedle (QwtDialNeedle *)
const QwtDialNeedleneedle () const
QwtDialNeedleneedle ()
QRect boundingRect () const
QRect contentsRect () const
virtual QRect scaleContentsRect () const
virtual QSize sizeHint () const
virtual QSize minimumSizeHint () const
 Return a minimum size hint.
virtual void setScaleDraw (QwtDialScaleDraw *)
QwtDialScaleDrawscaleDraw ()
 Return the scale draw.
const QwtDialScaleDrawscaleDraw () const
 Return the scale draw.

Protected Member Functions

virtual void paintEvent (QPaintEvent *)
virtual void resizeEvent (QResizeEvent *)
virtual void keyPressEvent (QKeyEvent *)
virtual void updateMask ()
 Update the mask of the dial.
virtual void drawFrame (QPainter *p)
virtual void drawContents (QPainter *) const
 Draw the contents inside the frame.
virtual void drawFocusIndicator (QPainter *) const
virtual void drawScale (QPainter *, const QPoint &center, int radius, double origin, double arcMin, double arcMax) const
virtual void drawScaleContents (QPainter *painter, const QPoint &center, int radius) const
virtual void drawNeedle (QPainter *, const QPoint &, int radius, double direction, QPalette::ColorGroup) const
virtual QwtText scaleLabel (double) const
void updateScale ()
virtual void rangeChange ()
 QwtDoubleRange update hook.
virtual void valueChange ()
 QwtDoubleRange update hook.
virtual double getValue (const QPoint &)
virtual void getScrollMode (const QPoint &, int &scrollMode, int &direction)

Properties

bool visibleBackground
int lineWidth
Shadow frameShadow
Mode mode
double origin
bool wrapping
Direction direction

Friends

class QwtDialScaleDraw

Detailed Description

QwtDial class provides a rounded range control.

QwtDial is intended as base class for dial widgets like speedometers, compass widgets, clocks ...

dials2.png

A dial contains a scale and a needle indicating the current value of the dial. Depending on Mode one of them is fixed and the other is rotating. If not isReadOnly() the dial can be rotated by dragging the mouse or using keyboard inputs (see keyPressEvent()). A dial might be wrapping, what means a rotation below/above one limit continues on the other limit (f.e compass). The scale might cover any arc of the dial, its values are related to the origin() of the dial.

Qwt is missing a set of good looking needles (QwtDialNeedle). Contributions are very welcome.

See also:
QwtCompass, QwtAnalogClock, QwtDialNeedle
Note:
The examples/dials example shows different types of dials.

Definition at line 67 of file qwt_dial.h.


Member Enumeration Documentation

Direction of the dial

Enumerator:
Clockwise 
CounterClockwise 

Definition at line 123 of file qwt_dial.h.

In case of RotateNeedle the needle is rotating, in case of RotateScale, the needle points to origin() and the scale is rotating.

Enumerator:
RotateNeedle 
RotateScale 

Definition at line 114 of file qwt_dial.h.

see QwtDial::setScaleOptions

Enumerator:
ScaleBackbone 
ScaleTicks 
ScaleLabel 

Definition at line 102 of file qwt_dial.h.

    {
        ScaleBackbone = 1,
        ScaleTicks = 2,
        ScaleLabel = 4
    };

Frame shadow.

Unfortunately it is not possible to use QFrame::Shadow as a property of a widget that is not derived from QFrame. The following enum is made for the designer only. It is safe to use QFrame::Shadow instead.

Enumerator:
Plain 
Raised 
Sunken 

Definition at line 94 of file qwt_dial.h.

    {
        Plain = QFrame::Plain,
        Raised = QFrame::Raised,
        Sunken = QFrame::Sunken
    };

Constructor & Destructor Documentation

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

Constructor.

Parameters:
parentParent widget

Create a dial widget with no scale and no needle. The default origin is 90.0 with no valid value. It accepts mouse and keyboard inputs and has no step size. The default mode is QwtDial::RotateNeedle.

Definition at line 131 of file qwt_dial.cpp.

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

Constructor.

Parameters:
parentParent widget
nameObject name

Create a dial widget with no scale and no needle. The default origin is 90.0 with no valid value. It accepts mouse and keyboard inputs and has no step size. The default mode is QwtDial::RotateNeedle.

Definition at line 148 of file qwt_dial.cpp.

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

Destructor.

Definition at line 195 of file qwt_dial.cpp.

{
    delete d_data;
}

Member Function Documentation

QRect QwtDial::boundingRect (  ) const
Returns:
bounding rect of the dial including the frame
See also:
setLineWidth(), scaleContentsRect(), contentsRect()

Definition at line 299 of file qwt_dial.cpp.

References qwtMin.

Referenced by contentsRect(), drawContents(), drawFrame(), and updateMask().

{
    const int radius = qwtMin(width(), height()) / 2;

    QRect r(0, 0, 2 * radius, 2 * radius);
    r.moveCenter(rect().center());
    return r;
}
QRect QwtDial::contentsRect (  ) const
Returns:
bounding rect of the circle inside the frame
See also:
setLineWidth(), scaleContentsRect(), boundingRect()

Definition at line 282 of file qwt_dial.cpp.

References boundingRect(), and lineWidth().

Referenced by drawFocusIndicator(), getScrollMode(), and scaleContentsRect().

{
    const int lw = lineWidth();

    QRect r = boundingRect();
    if ( lw > 0 )
    {
        r.setRect(r.x() + lw, r.y() + lw, 
            r.width() - 2 * lw, r.height() - 2 * lw);
    }
    return r;
}
Direction QwtDial::direction (  ) const
void QwtDial::drawContents ( QPainter *  painter ) const [protected, virtual]

Draw the contents inside the frame.

QColorGroup::Background is the background color outside of the frame. QColorGroup::Base is the background color inside the frame. QColorGroup::Foreground is the background color inside the scale.

Parameters:
painterPainter
See also:
boundingRect(), contentsRect(), scaleContentsRect(), QWidget::setPalette()

Definition at line 584 of file qwt_dial.cpp.

References boundingRect(), CounterClockwise, QwtDial::PrivateData::direction, direction(), drawNeedle(), drawScale(), drawScaleContents(), QwtAbstractSlider::isValid(), QwtDial::PrivateData::maxScaleArc, QwtDoubleRange::maxValue(), QwtDial::PrivateData::minScaleArc, QwtDoubleRange::minValue(), mode(), origin(), QwtDial::PrivateData::origin, RotateScale, scaleContentsRect(), and QwtDoubleRange::value().

Referenced by paintEvent().

{
#if QT_VERSION < 0x040000
    if ( backgroundMode() == Qt::NoBackground || 
        colorGroup().brush(QColorGroup::Base) != 
            colorGroup().brush(QColorGroup::Background) )
#else
    if ( testAttribute(Qt::WA_NoSystemBackground) ||
        palette().brush(QPalette::Base) != 
            palette().brush(QPalette::Background) )
#endif
    {

        const QRect br = boundingRect();

        painter->save();
        painter->setPen(Qt::NoPen);

#if QT_VERSION < 0x040000
        painter->setBrush(colorGroup().brush(QColorGroup::Base));
#else
        painter->setBrush(palette().brush(QPalette::Base));
#endif

        painter->drawEllipse(br);
        painter->restore();
    }


    const QRect insideScaleRect = scaleContentsRect();
#if QT_VERSION < 0x040000
    if ( colorGroup().brush(QColorGroup::Foreground) !=
        colorGroup().brush(QColorGroup::Base) )
#else
    if ( palette().brush(QPalette::Foreground) !=
        palette().brush(QPalette::Base) )
#endif
    {
        painter->save();
        painter->setPen(Qt::NoPen);

#if QT_VERSION < 0x040000
        painter->setBrush(colorGroup().brush(QColorGroup::Foreground));
#else
        painter->setBrush(palette().brush(QPalette::Foreground));
#endif

        painter->drawEllipse(insideScaleRect.x() - 1, insideScaleRect.y() - 1,
            insideScaleRect.width(), insideScaleRect.height() );

        painter->restore();
    }

    const QPoint center = insideScaleRect.center();
    const int radius = insideScaleRect.width() / 2;

    painter->save();
    drawScaleContents(painter, center, radius);
    painter->restore();

    double direction = d_data->origin;

    if (isValid())
    {
        direction = d_data->minScaleArc;
        if ( maxValue() > minValue() && d_data->maxScaleArc > d_data->minScaleArc )
        {
            const double ratio = 
                (value() - minValue()) / (maxValue() - minValue());
            direction += ratio * (d_data->maxScaleArc - d_data->minScaleArc);
        }

        if ( d_data->direction == QwtDial::CounterClockwise )
            direction = d_data->maxScaleArc - (direction - d_data->minScaleArc);

        direction += d_data->origin;
        if ( direction >= 360.0 )
            direction -= 360.0;
        else if ( direction < 0.0 )
            direction += 360.0;
    }

    double origin = d_data->origin;
    if ( mode() == RotateScale )
    {
        origin -= direction - d_data->origin;
        direction = d_data->origin;
    }

    painter->save();
    drawScale(painter, center, radius, origin, 
        d_data->minScaleArc, d_data->maxScaleArc);
    painter->restore();

    if ( isValid() )
    {
        QPalette::ColorGroup cg;
        if ( isEnabled() )
            cg = hasFocus() ? QPalette::Active : QPalette::Inactive;
        else
            cg = QPalette::Disabled;

        painter->save();
        drawNeedle(painter, center, radius, direction, cg);
        painter->restore();
    }
}
void QwtDial::drawFocusIndicator ( QPainter *  painter ) const [protected, virtual]

Draw a dotted round circle, if !isReadOnly()

Parameters:
painterPainter

Definition at line 477 of file qwt_dial.cpp.

References contentsRect(), and QwtAbstractSlider::isReadOnly().

Referenced by paintEvent().

{
    if ( !isReadOnly() )
    {
        QRect focusRect = contentsRect();

        const int margin = 2;
        focusRect.setRect( 
            focusRect.x() + margin,
            focusRect.y() + margin,
            focusRect.width() - 2 * margin,
            focusRect.height() - 2 * margin);

#if QT_VERSION < 0x040000
        QColor color = colorGroup().color(QColorGroup::Base);
#else
        QColor color = palette().color(QPalette::Base);
#endif
        if (color.isValid())
        {
            const QColor gray(Qt::gray);

            int h, s, v;
#if QT_VERSION < 0x040000
            color.hsv(&h, &s, &v);
#else
            color.getHsv(&h, &s, &v);
#endif
            color = (v > 128) ? gray.dark(120) : gray.light(120);
        }
        else
            color = Qt::darkGray;

        painter->save();
        painter->setBrush(Qt::NoBrush);
        painter->setPen(QPen(color, 0, Qt::DotLine));
        painter->drawEllipse(focusRect);
        painter->restore();
    }
}
void QwtDial::drawFrame ( QPainter *  painter ) [protected, virtual]

Draw the frame around the dial

Parameters:
painterPainter
See also:
lineWidth(), frameShadow()

Definition at line 524 of file qwt_dial.cpp.

References boundingRect(), QwtPainter::drawRoundFrame(), QwtDial::PrivateData::frameShadow, lineWidth(), Raised, and Sunken.

Referenced by paintEvent().

{
    const int lw = lineWidth();
    const int off = (lw + 1) % 2;

    QRect r = boundingRect();
    r.setRect(r.x() + lw / 2 - off, r.y() + lw / 2 - off,
        r.width() - lw + off + 1, r.height() - lw + off + 1);
#if QT_VERSION >= 0x040000
    r.setX(r.x() + 1);
    r.setY(r.y() + 1);
    r.setWidth(r.width() - 2);
    r.setHeight(r.height() - 2);
#endif

    if ( lw > 0 )
    {
        switch(d_data->frameShadow)
        {
            case QwtDial::Raised:
#if QT_VERSION < 0x040000
                QwtPainter::drawRoundFrame(painter, r, 
                    lw, colorGroup(), false);
#else
                QwtPainter::drawRoundFrame(painter, r, 
                    lw, palette(), false);
#endif
                break;
            case QwtDial::Sunken:
#if QT_VERSION < 0x040000
                QwtPainter::drawRoundFrame(painter, r, 
                    lw, colorGroup(), true);
#else
                QwtPainter::drawRoundFrame(painter, r, 
                    lw, palette(), true);
#endif
                break;
            default: // Plain
            {
                painter->save();
                painter->setPen(QPen(Qt::black, lw));
                painter->setBrush(Qt::NoBrush);
                painter->drawEllipse(r);
                painter->restore();
            }
        }
    }
}
void QwtDial::drawNeedle ( QPainter *  painter,
const QPoint &  center,
int  radius,
double  direction,
QPalette::ColorGroup  cg 
) const [protected, virtual]

Draw the needle

Parameters:
painterPainter
centerCenter of the dial
radiusLength for the needle
directionDirection of the needle in degrees, counter clockwise
cgColorGroup

Reimplemented in QwtAnalogClock.

Definition at line 701 of file qwt_dial.cpp.

References direction(), QwtDialNeedle::draw(), and QwtDial::PrivateData::needle.

Referenced by drawContents().

{
    if ( d_data->needle )
    {
        direction = 360.0 - direction; // counter clockwise
        d_data->needle->draw(painter, center, radius, direction, cg);
    }
}
void QwtDial::drawScale ( QPainter *  painter,
const QPoint &  center,
int  radius,
double  origin,
double  minArc,
double  maxArc 
) const [protected, virtual]

Draw the scale

Parameters:
painterPainter
centerCenter of the dial
radiusRadius of the scale
originOrigin of the scale
minArcMinimum of the arc
maxArcMinimum of the arc
See also:
QwtAbstractScaleDraw::setAngleRange()

Definition at line 723 of file qwt_dial.cpp.

References CounterClockwise, QwtDial::PrivateData::direction, QwtAbstractScaleDraw::draw(), QwtRoundScaleDraw::moveCenter(), origin(), QwtDialScaleDraw::penWidth(), QwtDial::PrivateData::scaleDraw, QwtRoundScaleDraw::setAngleRange(), and QwtRoundScaleDraw::setRadius().

Referenced by drawContents().

{
    if ( d_data->scaleDraw == NULL )
        return;

    origin -= 270.0; // hardcoded origin of QwtScaleDraw

    double angle = maxArc - minArc;
    if ( angle > 360.0 )
        angle = ::fmod(angle, 360.0);

    minArc += origin;
    if ( minArc < -360.0 )
        minArc = ::fmod(minArc, 360.0);
    
    maxArc = minArc + angle;
    if ( maxArc > 360.0 )
    {
        // QwtAbstractScaleDraw::setAngleRange accepts only values
        // in the range [-360.0..360.0]
        minArc -= 360.0;
        maxArc -= 360.0;
    }

    if ( d_data->direction == QwtDial::CounterClockwise )
        qSwap(minArc, maxArc);
    
    painter->setFont(font());

    d_data->scaleDraw->setAngleRange(minArc, maxArc);
    d_data->scaleDraw->setRadius(radius);
    d_data->scaleDraw->moveCenter(center);

#if QT_VERSION < 0x040000
    QColorGroup cg = colorGroup();

    const QColor textColor = cg.color(QColorGroup::Text);
    cg.setColor(QColorGroup::Foreground, textColor);
    painter->setPen(QPen(textColor, d_data->scaleDraw->penWidth()));
    
    d_data->scaleDraw->draw(painter, cg);
#else
    QPalette pal = palette();

    const QColor textColor = pal.color(QPalette::Text);
    pal.setColor(QPalette::Foreground, textColor); //ticks, backbone
    
    painter->setPen(QPen(textColor, d_data->scaleDraw->penWidth()));

    d_data->scaleDraw->draw(painter, pal);
#endif
}
void QwtDial::drawScaleContents ( QPainter *  painter,
const QPoint &  center,
int  radius 
) const [protected, virtual]

Draw the contents inside the scale

Paints nothing.

Parameters:
painterPainter
centerCenter of the contents circle
radiusRadius of the contents circle

Reimplemented in QwtCompass.

Definition at line 777 of file qwt_dial.cpp.

Referenced by drawContents().

{
    // empty default implementation
}
Shadow QwtDial::frameShadow (  ) const
void QwtDial::getScrollMode ( const QPoint &  pos,
int &  scrollMode,
int &  direction 
) [protected, virtual]

See QwtAbstractSlider::getScrollMode()

Parameters:
pospoint where the mouse was pressed
Return values:
scrollModeThe scrolling mode
directiondirection: 1, 0, or -1.
See also:
QwtAbstractSlider::getScrollMode()

Implements QwtAbstractSlider.

Definition at line 1192 of file qwt_dial.cpp.

References contentsRect(), QwtDial::PrivateData::previousDir, QwtAbstractSlider::ScrMouse, and QwtAbstractSlider::ScrNone.

{
    direction = 0;
    scrollMode = ScrNone;

    const QRegion region(contentsRect(), QRegion::Ellipse);
    if ( region.contains(pos) && pos != rect().center() )
    {
        scrollMode = ScrMouse;
        d_data->previousDir = -1.0;
    }
}
double QwtDial::getValue ( const QPoint &  pos ) [protected, virtual]

Find the value for a given position

Parameters:
posPosition
Returns:
Value

Implements QwtAbstractSlider.

Definition at line 1083 of file qwt_dial.cpp.

References line2Radians(), QwtDial::PrivateData::maxScaleArc, QwtDoubleRange::maxValue(), QwtDial::PrivateData::minScaleArc, QwtDoubleRange::minValue(), mode(), QwtAbstractSlider::mouseOffset(), QwtDial::PrivateData::origin, QwtDial::PrivateData::previousDir, RotateScale, QwtAbstractSlider::ScrMouse, QwtAbstractSlider::scrollMode(), QwtAbstractSlider::setMouseOffset(), QwtDoubleRange::value(), and wrapping().

{
    if ( d_data->maxScaleArc == d_data->minScaleArc || maxValue() == minValue() )
        return minValue();

    double dir = line2Radians(rect().center(), pos) - d_data->origin;
    if ( dir < 0.0 )
        dir += 360.0;

    if ( mode() == RotateScale )
        dir = 360.0 - dir;

    // The position might be in the area that is outside the scale arc.
    // We need the range of the scale if it was a complete circle.

    const double completeCircle = 360.0 / (d_data->maxScaleArc - d_data->minScaleArc) 
        * (maxValue() - minValue());

    double posValue = minValue() + completeCircle * dir / 360.0;

    if ( scrollMode() == ScrMouse )
    {
        if ( d_data->previousDir >= 0.0 ) // valid direction
        {
            // We have to find out whether the mouse is moving
            // clock or counter clockwise

            bool clockWise = false;

            const double angle = dir - d_data->previousDir;
            if ( (angle >= 0.0 && angle <= 180.0) || angle < -180.0 )
                clockWise = true;

            if ( clockWise )
            {
                if ( dir < d_data->previousDir && mouseOffset() > 0.0 )
                {
                    // We passed 360 -> 0
                    setMouseOffset(mouseOffset() - completeCircle);
                }

                if ( wrapping() )
                {
                    if ( posValue - mouseOffset() > maxValue() )
                    {
                        // We passed maxValue and the value will be set
                        // to minValue. We have to adjust the mouseOffset.

                        setMouseOffset(posValue - minValue());
                    }
                }
                else
                {
                    if ( posValue - mouseOffset() > maxValue() ||
                        value() == maxValue() )
                    {
                        // We fix the value at maxValue by adjusting
                        // the mouse offset.

                        setMouseOffset(posValue - maxValue());
                    }
                }
            }
            else
            {
                if ( dir > d_data->previousDir && mouseOffset() < 0.0 )
                {
                    // We passed 0 -> 360 
                    setMouseOffset(mouseOffset() + completeCircle);    
                }

                if ( wrapping() )
                {
                    if ( posValue - mouseOffset() < minValue() )
                    {
                        // We passed minValue and the value will be set
                        // to maxValue. We have to adjust the mouseOffset.

                        setMouseOffset(posValue - maxValue());
                    }
                }
                else
                {
                    if ( posValue - mouseOffset() < minValue() ||
                        value() == minValue() )
                    {
                        // We fix the value at minValue by adjusting
                        // the mouse offset.

                        setMouseOffset(posValue - minValue());
                    }
                }
            }
        }
        d_data->previousDir = dir;
    }

    return posValue;
}
bool QwtDial::hasVisibleBackground (  ) const

true when the area outside of the frame is visible

See also:
showBackground(), setMask()

Definition at line 222 of file qwt_dial.cpp.

References QwtDial::PrivateData::visibleBackground.

Referenced by resizeEvent().

{ 
    return d_data->visibleBackground; 
}
void QwtDial::keyPressEvent ( QKeyEvent *  event ) [protected, virtual]

Handles key events

  • Key_Down, KeyLeft
    Decrement by 1
  • Key_Prior
    Decrement by pageSize()
  • Key_Home
    Set the value to minValue()
  • Key_Up, KeyRight
    Increment by 1
  • Key_Next
    Increment by pageSize()
  • Key_End
    Set the value to maxValue()
Parameters:
eventKey event
See also:
isReadOnly()

Reimplemented from QwtAbstractSlider.

Reimplemented in QwtCompass.

Definition at line 1225 of file qwt_dial.cpp.

References QwtAbstractSlider::incValue(), QwtAbstractSlider::isReadOnly(), QwtAbstractSlider::isValid(), mitk::Key_Down, mitk::Key_End, mitk::Key_Home, mitk::Key_Left, mitk::Key_Next, mitk::Key_PageDown, mitk::Key_PageUp, mitk::Key_Prior, mitk::Key_Right, mitk::Key_Up, QwtDoubleRange::maxValue(), QwtDoubleRange::minValue(), QwtDoubleRange::pageSize(), QwtDoubleRange::prevValue(), QwtAbstractSlider::setValue(), QwtAbstractSlider::sliderMoved(), and QwtDoubleRange::value().

{
    if ( isReadOnly() )
    {
        event->ignore();
        return;
    }

    if ( !isValid() )
        return;

    double previous = prevValue();
    switch ( event->key() )
    {
        case Qt::Key_Down:
        case Qt::Key_Left:
            QwtDoubleRange::incValue(-1);
            break;
#if QT_VERSION < 0x040000
        case Qt::Key_Prior:
#else
        case Qt::Key_PageUp:
#endif
            QwtDoubleRange::incValue(-pageSize());
            break;
        case Qt::Key_Home:
            setValue(minValue());
            break;

        case Qt::Key_Up:
        case Qt::Key_Right:
            QwtDoubleRange::incValue(1);
            break;
#if QT_VERSION < 0x040000
        case Qt::Key_Next:
#else
        case Qt::Key_PageDown:
#endif
            QwtDoubleRange::incValue(pageSize());
            break;
        case Qt::Key_End:
            setValue(maxValue());
            break;
        default:;
            event->ignore();
    }

    if (value() != previous)
        emit sliderMoved(value());
}
int QwtDial::lineWidth (  ) const
double QwtDial::maxScaleArc (  ) const
Returns:
Upper limit of the scale arc

Definition at line 971 of file qwt_dial.cpp.

References QwtDial::PrivateData::maxScaleArc.

{ 
    return d_data->maxScaleArc; 
}
QSize QwtDial::minimumSizeHint (  ) const [virtual]

Return a minimum size hint.

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

Definition at line 1048 of file qwt_dial.cpp.

References QwtRoundScaleDraw::extent(), lineWidth(), and QwtDial::PrivateData::scaleDraw.

{   
    int sh = 0;
    if ( d_data->scaleDraw )
        sh = d_data->scaleDraw->extent(QPen(), font() );

    const int d = 3 * sh + 2 * lineWidth();
    
    return QSize( d, d );
}
double QwtDial::minScaleArc (  ) const
Returns:
Lower limit of the scale arc

Definition at line 965 of file qwt_dial.cpp.

References QwtDial::PrivateData::minScaleArc.

{ 
    return d_data->minScaleArc; 
}
Mode QwtDial::mode (  ) const
QwtDialNeedle * QwtDial::needle (  )
Returns:
needle
See also:
setNeedle()

Definition at line 818 of file qwt_dial.cpp.

References QwtDial::PrivateData::needle.

{ 
    return d_data->needle; 
}
const QwtDialNeedle * QwtDial::needle (  ) const
Returns:
needle
See also:
setNeedle()

Definition at line 809 of file qwt_dial.cpp.

References QwtDial::PrivateData::needle.

Referenced by QwtAnalogClock::drawHand(), QwtAnalogClock::setHand(), and setNeedle().

{ 
    return d_data->needle; 
}
double QwtDial::origin (  ) const
void QwtDial::paintEvent ( QPaintEvent *  e ) [protected, virtual]

Paint the dial

Parameters:
ePaint event

Definition at line 446 of file qwt_dial.cpp.

References drawContents(), drawFocusIndicator(), drawFrame(), and QwtPaintBuffer::painter().

{
    const QRect &ur = e->rect();
    if ( ur.isValid() )
    {
#if QT_VERSION < 0x040000
        QwtPaintBuffer paintBuffer(this, ur);
        QPainter &painter = *paintBuffer.painter();
#else
        QPainter painter(this);
        painter.setRenderHint(QPainter::Antialiasing, true);
#endif

        painter.save();
        drawContents(&painter);
        painter.restore();

        painter.save();
        drawFrame(&painter);
        painter.restore();

        if ( hasFocus() )
            drawFocusIndicator(&painter);
    }
}
void QwtDial::rangeChange (  ) [protected, virtual]

QwtDoubleRange update hook.

Reimplemented from QwtDoubleRange.

Definition at line 824 of file qwt_dial.cpp.

References updateScale().

{
    updateScale();
}
void QwtDial::resizeEvent ( QResizeEvent *  e ) [protected, virtual]

Resize the dial widget

Parameters:
eResize event

Definition at line 434 of file qwt_dial.cpp.

References hasVisibleBackground(), and updateMask().

QRect QwtDial::scaleContentsRect (  ) const [virtual]
Returns:
rect inside the scale
See also:
setLineWidth(), boundingRect(), contentsRect()

Definition at line 312 of file qwt_dial.cpp.

References contentsRect(), QwtRoundScaleDraw::extent(), and QwtDial::PrivateData::scaleDraw.

Referenced by drawContents().

{
#if QT_VERSION < 0x040000
    const QPen scalePen(colorGroup().text(), 0, Qt::NoPen);
#else
    const QPen scalePen(palette().text(), 0, Qt::NoPen);
#endif

    int scaleDist = 0;
    if ( d_data->scaleDraw )
    {
        scaleDist = d_data->scaleDraw->extent(scalePen, font());
        scaleDist++; // margin
    }

    const QRect rect = contentsRect();
    return QRect(rect.x() + scaleDist, rect.y() + scaleDist,
        rect.width() - 2 * scaleDist, rect.height() - 2 * scaleDist);
}
QwtDialScaleDraw * QwtDial::scaleDraw (  )

Return the scale draw.

Definition at line 849 of file qwt_dial.cpp.

References QwtDial::PrivateData::scaleDraw.

Referenced by setScaleDraw().

{ 
    return d_data->scaleDraw; 
}
const QwtDialScaleDraw * QwtDial::scaleDraw (  ) const

Return the scale draw.

Definition at line 855 of file qwt_dial.cpp.

References QwtDial::PrivateData::scaleDraw.

{ 
    return d_data->scaleDraw; 
}
QwtText QwtDial::scaleLabel ( double  value ) const [protected, virtual]

Find the label for a value

Parameters:
valueValue
Returns:
label

Reimplemented in QwtAnalogClock, and QwtCompass.

Definition at line 954 of file qwt_dial.cpp.

Referenced by QwtDialScaleDraw::label().

{
#if 1
    if ( value == -0 )
        value = 0;
#endif

    return QString::number(value);
}
void QwtDial::setDirection ( Direction  direction )

Set the direction of the dial (clockwise/counterclockwise)

Direction direction

See also:
direction()

Definition at line 409 of file qwt_dial.cpp.

References direction(), and QwtDial::PrivateData::direction.

{
    if ( direction != d_data->direction )
    {
        d_data->direction = direction;
        update();
    }
}
void QwtDial::setFrameShadow ( Shadow  shadow )

Sets the frame shadow value from the frame style.

Parameters:
shadowFrame shadow
See also:
setLineWidth(), QFrame::setFrameShadow()

Definition at line 232 of file qwt_dial.cpp.

References QwtDial::PrivateData::frameShadow, and lineWidth().

{
    if ( shadow != d_data->frameShadow )
    {
        d_data->frameShadow = shadow;
        if ( lineWidth() > 0 )
            update();
    }
}
void QwtDial::setLineWidth ( int  lineWidth )

Sets the line width

Parameters:
lineWidthLine width
See also:
setFrameShadow()

Definition at line 257 of file qwt_dial.cpp.

References lineWidth(), and QwtDial::PrivateData::lineWidth.

{
    if ( lineWidth < 0 )
        lineWidth = 0;

    if ( d_data->lineWidth != lineWidth )
    {
        d_data->lineWidth = lineWidth;
        update();
    }
}
void QwtDial::setMode ( Mode  mode )

Change the mode of the meter.

Parameters:
modeNew mode

The value of the meter is indicated by the difference between north of the scale and the direction of the needle. In case of QwtDial::RotateNeedle north is pointing to the origin() and the needle is rotating, in case of QwtDial::RotateScale, the needle points to origin() and the scale is rotating.

The default mode is QwtDial::RotateNeedle.

See also:
mode(), setValue(), setOrigin()

Definition at line 347 of file qwt_dial.cpp.

References mode(), and QwtDial::PrivateData::mode.

{   
    if ( mode != d_data->mode )
    {
        d_data->mode = mode;
        update(); 
    }
}       
void QwtDial::setNeedle ( QwtDialNeedle needle ) [virtual]

Set a needle for the dial

Qwt is missing a set of good looking needles. Contributions are very welcome.

Parameters:
needleNeedle
Warning:
The needle will be deleted, when a different needle is set or in ~QwtDial()

Definition at line 793 of file qwt_dial.cpp.

References needle(), and QwtDial::PrivateData::needle.

{
    if ( needle != d_data->needle )
    {
        if ( d_data->needle )
            delete d_data->needle;

        d_data->needle = needle;
        update();
    }
}
void QwtDial::setOrigin ( double  origin ) [virtual]

Change the origin.

The origin is the angle where scale and needle is relative to.

Parameters:
originNew origin
See also:
origin()

Definition at line 984 of file qwt_dial.cpp.

References origin(), and QwtDial::PrivateData::origin.

{
    d_data->origin = origin;
    update();
}
void QwtDial::setScale ( int  maxMajIntv,
int  maxMinIntv,
double  step = 0.0 
) [virtual]

Change the intervals of the scale

See also:
QwtAbstractScaleDraw::setScale()

Definition at line 883 of file qwt_dial.cpp.

References QwtDial::PrivateData::maxMajIntv, QwtDial::PrivateData::maxMinIntv, QwtDial::PrivateData::scaleStep, QwtDoubleRange::step(), and updateScale().

{
    d_data->maxMajIntv = maxMajIntv;
    d_data->maxMinIntv = maxMinIntv;
    d_data->scaleStep = step;

    updateScale();
}
void QwtDial::setScaleArc ( double  minArc,
double  maxArc 
)

Change the arc of the scale

Parameters:
minArcLower limit
maxArcUpper limit

Definition at line 1007 of file qwt_dial.cpp.

References QwtDial::PrivateData::maxScaleArc, QwtDial::PrivateData::minScaleArc, qwtMax, and qwtMin.

{
    if ( minArc != 360.0 && minArc != -360.0 )
        minArc = fmod(minArc, 360.0);
    if ( maxArc != 360.0 && maxArc != -360.0 )
        maxArc = fmod(maxArc, 360.0);

    d_data->minScaleArc = qwtMin(minArc, maxArc);
    d_data->maxScaleArc = qwtMax(minArc, maxArc);
    if ( d_data->maxScaleArc - d_data->minScaleArc > 360.0 )
        d_data->maxScaleArc = d_data->minScaleArc + 360.0;
    
    update();
}
void QwtDial::setScaleDraw ( QwtDialScaleDraw scaleDraw ) [virtual]

Set an individual scale draw

Parameters:
scaleDrawScale draw
Warning:
The previous scale draw is deleted

Definition at line 866 of file qwt_dial.cpp.

References scaleDraw(), QwtDial::PrivateData::scaleDraw, and updateScale().

Referenced by setScaleOptions().

{
    if ( scaleDraw != d_data->scaleDraw )
    {
        if ( d_data->scaleDraw )
            delete d_data->scaleDraw;
    
        d_data->scaleDraw = scaleDraw;
        updateScale();
        update();
    }
}
void QwtDial::setScaleOptions ( int  options )

A wrapper method for accessing the scale draw.

  • options == 0
    No visible scale: setScaleDraw(NULL)
  • options & ScaleBackbone
    En/disable the backbone of the scale.
  • options & ScaleTicks
    En/disable the ticks of the scale.
  • options & ScaleLabel
    En/disable scale labels
See also:
QwtAbstractScaleDraw::enableComponent()

Definition at line 906 of file qwt_dial.cpp.

References QwtAbstractScaleDraw::Backbone, QwtAbstractScaleDraw::enableComponent(), QwtAbstractScaleDraw::Labels, ScaleBackbone, QwtDial::PrivateData::scaleDraw, ScaleLabel, ScaleTicks, setScaleDraw(), and QwtAbstractScaleDraw::Ticks.

{
    if ( options == 0 )
        setScaleDraw(NULL);

    QwtDialScaleDraw *sd = d_data->scaleDraw;
    if ( sd == NULL )
        return;

    sd->enableComponent(QwtAbstractScaleDraw::Backbone, 
        options & ScaleBackbone);

    sd->enableComponent(QwtAbstractScaleDraw::Ticks, 
        options & ScaleTicks);
    
    sd->enableComponent(QwtAbstractScaleDraw::Labels, 
        options & ScaleLabel);
}
void QwtDial::setScaleTicks ( int  minLen,
int  medLen,
int  majLen,
int  penWidth = 1 
)

Assign length and width of the ticks

Parameters:
minLenLength of the minor ticks
medLenLength of the medium ticks
majLenLength of the major ticks
penWidthWidth of the pen for all ticks
See also:
QwtAbstractScaleDraw::setTickLength(), QwtDialScaleDraw::setPenWidth()

Definition at line 935 of file qwt_dial.cpp.

References QwtScaleDiv::MajorTick, QwtScaleDiv::MediumTick, QwtScaleDiv::MinorTick, QwtDial::PrivateData::scaleDraw, QwtDialScaleDraw::setPenWidth(), and QwtAbstractScaleDraw::setTickLength().

{
    QwtDialScaleDraw *sd = d_data->scaleDraw;
    if ( sd )
    {
        sd->setTickLength(QwtScaleDiv::MinorTick, minLen);
        sd->setTickLength(QwtScaleDiv::MediumTick, medLen);
        sd->setTickLength(QwtScaleDiv::MajorTick, majLen);
        sd->setPenWidth(penWidth);
    }
}
void QwtDial::setWrapping ( bool  wrapping ) [virtual]

Sets whether it is possible to step the value from the highest value to the lowest value and vice versa to on.

Parameters:
wrappingen/disables wrapping
See also:
wrapping(), QwtDoubleRange::periodic()
Note:
The meaning of wrapping is like the wrapping property of QSpinBox, but not like it is used in QDial.

Definition at line 385 of file qwt_dial.cpp.

References QwtDoubleRange::setPeriodic().

void QwtDial::showBackground ( bool  show )

Show/Hide the area outside of the frame

Parameters:
showShow if true, hide if false
See also:
hasVisibleBackground(), setMask()
Warning:
When QwtDial is a toplevel widget the window border might disappear too.

Definition at line 208 of file qwt_dial.cpp.

References updateMask(), and QwtDial::PrivateData::visibleBackground.

{
    if ( d_data->visibleBackground != show )
    {
        d_data->visibleBackground = show;
        updateMask();
    }
}
QSize QwtDial::sizeHint (  ) const [virtual]
Returns:
Size hint

Definition at line 1032 of file qwt_dial.cpp.

References QwtRoundScaleDraw::extent(), lineWidth(), and QwtDial::PrivateData::scaleDraw.

{
    int sh = 0;
    if ( d_data->scaleDraw )
        sh = d_data->scaleDraw->extent( QPen(), font() );

    const int d = 6 * sh + 2 * lineWidth();
    
    return QSize( d, d );
}
void QwtDial::updateMask (  ) [protected, virtual]

Update the mask of the dial.

In case of "hasVisibleBackground() == false", the backgound is transparent by a mask.

See also:
showBackground(), hasVisibleBackground()

Definition at line 1284 of file qwt_dial.cpp.

References boundingRect(), and QwtDial::PrivateData::visibleBackground.

Referenced by resizeEvent(), and showBackground().

{
    if ( d_data->visibleBackground )
        clearMask();
    else
        setMask(QRegion(boundingRect(), QRegion::Ellipse));
}
void QwtDial::updateScale (  ) [protected]
void QwtDial::valueChange (  ) [protected, virtual]

QwtDoubleRange update hook.

Reimplemented from QwtAbstractSlider.

Definition at line 1023 of file qwt_dial.cpp.

bool QwtDial::wrapping (  ) const

Referenced by getValue().


Friends And Related Function Documentation

friend class QwtDialScaleDraw [friend]

Definition at line 83 of file qwt_dial.h.


Property Documentation

QwtDial::Direction QwtDial::direction [read, write]
Returns:
Direction of the dial

The default direction of a dial is QwtDial::Clockwise

See also:
setDirection()

Definition at line 81 of file qwt_dial.h.

QwtDial::Shadow QwtDial::frameShadow [read, write]
Returns:
Frame shadow /sa setFrameShadow(), lineWidth(), QFrame::frameShadow

Definition at line 77 of file qwt_dial.h.

int QwtDial::lineWidth [read, write]
Returns:
Line width of the frame
See also:
setLineWidth(), frameShadow(), lineWidth()

Definition at line 76 of file qwt_dial.h.

QwtDial::Mode QwtDial::mode [read, write]
Returns:
mode of the dial.

The value of the dial is indicated by the difference between the origin and the direction of the needle. In case of QwtDial::RotateNeedle the scale arc is fixed to the origin() and the needle is rotating, in case of QwtDial::RotateScale, the needle points to origin() and the scale is rotating.

The default mode is QwtDial::RotateNeedle.

See also:
setMode(), origin(), setScaleArc(), value()

Definition at line 78 of file qwt_dial.h.

double QwtDial::origin [read, write]

The origin is the angle where scale and needle is relative to.

Returns:
Origin of the dial
See also:
setOrigin()

Definition at line 79 of file qwt_dial.h.

bool QwtDial::visibleBackground [read, write]

Definition at line 75 of file qwt_dial.h.

bool QwtDial::wrapping [read, write]

wrapping() holds whether it is possible to step the value from the highest value to the lowest value and vice versa.

See also:
setWrapping(), QwtDoubleRange::setPeriodic()
Note:
The meaning of wrapping is like the wrapping property of QSpinBox, but not like it is used in QDial.

Definition at line 80 of file qwt_dial.h.


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