Exemplo n.º 1
1
AdvancedPdf::PaperSize AdvancedPdf::paperSize(QPrinter::PaperSize paperSize)
{
    QPrinter pr;
    pr.setOutputFormat(QPrinter::PdfFormat);
    pr.setPaperSize(paperSize);
    QSizeF s = pr.paperSize(QPrinter::Point);
    PaperSize p = { qRound(s.width()), qRound(s.height()) };
    return p;
}
Exemplo n.º 2
0
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);
}
Exemplo n.º 3
0
bool Phantom::renderPdf(const QString &fileName)
{
    QPrinter printer;
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setOutputFileName(fileName);
    printer.setResolution(PHANTOMJS_PDF_DPI);
    QVariantMap paperSize = m_paperSize;

    if (paperSize.isEmpty()) {
        const QSize pageSize = m_page.mainFrame()->contentsSize();
        paperSize.insert("width", QString::number(pageSize.width()) + "px");
        paperSize.insert("height", QString::number(pageSize.height()) + "px");
        paperSize.insert("border", "0px");
    }

    if (paperSize.contains("width") && paperSize.contains("height")) {
        const QSizeF sizePt(ceil(stringToPointSize(paperSize.value("width").toString())),
                            ceil(stringToPointSize(paperSize.value("height").toString())));
        printer.setPaperSize(sizePt, QPrinter::Point);
    } else if (paperSize.contains("format")) {
        const QPrinter::Orientation orientation = paperSize.contains("orientation")
                && paperSize.value("orientation").toString().compare("landscape", Qt::CaseInsensitive) == 0 ?
                    QPrinter::Landscape : QPrinter::Portrait;
        printer.setOrientation(orientation);
        static const struct {
            QString format;
            QPrinter::PaperSize paperSize;
        } formats[] = {
            { "A3", QPrinter::A3 },
            { "A4", QPrinter::A4 },
            { "A5", QPrinter::A5 },
            { "Legal", QPrinter::Legal },
            { "Letter", QPrinter::Letter },
            { "Tabloid", QPrinter::Tabloid }
        };
        printer.setPaperSize(QPrinter::A4); // Fallback
        for (uint i = 0; i < sizeof(formats) / sizeof(formats[0]); ++i) {
            if (paperSize.value("format").toString().compare(formats[i].format, Qt::CaseInsensitive) == 0) {
                printer.setPaperSize(formats[i].paperSize);
                break;
            }
        }
    } else {
        return false;
    }

    const qreal border = paperSize.contains("border") ?
                floor(stringToPointSize(paperSize.value("border").toString())) : 0;
    printer.setPageMargins(border, border, border, border, QPrinter::Point);

    m_page.mainFrame()->print(&printer);
    return true;
}
Exemplo n.º 4
0
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();
}
Exemplo n.º 5
0
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();
}
Exemplo n.º 6
0
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();
}
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();

}
Exemplo n.º 8
0
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();
}
Exemplo n.º 9
0
void PrinterTests::paperSize()
{
    QPrinter printer;
    printer.setPaperSize(QPrinter::A4);
    const QSizeF size = Printer::paperSize(&printer);
    QCOMPARE(size.width(), 2100.0);
    QCOMPARE(size.height(), 2970.0);
}
Exemplo n.º 10
0
void QgsComposition::beginPrintAsPDF( QPrinter& printer, const QString& file )
{
  printer.setOutputFormat( QPrinter::PdfFormat );
  printer.setOutputFileName( file );
  printer.setPaperSize( QSizeF( paperWidth(), paperHeight() ), QPrinter::Millimeter );

  QgsPaintEngineHack::fixEngineFlags( printer.paintEngine() );
}
Exemplo n.º 11
0
void StressPlotter::postscript(QString fname, float w, float h)
{
  QPrinter printer;
  printer.setPaperSize(QSizeF(w, h), QPrinter::Point);
  printer.setOutputFormat(QPrinter::PostScriptFormat);
  printer.setOutputFileName(fname);  // can override to pdf if not .ps
  QPainter p(&printer);
  drawStress(&p, (int)w, int(h), true);
}
//! Print the checked in and missing items.
void wndInventoryCheck::printReport( void )
{
    QPrinter printer;
    printer.setPaperSize( QPrinter::Letter );
    printer.setPageMargins( 1, 1, 1, 1, QPrinter::Inch );

    QPrintDialog *dialog = new QPrintDialog( &printer, this );
    if ( dialog->exec() != QDialog::Accepted )
    {
        return;
    }

    // PDF printing:
    //printer.setOutputFormat(QPrinter::PdfFormat);
    //printer.setOutputFileName("test.pdf");

    // Build the painter data which is printed
    QPainter painter;

    if ( !painter.begin( &printer ) ) // Link the painter to the printer
    {
        qWarning("Printer Error: Could not link painter to printer. ");
        return;
    }

    painter.setFont( QFont( "Courier New", 12, QFont::Bold ) );

    int pw = (int)( printer.pageRect( QPrinter::DevicePixel ).width() );
    int ph = (int)( printer.pageRect( QPrinter::DevicePixel ).height() );
    int y = 0;
    painter.drawText( 0, 0, pw, ph, Qt::AlignHCenter, "Station 40 - Youngsville Fire Department\n"
                     "Inventory Audit Report\n"  + QDate::currentDate().toString( "dddd the d of MMMM yyyy" ) );
    y = 80;
    if ( _pUI->chkCheckedItems->isChecked() )
    {
        painter.drawText( 0, y, pw, ph, Qt::AlignLeft, "Checked Items" );
        y += 20;

        for ( int i = 0; i < _pUI->tblCheckedIn->model()->rowCount(); i++ )
        {
            painter.drawText( 20, y, pw, ph, Qt::AlignLeft, _pUI->tblCheckedIn->model()->index( i, 1 ).data().toString() );
            y += 20;
        }
    }

    if ( _pUI->chkMissingItems->isChecked() )
    {
        painter.drawText( 0, y, pw, ph, Qt::AlignLeft, "Missing Items" );
        y += 20;
        for ( int i=0; i < _pUI->tblNotCheckedIn->model()->rowCount(); i++ )
        {
            painter.drawText( 20, y, pw, ph, Qt::AlignLeft, _pUI->tblNotCheckedIn->model()->index( i, 1 ).data().toString() );
            y += 20;
        }
    }
    painter.end();
}
Exemplo n.º 13
0
void PrinterTests::pageSize()
{
    QPrinter printer;
    printer.setPaperSize(QPrinter::A4);
    printer.setPageMargins(10, 20, 30, 40, QPrinter::Millimeter);
    const QSizeF size = Printer::pageSize(&printer);
    QCOMPARE(size.width(), 1700.0);
    QCOMPARE(size.height(), 2370.0);
}
Exemplo n.º 14
0
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;
}
Exemplo n.º 15
0
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;
}
Exemplo n.º 16
0
//-------------------------------------------------------------------------
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);
}
Exemplo n.º 17
0
void MainWindow::on_actionPrint_triggered(bool)
{
	//no nothing without images
	if (images_.count()==0) return;

	QPrinter printer;
	printer.setResolution(180);
	printer.setPaperSize(QPrinter::A4);
	printer.setOrientation(QPrinter::Portrait);
	QPrintPreviewDialog dlg(&printer, this);
	dlg.setWindowFlags ( Qt::Window );
	connect(&dlg, SIGNAL(paintRequested(QPrinter*)), SLOT(printPreview(QPrinter *)));
	if(dlg.exec() == QDialog::Rejected) return;
}
Exemplo n.º 18
0
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);
  }
}
Exemplo n.º 19
0
/*----------------------------------------------------------------------------*/
void ReportDialog::onActionExportToPdf()
{
  QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
                             "",
                             tr("Pdf files (*.pdf)"));
  if(fileName.isEmpty())
    return;
  QPrinter printer;
  printer.setPaperSize(QPrinter::A4);
  printer.setOrientation(QPrinter::Portrait);
  printer.setPageMargins(20.0,10.0,10.0,10.0,QPrinter::Millimeter);
  printer.setOutputFileName(fileName);
  printer.setOutputFormat(QPrinter::PdfFormat);
  ui->webView->print(&printer);
  printer.newPage();
}
Exemplo n.º 20
0
bool WebPuppeteerTab::print(const QString &filename) {
	QPrinter print;
	print.setOutputFileName(filename);
	print.setOutputFormat(QPrinter::PdfFormat);
	print.setPaperSize(QPrinter::A4);

//	print.setPageMargins(0, 0, 0, 0, QPrinter::Inch);
	// we know our page is 72dpi, how many dpi do we need on the printer to fit it ?
//	int dpi = (mainFrame()->contentsSize().width() * print.paperSize(QPrinter::Inch).width() / 72.0) * 1.06;
//	print.setResolution(dpi);
//	QPainter print_p(&print);
//	QSize size = mainFrame()->contentsSize();
//	mainFrame()->render(&print_p, QWebFrame::ContentsLayer, QRegion(0, 0, size.width(), size.height()));
//	print_p.end();
	mainFrame()->print(&print);
	return true;
}
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();

}
Exemplo n.º 22
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
    }
}
/*!
  \param itemRow The row of the item for which to print the barcode lable.
  \see printLabelCurrent()
*/
void wndInventoryControl::printLabel( QVector<int> itemRow )
{
    QPrinter printer;

    // The labels used are 2.25"x0.75"
    // Set page size and margins accordingly
    qreal labelwidth = 2.25;
    qreal labelheight = 0.75;
    printer.setPaperSize( QSizeF( labelwidth, labelheight ), QPrinter::Inch );
    printer.setPageMargins( 0, 0, 0, 0, QPrinter::Inch );

    // PDF printing:
    //printer.setOutputFormat(QPrinter::PdfFormat);
    //printer.setOutputFileName("test.pdf");

    // Build the painter data which is printed
    QPainter painter;

    if ( !painter.begin( &printer ) ) // Link the painter to the printer
    {
        qWarning( "Printer Error: Could not link painter to printer." );
        return;
    }

    for ( int i = 0; i < itemRow.size(); i++ )
    {
        // Get the id column of the QTableView.
        QString codestring = "*" + _pUI->tblInventory->model()->data( _pUI->tblInventory->model()->index( itemRow[i] ,0 ) ).toString() + "*";

        // Draw the plaintext id centered at the top of the label
        painter.setFont( QFont( "Verdana", 10 ) );
        painter.drawText( 0 ,0, (int)( labelwidth * printer.resolution() ), (int)( labelheight * printer.resolution() ),
                          Qt::AlignHCenter, codestring );

        // Switch to the barcode font and do the same
        painter.setFont( QFont( "Free 3 of 9 Extended", 32 ) );
        painter.drawText( 0, 15, (int)( labelwidth * printer.resolution() ), (int)( labelheight * printer.resolution() ),
                          Qt::AlignHCenter, codestring );

        if ( i < itemRow.size() - 1 )
            printer.newPage();
    }

    painter.end(); // Send output
}
Exemplo n.º 24
0
/**
 * Drukuje bieżący wykres.
 */
