Пример #1
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);
}
Пример #2
0
void PaintMethods::paintDebugDrawing(QPainter& painter, const DebugDrawing& debugDrawing, const QTransform& baseTrans)
{
  for(const DebugDrawing::Element* e = debugDrawing.getFirst(); e; e = debugDrawing.getNext(e))
    switch(e->type)
    {
      case DebugDrawing::Element::POLYGON:
      {
        paintPolygon(*static_cast<const DebugDrawing::Polygon*>(e), painter);
        break;
      }
      case DebugDrawing::Element::GRID_RGBA:
      {
        paintGridRGBA(*static_cast<const DebugDrawing::GridRGBA*>(e), painter);
        break;
      }
      case DebugDrawing::Element::GRID_MONO:
      {
        paintGridMono(*static_cast<const DebugDrawing::GridMono*>(e), painter);
        break;
      }
      case DebugDrawing::Element::ELLIPSE:
      {
        paintEllipse(*static_cast<const DebugDrawing::Ellipse*>(e), painter);
        break;
      }
      case DebugDrawing::Element::ARC:
      {
        paintArc(*static_cast<const DebugDrawing::Arc*>(e), painter);
        break;
      }
      case DebugDrawing::Element::RECTANGLE:
      {
        paintRectangle(*static_cast<const DebugDrawing::Rectangle*>(e), painter);
        break;
      }
      case DebugDrawing::Element::LINE:
      {
        paintLine(*static_cast<const DebugDrawing::Line*>(e), painter);
        break;
      }
      case DebugDrawing::Element::ORIGIN:
      {
        paintOrigin(*static_cast<const DebugDrawing::Origin*>(e), painter, baseTrans);
        break;
      }
      case DebugDrawing::Element::TEXT:
      {
        paintText(*static_cast<const DebugDrawing::Text*>(e), painter);
        break;
      }
      default:
        break;
    }
}
Пример #3
0
void t_libraryEditor::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    QBrush polyBrush;
    polyBrush.setColor(g_color);
    QPen dotPen;
    uint8_t minThickness = 4;
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.scale(scale, scale);
    painter.translate(offsetx,offsety);
    painter.setBackgroundMode(Qt::OpaqueMode);
    painter.setBackground(QBrush(QColor(255,255,255)));
    painter.fillRect(-2000,-2000,4000,4000,QColor(255,255,255));

    dotPen.setStyle(Qt::DashLine);
    dotPen.setColor(QColor(200,200,200));
    dotPen.setWidth(0);
    painter.setPen(dotPen);
    for(int16_t x = -2000; x != 2000; x += 50)
    {
        painter.drawLine(x,-2000,x,2000);
        painter.drawLine(-2000,x,2000,x);
    }

    if(haveComp)
    {
        for(uint16_t t = 0; t != currentComponent->items.size(); ++t)
        {
            if(currentComponent->items.at(t)->thickness < minThickness)
                currentComponent->items.at(t)->thickness = minThickness;
            if(currentComponent->items.at(t)->type == 'P')
            {
                t_PolylineObject *ob = static_cast<t_PolylineObject*>(currentComponent->items.at(t));
                paintPolygon(painter, *ob);
            }
            else if(currentComponent->items.at(t)->type == 'C')
            {
                t_CircleObject *ob = static_cast<t_CircleObject*>(currentComponent->items.at(t));
                paintCircle(painter, *ob);
            }
            else if(currentComponent->items.at(t)->type == 'X')
            {
                t_PinObject *ob = static_cast<t_PinObject*>(currentComponent->items.at(t));
                paintPin(painter, *ob);
            }
            else if(currentComponent->items.at(t)->type == 'S')
            {
                t_RectangleObject *ob = static_cast<t_RectangleObject*>(currentComponent->items.at(t));
                paintRectangle(painter, *ob);
            }
            else if(currentComponent->items.at(t)->type == 'A')
            {
                t_ArcObject *ob = static_cast<t_ArcObject*>(currentComponent->items.at(t));
                paintArc(painter, *ob);
            }
        }
        for(uint8_t t = 0; t != currentComponent->fields.size(); ++t)
        {
            t_component_field tF = currentComponent->fields.at(t);
            if(tF.flags & (1 << VISIBLE))
            {
                paintText(painter, tF);
            }
        }
    }

