void AirspeedIndicator::paintArc(QPainter *painter,QColor color, double start, double end) {
    painter->save();
    QPen pen(color);
    pen.setWidth(4);
    painter->setPen(pen);
    painter->setBrush(color);

    double startInUnits = Units::convertSpeed(VELOCITY_MS, units, start);
    double endInUnits = Units::convertSpeed(VELOCITY_MS, units, end);
    double startAngle = -(value2Angle(startInUnits) - 90)*16.0;
    double endAngle = -(value2Angle(endInUnits) - 90)*16.0;
    painter->drawArc(-98,-98,196, 196, startAngle, endAngle - startAngle);
    painter->restore();
}
void EngineBattery::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){

    painter->save();
    //paint the background
    painter->drawPixmap(QPoint(0,0), *bottomPixmap);
    painter->setRenderHint(QPainter::Antialiasing);
    painter->setRenderHint(QPainter::SmoothPixmapTransform);

    //paint the needle
    int dimension;
    dimension=qMin(this->width(), this -> height());

    painter->save();
    QPen pen;
    QBrush brush;

    pen.setColor(QColor(0xc0,0x45,0x28)); //orange color
    pen.setWidth(5+dimension/153); //pen width increase when dimension increase

    painter->setClipping(true); //draw only in this area, the bottom of the needle is hidden
    painter->setClipRect(0,0,dimension,dimension*89/153);

    painter->setPen(pen);
    painter->setBrush(brush);
    painter->translate(dimension/2,dimension*3/4);
    painter->rotate(value2Angle(amperageValue));
    painter->drawLine(0,-1*dimension*1/2,0,0);

    painter->restore();

    PanelItem::paint(painter, option, widget);

}
void AirspeedIndicator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    setupPainter(painter);

    QPen pen = QPen(Qt::red);
    int side = qMin(width(), height());
