Ejemplo n.º 1
0
void QQuickContext2DTexture::paintWithoutTiles(QQuickContext2DCommandBuffer *ccb)
{
    if (!ccb || ccb->isEmpty())
        return;

    QPaintDevice* device = beginPainting();
    if (!device) {
        endPainting();
        return;
    }

    QPainter p;
    p.begin(device);
    if (m_antialiasing)
        p.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing, true);
    else
        p.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing, false);

    if (m_smooth)
        p.setRenderHint(QPainter::SmoothPixmapTransform, true);
    else
        p.setRenderHint(QPainter::SmoothPixmapTransform, false);

    p.setCompositionMode(QPainter::CompositionMode_SourceOver);

    ccb->replay(&p, m_state, scaleFactor());
    endPainting();
    markDirtyTexture();
}
Ejemplo n.º 2
0
void Plotter::drawCurves(QPainter& painter)
{
    noOfCurves = curveDataMap.count();
    QRect rect = this->printRect();
    double x=0,y=0;
    double width = rect.width() - 1;
    double height = rect.height() - 1;
    double yCount = maxY - minY;
    if(antiAliasing)
        painter.setRenderHints(QPainter::Antialiasing);
    painter.translate(Margin + 1,rect.bottom()-1);
    for(int i=0; i < noOfCurves ; i++)
    {
        QPolygonF polyline;
        QVector<double>* dataPtr = curveDataMap[i] ;
        for(int j = 0 ; j <= noOfPoints ; j++)
        {
            x = (width * j)/noOfPoints;
            y = (height * dataPtr->value(j))/yCount;
            polyline << QPoint(x,-y);
            //qDebug() << y;
        }
        qDebug() << x <<rect.right();
        painter.setPen(colorMap.value(i));
        painter.drawPolyline(polyline);

    }
}
Ejemplo n.º 3
0
void UIButton::paintEvent(QPaintEvent *event) {
  QPainter context;
  context.begin(this);


  QRect rect = contentsRect();

  rect.setX((contentsRect().width() - 128) / 2);
  rect.setY((contentsRect().height() - 128) / 2);
  rect.setWidth(128.0);
  rect.setHeight(128.0);

  if (isChecked()) {
    //rect = rect.adjusted(1, 1, -1, -1);
  }

  context.save();
  context.setRenderHints(QPainter::HighQualityAntialiasing |
                     QPainter::SmoothPixmapTransform |
                     QPainter::Antialiasing
                     );

  context.drawPixmap(rect,
                 ctx->m_icon_dict[ctx->m_current_action].pixmap(256, 256,
                 isEnabled() ? QIcon::Normal : QIcon::Disabled,
                 isChecked() ? QIcon::On : QIcon::Off));
  context.restore();
  context.end();
}
Ejemplo n.º 4
0
void CanvasRenderer::paintGrid( QPainter& painter )
{
    int gridSize = mOptions.nGridSize;

    QRectF rect = painter.viewport();
    QRectF boundingRect = mViewTransform.inverted().mapRect( rect );
    int w = boundingRect.width();
    int h = boundingRect.height();

    //qDebug() << mViewTransform;
    //qDebug() << mViewTransform.inverted();

    int left = round100( boundingRect.left(), gridSize ) - gridSize;
    int right = round100( boundingRect.right(), gridSize ) + gridSize;
    int top = round100( boundingRect.top(), gridSize ) - gridSize;
    int bottom = round100( boundingRect.bottom(), gridSize ) + gridSize;
    
    QPen pen( Qt::lightGray );
    pen.setCosmetic( true );
    painter.setPen( pen );
    painter.setWorldMatrixEnabled( true );
    painter.setBrush( Qt::NoBrush );
    QPainter::RenderHints previous_renderhints = painter.renderHints();
    painter.setRenderHint( QPainter::Antialiasing, false );
    for ( int x = left; x < right; x += gridSize )
    {
        painter.drawLine( x, top, x, bottom );
    }

    for ( int y = top; y < bottom; y += gridSize )
    {
        painter.drawLine( left, y, right, y );
    }
    painter.setRenderHints(previous_renderhints);
}
Ejemplo n.º 5
0
void FreeRegionGrabber::grabRect()
{
    QPolygon pol = selection;
    if ( !pol.isEmpty() )
    {
	grabbing = true;

        int xOffset = pixmap.rect().x() - pol.boundingRect().x();
        int yOffset = pixmap.rect().y() - pol.boundingRect().y();
        QPolygon translatedPol = pol.translated(xOffset, yOffset);

        QPixmap pixmap2(pol.boundingRect().size());
        pixmap2.fill(Qt::transparent);

        QPainter pt;
        pt.begin(&pixmap2);
        if (pt.paintEngine()->hasFeature(QPaintEngine::PorterDuff)) {
            pt.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform, true);
            pt.setBrush(Qt::black);
            pt.setPen(QPen(QBrush(Qt::black), 0.5));
            pt.drawPolygon(translatedPol);
            pt.setCompositionMode(QPainter::CompositionMode_SourceIn);
        } else {
            pt.setClipRegion(QRegion(translatedPol));
            pt.setCompositionMode(QPainter::CompositionMode_Source);
        }

        pt.drawPixmap(pixmap2.rect(), pixmap, pol.boundingRect());
        pt.end();

        emit freeRegionUpdated(pol);
        emit freeRegionGrabbed(pixmap2);
    }
}
Ejemplo n.º 6
0
// ********************************************************
ImageBufferData::ImageBufferData(const IntSize& size, bool accelerated)
{
    QPainter* painter = new QPainter;
    m_painter = adoptPtr(painter);

#if ENABLE(ACCELERATED_2D_CANVAS)
    if (accelerated) {
        m_impl = adoptPtr(new ImageBufferDataPrivateAccelerated(size));
    } else
#endif
        m_impl = adoptPtr(new ImageBufferDataPrivateUnaccelerated(size));

    if (!m_impl->paintDevice())
        return;
    if (!painter->begin(m_impl->paintDevice()))
        return;

    painter->setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing);
    QPen pen = painter->pen();
    pen.setColor(Qt::black);
    pen.setWidth(1);
    pen.setCapStyle(Qt::FlatCap);
    pen.setJoinStyle(Qt::SvgMiterJoin);
    pen.setMiterLimit(10);
    painter->setPen(pen);
    QBrush brush = painter->brush();
    brush.setColor(Qt::black);
    painter->setBrush(brush);
    painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
}
Ejemplo n.º 7
0
void My_Painter::drawCoordinates(QPainter &painter)
 {

     painter.setPen(QPen(Qt::black, 4, Qt::SolidLine));
     painter.setRenderHints(QPainter::Antialiasing, true);
     painter.drawPoint(10, 200);

     painter.setPen(Qt::black);

     painter.drawText(2 - xBoundingRect.width() / 2,
                      203 + xBoundingRect.height() / 2, tr("0") );

//---------------| t |------------------------------------------
     painter.drawLine(10, 10, 10, 200);
     painter.drawLine(10, 10, 15, 15);
     painter.drawLine(10, 10, 5, 15);
     painter.drawText( 2 - xBoundingRect.width() / 2,
                       5 + xBoundingRect.height() / 2, tr("t") );
//--------------------------------------------------------------

//---------------| n |------------------------------------------
     painter.drawLine(10, 200, 320, 200);
     painter.drawLine(320, 200, 315, 195);
     painter.drawLine(320, 200, 315, 205);
     painter.drawText(326 - yBoundingRect.width() / 2,
                      201 + yBoundingRect.height() / 2, tr("n"));
//--------------------------------------------------------------
 }