/*    if(incompleteStage)
    {
        dotPen.setWidth(5);
        dotPen.setStyle(Qt::SolidLine);
        dotPen.setColor(QColor(200,100,100));
        painter.setPen(dotPen);
        painter.drawLine(incompleteLine);
    }
    else if(pinPlacement)
    {
        dotPen.setWidth(1);
        dotPen.setColor(QColor(100,200,100));
        painter.setPen(dotPen);
        painter.drawEllipse(incompleteLine.p2(), 10, 10);
    }
    */
    dotPen.setColor(QColor(100,100,100));
    dotPen.setWidth(1);
    painter.setPen(dotPen);
    painter.drawLine(0,-10,0,10);
    painter.drawLine(-10,0,10,0);
    event->accept();
}
Пример #4
0
/*
ArcsDrawEventHandler : Handles the draw events for the "Arcs" window.

Parameter DescriptionsinHandler : A reference to the current handler call chain. This is passed to your handler so that you can call CallNextEventHandler if you need to.
inEvent : The event that triggered this call.
inUserData : The application-specific data you passed in to InstallEventHandler.
*/
OSStatus ArcsDrawEventHandler (EventHandlerCallRef inHandler, EventRef inEvent, void* inUserData) {
	OSStatus status = eventNotHandledErr;
	CGContextRef context;
    CGRect r;
	
	//CallNextEventHandler in order to make sure the default handling of the inEvent 
	// (drawing the white background) happens
	status = CallNextEventHandler( inHandler, inEvent );
	require_noerr(status, CantCallNextEventHandler);
	
	// Get the CGContextRef
	status = GetEventParameter (inEvent, 
								kEventParamCGContextRef, 
								typeCGContextRef, 
								NULL, 
								sizeof (CGContextRef),
								NULL,
								&context);
	require_noerr(status, CantGetEventParameter);
	
	//  Draw the outer arcs in the left portion of the window
	r.size.height = 210;
    r.origin.x = 20;
    r.origin.y = 20;
    r.size.width = 210;
    frameArc(context, r, 0, 135);
    frameArc(context, r, 180 - 10, 20);
    frameArc(context, r, 225, 45);
    frameArc(context, r, 315 - 20, 40);
	
	// Draw the inner arcs in the left portion of the window
    r.size.height = 145;
    r.origin.x = 75;
    r.origin.y = 55;
    r.size.width = 100;
    frameArc(context, r, 0, 135);
    frameArc(context, r, 180 - 10, 20);
    frameArc(context, r, 225, 45);
    frameArc(context, r, 315 - 20, 40);
	
    /* Set the fill color to green. */
    CGContextSetRGBFillColor(context, 0, 1, 0, 1);
	
	// Draw and fill the outer arcs in the right portion of the window
    r.size.height = 210;
    r.origin.x = 270;
    r.origin.y = 20;
    r.size.width = 210;
    paintArc(context, r, 0, 135);
    paintArc(context, r, 180 - 10, 20);
    paintArc(context, r, 225, 45);
    paintArc(context, r, 315 - 20, 40);
	
    /* Set the fill color to yellow. */
    CGContextSetRGBFillColor(context, 1, 1, 0, 1);

	// Draw and fill the inner arcs in the right portion of the window
    r.size.height = 145;
    r.origin.x = 325;
    r.origin.y = 55;
    r.size.width = 100;
    paintArc(context, r, 0, 135);
    paintArc(context, r, 180 - 10, 20);
    paintArc(context, r, 225, 45);
    paintArc(context, r, 315 - 20, 40);
	
CantCallNextEventHandler:
CantGetEventParameter:
	
		return status;
}