Correct pageSize determination
remove obsolete code
This commit is contained in:
parent
78924d3a22
commit
fe871cd245
|
@ -40,6 +40,8 @@
|
|||
#include <QPrintPreviewDialog>
|
||||
#endif // #ifndef _PreComp_
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "MDIViewPage.h"
|
||||
|
||||
#include <Base/Stream.h>
|
||||
|
@ -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<App::DocumentObject*> &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<QPrinter::PageSize, QString> 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<QPrinter::PageSize, QString>::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; i<listWidget->count(); 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<QListWidgetItem*> 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<QPrinter::PageSize>(i);
|
||||
ps = static_cast<QPrinter::PaperSize>(i);
|
||||
break;
|
||||
}
|
||||
else
|
||||
if (std::abs(paperSizes[i][0]-h) <= 1 &&
|
||||
std::abs(paperSizes[i][1]-w) <= 1) {
|
||||
ps = static_cast<QPrinter::PageSize>(i);
|
||||
ps = static_cast<QPrinter::PaperSize>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ps;
|
||||
}
|
||||
|
||||
|
||||
void MDIViewPage::setFrameState(bool state)
|
||||
{
|
||||
m_frameState = state;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<TechDraw::DrawParametricTemplate *>(obj);
|
||||
QGIDrawingTemplate *qTempItem = new QGIDrawingTemplate(scene());
|
||||
pageTemplate = qTempItem;
|
||||
} else if(obj->isDerivedFrom(TechDraw::DrawSVGTemplate::getClassTypeId())) {
|
||||
//TechDraw::DrawSVGTemplate *dwgTemplate = static_cast<TechDraw::DrawSVGTemplate *>(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<QGraphicsItem*> list = scene()->items();
|
||||
|
|
|
@ -77,7 +77,6 @@ public:
|
|||
const std::vector<QGIView *> & getViews() const { return views; }
|
||||
int addView(QGIView * view);
|
||||
void setViews(const std::vector<QGIView *> &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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user