A needle for dial widgets. More...
#include <qwt_dial_needle.h>


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) |
A needle for dial widgets.
The following colors are used:
Definition at line 73 of file qwt_dial_needle.h.
Style of the needle.
Definition at line 77 of file qwt_dial_needle.h.
| QwtDialSimpleNeedle::QwtDialSimpleNeedle | ( | Style | style, |
| bool | hasKnob = true, |
||
| const QColor & | mid = Qt::gray, |
||
| const QColor & | base = Qt::darkGray |
||
| ) |
Constructor
| style | Style |
| hasKnob | With/Without knob |
| mid | Middle color |
| base | Base 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);
}
| void QwtDialSimpleNeedle::draw | ( | QPainter * | painter, |
| const QPoint & | center, | ||
| int | length, | ||
| double | direction, | ||
| QPalette::ColorGroup | colorGroup = QPalette::Active |
||
| ) | const [virtual] |
Draw the needle
| painter | Painter |
| center | Center of the dial, start position for the needle |
| length | Length of the needle |
| direction | Direction of the needle, in degrees counter clockwise |
| colorGroup | Color 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
| painter | Painter |
| palette | Palette |
| colorGroup | Color group |
| center | center of the needle |
| length | Length of the needle |
| width | Width of the needle |
| direction | Current Direction |
| hasKnob | With/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
| painter | Painter |
| palette | Palette |
| colorGroup | Color group |
| center | center of the needle |
| length | Length of the needle |
| width | Width of the needle |
| direction | Current Direction |
| hasKnob | With/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
| width | Width |
Definition at line 119 of file qwt_dial_needle.cpp.
References width().
{
d_width = width;
}
| int QwtDialSimpleNeedle::width | ( | ) | const |
Definition at line 128 of file qwt_dial_needle.cpp.
Referenced by setWidth().
{
return d_width;
}
1.7.2