Public Types | Public Member Functions | Static Public Member Functions

QwtDialSimpleNeedle Class Reference

A needle for dial widgets. More...

#include <qwt_dial_needle.h>

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

List of all members.

Public Types

enum  Style { Arrow, Ray }
 

Style of the needle.

More...

Public Member Functions

 QwtDialSimpleNeedle (Style, bool hasKnob=true, const QColor &mid=Qt::gray, const QColor &base=Qt::darkGray)
virtual void draw (QPainter *, const QPoint &, int length, double direction, QPalette::ColorGroup=QPalette::Active) const
void setWidth (int width)
int width () const

Static Public Member Functions

static void drawArrowNeedle (QPainter *, const QPalette &, QPalette::ColorGroup, const QPoint &, int length, int width, double direction, bool hasKnob)
static void drawRayNeedle (QPainter *, const QPalette &, QPalette::ColorGroup, const QPoint &, int length, int width, double direction, bool hasKnob)

Detailed Description

A needle for dial widgets.

The following colors are used:

See also:
QwtDial, QwtCompass

Definition at line 73 of file qwt_dial_needle.h.


Member Enumeration Documentation

Style of the needle.

Enumerator:
Arrow 
Ray 

Definition at line 77 of file qwt_dial_needle.h.

    {
        Arrow,
        Ray
    };

Constructor & Destructor Documentation

QwtDialSimpleNeedle::QwtDialSimpleNeedle ( Style  style,
bool  hasKnob = true,
const QColor &  mid = Qt::gray,
const QColor &  base = Qt::darkGray 
)

Constructor

Parameters:
styleStyle
hasKnobWith/Without knob
midMiddle color
baseBase color

Definition at line 96 of file qwt_dial_needle.cpp.

References QwtDialNeedle::palette(), and QwtDialNeedle::setPalette().

                                              :
    d_style(style),
    d_hasKnob(hasKnob),
    d_width(-1)
{
    QPalette palette;
    for ( int i = 0; i < QPalette::NColorGroups; i++ )
    {
        palette.setColor((QPalette::ColorGroup)i,
            QwtPalette::Mid, mid);
        palette.setColor((QPalette::ColorGroup)i,
            QwtPalette::Base, base);
    }

    setPalette(palette);
}

Member Function Documentation

void QwtDialSimpleNeedle::draw ( QPainter *  painter,
const QPoint &  center,
int  length,
double  direction,
QPalette::ColorGroup  colorGroup = QPalette::Active 
) const [virtual]

Draw the needle

Parameters:
painterPainter
centerCenter of the dial, start position for the needle
lengthLength of the needle
directionDirection of the needle, in degrees counter clockwise
colorGroupColor group, used for painting

Implements QwtDialNeedle.

Definition at line 142 of file qwt_dial_needle.cpp.

References Arrow, drawArrowNeedle(), drawRayNeedle(), and QwtDialNeedle::palette().

{
    if ( d_style == Arrow )
    {
        drawArrowNeedle(painter, palette(), colorGroup,
            center, length, d_width, direction, d_hasKnob);
    }
    else
    {
        drawRayNeedle(painter, palette(), colorGroup, 
            center, length, d_width, direction, d_hasKnob); 
    }
}
void QwtDialSimpleNeedle::drawArrowNeedle ( QPainter *  painter,
const QPalette &  palette,
QPalette::ColorGroup  colorGroup,
const QPoint &  center,
int  length,
int  width,
double  direction,
bool  hasKnob 
) [static]

Draw a needle looking like an arrow

Parameters:
painterPainter
palettePalette
colorGroupColor group
centercenter of the needle
lengthLength of the needle
widthWidth of the needle
directionCurrent Direction
hasKnobWith/Without knob

Definition at line 230 of file qwt_dial_needle.cpp.

References QwtDialNeedle::drawKnob(), int(), M_PI, M_PI_2, qwtMax, and qwtPolar2Pos().

Referenced by draw().

