From d79fd9d6a900ec0e2e8451222519ee67413e31a1 Mon Sep 17 00:00:00 2001 From: Aapo Date: Tue, 19 Jan 2021 00:49:57 +0200 Subject: [PATCH] [TD] MDIViewPage: Add support for Qt5 automatic paper size handling with many new paper sizes possible. --- src/Mod/TechDraw/Gui/MDIViewPage.cpp | 59 +++++----------------------- src/Mod/TechDraw/Gui/MDIViewPage.h | 4 +- 2 files changed, 10 insertions(+), 53 deletions(-) diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.cpp b/src/Mod/TechDraw/Gui/MDIViewPage.cpp index 771814912d..b382fc56ac 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.cpp +++ b/src/Mod/TechDraw/Gui/MDIViewPage.cpp @@ -314,17 +314,21 @@ void MDIViewPage::attachTemplate(TechDraw::DrawTemplate *obj) m_view->setPageTemplate(obj); double width = obj->Width.getValue(); double height = obj->Height.getValue(); - m_paperSize = getPaperSize(int(round(width)),int(round(height))); + if (width > height) { #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 } @@ -496,17 +500,6 @@ void MDIViewPage::fixOrphans(bool force) } } } - - // Update all the QGIVxxxx - // WF: why do we do this? views should be keeping themselves up to date. -// const std::vector &upviews = m_view->getViews(); -// for(std::vector::const_iterator it = upviews.begin(); it != upviews.end(); ++it) { -// Base::Console().Message("TRACE - MDIVP::fixOrphans - updating a QGIVxxxx\n"); -// if((*it)->getViewObject()->isTouched() || -// forceUpdate) { -// (*it)->updateView(forceUpdate); -// } -// } } //NOTE: this doesn't add missing views. see fixOrphans() @@ -530,6 +523,7 @@ void MDIViewPage::redraw1View(TechDraw::DrawView* dv) } } } + void MDIViewPage::findMissingViews(const std::vector &list, std::vector &missing) { for(std::vector::const_iterator it = list.begin(); it != list.end(); ++it) { @@ -750,13 +744,9 @@ void MDIViewPage::print(QPrinter* printer) // a certain scaling effect can be observed and the content becomes smaller. QPaintEngine::Type paintType = printer->paintEngine()->type(); if (printer->outputFormat() == QPrinter::NativeFormat) { - int w = printer->widthMM(); - int h = printer->heightMM(); #if QT_VERSION >= 0x050300 - QPageSize::PageSizeId psPrtCalcd = getPaperSize(w, h); QPageSize::PageSizeId psPrtSetting = printer->pageLayout().pageSize().id(); #else - QPrinter::PaperSize psPrtCalcd = getPaperSize(w, h); QPrinter::PaperSize psPrtSetting = printer->paperSize(); #endif @@ -776,15 +766,7 @@ void MDIViewPage::print(QPrinter* printer) if (ret != QMessageBox::Yes) return; } - else if (doPrint && psPrtCalcd != m_paperSize) { - int ret = QMessageBox::warning(this, tr("Different paper size"), - tr("The printer uses a different paper size than the drawing.\n" - "Do you want to continue?"), - QMessageBox::Yes | QMessageBox::No); - if (ret != QMessageBox::Yes) - return; - } - else if (doPrint && psPrtSetting != m_paperSize) { + if (doPrint && psPrtSetting != m_paperSize) { int ret = QMessageBox::warning(this, tr("Different paper size"), tr("The printer uses a different paper size than the drawing.\n" "Do you want to continue?"), @@ -850,11 +832,8 @@ void MDIViewPage::print(QPrinter* printer) static_cast (blockConnection(false)); } -#if QT_VERSION >= 0x050300 -QPageSize::PageSizeId MDIViewPage::getPaperSize(int w, int h) const -#else +#if QT_VERSION < 0x050300 QPrinter::PaperSize MDIViewPage::getPaperSize(int w, int h) const -#endif { static const float paperSizes[][2] = { {210, 297}, // A4 @@ -889,49 +868,29 @@ QPrinter::PaperSize MDIViewPage::getPaperSize(int w, int h) const {279.4f, 431.8f} // Tabloid (29) causes trouble with orientation on PDF export }; -#if QT_VERSION >= 0x050300 - QPageSize::PageSizeId ps = QPageSize::Custom; -#else QPrinter::PaperSize ps = QPrinter::Custom; -#endif for (int i=0; i<30; i++) { if (std::abs(paperSizes[i][0]-w) <= 1 && std::abs(paperSizes[i][1]-h) <= 1) { -#if QT_VERSION >= 0x050300 - ps = static_cast(i); -#else ps = static_cast(i); -#endif break; } else //handle landscape & portrait w/h if (std::abs(paperSizes[i][0]-h) <= 1 && std::abs(paperSizes[i][1]-w) <= 1) { -#if QT_VERSION >= 0x050300 - ps = static_cast(i); -#else ps = static_cast(i); -#endif break; } } -#if QT_VERSION >= 0x050300 - if (ps == QPageSize::Ledger) { //check if really Tabloid - if (w < 431) { - ps = QPageSize::Tabloid; - } - } -#else if (ps == QPrinter::Ledger) { //check if really Tabloid if (w < 431) { ps = QPrinter::Tabloid; } } -#endif - return ps; } +#endif PyObject* MDIViewPage::getPyObject() { diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.h b/src/Mod/TechDraw/Gui/MDIViewPage.h index 9cf6864b05..69242c1af2 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.h +++ b/src/Mod/TechDraw/Gui/MDIViewPage.h @@ -128,9 +128,7 @@ protected: void contextMenuEvent(QContextMenuEvent *event); void closeEvent(QCloseEvent*); -#if QT_VERSION >= 0x050300 - QPageSize::PageSizeId getPaperSize(int w, int h) const; -#else +#if QT_VERSION < 0x050300 QPrinter::PaperSize getPaperSize(int w, int h) const; #endif