Ejemplo n.º 8
0
			void PiecesWidget::paintEvent (QPaintEvent *e)
			{
				int s = Pieces_.size ();
				QPainter painter (this);
				painter.setRenderHints (QPainter::Antialiasing |
						QPainter::SmoothPixmapTransform);
				if (!s)
				{
					painter.setBackgroundMode (Qt::OpaqueMode);
					painter.setBackground (Qt::white);
					painter.end ();
					return;
				}
			
				QPixmap tempPicture (s, 1);
				QPainter tempPainter (&tempPicture);
				tempPainter.setPen (Qt::red);
				tempPainter.drawLine (0, 0, s, 0);
				QList<QPair<int, int> > trues = FindTrues (Pieces_);
				for (int i = 0; i < trues.size (); ++i)
				{
					QPair<int, int> pair = trues.at (i);
			
					tempPainter.setPen (Qt::darkGreen);
					tempPainter.drawLine (pair.first, 0, pair.second, 0);
				}
				tempPainter.end ();
			
				painter.drawPixmap (QRect (0, 0, width (), height ()), tempPicture);
				painter.end ();
			
				e->accept ();
			}
Ejemplo n.º 9
0
void KarbonCalligraphyTool::paint(QPainter &painter, const KoViewConverter &converter)
{
    if (m_selectedPath) {
        painter.save();
        painter.setRenderHints(QPainter::Antialiasing, false);
        painter.setPen(Qt::red);   // TODO make configurable
        QRectF rect = m_selectedPath->boundingRect();
        QPointF p1 = converter.documentToView(rect.topLeft());
        QPointF p2 = converter.documentToView(rect.bottomRight());
        painter.drawRect(QRectF(p1, p2));
        painter.restore();
    }

    if (!m_shape) {
        return;
    }

    painter.save();

    painter.setTransform(m_shape->absoluteTransformation(&converter) *
                         painter.transform());
    KoShapePaintingContext paintContext; //FIXME
    m_shape->paint(painter, converter, paintContext);

    painter.restore();
}
Ejemplo n.º 10
0
void LinearChart::paintChart( QPainter& painter ) {

      painter.setRenderHints( QPainter::Antialiasing | QPainter::TextAntialiasing );
      this->paintAxis(painter);
      QList<int> orderedColumns = this->calculateColumnsOrder();
      foreach( int c, orderedColumns ) {
        this->paintValues( painter, c );
      }
void QSGPainterNode::paint()
{
    QRect dirtyRect = m_dirtyRect.isNull() ? QRect(0, 0, m_size.width(), m_size.height()) : m_dirtyRect;

    QPainter painter;
    if (m_actualRenderTarget == QQuickPaintedItem::Image) {
        if (m_image.isNull())
            return;
        painter.begin(&m_image);
    } else {
        if (!m_gl_device) {
            m_gl_device = new QOpenGLPaintDevice(m_fboSize);
            m_gl_device->setPaintFlipped(true);
        }

        if (m_multisampledFbo)
            m_multisampledFbo->bind();
        else
            m_fbo->bind();

        painter.begin(m_gl_device);
    }

    if (m_smoothPainting) {
        painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
    }

    painter.scale(m_contentsScale, m_contentsScale);

    QRect sclip(qFloor(dirtyRect.x()/m_contentsScale),
                qFloor(dirtyRect.y()/m_contentsScale),
                qCeil(dirtyRect.width()/m_contentsScale+dirtyRect.x()/m_contentsScale-qFloor(dirtyRect.x()/m_contentsScale)),
                qCeil(dirtyRect.height()/m_contentsScale+dirtyRect.y()/m_contentsScale-qFloor(dirtyRect.y()/m_contentsScale)));

    if (!m_dirtyRect.isNull())
        painter.setClipRect(sclip);

    painter.setCompositionMode(QPainter::CompositionMode_Source);
    painter.fillRect(sclip, m_fillColor);
    painter.setCompositionMode(QPainter::CompositionMode_SourceOver);

    m_item->paint(&painter);
    painter.end();

    if (m_actualRenderTarget == QQuickPaintedItem::Image) {
        m_texture->setImage(m_image);
        m_texture->setDirtyRect(dirtyRect);
    } else if (m_multisampledFbo) {
        QOpenGLFramebufferObject::blitFramebuffer(m_fbo, dirtyRect, m_multisampledFbo, dirtyRect);
    }

    if (m_multisampledFbo)
        m_multisampledFbo->release();
    else if (m_fbo)
        m_fbo->release();

    m_dirtyRect = QRect();
}
void ConnectionStatusWidget::paintEvent(QPaintEvent *){
  QPainter myPainter;
  myPainter.begin(this);
  myPainter.setRenderHints(QPainter::Antialiasing);
  myPainter.setBrush(diodeColor);
  int radious = qMin(height(), width())/2 -1;
  if(radious<1 )
    radious = 1;
  myPainter.drawEllipse(QPoint(width()/2,height()/2),radious,radious);
}
Ejemplo n.º 13
0
void GLC_Viewport::renderText(const GLC_Point3d& point, const QString &text, const QColor &color, const QFont &font)
{
    m_TextRenderingCollection.clear();
    if (!text.isEmpty())
    {
        QFontMetrics fontMetrics(font);
        const double width= fontMetrics.width(text);
        const double height= fontMetrics.height();

        // Compute the ratio betwwen screen and world
        const GLC_Matrix4x4 invertedViewMatrix(GLC_Context::current()->modelViewMatrix().rotationMatrix().invert());
        const GLC_Vector2d projectedPoint1(project(point, false));
        const GLC_Vector3d vector(invertedViewMatrix * GLC_Vector3d(0.0, height, 0.0));
        const GLC_Vector2d projectedPoint2(project((point + vector), false));
        const double ratio= height / (projectedPoint2 - projectedPoint1).length();

        QPixmap pixmap(width, height);
        pixmap.fill(Qt::transparent);
        QPainter painter;

        painter.begin(&pixmap);
        painter.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing);
        painter.setFont(font);
        painter.setPen(color);
        painter.drawText(0, fontMetrics.ascent(), text);
        painter.end();

        QImage image= pixmap.toImage();

        GLC_Texture *pTexture= new GLC_Texture(image);
        GLC_Material* pMaterial= new GLC_Material(Qt::black);
        pMaterial->setTexture(pTexture);
        pMaterial->setOpacity(0.99);

        GLC_3DViewInstance rectangle= GLC_Factory::instance()->createRectangle(width, height);

        GLC_Matrix4x4 scaleMatrix;
        scaleMatrix.setMatScaling(ratio, ratio, ratio);
        rectangle.setMatrix(scaleMatrix);
        rectangle.multMatrix(invertedViewMatrix);
        rectangle.multMatrix(GLC_Matrix4x4(point));
        rectangle.geomAt(0)->addMaterial(pMaterial);
        m_TextRenderingCollection.add(rectangle);

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
        glDisable(GL_DEPTH_TEST);
        m_TextRenderingCollection.render(0, glc::TransparentRenderFlag);
        glEnable(GL_DEPTH_TEST);
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        m_TextRenderingCollection.clear();
    }
}
Ejemplo n.º 14
0
void KateRenderer::paintIndentMarker(QPainter &paint, uint x, uint y /*row*/)
{
  QPen penBackup( paint.pen() );
  QPen myPen(config()->indentationLineColor());
  static const QVector<qreal> dashPattern = QVector<qreal>() << 1 << 1;
  myPen.setDashPattern(dashPattern);
  if (y % 2)
    myPen.setDashOffset(1);
  paint.setPen(myPen);

  const int height = fontHeight();
  const int top = 0;
  const int bottom = height-1;

  QPainter::RenderHints renderHints = paint.renderHints();
  paint.setRenderHints(renderHints, false);

  paint.drawLine(x + 2, top, x + 2, bottom);

  paint.setRenderHints(renderHints, true);

  paint.setPen( penBackup );
}
Ejemplo n.º 15
0
void MeshWidgetChart::paintEvent(QPaintEvent* event)
{
    QWidget::paintEvent(event);
    QPainter painter;

    painter.begin(this);

    setFont(font());
    painter.setRenderHints(QPainter::TextAntialiasing);
    painter.drawText(m_titleRect, Qt::AlignCenter, m_title);

    ChartItemList items = m_topItem.items();
    double maxVal = 0;
    foreach (MeshChartItem* item, items) { maxVal = std::max(maxVal, item->value()); }
Ejemplo n.º 16
0
void PHISurfaceEffect::draw( QPainter *painter )
{
    /*
    QPoint offset;
    QPixmap pixmap;
    if ( sourceIsPixmap() ) {
    // No point in drawing in device coordinates (pixmap will be scaled anyways).
        pixmap=sourcePixmap( Qt::LogicalCoordinates, &offset );
    } else {
    // Draw pixmap in device coordinates to avoid pixmap scaling;
        pixmap=sourcePixmap( Qt::DeviceCoordinates, &offset );
        painter->setWorldTransform( QTransform() );
    }

    QImage img=pixmap.toImage();
    img=PHI::getSurfacedImage( img, _yOff, _size );
    painter->drawImage( offset, img );
*/
    QRectF brect=sourceBoundingRect( Qt::LogicalCoordinates );
    QImage img( static_cast<int>(brect.width()+1), static_cast<int>(brect.height()+_size+_yOff),
        QImage::Format_ARGB32_Premultiplied );
    QPainter pixPainter;
    pixPainter.begin( &img );

    pixPainter.setRenderHints( painter->renderHints() );
    pixPainter.setCompositionMode( QPainter::CompositionMode_Clear );
    pixPainter.fillRect( 0., 0., brect.width()+1., brect.height()+_size+_yOff+1, Qt::transparent );
    pixPainter.setCompositionMode( QPainter::CompositionMode_SourceOver );
    drawSource( &pixPainter );

    QTransform t;
    t.rotate( 180., Qt::XAxis );
    t.translate( 0., (-brect.height()*2.)-_yOff+1. );
    pixPainter.setTransform( t );
    drawSource( &pixPainter );

    pixPainter.resetTransform();
    pixPainter.translate( 0., brect.height()+_yOff );
    QLinearGradient gradient( 0., 0., 0., 1.0 );
    gradient.setColorAt( 0., QColor( 0, 0, 0, 220 ) );
    gradient.setColorAt( 0.78, QColor( 0, 0, 0, 30 ) );
    gradient.setColorAt( 1., Qt::transparent );
    gradient.setCoordinateMode( QGradient::ObjectBoundingMode );

    pixPainter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
    pixPainter.fillRect( 0., 0., brect.width()+1, _size, gradient );
    pixPainter.end();
    painter->drawImage( 0, 0, img );
}
Ejemplo n.º 17
0
void PanWidget::
paintEvent ( QPaintEvent * event )
{
    QPainter painter (this);
    painter.setRenderHints (QPainter::Antialiasing | QPainter::HighQualityAntialiasing);
    painter.fillPath (path_, QColor(220,220,220,200));
    painter.strokePath (path_, QPen(
                            QColor(100,100,100,200),
                            hasFocus () ? 1.6 : .8,
                            Qt::SolidLine,
                            Qt::RoundCap,
                            Qt::RoundJoin));

    QWidget::paintEvent(event);
}
Ejemplo n.º 18
0
void AnchorGraph::paint_( QPainter &painter )
{
    QBrush brush( Qt::lightGray );
    painter.setRenderHints( QPainter::Antialiasing | QPainter::HighQualityAntialiasing );
    painter.setPen( Qt::lightGray );
    painter.setBrush( brush );

    const FloatVector& tfData = transferFunctionPtr_->getData( );
    for ( uint32_t i = 0; i < transferFunctionPtr_->getNumChannels( ); ++i )
    {
        painter.setPen( colors_[ i ] );
        paintCurve_( painter, static_cast< ColorChannel >( i ), tfData.size( ) / transferFunctionPtr_->getNumChannels( ) );
        paintAnchors_( painter, static_cast< ColorChannel >( i ) );
    }
}
Ejemplo n.º 19
0
void QvkWidgetcircle::paintEvent( QPaintEvent *event )
{
  (void)event;

  QRegion RegionWidget( 0, 0, width(), height() );
  QRegion RegionPaint( 0, 0, width(), height(), QRegion::Ellipse );
#ifdef QT4
  QRegion RegionSpace = RegionWidget.subtract( RegionPaint );
  QRegion RegionPaintWidget = RegionWidget.subtract( RegionSpace );
#endif
#ifdef QT5
  QRegion RegionSpace = RegionWidget.subtracted( RegionPaint );
  QRegion RegionPaintWidget = RegionWidget.subtracted( RegionSpace );
#endif  
  setMask(RegionPaintWidget);

  QPainter painter;;
  painter.begin( this );
    painter.setRenderHints( QPainter::Antialiasing, true );
    QBrush brush( widgetColor, Qt::SolidPattern );
    painter.setBrush( brush );
    painter.setPen( widgetColor );  
    painter.drawEllipse ( QPoint( width()/2, height()/2), width()/2-1, height()/2-1 );
    
    if ( set == false )
    {
      QBrush brush_1( Qt::white, Qt::SolidPattern );
      painter.setBrush( brush_1 );
      painter.setPen( Qt::white );  
      painter.drawEllipse ( QPoint( width()/2, height()/2), width()/5, height()/5 );
    }
    
    if ( set == true )
    {
      QBrush brush_2( Qt::white, Qt::SolidPattern );
      painter.setBrush( brush_2 );
      painter.setPen( Qt::white );  
      painter.drawEllipse ( QPoint( width()/2, height()/2), width()/5, height()/5 );
      
      QBrush brush_3( Qt::black, Qt::SolidPattern );
      painter.setBrush( brush_3 );
      painter.setPen( Qt::black );  
      painter.drawEllipse ( QPoint( width()/2, height()/2), width()/5-2, height()/5-2 );
    }


  painter.end();
}
Ejemplo n.º 20
0
void UvTemplateDialog::generateImage()
{

	QString mapName=uvMapDrop->text();

	QString fileName = QFileDialog::getSaveFileName(this, "Save UV Image Template", db->getProgramOptions()->lastSavedPathUVTemplate+"\\"+mapName,"Image (*.png)");

	if(fileName.isNull())
	{
		savedMsg->setText("Save cancelled.");
		return;
	}
	UvData uvData;

	int number=uvSizeEdit->text().toInt();
		
	QImage	img(QSize(number,number),QImage::Format_ARGB32);
	
	QColor empty(255,255,255,0);

	img.fill(empty.rgba());

	QPainter painter;

	QPalette palette = uvFColor->palette();

	painter.begin(&img);
	painter.setRenderHints (QPainter::Antialiasing,false);	
	painter.setPen(palette.color(QPalette::Button));
	

	uvData.painter=&painter;
	uvData.mainData=lwMain;

	// set the current uv map to one we will be editing
	lwMain->editOp->pointVSet(lwMain->editOp->state,0,LWVMAP_TXUV,mapName.toAscii().data());

	lwMain->editOp->polyScan( lwMain->editOp->state, (EDPolyScanFunc (__cdecl *))UvTemplateDialog::scan_poly_for_uv, &uvData, OPLYR_NONEMPTY );	

	painter.end();

	img.save (fileName, "png");
	savedMsg->setText("Template saved.");

	QFileInfo filePath(fileName);
	db->getProgramOptions()->lastSavedPathUVTemplate=filePath.path();
}
Ejemplo n.º 21
0
bool ExportWizard::printPdf()
{
    // get dpi, compute printed size
    int printDpi = m_pdfPrinter->resolution();
    QSizeF canvasPrintSize = canvasNatInches() * (qreal)printDpi;
    Qt::AspectRatioMode printAspect = Qt::KeepAspectRatio;

    // open the painter over the printer
    QPainter painter;
    if (!painter.begin(m_pdfPrinter)) {
        QMessageBox::warning(0, tr("PDF Error"), tr("Error saving to the PDF file, try to chose another one."), QMessageBox::Cancel);
        return false;
    }
    QRect paperRect = painter.viewport();
    QRect targetRect(0, 0, (int)canvasPrintSize.width(), (int)canvasPrintSize.height());

    // adapt rect Scale
    switch (m_ui->pdfScaleCombo->currentIndex()) {
    case 0:     // Original
        break;
    case 1: {   // Fit to page
        QSize targetSize = targetRect.size();
        targetSize.scale(paperRect.size(), printAspect);
        targetRect.setSize(targetSize);
        } break;
    }

    // adapt Position
    switch (m_ui->pdfPosCombo->currentIndex()) {
    case 0:     // Top Left
        targetRect.moveTopLeft(paperRect.topLeft());
        break;
    case 1:     // Center
        targetRect.moveCenter(paperRect.center());
        break;
    }

    // render to PDF
    painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, true);
    RenderOpts::PDFExporting = true;
    m_canvas->renderVisible(&painter, targetRect, m_canvas->sceneRect(), Qt::IgnoreAspectRatio, true);
    RenderOpts::PDFExporting = false;
    painter.end();
    return true;
}
Ejemplo n.º 22
0
void RescaleWidget::
        paintEvent(QPaintEvent *event)
{
    QPainter painter (this);
    painter.setRenderHints (QPainter::Antialiasing | QPainter::HighQualityAntialiasing);
    //painter.fillPath (path_, QBrush(QColor(125,125,125,125)));
    painter.fillPath (path_, QColor(220,220,220,200));
    painter.strokePath (path_, QPen(
                            QColor(100,100,100,200),
                            hasFocus () ? 1.6 : .8,
                            Qt::SolidLine,
                            Qt::RoundCap,
                            Qt::RoundJoin));

    //painter.drawImage(QPoint(),qimage_);

    QWidget::paintEvent (event);
}
Ejemplo n.º 23
0
void myGauge1::paintEvent(QPaintEvent *)
{
    QPainter painter;
    painter.begin(this);
    painter.setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);

    resetVariables(&painter);
    drawOuterCircle(&painter);
    drawInnerCircle(&painter);
    drawColorPies(&painter);
    drawGraph(&painter);
    drawCoverLines(&painter);
    drawCoverCircle(&painter);
    drawMarkAndText(&painter);

    drawTextRect(&painter);

    painter.end();
}
Ejemplo n.º 24
0
void GraphWidget::paintEvent (QPaintEvent*)
{
	quint64 max = 0;
	for (int i = 0; i < DownSpeeds_.size (); ++i)
	{
		if (DownSpeeds_.at (i) > max)
			max = DownSpeeds_.at (i);
		if (UpSpeeds_.at (i) > max)
			max = UpSpeeds_.at (i);
	}

	QPainter painter (this);
	painter.setRenderHints (QPainter::Antialiasing | QPainter::SmoothPixmapTransform);

	if (max && DownSpeeds_.size ())
	{
		painter.setPen (UpColor_);
		PaintSingle (max, UpSpeeds_, &painter);
		painter.setPen (DownColor_);
		PaintSingle (max, DownSpeeds_, &painter);
	}
}
Ejemplo n.º 25
0
void paint_QPixmapCachedRoundedRect(QPainter &p)
{
    static bool first = true;
    static QPixmap cacheRect;
    if (first) {
        const int pw = 0;
        const int radius = 8;
        cacheRect = QPixmap(radius*2 + 3 + pw*2, radius*2 + 3 + pw*2);
        cacheRect.fill(Qt::transparent);
        QPainter paint(&cacheRect);
        paint.setRenderHint(QPainter::Antialiasing);
        paint.setPen(Qt::black);
        paint.setBrush(Qt::red);
        if (pw%2)
            paint.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, cacheRect.width()-(pw+1), cacheRect.height()-(pw+1)), radius, radius);
        else
            paint.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, cacheRect.width()-pw, cacheRect.height()-pw), radius, radius);

        first = false;
    }
    for (int i = 0; i < count; i++) {
        for (int j = 0; j < lines; ++j) {
            QSize size((j+1)*50, spacing-1);

            p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, true);

            const int pw = 0;

            int xOffset = (cacheRect.width()-1)/2;
            int yOffset = (cacheRect.height()-1)/2;

            QMargins margins(xOffset, yOffset, xOffset, yOffset);
            QTileRules rules(Qt::StretchTile, Qt::StretchTile);
            //NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects
            qDrawBorderPixmap(&p, QRect(-pw/2, j*spacing-pw/2, size.width()+pw, size.height()+pw), margins, cacheRect, cacheRect.rect(), margins, rules);
        }
    }
}
Ejemplo n.º 26
0
// --------------------------------------------------------------------------------------------------------------------------------------
void CCachedGraphicsItem::updateCache()
{
    if(isActive())
    {
        QPixmap *pixmap = new QPixmap(size().toSize());
        pixmap->fill(QColor(0,0,0,0));

        QPainter *painter = new QPainter(pixmap);
        painter->setBackgroundMode(Qt::TransparentMode);
        painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing, true);
        painter->setPen(m_stdPen);
        painter->setBrush(m_stdBrush);
        painter->setFont(m_stdFont);

        paintToCache(painter);

        delete painter;
        QPixmap *tmp = m_pixmap;
        m_pixmap = pixmap;
        delete tmp;
        //update(boundingRect());
    }
}
Ejemplo n.º 27
0
			void PiecesWidget::paintEvent (QPaintEvent *e)
			{
				int s = Pieces_.size ();
				QPainter painter (this);
				painter.setRenderHints (QPainter::Antialiasing |
						QPainter::SmoothPixmapTransform);
				if (!s)
				{
					painter.setBackgroundMode (Qt::OpaqueMode);
					painter.setBackground (Qt::white);
					painter.end ();
					return;
				}
			
				const QPalette& palette = QApplication::palette ();
				const QColor& backgroundColor = palette.color (QPalette::Base);
				const QColor& downloadedPieceColor = palette.color (QPalette::Highlight);

				QPixmap tempPicture (s, 1);
				QPainter tempPainter (&tempPicture);
				tempPainter.setPen (backgroundColor);
				tempPainter.drawLine (0, 0, s, 0);
				QList<QPair<int, int> > trues = FindTrues (Pieces_);
				for (int i = 0; i < trues.size (); ++i)
				{
					QPair<int, int> pair = trues.at (i);
			
					tempPainter.setPen (downloadedPieceColor);
					tempPainter.drawLine (pair.first, 0, pair.second, 0);
				}
				tempPainter.end ();
			
				painter.drawPixmap (QRect (0, 0, width (), height ()), tempPicture);
				painter.end ();
			
				e->accept ();
			}
