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


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 ¢er, int length, int width, double direction) |
A magnet needle for compass widgets.
A magnet needle points to two opposite directions indicating north and south.
The following colors are used:
Definition at line 125 of file qwt_dial_needle.h.
Style of the needle.
Definition at line 129 of file qwt_dial_needle.h.
{
TriangleStyle,
ThinStyle
};
| 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);
}
| void QwtCompassMagnetNeedle::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 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
| painter | Painter |
| brush | Brush |
| colorOffset | Color offset |
| center | Center, where the needle starts |
| length | Length of the needle |
| width | Width of the needle |
| direction | Direction |
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
| painter | Painter |
| palette | Palette |
| colorGroup | Color group |
| center | Center, where the needle starts |
| length | Length of the needle |
| direction | Direction |
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
| painter | Painter |
| palette | Palette |
| colorGroup | Color group |
| center | Center, where the needle starts |
| length | Length of the needle |
| direction | Direction |
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();
}
1.7.2