Ejemplo n.º 1
0
void DrawingPolylineItem::render(QPainter* painter, const DrawingStyleOptions& styleOptions)
{
	DrawingItemPoint* point0 = point(0);
	DrawingItemPoint* point1 = point(numberOfPoints() - 1);
	QList<DrawingItemPoint*> lPoints = points();
	QPolygonF polygon;
	DrawingItemPoint* otherPoint;
	qreal theta;

	// Polyline
	for(auto pointIter = lPoints.begin(); pointIter != lPoints.end(); pointIter++)
		polygon.append((*pointIter)->pos());

	setupPainter(painter, styleOptions, pen());
	painter->drawPolyline(polygon);

	// Arrows
	if (pen().style() != Qt::NoPen)
	{
		QPen arrowPen = pen();
		arrowPen.setStyle(Qt::SolidLine);
		setupPainter(painter, styleOptions, arrowPen, styleOptions.outputBrush(DrawingStyleOptions::Background));

		otherPoint = point(1);
		if (otherPoint)
		{
			theta = qAtan2(otherPoint->y() - point0->y(),
				otherPoint->x() - point0->x()) * 180.0 / 3.1414592654;

			if (Drawing::magnitude(otherPoint->pos() - point0->pos()) > startArrowSize())
				startArrow().render(painter, point0->pos(), theta);
		}

		otherPoint = point(numberOfPoints() - 2);
		if (otherPoint)
		{
			theta = qAtan2(otherPoint->y() - point1->y(),
				otherPoint->x() - point1->x()) * 180.0 / 3.1414592654;

			if (Drawing::magnitude(otherPoint->pos() - point1->pos()) > endArrowSize())
				endArrow().render(painter, point1->pos(), theta);
		}
	}

#ifdef DEBUG_DRAW_ITEM_SHAPE
	painter->setBrush(Qt::magenta);
	painter->setPen(QPen(Qt::magenta, 1));
	painter->drawPath(shape());
#endif
}
Ejemplo n.º 2
0
void Overlay::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * /*widget*/)
{
	QRectF rect = (option->type == QStyleOption::SO_GraphicsItem) ? boundingRect() : option->exposedRect;

	setupPainter(painter);

	painter->fillRect(rect, painter->brush());

	if (option->type == QStyleOption::SO_GraphicsItem)
	{
		drawSelection(painter, rect);
		painter->setPen(QColor(225,224,224));
		painter->drawText(rect, tr("Overlay"));
	}

	adjustRect(rect);

	if (frame()&DrawLeft)
		painter->drawLine(rect.left(), rect.top(), rect.left(), rect.bottom());

	if (frame()&DrawRight)
		painter->drawLine(rect.right(), rect.top(), rect.right(), rect.bottom());

	if (frame()&DrawTop)
		painter->drawLine(rect.left(), rect.top(), rect.right(), rect.top());

	if (frame()&DrawBottom)
		painter->drawLine(rect.left(), rect.bottom(), rect.right(), rect.bottom());
}
Ejemplo n.º 3
0
void AttitudeIndicator::createBackground(float w, float h){
    // Init dimensions
    double origW = 200.0;
    double targetW = qMin(w,h);
    double targetH = targetW;

    // Create image
    QImage _glassImage = QImage(QSize(targetW,targetH), QImage::Format_ARGB32);
    _glassImage.fill(0x00ffffff);
    
    // Init painter and scale to the original drawing size at 200x200
    QPainter p;
    p.begin(&_glassImage);
    setupPainter(&p);
    double scale = targetW/origW;
    p.scale(scale,scale);
    p.translate(100, 100);
    
    // Draw back face
    QLinearGradient gradient(0,-85,0,85);
    gradient.setColorAt(0, SKYBLUE);
    gradient.setColorAt(1, GROUNDBROWN);
    QBrush gbrush(gradient); 
    p.setBrush(gbrush);
    p.drawChord(-85,-85,170,170, 0, 360*16);

    // Save as pixmap
    p.end();    
    _background = QPixmap::fromImage(_glassImage, Qt::AutoColor);
}    
Ejemplo n.º 4
0
void IndicatorLight::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {

    // Init painter
    setupPainter(painter);
    painter->save(); {

        // Draw the dataref name and value
        painter->setBrush(Qt::NoBrush);
        painter->setPen(_labelColor);
        QFont font = defaultFont;
        font.setBold(true);
        font.setPixelSize(height()*0.7+itemFontSize());
        painter->setFont(font);
        if(_on) {
            painter->setOpacity(_strengthOn/100.0);
            painter->drawText(QRect(0,0,width(), height()), Qt::AlignCenter, _labelOn);
        } else {
            painter->setOpacity(_strengthOff/100.0);
            painter->drawText(QRect(0,0,width(), height()), Qt::AlignCenter, _labelOff);
        }

    } painter->restore();

    // Update the glow if enabled
    if(_glowEnabled && _labelGlowItem) {
        _labelGlowItem->setVisible(_on);
    }

    PanelItem::paint(painter, option, widget);
}
Ejemplo n.º 5
0
void Variometer::paintTopPixmap() {
    topPixmap = QPixmap(width(),height());
    topPixmap.fill(Qt::transparent);

    QPainter painter(&topPixmap);
    setupPainter(&painter);

    painter.save();
    double side = qMin(width(), height());
    // Round center
    painter.setPen(Qt::NoPen);
    painter.setBrush(darkGrayColor);
    painter.drawEllipse(QPointF(side/2, side/2), side/5, side/5);
    painter.setPen(Qt::white);

    // Unit text
    QTextOption textOption(Qt::AlignCenter);
    QFont unitFont = defaultFont;
    unitFont.setPointSizeF(side/20);
    painter.setFont(unitFont);

    painter.drawText(QRect(side/2 + side/5, 0, side/2 - side/5, side), Units::unitName(units), textOption);

    // Up and down arrows
    QFont arrowFont = defaultFont;
    arrowFont.setPointSizeF(side/10);
    painter.setFont(arrowFont);
    int textstartX = side/2 - side/5;
    int textWidth = side/2.5f;
    int textHeight = side/5.f;
    painter.drawText(QRect(textstartX, textstartX, textWidth, textHeight), QString::fromUtf8("↑"), textOption);
    painter.drawText(QRect(textstartX, textstartX + textHeight, textWidth, textHeight), QString::fromUtf8("↓"), textOption);
    painter.restore();
}
Ejemplo n.º 6
0
void IndicatorLight::createLabel(int w, int h) {
    if(_glowEnabled && this->scene()) {

        // Draw label glow
        QPixmap pixmap = QPixmap(w,h);
        pixmap.fill(Qt::transparent);
        QPainter painter;
        painter.begin(&pixmap); {
            setupPainter(&painter);
            painter.setBrush(_labelColor);
            painter.setPen(Qt::NoPen);
            painter.drawRoundedRect(0,0,w,h,20,20);
        } painter.end();

        // Setup the graphics item for glow
        // This has a special z-value ontop of other graphics items so that it can glow above the panel cover...
        if(_labelGlowItem) {
            this->scene()->removeItem(_labelGlowItem);
        }
        _labelGlowItem = new QGraphicsPixmapItem(NULL);
        _labelGlowItem->setPixmap(pixmap);
        _labelGlowItem->setOpacity(_glowStrength/100.0);
        _labelGlowItem->setX(this->x());
        _labelGlowItem->setY(this->y());
        _labelGlowItem->setZValue(PANEL_PANELITEM_GLOW_ZVALUE);
        QGraphicsBlurEffect *effect = new QGraphicsBlurEffect(this);
        effect->setBlurRadius(40);
        _labelGlowItem->setGraphicsEffect(effect);
        this->scene()->addItem(_labelGlowItem);
    }
}
Ejemplo n.º 7
0
void Summary::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * /*widget*/)
{
	QRectF rect = (option->type == QStyleOption::SO_GraphicsItem) ? boundingRect() : option->exposedRect;

	setupPainter(painter);
	painter->fillRect(rect,painter->brush());

	if (option->type == QStyleOption::SO_GraphicsItem)
	{
		drawSelection(painter, rect);
		drawTitle(tr("Summary"), TitleLeft, Qt::AlignCenter);
	}

	adjustRect(rect);

	if (frame()&DrawLeft)
		painter->drawLine(rect.left(), rect.top(), rect.left(), rect.bottom());

	if (frame()&DrawRight)
		painter->drawLine(rect.right(), rect.top(), rect.right(), rect.bottom());

	if (frame()&DrawTop)
		painter->drawLine(rect.left(), rect.top(), rect.right(), rect.top());

	if (frame()&DrawBottom)
		painter->drawLine(rect.left(), rect.bottom(), rect.right(), rect.bottom());
}
Ejemplo n.º 8
0
void GaugeCover::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
    setupPainter(painter);

    // Draw the cover image when not editing
    if(!isEditMode()) painter->drawImage(QPoint(0,0),_coverImage);

    PanelItem::paint(painter, option, widget);
}
void CSliderMultiPos::drawSpan(QStylePainter* painter, const QRect& rect,int baseElemIndex){
    QStyleOptionSlider opt;
    QColor currentColor;
    QPointF point1,point2;

    // area
    initStyleOption( &opt,baseElemIndex );
    QRect groove = this->style()->subControlRect( QStyle::CC_Slider,&opt,QStyle::SC_SliderGroove,this );

    // Apply color depending on span index
    // Considering the base element index is the interval index
    currentColor = getSpanColor(baseElemIndex);

    if( opt.orientation == Qt::Horizontal ){
        groove.adjust( 0,0,-1,0 );
        point1.setX( groove.center().x() );
        point1.setY( groove.top() );
        point2.setX( groove.center().x() );
        point2.setY( groove.bottom() );
    }
    else{
        groove.adjust( 0,0,0,-1 );
        point1.setX( groove.left() );
        point1.setY( groove.center().y() );
        point2.setX( groove.right() );
        point2.setY( groove.center().y() );
    }
    setupPainter( painter,point1,point2,currentColor );

    // draw groove
    painter->drawRect( rect );//.intersected( groove ) );

    if( displayPosition ){
        QPoint endOfSpan;
        if( this->tickPosition()==TicksBelow ){
            endOfSpan = rect.bottomLeft();
        }
        else{
            endOfSpan = rect.topLeft();
        }
        drawSpanValue( painter,endOfSpan,baseElemIndex );
        if( baseElemIndex==nbValues()-2 ){
            if( this->tickPosition()==TicksBelow ){
                endOfSpan = rect.bottomRight();
            }
            else{
                endOfSpan = rect.topRight();
            }
            drawSpanValue( painter,endOfSpan,baseElemIndex+1 );
        }
    }

    if( displayIntervalLabel ){
        drawSpanLabel( painter,rect,baseElemIndex );
    }

}
Ejemplo n.º 10
0
void PainterWidget::drawBrush(float x, float y)
{
        x = std::min(1.0f, std::max(0.0f, x));
        y = std::min(1.0f, std::max(0.0f, y));
            QPainter painter(&image);
            setupPainter(painter);
            painter.drawImage(x*image.width()-soft_brush.width()/2,y*image.height()-soft_brush.height()/2,soft_brush);
            update();
}
Ejemplo n.º 11
0
void PainterWidget::drawBrushAbsolute(QPoint p)
{
        p.setX(std::min(width(), std::max(0, p.x())));
        p.setY(std::min(height(), std::max(0, p.y())));
            QPainter painter(&image);
            setupPainter(painter);
            painter.drawImage(p.x()-soft_brush.width()/2,p.y()-soft_brush.height()/2,soft_brush);
            update();
}
Ejemplo n.º 12
0
void CSliderMultiPos::drawSpanLabel(QStylePainter* painter,QRect rect,int baseElemIndex){

    setupPainter( painter,rect.topLeft(),rect.bottomRight(),
                        this->palette().color( QPalette::Dark ).light( 50 ) );
    rect.setHeight(25);
    if( this->tickPosition()==TicksBelow ){
        rect.translate(0,-20);
    }
    painter->drawText( rect,Qt::AlignCenter,intervalLabelPrefix+QString::number(baseElemIndex+1) );
}
Ejemplo n.º 13
0
void SmoothCanvas::paintEvent(QPaintEvent* ev){
	Q_UNUSED(ev);

	QPainter* p = new QPainter();
	p->begin(this);
	setupPainter(p);

	// Draw the cache
	if(NULL != m_pCache){
		p->drawPixmap(QPoint(), *m_pCache);
	}else{
		p->setPen(Qt::NoPen);
		p->setBrush(QBrush(Qt::white));
		p->drawRect(rect());
		setupPainter(p);
	}

	// Draw the current path
	if(NULL != m_pCrntPath){
		p->drawPath(*m_pCrntPath);
	}
	p->end();
}
//! [1]
void PaintArea::mouseMoveEvent(QMouseEvent *event)
{
    if ((event->buttons() & Qt::LeftButton) && lastPos != QPoint(-1, -1)) {
        if (brushInterface) {
            QPainter painter(&theImage);
            setupPainter(painter);
            const QRect rect = brushInterface->mouseMove(brush, painter, lastPos,
                                                         event->pos());
            update(rect);
        }

        lastPos = event->pos();
    }
}
Ejemplo n.º 15
0
void QxtSpanSliderPrivate::drawSpan(QStylePainter* painter, const QRect& rect) const
{
    QStyleOptionSlider opt;
    initStyleOption(&opt);
    const QSlider* p = &qxt_p();

    // area
    QRect groove = p->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, p);
    if (opt.orientation == Qt::Horizontal)
        groove.adjust(0, 0, -1, 0);
    else
        groove.adjust(0, 0, 0, -1);

    // pen & brush
    painter->setPen(QPen(p->palette().color(QPalette::Dark).light(110), 0));
    if (opt.orientation == Qt::Horizontal)
        setupPainter(painter, opt.orientation, groove.center().x(), groove.top(), groove.center().x(), groove.bottom());
    else
        setupPainter(painter, opt.orientation, groove.left(), groove.center().y(), groove.right(), groove.center().y());

    // draw groove
    painter->drawRect(rect.intersected(groove));
}
void PaintArea::mouseReleaseEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton && lastPos != QPoint(-1, -1)) {
        if (brushInterface) {
            QPainter painter(&theImage);
            setupPainter(painter);
            QRect rect = brushInterface->mouseRelease(brush, painter,
                                                      event->pos());
            update(rect);
        }

        lastPos = QPoint(-1, -1);
    }
}
Ejemplo n.º 17
0
 void PaintArea::mousePressEvent(QMouseEvent *event)
 {
     if (event->button() == Qt::LeftButton) {
         if (!pendingPath.isEmpty()) {
             QPainter painter(&theImage);
             setupPainter(painter);

             const QRectF boundingRect = pendingPath.boundingRect();
             QLinearGradient gradient(boundingRect.topRight(),boundingRect.bottomLeft());
             gradient.setColorAt(0.0, QColor(color.red(), color.green(),color.blue(), 63));
             gradient.setColorAt(1.0, QColor(color.red(), color.green(),color.blue(), 191));
             painter.setBrush(gradient);
             painter.translate(event->pos() - boundingRect.center());
             painter.drawPath(pendingPath);

             pendingPath = QPainterPath();
 #ifndef QT_NO_CURSOR
             unsetCursor();
 #endif
             update();
         } 
	
	else {

             if (brushInterface) {

                 QPainter painter(&theImage);
                 setupPainter(painter);
                 const QRect rect = brushInterface->mousePress(brush, painter, event->pos());

                 update(rect);
             }

             lastPos = event->pos();
         }
     }
 }
