parent
36cb8b293d
commit
c2c2e6a0cc
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
# Use out-of-source builds (shadow builds)
|
# Use out-of-source builds (shadow builds)
|
||||||
|
|
||||||
QT += core gui widgets xml svg
|
QT += core gui widgets xml svg printsupport
|
||||||
|
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,8 @@ DialogSinglePoint::DialogSinglePoint(const VContainer *data, QWidget *parent)
|
||||||
point(QPointF())
|
point(QPointF())
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->doubleSpinBoxX->setRange(0, toMM(PaperSize));
|
ui->doubleSpinBoxX->setRange(0, toMM(SceneSize));
|
||||||
ui->doubleSpinBoxY->setRange(0, toMM(PaperSize));
|
ui->doubleSpinBoxY->setRange(0, toMM(SceneSize));
|
||||||
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
|
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
|
||||||
labelEditNamePoint = ui->labelEditName;
|
labelEditNamePoint = ui->labelEditName;
|
||||||
flagName = false;
|
flagName = false;
|
||||||
|
|
|
@ -78,7 +78,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
}
|
}
|
||||||
ToolBarOption();
|
ToolBarOption();
|
||||||
ToolBarDraws();
|
ToolBarDraws();
|
||||||
QRectF sceneRect = QRectF(0, 0, PaperSize, PaperSize);
|
QRectF sceneRect = QRectF(0, 0, SceneSize, SceneSize);
|
||||||
sceneDraw = new VMainGraphicsScene(sceneRect);
|
sceneDraw = new VMainGraphicsScene(sceneRect);
|
||||||
currentScene = sceneDraw;
|
currentScene = sceneDraw;
|
||||||
connect(sceneDraw, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
|
connect(sceneDraw, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
|
||||||
|
|
|
@ -31,8 +31,9 @@
|
||||||
|
|
||||||
#include <QFlags>
|
#include <QFlags>
|
||||||
|
|
||||||
|
#define SceneSize 50000
|
||||||
|
|
||||||
#define PrintDPI 96
|
#define PrintDPI 96
|
||||||
#define PaperSize 50000
|
|
||||||
#define toPixel(mm) ((mm / 25.4) * PrintDPI)
|
#define toPixel(mm) ((mm / 25.4) * PrintDPI)
|
||||||
#define toMM(pix) ((pix / PrintDPI) * 25.4)
|
#define toMM(pix) ((pix / PrintDPI) * 25.4)
|
||||||
#define widthMainLine 1.2
|
#define widthMainLine 1.2
|
||||||
|
|
|
@ -29,8 +29,9 @@
|
||||||
#include "tablewindow.h"
|
#include "tablewindow.h"
|
||||||
#include "ui_tablewindow.h"
|
#include "ui_tablewindow.h"
|
||||||
#include "widgets/vtablegraphicsview.h"
|
#include "widgets/vtablegraphicsview.h"
|
||||||
#include "options.h"
|
|
||||||
#include <QtSvg>
|
#include <QtSvg>
|
||||||
|
#include <QPrinter>
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
TableWindow::TableWindow(QWidget *parent)
|
TableWindow::TableWindow(QWidget *parent)
|
||||||
:QMainWindow(parent), numberDetal(0), colission(0), ui(new Ui::TableWindow),
|
:QMainWindow(parent), numberDetal(0), colission(0), ui(new Ui::TableWindow),
|
||||||
|
@ -159,12 +160,37 @@ void TableWindow::StopTable()
|
||||||
|
|
||||||
void TableWindow::saveScene()
|
void TableWindow::saveScene()
|
||||||
{
|
{
|
||||||
QString name = QFileDialog::getSaveFileName(0, tr("Save layout"), "", "Images (*.png);;Svg files (*.svg)");
|
QMap<QString, QString> extByMessage;
|
||||||
if (name.isNull())
|
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;
|
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();
|
QBrush *brush = new QBrush();
|
||||||
brush->setColor( QColor( Qt::white ) );
|
brush->setColor( QColor( Qt::white ) );
|
||||||
tableScene->setBackgroundBrush( *brush );
|
tableScene->setBackgroundBrush( *brush );
|
||||||
|
@ -183,6 +209,12 @@ void TableWindow::saveScene()
|
||||||
PngFile(name);
|
PngFile(name);
|
||||||
paper->setPen(QPen(Qt::black, widthMainLine));
|
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->setColor( QColor( Qt::gray ) );
|
||||||
brush->setStyle( Qt::SolidPattern );
|
brush->setStyle( Qt::SolidPattern );
|
||||||
|
@ -399,3 +431,26 @@ void TableWindow::PngFile(const QString &name) const
|
||||||
tableScene->render(&painter);
|
tableScene->render(&painter);
|
||||||
image.save(name);
|
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
|
* @brief PsFile
|
||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
void PsFile(const QString &name)const;
|
void PdfFile(const QString &name)const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TABLEWINDOW_H
|
#endif // TABLEWINDOW_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user