void MultiLayer::exportToEPS(const QString& fname, int res, QPrinter::Orientation o, QPrinter::PageSize pageSize, QPrinter::ColorMode col) { QPrinter printer; printer.setResolution(res); printer.setPageSize(pageSize); printer.setColorMode(col); printer.setOrientation(o); printer.setFullPage(TRUE); printer.setOutputToFile (TRUE); printer.setOutputFileName(fname); QPainter paint(&printer); QPaintDeviceMetrics pdmTo(&printer); int dpiy = pdmTo.logicalDpiY(); int margin = (int) ( (0.5/2.54)*dpiy ); // 5 mm margins QSize size = canvas->size(); double scaleFactorX=(double)(pdmTo.width() - 2*margin)/(double)size.width(); double scaleFactorY=(double)(pdmTo.height() - 2*margin)/(double)size.height(); for (int i=0;i<(int)graphsList->count();i++) { Graph *gr=(Graph *)graphsList->at(i); Plot *myPlot= (Plot *)gr->plotWidget(); PrintFilter filter(myPlot); filter.setOptions(QwtPlotPrintFilter::PrintAll | QwtPlotPrintFilter::PrintTitle | QwtPlotPrintFilter::PrintCanvasBackground); QPoint pos=gr->pos(); pos=QPoint(int(margin + pos.x()*scaleFactorX),int(margin + pos.y()*scaleFactorY)); int width=int(myPlot->frameGeometry().width()*scaleFactorX); int height=int(myPlot->frameGeometry().height()*scaleFactorY); QRect rect = QRect(pos,QSize(width,height)); if (myPlot->paletteBackgroundColor() != QColor(white)) paint.fillRect(rect, myPlot->paletteBackgroundColor()); int lw = myPlot->lineWidth(); if ( lw > 0) { myPlot->printFrame(&paint, rect); rect.moveBy ( lw, lw); rect.setWidth(rect.width() - 2*lw); rect.setHeight(rect.height() - 2*lw); } myPlot->print(&paint, rect, filter); } if (hasOverlapingLayers()) updateTransparency(); }
// -------------------------------------------------------------------------------- void QmvFormTool::buildBackgroundPixmap( ) { // Determine page size using a QPinter object QPrinter* prt; QSize ps; // Set the page size prt = new QPrinter(); prt->setFullPage(true); prt->setPageSize( (QPrinter::PageSize) fh->form_pagesize.toInt() ); prt->setOrientation( (QPrinter::Orientation) fh->form_orientation.toInt() ); // Get the page metrics QPaintDeviceMetrics pdm(prt); ps.setWidth(pdm.width()); ps.setHeight(pdm.height()); delete prt; background.resize( ps ); pagesize = ps; background.fill( getTransparentColor() ); // clear the canvas event index canvas_details.setAutoDelete(FALSE); canvas_details.clear(); }
void PageScreen::saveAsDocument(const QString &format) { const QString &suffix = QLatin1Char('.') + format.toLower(); QString pathWithoutSuffix = ui->location->text(); if (pathWithoutSuffix.endsWith(suffix, Qt::CaseInsensitive)) { pathWithoutSuffix = pathWithoutSuffix.mid(0, pathWithoutSuffix.length() - suffix.length()); } QPrinter printer; printer.setCreator(QupZilla::tr("QupZilla %1 (%2)").arg(QupZilla::VERSION, QupZilla::WWWADDRESS)); printer.setOutputFileName(pathWithoutSuffix + suffix); printer.setOutputFormat(QPrinter::PdfFormat); printer.setPaperSize(m_pageImages.first().size(), QPrinter::DevicePixel); printer.setPageMargins(0, 0, 0, 0, QPrinter::DevicePixel); printer.setFullPage(true); QPainter painter; painter.begin(&printer); for (int i = 0; i < m_pageImages.size(); ++i) { const QImage &image = m_pageImages.at(i); painter.drawImage(0, 0, image); if (i != m_pageImages.size() - 1) { printer.newPage(); } } painter.end(); }
void Dialog::on_button_clicked() { const QString filename = "CppQPrinterExample2.pdf"; //Set up a QPrinter QPrinter printer; printer.setOutputFormat(QPrinter::PdfFormat); printer.setOrientation(QPrinter::Portrait); printer.setPaperSize(QPrinter::A4); printer.setFullPage(false); printer.setOutputFileName(filename); //Grab the window const QImage image = QPixmap::grabWindow(this->winId()).toImage(); //Draw the image to painter to printer QPainter painter; painter.begin(&printer); painter.drawImage(0,0,image); painter.end(); //Start the printer boost::shared_ptr<QPrintDialog> dialog(new QPrintDialog(&printer)); dialog->exec(); }
void Help::filePrint() { QPrinter printer; printer.setFullPage(TRUE); if ( printer.setup() ) { QPainter p( &printer ); QPaintDeviceMetrics metrics(p.device()); int dpix = metrics.logicalDpiX(); int dpiy = metrics.logicalDpiY(); const int margin = 72; // pt QRect body(margin*dpix/72, margin*dpiy/72, metrics.width()-margin*dpix/72*2, metrics.height()-margin*dpiy/72*2 ); QFont font("times", 10); QSimpleRichText richText( browser->text(), font, browser->context(), browser->styleSheet(), browser->mimeSourceFactory(), body.height() ); richText.setWidth( &p, body.width() ); QRect view( body ); int page = 1; for (;;) { richText.draw( &p, body.left(), body.top(), view, colorGroup() ); view.moveBy( 0, body.height() ); p.translate( 0 , -body.height() ); p.setFont( font ); p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ), view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) ); if ( view.top() >= richText.height() ) break; printer.newPage(); page++; } } }
QRectF M_PagesizeMake( QPrinter::PageSize psize , bool landscape) { QPrinter *print = new QPrinter(QPrinter::HighResolution); print->setFullPage(true); print->setPageSize(psize); if (landscape) { print->setOrientation(QPrinter::Landscape); } else { print->setOrientation(QPrinter::Portrait); } const QRectF pa = print->pageRect(QPrinter::Point); const qreal faktor = qMax(pa.width(),pa.height()) / qMin(pa.width(),pa.height()); const qreal smaller = qMin(pa.width(),pa.height()); const qreal biger = smaller * faktor; delete print; if ( landscape ) { return QRectF(0,0,biger,smaller); } else { return QRectF(0,0,smaller,biger); } }
/** * Methode permettant d'imprimer un document */ void ValidDocument::print(){ QWebView webView; QPrinter printer ; printer.setPageSize(QPrinter::A4); printer.setFullPage(true); QString type=(docType==Document::Facture)?QObject::trUtf8("Facture"):QObject::trUtf8("Devis"); printer.setDocName(type+"_"+QString::number(id) ); printer.setCreator(QObject::trUtf8("QFacturation")); printer.setOutputFormat(QPrinter::NativeFormat); webView.setHtml(view); webView.show(); QPrintDialog printDialog(&printer); if(printDialog.exec() == QDialog::Accepted) { qDebug("Ne fonctionne pas sous windows")<<" Hack ...."; #if defined(Q_WS_WIN) QTextDocument text; text.setHtml(view); text.print(&printer); #endif #if defined(Q_WS_QWS) webView.print(&printer); #endif #if defined(Q_WS_X11) webView.print(&printer); #endif } }
void Qt_help_window::print() { #ifndef QT_NO_PRINTER QPrinter printer; printer.setFullPage(TRUE); if ( printer.setup( this ) ) { QPainter p( &printer ); QPaintDeviceMetrics metrics(p.device()); int dpix = metrics.logicalDpiX(); int dpiy = metrics.logicalDpiY(); const int margin = 72; // pt QRect body(margin*dpix/72, margin*dpiy/72, metrics.width()-margin*dpix/72*2, metrics.height()-margin*dpiy/72*2 ); QSimpleRichText richText( browser->text(), QFont(), browser->context(), browser->styleSheet(), browser->mimeSourceFactory(), body.height() ); richText.setWidth( &p, body.width() ); QRect view( body ); int page = 1; do { richText.draw( &p, body.left(), body.top(), view, colorGroup() ); view.moveBy( 0, body.height() ); p.translate( 0 , -body.height() ); p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ), view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) ); if ( view.top() >= richText.height() ) break; printer.newPage(); page++; } while (TRUE); } #endif }
void Matrix::exportVector(const QString& fileName, int res, bool color) { if ( fileName.isEmpty() ){ QMessageBox::critical(this, tr("QtiPlot - Error"), tr("Please provide a valid file name!")); return; } QPrinter printer; printer.setCreator("QtiPlot"); printer.setFullPage(true); if (res) printer.setResolution(res); printer.setOutputFileName(fileName); if (fileName.contains(".eps")) printer.setOutputFormat(QPrinter::PostScriptFormat); if (color) printer.setColorMode(QPrinter::Color); else printer.setColorMode(QPrinter::GrayScale); printer.setOrientation(QPrinter::Portrait); int cols = numCols(); int rows = numRows(); QRect rect = QRect(0, 0, cols, rows); printer.setPaperSize(QSizeF(cols, rows), QPrinter::DevicePixel); QPainter paint(&printer); paint.drawImage(rect, d_matrix_model->renderImage()); paint.end(); }
int main(int argc, char** argv) { Genome* g(new Genome()); std::string fileName; if (argc > 1) { fileName = argv[1]; } else { fileName = "out.sam"; } g->read(fileName); QApplication app(argc, argv); LinearPlot lp(); auto seed = g->getReadAt(1, 1); assume(seed != nullptr, "Error, no read found!"); lp.setSceneRect(0, 0, 1200, 300); lp.fromRead(seed, g); QGraphicsView view(&lp); view.setWindowTitle("Chipboard demo v0.0.1"); view.show(); QPrinter printer; printer.setPaperSize(QSize(view.width(), view.height()), QPrinter::Point); printer.setFullPage(true); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName("plot.pdf"); QPainter pdfPainter; pdfPainter.begin(&printer); view.render(&pdfPainter); return app.exec(); }
void ribi::braw::QtPrintRatingDialog::Print(const std::string& filename) { QPrinter printer; printer.setOrientation(QPrinter::Portrait); printer.setPaperSize(QPrinter::A4); printer.setFullPage(false); printer.setOutputFileName(filename.c_str()); //Draw the image to painter to printer (?must be done before printing) QPainter painter; painter.begin(&printer); { //Collect widgets to print const std::vector<QWidget *> widgets = CollectWidgets(); int y = 0; for (QWidget * const widget: widgets) { const int h = widget->height(); if (y+h > painter.window().height()) { printer.newPage(); y = 0; } widget->render(&painter,QPoint(0,y)); y+=h; } } painter.end(); }
void MultiLayer::exportVector(const QString &fileName, int res, bool color, bool keepAspect, QPrinter::PageSize pageSize, QPrinter::Orientation orientation) { Q_UNUSED(res); if (fileName.isEmpty()) { QMessageBox::critical(this, tr("Error"), tr("Please provide a valid file name!")); return; } QPrinter printer; printer.setDocName(this->name()); printer.setCreator("AlphaPlot"); printer.setFullPage(true); printer.setOutputFileName(fileName); if (fileName.contains(".eps")) printer.setOutputFormat(QPrinter::PostScriptFormat); if (color) printer.setColorMode(QPrinter::Color); else printer.setColorMode(QPrinter::GrayScale); if (pageSize == QPrinter::Custom) printer.setPaperSize(canvas->size(), QPrinter::Point); else { printer.setOrientation(orientation); printer.setPaperSize(pageSize); } exportPainter(printer, keepAspect); }
void HelpBrowser::print() { QPrinter printer; printer.setFullPage(true); QPrintDialog dialog(&printer, this); if (dialog.exec()) textBrowser->print(&printer); }
//------------------------------------------------------------------------- void QGuidoItemContainer::exportToPdf(const QString& fileName) { QPrinter printer; printer.setFullPage(true); printer.setOutputFileName( fileName ); printer.setOutputFormat( QPrinter::PdfFormat ); exportToPdf( &printer ); }
void QgsComposition::beginPrint( QPrinter &printer ) { //set resolution based on composer setting printer.setFullPage( true ); printer.setColorMode( QPrinter::Color ); //set user-defined resolution printer.setResolution( printResolution() ); }
void SchedulePrintDialog::setupPdfPrinter( QPrinter & printer ) { printer.setOutputFormat( QPrinter::PdfFormat ); setupPrinter(printer); printer.setFullPage( true ); printer.setResolution( mDpiSpin->value() ); printer.setFontEmbeddingEnabled(false); }
void UBExportFullPDF::saveOverlayPdf(UBDocumentProxy* pDocumentProxy, const QString& filename) { if (!pDocumentProxy || filename.length() == 0 || pDocumentProxy->pageCount() == 0) return; //PDF qDebug() << "exporting document to PDF Merger" << filename; QPrinter pdfPrinter; pdfPrinter.setOutputFormat(QPrinter::PdfFormat); pdfPrinter.setResolution(UBSettings::settings()->pdfResolution->get().toInt()); pdfPrinter.setOutputFileName(filename); pdfPrinter.setFullPage(true); QPainter* pdfPainter = 0; for(int pageIndex = 0 ; pageIndex < pDocumentProxy->pageCount(); pageIndex++) { UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocumentProxy, pageIndex); // set background to white, no grid for PDF output bool isDark = scene->isDarkBackground(); bool isCrossed = scene->isCrossedBackground(); scene->setBackground(false, false); // set high res rendering scene->setRenderingQuality(UBItem::RenderingQualityHigh); scene->setRenderingContext(UBGraphicsScene::PdfExport); QSize pageSize = scene->nominalSize(); UBGraphicsPDFItem *pdfItem = qgraphicsitem_cast<UBGraphicsPDFItem*>(scene->backgroundObject()); if (pdfItem) mHasPDFBackgrounds = true; pdfPrinter.setPaperSize(QSizeF(pageSize.width()*mScaleFactor, pageSize.height()*mScaleFactor), QPrinter::Point); if (!pdfPainter) pdfPainter = new QPainter(&pdfPrinter); if (pageIndex != 0) pdfPrinter.newPage(); //render to PDF scene->setDrawingMode(true); scene->render(pdfPainter, QRectF(), scene->normalizedSceneRect()); //restore screen rendering quality scene->setRenderingContext(UBGraphicsScene::Screen); scene->setRenderingQuality(UBItem::RenderingQualityNormal); //restore background state scene->setDrawingMode(false); scene->setBackground(isDark, isCrossed); } if (pdfPainter) delete pdfPainter; }
bool UBExportPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QString& filename) { QPrinter pdfPrinter; qDebug() << "exporting document to PDF" << filename; pdfPrinter.setOutputFormat(QPrinter::PdfFormat); pdfPrinter.setResolution(UBSettings::settings()->pdfResolution->get().toInt()); pdfPrinter.setOutputFileName(filename); pdfPrinter.setFullPage(true); //need to calculate screen resolution QDesktopWidget* desktop = UBApplication::desktop(); int dpiCommon = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2; float scaleFactor = 72.0f / dpiCommon; QPainter pdfPainter; bool painterNeedsBegin = true; int existingPageCount = pDocumentProxy->pageCount(); for(int pageIndex = 0 ; pageIndex < existingPageCount; pageIndex++) { UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocumentProxy, pageIndex); UBApplication::showMessage(tr("Exporting page %1 of %2").arg(pageIndex + 1).arg(existingPageCount)); // set background to white, no crossing for PDF output bool isDark = scene->isDarkBackground(); bool isCrossed = scene->isCrossedBackground(); scene->setBackground(false, false); QSize pageSize = scene->nominalSize(); // set high res rendering scene->setRenderingQuality(UBItem::RenderingQualityHigh); scene->setRenderingContext(UBGraphicsScene::NonScreen); //setting page size to appropriate value pdfPrinter.setPaperSize(QSizeF(pageSize.width()*scaleFactor, pageSize.height()*scaleFactor), QPrinter::Point); if(painterNeedsBegin) painterNeedsBegin = !pdfPainter.begin(&pdfPrinter); //render to PDF scene->render(&pdfPainter, QRectF(), scene->normalizedSceneRect()); if (pageIndex < existingPageCount - 1) pdfPrinter.newPage(); //restore screen rendering quality scene->setRenderingContext(UBGraphicsScene::Screen); scene->setRenderingQuality(UBItem::RenderingQualityNormal); //restore background state scene->setBackground(isDark, isCrossed); } if(!painterNeedsBegin) pdfPainter.end(); return true; }
//------------------------------------------------------------------------- void MainWindow::exportRect(const QRectF& exportRectangle , const QString& fileName , const QString& fileType ) { QList<QLanguageItem*> selectedItems = selectedLanguageItems(); unselectAll(); QPainter painter; if ( fileType == PNG_FILE_FILTER ) { int result = QResolutionDialog( exportRectangle , EXPORT_MIN_DETAIL , EXPORT_MAX_DETAIL , EXPORT_DEFAULT_DETAIL , EXPORT_DETAIL_TO_SCALE_FACTOR ).exec(); if ( result ) { //Create a new QImage, with a size corresponding to the Guido Score page QSizeF size( exportRectangle.width() , exportRectangle.height() ); size.setWidth( result * EXPORT_DETAIL_TO_SCALE_FACTOR * size.width() ); size.setHeight( result * EXPORT_DETAIL_TO_SCALE_FACTOR * size.height() ); QImage image( size.width() , size.height() , QImage::Format_ARGB32); image.fill( QColor(Qt::white).rgb() ); painter.begin( &image ); //Paint in the QImage paintSceneRect( exportRectangle , &painter ); painter.end(); image.save( fileName , "PNG" ); } } else if ( ( fileType == PDF_FILE_FILTER ) || ( fileType == PS_FILE_FILTER ) ) { QPrinter printer; printer.setFullPage(true); printer.setOutputFileName( fileName ); if ( fileType == PS_FILE_FILTER ) { printer.setOutputFormat( QPrinter::PostScriptFormat ); } else if ( fileType == PDF_FILE_FILTER ) { printer.setOutputFormat( QPrinter::PdfFormat ); } printer.setPaperSize( QSizeF( exportRectangle.width() , exportRectangle.height() ) , QPrinter::Millimeter ); painter.setWindow( exportRectangle.toRect() ); painter.begin( &printer ); paintSceneRect( exportRectangle , &painter ); painter.end(); } for ( int i = 0 ; i < selectedItems.size() ; i++ ) selectedItems[i]->setSelected(true); }
/** Gets the metrics for the selected page size & orientation */ QSize MReportEngine::getPageMetrics( int size, int orientation ) { QSize ps; // Set the page size if (( QPrinter::PageSize ) size == QPrinter::Custom ) { ps.setWidth( customWidthMM / 25.4 * 78. ); ps.setHeight( customHeightMM / 25.4 * 78. ); return ps; } #if defined(Q_OS_WIN32) if ( !printToPos ) { PSPrinter *printer = new PSPrinter( PSPrinter::HighResolution ); printer->setFullPage( true ); printer->setPageSize(( PSPrinter::PageSize ) size ); printer->setOrientation(( PSPrinter::Orientation ) orientation ); QPaintDeviceMetrics pdm( printer ); ps.setWidth( pdm.widthMM() / 25.4 * 78. ); ps.setHeight( pdm.heightMM() / 25.4 * 78. ); delete printer; } else { FLPosPrinter * printer = new FLPosPrinter(); QPaintDeviceMetrics pdm( printer ); ps.setWidth( pdm.widthMM() / 25.4 * 78. ); ps.setHeight( pdm.heightMM() / 25.4 * 78. ); delete printer; } #else if ( !printToPos ) { QPrinter * printer = new QPrinter( QPrinter::HighResolution ); printer->setFullPage( true ); printer->setPageSize(( QPrinter::PageSize ) size ); printer->setOrientation(( QPrinter::Orientation ) orientation ); QPaintDeviceMetrics pdm( printer ); ps.setWidth( pdm.widthMM() / 25.4 * 78. ); ps.setHeight( pdm.heightMM() / 25.4 * 78. ); delete printer; } else { FLPosPrinter * printer = new FLPosPrinter(); QPaintDeviceMetrics pdm( printer ); ps.setWidth( pdm.widthMM() / 25.4 * 78. ); ps.setHeight( pdm.heightMM() / 25.4 * 78. ); delete printer; } #endif return ps; }
void HelpWindow::print() { #ifndef QT_NO_PRINTER QPrinter printer; printer.setFullPage(TRUE); if ( printer.setup() ) { QPainter p( &printer ); QPaintDeviceMetrics metrics(p.device()); int dpix = metrics.logicalDpiX(); int dpiy = metrics.logicalDpiY(); const int margin = 72; // pt QRect body(margin*dpix/72, margin*dpiy/72, metrics.width()-margin*dpix/72*2, metrics.height()-margin*dpiy/72*2 ); QFont font("times", 10); QStringList filePaths = browser->mimeSourceFactory()->filePath(); QString file; QStringList::Iterator it = filePaths.begin(); for ( ; it != filePaths.end(); ++it ) { file = QUrl( *it, QUrl( browser->source() ).path() ).path(); if ( QFile::exists( file ) ) break; else file = QString::null; } if ( file.isEmpty() ) return; QFile f( file ); if ( !f.open( IO_ReadOnly ) ) return; QTextStream ts( &f ); QSimpleRichText richText( ts.read(), font, browser->context(), browser->styleSheet(), browser->mimeSourceFactory(), body.height() ); richText.setWidth( &p, body.width() ); QRect view( body ); int page = 1; do { richText.draw( &p, body.left(), body.top(), view, colorGroup() ); view.moveBy( 0, body.height() ); p.translate( 0 , -body.height() ); p.setFont( font ); p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ), view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) ); if ( view.top() >= richText.height() ) break; printer.newPage(); page++; } while (TRUE); } #endif }
void MainWindow::on_actionSave_Document_triggered() { QString fileName = QFileDialog::getSaveFileName(this, "Save document...", qApp->applicationDirPath(), "*.pdf"); if (!fileName.isEmpty()) { QPrinter printer; printer.setFullPage(true); printer.setPaperSize(QPrinter::A4); printer.setOrientation(QPrinter::Portrait); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); ui->textEdit->document()->print(&printer); } }
void MultiLayer::print() { QPrinter printer; printer.setResolution(84); printer.setOrientation(QPrinter::Landscape); printer.setColorMode (QPrinter::Color); printer.setFullPage(TRUE); if (printer.setup()) { QPainter paint(&printer); printAllLayers(&paint); paint.end(); } }
void SvgCanvas::export_to_pdf_ps(int width, int height, QString filename) { QPainter plot; QPrinter p; p.setFullPage(true); p.setPageSize(QPrinter::Custom); if( filename.endsWith(".pdf") ) p.setOutputFormat(QPrinter::PdfFormat); else p.setOutputFormat(QPrinter::PostScriptFormat); p.setOutputFileName(filename); plot.begin(&p); svg_plot->renderer()->render(&plot); plot.end(); }
void Matrix::print(const QString& fileName) { QPrinter printer; printer.setColorMode (QPrinter::GrayScale); if (!fileName.isEmpty()){ printer.setCreator("QtiPlot"); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); } else { QPrintDialog printDialog(&printer, applicationWindow()); if (printDialog.exec() != QDialog::Accepted) return; } printer.setFullPage( true ); print(&printer); }
void ribi::pvdb::QtPvdbPrintRatingDialog::Print() { //Start save dialog const boost::shared_ptr<QFileDialog> print_dialog( pvdb::QtFileDialog::GetSaveFileDialog( pvdb::QtFileDialog::FileType::pdf)); print_dialog->setWindowTitle("Exporteer document naar PDF"); if (print_dialog->exec() != QDialog::Accepted || print_dialog->selectedFiles().empty() ) { return; } assert(!print_dialog->selectedFiles().empty()); assert(print_dialog->selectedFiles().size() == 1); const std::string filename = print_dialog->selectedFiles()[0].toStdString(); QPrinter printer; printer.setOrientation(QPrinter::Portrait); printer.setPaperSize(QPrinter::A4); printer.setFullPage(false); printer.setOutputFileName(filename.c_str()); //Draw the image to painter to printer (?must be done before printing) QPainter painter; painter.begin(&printer); { //Collect widgets to print const std::vector<QWidget *> widgets = CollectWidgets(); int y = 0; for (QWidget * const widget: widgets) { const int h = widget->height(); if (y+h > painter.window().height()) { printer.newPage(); y = 0; } widget->render(&painter,QPoint(0,y)); y+=h; } } painter.end(); }
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 QgsComposition::print( QPrinter &printer ) { //set resolution based on composer setting printer.setFullPage( true ); printer.setColorMode( QPrinter::Color ); //set user-defined resolution printer.setResolution( printResolution() ); QPainter p( &printer ); //QgsComposition starts page numbering at 0 int fromPage = ( printer.fromPage() < 1 ) ? 0 : printer.fromPage() - 1 ; int toPage = ( printer.toPage() < 1 ) ? numPages() - 1 : printer.toPage() - 1; if ( mPrintAsRaster ) { for ( int i = fromPage; i <= toPage; ++i ) { if ( i > fromPage ) { printer.newPage(); } QImage image = printPageAsRaster( i ); if ( !image.isNull() ) { QRectF targetArea( 0, 0, image.width(), image.height() ); p.drawImage( targetArea, image, targetArea ); } } } if ( !mPrintAsRaster ) { for ( int i = fromPage; i <= toPage; ++i ) { if ( i > fromPage ) { printer.newPage(); } renderPage( &p, i ); } } }
void MultiLayer::print() { QPrinter printer; printer.setColorMode(QPrinter::Color); printer.setFullPage(true); QRect canvasRect = canvas->rect(); double aspect = double(canvasRect.width()) / double(canvasRect.height()); if (aspect < 1) printer.setOrientation(QPrinter::Portrait); else printer.setOrientation(QPrinter::Landscape); QPrintDialog printDialog(&printer); if (printDialog.exec() == QDialog::Accepted) { QPainter paint(&printer); printAllLayers(&paint); paint.end(); } }
//---------------------------------------------------------------------------- void Guido2Image::writePDF( QGuidoPainter * guidoPainter, int pageIndex, const char * fname ) { QString fileName (fname); if ( !fileName.toUpper().endsWith( PDF_FORMAT.toUpper())) fileName += PDF_FORMAT; QPrinter printer; printer.setFullPage(true); printer.setOutputFileName( fileName ); printer.setOutputFormat( QPrinter::PdfFormat ); QSizeF firstPageSize = guidoPainter->pageSizeMM(1); printer.setPaperSize( firstPageSize, QPrinter::Millimeter ); QPainter painter(&printer); painter.setRenderHint( QPainter::Antialiasing ); painter.setWindow( QRect( 0 , 0 , firstPageSize.width() , firstPageSize.height() ) ); int pageCount = guidoPainter->pageCount(); int startPage = 1; int lastPage = pageCount; if ( pageIndex != 0 ) //Draw only the requested page { startPage = pageIndex; lastPage = pageIndex; } for ( int page = startPage ; page <= lastPage ; page++ ) { QSizeF paperSize = guidoPainter->pageSizeMM(page); // printer.setPaperSize( paperSize , QPrinter::Millimeter ); // painter.setWindow( QRect( 0 , 0 , paperSize.width() , paperSize.height() ) ); // paperSize = printer.paperSize( QPrinter::DevicePixel ); guidoPainter->draw(&painter,page,QRect(0,0,paperSize.width() , paperSize.height() ) ); if (page != lastPage) printer.newPage(); } painter.end(); }