bool QPlatformPrintDevice::isValidPageLayout(const QPageLayout &layout, int resolution) const { // Check the page size is supported if (!supportedPageSize(layout.pageSize()).isValid()) return false; // Check the margins are valid QMarginsF pointMargins = layout.margins(QPageLayout::Point); QMarginsF printMargins = printableMargins(layout.pageSize(), layout.orientation(), resolution); return pointMargins.left() >= printMargins.left() && pointMargins.right() >= printMargins.right() && pointMargins.top() >= printMargins.top() && pointMargins.bottom() >= printMargins.bottom(); }
void ObjectsScene::configurePrinter(QPrinter *printer) { if(!printer) throw Exception(ERR_OPR_NOT_ALOC_OBJECT ,__PRETTY_FUNCTION__,__FILE__,__LINE__); if(paper_size!=QPrinter::Custom) printer->setPaperSize(paper_size); else { #if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) //The QTBUG-33645 is fixed on Qt 5.3 QPageLayout pl; QPageSize ps; ps=QPageSize(QSizeF(custom_paper_size.width(), custom_paper_size.height()), QPageSize::Point, QString(), QPageSize::ExactMatch); pl.setPageSize(ps); pl.setOrientation(page_orientation==QPrinter::Landscape ? QPageLayout::Landscape : QPageLayout::Portrait); printer->setPageSize(pl.pageSize()); #else #warning "Custom page size bug (QTBUG-33645) workaround for Qt 5.2 or lower. NOTE: This issue is fixed on Qt 5.3" printer->setPaperSize(QSizeF(custom_paper_size.height(), custom_paper_size.width()), QPrinter::Point); #endif } if(paper_size==QPrinter::Custom) { if(custom_paper_size.width() > custom_paper_size.height()) ObjectsScene::page_orientation=QPrinter::Landscape; else ObjectsScene::page_orientation=QPrinter::Portrait; } else printer->setOrientation(page_orientation); printer->setPageMargins(page_margins.left(), page_margins.top(), page_margins.width(), page_margins.height(), QPrinter::Millimeter); }
QDebug operator<<(QDebug dbg, const QPageLayout &layout) { QDebugStateSaver saver(dbg); if (layout.isValid()) { QString output = QStringLiteral("QPageLayout(%1, %2, l:%3 r:%4 t:%5 b:%6 %7)"); QString units; switch (layout.units()) { case QPageLayout::Millimeter: units = QStringLiteral("mm"); break; case QPageLayout::Point: units = QStringLiteral("pt"); break; case QPageLayout::Inch: units = QStringLiteral("in"); break; case QPageLayout::Pica: units = QStringLiteral("pc"); break; case QPageLayout::Didot: units = QStringLiteral("DD"); break; case QPageLayout::Cicero: units = QStringLiteral("CC"); break; } output = output.arg(layout.pageSize().name()) .arg(layout.orientation() == QPageLayout::Portrait ? QStringLiteral("Portrait") : QStringLiteral("Landscape")) .arg(layout.margins().left()) .arg(layout.margins().right()) .arg(layout.margins().top()) .arg(layout.margins().bottom()) .arg(units); dbg.nospace() << output; } else { dbg.nospace() << "QPageLayout()"; } return dbg; }