From 3ca81a79163ea53cfbcad78f8fdebf9f90e2acf2 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Mon, 12 Sep 2022 15:07:38 -0400 Subject: [PATCH] [TD]fix PrintAll output to printer --- src/Mod/TechDraw/App/DrawPage.cpp | 17 ++++++++++ src/Mod/TechDraw/App/DrawPage.h | 1 + src/Mod/TechDraw/Gui/MDIViewPage.cpp | 46 +++++++++++++--------------- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawPage.cpp b/src/Mod/TechDraw/App/DrawPage.cpp index ef36bd1fae..e7f1f3bdea 100644 --- a/src/Mod/TechDraw/App/DrawPage.cpp +++ b/src/Mod/TechDraw/App/DrawPage.cpp @@ -235,6 +235,7 @@ double DrawPage::getPageHeight() const throw Base::RuntimeError("Template not set for Page"); } +//orientation as text const char * DrawPage::getPageOrientation() const { App::DocumentObject *obj; @@ -250,6 +251,22 @@ const char * DrawPage::getPageOrientation() const throw Base::RuntimeError("Template not set for Page"); } +//orientation as 0(Portrait) or 1(Landscape) +int DrawPage::getOrientation() const +{ + App::DocumentObject *obj; + obj = Template.getValue(); + + if(obj) { + if(obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) { + TechDraw::DrawTemplate *templ = static_cast(obj); + + return templ->Orientation.getValue(); + } + } + throw Base::RuntimeError("Template not set for Page"); +} + int DrawPage::addView(App::DocumentObject *docObj) { if(!docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) diff --git a/src/Mod/TechDraw/App/DrawPage.h b/src/Mod/TechDraw/App/DrawPage.h index cc49ef77e2..df51c2f431 100644 --- a/src/Mod/TechDraw/App/DrawPage.h +++ b/src/Mod/TechDraw/App/DrawPage.h @@ -91,6 +91,7 @@ public: */ double getPageHeight() const; const char* getPageOrientation() const; + int getOrientation() const; bool isUnsetting() { return nowUnsetting; } void requestPaint(); std::vector getAllViews() ; diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.cpp b/src/Mod/TechDraw/Gui/MDIViewPage.cpp index ceb5bf1910..997b1b0460 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.cpp +++ b/src/Mod/TechDraw/Gui/MDIViewPage.cpp @@ -310,6 +310,7 @@ void MDIViewPage::printPdf(std::string file) void MDIViewPage::print() { +// Base::Console().Message("MDIVP::print()\n"); getPaperAttributes(); QPrinter printer(QPrinter::HighResolution); @@ -349,6 +350,7 @@ void MDIViewPage::printPreview() void MDIViewPage::print(QPrinter* printer) { +// Base::Console().Message("MDIVP::print(printer)\n"); getPaperAttributes(); // As size of the render area paperRect() should be used. When performing a real @@ -441,8 +443,7 @@ void MDIViewPage::print(QPrinter* printer) void MDIViewPage::printAll(QPrinter* printer, App::Document* doc) { -// Base::Console().Message("MDIVP::printAll(printer, doc)\n"); - + QPainter painter; std::vector docObjs = doc->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); bool firstTime = true; for (auto& obj: docObjs) { @@ -460,32 +461,28 @@ void MDIViewPage::printAll(QPrinter* printer, if (!vpp) { continue; // can't print this one } + + App::DocumentObject* objTemplate = dp->Template.getValue(); + auto pageTemplate( dynamic_cast(objTemplate) ); + double width = 297.0; //default to A4 Landscape 297 x 210 + double height = 210.0; + if( pageTemplate ) { + width = pageTemplate->Width.getValue(); + height = pageTemplate->Height.getValue(); + } + + printer->setPageSize(QPageSize(QSizeF(width, height), QPageSize::Millimeter, QString(), QPageSize::FuzzyOrientationMatch)); + printer->setOrientation((QPrinter::Orientation) dp->getOrientation()); + QRectF sourceRect(0.0, Rez::guiX(-height), Rez::guiX(width), Rez::guiX(height)); + QRect targetRect = printer->pageLayout().fullRectPixels(printer->resolution()); + bool saveState = vpp->getFrameState(); vpp->setFrameState(false); vpp->setTemplateMarkers(false); vpp->getQGSPage()->refreshViews(); - - App::DocumentObject* objTemplate = dp->Template.getValue(); - auto pageTemplate( dynamic_cast(objTemplate) ); - double width = 0.0; - double height = 0.0; - if( pageTemplate ) { - width = pageTemplate->Width.getValue(); - height = pageTemplate->Height.getValue(); - } - QPageSize paperSize(QSizeF(width, height), QPageSize::Millimeter); - printer->setPageSize(paperSize); - QPageLayout::Orientation orientation = QPageLayout::Portrait; - if (width > height) { - orientation = QPageLayout::Landscape; - } - printer->setPageOrientation(orientation); - - QRectF sourceRect(0.0,-height,width,height); - QRect targetRect = printer->pageLayout().fullRectPixels(printer->resolution()); - QPainter p(printer); - vpp->getQGSPage()->render(&p, targetRect,sourceRect); - + painter.begin(printer); + vpp->getQGSPage()->render(&painter, targetRect, sourceRect); + painter.end(); // Reset vpp->setFrameState(saveState); vpp->setTemplateMarkers(saveState); @@ -493,7 +490,6 @@ void MDIViewPage::printAll(QPrinter* printer, } } - PyObject* MDIViewPage::getPyObject() { if (!pythonObject)