void Altimeter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { setupPainter(painter); painter->drawPixmap(0,0, bottomPixmap); double side = qMin(width(), height()); painter->save(); painter->setBrush(Qt::white); painter->setPen(Qt::white); // Pressure text QFont pressureFont = defaultFont; pressureFont.setPointSizeF(defaultFont.pointSizeF() * side/300.f); painter->setFont(pressureFont); QString pressureText = QString::number(_baroPressure); painter->drawText(pressureWindow, Qt::AlignRight | Qt::AlignVCenter, pressureText); painter->restore(); // Draw needles painter->save(); painter->translate(side/2,side/2); painter->scale(side/2,side/2); painter->save(); painter->rotate(value2Angle2(_value)); shortNeedle->paint(painter); painter->restore(); painter->save(); painter->rotate(value2Angle1(_value)); longNeedle->paint(painter); painter->restore(); painter->restore(); PanelItem::paint(painter, option, widget); }
void Altimeter::repaintPixmap() { // Paint bottom pixmap bottomPixmap = QPixmap(width(),height()); bottomPixmap.fill(Qt::transparent); QPainter painter(&bottomPixmap); painter.setFont(defaultFont); double side = qMin(width(), height()); pressureWindow = QRect(side * 0.7, side * 0.45, side*0.2, side*0.1); painter.setRenderHint(QPainter::Antialiasing); // Pressure window painter.setPen(Qt::white); painter.setBrush(Qt::black); painter.drawRect(pressureWindow); painter.save(); painter.scale(side / 200.0, side / 200.0); painter.save(); painter.translate(100, 100); if(!_label.isEmpty()) { int textwidth = painter.fontMetrics().width(_label); painter.drawText(-textwidth/2,-70, textwidth, 200, Qt::AlignCenter, _label); } int textwidth = painter.fontMetrics().width("Altitude"); painter.drawText(-textwidth/2,-130, textwidth, 200, Qt::AlignCenter, "Altitude"); painter.setFont(defaultFont); painter.setBrush(Qt::white); if(_thickBars > 0) { for (float i = 0 ; i <= _range1; i+=_thickBars) { painter.save(); painter.rotate(value2Angle1(i)); painter.drawRect(-1, -100, 2, 14); painter.restore(); } } if(_thinBars > 0) { for (float i = 0 ; i <= _range2; i+=_thinBars) { painter.save(); painter.rotate(value2Angle1(i)); painter.drawRect(-0.3, -100, 0.6, 8); painter.restore(); } } painter.setPen(QColor(200,200,200)); if(_numbers != 0) { for (float i = 0 ; i < _range1; i+=_numbers) { painter.save(); painter.rotate(value2Angle1(i)); painter.save(); QString lineNumber = QString::number(i*_numbersScale); painter.translate(0,-70); painter.rotate(-value2Angle1(i)); int width = painter.fontMetrics().width(lineNumber); int height =painter.fontMetrics().height(); painter.drawText(-width/2,-height/2,width,height, Qt::AlignCenter, lineNumber); painter.restore(); painter.restore(); } } painter.restore(); painter.restore(); update(); }
void Altimeter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { static const QPoint needle[3] = { QPoint(4, 8), QPoint(-4, 8), QPoint(0, -95) }; static const QPoint needle2[3] = { QPoint(8, 8), QPoint(-8, 8), QPoint(0, -70) }; QColor needleColor(255, 255, 255); QColor needleColor2(200, 200, 200); int side = qMin(width(), height()); painter->setRenderHint(QPainter::Antialiasing); painter->save(); painter->scale(side / 200.0, side / 200.0); painter->save(); painter->translate(100, 100); painter->setBrush(Qt::black); painter->drawChord(-100,-100,200,200,0,360*16); painter->save(); painter->scale(0.90, 0.90); // Scale to draw within bezel painter->setPen(Qt::white); if(!_label.isEmpty()) { int textwidth = painter->fontMetrics().width(_label); painter->drawText(-textwidth/2,-70, textwidth, 200, Qt::AlignCenter, _label); } int textwidth = painter->fontMetrics().width("Altitude"); painter->drawText(-textwidth/2,-130, textwidth, 200, Qt::AlignCenter, "Altitude"); painter->setBrush(Qt::black); painter->drawRect(30,-10,60,20); QString pressureText = QString::number(_baroPressure); textwidth = painter->fontMetrics().width(pressureText); painter->drawText(30,-10, 60, 20, Qt::AlignRight | Qt::AlignVCenter, pressureText); painter->setBrush(Qt::white); if(_thickBars > 0) { for (float i = 0 ; i <= _range1; i+=_thickBars) { painter->save(); painter->rotate(value2Angle1(i)); painter->drawRect(-1, -100, 2, 14); painter->restore(); } } if(_thinBars > 0) { for (float i = 0 ; i <= _range2; i+=_thinBars) { painter->save(); painter->rotate(value2Angle1(i)); painter->drawRect(-0.3, -100, 0.6, 8); painter->restore(); } } painter->setPen(QColor(200,200,200)); if(_numbers != 0) { for (float i = 0 ; i < _range1; i+=_numbers) { painter->save(); painter->rotate(value2Angle1(i)); painter->save(); QString lineNumber = QString::number(i*_numbersScale); painter->translate(0,-73); painter->rotate(-value2Angle1(i)); painter->setPen(QColor(200,200,200)); painter->setFont(QFont(QString("Helvetica"), 16, QFont::Bold, false)); int width = painter->fontMetrics().width(lineNumber); int height =painter->fontMetrics().height(); painter->drawText(-width/2,-height/2,width,height, Qt::AlignCenter, lineNumber); painter->restore(); painter->restore(); } } painter->setPen(Qt::NoPen); painter->setBrush(needleColor2); painter->save(); painter->rotate(value2Angle2(_value)); painter->drawConvexPolygon(needle2, 3); painter->restore(); painter->setBrush(needleColor); painter->save(); painter->rotate(value2Angle1(_value)); painter->drawConvexPolygon(needle, 3); painter->restore(); painter->setBrush(Qt::white); painter->restore(); painter->drawPixmap(-100,-100,200,200,_bezel); painter->restore(); painter->restore(); PanelItem::paint(painter, option, widget); }