示例#1
0
/**
 * @brief Draw the end point.
 * @param painter
 */
void RenderArea::drawEndPos(QPainter &painter)
{
    painter.save();
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setPen(Qt::black);
    painter.setBrush(QBrush(Qt::blue));
    painter.drawEllipse(END_POS_X - BOT_RADIUS, END_POS_Y - BOT_RADIUS, 2 * BOT_RADIUS, 2 * BOT_RADIUS);
    painter.restore();
}
示例#2
0
void TurnAndBank::createBall(void){
    QImage _glassImage = QImage(QSize(800,800), QImage::Format_ARGB32);
    _glassImage.fill(0x00ffffff);
    
    QPainter p;
    
    p.setRenderHint(QPainter::Antialiasing, true);
    p.begin(&_glassImage);
    p.translate(400, 400);
    
    // QLinearGradient gradient(0,101,0,199);
    // gradient.setColorAt(0, SKYBLUE);
    // gradient.setColorAt(1, GROUNDBROWN);
   
    QRadialGradient gradient(0,-4500, 4750, 0, 30000);
    gradient.setColorAt(0, Qt::white);
    gradient.setColorAt(1, Qt::green);
    gradient.setSpread(QGradient::ReflectSpread);
    
    QBrush gbrush(gradient); 
    p.setBrush(gbrush);
    //    p.drawRect(-350, 120, 700, 150);
    
    
    QPainterPath pathBottom;
    pathBottom.moveTo(-310, 150);
    pathBottom.arcTo(-2500+50,-3830-1000,5000,5000, -96, 12);
    //pathBottom.lineTo(310, 250);
    pathBottom.arcTo(-2000,-3700,4000,4000, -81, -18);
    //pathBottom.lineTo(-310, 150);
    
    //    pathBottom.lineTo(-240,0);
    //pathBottom.arcTo(-240,-240,480,480, 180, 180);
    
    //    p.setPen(QPen(QColor(79, 106, 25), 0, Qt::SolidLine,
    //                     Qt::FlatCap, Qt::MiterJoin));
    p.setPen(QPen(Qt::white, 4, Qt::SolidLine,
                  Qt::FlatCap, Qt::MiterJoin));
    p.setPen(Qt::NoPen);
    p.setBrush(gbrush);
    // p.setBrush(GROUNDBROWN);
    
    p.drawPath(pathBottom);
    
    p.setBrush(Qt::black);
    
    
    p.setPen(QPen(Qt::black, 4, Qt::SolidLine,
                  Qt::FlatCap, Qt::MiterJoin));    
    p.drawLine(-50,170, -50, 300);
    p.drawLine(50,170, 50, 300);
    
    p.end();    
    
    _ball = QPixmap::fromImage(_glassImage, Qt::AutoColor);
    
}    
void ConnectionTool::paint(QPainter &painter, const KoViewConverter &converter)
{
    // get the correctly sized rect for painting handles
    QRectF handleRect = handlePaintRect(QPointF());

    painter.setRenderHint(QPainter::Antialiasing, true);

    if (m_currentStrategy) {
        painter.save();
        m_currentStrategy->paint(painter, converter);
        painter.restore();
    }

    QList<KoShape*> shapes = canvas()->shapeManager()->shapes();
    for (QList<KoShape*>::const_iterator end = shapes.constBegin(); end !=  shapes.constEnd(); ++end) {
        KoShape* shape = *end;
        if (!dynamic_cast<KoConnectionShape*>(shape)) {
            // only paint connection points of textShapes not inside a tos container and other shapes
            if (shape->shapeId() == TextShape_SHAPEID && dynamic_cast<KoTosContainer*>(shape->parent())) continue;

            painter.save();
            painter.setPen(Qt::black);
            QTransform transform = shape->absoluteTransformation(0);
            KoShape::applyConversion(painter, converter);
            // Draw all the connection points of the shape
            KoConnectionPoints connectionPoints = shape->connectionPoints();
            KoConnectionPoints::const_iterator cp = connectionPoints.constBegin();
            KoConnectionPoints::const_iterator lastCp = connectionPoints.constEnd();
            for(; cp != lastCp; ++cp) {
                if (shape == findNonConnectionShapeAtPosition(transform.map(cp.value().position)) ) {
                    handleRect.moveCenter(transform.map(cp.value().position));
                    painter.setBrush(cp.key() == m_activeHandle && shape == m_currentShape ?
                                     Qt::red : Qt::white);
                    painter.drawRect(handleRect);
                }
            }
            painter.restore();
        }
    }
    // paint connection points or connection handles depending
    // on the shape the mouse is currently
    if (m_currentShape && m_editMode == EditConnection) {
        KoConnectionShape *connectionShape = dynamic_cast<KoConnectionShape*>(m_currentShape);
        if (connectionShape) {
            int radius = handleRadius()+1;
            int handleCount = connectionShape->handleCount();
            for(int i = 0; i < handleCount; ++i) {
                painter.save();
                painter.setPen(Qt::blue);
                painter.setBrush(i == m_activeHandle ? Qt::red : Qt::white);
                painter.setTransform(connectionShape->absoluteTransformation(&converter) * painter.transform());
                connectionShape->paintHandle(painter, converter, i, radius);
                painter.restore();
            }
        }
    }
}
示例#4
0
void
drawCompositedPopup( QWidget* widget,
                     const QPainterPath& outline,
                     const QColor& lineColor,
                     const QBrush& backgroundBrush,
                     qreal opacity )
{
    bool compositingWorks = true;
#if defined(Q_WS_WIN)   //HACK: Windows refuses to perform compositing so we must fake it
    compositingWorks = false;
#elif defined(Q_WS_X11)
    if ( !QX11Info::isCompositingManagerRunning() )
        compositingWorks = false;
#endif

    QPainter p;
    QImage result;
    if ( compositingWorks )
    {
        p.begin( widget );
        p.setRenderHint( QPainter::Antialiasing );
        p.setBackgroundMode( Qt::TransparentMode );
    }
    else
    {
        result =  QImage( widget->rect().size(), QImage::Format_ARGB32_Premultiplied );
        p.begin( &result );
        p.setCompositionMode( QPainter::CompositionMode_Source );
        p.fillRect( result.rect(), Qt::transparent );
        p.setCompositionMode( QPainter::CompositionMode_SourceOver );
    }

    QPen pen( lineColor );
    pen.setWidth( 2 );
    p.setPen( pen );
    p.drawPath( outline );

    p.setOpacity( opacity );
    p.fillPath( outline, backgroundBrush );
    p.end();

    if ( !compositingWorks )
    {
        QPainter finalPainter( widget );
        finalPainter.setRenderHint( QPainter::Antialiasing );
        finalPainter.setBackgroundMode( Qt::TransparentMode );
        finalPainter.drawImage( 0, 0, result );
        widget->setMask( QPixmap::fromImage( result ).mask() );
    }

#ifdef QT_MAC_USE_COCOA
    // Work around bug in Qt/Mac Cocoa where opening subsequent popups
    // would incorrectly calculate the background due to it not being
    // invalidated.
    SourceTreePopupHelper::clearBackground( widget );
#endif
}
void MapGrid::paintEvent(QPaintEvent *event)
{
    QPainter painter;
    painter.begin(this);
    painter.setRenderHint(QPainter::Antialiasing);

    gesti->paint(&painter,event,elapsed);
   // painter.end();
}
void DivineProportionShape::paintDecorations(QPainter &painter, const KoViewConverter &converter, const KoCanvasBase *canvas)
{
    Q_UNUSED(canvas);
    if (!m_printable) {
        applyConversion(painter, converter);
        painter.setRenderHint(QPainter::Antialiasing);
        draw(painter);
    }
}
示例#7
0
void DBThread::RenderMessage(QPainter& painter, qreal width, qreal height, const char* message)
{
  painter.setRenderHint(QPainter::Antialiasing);
  painter.setRenderHint(QPainter::TextAntialiasing);
  painter.setRenderHint(QPainter::SmoothPixmapTransform);

  painter.fillRect(0,0,width,height,
                   QColor::fromRgbF(0.0,0.0,0.0,1.0));

  painter.setPen(QColor::fromRgbF(1.0,1.0,1.0,1.0));

  QString text(message);

  painter.drawText(QRectF(0.0,0.0,width,height),
                   Qt::AlignCenter|Qt::AlignVCenter,
                   text,
                   NULL);
}
示例#8
0
void CMeter2DGraphView::InitializeRasterRenderer( QPainter& aPainter, QImage& anImage )
{
   anImage.fill( 0x00000000 );
   
   aPainter.begin( &anImage );
   aPainter.setViewport( 0, 0, anImage.width(), anImage.height() );
   aPainter.setWindow( 0, anImage.height(), anImage.width(), -anImage.height() );
   aPainter.setRenderHint( QPainter::HighQualityAntialiasing );
}
示例#9
0
void QRWidget::paintEvent(QPaintEvent *pe)
{
    Q_UNUSED(pe);
    QPainter painter;
    painter.begin(this);
    painter.setRenderHint(QPainter::Antialiasing);
    paint(painter);
    painter.end();
}
示例#10
0
		void paint(QPainter &painter){
			painter.setRenderHint(QPainter::Antialiasing,true);
			const T w=painter.device()->width();
			const T h=painter.device()->height();
			QPen base(QBrush(Qt::NoBrush),2);

			QPen brown(base);
			brown.setWidthF(0.01);
			brown.setStyle(Qt::SolidLine);
			brown.setColor(QColor("brown"));

			QPen green(base);
			green.setWidthF(0.04);
			green.setColor(QColor("green"));

			QPen purple(base);
			purple.setWidthF(0.01);
			purple.setColor(QColor("purple").darker());

			painter.translate(w/2,h/2);
			qreal s=qMin(w,h);
			painter.scale(s,s);

			T step=0.02;
			T gx=cx/step;
			gx-=floor(gx);
			gx*=-step;
			T gy=cy/step;
			gy-=floor(gy);
			gy*=-step;
			painter.setPen(brown);
			for(T y=gy-h;y<h;y+=step){
				painter.drawLine(QPointF(0,y-1),QPointF(w,y+1));
			}
			for(T x=gx-w;x<w;x+=step){
				painter.drawLine(QPointF(x-1,0),QPointF(x+1,h));
			}
			if(singleLimbMode){
				limbs[0]->paint(painter);
			}
			else{

				for(quint32 i=0;i<limbCount;++i){
					limbs[i]->paint(painter);
				}

				const T r=0.01;
				QPointF cob(cobx,coby);
				painter.setPen(green);
				painter.drawEllipse(cob,r,r);

				QPointF cog(cogx,cogy);
				painter.setPen(purple);
				painter.drawEllipse(cog,r,r);
			}

		}
