Skip to content

Commit

Permalink
[TD] MDIViewPage: Support printing/exporting arbitrary custom paper s…
Browse files Browse the repository at this point in the history
…izes for Qt5.
  • Loading branch information
aapo-aapo committed Jan 19, 2021
1 parent d79fd9d commit 4d40ab0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/Mod/TechDraw/Gui/MDIViewPage.cpp
Expand Up @@ -312,23 +312,23 @@ void MDIViewPage::closeEvent(QCloseEvent* ev)
void MDIViewPage::attachTemplate(TechDraw::DrawTemplate *obj)
{
m_view->setPageTemplate(obj);
double width = obj->Width.getValue();
double height = obj->Height.getValue();

if (width > height) {
pagewidth = obj->Width.getValue();
pageheight = obj->Height.getValue();
#if QT_VERSION >= 0x050300
m_paperSize = QPageSize::id(QSizeF(pagewidth, pageheight), QPageSize::Millimeter, QPageSize::FuzzyOrientationMatch);
#else
m_paperSize = getPaperSize(int(round(pagewidth)), int(round(pageheight)));
#endif
if (pagewidth > pageheight) {
#if QT_VERSION >= 0x050300
m_paperSize = QPageSize::id(QSizeF(height, width), QPageSize::Millimeter);
m_orientation = QPageLayout::Landscape;
#else
m_paperSize = getPaperSize(int(round(width)), int(round(height)));
m_orientation = QPrinter::Landscape;
#endif
} else {
#if QT_VERSION >= 0x050300
m_paperSize = QPageSize::id(QSizeF(width, height), QPageSize::Millimeter);
m_orientation = QPageLayout::Portrait;
#else
m_paperSize = getPaperSize(int(round(width)), int(round(height)));
m_orientation = QPrinter::Portrait;
#endif
}
Expand Down Expand Up @@ -686,7 +686,11 @@ void MDIViewPage::printPdf(std::string file)
#endif
}
#if QT_VERSION >= 0x050300
printer.setPageSize(QPageSize(m_paperSize));
if (m_paperSize == QPageSize::Custom) {
printer.setPageSize(QPageSize(QSizeF(pagewidth, pageheight), QPageSize::Millimeter));
} else {
printer.setPageSize(QPageSize(m_paperSize));
}
#else
printer.setPaperSize(m_paperSize);
#endif
Expand All @@ -698,7 +702,11 @@ void MDIViewPage::print()
QPrinter printer(QPrinter::HighResolution);
printer.setFullPage(true);
#if QT_VERSION >= 0x050300
printer.setPageSize(QPageSize(m_paperSize));
if (m_paperSize == QPageSize::Custom) {
printer.setPageSize(QPageSize(QSizeF(pagewidth, pageheight), QPageSize::Millimeter));
} else {
printer.setPageSize(QPageSize(m_paperSize));
}
printer.setPageOrientation(m_orientation);
#else
printer.setPaperSize(m_paperSize);
Expand All @@ -715,7 +723,11 @@ void MDIViewPage::printPreview()
QPrinter printer(QPrinter::HighResolution);
printer.setFullPage(true);
#if QT_VERSION >= 0x050300
printer.setPageSize(QPageSize(m_paperSize));
if (m_paperSize == QPageSize::Custom) {
printer.setPageSize(QPageSize(QSizeF(pagewidth, pageheight), QPageSize::Millimeter));
} else {
printer.setPageSize(QPageSize(m_paperSize));
}
printer.setPageOrientation(m_orientation);
#else
printer.setPaperSize(m_paperSize);
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/Gui/MDIViewPage.h
Expand Up @@ -169,6 +169,7 @@ public Q_SLOTS:
QPrinter::Orientation m_orientation;
QPrinter::PaperSize m_paperSize;
#endif
qreal pagewidth, pageheight;
ViewProviderPage *m_vpPage;

QList<QGraphicsItem*> m_qgSceneSelected; //items in selection order
Expand Down

0 comments on commit 4d40ab0

Please sign in to comment.