Exemple #1
0
void
SpectrogramWnd::handlePrintCurrentView( const QString& pdfname )
{
	// A4 := 210mm x 297mm (8.27 x 11.69 inch)

    QPrinter printer( QPrinter::HighResolution );

    printer.setOutputFileName( pdfname );
    printer.setOrientation( QPrinter::Landscape );
    printer.setDocName( "QtPlatz Spectrogram" );
    printer.setColorMode( QPrinter::Color );
    printer.setPaperSize( QPrinter::A4 );
    printer.setFullPage( false );
    printer.setResolution( 300 );

    QPainter painter( &printer );
    QRectF drawRect( printer.resolution()/2, printer.resolution()/2, printer.width() - printer.resolution(), (12.0/72)*printer.resolution() );
    
    QRectF boundingRect;
    printer.setDocName( "QtPlatz Process Report" );
    painter.drawText( drawRect, Qt::TextWordWrap, fullpath_.c_str(), &boundingRect );

    drawRect.setTop( boundingRect.bottom() + printer.resolution() / 4 );
    drawRect.setHeight( printer.height() - boundingRect.top() - printer.resolution()/2 );
    // drawRect.setWidth( printer.width() );
    
    QwtPlotRenderer renderer;
    renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground, true );
    renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasBackground, true );
    renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasFrame, true );
    
    if ( printer.colorMode() == QPrinter::GrayScale )
        renderer.setLayoutFlag( QwtPlotRenderer::FrameWithScales );

    QRectF rc1( drawRect );
    rc1.setHeight( drawRect.height() * 0.60 );
    renderer.render( plot_.get(), &painter, rc1 );

    QRectF rc2( drawRect );
    rc2.setTop( rc1.bottom() + printer.resolution() / 4 );
	rc2.setHeight( drawRect.height() * 0.30 );
    rc2.setRight( drawRect.width() / 2 );
    renderer.render( sp_.get(), &painter, rc2 );
    
    rc2.moveLeft( rc2.right() + printer.resolution() / 4 );
    renderer.render( chromatogr_.get(), &painter, rc2 );
}
Exemple #2
0
void
MSPeaksWnd::handlePrintCurrentView( const QString& pdfname )
{
	// A4 := 210mm x 297mm (8.27 x 11.69 inch)
	QSizeF sizeMM( 260, 160 ); // 260x160mm 

    int resolution = 300;
	const double mmToInch = 1.0 / 25.4;
    const QSizeF size = sizeMM * mmToInch * resolution;
    double margin_left = 0.2 /* inch */ * resolution;
    //double margin_right = ( 8.27 - 0.2 ) * resolution;
    //double margin_center = (margin_right - margin_left) / 2 + margin_left;

	QPrinter printer;
    printer.setColorMode( QPrinter::Color );
    printer.setPaperSize( QPrinter::A4 );
    printer.setFullPage( false );
	printer.setOrientation( QPrinter::Landscape );
    
    printer.setDocName( "QtPlatz MS Peaks" );
    printer.setOutputFileName( pdfname );
    printer.setResolution( resolution );

    //-------------------- 
    QPainter painter( &printer );
    int n = 0;
    for ( auto& plot: plots_ ) {
        QRectF boundingRect;
        QRectF drawRect( margin_left, 0.0, printer.width() / 2.0, printer.height() );
        if ( n++ & 01 ) {
			drawRect.moveLeft( printer.width() / 2.0 );
            painter.drawText( drawRect, Qt::TextWordWrap, "Relationship between time and flight length", &boundingRect );
        } else {
            painter.drawText( drawRect, Qt::TextWordWrap, "Relationship between time and m/z", &boundingRect );
        }
        QwtPlotRenderer renderer;
        renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasBackground, true );
        renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasFrame, true );
        renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground, true );
        
        drawRect.setTop( boundingRect.bottom() );
        drawRect.setHeight( size.height() );
        drawRect.setWidth( size.width() / 2 );
        renderer.render( plot.get(), &painter, drawRect ); // render plot
    }
}
Exemple #3
0
void QcepPlot::printGraph()
{
  QPrinter printer( QPrinter::HighResolution );

  QString docName = this->title().text();
  if ( !docName.isEmpty() )
  {
    docName.replace ( QRegExp ( QString::fromLatin1 ( "\n" ) ), tr ( " -- " ) );
    printer.setDocName ( docName );
  }

//  printer.setCreator( "Bode example" );
  printer.setOrientation( QPrinter::Landscape );

  QPrintDialog dialog( &printer );

  if ( dialog.exec() ) {
    QwtPlotRenderer renderer;

    if ( printer.colorMode() == QPrinter::GrayScale ) {
      renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground );
      renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasBackground );
      renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasFrame );
//      renderer.setLayoutFlag( QwtPlotRenderer::FrameWithScales );
    }

    double gw = this->width();
    double gh = this->height();
    double pw = printer.width();
    double ph = printer.height();
    double scal = qMin( pw/gw, ph/gh);

    pw = gw*scal;
    ph = gh*scal;

    QRectF rect(0,0, pw,ph);

    QPainter p(&printer);

    renderer.render( this, &p, rect);
  }
}
Exemple #4
0
void
ChartView::saveImage( bool clipboard )
{
    QSvgGenerator generator;
    QByteArray svg;
    QBuffer buffer( &svg );
    
    generator.setTitle( "QtPlatz Generated SVG" );
    generator.setDescription( "Copyright (C) 2013-2017 MS-Cheminformataics, All rights reserved" );
    auto sz = this->size();
    QRectF rc( 0, 0, sz.width(), sz.height() );
    generator.setViewBox( rc );

    if ( clipboard ) {

        generator.setOutputDevice( &buffer );        

    } else {
        auto name = QFileDialog::getSaveFileName( this, tr( "Save SVG File" )
                                                  , "chart.svg"
                                                  , tr( "SVG (*.svg)" ) );
        if ( ! name.isEmpty() )
            generator.setFileName( name );
    }

    QwtPlotRenderer renderer;

    renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasBackground, true );
    renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasFrame, true );
    renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground, true );

    QPainter painter;
    painter.begin( &generator );
    renderer.render( this, &painter, rc );
    painter.end();

    if ( clipboard ) {
        QMimeData * mime = new QMimeData();
        mime->setData( "image/svg+xml", svg );
        QApplication::clipboard()->setMimeData( mime, QClipboard::Clipboard );
    }
}
Exemple #5
0
void BarChart::render( QPainter* painter, const QRectF & targetRect )
{
    const int r = 20;
    const QRectF plotRect = targetRect.adjusted( 0.5 * r, 0.5 * r, -0.5 * r, -0.5 * r );

    QwtPlotRenderer renderer;

    if ( qApp->styleSheet().isEmpty() )
    {
        renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground, true );

        painter->save();
        painter->setRenderHint( QPainter::Antialiasing, true );
        painter->setPen( QPen( Qt::darkGray, 1 ) );
        painter->setBrush( QColor( "WhiteSmoke" ) );
        painter->drawRoundedRect( targetRect, r, r );
        painter->restore();
    }

    renderer.render( this, painter, plotRect );
}
Exemple #6
0
/* ------- Копировать в буфер ЗОЗ ------- */
void ViewPlot::copyToBuffer()
{
    QBuffer b;
    QClipboard *clipboard = QApplication::clipboard();
    QSvgGenerator p;
    p.setOutputDevice(&b);
    p.setSize(QSize(800,800));
    p.setViewBox(QRect(0,0,800,800));

    QPainter painter;
    QwtPlotRenderer renderer;

    painter.begin(&p);
    painter.setRenderHint(QPainter::Antialiasing);
    renderer.render(ui->qwtPlot_spectrogram,&painter,QRect(0,0,800,800));
    painter.end();

    QMimeData * d = new QMimeData();
    d->setData("image/svg+xml",b.buffer());
    d->setData("image/svg+xml-compressed", b.buffer());
    d->setImageData(QPixmap::grabWidget(ui->qwtPlot_spectrogram, 0,0,-1,-1));

    clipboard->setMimeData(d,QClipboard::Clipboard);
}
Exemple #7
0
void
ChartView::copyToClipboard()
{
    auto sz = this->size();

    QImage img( sz, QImage::Format_ARGB32 );
    img.fill( qRgba( 0, 0, 0, 0 ) );
    
    QRectF rc( 0, 0, sz.width(), sz.height() );
    
    QwtPlotRenderer renderer;
    renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasBackground, false );
    renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasFrame, true );
    renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground, true );
    
    QPainter painter;

    painter.begin(&img);
    renderer.render( this, &painter, this->rect() );
    painter.end();

    if ( auto clipboard = QApplication::clipboard() )
        clipboard->setImage( img );
}