//    painter->setRenderHint(QPainter::Antialiasing);
    painter->save();
    painter->scale(side / 200.0, side / 200.0);
    painter->translate(100, 100);

    // VNE line
    painter->setBrush(Qt::red);
    painter->setPen(pen);
    painter->save();
    double vneUnits = Units::convertSpeed(VELOCITY_MS, units, vne);
    painter->rotate(value2Angle(vneUnits));
    painter->drawRect(-3, -100, 6, 20);
    painter->restore();

    // Arcs
    paintArc(painter, Qt::green, vs, vno);
    paintArc(painter, Qt::yellow, vno, vne);

    painter->save();
    painter->scale(0.95, 0.95);
    paintArc(painter, Qt::white, vso, vfe);
    painter->restore();

    // Yellow triangle
    painter->setBrush(Qt::yellow);
    painter->setPen(Qt::yellow);
    painter->save();
    double vsUnits = Units::convertSpeed(VELOCITY_MS, units, vs);
    painter->rotate(value2Angle(vsUnits));
    QPolygon p;
    p << QPoint(-5, -83) << QPoint(5, -83) << QPoint(0,-90);
    painter->drawPolygon(p);
    painter->restore();


    painter->restore();
    NeedleInstrument::paint(painter, option, widget);
}
示例#4
0
void NeedleInstrument::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
    setupPainter(painter);

    painter->drawPixmap(0,0, bottomPixmap);
    int side = qMin(width(), height());

    // Paint needle
    painter->save();
    painter->translate(side/2,side/2);
    float needleValue = qMax(qMin(_value, _maxValue), _zeroValue);
    painter->rotate(value2Angle(needleValue));
    painter->scale(side/2,side/2);
    needle->paint(painter);
    painter->restore();
    // END paint needle

    PanelItem::paint(painter, option, widget);

    painter->drawPixmap(0,0, topPixmap);
}
示例#5
0
void NeedleInstrument::repaintPixmaps() {

    // Paint bottom pixmap
    bottomPixmap = QPixmap(width(),height());
    bottomPixmap.fill(Qt::transparent);

    QPainter painter(&bottomPixmap);
    setupPainter(&painter);

    QFont numberFont = defaultFont;
    numberFont.setPointSizeF(defaultFont.pointSizeF() * 1.5);
    painter.setFont(numberFont);

    int side = qMin(width(), height());

    painter.save();
    painter.scale(side / 200.0, side / 200.0);
    painter.save();

    painter.translate(100, 100);
    painter.setPen(Qt::NoPen);
    painter.setBrush(Qt::white);

    painter.setPen(Qt::white);
    if(!_label.isEmpty()) {
        int textwidth = painter.fontMetrics().width(_label);
        painter.drawText(-textwidth/2,-70, textwidth, 200, Qt::AlignCenter, _label);
    }
    if(_thickBars != 0) {
        for (float i = _zeroValue ; i <= _maxValue; i+=_thickBars) {
            painter.save();
            painter.rotate(value2Angle(i));
            painter.drawRect(-1, -100, 2, 14);
            painter.restore();
        }
    }
    if(_thinBars != 0) {
        for (float i = _zeroValue ; i <= _maxValue; i+=_thinBars) {
            painter.save();
            painter.rotate(value2Angle(i));
            painter.drawRect(-0.3, -100, 0.6, 8);
            painter.restore();
        }
    }
    painter.setPen(QColor(200,200,200));
    if(_numbers != 0) {
        for (float i = _zeroValue ; i <= _maxValue; i+=_numbers) {
            painter.save();
            painter.rotate(value2Angle(i));
            painter.save();
            QString lineNumber = QString::number(i * _numberScale);
            painter.translate(0,-70);
            painter.rotate(-value2Angle(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();

    paintTopPixmap();

    update();
}
示例#6
0
void HSI::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
    static const QPoint needle[3] = {
        QPoint(0, -90),
        QPoint(-5, -103),
        QPoint(5, -103)
    };
    
    static const QPoint Plane[] = {
        QPoint(0, 70),
        QPoint(5, 60),
        QPoint(5, 30),
        QPoint(60,-10),
        QPoint(60,-20),
        QPoint(5,-10),
        QPoint(5,-30),
        QPoint(4,-40),
        QPoint(25,-55),
        QPoint(25,-65),
        QPoint(2,-60),
        QPoint(0,-65), 
        
        QPoint(-2,-60),
        QPoint(-25,-65),
        QPoint(-25,-55),
        QPoint(-4,-40),
        QPoint(-5,-30),
        QPoint(-5,-10),
        QPoint(-60,-20),
        QPoint(-60,-10),
        QPoint(-5, 30),
        QPoint(-5, 60),
        
    }; 
    
    static const QPoint arrowHead[] = {
        QPoint(-4, -52),
        QPoint(4, -52),
        QPoint(0, -59)
    };
    static const QPoint triangle[] = {
        QPoint(0, -33),
        QPoint(5, -23),
        QPoint(-5, -23)
    };
    
    
    const int centreY = 9;          // In a 200x200 grid centred on zero 
    const int centreX = 0;
    
    
    QColor needleColor(255, 255, 255);
    
    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->save();
    //painter->scale(0.91,0.91);
    
    painter->save();
    
    // Draw compass card at heading angle:
    painter->save();
    painter->translate(0, centreY);
    painter->rotate(- _heading);
    painter->drawPixmap(-67, -67, 134, 134, _card);
    painter->restore();
    
    painter->setPen(Qt::NoPen);
    
   
    QPen planePen(QColor(255,209,0)); // Nice orangy yellow
    planePen.setWidth(2);
    painter->setPen(planePen);
    painter->setBrush(QColor(255,209,0));
    
    // Draw dots, etc on rotating centre of compass card:
    painter->save();
        painter->translate(0, centreY);
        painter->rotate(value2Angle(_course-_heading));
        painter->drawLine(0,66, 0,36);
        painter->drawLine(0,-36, 0,-52);
        painter->drawConvexPolygon(arrowHead, 3);

        planePen.setColor(QColor(200,200,200));
        painter->setBrush(QColor(200,200,200));
        planePen.setWidthF(1.5);
        painter->setPen(Qt::white);
        
        float radius=1.5;
        float deflection =_hdots;
        if (deflection>2.5) deflection=2.5;
        if (deflection<-2.5) deflection=-2.5;
    
        for(int i=-5;i<=5;i++){
            painter->drawLine(QPointF(7*i,-5), QPointF(7*i,5));
            painter->drawChord(QRectF(7*i-radius, -radius, 2.*radius, 2.0*radius), 0, 360*16);
               
        }
        planePen.setColor(QColor(255,209,0)); // Nice orangy yellow
        planePen.setWidth(2);
        painter->setPen(planePen);
        painter->drawLine(QPointF(deflection*7*2., -33), QPointF(deflection*7*2., 33));
        
        painter->setPen(Qt::white);
        painter->setBrush(Qt::white);
        painter->drawConvexPolygon(triangle, 3);
    
    painter->restore();

    // Draw bug rotating centre of compass card:
    planePen.setColor(QColor(255,132,16)); // Orange for bug
    planePen.setWidth(1);
    painter->setPen(planePen);
    painter->save();
        painter->translate(0, centreY);
        painter->rotate(value2Angle(_bug-_heading));
    
        painter->drawLine(-6,-67,  6,-67);
        painter->drawLine(-6,-67, -6,-63);
        painter->drawLine( 6,-67,  6,-63);
        painter->drawLine( 6,-63,  4,-63);
        painter->drawLine(-6,-64, -4,-63);
        painter->drawLine(-4,-63, 0,-59);
        painter->drawLine( 4,-63, 0,-59);
    
    painter->restore();

    
    // Orange plane in centre of dial:
    planePen.setColor(QColor(255,150,0)); // Orange for bug
    planePen.setWidthF(2.);
    painter->setPen(planePen);
    
    painter->drawLine(-13, centreY-3, 13, centreY-3);
    painter->drawLine( 0, centreY-10, 0, centreY+20);
    painter->drawLine(-3, centreY+17, 3, centreY+17);
    
    
    painter->setPen(Qt::white);
  //painter->drawText(-40,-30, 100, 20, Qt::AlignRight | Qt::AlignVCenter, "hdg "+ QString::number(_heading));
  //painter->drawText(-40,-15, 100, 20, Qt::AlignRight | Qt::AlignVCenter, "crs "+ QString::number(_course));
  //painter->drawText(-40,0, 100, 20, Qt::AlignRight | Qt::AlignVCenter, "bug "+QString::number(_bug));
  //painter->drawText(-40,15, 100, 20, Qt::AlignRight | Qt::AlignVCenter, "hdt "+QString::number(_hdots));
  //    painter->drawText(-40,30, 100, 20, Qt::AlignRight | Qt::AlignVCenter, "gs "+QString::number(_glideslopeFlag));
    
    
    painter->restore();
    painter->setBrush(Qt::white);
    
    painter->restore();
    painter->drawPixmap(-100,-100,200,200, _bezel);
    
    painter->restore();
    
    painter->restore();

    PanelItem::paint(painter, option, widget);
}
示例#7
0
void HSI::createCard(void){
    QImage _cardImage = QImage(QSize(600,600), QImage::Format_ARGB32);
    _cardImage.fill(0x00ff0000);
    //_cardImage.moveTo(10,10);
    
    uint midx, midy, width, height;
    width = _cardImage.width();
    midx = width/2;
    height = _cardImage.height();
    midy = height/2;
    
    
    QPainter p;
    p.setRenderHint(QPainter::Antialiasing, true);
    p.begin(&_cardImage);
    
    p.translate(midx, midy);
    p.setPen(Qt::black);
    
    p.setBrush(Qt::black);
    p.drawChord(-midx,-midy,width,height,0,360*16);
    
    
    p.setPen(Qt::white);
    p.setBrush(Qt::white);
    if(_thickBars > 0) {
        for (float i = 0 ; i <= 360; i+=_thickBars) {
            p.save();
            p.rotate(value2Angle(i));
            p.drawRect(-2.5, -300, 5.0, 30);
            p.restore();
        }
    }
    if(_thinBars > 0) {
        for (float i = 0 ; i <= 360; i+=_thinBars) {
            p.save();
            p.rotate(value2Angle(i));
            p.drawRect(-1.0, -300, 2.0, 20);
            p.restore();
        }
    }
    p.setPen(QColor(200,200,200));
    p.setFont(QFont(QString("Helvetica"), 48, QFont::Bold, false));
    
    if(1) {
        for (float i = 0 ; i < 360; i+=_numbers) {
            p.save();
            p.rotate(value2Angle(i));
            p.save();
            QString lineNumber;
            switch (int(i)) {
                case 0:
                    lineNumber = QString("N");
                    break;
                case 90:
                    lineNumber = QString("E");
                    break;
                case 180:
                    lineNumber = QString("S");
                    break;
                case 270:
                    lineNumber = QString("W");
                    break;
                default:
                    lineNumber = QString::number(i/10);
                    break;
            }
            p.translate(0,-234);
            int width = p.fontMetrics().width(lineNumber);
            int height = p.fontMetrics().height();
            p.drawText(-width/2,-height/2,width,height, Qt::AlignCenter,  lineNumber);
            p.restore();
            p.restore();
        }
    }
    
    
    
    p.end();    
    _card = QPixmap::fromImage(_cardImage, Qt::AutoColor);
    
}