diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index effd540a80..8c9e2a8ae6 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -82,12 +82,12 @@ #include #include #include +#include #include "DrawGuiUtil.h" #include "QGSPage.h" #include "QGVPage.h" #include "MDIViewPage.h" -#include "PreferencesGui.h" #include "QGIViewPart.h" #include "Rez.h" #include "TaskProjGroup.h" @@ -285,6 +285,35 @@ bool CmdTechDrawRedrawPage::isActive() return (havePage && haveView); } +//=========================================================================== +// TechDraw_PrintAll +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawPrintAll) + +CmdTechDrawPrintAll::CmdTechDrawPrintAll() + : Command("TechDraw_PrintAll") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Print All Pages"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_PrintAll"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_PrintAll"; +} + +void CmdTechDrawPrintAll::activated(int iMsg) +{ + Q_UNUSED(iMsg); + MDIViewPage::printAllPages(); +} + +bool CmdTechDrawPrintAll::isActive() +{ + return DrawGuiUtil::needPage(this); +} + //=========================================================================== // TechDraw_View //=========================================================================== @@ -1494,6 +1523,7 @@ void CreateTechDrawCommands() rcCmdMgr.addCommand(new CmdTechDrawPageDefault()); rcCmdMgr.addCommand(new CmdTechDrawPageTemplate()); rcCmdMgr.addCommand(new CmdTechDrawRedrawPage()); + rcCmdMgr.addCommand(new CmdTechDrawPrintAll()); rcCmdMgr.addCommand(new CmdTechDrawView()); rcCmdMgr.addCommand(new CmdTechDrawActiveView()); rcCmdMgr.addCommand(new CmdTechDrawSectionView()); diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.cpp b/src/Mod/TechDraw/Gui/MDIViewPage.cpp index af81dcf9dc..06a0ce3c7f 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.cpp +++ b/src/Mod/TechDraw/Gui/MDIViewPage.cpp @@ -30,7 +30,6 @@ #include #include #include - #include #include #include #include @@ -124,6 +123,9 @@ MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget* m_exportPDFAction = new QAction(tr("Export PDF"), this); connect(m_exportPDFAction, SIGNAL(triggered()), this, SLOT(savePDF())); + m_printAllAction = new QAction(tr("Print All Pages"), this); + connect(m_printAllAction, SIGNAL(triggered()), this, SLOT(printAll())); + isSelectionBlocked = false; QString tabText = QString::fromUtf8(pageVp->getDrawPage()->getNameInDocument()); @@ -236,7 +238,9 @@ bool MDIViewPage::onHasMsg(const char* pMsg) const return true; else if (strcmp("PrintPreview", pMsg) == 0) return true; - else if (strcmp("PrintPdf", pMsg) == 0) + else if (strcmp("PrintPdf",pMsg) == 0) + return true; + else if (strcmp("PrintAll",pMsg) == 0) return true; return false; } @@ -440,6 +444,63 @@ void MDIViewPage::print(QPrinter* printer) static_cast (blockSelection(false)); } +//static routine to print all pages in a document +void MDIViewPage::printAll(QPrinter* printer, + App::Document* doc) +{ +// Base::Console().Message("MDIVP::printAll(printer, doc)\n"); + + std::vector docObjs = doc->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + bool firstTime = true; + for (auto& obj: docObjs) { + if (firstTime) { + firstTime = false; + } else { + printer->newPage(); + } + TechDraw::DrawPage* dp = static_cast(obj); + Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(obj); + if (!vp) { + continue; // can't print this one + } + TechDrawGui::ViewProviderPage* vpp = dynamic_cast(vp); + if (!vpp) { + continue; // can't print this one + } + 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); + + // Reset + vpp->setFrameState(saveState); + vpp->setTemplateMarkers(saveState); + vpp->getQGSPage()->refreshViews(); + } +} + + PyObject* MDIViewPage::getPyObject() { if (!pythonObject) @@ -539,6 +600,28 @@ void MDIViewPage::savePDF(std::string file) printPdf(file); } +//mdiviewpage method for printAll action +void MDIViewPage::printAll() +{ +// Base::Console().Message("MDIVP::printAll()\n"); + printAllPages(); +} + +//static routine for PrintAll command +void MDIViewPage::printAllPages() +{ + QPrinter printer(QPrinter::HighResolution); + printer.setFullPage(true); + + QPrintDialog dlg(&printer, Gui::getMainWindow()); + if (dlg.exec() == QDialog::Accepted) { + App::Document* doc = App::GetApplication().getActiveDocument(); + if (doc) { + printAll(&printer, doc); + } + } +} + /////////////// Selection Routines /////////////////// // wf: this is never executed??? // needs a signal from Scene? hoverEvent? Scene does not emit signal for "preselect" diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.h b/src/Mod/TechDraw/Gui/MDIViewPage.h index d3cce4a5e4..3ee2265c24 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.h +++ b/src/Mod/TechDraw/Gui/MDIViewPage.h @@ -84,6 +84,9 @@ public: void printPdf() override; void printPdf(std::string file); void printPreview() override; + static void printAllPages(); + static void printAll(QPrinter* printer, + App::Document* doc); void saveSVG(std::string file); void saveDXF(std::string file); @@ -112,6 +115,7 @@ public Q_SLOTS: void toggleFrame(); void toggleKeepUpdated(); void sceneSelectionChanged(); + void printAll(); protected: void closeEvent(QCloseEvent* event) override; @@ -133,6 +137,7 @@ private: QAction *m_exportSVGAction; QAction *m_exportDXFAction; QAction *m_exportPDFAction; + QAction *m_printAllAction; std::string m_objectName; std::string m_documentName; diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 9092f93518..d33658baa9 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -31,6 +31,7 @@ icons/actions/TechDraw_Multiview.svg icons/actions/TechDraw_PageDefault.svg icons/actions/TechDraw_PageTemplate.svg + icons/actions/TechDraw_PrintAll.svg icons/actions/TechDraw_ProjectionGroup.svg icons/actions/TechDraw_ProjectShape.svg icons/actions/TechDraw_Quadrants.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/TechDraw_PrintAll.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/TechDraw_PrintAll.svg new file mode 100644 index 0000000000..d785046923 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/TechDraw_PrintAll.svg @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index 6f6da5d751..742ebf897c 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -174,6 +174,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_PageDefault"; *draw << "TechDraw_PageTemplate"; *draw << "TechDraw_RedrawPage"; + *draw << "TechDraw_PrintAll"; *draw << "Separator"; *draw << "TechDraw_View"; *draw << "TechDraw_ActiveView"; @@ -226,6 +227,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *pages << "TechDraw_PageDefault"; *pages << "TechDraw_PageTemplate"; *pages << "TechDraw_RedrawPage"; + *pages << "TechDraw_PrintAll"; Gui::ToolBarItem *views = new Gui::ToolBarItem(root); views->setCommand("TechDraw Views"); @@ -365,6 +367,8 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *pages << "TechDraw_PageDefault"; *pages << "TechDraw_PageTemplate"; *pages << "TechDraw_RedrawPage"; + *pages << "TechDraw_PrintAll"; + Gui::ToolBarItem *views = new Gui::ToolBarItem(root); views->setCommand("Views");