void MainWindow::print() { QPrinter printer( QPrinter::HighResolution ); QString docName = d_plot->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::DiscardCanvasBackground ); renderer.setLayoutFlag( QwtPlotRenderer::FrameWithScales ); } renderer.renderTo( d_plot, printer ); } }
void plotsDialog::print() { QPrinter printer( QPrinter::HighResolution ); Plot* currentPlot = dynamic_cast<Plot*>(tabs->currentWidget()); QString docName = currentPlot->title().text(); if ( !docName.isEmpty() ) { docName.replace ( QRegExp ( QString::fromLatin1 ( "\n" ) ), tr ( " -- " ) ); printer.setDocName ( docName ); } printer.setCreator( currentPlot->title().text()); 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 ); } renderer.renderTo( currentPlot, printer ); } }
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 ); }
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 } }
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); } }
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 ); } }
void Plot::printPlot() { QPrinter printer( QPrinter::HighResolution ); printer.setOrientation( QPrinter::Landscape ); printer.setOutputFileName( "spectrogram.pdf" ); 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 ); } renderer.renderTo( this, printer ); } }
void MainWindow::exportDocument() { #ifndef QT_NO_PRINTER QString fileName = "bode.pdf"; #else QString fileName = "bode.png"; #endif #ifndef QT_NO_FILEDIALOG const QList<QByteArray> imageFormats = QImageWriter::supportedImageFormats(); QStringList filter; filter += "PDF Documents (*.pdf)"; #ifndef QWT_NO_SVG filter += "SVG Documents (*.svg)"; #endif filter += "Postscript Documents (*.ps)"; if ( imageFormats.size() > 0 ) { QString imageFilter( "Images (" ); for ( int i = 0; i < imageFormats.size(); i++ ) { if ( i > 0 ) imageFilter += " "; imageFilter += "*."; imageFilter += imageFormats[i]; } imageFilter += ")"; filter += imageFilter; } fileName = QFileDialog::getSaveFileName( this, "Export File Name", fileName, filter.join( ";;" ), NULL, QFileDialog::DontConfirmOverwrite ); #endif if ( !fileName.isEmpty() ) { QwtPlotRenderer renderer; // flags to make the document look like the widget renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground, false ); renderer.setLayoutFlag( QwtPlotRenderer::KeepFrames, true ); renderer.renderDocument( d_plot, fileName, QSizeF( 300, 200 ), 85 ); } }
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 ); }
void LevelOneMuChart::exportLevelOnePlotToImage() { #ifndef QT_NO_PRINTER QString fileName = "MuChartOneLevel.pdf"; #else QString fileName = "MuChartOneLevel.png"; #endif #ifndef QT_NO_FILEDIALOG const QList<QByteArray> imageFormats = QImageWriter::supportedImageFormats(); QStringList filter; filter += tr("PDF Documents (*.pdf)"); #ifndef QWT_NO_SVG filter += tr("SVG Documents (*.svg)"); #endif filter += tr("Postscript Documents (*.ps)"); if (imageFormats.size() > 0) { QString imageFilter(tr("Images (")); for (int i = 0; i < imageFormats.size(); i++) { if (i > 0) imageFilter += " "; imageFilter += "*."; imageFilter += imageFormats[i]; } imageFilter += ")"; filter += imageFilter; } fileName = QFileDialog::getSaveFileName( this, tr("Export File Name"), fileName, filter.join(";;"), NULL, QFileDialog::DontConfirmOverwrite); #endif if (!fileName.isEmpty()) { QwtPlotRenderer renderer; renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false); renderer.renderDocument(this, fileName, QSizeF(300, 200), 85); } }
void Plot::printPlot() { #if 1 QPrinter printer; #else QPrinter printer(QPrinter::HighResolution); #endif printer.setOrientation(QPrinter::Landscape); printer.setOutputFileName("spectrogram.pdf"); QPrintDialog dialog(&printer); if ( dialog.exec() ) { QwtPlotRenderer renderer; renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false); renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true); renderer.renderTo(this, printer); } }
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 ); }
// Get canvas and print in the output file void DataPlot::saveAsSVG() { Q_EMIT disconnectUpdateDynamicsView(); #if 1 QPrinter printer; #else QPrinter printer(QPrinter::HighResolution); #endif printer.setOrientation(QPrinter::Landscape); printer.setOutputFileName("iarc_simulation01.pdf"); QPrintDialog dialog(&printer); if ( dialog.exec() ) { QwtPlotRenderer renderer; renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false); renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true); renderer.renderTo(this, printer); } Q_EMIT connectUpdateDynamicsView(); }
void plotter::save() { QString fileName = "distrib.svg"; const QList<QByteArray> imageFormats = QImageWriter::supportedImageFormats(); QStringList filter; filter += "SVG Documents (*.svg)"; filter += "PDF Documents (*.pdf)"; filter += "Postscript Documents (*.ps)"; if ( imageFormats.size() > 0 ) { QString imageFilter("Images ("); for ( int i = 0; i < imageFormats.size(); i++ ) { if ( i > 0 ) imageFilter += " "; imageFilter += "*."; imageFilter += imageFormats[i]; } imageFilter += ")"; filter += imageFilter; } fileName = QFileDialog::getSaveFileName( this, "Export File Name", fileName, filter.join(";;"), NULL, QFileDialog::DontConfirmOverwrite); if ( !fileName.isEmpty() ) { QwtPlotRenderer renderer; renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false); renderer.renderDocument(&plot, fileName, plot.size(), 85);//QSizeF(300, 200) } }
void qfit::savePlot() { QString imageFilter; const QList<QByteArray> imageFormats = QImageWriter::supportedImageFormats(); if(imageFormats.size() > 0) { for(int i = 0; i < imageFormats.size(); i++) { imageFilter += "Image "; imageFilter += imageFormats[i]; imageFilter += " (*."; imageFilter += imageFormats[i]; imageFilter += ");;"; } } #ifndef QWT_NO_SVG imageFilter += "File SVG (*.svg)"; #endif imageFilter += ";;File PDF (*.pdf);;File Postscript (*.ps)"; QString fileName = QFileDialog::getSaveFileName(this, trUtf8("Export"), "", imageFilter, NULL, QFileDialog::DontConfirmOverwrite); if(!fileName.isEmpty()) { QwtPlotRenderer renderer; renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false); renderer.renderDocument(qwtPlot, fileName, QSizeF(300, 200), 85); } }