示例#1
0
void MainWindow::printAllSheets()
{
    QPrinter printer(QPrinter::HighResolution);

    QPrintDialog dialog(&printer);
    dialog.addEnabledOption(QAbstractPrintDialog::PrintPageRange);
    dialog.setMinMax(1, INT_MAX);

    if (dialog.exec() != QPrintDialog::Accepted)
        return;

    preparePrinter(&printer);

    QPainter painter(&printer);
    painter.setRenderHint(QPainter::Antialiasing);

    currentSheetNumber = -1;
    ui->toolBar->actions()[ToolButton::Next]->setEnabled(true);
    ui->svgView->hideBorders(true);

    while (ui->toolBar->actions()[ToolButton::Next]->isEnabled()) //while "Next Sheet" tool button is enabled,
    {                                                             //i.e. while printing all sheets
        renderNextSheet();

        if (printer.fromPage() != 0 && printer.fromPage() > currentSheetNumber + 1)
            continue;
        if (printer.toPage() != 0 && printer.toPage() < currentSheetNumber + 1)
            continue;

        QImage image = ui->svgView->saveRenderToImage();

        if (image.format() == QImage::Format_Invalid || !printer.isValid())
            return;

        painter.drawImage(0, 0, image);

        if (ui->toolBar->actions()[ToolButton::Next]->isEnabled() //if "Next Sheet" tool button is enabled,
               && (printer.toPage() != 0                          //i.e this sheet is not the last,
                   && currentSheetNumber + 1 < printer.toPage())) //and we're not going out of page range
            printer.newPage();                                    //defined by user
    }

    painter.end();
    ui->svgView->hideBorders(false);

    //we used renderNextSheet() for the first sheet instead of renderFirstSheet()
    //so we need to check the number of sheet and disable previous toolbutton if needed
    if (currentSheetNumber == 0)
        ui->toolBar->actions()[ToolButton::Previous]->setDisabled(true);
}
示例#2
0
void MainWindow::printAllSheets(QPrinter *printer)
{
    if (printer->outputFormat() != QPrinter::PdfFormat)
    {
        QPrintDialog dialog(printer);
        if (dialog.exec() != QPrintDialog::Accepted)
            return;
    }

    preparePrinter(printer);

    QPainter painter(printer);
    painter.setRenderHint(QPainter::Antialiasing);

    currentSheetNumber = -1;
    ui->toolBar->actions()[4]->setEnabled(true); //enable "Next Sheet" tool button

    while (ui->toolBar->actions()[4]->isEnabled())//while "Next Sheet" tool button is enabled,
    {                                             //i.e. print all sheets
        renderNextSheet();
        ui->svgView->hideBorders(true);
        QImage image = ui->svgView->saveRenderToImage();
        if (image.format() == QImage::Format_Invalid || !printer->isValid())
        {
            delete printer;
            return;
        }
        painter.drawImage(0, 0, image);

        if (ui->toolBar->actions()[4]->isEnabled()) //if "Next Sheet" tool button is disabled,
            printer->newPage();                      //i.e this sheet is the last
    }

    painter.end();
    ui->svgView->hideBorders(false);

    delete printer;

    if (currentSheetNumber == 0)
        ui->toolBar->actions()[5]->setDisabled(true); //disable "Previous Sheet" tool button
}
示例#3
0
void MainWindow::printSheet()
{
    QPrinter printer(QPrinter::HighResolution);
    QPrintDialog dialog(&printer);
    if (dialog.exec() != QPrintDialog::Accepted)
        return;

    preparePrinter(&printer);

    QPainter painter(&printer);
    painter.setRenderHint(QPainter::Antialiasing);

    ui->svgView->hideBorders(true);
    QImage image = ui->svgView->saveRenderToImage();
    ui->svgView->hideBorders(false);

    if (image.format() == QImage::Format_Invalid || !printer.isValid())
        return;

    painter.drawImage(0, 0, image);
    painter.end();
}
示例#4
0
void MainWindow::saveAllSheetsToPDF(const QString &fileName)
{
    QPrinter printer(QPrinter::PrinterResolution);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setOutputFileName(fileName);
    preparePrinter(&printer);

    QPainter painter(&printer);
    painter.setRenderHint(QPainter::Antialiasing);

    currentSheetNumber = -1;
    ui->toolBar->actions()[ToolButton::Next]->setEnabled(true);
    ui->svgView->hideBorders(true);

    while (ui->toolBar->actions()[ToolButton::Next]->isEnabled()) //while "Next Sheet" tool button is enabled,
    {                                                             //i.e. while printing all sheets
        renderNextSheet();

        QImage image = ui->svgView->saveRenderToImage();

        if (image.format() == QImage::Format_Invalid || !printer.isValid())
            return;

        painter.drawImage(0, 0, image);

        if (ui->toolBar->actions()[ToolButton::Next]->isEnabled()) //if "Next Sheet" tool button is enabled,
            printer.newPage();                                     //i.e this sheet isn't the last one
    }

    painter.end();
    ui->svgView->hideBorders(false);

    //we used renderNextSheet() for the first sheet instead of renderFirstSheet()
    //so we need to check the number of sheet and disable previous toolbutton if needed
    if (currentSheetNumber == 0)
        ui->toolBar->actions()[ToolButton::Previous]->setDisabled(true);
}