From c2c2e6a0ccf26192efbfb292e955b48470d71eee Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 9 Jan 2014 13:39:58 +0200 Subject: [PATCH] Fixed issue #36. --HG-- branch : develop --- Valentina.pro | 2 +- src/dialogs/dialogsinglepoint.cpp | 4 +- src/mainwindow.cpp | 2 +- src/options.h | 3 +- src/tablewindow.cpp | 63 +++++++++++++++++++++++++++++-- src/tablewindow.h | 2 +- 6 files changed, 66 insertions(+), 10 deletions(-) diff --git a/Valentina.pro b/Valentina.pro index e4cc56687..f48174407 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -6,7 +6,7 @@ # Use out-of-source builds (shadow builds) -QT += core gui widgets xml svg +QT += core gui widgets xml svg printsupport TEMPLATE = app diff --git a/src/dialogs/dialogsinglepoint.cpp b/src/dialogs/dialogsinglepoint.cpp index 2ca5baa4a..af69ba8b5 100644 --- a/src/dialogs/dialogsinglepoint.cpp +++ b/src/dialogs/dialogsinglepoint.cpp @@ -36,8 +36,8 @@ DialogSinglePoint::DialogSinglePoint(const VContainer *data, QWidget *parent) point(QPointF()) { ui->setupUi(this); - ui->doubleSpinBoxX->setRange(0, toMM(PaperSize)); - ui->doubleSpinBoxY->setRange(0, toMM(PaperSize)); + ui->doubleSpinBoxX->setRange(0, toMM(SceneSize)); + ui->doubleSpinBoxY->setRange(0, toMM(SceneSize)); bOk = ui->buttonBox->button(QDialogButtonBox::Ok); labelEditNamePoint = ui->labelEditName; flagName = false; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7de3f9905..ac479a756 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -78,7 +78,7 @@ MainWindow::MainWindow(QWidget *parent) } ToolBarOption(); ToolBarDraws(); - QRectF sceneRect = QRectF(0, 0, PaperSize, PaperSize); + QRectF sceneRect = QRectF(0, 0, SceneSize, SceneSize); sceneDraw = new VMainGraphicsScene(sceneRect); currentScene = sceneDraw; connect(sceneDraw, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove); diff --git a/src/options.h b/src/options.h index c70e4c195..3633b6f7a 100644 --- a/src/options.h +++ b/src/options.h @@ -31,8 +31,9 @@ #include +#define SceneSize 50000 + #define PrintDPI 96 -#define PaperSize 50000 #define toPixel(mm) ((mm / 25.4) * PrintDPI) #define toMM(pix) ((pix / PrintDPI) * 25.4) #define widthMainLine 1.2 diff --git a/src/tablewindow.cpp b/src/tablewindow.cpp index f5694a1d2..92dcd598f 100644 --- a/src/tablewindow.cpp +++ b/src/tablewindow.cpp @@ -29,8 +29,9 @@ #include "tablewindow.h" #include "ui_tablewindow.h" #include "widgets/vtablegraphicsview.h" -#include "options.h" #include +#include +#include "options.h" TableWindow::TableWindow(QWidget *parent) :QMainWindow(parent), numberDetal(0), colission(0), ui(new Ui::TableWindow), @@ -159,18 +160,43 @@ void TableWindow::StopTable() void TableWindow::saveScene() { - QString name = QFileDialog::getSaveFileName(0, tr("Save layout"), "", "Images (*.png);;Svg files (*.svg)"); - if (name.isNull()) + QMap extByMessage; + extByMessage[ tr("Svg files (*.svg)") ] = ".svg"; + extByMessage[ tr("PDF files (*.pdf)") ] = ".pdf"; + extByMessage[ tr("Images (*.png)") ] = ".png"; + + QString saveMessage; + QMapIterator i(extByMessage); + while (i.hasNext()) + { + i.next(); + saveMessage += i.key(); + if (i.hasNext()) + saveMessage += ";;"; + } + + QString sf; + // the save function + QString name = QFileDialog::getSaveFileName(this, tr("Save layout"), QDir::homePath(), saveMessage, &sf); + + if (name.isEmpty()) { return; } + // what if the users did not specify a suffix...? + QFileInfo f( name ); + if (f.suffix().isEmpty() && f.suffix() != "svg" && f.suffix() != "png" && f.suffix() != "pdf") + { + name += extByMessage[sf]; + } + QBrush *brush = new QBrush(); brush->setColor( QColor( Qt::white ) ); tableScene->setBackgroundBrush( *brush ); tableScene->clearSelection(); // Selections would also render to the file, so need delete them shadowPaper->setVisible(false); - QFileInfo fi(name); + QFileInfo fi( name ); if (fi.suffix() == "svg") { paper->setVisible(false); @@ -183,6 +209,12 @@ void TableWindow::saveScene() PngFile(name); paper->setPen(QPen(Qt::black, widthMainLine)); } + else if (fi.suffix() == "pdf") + { + paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen)); + PdfFile(name); + paper->setPen(QPen(Qt::black, widthMainLine)); + } brush->setColor( QColor( Qt::gray ) ); brush->setStyle( Qt::SolidPattern ); @@ -399,3 +431,26 @@ void TableWindow::PngFile(const QString &name) const tableScene->render(&painter); image.save(name); } + +void TableWindow::PdfFile(const QString &name) const +{ + QPrinter printer; + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setOutputFileName(name); + QRectF r = paper->rect(); + qreal x=0, y=0, w=0, h=0; + r.getRect(&x, &y, &w, &h);// Re-shrink the scene to it's bounding contents + printer.setResolution(PrintDPI); + printer.setPaperSize ( QSizeF(toMM(w), toMM(h)), QPrinter::Millimeter ); + QPainter painter; + if (! painter.begin( &printer )) { // failed to open file + qCritical("Can't open printer %s",qPrintable(name)); + return; + } + painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen(Qt::black, widthMainLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setBrush ( QBrush ( Qt::NoBrush ) ); + tableScene->render(&painter); + painter.end(); +} diff --git a/src/tablewindow.h b/src/tablewindow.h index 94321fff1..a17206788 100644 --- a/src/tablewindow.h +++ b/src/tablewindow.h @@ -209,7 +209,7 @@ private: * @brief PsFile * @param name */ - void PsFile(const QString &name)const; + void PdfFile(const QString &name)const; }; #endif // TABLEWINDOW_H