parent
36cb8b293d
commit
c2c2e6a0cc
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -31,8 +31,9 @@
|
|||
|
||||
#include <QFlags>
|
||||
|
||||
#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
|
||||
|
|
|
@ -29,8 +29,9 @@
|
|||
#include "tablewindow.h"
|
||||
#include "ui_tablewindow.h"
|
||||
#include "widgets/vtablegraphicsview.h"
|
||||
#include "options.h"
|
||||
#include <QtSvg>
|
||||
#include <QPrinter>
|
||||
#include "options.h"
|
||||
|
||||
TableWindow::TableWindow(QWidget *parent)
|
||||
:QMainWindow(parent), numberDetal(0), colission(0), ui(new Ui::TableWindow),
|
||||
|
@ -159,12 +160,37 @@ void TableWindow::StopTable()
|
|||
|
||||
void TableWindow::saveScene()
|
||||
{
|
||||
QString name = QFileDialog::getSaveFileName(0, tr("Save layout"), "", "Images (*.png);;Svg files (*.svg)");
|
||||
if (name.isNull())
|
||||
QMap<QString, QString> extByMessage;
|
||||
extByMessage[ tr("Svg files (*.svg)") ] = ".svg";
|
||||
extByMessage[ tr("PDF files (*.pdf)") ] = ".pdf";
|
||||
extByMessage[ tr("Images (*.png)") ] = ".png";
|
||||
|
||||
QString saveMessage;
|
||||
QMapIterator<QString, QString> 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 );
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -209,7 +209,7 @@ private:
|
|||
* @brief PsFile
|
||||
* @param name
|
||||
*/
|
||||
void PsFile(const QString &name)const;
|
||||
void PdfFile(const QString &name)const;
|
||||
};
|
||||
|
||||
#endif // TABLEWINDOW_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user