Ejemplo n.º 18
0
void DrawingPolygonItem::render(QPainter* painter, const DrawingStyleOptions& styleOptions)
{
	QList<DrawingItemPoint*> lPoints = points();
	QPolygonF points;

	for(auto pointIter = lPoints.begin(); pointIter != lPoints.end(); pointIter++)
		points.append((*pointIter)->pos());

	setupPainter(painter, styleOptions, pen(), brush());
	painter->drawPolygon(points);

#ifdef DEBUG_DRAW_ITEM_SHAPE
	painter->setBrush(Qt::magenta);
	painter->setPen(QPen(Qt::magenta, 1));
	painter->drawPath(shape());
#endif
}
Ejemplo n.º 19
0
void Context2D::beginPainting()
{
    if (m_width <= 0 || m_height <=0)
        return;

    if (m_pixmap.width() != m_width || m_pixmap.height() != m_height) {
        if (m_painter.isActive())
            m_painter.end();
        m_pixmap = QPixmap(m_width, m_height);
        m_pixmap.fill(parent()->property("color").value<QColor>());
    }

    if (m_state.shadowBlur > 0 && m_painter.device() != &m_shadowbuffer) {
        if (m_painter.isActive())
            m_painter.end();
        updateShadowBuffer();
        m_painter.begin(&m_shadowbuffer);
        m_painter.setViewport(m_state.shadowOffsetX,
                              m_state.shadowOffsetY,
                              m_shadowbuffer.width(),
                              m_shadowbuffer.height());
        m_shadowbuffer.fill(Qt::transparent);
    }

    if (!m_painter.isActive()) {
        m_painter.begin(&m_pixmap);
        m_painter.setRenderHint(QPainter::Antialiasing);
        if (!m_state.clipPath.isEmpty())
            m_painter.setClipPath(m_state.clipPath);
        m_painter.setBrush(m_state.fillStyle);
        m_painter.setOpacity(m_state.globalAlpha);
        QPen pen;
        pen.setBrush(m_state.strokeStyle);
        if (pen.style() == Qt::NoPen)
            pen.setStyle(Qt::SolidLine);
        pen.setCapStyle(m_state.lineCap);
        pen.setJoinStyle(m_state.lineJoin);
        pen.setWidthF(m_state.lineWidth);
        pen.setMiterLimit(m_state.miterLimit);
        m_painter.setPen(pen);
    } else {
        setupPainter();
        m_state.flags = 0;
    }
}
Ejemplo n.º 20
0
void RotaryKnob::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
    setupPainter(painter);
    painter->setBrush(Qt::gray);
    painter->setPen(Qt::gray);
    double circleSize = height();
    painter->drawEllipse(0, 0, circleSize, circleSize);
    painter->setBrush(Qt::black);
    painter->setPen(Qt::black);
    painter->save();
    painter->translate(circleSize/2,circleSize/2);
    painter->rotate(_value);
    for(int i=0;i<8;i++) {
        painter->drawEllipse(0, circleSize/3, circleSize/10, circleSize/10);
        painter->rotate(45);
    }
    painter->restore();

    PanelItem::paint(painter, option, widget);
}
Ejemplo n.º 21
0
void SmoothCanvas::updateCache(){
	if(NULL != m_pCache){
		delete m_pCache;
	}
	m_pCache = new QPixmap(rect().width(), rect().height());
	QPainter* p = new QPainter();
	p->begin(m_pCache);
	p->setBrush(QBrush(Qt::white));
	p->setPen(Qt::white);
	p->drawRect(m_pCache->rect());
	setupPainter(p);

	foreach(QPainterPath* path, m_lPreviousPath){
		if(NULL != path){
			p->drawPath(*path);
		}
	}
	p->end();
}
Ejemplo n.º 22
0
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);
}
Ejemplo n.º 23
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);
}
Ejemplo n.º 24
0
void ImageViewer::paintEvent(QPaintEvent * /* event */)
{
    QPainter painter(this);
    painter.drawImage(QPoint(0, 0), *_displayImage);

    if ( bPaintable && _labelMapImage )
    {
        QImage _alphaChannel(_displayImage->width(), _displayImage->height(), QImage::Format_Indexed8);
        _alphaChannel.fill(100);
        QImage labelMapImage(*_labelMapImage);
        labelMapImage.setAlphaChannel(_alphaChannel);
        painter.drawImage(QPoint(0, 0), labelMapImage);
    }

    if(_labelType == 0 && bPaintable)
    {
        setupPainter(painter);
    }
    else if(_labelType == 1 && bPaintable)
    {
        setupOtherPainter(painter);
        painter.drawRect(_start_rect.x(), _start_rect.y(), _end_rect.x()-_start_rect.x(), _end_rect.y()-_start_rect.y());
    }
    else if(_labelType == 2 && bPaintable)
    {
        painter.setPen(QPen(Qt::red, 7));

        if( _bPolygonEndDrawing ) _polygonPointList.push_back(_polygonPointList.first());

        QPoint lastPt = _polygonPointList.first();
        painter.drawPoint(lastPt);
        foreach(QPoint curPt, _polygonPointList)
        {
            painter.setPen(QPen(Qt::red, 7));
            painter.drawPoint(curPt);

            painter.setPen(QPen(_lineColor, _lineThickness, Qt::SolidLine));
            painter.drawLine(lastPt, curPt);
            lastPt = curPt;
        }
Ejemplo n.º 25
0
void AttitudeIndicator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {

    // Init
    setupPainter(painter);
    double side = qMin(width(), height());
    double pitch = _pitchValue;
    if (pitch > maxPitch) pitch = maxPitch;
    if (pitch < (0-maxPitch)) pitch = (0-maxPitch);

    // Do drawing of cached pixmaps
    painter->save(); {

        // Make sure to clip the widget because of moving card
        painter->setClipRect(0,0,width(),height());

        // Move to center and draw background
        painter->translate(width()/2, height()/2);
        painter->drawPixmap(-_background.width()/2,-_background.height()/2,_background);

        // Rotate to roll and draw moving card
        painter->rotate(-_rollValue);
        double pitchPixelsY = pitch*(side*0.005f);
                DEBUG << pitchPixelsY;
        painter->drawPixmap(QPointF(-_card.width()/2.0,-_card.height()/2.0 + pitchPixelsY),_card);

        // Draw frame
        painter->drawPixmap(-_frame.width()/2,-_frame.height()/2,_frame);

        // Undo roll and draw glass
        painter->rotate(+_rollValue);
        painter->drawPixmap(-_glass.width()/2,-_glass.height()/2,_glass);

    } painter->restore();

    PanelItem::paint(painter, option, widget);
}
Ejemplo n.º 26
0
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);
}
Ejemplo n.º 27
0
void TurnAndBank::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {

    int side = qMin(width(), height());
    setupPainter(painter);
    painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
    painter->save();
    painter->scale(side / 200.0, side / 200.0);
    painter->save();
    painter->translate(100, 100);
    
    painter->setBrush(Qt::black);
    painter->drawChord(-95,-95,190,190,0,360*16);
    
    painter->save();
    painter->scale(0.92,0.92);
    
    painter->setPen(Qt::white);
    
    painter->setBrush(Qt::NoBrush);
    
    painter->drawPixmap(-_frame.width()/6.,
                        -_frame.height()/6.,
                        _frame.width()/3.,
                        _frame.height()/3.,
                        _frame);
    
    painter->drawPixmap(-80, -(_ball.height()*160./_ball.width())/2.,
                        160, _ball.height()*160./_ball.width(),
                        _ball);
    
    float x=0., y=0;
    const float pixelDeflectionPerDegree = 7.;
    
    if (_slipValue>maxOffbalance) _slipValue=maxOffbalance;
    if (_slipValue<(0-maxOffbalance)) _slipValue=0-maxOffbalance;
    
    
    x-=pixelDeflectionPerDegree*_slipValue;
    
    
    
    y-=fabs(_slipValue)/3.1;
    painter->setBrush(Qt::black);
    painter->drawEllipse(QRectF(x-10.,35.+y, 20., 25.));
    
    
    painter->save();
    float roll = _rollValue;
    if (roll>maxRoll) roll=maxRoll;
    if (roll<(0-maxRoll)) roll=(0-maxRoll);

    
    
    painter->rotate(roll);
    
    painter->drawPixmap(-80, -(_card.height()*160./_card.width())/2.,
                        160, _card.height()*160./_card.width(),
                        _card);
    
    painter->restore();     //Unroll
    
    if (0){
        // Print roll and pitch on AI for debugging, if needed.
        QString pitchS = QString::number(_slipValue, 'f', 2);
        int width = painter->fontMetrics().width(pitchS);
        int height =painter->fontMetrics().height();
        painter->drawText(-width/2,68,width, height, Qt::AlignCenter,  pitchS);
    }

    painter->restore();
    painter->drawPixmap(-100,-100,200,200, _bezel);
    
    painter->restore();     //Untranslate
    painter->restore();     //Unscale
    
    
    PanelItem::paint(painter, option, widget);
    
}
Ejemplo n.º 28
0
void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, QWidget* widget) {
    Q_UNUSED(widget);
    Q_UNUSED(style);

    painter->save();

    setupPainter(painter);
    prepareRect(painter,style,widget);

    QSizeF tmpSize = rect().size()-m_textSize;

    if (!painter->clipRegion().isEmpty()){
        QRegion clipReg=painter->clipRegion().xored(painter->clipRegion().subtracted(rect().toRect()));
        painter->setClipRegion(clipReg);
    } else {
        painter->setClipRect(rect());
    }

    qreal hOffset = 0, vOffset=0;
    switch (m_angle){
        case Angle0:
            hOffset = fakeMarginSize();
            if ((tmpSize.height()>0) && (m_alignment & Qt::AlignVCenter)){
                vOffset = tmpSize.height()/2;
            }
            if ((tmpSize.height()>0) && (m_alignment & Qt::AlignBottom)) // allow html
                vOffset = tmpSize.height();
            painter->translate(hOffset,vOffset);
        break;
        case Angle90:
            hOffset = width()-fakeMarginSize();
            vOffset = fakeMarginSize();
            if (m_alignment & Qt::AlignVCenter){
                hOffset = (width()-m_text->size().height())/2+m_text->size().height();
            }

            if (m_alignment & Qt::AlignBottom){
                hOffset = (m_text->size().height());
            }
            painter->translate(hOffset,vOffset);
            painter->rotate(90);
        break;
        case Angle180:
            hOffset = width()-fakeMarginSize();
            vOffset = height()-fakeMarginSize();
            if ((tmpSize.width()>0) && (m_alignment & Qt::AlignVCenter)){
                vOffset = tmpSize.height()/2+m_text->size().height();
            }
            if ((tmpSize.height()>0) && (m_alignment & Qt::AlignBottom)){
                vOffset = (m_text->size().height());
            }
            painter->translate(hOffset,vOffset);
            painter->rotate(180);
        break;
        case Angle270:
            hOffset = fakeMarginSize();
            vOffset = height()-fakeMarginSize();
            if (m_alignment & Qt::AlignVCenter){
                hOffset = (width()-m_text->size().height())/2;
            }

            if (m_alignment & Qt::AlignBottom){
                hOffset = (width()-m_text->size().height());
            }
            painter->translate(hOffset,vOffset);
            painter->rotate(270);
        break;
        case Angle45:
            painter->translate(width()/2,0);
            painter->rotate(45);
            m_text->setTextWidth(sqrt(2*(pow(width()/2,2))));
        break;
        case Angle315:
            painter->translate(0,height()/2);
            painter->rotate(315);
            m_text->setTextWidth(sqrt(2*(pow(height()/2,2))));
        break;
    }

//    for(QTextBlock it=m_text->begin();it!=m_text->end();it=it.next()){
//        for (int i=0;i<it.layout()->lineCount();i++){
//            painter->setOpacity(qreal(foregroundOpacity())/100);
//            it.layout()->lineAt(i).draw(painter,QPointF(0,0));
//        }
//    }

    painter->setOpacity(qreal(foregroundOpacity())/100);

    //m_text->setDefaultTextOption();
    QAbstractTextDocumentLayout::PaintContext ctx;
    ctx.palette.setColor(QPalette::Text, fontColor());
    m_text->documentLayout()->draw(painter,ctx);

//    m_layout.draw(ppainter,QPointF(marginSize(),0),);
//    ppainter->setFont(transformToSceneFont(font()));
//    QTextOption o;
//    o.setAlignment(alignment());
//    ppainter->drawText(rect(), content(), o);

    painter->restore();
    BaseDesignIntf::paint(painter, style, widget);
}
Ejemplo n.º 29
0
void AttitudeIndicator::createCard(float w, float h){
    // Init dimensions
    double size = 0.85;
    double targetW = qMin(w*size,h*size);
    double targetH = targetW*0.70;
    double realH = targetH*1.3;
    double midX = targetW / 2.0;
    double midY = targetH / 2.0;

    // Create image
    QImage _cardImage = QImage(QSize(targetW,realH), QImage::Format_ARGB32);
    _cardImage.fill(0x00ff0000);

    QPainter p;
    p.begin(&_cardImage);
    setupPainter(&p);
    p.translate(0,(realH-targetH)/2.0);

    // Shadow
    p.save(); {
        double shadowSize = 0.86;
        p.setPen(Qt::NoPen);
        double shadowRH = realH/2.0*shadowSize;
        QRadialGradient radial(QPointF(midX, midY), shadowRH);
        p.scale(1.8,1.0);
        p.translate(-midX*0.4,0);
        radial.setColorAt(0.6, Qt::black); //I want the center to be black
        radial.setColorAt(1, Qt::transparent); //I want the sides to be white
        p.setBrush(QBrush(radial));
        p.setOpacity(0.4);
        p.drawEllipse(QPointF(midX,midY),targetW/2.0*0.8,shadowRH);
    } p.restore();

    // Draw upper horizon
    QLinearGradient gradient(5, midY-5,midX,midY-5);
    gradient.setSpread(QGradient::ReflectSpread);
    gradient.setColorAt(0, ATTITUDE_COLOR_BLUE_DARK);
    gradient.setColorAt(1, ATTITUDE_COLOR_BLUE_LIGHT);
    QBrush gbrush(gradient);
    p.setPen(QPen(QColor(0,0,0,50),targetW*0.004));
    p.setBrush(gbrush);
    p.drawChord(0,0,targetW, targetH, 0, 180*16);

    // Draw lower ground
    gradient.setColorAt(0, ATTITUDE_COLOR_BROWN_DARK);
    gradient.setColorAt(1, ATTITUDE_COLOR_BROWN_LIGHT);
    QBrush gbrush2(gradient);
    p.setBrush(gbrush2);
    p.drawChord(0,0, targetW, targetH, 180*16, 180*16);

    p.save(); {
        // Original drawing code was 510x360, so we to keep that code we need to scale for it
        double origW = 510.0;
        double origH = 360;
        double origMidX = origW / 2.0;
        double origMidY = origH / 2.0;
        double scale = targetW/origW;
        p.scale(scale,scale);

        // Draw horizon and angle cues
        p.setPen(QPen(Qt::white, 7, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
        p.drawLine(0,origMidY,origW-1,origMidY);
        p.setPen(QPen(Qt::white, 5, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
        float sl = origMidX*0.72;
        float ll = origMidX*0.84;
        p.drawLine(origMidX,origMidY,origMidX+cos(30./180.*3.14159)*ll,origMidY+sin(30./180.*3.14159)*ll);
        p.drawLine(origMidX,origMidY,origMidX+cos(60./180.*3.14159)*sl,origMidY+sin(60./180.*3.14159)*sl);
        p.drawLine(origMidX,origMidY,origMidX-cos(30./180.*3.14159)*ll,origMidY+sin(30./180.*3.14159)*ll);
        p.drawLine(origMidX,origMidY,origMidX-cos(60./180.*3.14159)*sl,origMidY+sin(60./180.*3.14159)*sl);

        // Draw pitch up and down lines
        p.setPen(QPen(QColor(0,0,15), 5, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
        p.drawLine(origMidX-45, origMidY-60*pitchPixelsPerDegree, origMidX+45,origMidY-60*pitchPixelsPerDegree);
        p.drawLine(origMidX-24, origMidY-30*pitchPixelsPerDegree, origMidX+24,origMidY-30*pitchPixelsPerDegree);
        p.setPen(QPen(Qt::white, 5, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
        p.drawLine(origMidX-35, origMidY+80*pitchPixelsPerDegree, origMidX+35,origMidY+80*pitchPixelsPerDegree);
        p.drawLine(origMidX-17, origMidY+46*pitchPixelsPerDegree, origMidX+17,origMidY+46*pitchPixelsPerDegree);

    } p.restore();

    // Save as pixmap
    p.end();
    _card = QPixmap::fromImage(_cardImage, Qt::AutoColor);
}
Ejemplo n.º 30
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();
}