First tiles export

This commit is contained in:
Ronan Le Tiec 2020-11-15 12:30:29 +01:00
parent e7cd13b703
commit f90f8ca01b
4 changed files with 129 additions and 12 deletions

View File

@ -268,16 +268,22 @@ QSizeF VPLayout::GetTilesSize() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QSizeF VPLayout::GetTilesSizeConverted() const QSizeF VPLayout::GetTilesSize(Unit unit) const
{ {
QSizeF convertedSize = QSizeF( QSizeF convertedSize = QSizeF(
UnitConvertor(m_tilesSize.width(), Unit::Px, GetUnit()), UnitConvertor(m_tilesSize.width(), Unit::Px, unit),
UnitConvertor(m_tilesSize.height(), Unit::Px, GetUnit()) UnitConvertor(m_tilesSize.height(), Unit::Px, unit)
); );
return convertedSize; return convertedSize;
} }
//---------------------------------------------------------------------------------------------------------------------
QSizeF VPLayout::GetTilesSizeConverted() const
{
return GetTilesSize(GetUnit());
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
PageOrientation VPLayout::GetTilesOrientation() PageOrientation VPLayout::GetTilesOrientation()
{ {
@ -330,6 +336,12 @@ QMarginsF VPLayout::GetTilesMargins() const
return m_tilesMargins; return m_tilesMargins;
} }
//---------------------------------------------------------------------------------------------------------------------
QMarginsF VPLayout::GetTilesMargins(Unit unit) const
{
return UnitConvertor(m_tilesMargins, Unit::Px, unit);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QMarginsF VPLayout::GetTilesMarginsConverted() const QMarginsF VPLayout::GetTilesMarginsConverted() const
{ {

View File

@ -154,21 +154,27 @@ public:
/** /**
* @brief SetTilesSize sets the size of the tiles, the values have to be in Unit::Px * @brief SetTilesSize sets the size of the tiles, the values have to be in Unit::Px
* @param size sheet size * @param size tiles size
*/ */
void SetTilesSize(const QSizeF &size); void SetTilesSize(const QSizeF &size);
/** /**
* @brief SetTilesSizeConverted sets the size of the tiles, the values have to be in the layout's unit * @brief SetTilesSizeConverted sets the size of the tiles, the values have to be in the layout's unit
* @param size sheet size * @param size tiles size
*/ */
void SetTilesSizeConverted(const QSizeF &size); void SetTilesSizeConverted(const QSizeF &size);
/** /**
* @brief GetTilesSize Returns the size of the tiles in Unit::Px * @brief GetTilesSize Returns the size of the tiles in Unit::Px
* @return sheet size in Unit::Px * @return tiles size in Unit::Px
*/ */
QSizeF GetTilesSize() const; QSizeF GetTilesSize() const;
/**
* @brief GetTilesSize Returns the size of the tiles in given Unit
* @return tiles size
*/
QSizeF GetTilesSize(Unit unit) const;
/** /**
* @brief GetTilesSizeConverted Returns the size of the tiles in the layout's unit * @brief GetTilesSizeConverted Returns the size of the tiles in the layout's unit
* @return the size in the layout's unit * @return the size in the layout's unit
@ -219,10 +225,17 @@ public:
/** /**
* @brief GetTilesMargins Returns margins of the tiles in Unit::Px * @brief GetTilesMargins Returns margins of the tiles in Unit::Px
* @return the size in Unit::Px * @return the margins in Unit::Px
*/ */
QMarginsF GetTilesMargins() const; QMarginsF GetTilesMargins() const;
/**
* @brief GetTilesMargins Returns margins of the tiles in the given unit
* @param unit the unit in which we want the margins
* @return the margins in the given unit
*/
QMarginsF GetTilesMargins(Unit unit) const;
/** /**
* @brief GetTilesMarginsConverted Returns the margins of the tiles in the layout's unit * @brief GetTilesMarginsConverted Returns the margins of the tiles in the layout's unit
* @return the margins in the tiles's unit * @return the margins in the tiles's unit

View File

@ -496,7 +496,7 @@ void VPMainWindow::SetPropertyTabTilesData()
SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesMarginBottom, margins.bottom()); SetDoubleSpinBoxValue(ui->doubleSpinBoxTilesMarginBottom, margins.bottom());
// set "show tiles" checkbox // set "show tiles" checkbox
ui->checkBoxTilesShowTiles->setChecked(m_layout->GetShowTiles()); SetCheckBoxValue(ui->checkBoxTilesShowTiles, m_layout->GetShowTiles());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -913,8 +913,9 @@ void VPMainWindow::on_comboBoxLayoutUnit_currentIndexChanged(int index)
m_layout->SetUnit(Unit::Inch); m_layout->SetUnit(Unit::Inch);
} }
SetPropertyTabSheetData();
SetPropertyTabCurrentPieceData(); SetPropertyTabCurrentPieceData();
SetPropertyTabSheetData();
SetPropertyTabTilesData();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1061,13 +1062,96 @@ void VPMainWindow::on_pushButtonTilesExport_clicked()
if(not fileName.isEmpty()) if(not fileName.isEmpty())
{ {
// tests for now, later we want this in a separated function
m_graphicsView->PrepareForExport(); m_graphicsView->PrepareForExport();
PageOrientation tilesOrientation = m_layout->GetTilesOrientation();
QSizeF tilesSize = m_layout->GetTilesSize();
QMarginsF tilesMargins = m_layout->GetTilesMargins();
// TODO : Tiles export // ------------- 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(); m_graphicsView->CleanAfterExport();
} }

View File

@ -1014,7 +1014,11 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxTilesWidth"/> <widget class="QDoubleSpinBox" name="doubleSpinBoxTilesWidth">
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="labelTilesLength"> <widget class="QLabel" name="labelTilesLength">
@ -1024,7 +1028,11 @@
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxTilesLength"/> <widget class="QDoubleSpinBox" name="doubleSpinBoxTilesLength">
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="labelTilesOrientation"> <widget class="QLabel" name="labelTilesOrientation">