All tiles exported

This commit is contained in:
Ronan Le Tiec 2020-11-15 13:06:57 +01:00
parent f90f8ca01b
commit cbf0651486
2 changed files with 135 additions and 96 deletions

View File

@ -702,6 +702,132 @@ bool VPMainWindow::MaybeSave()
return true;
}
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::generateTiledPdf(QString fileName)
{
if(not fileName.isEmpty())
{
m_graphicsView->PrepareForExport();
PageOrientation tilesOrientation = m_layout->GetTilesOrientation();
QSizeF tilesSize = m_layout->GetTilesSize();
QMarginsF tilesMargins = m_layout->GetTilesMargins();
// ------------- Set up the printer
QPrinter* printer = new QPrinter();
printer->setCreator(QGuiApplication::applicationDisplayName()+QChar(QChar::Space)+
QCoreApplication::applicationVersion());
printer->setOrientation(QPrinter::Portrait); // in the pdf file the pages should always be in portrait
// here we might need to so some rounding for the size.
printer->setPageSize(QPageSize(m_layout->GetTilesSize(Unit::Mm),
QPageSize::Millimeter));
printer->setFullPage(true);
const bool success = printer->setPageMargins(m_layout->GetTilesMargins(Unit::Mm), QPageLayout::Millimeter);
if (not success)
{
qWarning() << tr("Cannot set printer margins");
}
#ifdef Q_OS_MAC
printer->setOutputFormat(QPrinter::NativeFormat);
#else
printer->setOutputFormat(QPrinter::PdfFormat);
#endif
printer->setOutputFileName(fileName);
printer->setResolution(static_cast<int>(PrintDPI));
printer->setDocName("Test");
// ------------- Set up the painter
QPainter painter;
if (not painter.begin(printer))
{ // failed to open file
qCritical() << tr("Failed to open file, is it writable?");
return;
}
painter.setFont( QFont( QStringLiteral("Arial"), 8, QFont::Normal ) );
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter.setBrush ( QBrush ( Qt::NoBrush ) );
if(tilesOrientation == PageOrientation::Landscape)
{
// The landscape tiles have to be rotated, because the pages
// stay portrait in the pdf
painter.rotate(90);
painter.translate(0, -ToPixel(printer->pageRect(QPrinter::Millimeter).width(), Unit::Mm));
}
// ------------- Prepare infos for the tiling
qreal tilesDrawingAreaHeight = (tilesOrientation == PageOrientation::Portrait)?
tilesSize.height() : tilesSize.width();
tilesDrawingAreaHeight -=
tilesMargins.top() + tilesMargins.bottom() + UnitConvertor(1, Unit::Cm, Unit::Px);
// the -1cm is for test purpuses, it correspondings to the overlaping for gluing the parts,
// later we'll have a proper abstract value
qreal tilesDrawingAreaWidth = (tilesOrientation == PageOrientation::Portrait)?
tilesSize.width() : tilesSize.height();
tilesDrawingAreaWidth -=
tilesMargins.left() + tilesMargins.right() + UnitConvertor(1, Unit::Cm, Unit::Px);
QSizeF sheetSize = m_layout->GetFocusedSheet()->GetSheetSize();
qreal drawingWidth = 0;
qreal drawingHeight = 0;
if(m_layout->GetFocusedSheet()->GetOrientation() == PageOrientation::Portrait)
{
drawingWidth = sheetSize.width();
drawingHeight = sheetSize.height();
}
else
{
drawingWidth = sheetSize.height();
drawingHeight = sheetSize.width();
}
int nbCol = qCeil(drawingWidth/tilesDrawingAreaWidth);
int nbRow = qCeil(drawingHeight/tilesDrawingAreaHeight);
// ------------- Perform the tiling
for(int i=0;i<nbRow;i++) // for each row of the tiling grid
{
for(int j=0;j<nbCol;j++) // for each column of tiling grid
{
if(not (i == 0 && j == 0))
{
if (not printer->newPage())
{
qWarning("failed in flushing page to disk, disk full?");
return;
}
}
QRectF source = QRectF(j*tilesDrawingAreaWidth, i*tilesDrawingAreaHeight, tilesDrawingAreaWidth, tilesDrawingAreaHeight);
QRectF target = QRectF(m_layout->GetTilesMargins().left(), m_layout->GetTilesMargins().top(),
source.width(), source.height());
// TODO: add the lines etc
m_graphicsView->GetScene()->render(&painter, target, source, Qt::IgnoreAspectRatio);
}
}
painter.end();
m_graphicsView->CleanAfterExport();
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::on_actionNew_triggered()
{
@ -811,7 +937,8 @@ void VPMainWindow::on_actionSave_triggered()
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::on_actionSaveAs_triggered()
{
// TODO / FIXME : See valentina how the save is done over there. we need to add the extension .vlt, check for empty file names etc.
// TODO / FIXME : See valentina how the save is done over there. we need to add the
// extension .vlt, check for empty file names etc.
//Get list last open files
QStringList recentFiles = qApp->PuzzleSettings()->GetRecentFileList();
@ -1060,101 +1187,7 @@ void VPMainWindow::on_pushButtonTilesExport_clicked()
#endif
);
if(not fileName.isEmpty())
{
// tests for now, later we want this in a separated function
m_graphicsView->PrepareForExport();
PageOrientation tilesOrientation = m_layout->GetTilesOrientation();
QSizeF tilesSize = m_layout->GetTilesSize();
QMarginsF tilesMargins = m_layout->GetTilesMargins();
// ------------- Set up the printer
QPrinter* printer = new QPrinter();
printer->setCreator(QGuiApplication::applicationDisplayName()+QChar(QChar::Space)+
QCoreApplication::applicationVersion());
printer->setOrientation(QPrinter::Portrait); // in the pdf file the pages should always be in portrait
// here we might need to so some rounding for the size.
printer->setPageSize(QPageSize(m_layout->GetTilesSize(Unit::Mm),
QPageSize::Millimeter));
printer->setFullPage(true);
const bool success = printer->setPageMargins(m_layout->GetTilesMargins(Unit::Mm), QPageLayout::Millimeter);
if (not success)
{
qWarning() << tr("Cannot set printer margins");
}
#ifdef Q_OS_MAC
printer->setOutputFormat(QPrinter::NativeFormat);
#else
printer->setOutputFormat(QPrinter::PdfFormat);
#endif
printer->setOutputFileName(fileName);
printer->setResolution(static_cast<int>(PrintDPI));
printer->setDocName("Test");
// ------------- Set up the painter
QPainter painter;
if (not painter.begin(printer))
{ // failed to open file
qCritical() << tr("Failed to open file, is it writable?");
return;
}
painter.setFont( QFont( QStringLiteral("Arial"), 8, QFont::Normal ) );
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter.setBrush ( QBrush ( Qt::NoBrush ) );
if(tilesOrientation == PageOrientation::Landscape)
{
// The landscape tiles have to be rotated, because the pages
// stay portrait in the pdf
painter.rotate(90);
painter.translate(0, -ToPixel(printer->pageRect(QPrinter::Millimeter).width(), Unit::Mm));
}
// ------------- Perform the Tiling
qreal tilesDrawingAreaHeight = (tilesOrientation == PageOrientation::Portrait)?
tilesSize.height() : tilesSize.width();
tilesDrawingAreaHeight -=
tilesMargins.top() + tilesMargins.bottom() + UnitConvertor(1, Unit::Cm, Unit::Px);
// the -1cm is for test purpuses, it correspondings to the overlaping for gluing the parts,
// later we'll have a proper abstract value
qreal tilesDrawingAreaWidth = (tilesOrientation == PageOrientation::Portrait)?
tilesSize.width() : tilesSize.height();
tilesDrawingAreaWidth -=
tilesMargins.left() + tilesMargins.right() + UnitConvertor(1, Unit::Cm, Unit::Px);
QRectF source = QRectF(0,0,tilesDrawingAreaWidth, tilesDrawingAreaHeight);
QRectF target = QRectF(m_layout->GetTilesMargins().left(), m_layout->GetTilesMargins().top(),
source.width(), source.height());
m_graphicsView->GetScene()->render(&painter, target, source, Qt::IgnoreAspectRatio);
if (not printer->newPage())
{
qWarning("failed in flushing page to disk, disk full?");
return;
}
source = QRectF(tilesDrawingAreaWidth,0,tilesDrawingAreaWidth, tilesDrawingAreaHeight);
m_graphicsView->GetScene()->render(&painter, target, source, Qt::IgnoreAspectRatio);
painter.end();
m_graphicsView->CleanAfterExport();
}
generateTiledPdf(fileName);
}

View File

@ -217,6 +217,12 @@ private:
bool MaybeSave();
/**
* @brief generateTiledPdf Generates the tiled Pdf in the given filename
* @param filename
*/
void generateTiledPdf(QString fileName);
private slots:
/**