Ejemplo n.º 28
0
    //___________________________________________________
    void Button::paint( QPainter& painter )
    {

        QPalette palette( _client.palette() );
        palette.setCurrentColorGroup( isActive() ? QPalette::Active : QPalette::Inactive);

        if(
            _client.compositingActive() &&
            !( _client.isMaximized() || _type == ButtonItemClose || _type == ButtonItemMenu ) )
        { painter.translate( 0, -1 ); }

        // translate buttons down if window maximized
        if( _client.isMaximized() ) painter.translate( 0, 1 );

        // base button color
        QColor base;
        if( _type == ButtonItemClose && _forceInactive ) base = _client.backgroundPalette( this, palette ).window().color();
        else if( _type == ButtonItemClose ) base = palette.window().color();
        else base = palette.button().color();

        // text color
        QColor color = (_type == ButtonItemClose && _forceInactive ) ?
            buttonDetailColor( _client.backgroundPalette( this, palette ) ):
            buttonDetailColor( palette );

        // decide decoration color
        QColor glow;
        if( isAnimated() || (_status&Hovered) )
        {
            glow = isCloseButton() ?
                _helper.viewNegativeTextBrush().brush(palette).color():
                _helper.viewHoverBrush().brush(palette).color();

            if( isAnimated() )
            {

                color = KColorUtils::mix( color, glow, glowIntensity() );
                glow = _helper.alphaColor( glow, glowIntensity() );

            } else if( _status&Hovered  ) color = glow;

        }

        if( hasDecoration() )
        {
            // scale
            qreal scale( (21.0*_client.buttonSize())/22.0 );

            // pressed state
            const bool pressed(
                (_status&Pressed) ||
                ( _type == ButtonSticky && _client.isOnAllDesktops()  ) ||
                ( _type == ButtonAbove && _client.keepAbove() ) ||
                ( _type == ButtonBelow && _client.keepBelow() ) );

            // draw button shape
            painter.drawPixmap(0, 0, _helper.windecoButton( base, glow, pressed, scale ) );

        }

        // Icon
        // for menu button the application icon is used
        if( isMenuButton() )
        {

            int iconScale( 0 );
            switch( _client.buttonSize() )
            {
                case Configuration::ButtonSmall: iconScale = 13; break;

                default:
                case Configuration::ButtonDefault: iconScale = 16; break;
                case Configuration::ButtonLarge: iconScale = 20; break;
                case Configuration::ButtonVeryLarge: iconScale = 24; break;
                case Configuration::ButtonHuge: iconScale = 35; break;
            }

            const QPixmap& pixmap( _client.icon().pixmap( iconScale ) );
            const double offset = 0.5*(width()-pixmap.width() );
            painter.drawPixmap(offset, offset-1, pixmap );

        } else {

            painter.setRenderHints(QPainter::Antialiasing);
            qreal width( 1.2 );

            // contrast
            painter.setBrush(Qt::NoBrush);
            painter.setPen(QPen( _helper.calcLightColor( base ), width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
            drawIcon(&painter);

            // main
            painter.translate(0,-1.5);
            painter.setBrush(Qt::NoBrush);
            painter.setPen(QPen(color, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
            drawIcon(&painter);

        }

    }
Ejemplo n.º 29
0
static int get_image( mlt_frame a_frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
{
	mlt_frame b_frame = mlt_frame_pop_frame( a_frame );
	mlt_properties properties = MLT_FRAME_PROPERTIES( a_frame );
	mlt_transition transition = MLT_TRANSITION( mlt_frame_pop_service( a_frame ) );
	uint8_t *b_image;
	int window_size = mlt_properties_get_int( MLT_TRANSITION_PROPERTIES( transition ), "window_size" );
	double psnr[3], ssim[3];

	*format = mlt_image_yuv422;
	mlt_frame_get_image( b_frame, &b_image, format, width, height, writable );
	mlt_frame_get_image( a_frame, image, format, width, height, writable );

	psnr[0] = calc_psnr( *image, b_image, *width * *height, 2 );
	psnr[1] = calc_psnr( *image + 1, b_image + 1, *width * *height / 2, 4 );
	psnr[2] = calc_psnr( *image + 3, b_image + 3, *width * *height / 2, 4 );
	ssim[0] = calc_ssim( *image, b_image, *width, *height, window_size, 2 );
	ssim[1] = calc_ssim( *image + 1, b_image + 1, *width / 2, *height, window_size, 4 );
	ssim[2] = calc_ssim( *image + 3, b_image + 3, *width / 2, *height, window_size, 4 );
	mlt_properties_set_double( properties, "meta.vqm.psnr.y", psnr[0] );
	mlt_properties_set_double( properties, "meta.vqm.psnr.cb", psnr[1] );
	mlt_properties_set_double( properties, "meta.vqm.psnr.cr", psnr[2] );
	mlt_properties_set_double( properties, "meta.vqm.ssim.y", ssim[0] );
	mlt_properties_set_double( properties, "meta.vqm.ssim.cb", ssim[1] );
	mlt_properties_set_double( properties, "meta.vqm.ssim.cr", ssim[2] );
	printf( "%05d %05.2f %05.2f %05.2f %5.3f %5.3f %5.3f\n",
			mlt_frame_get_position( a_frame ), psnr[0], psnr[1], psnr[2],
			ssim[0], ssim[1], ssim[2] );

	// copy the B frame to the bottom of the A frame for comparison
	window_size = mlt_image_format_size( *format, *width, *height, NULL ) / 2;
	memcpy( *image + window_size, b_image + window_size, window_size );

	if ( !mlt_properties_get_int( MLT_TRANSITION_PROPERTIES( transition ), "render" ) )
		return 0;

	// get RGBA image for Qt drawing
	*format = mlt_image_rgb24a;
	mlt_frame_get_image( a_frame, image, format, width, height, 1 );

	// convert mlt image to qimage
	QImage img( *width, *height, QImage::Format_ARGB32 );
	int y = *height + 1;
	uint8_t *src = *image;
	while ( --y )
	{
		QRgb *dst = (QRgb*) img.scanLine( *height - y );
		int x = *width + 1;
		while ( --x )
		{
			*dst++ = qRgba( src[0], src[1], src[2], 255 );
			src += 4;
		}
	}

	// setup Qt drawing
	QPainter painter;
	painter.begin( &img );
	painter.setRenderHints( QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing );

	// draw some stuff with Qt
	QPalette palette;
	QFont font;
	QString s;
	font.setBold( true );
	font.setPointSize( 30 * *height / 1080 );
	painter.setPen( QColor("black") );
	painter.drawLine( 0, *height/2 + 1, *width, *height/2 );
	painter.setPen( QColor("white") );
	painter.drawLine( 0, *height/2 - 1, *width, *height/2 );
	painter.setFont( font );
	s.sprintf( "Frame: %05d\nPSNR:   %05.2f (Y) %05.2f (Cb) %05.2f (Cr)\nSSIM:    %5.3f (Y) %5.3f (Cb) %5.3f (Cr)",
			  mlt_frame_get_position( a_frame ), psnr[0], psnr[1], psnr[2],
			  ssim[0], ssim[1], ssim[2] );
	painter.setPen( QColor("black") );
	painter.drawText( 52, *height * 8 / 10 + 2, *width, *height, 0, s );
	painter.setPen( QColor("white") );
	painter.drawText( 50, *height * 8 / 10, *width, *height, 0, s );

	// finish Qt drawing
	painter.end();
	window_size = mlt_image_format_size( *format, *width, *height, NULL );
	uint8_t *dst = (uint8_t *) mlt_pool_alloc( window_size );
	mlt_properties_set_data( MLT_FRAME_PROPERTIES(a_frame), "image", dst, window_size, mlt_pool_release, NULL );
	*image = dst;

	// convert qimage to mlt
	y = *height + 1;
	while ( --y )
	{
		QRgb *src = (QRgb*) img.scanLine( *height - y );
		int x = *width + 1;
		while ( --x )
		{
			*dst++ = qRed( *src );
			*dst++ = qGreen( *src );
			*dst++ = qBlue( *src );
			*dst++ = qAlpha( *src );
			src++;
		}
	}

	return 0;
}
Ejemplo n.º 30
0
void
ImageView::onPaint(QPainter& painter, InteractionState const& interaction)
{
	painter.setWorldMatrixEnabled(false);
	painter.setRenderHints(QPainter::Antialiasing, false);

	double const w = maxViewportRect().width();
	double const h = maxViewportRect().height();
	QPointF const center(getImageRotationOrigin());

	// Draw the semi-transparent grid.
	QPen pen(QColor(0, 0, 255, 90));
	pen.setCosmetic(true);
	pen.setWidth(1);
	painter.setPen(pen);
	QVector<QLineF> lines;
	for (double y = center.y(); (y -= m_cellSize) > 0.0;) {
		lines.push_back(QLineF(0.5, y, w - 0.5, y));
	}
	for (double y = center.y(); (y += m_cellSize) < h;) {
		lines.push_back(QLineF(0.5, y, w - 0.5, y));
	}
	for (double x = center.x(); (x -= m_cellSize) > 0.0;) {
		lines.push_back(QLineF(x, 0.5, x, h - 0.5));
	}
	for (double x = center.x(); (x += m_cellSize) < w;) {
		lines.push_back(QLineF(x, 0.5, x, h - 0.5));
	}
	painter.drawLines(lines);

	// Draw the horizontal and vertical line crossing at the center.
	pen.setColor(QColor(0, 0, 255));
	painter.setPen(pen);
	painter.setBrush(Qt::NoBrush);
	painter.drawLine(
		QPointF(0.5, center.y()),
		QPointF(w - 0.5, center.y())
	);
	painter.drawLine(
		QPointF(center.x(), 0.5),
		QPointF(center.x(), h - 0.5)
	);

	// Draw the rotation arcs.
	// Those will look like this (  )
	QRectF const arc_square(getRotationArcSquare());

	painter.setRenderHints(QPainter::Antialiasing, true);
	pen.setWidthF(1.5);
	painter.setPen(pen);
	painter.setBrush(Qt::NoBrush);
	painter.drawArc(
		arc_square,
		qRound(16 * -m_maxRotationDeg),
		qRound(16 * 2 * m_maxRotationDeg)
	);
	painter.drawArc(
		arc_square,
		qRound(16 * (180 - m_maxRotationDeg)),
		qRound(16 * 2 * m_maxRotationDeg)
	);

	std::pair<QPointF, QPointF> const handles(
		getRotationHandles(arc_square)
	);

	QRectF rect(m_handlePixmap.rect());
	rect.moveCenter(handles.first);
	painter.drawPixmap(rect.topLeft(), m_handlePixmap);
	rect.moveCenter(handles.second);
	painter.drawPixmap(rect.topLeft(), m_handlePixmap);
}