Public Types | Public Member Functions | Static Public Member Functions | Static Protected Member Functions

QwtCompassMagnetNeedle Class Reference

A magnet needle for compass widgets. More...

#include <qwt_dial_needle.h>

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

List of all members.

Public Types

enum  Style { TriangleStyle, ThinStyle }
 

Style of the needle.

More...

Public Member Functions

 QwtCompassMagnetNeedle (Style=TriangleStyle, const QColor &light=Qt::white, const QColor &dark=Qt::red)
 Constructor.
virtual void draw (QPainter *, const QPoint &, int length, double direction, QPalette::ColorGroup=QPalette::Active) const

Static Public Member Functions

static void drawTriangleNeedle (QPainter *, const QPalette &, QPalette::ColorGroup, const QPoint &, int length, double direction)
static void drawThinNeedle (QPainter *, const QPalette &, QPalette::ColorGroup, const QPoint &, int length, double direction)

Static Protected Member Functions

static void drawPointer (QPainter *painter, const QBrush &brush, int colorOffset, const QPoint &center, int length, int width, double direction)

Detailed Description

A magnet needle for compass widgets.

A magnet needle points to two opposite directions indicating north and south.

The following colors are used:

See also:
QwtDial, QwtCompass

Definition at line 125 of file qwt_dial_needle.h.


Member Enumeration Documentation

Style of the needle.

Enumerator:
TriangleStyle 
ThinStyle 

Definition at line 129 of file qwt_dial_needle.h.


Constructor & Destructor Documentation

QwtCompassMagnetNeedle::QwtCompassMagnetNeedle ( Style  style = TriangleStyle,
const QColor &  light = Qt::white,
const QColor &  dark = Qt::red 
)

Constructor.

Definition at line 293 of file qwt_dial_needle.cpp.

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

                                                :
    d_style(style)
{   
    QPalette palette;
    for ( int i = 0; i < QPalette::NColorGroups; i++ )
    {
        palette.setColor((QPalette::ColorGroup)i,
            QwtPalette::Light, light);
        palette.setColor((QPalette::ColorGroup)i,
            QwtPalette::Dark, dark);
        palette.setColor((QPalette::ColorGroup)i,
            QwtPalette::Base, Qt::darkGray);
    }

    setPalette(palette); 
}

Member Function Documentation

void QwtCompassMagnetNeedle::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 320 of file qwt_dial_needle.cpp.

References drawThinNeedle(), drawTriangleNeedle(), QwtDialNeedle::palette(), and ThinStyle.

{
    if ( d_style == ThinStyle )
    {
        drawThinNeedle(painter, palette(), colorGroup, 
            center, length, direction); 
    }
    else
    {
        drawTriangleNeedle(painter, palette(), colorGroup,
            center, length, direction);
    }
}
void QwtCompassMagnetNeedle::drawPointer ( QPainter *  painter,
const QBrush &  brush,
int  colorOffset,
const QPoint &  center,
int  length,
int  width,
double  direction 
) [static, protected]

Draw a compass needle

Parameters:
painterPainter
brushBrush
colorOffsetColor offset
centerCenter, where the needle starts
lengthLength of the needle
widthWidth of the needle
directionDirection

Definition at line 447 of file qwt_dial_needle.cpp.

References qwtDegree2Pos(), and qwtMax.

Referenced by drawThinNeedle().

