From fe871cd245e1567f35790ed330d8bf16658d2eed Mon Sep 17 00:00:00 2001 From: WandererFan Date: Wed, 27 Jul 2016 14:12:49 -0400 Subject: [PATCH] Correct pageSize determination remove obsolete code --- src/Mod/TechDraw/Gui/MDIViewPage.cpp | 114 ++++++++------------------- src/Mod/TechDraw/Gui/MDIViewPage.h | 7 +- src/Mod/TechDraw/Gui/QGVPage.cpp | 56 +------------ src/Mod/TechDraw/Gui/QGVPage.h | 5 -- 4 files changed, 36 insertions(+), 146 deletions(-) diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.cpp b/src/Mod/TechDraw/Gui/MDIViewPage.cpp index b3775bb1a..158cbe620 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.cpp +++ b/src/Mod/TechDraw/Gui/MDIViewPage.cpp @@ -40,6 +40,8 @@ #include #endif // #ifndef _PreComp_ +#include + #include "MDIViewPage.h" #include @@ -92,28 +94,16 @@ using namespace TechDrawGui; MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget* parent) : Gui::MDIView(doc, parent), - //m_view(new QGVPage(pageVp)), + m_orientation(QPrinter::Landscape), + m_paperSize(QPrinter::A4), pageGui(pageVp), m_frameState(true) { m_view = new QGVPage(pageVp,m_scene,this); - m_backgroundAction = new QAction(tr("&Background"), this); - m_backgroundAction->setEnabled(false); - m_backgroundAction->setCheckable(true); - m_backgroundAction->setChecked(true); - connect(m_backgroundAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewBackground(bool))); - m_exportSVGAction = new QAction(tr("&Export SVG"), this); connect(m_exportSVGAction, SIGNAL(triggered()), this, SLOT(saveSVG())); - //m_outlineAction is obs? never set to Enabled? - m_outlineAction = new QAction(tr("&Outline"), this); - m_outlineAction->setEnabled(false); - m_outlineAction->setCheckable(true); - m_outlineAction->setChecked(false); - connect(m_outlineAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewOutline(bool))); //in QGVPage - m_nativeAction = new QAction(tr("&Native"), this); m_nativeAction->setCheckable(true); m_nativeAction->setChecked(false); @@ -147,9 +137,6 @@ MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget* setWindowTitle(tr("dummy[*]")); //Yuck. prevents "QWidget::setWindowModified: The window title does not contain a '[*]' placeholder" setCentralWidget(m_view); //this makes m_view a Qt child of MDIViewPage - m_orientation = QPrinter::Landscape; - m_pageSize = QPrinter::A4; - // Connect Signals and Slots QObject::connect( m_view->scene(), SIGNAL(selectionChanged()), @@ -157,7 +144,7 @@ MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget* ); - // A fresh page is added and we iterate through its collected children and add these to Canvas View + // A fresh page is added and we iterate through its collected children and add these to Canvas View -MLP // if docobj is a featureviewcollection (ex orthogroup), add its child views. if there are ever children that have children, // we'll have to make this recursive. -WF const std::vector &grp = pageGui->getPageObject()->Views.getValues(); @@ -220,48 +207,6 @@ void MDIViewPage::setDimensionGroups(void) } } - -void MDIViewPage::findPrinterSettings(const QString& fileName) -{ - if (fileName.indexOf(QLatin1String("Portrait"), Qt::CaseInsensitive) >= 0) { - m_orientation = QPrinter::Portrait; - } - else { - m_orientation = QPrinter::Landscape; - } - - QMap pageSizes; - pageSizes[QPrinter::A0] = QString::fromLatin1("A0"); - pageSizes[QPrinter::A1] = QString::fromLatin1("A1"); - pageSizes[QPrinter::A2] = QString::fromLatin1("A2"); - pageSizes[QPrinter::A3] = QString::fromLatin1("A3"); - pageSizes[QPrinter::A4] = QString::fromLatin1("A4"); - pageSizes[QPrinter::A5] = QString::fromLatin1("A5"); - pageSizes[QPrinter::A6] = QString::fromLatin1("A6"); - pageSizes[QPrinter::A7] = QString::fromLatin1("A7"); - pageSizes[QPrinter::A8] = QString::fromLatin1("A8"); - pageSizes[QPrinter::A9] = QString::fromLatin1("A9"); - pageSizes[QPrinter::B0] = QString::fromLatin1("B0"); - pageSizes[QPrinter::B1] = QString::fromLatin1("B1"); - pageSizes[QPrinter::B2] = QString::fromLatin1("B2"); - pageSizes[QPrinter::B3] = QString::fromLatin1("B3"); - pageSizes[QPrinter::B4] = QString::fromLatin1("B4"); - pageSizes[QPrinter::B5] = QString::fromLatin1("B5"); - pageSizes[QPrinter::B6] = QString::fromLatin1("B6"); - pageSizes[QPrinter::B7] = QString::fromLatin1("B7"); - pageSizes[QPrinter::B8] = QString::fromLatin1("B8"); - pageSizes[QPrinter::B9] = QString::fromLatin1("B9"); - pageSizes[QPrinter::Letter] = QString::fromLatin1("Letter"); - pageSizes[QPrinter::Legal] = QString::fromLatin1("Legal"); - for (QMap::iterator it = pageSizes.begin(); it != pageSizes.end(); ++it) { - if (fileName.startsWith(it.value(), Qt::CaseInsensitive)) { - m_pageSize = it.key(); - break; - } - } -} - - void MDIViewPage::setDocumentObject(const std::string& name) { m_objectName = name; @@ -290,8 +235,6 @@ void MDIViewPage::closeEvent(QCloseEvent* ev) void MDIViewPage::contextMenuEvent(QContextMenuEvent *event) { QMenu menu; - menu.addAction(m_backgroundAction); - menu.addAction(m_outlineAction); menu.addAction(m_exportSVGAction); QMenu* submenu = menu.addMenu(tr("&Renderer")); submenu->addAction(m_nativeAction); @@ -305,10 +248,17 @@ void MDIViewPage::contextMenuEvent(QContextMenuEvent *event) void MDIViewPage::attachTemplate(TechDraw::DrawTemplate *obj) { + //why doesn't setting the template set the papersize??? m_view->setPageTemplate(obj); double width = obj->Width.getValue(); double height = obj->Height.getValue(); m_view->scene()->setSceneRect(QRectF(-1.,-height,width+1.,height)); //the +/- 1 is because of the way the template is define??? + m_paperSize = getPaperSize(int(round(width)),int(round(height))); + if (width > height) { + m_orientation = QPrinter::Landscape; + } else { + m_orientation = QPrinter::Portrait; + } } @@ -576,7 +526,6 @@ void MDIViewPage::onRelabel(Gui::Document *pDoc) } } - void MDIViewPage::printPdf() { Gui::FileOptionsDialog dlg(this, 0); @@ -599,6 +548,8 @@ void MDIViewPage::printPdf() gridLayout->addWidget(listWidget, 0, 0, 1, 1); formLayout->addWidget(groupBox, 0, 0, 1, 1); + //the "Extended" part of the dialog + //doesn't have any impact on result? groupBox->setTitle(tr("Page sizes")); item = new QListWidgetItem(tr("A0"), listWidget); item->setData(Qt::UserRole, QVariant(QPrinter::A0)); @@ -619,7 +570,7 @@ void MDIViewPage::printPdf() //listWidget->item(4)->setSelected(true); // by default A4 int index = 4; // by default A4 for (int i=0; icount(); i++) { - if (listWidget->item(i)->data(Qt::UserRole).toInt() == m_pageSize) { + if (listWidget->item(i)->data(Qt::UserRole).toInt() == m_paperSize) { index = i; break; } @@ -635,11 +586,13 @@ void MDIViewPage::printPdf() printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(filename); printer.setOrientation(m_orientation); + printer.setPaperSize(m_paperSize); QList items = listWidget->selectedItems(); - if (items.size() == 1) { - int AX = items.front()->data(Qt::UserRole).toInt(); - printer.setPaperSize(QPrinter::PageSize(AX)); - } + +// if (items.size() == 1) { +// int AX = items.front()->data(Qt::UserRole).toInt(); +// printer.setPaperSize(QPrinter::PaperSize(AX)); +// } print(&printer); } @@ -650,7 +603,7 @@ void MDIViewPage::print() { QPrinter printer(QPrinter::HighResolution); printer.setFullPage(true); - printer.setPageSize(m_pageSize); + printer.setPaperSize(m_paperSize); printer.setOrientation(m_orientation); QPrintDialog dlg(&printer, this); if (dlg.exec() == QDialog::Accepted) { @@ -658,12 +611,11 @@ void MDIViewPage::print() } } - void MDIViewPage::printPreview() { QPrinter printer(QPrinter::HighResolution); printer.setFullPage(true); - printer.setPageSize(m_pageSize); + printer.setPaperSize(m_paperSize); printer.setOrientation(m_orientation); QPrintPreviewDialog dlg(&printer, this); @@ -690,8 +642,8 @@ void MDIViewPage::print(QPrinter* printer) if (printer->outputFormat() == QPrinter::NativeFormat) { int w = printer->widthMM(); int h = printer->heightMM(); - QPrinter::PaperSize realPaperSize = getPageSize(w, h); - QPrinter::PaperSize curPaperSize = printer->paperSize(); + QPrinter::PaperSize psPrtCalcd = getPaperSize(w, h); + QPrinter::PaperSize psPrtSetting = printer->paperSize(); // for the preview a 'Picture' paint engine is used which we don't // care if it uses wrong printer settings @@ -705,7 +657,7 @@ void MDIViewPage::print(QPrinter* printer) if (ret != QMessageBox::Yes) return; } - else if (doPrint && realPaperSize != m_pageSize) { + 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?"), @@ -713,7 +665,7 @@ void MDIViewPage::print(QPrinter* printer) if (ret != QMessageBox::Yes) return; } - else if (doPrint && curPaperSize != m_pageSize) { + else 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?"), @@ -756,8 +708,7 @@ void MDIViewPage::print(QPrinter* printer) } -//QPrinter::PageSize is obsolete. Use QPrinter::PaperSize instead. -QPrinter::PageSize MDIViewPage::getPageSize(int w, int h) const +QPrinter::PaperSize MDIViewPage::getPaperSize(int w, int h) const { static const float paperSizes[][2] = { {210, 297}, // A4 @@ -792,23 +743,24 @@ QPrinter::PageSize MDIViewPage::getPageSize(int w, int h) const {279.4f, 431.8f} // Tabloid }; - QPrinter::PageSize ps = QPrinter::Custom; + QPrinter::PaperSize ps = QPrinter::Custom; for (int i=0; i<30; i++) { if (std::abs(paperSizes[i][0]-w) <= 1 && std::abs(paperSizes[i][1]-h) <= 1) { - ps = static_cast(i); + ps = static_cast(i); break; } else if (std::abs(paperSizes[i][0]-h) <= 1 && std::abs(paperSizes[i][1]-w) <= 1) { - ps = static_cast(i); + ps = static_cast(i); break; } } - return ps; } + + void MDIViewPage::setFrameState(bool state) { m_frameState = state; diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.h b/src/Mod/TechDraw/Gui/MDIViewPage.h index 9d08bd462..a149ebaa2 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.h +++ b/src/Mod/TechDraw/Gui/MDIViewPage.h @@ -95,8 +95,7 @@ protected: int attachView(App::DocumentObject *obj); void contextMenuEvent(QContextMenuEvent *event); void closeEvent(QCloseEvent*); - void findPrinterSettings(const QString&); - QPrinter::PageSize getPageSize(int w, int h) const; + QPrinter::PaperSize getPaperSize(int w, int h) const; void setDimensionGroups(void); void showStatusMsg(const char* s1, const char* s2, const char* s3) const; @@ -106,8 +105,6 @@ private: QAction *m_exportSVGAction; QAction *m_imageAction; QAction *m_highQualityAntialiasingAction; - QAction *m_backgroundAction; - QAction *m_outlineAction; std::string m_objectName; bool isSelectionBlocked; @@ -115,7 +112,7 @@ private: QString m_currentPath; QPrinter::Orientation m_orientation; - QPrinter::PageSize m_pageSize; + QPrinter::PaperSize m_paperSize; ViewProviderPage *pageGui; bool m_frameState; diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index 1ab5fd156..eae2f17b1 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -85,8 +85,6 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene& s, QWidget *parent) , pageTemplate(0) , m_renderer(Native) , drawBkg(true) - , m_backgroundItem(0) - , m_outlineItem(0) , pageGui(0) { assert(vp); @@ -103,11 +101,6 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene& s, QWidget *parent) setCursor(QCursor(Qt::ArrowCursor)); setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); - //m_backgroundItem = new QGraphicsRectItem(); - //m_backgroundItem->setCacheMode(QGraphicsItem::NoCache); - //m_backgroundItem->setZValue(ZVALUE::BACKGROUND); -// scene()->addItem(m_backgroundItem); // TODO IF SEGFAULTS WITH DRAW ENABLE THIS (REDRAWS ARE SLOWER :s) - bkgBrush = new QBrush(QColor::fromRgb(70,70,70)); resetCachedContent(); @@ -115,7 +108,7 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene& s, QWidget *parent) QGVPage::~QGVPage() { delete bkgBrush; - //delete m_backgroundItem; + } void QGVPage::drawBackground(QPainter *p, const QRectF &) @@ -382,35 +375,6 @@ QGIView * QGVPage::findParent(QGIView *view) const return 0; } -void QGVPage::setPageFeature(TechDraw::DrawPage *page) -{ - //redundant -#if 0 - // TODO verify if the pointer should even be used. Not really safe - pageFeat = page; - - float pageWidth = pageGui->getPageObject()->getPageWidth(); - float pageHeight = pageGui->getPageObject()->getPageHeight(); - - QRectF paperRect(0, -pageHeight, pageWidth, pageHeight); - - QBrush brush(Qt::white); - - m_backgroundItem->setBrush(brush); - m_backgroundItem->setRect(paperRect); - - QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(); - shadow->setBlurRadius(10.0); - shadow->setColor(Qt::white); - shadow->setOffset(0,0); - m_backgroundItem->setGraphicsEffect(shadow); - - QRectF myRect = paperRect; - myRect.adjust(-20,-20,20,20); - setSceneRect(myRect); -#endif -} - void QGVPage::setPageTemplate(TechDraw::DrawTemplate *obj) { // Remove currently set background template @@ -418,11 +382,9 @@ void QGVPage::setPageTemplate(TechDraw::DrawTemplate *obj) removeTemplate(); if(obj->isDerivedFrom(TechDraw::DrawParametricTemplate::getClassTypeId())) { - //TechDraw::DrawParametricTemplate *dwgTemplate = static_cast(obj); QGIDrawingTemplate *qTempItem = new QGIDrawingTemplate(scene()); pageTemplate = qTempItem; } else if(obj->isDerivedFrom(TechDraw::DrawSVGTemplate::getClassTypeId())) { - //TechDraw::DrawSVGTemplate *dwgTemplate = static_cast(obj); QGISVGTemplate *qTempItem = new QGISVGTemplate(scene(),this); pageTemplate = qTempItem; } @@ -465,22 +427,6 @@ void QGVPage::setHighQualityAntialiasing(bool highQualityAntialiasing) #endif } -void QGVPage::setViewBackground(bool enable) -{ -// if (!m_backgroundItem) -// return; - -// m_backgroundItem->setVisible(enable); -} - -void QGVPage::setViewOutline(bool enable) -{ - if (!m_outlineItem) - return; - - m_outlineItem->setVisible(enable); -} - void QGVPage::toggleMarkers(bool enable) { QList list = scene()->items(); diff --git a/src/Mod/TechDraw/Gui/QGVPage.h b/src/Mod/TechDraw/Gui/QGVPage.h index 73fe7e1da..3026d1609 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.h +++ b/src/Mod/TechDraw/Gui/QGVPage.h @@ -77,7 +77,6 @@ public: const std::vector & getViews() const { return views; } int addView(QGIView * view); void setViews(const std::vector &view) {views = view; } - void setPageFeature(TechDraw::DrawPage *page); void setPageTemplate(TechDraw::DrawTemplate *pageTemplate); QGITemplate * getTemplate() const; @@ -93,8 +92,6 @@ public: public Q_SLOTS: void setHighQualityAntialiasing(bool highQualityAntialiasing); - void setViewBackground(bool enable); - void setViewOutline(bool enable); protected: void wheelEvent(QWheelEvent *event); @@ -113,8 +110,6 @@ private: RendererType m_renderer; bool drawBkg; - QGraphicsRectItem *m_backgroundItem; - QGraphicsRectItem *m_outlineItem; QBrush* bkgBrush; QImage m_image; ViewProviderPage *pageGui;