[TD]add PrintAll command
This commit is contained in:
@@ -82,12 +82,12 @@
|
||||
#include <Mod/TechDraw/App/DrawViewDetail.h>
|
||||
#include <Mod/TechDraw/App/DrawViewArch.h>
|
||||
#include <Mod/TechDraw/App/DrawUtil.h>
|
||||
#include <Mod/TechDraw/App/Preferences.h>
|
||||
|
||||
#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());
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <QApplication>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QFileDialog>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QListWidget>
|
||||
@@ -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<void> (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<App::DocumentObject*> 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<TechDraw::DrawPage*>(obj);
|
||||
Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(obj);
|
||||
if (!vp) {
|
||||
continue; // can't print this one
|
||||
}
|
||||
TechDrawGui::ViewProviderPage* vpp = dynamic_cast<TechDrawGui::ViewProviderPage*>(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<TechDraw::DrawTemplate *>(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"
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
<file>icons/actions/TechDraw_Multiview.svg</file>
|
||||
<file>icons/actions/TechDraw_PageDefault.svg</file>
|
||||
<file>icons/actions/TechDraw_PageTemplate.svg</file>
|
||||
<file>icons/actions/TechDraw_PrintAll.svg</file>
|
||||
<file>icons/actions/TechDraw_ProjectionGroup.svg</file>
|
||||
<file>icons/actions/TechDraw_ProjectShape.svg</file>
|
||||
<file>icons/actions/TechDraw_Quadrants.svg</file>
|
||||
|
||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 7.9 KiB |
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user