예제 #1
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();
}
//! 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();
}
예제 #3
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);
}
예제 #4
0
void PrintDialog::on_printButton_clicked()
{
  QPrinter printer;
  printer.setPageMargins(10.0,10.0,10.0,10.0,printer.Millimeter);
  QPrintDialog *dialog = new QPrintDialog(&printer, this);
  dialog->setWindowTitle(tr("Print Document"));
  if (dialog->exec() != QDialog::Accepted)
    return;
  ui->textEdit->print(&printer);
}
예제 #5
0
void Document::print()
{
	QPrinter printer;
	printer.setPageSize(QPrinter::Letter);
	printer.setPageMargins(0.5, 0.5, 0.5, 0.5, QPrinter::Inch);
	QPrintDialog dialog(&printer, this);
	if (dialog.exec() == QDialog::Accepted) {
		m_text->print(&printer);
	}
}
예제 #6
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;
}
예제 #7
0
void CodeEditor::handlePrint()
{
	ENABLED_IF( true );

	QPrinter p;
	p.setPageMargins( 15, 10, 10, 10, QPrinter::Millimeter );

	QPrintDialog dialog( &p, this );
	if( dialog.exec() )
	{
		print( &p );
	}
}
예제 #8
0
void Document::print()
{
	QPrinter printer;
	printer.setPageSize(QPrinter::Letter);
	printer.setPageMargins(0.5, 0.5, 0.5, 0.5, QPrinter::Inch);
	QPrintDialog dialog(&printer, this);
	if (dialog.exec() == QDialog::Accepted) {
		bool enabled = m_highlighter->enabled();
		m_highlighter->setEnabled(false);
		m_text->print(&printer);
		if (enabled) {
			m_highlighter->setEnabled(true);
		}
	}
}
예제 #9
0
void CompareDialog::on_printFileButton_clicked()
{
  QPrinter printer;
  QString filename = QFileDialog::getSaveFileName(this, tr("Select PDF output file"), QString(), "Pdf File(*.pdf)");
  printer.setPageMargins(10.0, 10.0, 10.0, 10.0, printer.Millimeter);
  printer.setOutputFormat(QPrinter::PdfFormat);
  printer.setOrientation(QPrinter::Landscape);
  printer.setColorMode(QPrinter::Color);
  if (!filename.isEmpty()) {
    if (QFileInfo(filename).suffix().isEmpty())
      filename.append(".pdf");
    printer.setOutputFileName(filename);
    ui->textEdit->print(&printer);
  }
}
예제 #10
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();
}
/*!
  \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
}
예제 #12
0
void WMain::printChecker()
{
    // Preparing.
    QPrinter printer;
    printer.setOrientation(QPrinter::Landscape);
    QPrintDialog dialog(&printer, this);

    // Setting up margins.
    printer.setPageMargins(12.5, 12.5, 12.5, 12.5, QPrinter::Millimeter);

    // Printing.
    if (dialog.exec() == QDialog::Accepted)
    {
        QPainter painter(&printer);
        painter.drawPixmap(0, 0, checker);
        painter.end();
    }
}
예제 #13
0
void PrintDialog::printToFile()
{
  if (printfilename.isEmpty())
    return;
  if (! (printfilename.endsWith(".odt", Qt::CaseInsensitive) || printfilename.endsWith(".pdf", Qt::CaseInsensitive) || printfilename.endsWith(".htm", Qt::CaseInsensitive) || printfilename.endsWith(".html", Qt::CaseInsensitive)) )
    printfilename += ".pdf"; // default
  if (printfilename.endsWith(".pdf", Qt::CaseInsensitive)) {
    QPrinter printer;
    printer.setPageMargins(10.0,10.0,10.0,10.0,printer.Millimeter);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setColorMode(QPrinter::Color);
    printer.setOutputFileName(printfilename);
    ui->textEdit->print(&printer);
  }
  else {
    QTextDocumentWriter writer(printfilename);
    writer.write(ui->textEdit->document());
  }
}
예제 #14
0
void PrintDialog::on_printFileButton_clicked()
{
  QString fn = QFileDialog::getSaveFileName(this,tr("Select PDF output file"),QString(),tr("ODF files (*.odt);;PDF Files(*.pdf);;HTML-Files (*.htm *.html);;All Files (*)"));
  if (fn.isEmpty())
    return;
  if (! (fn.endsWith(".odt", Qt::CaseInsensitive) || fn.endsWith(".pdf", Qt::CaseInsensitive) || fn.endsWith(".htm", Qt::CaseInsensitive) || fn.endsWith(".html", Qt::CaseInsensitive)) )
    fn += ".pdf"; // default
  if (fn.endsWith(".pdf", Qt::CaseInsensitive)) {
    QPrinter printer;
    printer.setPageMargins(10.0,10.0,10.0,10.0,printer.Millimeter);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setColorMode(QPrinter::Color);
    printer.setOutputFileName(fn);
    ui->textEdit->print(&printer);
  }
  else {
    QTextDocumentWriter writer(fn);
     writer.write(ui->textEdit->document());
  }
}
예제 #15
0
void CodeEditor::handleExportPdf()
{
	ENABLED_IF( true );

	QString fileName = QFileDialog::getSaveFileName(this, tr("Export PDF"), QString(), tr("*.pdf") );
	if (fileName.isEmpty())
		return;

	QFileInfo info( fileName );

	if( info.suffix().toUpper() != "PDF" )
		fileName += ".pdf";
	info.setFile( fileName );

	QPrinter p;
	p.setPageMargins( 15, 10, 10, 10, QPrinter::Millimeter );
	p.setOutputFormat(QPrinter::PdfFormat);
	p.setOutputFileName(fileName);

	print( &p );
}
예제 #16
0
void MainWindow::on_pushButton_clicked()
{
    int current_tab = this->ui->tabWidget->currentIndex();

    QPrinter printer;
    QTableView *myWidget;

    switch(current_tab)
    {
    case TABLE::StudentsTableTab:
        myWidget = this->ui->StudentsTableView;
        break;

    case TABLE::TeachersTableTab:
        myWidget = this->ui->TeachersTableView;
        break;
    default:
        return;
    }

    QPixmap pix = myWidget->grab();
    QPainter painter;
    printer.setResolution(QPrinter::HighResolution);

    printer.setPageMargins (15,15,15,15,QPrinter::Millimeter);
    painter.begin(&printer);
    double xscale = printer.pageRect().width()/double(myWidget->width() + 50);
    double yscale = printer.pageRect().height()/double(myWidget->height() + 50);
    double scale = qMin(xscale, yscale);
    painter.scale(scale, scale);

    painter.drawPixmap(0, 0, pix);
    painter.end();

    myWidget->render(&painter);

}
예제 #17
0
//BEGIN KatePrinter
void KatePrinter::readSettings(QPrinter& printer)
{
  // NOTE: Saving & loading the margins works around QPrinter/QPrintDialog bugs:
  // - https://bugreports.qt.nokia.com/browse/QTBUG-15351
  // - https://bugs.kde.org/show_bug.cgi?id=205802
  // - https://bugs.kde.org/show_bug.cgi?id=180051
  // Changing the margins now works. However, when you reopen the print dialog
  // later, the WRONG margins are displayed. The correct ones are still used.
  // This is a critical bug in Qt.

  KSharedConfigPtr config = KGlobal::config();
  KConfigGroup group(config, "Kate Print Settings");
  KConfigGroup margins(&group, "Margins");

  qreal left, right, top, bottom;
  printer.getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);

  left = margins.readEntry("left", left);
  top = margins.readEntry("top", top);
  right = margins.readEntry("right", right);
  bottom = margins.readEntry("bottom", bottom);

  printer.setPageMargins(left, top, right, bottom, QPrinter::Millimeter);
}
예제 #18
0
void SceneImageExporter::GraphicsSceneToPrinter(
        QGraphicsScene *scene, QPrinter& printer,
        QString fileName, QString documentName __attribute__((unused)),
        bool bSizeToOneSheet)
{
    if (!fileName.isEmpty() && fileName != "" && fileName.endsWith(".pdf",Qt::CaseInsensitive))
    {
        printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setOutputFileName(fileName);
    }

    // When printing, use full page mode, IE ignore hardware margins. It's up
    // to users to set them as they desire.
    printer.setFullPage(true);
    printer.setPaperSize(QSizeF(PrintingPreferences::prefs().selectedMeasure().width(),
                                PrintingPreferences::prefs().selectedMeasure().height()),
                         QPrinter::Millimeter);
    printer.setPageMargins(PrintingPreferences::prefs().leftMargin(),
                           PrintingPreferences::prefs().topMargin(),
                           PrintingPreferences::prefs().rightMargin(),
                           PrintingPreferences::prefs().bottomMargin(),
                           QPrinter::Millimeter);


    if (!bSizeToOneSheet) {

        //here, I print using selected sheets and divisions.
        QPainter painter(&printer);
        qreal left,top,right,bottom;
        printer.getPageMargins(&left,&top,&right,&bottom,QPrinter::DevicePixel);

        // get the FULL PAGE RECTANGLE and adjust margins.
        QRectF pageRect = printer.paperRect();
        pageRect.adjust(left,top,-right, -bottom);


        //get height/width page rect ratio
        double pageRatio = pageRect.width()/pageRect.height();

        //get scene rectangle and calculating pages.
        int stepY = PrintingPreferences::prefs().yDivisions();
        QRectF sceneRect = scene->sceneRect();
        double scene_dy = sceneRect.height()/( (double)stepY);
        double scene_dx = scene_dy * pageRatio;


        double o_scene_dx = scene_dx * 1.1;
        double o_scene_dy = scene_dy * 1.1;

        double o_rect_dx = pageRect.width() / 1.1;
        double o_rect_dy = pageRect.height() / 1.1;

        double odx = ( pageRect.width() -o_rect_dx)/2.0;
        double ody = (pageRect.height() - o_rect_dy)/ 2.0;

        QRectF pageRectInner = QRectF (pageRect.left() + odx,
                                       pageRect.top() + ody,
                                       o_rect_dx, o_rect_dy);

        int stepX = 1+ (int)(sceneRect.width() / scene_dx);

        //ok, calculated my boxes. NOW, let's print everything out.
        QColor transparent(0,0,0,0);
        QColor transBorder (0,0,0,128);
        QPen pen (transBorder);
        pen.setStyle(Qt::DotLine);
        QBrush brush(transparent);

        bool bNewPage = false;

        for (int y = 0; y < stepY; y++) {
            for (int x = 0; x < stepX; x++) {
                if (bNewPage)
                    printer.newPage();
                else
                    bNewPage = true;

                //I've already got my target rectangle
                QRectF sourceRect = QRectF (
                        sceneRect.left()+((double)x * scene_dx  + (o_scene_dx - scene_dx)/2.0 ),
                        sceneRect.top()+((double)y * scene_dy + (o_scene_dy - scene_dy)/2.0),
                        o_scene_dx,o_scene_dy);


                scene->render(&painter,pageRect, sourceRect);

                QBrush oldBrush = painter.brush();
                QPen oldPen = painter.pen();

                //qDebug() << "pageRect " << pageRect;
                //qDebug() << "pageRectInner " << pageRectInner;

                painter.setPen(pen);
                painter.setBrush(brush);
                painter.drawRect(pageRect);
                painter.drawRect(pageRectInner);

                painter.setPen(oldPen);
                painter.setBrush(oldBrush);

            }
        }
        painter.end();
    }
    else {
        QRectF sceneRect = scene->sceneRect();
        //qDebug() << "scene Rect:" << sceneRect;
        printer.setResolution(96);
        printer.setPaperSize(QSizeF (
                scene->sceneRect().width()+(76*2),
                scene->sceneRect().height()+(76*2)), QPrinter::DevicePixel);

        printer.setFullPage(true);
        printer.setPageMargins( 76.0,76.0,76.0,76.0, QPrinter::DevicePixel);
        QPainter painter(&printer);
        qreal left,top,right,bottom;
        printer.getPageMargins(&left,&top,&right,&bottom,QPrinter::DevicePixel);
        QRectF pageRect = printer.paperRect();

        //qDebug() << "pageRect: " << pageRect;

        pageRect = pageRect.adjusted(left,top,-right,-bottom);

        //qDebug() << "pageRect: " << pageRect;
        //qDebug() << "sceneRect: " << sceneRect;

        scene->render(&painter,pageRect, sceneRect, Qt::IgnoreAspectRatio);

        //qDebug() << left << "," << right << "," << top << "," << bottom;
        //qDebug() << printer.paperRect().left() << ","
        //        << printer.paperRect().width() << ","
        //        << printer.paperRect().top() << ","
        //        << printer.paperRect().height();
        pageRect = printer.pageRect();
        //qDebug() << pageRect.left() << ","
        //        << pageRect.width() << ","
        //        << pageRect.top() << ","
        //        << pageRect.height();

        QColor transparent(0,0,0,0);
        QColor transBorder (0,0,0,128);
        QPen pen (transBorder);
        pen.setStyle(Qt::DotLine);
        QBrush brush(transparent);

        painter.setPen(pen);
        painter.setBrush(brush);
        painter.drawRect(pageRect);
        painter.end();
    }
}
예제 #19
0
//-----------------------------------------------------------
void CenaObjetos::definirGrade(unsigned tam)
{
 if(tam >= 20 || grade.style()==Qt::NoBrush)
 {
  QImage img_grade;
  float larg, alt, x, y;
  QSizeF tam_aux;
  QPrinter printer;
  QPainter painter;
  QPen pen;

  //Caso o tamanho do papel não seja personalizado
  if(tam_papel!=QPrinter::Custom)
  {
   //Configura um dispositivo QPrinter para obter os tamanhos de página
   printer.setPageSize(tam_papel);
   printer.setOrientation(orientacao_pag);
   printer.setPageMargins(margens_pag.left(), margens_pag.top(),
                          margens_pag.right(), margens_pag.bottom(), QPrinter::Millimeter);
   tam_aux=printer.pageRect(QPrinter::DevicePixel).size();
  }
  //Caso o tipo de papel seja personalizado, usa as margens como tamanho do papel
  else
   tam_aux=margens_pag.size();


  larg=fabs(roundf(tam_aux.width()/static_cast<float>(tam)) * tam);
  alt=fabs(roundf(tam_aux.height()/static_cast<float>(tam)) * tam);

  //Cria uma instância de QImage para ser a textura do brush
  tam_grade=tam;
  img_grade=QImage(larg, alt, QImage::Format_ARGB32);

  //Aloca um QPaointer para executar os desenhos sobre a imagem
  painter.begin(&img_grade);

  //Limpa a imagem
  painter.fillRect(QRect(0,0,larg,alt), QColor(255,255,255));

  if(exibir_grade)
  {
   //Cria a grade
   pen.setColor(QColor(225, 225, 225));
   painter.setPen(pen);

   for(x=0; x < larg; x+=tam)
    for(y=0; y < alt; y+=tam)
     painter.drawRect(QRectF(QPointF(x,y),QPointF(x + tam,y + tam)));
  }

  //Cria as linhas que definem o limite do papel
  if(exibir_lim_pagina)
  {
   pen.setColor(QColor(75,115,195));
   pen.setStyle(Qt::DashLine);
   pen.setWidthF(1.85f);
   painter.setPen(pen);
   painter.drawLine(larg-1, 0,larg-1,alt-1);
   painter.drawLine(0, alt-1,larg-1,alt-1);
  }

  painter.end();
  grade.setTextureImage(img_grade);
 }
}
예제 #20
0
void QPrinterProto::setPageMargins(qreal left, qreal top, qreal right, qreal bottom, QPrinter::Unit unit)
{
  QPrinter *item = qscriptvalue_cast<QPrinter*>(thisObject());
  if (item)
    item->setPageMargins(left, top, right, bottom, unit);
}
예제 #21
0
void TSController::printReport()
{
    //    qDebug()<<"TSController::printReport";
    QPrinter printer;
    QPrintDialog *dialog = new QPrintDialog(&printer, this);
    dialog->setWindowTitle(tr("Предварительный просмотр"));

    int endIndex=curveBuffer->lenght;

    float listh=printer.widthMM()*printer.resolution()/25.4-60;
    float listw=printer.heightMM()*printer.resolution()/25.4-60;
    printer.setPageMargins(5,5,5,5,QPrinter::Millimeter);
    printer.setOrientation(QPrinter::Landscape);
    printer.setResolution(QPrinter::HighResolution);
    printer.setPaperSize(QPrinter::A4);
    Ui::Form pf;

    pf.setupUi(&wpf);
    pf.mainBox->setMaximumSize((int)listw,(int)listh);
    pf.mainBox->setMinimumSize((int)listw,(int)listh);
    pf.resultsTable->setMinimumWidth(40+(int)listw/3);
    pf.resultsTable->setRowCount(13);
    pf.resultsTable->setColumnCount(2);
    pf.resultsTable->verticalHeader()->setVisible(false);
    pf.resultsTable->setHorizontalHeaderLabels(QString(tr("Параметр; Значение")).split(";"));
    pf.resultsTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
    int i=0,j=0;
    for(i=0;i<ui->resultsTable->rowCount();i++){
        for(j=0;j<2;j++){
            pf.resultsTable->setItem(i,j,getQTableWidgetItem(ui->resultsTable->item(i,j)->text()));
        }
    }
    int myH=0,myW=0;
    wpf.resize(pf.mainBox->size());
    wpf.show();

    myH = pf.gVolume->height();
    myW = pf.gVolume->width();

    QPixmap pmTempIn(myW,myH);
    QPixmap pmTempOut(myW,myH);
    QPixmap pmVolume(myW,myH);

    QPainter prTempIn;
    QPainter prTempOut;
    QPainter prVolume;
    prTempIn.begin(&pmTempIn);
    prTempOut.begin(&pmTempOut);
    prVolume.begin(&pmVolume);

    int h = pf.gVolume->height()/2;
    int step = h/10;
    if(h%10>=5)
    {
        h+=step/2;
    }
    prVolume.fillRect(0,0,myW,myH,Qt::white);
    prTempIn.fillRect(0,0,myW,myH,Qt::white);
    prTempOut.fillRect(0,0,myW,myH,Qt::white);

    prVolume.setPen(QColor(225,225,225));
    prTempIn.setPen(QColor(225,225,225));
    prTempOut.setPen(QColor(225,225,225));
    for(i=step;i<h;i+=step)
    {
        prVolume.drawLine(0,h+i,myW,h+i);
        prTempIn.drawLine(0,h+i,myW,h+i);
        prTempOut.drawLine(0,h+i,myW,h+i);
        prVolume.drawLine(0,h-i,myW,h-i);
        prTempIn.drawLine(0,h-i,myW,h-i);
        prTempOut.drawLine(0,h-i,myW,h-i);
    }
    for(i=10;i<myW;i+=10)
    {
        prVolume.drawLine(i,0,i,h<<1);
        prTempIn.drawLine(i,0,i,h<<1);
        prTempOut.drawLine(i,0,i,h<<1);
    }
    prVolume.setPen(QColor(0,0,0));
    prTempIn.setPen(QColor(0,0,0));
    prTempOut.setPen(curveBuffer->toutColor);
    prVolume.setPen(QColor(255,0,0));
    int* tinInt = curveBuffer->getTempInInterval();
    int* toutInt = curveBuffer->getTempOutInterval();
    int* volInt = curveBuffer->getVolumeInterval();
    float tempInK = 1;
    float tempOutK = 1;
    float tempInZ = h;
    float tempOutZ = h;
    tempInAdaptive = (float)myH/(tinInt[1]-tinInt[0]);
    tempOutAdaptive = (float)myH/(toutInt[1]-toutInt[0]);
    volumeAdaptive = (float)myH/(volInt[1]-volInt[0]);
    tempInZ = h + ceil((float)(tinInt[1]+tinInt[0])*tempInAdaptive*tempInK/2);
    tempOutZ = h + ceil((float)(toutInt[1]+toutInt[0])*tempOutAdaptive*tempOutK/2);
    float volumeK =1;

    i=0;
    int k=ceil((float)curveBuffer->lenght/pf.gTempIn->width());
    for(j=0;j<myW-35;j+=1)
    {
        if(i>=k*endIndex)break;
        prVolume.drawLine(
                    j,h-volumeK*volumeAdaptive*volume[i],j+1,h-volumeK*volumeAdaptive*volume[i+k]
                );
        prTempIn.drawLine(j,tempInZ-tempInK*tempInAdaptive*tempIn[i]
                          ,j+1,tempInZ-tempInK*tempInAdaptive*tempIn[i+k]);
        prTempOut.drawLine(j,tempOutZ-tempOutK*tempOutAdaptive*tempOut[i]
                           ,j+1,tempOutZ-tempOutK*tempOutAdaptive*tempOut[i+k]);
        i+=k;
    }
    pf.gVolume->setPixmap(pmVolume);
    pf.gTempIn->setPixmap(pmTempIn);
    pf.gTempOut->setPixmap(pmTempOut);
    pf.PatientName->setText(patientsModel->record(0).value("sname").toString()+" "+patientsModel->record(0).value("fname").toString());

    wpf.hide();
    if (dialog->exec() == QDialog::Accepted){
        QPainter painter;
        painter.begin(&printer);
        int i=0;
        pf.mainBox->render(&painter);
    }
}
예제 #22
0
void SceneImageExporter::printScene(QGraphicsScene *scene, QPrinter& printer,
                                    QString fileName, QString documentName,
                                    int printingFlags)
{

    if (!fileName.isEmpty() && fileName != "" && fileName.endsWith(".pdf",Qt::CaseInsensitive))
    {
        printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setOutputFileName(fileName);
    }
    else {
        //set page margins if I have to print on paper.
        printer.setPageMargins(10,10,10,10,QPrinter::Millimeter);
    }


    QPainter painter(&printer);

    QRectF sceneRect = scene->sceneRect();
    double sceneRatio = scene->sceneRect().width()/scene->sceneRect().height();
    qreal left,top,right,bottom;
    printer.getPageMargins(&left,&top,&right,&bottom,QPrinter::DevicePixel);
    QRect pageRect = QRect(
            printer.pageRect().top()+top,
            printer.pageRect().left()+left,
            printer.pageRect().width()-(left+right),
            printer.pageRect().height()-(top+bottom));

    int xSize, ySize, dxSize, dySize, xPages, yPages;
    double fWidth, fHeight, fHeightStep, fWidthStep;
    double pageRectRatio = (double)pageRect.width()/(double)pageRect.height();

    xSize = (int)((double)(3*pageRect.width()) * 1.0);
    ySize = (int)((double)(3*pageRect.height()) * .9);
    dxSize = (int)((double)(3*pageRect.width()) * .05);
    dySize = (int)((double)(3*pageRect.height()) * .05);

    xPages = 1+ (((int)sceneRect.width()) / xSize);
    yPages = 1+ (((int)sceneRect.height()) / ySize);

    if (SIEOptions::ScaleToSceneHeight(printingFlags)) {
        yPages = 1;
        xPages = 1+(int)( (double)yPages *sceneRatio);
        ySize = (int) ((double)scene->sceneRect().height()*.9);
        xSize = (int) ( (double)ySize * pageRectRatio);
        dySize = (int) (.05 * (double)scene->sceneRect().height()*.9);
        dxSize = (int) ( .05 *(double)ySize * pageRectRatio);

    }

    if (SIEOptions::ScaleToSceneWidth(printingFlags)) {
        xPages = 1;
        yPages = 1+(int)( (double)yPages / sceneRatio);
    }


    fWidth = 1.0* (double)pageRect.width();
    fHeight = .9* (double)pageRect.height();
    fHeightStep = .15* (double)pageRect.height();
    fWidthStep = fHeightStep * sceneRatio;

    bool bNewPage = false;
    double fWidth2 = fWidth * .9;
    double fHeight2 = fHeight * .9;

    QPainterPath path;
    QRectF rectOuter;
    rectOuter.setLeft((double)pageRect.left());
    rectOuter.setTop((double)pageRect.top());
    rectOuter.setWidth(fWidth2);
    rectOuter.setHeight(fHeight2);

    path.addRect(rectOuter);

    QRectF rectInner(rectOuter);
    rectInner.setTopLeft(QPointF(
            rectInner.left()+fWidth2/20,
            rectInner.top()+fHeight2/20));
    rectInner.setSize(QSizeF(fWidth2*.9,fHeight2*.9));
    path.addRect(rectInner);


    painter.begin(&printer);

    QBrush shadowBrush = QBrush(QColor(192,192,192,64));
    QBrush transparent = QBrush(QColor(192,192,192,16));
    //QPen pen = QPen(QColor (65,65,65,192));
    QPen pen = QPen(QColor (255,0,0,192));
    QFont font = QFont("Droid Sans");
    font.setBold(true);
    font.setPointSizeF(16.0);

    QFont fontb = QFont("Droid Sans");
    fontb.setBold(false);
    fontb.setPointSizeF(11.0);


    //double fh = fHeightStep / yPages;
    //double fw = fWidthStep / xPages;

    double tinyRectXRatio = fWidthStep / scene->sceneRect().width();
    double tinyRectYRatio = fHeightStep / scene->sceneRect().height();

    int nCur = 0;
    int nMax = yPages*xPages;

    for (int y = 0; y < yPages; y++) {
        for (int x = 0; x < xPages; x++) {
            nCur = (y*xPages)+(x+1);
            if (bNewPage)
                printer.newPage();
            else
                bNewPage = true;

            QRectF targetRect = QRectF((double)pageRect.left(),(double)pageRect.top(),fWidth2,fHeight2);

            QRectF sourceRect = QRectF (
                    (double)(x*xSize)+sceneRect.left()-(double)dxSize,
                    (double)(y*ySize)+sceneRect.top()-(double)dySize,
                    (double)(xSize)+2*(double)dxSize,
                    (double)(ySize)+2*(double)dySize);

            QRectF targetRect2 = QRectF(
                    (double)targetRect.left()+10,
                    (double)targetRect.top()+ fHeight2+10,
                    fWidthStep,
                    fHeightStep);

            QRectF tinyRect;
            tinyRect.setLeft((sourceRect.left()-sceneRect.left()) * tinyRectXRatio+targetRect2.left());
            tinyRect.setTop((sourceRect.top()-sceneRect.top()) * tinyRectYRatio+ targetRect2.top());
            tinyRect.setWidth(sourceRect.width()*tinyRectXRatio);
            tinyRect.setHeight(sourceRect.height()*tinyRectYRatio);


            scene->render(&painter,targetRect, sourceRect);
            painter.setPen(pen);
            painter.setBrush(transparent);
            painter.drawRect(targetRect2);

            scene->render(&painter,targetRect2, scene->sceneRect(), Qt::IgnoreAspectRatio);
            painter.setPen(pen);
            painter.setBrush(shadowBrush);
            painter.drawPath(path);
            painter.drawRect(tinyRect);

            QFontMetricsF metrics(font);

            int nDelta = 0;
            painter.setFont(font);
            painter.setBrush(QBrush(QColor("black")));
            painter.drawText(
                    targetRect2.left()+fWidthStep+10,
                    targetRect2.top()+metrics.height(),
                    documentName);

            nDelta+= (int)metrics.height()+10;

            painter.setFont(fontb);
            QFontMetricsF metricsb(fontb);
            nDelta+= (int)metricsb.height();
            QString txt = QString().sprintf("Folio [%d,%d] -- page %d of %d",x,y,nCur, nMax);
            painter.drawText(
                    targetRect2.left()+fWidthStep+10,
                    targetRect2.top()+nDelta,
                    txt);


        }
    }
    painter.end();
}
예제 #23
0
void PrintAPI::PrintA4(QString title, QString type, QList<QString> columnNames, QList<int> columnWidths,
                       QStringList content)
{
    //计算行数列数
    int columnCount = columnNames.count();
    int rowCount = content.count();

    //清空原有数据,确保每次都是新的数据
    html.clear();

    //表格开始
    html.append("<table border='0.5' cellspacing='0' cellpadding='3'>");

    //标题占一行,居中显示
    html.append(QString("<tr><td colspan='%1'>").arg(columnCount));
    html.append("<p align='center' style='vertical-align:middle;font-weight:bold;font-size:15px;'>");
    html.append(title);
    html.append("</p></td></tr>");

    //循环写入字段名,字段名占一行,居中显示
    html.append("<tr>");
    for (int i = 0; i < columnCount; i++) {
        html.append(QString("<td width='%1' bgcolor='lightgray'>").arg(columnWidths.at(i)));
        html.append("<p align='center' style='vertical-align:middle;'>");
        html.append(columnNames.at(i));
        html.append("</p></td>");
    }
    html.append("</tr>");

    //循环一行行构建数据
    for (int i = 0; i < rowCount; i++) {
        QStringList value = content.at(i).split(";");
        html.append("<tr>");
        for (int j = 0; j < columnCount; j++) {
            html.append(QString("<td width='%1'>").arg(columnWidths.at(j)));
            html.append(value.at(j));
            html.append("</td>");
        }
        html.append("</tr>");
    }

    html.append("</table>");

    //调用打印机打印
    QPrinter printer;
    //设置输出格式
    printer.setOutputFormat(QPrinter::NativeFormat);
    //设置纸张规格
    printer.setPageSize(QPrinter::A4);
    //设置横向纵向及页边距
    if (type == "横向") {
        printer.setOrientation(QPrinter::Landscape);
        printer.setPageMargins(10, 10, 10, 12, QPrinter::Millimeter);
    } else {
        printer.setOrientation(QPrinter::Portrait);
        printer.setPageMargins(10, 10, 10, 16, QPrinter::Millimeter);
    }

    QPrintPreviewDialog preview(&printer);
    preview.setWindowTitle("打印预览");
    connect(&preview, SIGNAL(paintRequested(QPrinter *)), this, SLOT(printView(QPrinter *)));
    preview.showMaximized();
    preview.exec();
}
예제 #24
0
void SceneImageExporter::PageGraphicsSceneToPrinter(QGraphicsScene *scene, QPrinter &printer,
                                                    QList<SectorRectHolder>& pageRegions, QString fileName,
                                                    QString documentName __attribute__((unused)))
{
    PrintingPreferences &pref  __attribute__ ((unused))  = PrintingPreferences::prefs();
    //qDebug()  << pref.yDivisions();
    //qDebug()  << pref.selectedMeasure();
    //qDebug() << pref.measures();

    if (!fileName.isEmpty() && fileName != "" && fileName.endsWith(".pdf",Qt::CaseInsensitive))
    {
        printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setOutputFileName(fileName);
    }

    // When printing, use full page mode, IE ignore hardware margins. It's up
    // to users to set them as they desire.
    printer.setFullPage(true);
    printer.setPaperSize(QSizeF(PrintingPreferences::prefs().selectedMeasure().width(),
                                PrintingPreferences::prefs().selectedMeasure().height()),
                         QPrinter::Millimeter);
    printer.setPageMargins(PrintingPreferences::prefs().leftMargin(),
                           PrintingPreferences::prefs().topMargin(),
                           PrintingPreferences::prefs().rightMargin(),
                           PrintingPreferences::prefs().bottomMargin(),
                           QPrinter::Millimeter);

    //here, I print using selected sheets and divisions.
    QPainter painter(&printer);
    qreal left,top,right,bottom;
    printer.getPageMargins(&left,&top,&right,&bottom,QPrinter::DevicePixel);

    // get the FULL PAGE RECTANGLE and adjust margins.
    QRectF pageRect = printer.paperRect();
    pageRect.adjust(left,top,-right, -bottom);


    QColor transparent(0,0,0,0);
    QColor transBorder (0,0,0,128);
    QPen pen (transBorder);
    pen.setStyle(Qt::DotLine);
    QBrush brush;

    QGraphicsScene sceneFirst;
    QPen pen2 (QColor(0,0,0));
    pen2.setStyle(Qt::DotLine);
    pen2.setWidthF(2.0);
    QBrush brush2;
    for (int h = 0; h < pageRegions.count(); h++)
    {
        QRectF rect = pageRegions[h].rectInner();
        sceneFirst.addRect (rect.left(), rect.top(), rect.width(),rect.height(),pen2, brush2);
        rect = pageRegions[h].rectOuter();
        sceneFirst.addRect (rect.left(), rect.top(), rect.width(),rect.height(),pen2, brush2);
    }
    scene->render(&painter, pageRect, scene->itemsBoundingRect(),Qt::KeepAspectRatio);
    sceneFirst.render(&painter,pageRect, sceneFirst.sceneRect(),Qt::KeepAspectRatio);


    for (int h = 0; h < pageRegions.count(); h++)
    {
        QRectF rect = pageRegions[h].rectOuter();
        double ratio = rect.width()/rect.height();
        QRectF rectTarget = QRectF(pageRect.left(), pageRect.top(), pageRect.width(), pageRect.width()/ratio);
        printer.newPage();
        scene->render(&painter,rectTarget, rect);
        painter.setPen(pen2);
        painter.setBrush(brush);
        painter.drawRect(rectTarget);
        QRectF rect2 = pageRegions[h].rectInner();
        double ratioX = rectTarget.width()/rect.width();
        double ratioY = rectTarget.height()/rect.height();

        double dy = rect2.top()-rect.top();
        double dx = rect2.left() - rect.left();

        //qDebug() << "rect outer: " << rect
        //        <<  "\nrect inner: " << rect2
        //        << "\nrect target: " << rectTarget
        //        << "\nx: " << dx << ",y:" << dy;

        QRectF rectTarget2 (rectTarget.top()+ dx*ratioX,
                            rectTarget.left()+dy*ratioY,
                            rect2.width()*ratioX,
                            rect2.height()*ratioY);
        painter.drawRect(rectTarget2);

    }
    painter.end();
}