4
#include <qwt_polygon.h>
5
#include "attitude_indicator.h"
7
AttitudeIndicatorNeedle::AttitudeIndicatorNeedle(const QColor &c)
10
for ( int i = 0; i < QPalette::NColorGroups; i++ )
12
#if QT_VERSION < 0x040000
13
palette.setColor((QPalette::ColorGroup)i,
14
QColorGroup::Text, c);
16
palette.setColor((QPalette::ColorGroup)i,
23
void AttitudeIndicatorNeedle::draw(QPainter *painter, const QPoint ¢er,
24
int length, double direction, QPalette::ColorGroup cg) const
26
direction *= M_PI / 180.0;
27
int triangleSize = qRound(length * 0.1);
31
const QPoint p0(QPoint(center.x() + 1, center.y() + 1));
33
const QPoint p1 = qwtPolar2Pos(p0,
34
length - 2 * triangleSize - 2, direction);
37
pa.setPoint(0, qwtPolar2Pos(p1, 2 * triangleSize, direction));
38
pa.setPoint(1, qwtPolar2Pos(p1, triangleSize, direction + M_PI_2));
39
pa.setPoint(2, qwtPolar2Pos(p1, triangleSize, direction - M_PI_2));
42
#if QT_VERSION < 0x040000
43
palette().color(cg, QColorGroup::Text);
45
palette().color(cg, QPalette::Text);
47
painter->setBrush(color);
48
painter->drawPolygon(pa);
50
painter->setPen(QPen(color, 3));
51
painter->drawLine(qwtPolar2Pos(p0, length - 2, direction + M_PI_2),
52
qwtPolar2Pos(p0, length - 2, direction - M_PI_2));
57
AttitudeIndicator::AttitudeIndicator(
66
setScaleOptions(ScaleTicks);
70
#if QT_VERSION < 0x040000
73
palette().color(QPalette::Text);
76
setNeedle(new AttitudeIndicatorNeedle(color));
79
void AttitudeIndicator::setGradient(double gradient)
81
if ( gradient < -1.0 )
83
else if ( gradient > 1.0 )
86
if ( d_gradient != gradient )
88
d_gradient = gradient;
93
void AttitudeIndicator::drawScale(QPainter *painter, const QPoint ¢er,
94
int radius, double origin, double minArc, double maxArc) const
96
double dir = (360.0 - origin) * M_PI / 180.0; // counter clockwise, radian
100
const QPoint p0 = qwtPolar2Pos(center, offset, dir + M_PI);
102
const int w = contentsRect().width();
105
pa.setPoint(0, qwtPolar2Pos(p0, w, dir - M_PI_2));
106
pa.setPoint(1, qwtPolar2Pos(pa.point(0), 2 * w, dir + M_PI_2));
107
pa.setPoint(2, qwtPolar2Pos(pa.point(1), w, dir));
108
pa.setPoint(3, qwtPolar2Pos(pa.point(2), 2 * w, dir - M_PI_2));
111
painter->setClipRegion(pa); // swallow 180 - 360 degrees
113
QwtDial::drawScale(painter, center, radius, origin,
119
void AttitudeIndicator::drawScaleContents(QPainter *painter,
120
const QPoint &, int) const
122
int dir = 360 - qRound(origin() - value()); // counter clockwise
123
int arc = 90 + qRound(gradient() * 90);
125
const QColor skyColor(38, 151, 221);
128
painter->setBrush(skyColor);
129
painter->drawChord(scaleContentsRect(),
130
(dir - arc) * 16, 2 * arc * 16 );
134
void AttitudeIndicator::keyPressEvent(QKeyEvent *e)
139
setGradient(gradient() + 0.05);
143
setGradient(gradient() - 0.05);
147
QwtDial::keyPressEvent(e);