Newer
Older
Anton Babushkin
committed
float xcenter = rightEdge-w*ALTIMETER_VVI_WIDTH/2;
Anton Babushkin
committed
QPointF vvArrowHead(xcenter+vvArowHeadSize, vvPixHeight - vvSign *vvArowHeadSize);
painter.drawLine(vvArrowHead, vvArrowEnd);
Anton Babushkin
committed
vvArrowHead = QPointF(xcenter-vvArowHeadSize, vvPixHeight - vvSign * vvArowHeadSize);
painter.drawLine(vvArrowHead, vvArrowEnd);
}
// print secondary altitude
Anton Babushkin
committed
if (!isnan(secondaryAltitude)) {
QRectF saBox(area.x(), area.y()-secondaryAltitudeBoxHeight, w, secondaryAltitudeBoxHeight);
painter.resetTransform();
painter.translate(saBox.center());
QString s_salt;
s_salt.sprintf("%3.0f", secondaryAltitude);
drawTextCenter(painter, s_salt, mediumTextSize, 0, 0);
}
dongfang
committed
}
void PrimaryFlightDisplay::drawVelocityMeter(
QPainter& painter,
Anton Babushkin
committed
QRectF area
) {
painter.resetTransform();
fillInstrumentBackground(painter, area);
QPen pen;
pen.setWidthF(lineWidth);
float h = area.height();
float w = area.width();
float effectiveHalfHeight = h*0.45;
float tickmarkRight = w-leftEdge;
float tickmarkLeftMajor = tickmarkRight-w*TAPE_GAUGES_TICKWIDTH_MAJOR;
float tickmarkLeftMinor = tickmarkRight-w*TAPE_GAUGES_TICKWIDTH_MINOR;
float numbersRight = 0.42*w;
float markerTip = (tickmarkLeftMajor+tickmarkRight*2)/3;
// Select between air and ground speed:
float speed = (isAirplane() && !isnan(airSpeed)) ? airSpeed : groundSpeed;
Anton Babushkin
committed
float centerScaleSpeed = isnan(speed) ? 0 : speed;
float start = centerScaleSpeed - AIRSPEED_LINEAR_SPAN/2;
float end = centerScaleSpeed + AIRSPEED_LINEAR_SPAN/2;
int firstTick = ceil(start / AIRSPEED_LINEAR_RESOLUTION) * AIRSPEED_LINEAR_RESOLUTION;
int lastTick = floor(end / AIRSPEED_LINEAR_RESOLUTION) * AIRSPEED_LINEAR_RESOLUTION;
for (int tickSpeed = firstTick; tickSpeed <= lastTick; tickSpeed += AIRSPEED_LINEAR_RESOLUTION) {
pen.setColor(tickSpeed<0 ? redColor : Qt::white);
painter.setPen(pen);
float y = (tickSpeed-centerScaleSpeed)*effectiveHalfHeight/(AIRSPEED_LINEAR_SPAN/2);
bool hasText = tickSpeed % AIRSPEED_LINEAR_MAJOR_RESOLUTION == 0;
painter.resetTransform();
painter.translate(area.left(), area.center().y() - y);
if (hasText) {
QString s_speed;
drawTextRightCenter(painter, s_speed, mediumTextSize, numbersRight, 0);
} else {
painter.drawLine(tickmarkLeftMinor, 0, tickmarkRight, 0);
}
}
QPainterPath markerPath(QPoint(markerTip, 0));
markerPath.lineTo(markerTip-markerHalfHeight, markerHalfHeight);
markerPath.lineTo(leftEdge, markerHalfHeight);
markerPath.lineTo(leftEdge, -markerHalfHeight);
markerPath.lineTo(markerTip-markerHalfHeight, -markerHalfHeight);
markerPath.closeSubpath();
painter.resetTransform();
painter.translate(area.left(), area.center().y());
pen.setWidthF(lineWidth);
pen.setColor(Qt::white);
painter.setPen(pen);
painter.setBrush(Qt::SolidPattern);
painter.drawPath(markerPath);
painter.setBrush(Qt::NoBrush);
pen.setColor(Qt::white);
painter.setPen(pen);
QString s_alt;
Anton Babushkin
committed
if (isnan(speed))
s_alt.sprintf("%3.1f", speed);
drawTextCenter(painter, s_alt, mediumTextSize, xCenter, 0);
}
static const int TOP = (1<<0);
static const int BOTTOM = (1<<1);
static const int LEFT = (1<<2);
static const int RIGHT = (1<<3);
static const int TOP_HALF = (1<<4);
static const int BOTTOM_HALF = (1<<5);
static const int LEFT_HALF = (1<<6);
static const int RIGHT_HALF = (1<<7);
void applyMargin(QRectF& area, float margin, int where) {
if (margin < 0.01) return;
QRectF save(area);
qreal consumed;
if (where & LEFT) {
area.setX(save.x() + (consumed = margin));
area.setX(save.x() + (consumed = margin/2));
} else {
consumed = 0;
}
if (where & RIGHT) {
area.setWidth(save.width()-consumed-margin);
} else if (where & RIGHT_HALF) {
area.setWidth(save.width()-consumed-margin/2);
} else {
area.setWidth(save.width()-consumed);
}
if (where & TOP) {
area.setY(save.y() + (consumed = margin));
area.setY(save.y() + (consumed = margin/2));
} else {
consumed = 0;
}
if (where & BOTTOM) {
area.setHeight(save.height()-consumed-margin);
} else if (where & BOTTOM_HALF) {
area.setHeight(save.height()-consumed-margin/2);
} else {
area.setHeight(save.height()-consumed);
}
}
void setMarginsForInlineLayout(qreal margin, QRectF& panel1, QRectF& panel2, QRectF& panel3, QRectF& panel4) {
applyMargin(panel1, margin, BOTTOM|LEFT|RIGHT_HALF);
applyMargin(panel2, margin, BOTTOM|LEFT_HALF|RIGHT_HALF);
applyMargin(panel3, margin, BOTTOM|LEFT_HALF|RIGHT_HALF);
applyMargin(panel4, margin, BOTTOM|LEFT_HALF|RIGHT);
dongfang
committed
}
void setMarginsForCornerLayout(qreal margin, QRectF& panel1, QRectF& panel2, QRectF& panel3, QRectF& panel4) {
applyMargin(panel1, margin, BOTTOM|LEFT|RIGHT_HALF);
applyMargin(panel2, margin, BOTTOM|LEFT_HALF|RIGHT_HALF);
applyMargin(panel3, margin, BOTTOM|LEFT_HALF|RIGHT_HALF);
applyMargin(panel4, margin, BOTTOM|LEFT_HALF|RIGHT);
}
inline qreal tapesGaugeWidthFor(qreal containerWidth, qreal preferredAIWidth) {
qreal result = (containerWidth - preferredAIWidth) / 2.0f;
if (result < minimum) result = minimum;
return result;
}
void PrimaryFlightDisplay::doPaint() {
dongfang
committed
QPainter painter;
painter.begin(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
dongfang
committed
// The AI centers on this area.
QRectF AIMainArea;
// The AI paints on this area. It should contain the AIMainArea.
QRectF AIPaintArea;
QRectF compassArea;
QRectF altimeterArea;
QRectF velocityMeterArea;
QRectF sensorsStatsArea;
QRectF linkStatsArea;
QRectF sysStatsArea;
QRectF missionStatsArea;
dongfang
committed
painter.fillRect(rect(), Qt::black);
qreal compassHalfSpan = 180;
float compassAIIntrusion = 0;
qreal aiwidth = width()-tapeGaugeWidth*2;
if (aiheight > aiwidth) aiheight = aiwidth;
AIMainArea = QRectF(
tapeGaugeWidth,
0,
aiheight);
AIPaintArea = QRectF(
0,
0,
width(),
height());
// Tape gauges get so much width that the AI area not covered by them is perfectly square.
velocityMeterArea = QRectF (0, 0, tapeGaugeWidth, aiheight);
altimeterArea = QRectF(AIMainArea.right(), 0, tapeGaugeWidth, aiheight);
if (style == NO_OVERLAYS) {
applyMargin(AIMainArea, margin, TOP|BOTTOM);
applyMargin(altimeterArea, margin, TOP|BOTTOM|RIGHT);
applyMargin(velocityMeterArea, margin, TOP|BOTTOM|LEFT);
setMarginsForInlineLayout(margin, sensorsStatsArea, linkStatsArea, sysStatsArea, missionStatsArea);
}
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
qreal compassRelativeWidth = 0.75;
qreal compassBottomMargin = 0.78;
qreal compassSize = compassRelativeWidth * AIMainArea.width(); // Diameter is this times the width.
qreal compassCenterY;
compassCenterY = AIMainArea.bottom() + compassSize / 4;
if (height() - compassCenterY > AIMainArea.width()/2*compassBottomMargin)
compassCenterY = height()-AIMainArea.width()/2*compassBottomMargin;
// TODO: This is bad style...
compassCenterY = (compassCenterY * 2 + AIMainArea.bottom() + compassSize / 4) / 3;
compassArea = QRectF(AIMainArea.x()+(1-compassRelativeWidth)/2*AIMainArea.width(),
compassCenterY-compassSize/2,
compassSize,
compassSize);
if (height()-compassCenterY < compassSize/2) {
compassHalfSpan = acos((compassCenterY-height())*2/compassSize) * 180/M_PI + COMPASS_DISK_RESOLUTION;
if (compassHalfSpan > 180) compassHalfSpan = 180;
}
compassAIIntrusion = compassSize/2 + AIMainArea.bottom() - compassCenterY;
if (compassAIIntrusion<0) compassAIIntrusion = 0;
case COMPASS_SEPARATED: {
// A layout for containers higher than their width.
tapeGaugeWidth = tapesGaugeWidthFor(width(), width());
qreal aiheight = width() - tapeGaugeWidth*2;
qreal panelsHeight = 0;
AIMainArea = QRectF(
tapeGaugeWidth,
AIPaintArea = style == OVERLAY_HSI ?
QRectF(
0,
0,
width(),
height() - panelsHeight) : AIMainArea;
velocityMeterArea = QRectF (0, 0, tapeGaugeWidth, aiheight);
altimeterArea = QRectF(AIMainArea.right(), 0, tapeGaugeWidth, aiheight);
QPoint compassCenter = QPoint(width()/2, AIMainArea.bottom()+width()/2);
qreal compassDiam = width() * 0.8;
compassArea = QRectF(compassCenter.x()-compassDiam/2, compassCenter.y()-compassDiam/2, compassDiam, compassDiam);
dongfang
committed
painter.setClipRect(AIPaintArea);
dongfang
committed
drawAIGlobalFeatures(painter, AIMainArea, AIPaintArea);
drawAIAirframeFixedFeatures(painter, AIMainArea);
dongfang
committed
drawAICompassDisk(painter, compassArea, compassHalfSpan);
dongfang
committed
dongfang
committed
Anton Babushkin
committed
drawAltimeter(painter, altimeterArea);
dongfang
committed
Anton Babushkin
committed
drawVelocityMeter(painter, velocityMeterArea);
dongfang
committed