本文整理汇总了C++中QPrinter::newPage方法的典型用法代码示例。如果您正苦于以下问题:C++ QPrinter::newPage方法的具体用法?C++ QPrinter::newPage怎么用?C++ QPrinter::newPage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPrinter
的用法示例。
在下文中一共展示了QPrinter::newPage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: print
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
}
示例2: newPage
bool QPrinterProto::newPage()
{
QPrinter *item = qscriptvalue_cast<QPrinter*>(thisObject());
if (item)
return item->newPage();
return false;
}
示例3: CollectWidgets
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();
}
示例4: saveAsDocument
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();
}
示例5: filePrint
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++;
}
}
}
示例6: metrics
/*!
* \en
* Print browser content.
* \_en
* \ru
* Печатает содержимое браузера.
* \_ru
*/
void
aReportBrowser::print()
{
QPrinter printer;
QPainter p;
if (!printer.setup()) return;
if ( p.begin( &printer ) ){
QPaintDeviceMetrics metrics( p.device() );
int dpiy = metrics.logicalDpiY();
int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
QRect body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin );
QSimpleRichText richText( textBrowser->text(),
QFont(),
textBrowser->context(),
textBrowser->styleSheet(),
textBrowser->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);
}
}
示例7: printer
void MainWindow::on_pushButton_4_clicked()
{
QTextDocument doc;
QString txt;
txt = ::textAt(h3,65,"ASAP Film Order") %
::textAt(h3,40,"From C&C Special Products Co. 952-881-0073") %
::textAt(h3,67,"Mark Robin") %
::textAt(h3,6,"Attn: Customer Service") % ::nbsp(63) % "Rip Settings:"%
::textAt(h3,103,"1) Film Positives") %
::textAt(h3,103,"2) DO NOT TRAP") %
::textAt(h3,103,"3) Send Pre Separated") %
::textAt(h3,6,"Date: " % ui->dateEdit->text()) %
::textAt(h3,6,"File Name: " % ui->lineEdit_2->text());
qDebug() << "The memory used is: " << txt.capacity();
doc.setHtml(txt);
#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG)
QPrinter printer(QPrinter::HighResolution);
QPrintDialog *dlg = new QPrintDialog(&printer, this);
dlg->addEnabledOption(QAbstractPrintDialog::PrintSelection);
dlg->setWindowTitle(tr("Print Document"));
if (dlg->exec() == QDialog::Accepted)
{
QPrinter printer;
// printer.setOutputFileName("c:\\temp\\filenew.pdf");
// printer.setOutputFormat(QPrinter::PdfFormat);
qDebug() << "Sending to printer";
doc.print(&printer);
printer.newPage();
printer.setOutputFileName("c:\\temp\\faxASAP.pdf");
printer.setOutputFormat(QPrinter::PdfFormat);
qDebug() << "Creating PDF";
doc.print(&printer);
printer.newPage();
}
delete dlg;
#endif
}
示例8: print
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 );
}
}
}
示例9: saveOverlayPdf
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;
}
示例10: persistsDocument
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;
}
示例11: print
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
}
示例12: doPrint
void QgsComposition::doPrint( QPrinter& printer, QPainter& p )
{
//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 );
}
}
}
示例13: onActionExportToPdf
/*----------------------------------------------------------------------------*/
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();
}
示例14: exportAsPdf
bool Utils::exportAsPdf(const QString &fileName, const QJsonObject &contents) {
QTextDocument doc;
QString html;
QTextStream stream(&html);
stream << QString("<html><head><style type=\"text/css\">"
"h1 {color:red;} "
" "
"</style></head><body>");
stream << QString("<h1>%1</h1>").arg(contents["name"].toString());
stream << QString("<p>%1 <br>").arg(contents["totaltime"].toString());
stream << QString(tr("Difficulty: %1<br>")).arg(contents["difficulty"].toDouble()); // FIXME: how can I access the array?
stream << QString(tr("Restriction: %1</p>")).arg(contents["restriction"].toDouble());
stream << QString(tr("<h2>Ingredients</h2>"));
stream << "<ul>";
QJsonArray ingredients = contents["ingredients"].toArray();
for (int i = 0; i < ingredients.count(); i++) {
QJsonObject ingredient = ingredients[i].toObject();
stream << QString("<li>%1 %2 %3</li>").arg(ingredient["quantity"].toDouble())
.arg(ingredient["type"].toString(), ingredient["name"].toString());
}
stream << "</ul>";
stream << QString(tr("<h2>Directions</h2>"));
stream << QString("<p>%1</p>").arg(contents["directions"].toString());
stream << QString(tr("<h2>Photos</h2><br />"));
QJsonArray photos = contents["photos"].toArray();
for (int i = 0; i < photos.count(); i++)
stream << QString("<img src='%1' width=200 />").arg(photos[i].toString());
stream << QString("</body></html>");
doc.setHtml(html);
QPrinter printer;
printer.setOutputFileName(fileName);
printer.setOutputFormat(QPrinter::PdfFormat);
doc.print(&printer);
printer.newPage();
return true;
}
示例15: assert
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();
}