示例#11
0
void CodClassInstCanvas::draw(QPainter & p) {
  if (visible()) {
	p.setRenderHint(QPainter::Antialiasing, true);
    ClassInstCanvas::draw(p, the_canvas(), rect());

    if (selected())
      show_mark(p, rect());
  }
}
示例#12
0
/**
 * @brief Draw the start position of the bot.
 * @param painter
 */
void RenderArea::drawStartPos(QPainter &painter)
{
    painter.save();
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setPen(Qt::black);
    painter.setBrush(QBrush(Qt::red));
    painter.drawEllipse(this->x() + START_POS_X - BOT_RADIUS, this->y() + START_POS_Y - BOT_RADIUS, 2 * BOT_RADIUS, 2 * BOT_RADIUS);
    painter.restore();
}
示例#13
0
void dslDial::paint(QPainter &p, QRectF dialRect, QColor dialColor, bool hover, bool inc)
{
    p.setRenderHint(QPainter::Antialiasing, true);
    p.setPen(dialColor);
    p.setBrush(dialColor);

    int dialStartAngle = 225 * 16;
    int dialSpanAngle = -270 * 16;

    // draw dial arc
    p.drawArc(dialRect, dialStartAngle, dialSpanAngle);
    // draw ticks
    p.save();
    p.translate(dialRect.center());
    p.rotate(45);
    for (uint64_t i = 0; i < _div; i++) {
        // draw major ticks
        p.drawLine(0, dialRect.width()/2+3, 0, dialRect.width()/2+8);
        // draw minor ticks
        for (uint64_t j = 0; (j < 5) && (i < _div - 1); j++) {
            p.drawLine(0, dialRect.width()/2+3, 0, dialRect.width()/2+5);
            p.rotate(54.0/(_div-1));
        }
    }
    // draw pointer
    p.rotate(90+270.0/(_div-1)*_sel);
    p.drawEllipse(-3, -3, 6, 6);
    p.drawLine(3, 0, 0, dialRect.width()/2-3);
    p.drawLine(-3, 0, 0, dialRect.width()/2-3);
    p.restore();
    // draw value
    uint64_t displayValue = _value[_sel]*_factor;
    uint64_t displayIndex = 0;
    while(displayValue / _step >= 1) {
        displayValue = displayValue / _step;
        displayIndex++;
    }
    QString pText = QString::number(displayValue) + _unit[displayIndex] + "/div";
    QFontMetrics fm(p.font());
    const QRectF valueRect = QRectF(dialRect.left(), dialRect.bottom()-dialRect.width()*0.3+fm.height()*0.5, dialRect.width(), fm.height());
    p.drawText(valueRect, Qt::AlignCenter, pText);

    // draw +/-
    if (hover) {
        const int arcInc = 15;
        const QRectF hoverRect = QRectF(dialRect.left()-arcInc, dialRect.top()-arcInc, dialRect.width()+arcInc*2, dialRect.height()+arcInc*2);
        const double arcSpan = hoverRect.width()/(2*sqrt(2));
        p.drawArc(hoverRect, 135 * 16, -90 * 16);
        if (inc)
            p.drawLine(hoverRect.center().x()+arcSpan, hoverRect.center().y()-arcSpan,
                       hoverRect.center().x()+arcSpan-4, hoverRect.center().y()-arcSpan-10);
        else
            p.drawLine(hoverRect.center().x()-arcSpan, hoverRect.center().y()-arcSpan,
                       hoverRect.center().x()-arcSpan+4, hoverRect.center().y()-arcSpan-10);
    }
}
示例#14
0
// paint a ROUND FLAT led lamp
void KLed::paintFlat()
{
  if ( paintCachedPixmap() )
    return;

  QPainter paint;
  QColor color;
  QBrush brush;
  QPen pen;

  int width = ledWidth();

  int scale = 3;
  QPixmap *tmpMap = 0;

  width *= scale;

  tmpMap = new QPixmap( width + 6, width + 6 );
  tmpMap->fill( palette().color( backgroundRole() ) );

  // start painting widget
  paint.begin( tmpMap );
  paint.setRenderHint(QPainter::Antialiasing);

  // Set the color of the LED according to given parameters
  color = ( d->state ) ? d->color : d->offColor;

  // Set the brush to SolidPattern, this fills the entire area
  // of the ellipse which is drawn with a thin gray "border" (pen)
  brush.setStyle( Qt::SolidPattern );
  brush.setColor( color );

  pen.setWidth( scale );
  color = palette().color( QPalette::Dark );
  pen.setColor( color ); // Set the pen accordingly

  paint.setPen( pen ); // Select pen for drawing
  paint.setBrush( brush ); // Assign the brush to the painter

  // Draws a "flat" LED with the given color:
  paint.drawEllipse( scale, scale, width - scale * 2, width - scale * 2 );

  paint.end();

  // painting done
  QPixmap *&dest = ( d->state == On ? d->onMap : d->offMap );
  QImage i = tmpMap->toImage();
  width /= 3;
  i = i.scaled( width, width, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
  delete tmpMap;

  dest = new QPixmap( QPixmap::fromImage( i ) );
  paint.begin( this );
  paint.drawPixmap( 0, 0, *dest );
  paint.end();
}
示例#15
0
void
Thumbnail::paintOverImage(
	QPainter& painter, QTransform const& image_to_display,
	QTransform const& thumb_to_display)
{	
	// We work in display coordinates because we want to be
	// pixel-accurate with what we draw.
	painter.setWorldTransform(QTransform());

	QTransform const virt_to_display(virtToThumb() * thumb_to_display);

	QRectF const inner_rect(virt_to_display.map(m_virtContentRect).boundingRect());
	
	// We extend the outer rectangle because otherwise we may get white
	// thin lines near the edges due to rounding errors and the lack
	// of subpixel accuracy.  Doing that is actually OK, because what
	// we paint will be clipped anyway.
	QRectF const outer_rect(
		virt_to_display.map(m_virtOuterRect).boundingRect().adjusted(-1.0, -1.0, 1.0, 1.0)
	);
	
	QPainterPath outer_outline;
	outer_outline.addPolygon(PolygonUtils::round(outer_rect));
	
	QPainterPath content_outline;
	content_outline.addPolygon(PolygonUtils::round(inner_rect));
	
	painter.setRenderHint(QPainter::Antialiasing, true);
	
	QColor bg_color;
	QColor fg_color;
	if (m_params.alignment().isNull()) {
		// "Align with other pages" is turned off.
		// Different color is useful on a thumbnail list to
		// distinguish "safe" pages from potentially problematic ones.
		bg_color = QColor(0x58, 0x7f, 0xf4, 70);
		fg_color = QColor(0x00, 0x52, 0xff);
	} else {
		bg_color = QColor(0xbb, 0x00, 0xff, 40);
		fg_color = QColor(0xbe, 0x5b, 0xec);
	}

	// Draw margins.
	painter.fillPath(outer_outline.subtracted(content_outline), bg_color);
	
	QPen pen(fg_color);
	pen.setCosmetic(true);
	pen.setWidthF(1.0);
	painter.setPen(pen);
	painter.setBrush(Qt::NoBrush);
	
	// toRect() is necessary because we turn off antialiasing.
	// For some reason, if we let Qt round the coordinates,
	// the result is slightly different.
	painter.drawRect(inner_rect.toRect());
}
示例#16
0
void Trace::paint_label(QPainter &p, int right, const QPoint pt)
{
    compute_text_size(p);
    const int y = get_y();

    const QRectF color_rect = get_rect("color", y, right);
    const QRectF name_rect  = get_rect("name",  y, right);
    const QRectF label_rect = get_rect("label", get_zeroPos(), right);

    p.setRenderHint(QPainter::Antialiasing);
    // Paint the ColorButton
    p.setPen(Qt::transparent);
    p.setBrush(enabled() ? _colour : dsDisable);
    p.drawRect(color_rect);

    // Paint the signal name
    p.setPen(enabled() ? Qt::black : dsDisable);
    p.drawText(name_rect, Qt::AlignLeft | Qt::AlignVCenter, _name);

    // Paint the trigButton
    paint_type_options(p, right, pt);

    // Paint the label
    if (enabled()) {
        const QPointF points[] = {
            label_rect.topLeft(),
            label_rect.topRight(),
            QPointF(right, get_zeroPos()),
            label_rect.bottomRight(),
            label_rect.bottomLeft()
        };

        p.setPen(Qt::transparent);
        if (_type == SR_CHANNEL_DSO)
            p.setBrush((label_rect.contains(pt) || selected()) ? _colour.darker() : _colour);
        else
            p.setBrush((label_rect.contains(pt) || selected()) ? dsYellow : dsBlue);
        p.drawPolygon(points, countof(points));

        p.setPen(QPen(Qt::blue, 1, Qt::DotLine));
        p.setBrush(Qt::transparent);
        p.drawLine(label_rect.right(), label_rect.top() + 3,
                    label_rect.right(), label_rect.bottom() - 3);

        // Paint the text
        p.setPen(Qt::white);
        if (_type == SR_CHANNEL_GROUP)
            p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, "G");
        else if (_type == SR_CHANNEL_ANALOG)
            p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, "A");
        else if (_type == SR_CHANNEL_DECODER)
            p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, "D");
        else
            p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, QString::number(_index_list.front()));
    }
}
示例#17
0
void Interface::DisegnaRect( QPoint topLeft ,  QPoint bottomRight )
{
                 Top_startX = QMIN(topLeft.x(), bottomRight.x());
                 Top_startY = QMIN(topLeft.y(), bottomRight.y()) ;
      
                 int Bot_endX = QMAX(topLeft.x(), bottomRight.x());
                 int Bot_endY = QMAX(topLeft.y(), bottomRight.y());
    
    
      QPoint topLefta( Top_startX , Top_startY );
      QPoint bottomRighta( Bot_endX , Bot_endY );  
      QRect areaplace( topLefta, bottomRighta );
    
      /*
      
      */
    
                TagliaPoi = areaplace;
                
                 /////////////////qDebug() << "####### TagliaPoi.width()  " << TagliaPoi.height(); 
    
                if (areaplace.width() > 9 ) {
                TagliaPoi = areaplace;
                QPen pen;
                pen.setStyle( Qt::SolidLine );
                    
                pen.setWidth( 2 );
                if (ratio > 80 && ratio < 110) {                    
                pen.setWidth( 2 );
                } 
                if (ratio < 81) {
                pen.setWidth( 4 ); 
                }
                if (ratio < 50) {
                pen.setWidth( 6 ); 
                }
                if (ratio > 130) {
                pen.setWidth( 1 ); 
                }
           
                pen.setColor( color1 );
                QPixmap nuovo(original2.width(),original2.height());
                QPainter painter;
                painter.begin(&nuovo); 
                painter.setRenderHint(QPainter::Antialiasing);
                painter.drawPixmap(0,0,original2);
                painter.setPen( pen);    /* penna */
                painter.drawRect(areaplace);  /* disegna */
                painter.end();  
                display = nuovo;
                int newlarge = (original2.width()/cento)*ratio;
                wrapper->paint(QPixmap(display.scaledToWidth(newlarge,Qt::FastTransformation)));
                setCursor(Qt::CrossCursor);
                UpdateNow();
                }
}
示例#18
0
//Copied from QgsDecorationNorthArrowDialog adapted to be portable
void QgsCompassPluginGui::rotatePixmap( QLabel * pixmapLabel, QString myFileNameQString, int theRotationInt )
{
  QPixmap myQPixmap;
  if ( myQPixmap.load( myFileNameQString ) )
  {
    QPixmap  myPainterPixmap( myQPixmap.height(), myQPixmap.width() );
    myPainterPixmap.fill();
    QPainter myQPainter;
    myQPainter.begin( &myPainterPixmap );

    myQPainter.setRenderHint( QPainter::SmoothPixmapTransform );

    double centerXDouble = myQPixmap.width() / 2;
    double centerYDouble = myQPixmap.height() / 2;
    //save the current canvas rotation
    myQPainter.save();
    //myQPainter.translate( (int)centerXDouble, (int)centerYDouble );

    //rotate the canvas
    myQPainter.rotate( theRotationInt );
    //work out how to shift the image so that it appears in the center of the canvas
    //(x cos a + y sin a - x, -x sin a + y cos a - y)
    const double PI = 3.14159265358979323846;
    double myRadiansDouble = ( PI / 180 ) * theRotationInt;
    int xShift = static_cast<int>((
                                    ( centerXDouble * cos( myRadiansDouble ) ) +
                                    ( centerYDouble * sin( myRadiansDouble ) )
                                  ) - centerXDouble );
    int yShift = static_cast<int>((
                                    ( -centerXDouble * sin( myRadiansDouble ) ) +
                                    ( centerYDouble * cos( myRadiansDouble ) )
                                  ) - centerYDouble );

    //draw the pixmap in the proper position
    myQPainter.drawPixmap( xShift, yShift, myQPixmap );

    //unrotate the canvas again
    myQPainter.restore();
    myQPainter.end();

    pixmapLabel->setPixmap( myPainterPixmap );
  }
  else
  {
    QPixmap  myPainterPixmap( 200, 200 );
    myPainterPixmap.fill();
    QPainter myQPainter;
    myQPainter.begin( &myPainterPixmap );
    QFont myQFont( "time", 12, QFont::Bold );
    myQPainter.setFont( myQFont );
    myQPainter.setPen( Qt::red );
    myQPainter.drawText( 10, 20, tr( "Pixmap not found" ) );
    myQPainter.end();
    pixmapLabel->setPixmap( myPainterPixmap );
  }
}
QImage DlgSettingsSegments::createPreviewImage () const
{
  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsSegments::createPreviewImage";

  QImage image (IMAGE_WIDTH,
                IMAGE_HEIGHT,
                QImage::Format_RGB32);
  image.fill (Qt::white);
  QPainter painter (&image);
  painter.setRenderHint(QPainter::Antialiasing);
  painter.setPen (QPen (QBrush (Qt::black), BRUSH_WIDTH));

  int margin = IMAGE_WIDTH / 15;
  int yCenter = IMAGE_HEIGHT / 2;
  int yHeight = IMAGE_HEIGHT / 4;
  int x, y, xLast, yLast;
  bool isFirst;

  // Draw sinusoid
  isFirst = true;
  int xStart = margin, xEnd = IMAGE_WIDTH / 2 - margin;
  for (x = xStart; x < xEnd; x++) {
    double s = (double) (x - xStart) / (double) (xEnd - xStart);
    int y = yCenter - yHeight * qSin (TWOPI * s);

    if (!isFirst) {
      painter.drawLine (xLast, yLast, x, y);
    }
    isFirst = false;
    xLast = x;
    yLast = y;
  }

  // Draw triangular waveform that looks like sinusoid straightened up into line segments
  isFirst = true;
  xStart = IMAGE_WIDTH / 2 + margin, xEnd = IMAGE_WIDTH - margin;
  for (x = xStart; x < xEnd; x++) {
    double s = (double) (x - xStart) / (double) (xEnd - xStart);
    if (s <= 0.25) {
      y = yCenter - yHeight * (4.0 * s);
    } else if (s < 0.75) {
      y = yCenter - yHeight * (1.0 - 4.0 * (s - 0.25));
    } else {
      y = yCenter + yHeight * (1.0 - 4 * (s - 0.75));
    }

    if (!isFirst) {
      painter.drawLine (xLast, yLast, x, y);
    }
    isFirst = false;
    xLast = x;
    yLast = y;
  }

  return image;
}
示例#20
0
文件: image.cpp 项目: Rubusch/cpp
int main(int argc, char *argv[])
{
        // qt settings
        QApplication app( argc, argv );

        // 1) read image: init png
        QImage png_orig( "a09_gray.png" );
        QImage png = png_orig.convertToFormat( QImage::Format_RGB32 );


        // 2) preparation: set information to png
        for( int ycoord = 0; ycoord < png.height(); ++ycoord ){
                for( int xcoord = 0; xcoord < png.width(); ++xcoord ){

                        // Returns the color of the pixel at the given position.
                        int pixel = png.pixel( xcoord, ycoord );


                        //  Returns a gray value (0 to 255) from the (r, g, b) triplet.
                        //  The gray value is calculated using the formula (r * 11 + g * 16 + b * 5)/32.
                        int gray  = qGray( pixel );

                        // filter out only the white pieces
                        if( 70 > gray ){ gray = 0; }

                        // Returns the alpha component of the ARGB quadruplet rgba
                        int alpha = qAlpha( pixel );

                        // Sets the pixel index or color at the given position to index_or_rgb.
                        png.setPixel( xcoord, ycoord, qRgba( gray, gray, gray, alpha ) );
                }
        }

        // 3) init result: set up a png_new by png data
        QPixmap png_new( png.width(), png.height() );
        png_new.fill();


        // 4) operation: write png_new
        QPainter painter;
        // init painter with png_new (where the result will be)
        painter.begin( &png_new );
        // can be set also - the render hint for the painter
        painter.setRenderHint( QPainter::Antialiasing );
        painter.drawImage( 0, 0, png );
        painter.end();

        // 6) save
        png_new.save( "a09_threshold_white.png" );

        // 5) display image
        QLabel *label = new QLabel();
        label->setPixmap( png_new );
        label->show();
        return app.exec();
};
示例#21
0
//==============================================================
//  Функция вызывается при перерисовке
//==============================================================
void FormAnimation::paintEvent(QPaintEvent*)
{
    QPainter painter {this};

    painter.setRenderHint(QPainter::SmoothPixmapTransform);

    drawTimeScale(&painter);
    drawFrames(&painter);
    drawCurrentFrame(&painter);
}
PassOwnPtr<GraphicsContext> ShareableBitmap::createGraphicsContext()
{
    // FIXME: Should this be OwnPtr<QImage>?
    QImage* image = new QImage(createQImage());
    QPainter* painter = new QPainter(image);
    painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
    OwnPtr<GraphicsContext> context = adoptPtr(new GraphicsContext(painter));
    context->takeOwnershipOfPlatformContext();
    return context.release();
}
示例#23
0
//void Object::paintImage(QPainter &painter, int frameNumber, const QRectF &source, const QRectF &target, bool background, qreal curveOpacity, bool antialiasing, bool niceGradients) {
void Object::paintImage(QPainter &painter, int frameNumber, bool background, qreal curveOpacity, bool antialiasing, int gradients) {
	painter.setRenderHint(QPainter::Antialiasing, true);
	painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
	
	//painter.setWorldMatrix(matrix);
	painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
	
	// paints the background
	if(background) {
		painter.setPen(Qt::NoPen);
		painter.setBrush(Qt::white);
		painter.setWorldMatrixEnabled(false);
		painter.drawRect( QRect(0,0, painter.device()->width(), painter.device()->height() ) );
		painter.setWorldMatrixEnabled(true);
	}
	
	for(int i=0; i < getLayerCount(); i++) {
		Layer* layer = getLayer(i);
		if(layer->visible) {
			painter.setOpacity(1.0);
			
			// paints the bitmap images
			if(layer->type == Layer::BITMAP) {
				LayerBitmap* layerBitmap = (LayerBitmap*)layer;
				/*BitmapImage* bitmapImage = layerBitmap->getLastBitmapImageAtFrame(frameNumber, 0);
				// TO BE FIXED
				if(bitmapImage != NULL) {
					if( mirror) {
						painter.drawImage(target, (*(bitmapImage->image)).mirrored(true, false), source);
					} else {
						painter.drawImage(target, *(bitmapImage->image), source);
					}
				}*/
				layerBitmap->getLastBitmapImageAtFrame(frameNumber, 0)->paintImage(painter);
			}
			// paints the vector images
			if(layer->type == Layer::VECTOR) {
				LayerVector* layerVector = (LayerVector*)layer;
				layerVector->getLastVectorImageAtFrame(frameNumber, 0)->paintImage(painter, false, false, curveOpacity, antialiasing, gradients);
			}
		}
	}
}
示例#24
0
void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
{
  QPainter* p = context.renderContext().painter();
  if ( !p )
  {
    return;
  }

  //size scaling by field
  if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale )
  {
    applySizeScale( context, mPen, mSelPen );
  }

  double offset = mOffset;
  applyDataDefinedSymbology( context, mPen, mSelPen, offset );

  p->setPen( context.selected() ? mSelPen : mPen );

  // Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #2 points).
  if ( points.size() <= 2 &&
       ( context.renderContext().vectorSimplifyMethod().simplifyHints() & QgsVectorSimplifyMethod::AntialiasingSimplification ) &&
       QgsAbstractGeometrySimplifier::isGeneralizableByDeviceBoundingBox( points, context.renderContext().vectorSimplifyMethod().threshold() ) &&
       ( p->renderHints() & QPainter::Antialiasing ) )
  {
    p->setRenderHint( QPainter::Antialiasing, false );
    p->drawPolyline( points );
    p->setRenderHint( QPainter::Antialiasing, true );
    return;
  }

  if ( qgsDoubleNear( offset, 0 ) )
  {
    p->drawPolyline( points );
  }
  else
  {
    double scaledOffset = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), offset, mOffsetUnit, mOffsetMapUnitScale );
    QList<QPolygonF> mline = ::offsetLine( points, scaledOffset, context.feature() ? context.feature()->constGeometry()->type() : QGis::Line );
    for ( int part = 0; part < mline.count(); ++part )
      p->drawPolyline( mline[ part ] );
  }
}
示例#25
0
void KWCanvasBase::paintGrid(QPainter &painter, KWViewMode::ViewMap &vm)
{
    painter.save();
    painter.translate(-vm.distance.x(), -vm.distance.y());
    painter.setRenderHint(QPainter::Antialiasing, false);
    const QRectF clipRect = viewConverter()->viewToDocument(vm.clipRect);
    document()->gridData().paintGrid(painter, *(viewConverter()), clipRect);
    document()->guidesData().paintGuides(painter, *(viewConverter()), clipRect);
    painter.restore();
}
示例#26
0
 virtual void draw(QPainter &painter, bool /*enabled*/)
 {
     int height       = drawingArea().height()-1;
     int top          = height * m_verticalPadding;
     int handleHeight = height - 2*top;
     painter.setRenderHint(QPainter::Antialiasing);
     painter.setPen(m_pen);
     painter.setBrush(m_brush);
     painter.drawRect(m_pos - halfWidth(), top, m_width, handleHeight);
 }