{
    painter->save();

    const int peak = qwtMax(qRound(length / 10.0), 5);

    const int knobWidth = width + 8;
    QRect knobRect(0, 0, knobWidth, knobWidth);
    knobRect.moveCenter(center);

    QwtPolygon pa(5);

    pa.setPoint(0, qwtDegree2Pos(center, width / 2, direction + 90.0));
    pa.setPoint(1, center);
    pa.setPoint(2, qwtDegree2Pos(pa.point(1), length - peak, direction));
    pa.setPoint(3, qwtDegree2Pos(center, length, direction));
    pa.setPoint(4, qwtDegree2Pos(pa.point(0), length - peak, direction));

    painter->setPen(Qt::NoPen);

    QBrush darkBrush = brush;
    darkBrush.setColor(darkBrush.color().dark(100 + colorOffset));
    painter->setBrush(darkBrush);
    painter->drawPolygon(pa);
    painter->drawPie(knobRect, qRound(direction * 16), 90 * 16);

    pa.setPoint(0, qwtDegree2Pos(center, width / 2, direction - 90.0));
    pa.setPoint(4, qwtDegree2Pos(pa.point(0), length - peak, direction));

    QBrush lightBrush = brush;
    lightBrush.setColor(lightBrush.color().dark(100 - colorOffset));
    painter->setBrush(lightBrush);
    painter->drawPolygon(pa);
    painter->drawPie(knobRect, qRound(direction * 16), -90 * 16);

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

Draw a compass needle

Parameters:
painterPainter
palettePalette
colorGroupColor group
centerCenter, where the needle starts
lengthLength of the needle
directionDirection

Definition at line 411 of file qwt_dial_needle.cpp.

References QwtDialNeedle::drawKnob(), drawPointer(), and qwtMax.

Referenced by draw().

{
    const QBrush darkBrush = palette.brush(colorGroup, QwtPalette::Dark);
    const QBrush lightBrush = palette.brush(colorGroup, QwtPalette::Light);
    const QBrush baseBrush = palette.brush(colorGroup, QwtPalette::Base);

    const int colorOffset = 10;
    const int width = qwtMax(qRound(length / 6.0), 3);

    painter->save();

    const QPoint arrowCenter(center.x() + 1, center.y() + 1);

    drawPointer(painter, darkBrush, colorOffset, 
        arrowCenter, length, width, direction);
    drawPointer(painter, lightBrush, -colorOffset, 
        arrowCenter, length, width, direction + 180.0);
    
    drawKnob(painter, arrowCenter, width, baseBrush, true);

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

Draw a compass needle

Parameters:
painterPainter
palettePalette
colorGroupColor group
centerCenter, where the needle starts
lengthLength of the needle
directionDirection

Definition at line 345 of file qwt_dial_needle.cpp.

References qwtDegree2Pos().

Referenced by draw().

{
    const QBrush darkBrush = palette.brush(colorGroup, QwtPalette::Dark);
    const QBrush lightBrush = palette.brush(colorGroup, QwtPalette::Light);

    QBrush brush;

    const int width = qRound(length / 3.0);
    const int colorOffset =  10;

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

    const QPoint arrowCenter(center.x() + 1, center.y() + 1);

    QwtPolygon pa(3);
    pa.setPoint(0, arrowCenter);
    pa.setPoint(1, qwtDegree2Pos(arrowCenter, length, direction));

    pa.setPoint(2, qwtDegree2Pos(arrowCenter, width / 2, direction + 90.0));

    brush = darkBrush;
    brush.setColor(brush.color().dark(100 + colorOffset));
    painter->setBrush(brush);
    painter->drawPolygon(pa);

    pa.setPoint(2, qwtDegree2Pos(arrowCenter, width / 2, direction - 90.0));

    brush = darkBrush;
    brush.setColor(brush.color().dark(100 - colorOffset));
    painter->setBrush(brush);
    painter->drawPolygon(pa);

    // --

    pa.setPoint(1, qwtDegree2Pos(arrowCenter, length, direction + 180.0));

    pa.setPoint(2, qwtDegree2Pos(arrowCenter, width / 2, direction + 90.0));

    brush = lightBrush;
    brush.setColor(brush.color().dark(100 + colorOffset));
    painter->setBrush(brush);
    painter->drawPolygon(pa);

    pa.setPoint(2, qwtDegree2Pos(arrowCenter, width / 2, direction - 90.0));

    brush = lightBrush;
    brush.setColor(brush.color().dark(100 - colorOffset));
    painter->setBrush(brush);
    painter->drawPolygon(pa);

    painter->restore();
}

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