void ChartsWidget::print()
{
    QPrinter printer;
    printer.setPaperSize(QPrinter::A4);
    QWidget* plot = ui->tabCharts->currentWidget();
    if (plot->width() > plot->height())
        printer.setOrientation(QPrinter::Landscape);
    else
        printer.setOrientation(QPrinter::Portrait);

    QPrintDialog* dlg = new QPrintDialog(&printer, this);
    if (dlg->exec() == QDialog::Accepted)
    {
        emit sendMessage(tr("Printing..."));
        QPainter p(&printer);
        p.drawPixmap(0, 0, QPixmap::grabWidget(plot));
    }
}
Exemplo n.º 25
0
//----------------------------------------------------------------------------
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();
}
Exemplo n.º 26
0
void PlaxWindow::printSlot(bool state)
{
  QPrinter printer;
#if QT_VERSION >= 0x040400
  printer.setPaperSize(QPrinter::Letter);
#endif
  QPrintDialog *dialog = new QPrintDialog(&printer, this);
  dialog->setWindowTitle(tr("Print Graph"));
  if (dialog->exec() != QDialog::Accepted)
    return;
  sSpecialPainter = true;
  sPainter = new QPainter(&printer);
  sOutListInd = 0;
  QCoreApplication::postEvent(sPlaxWidget, new QPaintEvent
                              (QRect(0, 0, sPlaxWidth, sPlaxHeight)));
  QApplication::processEvents();
  delete sPainter;
  sSpecialPainter = false;

}
void QtPvdbRatingDialog::on_button_print_clicked()
{
  #define PVDB_SHOW_WHAT_TO_PRINT_7212367586280756
  #ifdef  PVDB_SHOW_WHAT_TO_PRINT_7212367586280756
  QtPvdbPrintRatingDialog d(this->m_file);

  DisplayConcepts(m_file,d.GetTableConcepts());
  {
    const int sz = static_cast<int>(m_file->GetConceptMap()->GetNodes().size());
    d.GetTableConcepts()->setMinimumHeight( ((sz-1) * 30) + 25 ); //Standard row is 30 pixels high, header 25 pixels
  }

  DisplayExamples(m_file,d.GetTableExamples());
  DisplayValues(m_file,d.GetTableValues());

  this->ShowChild(&d);
  #else
  //Set up a QPrinter
  QPrinter printer;
  const QString filename = "ProjectVanDenBogaart.pdf";
  printer.setOutputFormat(QPrinter::PdfFormat);
  printer.setOrientation(QPrinter::Portrait);
  printer.setPaperSize(QPrinter::A4);
  printer.setFullPage(false);
  printer.setOutputFileName(filename);

  //Start printer dialog
  const boost::shared_ptr<QPrintDialog> print_dialog(new QPrintDialog(&printer));
  print_dialog->setWindowTitle(tr("Print document"));
  if (print_dialog->exec() != QDialog::Accepted) return;

  //Draw the image to painter to printer
  QPainter painter;
  painter.begin(&printer);

  QtPvdbPrintRatingDialog d(this->m_file);
  d.render(&painter);
  painter.end();
  #endif

}
Exemplo n.º 28
0
void MainWindow::print()
{
    QString text("<p align='center'>Binary Decision Diagram(BDD)<br>"
            "Version 0.1<br>"
            "By Ali Diouri<br>"
          "[email protected]<br>"
   "Licensed under BSD 3-Clause License</p>");

    QPrinter printer;
    printer.setPaperSize(QPrinter::A4);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setOutputFileName("/home/theshadowx7/Bureau/BDD.pdf");
    QPrintDialog printDialog(&printer, this);
    if (printDialog.exec() == QDialog::Accepted) {
        QTextDocument textDoc(this);
        QPainter painter(&printer);
        painter.setRenderHint(QPainter::Antialiasing);
        //textDoc.setPlainText(text);
        textDoc.setPlainText(this->lineEdit->text());
        this->view->scene->render(&painter);
        textDoc.drawContents(&painter);
    }
}
Exemplo n.º 29
0
/*!
  Render a plot to a file

  Supported formats are:

  - pdf\n
  - ps\n
  - svg\n
  - all image formats supported by Qt, see QImageWriter::supportedImageFormats()

  \param plot Plot widget
  \param fileName Path of the file, where the document will be stored
  \param format Format for the document
  \param sizeMM Size for the document in millimeters.
  \param resolution Resolution in dots per Inch (dpi)

  \sa renderTo(), render(), QwtPainter::setRoundingAlignment()
*/
void QwtPolarRenderer::renderDocument( QwtPolarPlot *plot,
    const QString &fileName, const QString &format,
    const QSizeF &sizeMM, int resolution )
{
    if ( plot == NULL || sizeMM.isEmpty() || resolution <= 0 )
        return;

    QString title = plot->title().text();
    if ( title.isEmpty() )
        title = "Plot Document";

    const double mmToInch = 1.0 / 25.4;
    const QSizeF size = sizeMM * mmToInch * resolution;

    const QRectF documentRect( 0.0, 0.0, size.width(), size.height() );

    const QString fmt = format.toLower();
    if ( format == "pdf" || format == "ps" )
    {
        QPrinter printer;
        printer.setFullPage( true );
        printer.setPaperSize( sizeMM, QPrinter::Millimeter );
        printer.setDocName( title );
        printer.setOutputFileName( fileName );
        printer.setOutputFormat( ( format == "pdf" )
            ? QPrinter::PdfFormat : QPrinter::PostScriptFormat );
        printer.setResolution( resolution );

        QPainter painter( &printer );
        render( plot, &painter, documentRect );
    }
#ifndef QWT_NO_POLAR_SVG
#ifdef QT_SVG_LIB
#if QT_VERSION >= 0x040500
    else if ( format == "svg" )
    {
        QSvgGenerator generator;
        generator.setTitle( title );
        generator.setFileName( fileName );
        generator.setResolution( resolution );
        generator.setViewBox( documentRect );

        QPainter painter( &generator );
        render( plot, &painter, documentRect );
    }
#endif
#endif
#endif
    else
    {
        if ( QImageWriter::supportedImageFormats().indexOf(
            format.toLatin1() ) >= 0 )
        {
            const QRect imageRect = documentRect.toRect();
            const int dotsPerMeter = qRound( resolution * mmToInch * 1000.0 );

            QImage image( imageRect.size(), QImage::Format_ARGB32 );
            image.setDotsPerMeterX( dotsPerMeter );
            image.setDotsPerMeterY( dotsPerMeter );
            image.fill( QColor( Qt::white ).rgb() );

            QPainter painter( &image );
            render( plot, &painter, imageRect );
            painter.end();

            image.save( fileName, format.toLatin1() );
        }
    }
}
Exemplo n.º 30
0
void QPrinterProto::setPaperSize(const QSizeF & paperSize, QPrinter::Unit unit)
{
  QPrinter *item = qscriptvalue_cast<QPrinter*>(thisObject());
  if (item)
    item->setPaperSize(paperSize, unit);
}