示例#27
0
//--------------------------------------------------------------------------------------------------
void repere::Save(QString nom)
{
    QImage *image = new QImage(QSize(400,400),QImage::Format_ARGB32);
    image->fill(QColor(Qt::white).rgb());
    QPainter *pngPainter = new QPainter(image);
    pngPainter->setRenderHint(QPainter::Antialiasing);
    Scene->render(pngPainter);
    pngPainter->end();
    image->save(nom+".png","PNG",100);
}
示例#28
0
void
PictureZoneEditor::paintOverPictureMask(QPainter& painter)
{
	painter.setRenderHint(QPainter::Antialiasing);
	painter.setTransform(imageToVirtual() * virtualToWidget(), true);
	painter.setPen(Qt::NoPen);
	painter.setBrush(QColor(mask_color));

#ifndef Q_WS_X11
	// That's how it's supposed to be.
	painter.setCompositionMode(QPainter::CompositionMode_Clear);
#else
	// QPainter::CompositionMode_Clear doesn't work for arbitrarily shaped
	// objects on X11, as well as CompositionMode_Source with a transparent
	// brush.  Fortunately, CompositionMode_DestinationOut with a non-transparent
	// brush does actually work.
	painter.setCompositionMode(QPainter::CompositionMode_DestinationOut);
#endif

	typedef PictureLayerProperty PLP;

	// First pass: ERASER1
	BOOST_FOREACH(EditableZoneSet::Zone const& zone, m_zones) {
		if (zone.properties()->locateOrDefault<PLP>()->layer() == PLP::ERASER1) {
			painter.drawPolygon(zone.spline()->toPolygon(), Qt::WindingFill);
		}
	}

	painter.setCompositionMode(QPainter::CompositionMode_SourceOver);

	// Second pass: PAINTER2
	BOOST_FOREACH (EditableZoneSet::Zone const& zone, m_zones) {
		if (zone.properties()->locateOrDefault<PLP>()->layer() == PLP::PAINTER2) {
			painter.drawPolygon(zone.spline()->toPolygon(), Qt::WindingFill);
		}
	}

#ifndef Q_WS_X11
	// That's how it's supposed to be.
	painter.setCompositionMode(QPainter::CompositionMode_Clear);
#else
	// QPainter::CompositionMode_Clear doesn't work for arbitrarily shaped
	// objects on X11, as well as CompositionMode_Source with a transparent
	// brush.  Fortunately, CompositionMode_DestinationOut with a non-transparent
	// brush does actually work.
	painter.setCompositionMode(QPainter::CompositionMode_DestinationOut);
#endif

	// Third pass: ERASER1
	BOOST_FOREACH (EditableZoneSet::Zone const& zone, m_zones) {
		if (zone.properties()->locateOrDefault<PLP>()->layer() == PLP::ERASER3) {
			painter.drawPolygon(zone.spline()->toPolygon(), Qt::WindingFill);
		}
	}
}
示例#29
0
void CommandPanel::drawPanel(QPainter& painter, const QRect& clipRect)
{
   QColor textColor = palette().color(QPalette::Text);
   QColor backgroundColor = palette().color(QPalette::Background);
   QColor disabledTextColor = blendColor(textColor, backgroundColor);
   //
   painter.setRenderHint(QPainter::TextAntialiasing);
   //
   painter.setPen(Qt::NoPen);
   painter.setBrush(backgroundColor);
   painter.drawRect(clipRect);
   //
   painter.setFont(font());
   painter.setPen(textColor);
   painter.setBackgroundMode(Qt::OpaqueMode);
   painter.setBackground(backgroundColor);
   //
   std::list<CommandOption>::const_iterator it = options_.items().begin(), itEnd = options_.items().end();
   for(int i=0;it!=itEnd;++it, ++i)
   {
      assert(i<(int)rects_.size());
      //
      QRect rect(rects_[i]);
      QRect textRect(rect);
      textRect.setBottom(textRect.bottom()-cUnderlineHeight);
      //
      if(!rect.intersects(clipRect)) continue;
      //
      if(i==pressedIndex_)
      {
         painter.setPen(backgroundColor);
         painter.setBackground(textColor);
         painter.drawText(textRect, Qt::AlignHCenter, it->text());
      }
      else if(enabled_[i])
      {
         painter.setPen(textColor);
         //
         QRect underlineRect(rect.left(), rect.bottom()-cUnderlineHeight,
                             rect.width()-1, cUnderlineHeight);
         if(i==highlightedIndex_ && showHighlight_)
         {
            painter.setBrush(textColor);
            painter.drawRect(underlineRect);
         }
         //
         painter.drawText(textRect, Qt::AlignCenter, it->text());
      }
      else
      {
         painter.setPen(disabledTextColor);
         painter.drawText(textRect, Qt::AlignCenter, it->text());
      }
   }
}
void KisVisualEllipticalSelectorShape::drawCursor()
{
    //qDebug() << this << "KisVisualEllipticalSelectorShape::drawCursor: image needs update" << imagesNeedUpdate();
    QPointF cursorPoint = convertShapeCoordinateToWidgetCoordinate(getCursorPosition());
    QImage fullSelector = getImageMap();
    QColor col = getColorFromConverter(getCurrentColor());
    QPainter painter;
    painter.begin(&fullSelector);
    painter.setRenderHint(QPainter::Antialiasing);
    QRect innerRect(m_barWidth, m_barWidth, width()-(m_barWidth*2), height()-(m_barWidth*2));

    painter.save();
    painter.setCompositionMode(QPainter::CompositionMode_Clear);
    QPen pen;
    pen.setWidth(5);
    painter.setPen(pen);
    painter.drawEllipse(QRect(0,0,width(),height()));

    if (getDimensions()==KisVisualColorSelectorShape::onedimensional) {
        painter.setBrush(Qt::SolidPattern);
        painter.drawEllipse(innerRect);
    }
    painter.restore();

    QBrush fill;
    fill.setStyle(Qt::SolidPattern);

    int cursorwidth = 5;

    if (m_type==KisVisualEllipticalSelectorShape::borderMirrored) {
        painter.setPen(Qt::white);
        fill.setColor(Qt::white);
        painter.setBrush(fill);
        painter.drawEllipse(cursorPoint, cursorwidth, cursorwidth);
        QPoint mirror(innerRect.center().x()+(innerRect.center().x()-cursorPoint.x()),cursorPoint.y());
        painter.drawEllipse(mirror, cursorwidth, cursorwidth);
        fill.setColor(col);
        painter.setPen(Qt::black);
        painter.setBrush(fill);
        painter.drawEllipse(cursorPoint, cursorwidth-1, cursorwidth-1);
        painter.drawEllipse(mirror, cursorwidth-1, cursorwidth-1);

    } else {
        painter.setPen(Qt::white);
        fill.setColor(Qt::white);
        painter.setBrush(fill);
        painter.drawEllipse(cursorPoint, cursorwidth, cursorwidth);
        fill.setColor(col);
        painter.setPen(Qt::black);
        painter.setBrush(fill);
        painter.drawEllipse(cursorPoint, cursorwidth-1.0, cursorwidth-1.0);
    }
    painter.end();
    setFullImage(fullSelector);
}