{
    direction *= M_PI / 180.0;

    painter->save();

    if ( width <= 0 )
    {
        width = (int)qwtMax(length * 0.06, 9.0);
        if ( width % 2 == 0 )
            width++;
    }

    const int peak = 3;
    const QPoint p1(center.x() + 1, center.y() + 1);
    const QPoint p2 = qwtPolar2Pos(p1, length - peak, direction);
    const QPoint p3 = qwtPolar2Pos(p1, length, direction);

    QwtPolygon pa(5);
    pa.setPoint(0, qwtPolar2Pos(p1, width / 2, direction - M_PI_2));
    pa.setPoint(1, qwtPolar2Pos(p2, 1, direction - M_PI_2));
    pa.setPoint(2, p3);
    pa.setPoint(3, qwtPolar2Pos(p2, 1, direction + M_PI_2));
    pa.setPoint(4, qwtPolar2Pos(p1, width / 2, direction + M_PI_2));

    painter->setPen(Qt::NoPen);
    painter->setBrush(palette.brush(colorGroup, QwtPalette::Mid));
    painter->drawPolygon(pa);

    QwtPolygon shadowPa(3);

    const int colorOffset = 10;

    int i;
    for ( i = 0; i < 3; i++ )
        shadowPa.setPoint(i, pa[i]);

    const QColor midColor = palette.color(colorGroup, QwtPalette::Mid);

    painter->setPen(midColor.dark(100 + colorOffset));
    painter->drawPolyline(shadowPa);

    for ( i = 0; i < 3; i++ )
        shadowPa.setPoint(i, pa[i + 2]);

    painter->setPen(midColor.dark(100 - colorOffset));
    painter->drawPolyline(shadowPa);

    if ( hasKnob )
    {
        drawKnob(painter, center, qRound(width * 1.3), 
            palette.brush(colorGroup, QwtPalette::Base),
            false);
    }

    painter->restore();
}
void QwtDialSimpleNeedle::drawRayNeedle ( QPainter *  painter,
const QPalette &  palette,
QPalette::ColorGroup  colorGroup,
const QPoint &  center,
int  length,
int  width,
double  direction,
bool  hasKnob 
) [static]

Draw a needle looking like a ray

Parameters:
painterPainter
palettePalette
colorGroupColor group
centercenter of the needle
lengthLength of the needle
widthWidth of the needle
directionCurrent Direction
hasKnobWith/Without knob

Definition at line 169 of file qwt_dial_needle.cpp.

References QwtDialNeedle::drawKnob(), M_PI, M_PI_2, qwtMax, and qwtPolar2Pos().

Referenced by draw().

{
    if ( width <= 0 )
        width = 5;

    direction *= M_PI / 180.0;

    painter->save();

    const QPoint p1(center.x() + 1, center.y() + 2);
    const QPoint p2 = qwtPolar2Pos(p1, length, direction);

    if ( width == 1 )
    {
        const QColor midColor =
            palette.color(colorGroup, QwtPalette::Mid);

        painter->setPen(QPen(midColor, 1));
        painter->drawLine(p1, p2);
    }
    else
    {
        QwtPolygon pa(4);
        pa.setPoint(0, qwtPolar2Pos(p1, width / 2, direction + M_PI_2));
        pa.setPoint(1, qwtPolar2Pos(p2, width / 2, direction + M_PI_2));
        pa.setPoint(2, qwtPolar2Pos(p2, width / 2, direction - M_PI_2));
        pa.setPoint(3, qwtPolar2Pos(p1, width / 2, direction - M_PI_2));

        painter->setPen(Qt::NoPen);
        painter->setBrush(palette.brush(colorGroup, QwtPalette::Mid));
        painter->drawPolygon(pa);
    }
    if ( hasKnob )
    {
        int knobWidth = qwtMax(qRound(width * 0.7), 5);
        if ( knobWidth % 2 == 0 )
            knobWidth++;

        drawKnob(painter, center, knobWidth, 
            palette.brush(colorGroup, QwtPalette::Base), 
            false);
    }

    painter->restore();
}
void QwtDialSimpleNeedle::setWidth ( int  width )

Set the width of the needle

Parameters:
widthWidth
See also:
width()

Definition at line 119 of file qwt_dial_needle.cpp.

References width().

{
    d_width = width;
}
int QwtDialSimpleNeedle::width (  ) const
Returns:
the width of the needle
See also:
setWidth()

Definition at line 128 of file qwt_dial_needle.cpp.

Referenced by setWidth().

{
    return d_width;
}

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