2020-11-19 14:33:27 +01:00
|
|
|
#include "vptilefactory.h"
|
|
|
|
|
|
|
|
#include <QtSvg>
|
|
|
|
|
|
|
|
#include "../vwidgets/vmaingraphicsscene.h"
|
2021-08-09 14:09:10 +02:00
|
|
|
#include "layout/vpsheet.h"
|
|
|
|
#include "scene/vpmaingraphicsview.h"
|
|
|
|
#include "../vmisc/def.h"
|
|
|
|
#include "../vmisc/vcommonsettings.h"
|
2021-09-06 14:31:19 +02:00
|
|
|
#include "../vlayout/vprintlayout.h"
|
2020-11-19 14:33:27 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-17 17:49:28 +02:00
|
|
|
VPTileFactory::VPTileFactory(const VPLayoutPtr &layout, VCommonSettings *commonSettings):
|
2020-11-19 14:33:27 +01:00
|
|
|
m_layout(layout),
|
2021-09-06 14:31:19 +02:00
|
|
|
m_commonSettings(commonSettings),
|
|
|
|
m_infoStripeWidth(UnitConvertor(1, Unit::Cm, Unit::Px))
|
2020-11-19 14:33:27 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPTileFactory::refreshTileInfos()
|
|
|
|
{
|
2021-08-17 17:49:28 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if(not layout.isNull())
|
2020-11-19 14:33:27 +01:00
|
|
|
{
|
2021-08-25 15:58:50 +02:00
|
|
|
QSizeF tilesSize = layout->LayoutSettings().GetTilesSize();
|
2021-08-17 17:49:28 +02:00
|
|
|
QMarginsF tilesMargins = layout->LayoutSettings().GetTilesMargins();
|
2020-11-20 15:51:24 +01:00
|
|
|
|
|
|
|
// sets the drawing height
|
2021-08-25 15:58:50 +02:00
|
|
|
m_drawingAreaHeight = tilesSize.height();
|
2020-11-20 15:51:24 +01:00
|
|
|
|
2021-08-25 15:58:50 +02:00
|
|
|
if (not layout->LayoutSettings().IgnoreTilesMargins())
|
|
|
|
{
|
|
|
|
m_drawingAreaHeight -= tilesMargins.top() + tilesMargins.bottom() + m_infoStripeWidth;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_drawingAreaHeight += m_infoStripeWidth;
|
|
|
|
}
|
2020-11-20 15:51:24 +01:00
|
|
|
|
2021-08-25 15:58:50 +02:00
|
|
|
// sets the drawing width
|
|
|
|
m_drawingAreaWidth = tilesSize.width();
|
2020-11-20 15:51:24 +01:00
|
|
|
|
2021-08-25 15:58:50 +02:00
|
|
|
if (not layout->LayoutSettings().IgnoreTilesMargins())
|
2020-11-20 15:51:24 +01:00
|
|
|
{
|
2021-08-25 15:58:50 +02:00
|
|
|
m_drawingAreaWidth -= tilesMargins.left() + tilesMargins.right() + m_infoStripeWidth;
|
2020-11-20 15:51:24 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-25 15:58:50 +02:00
|
|
|
m_drawingAreaWidth += m_infoStripeWidth;
|
2020-11-20 15:51:24 +01:00
|
|
|
}
|
2020-11-19 14:33:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-06 14:31:19 +02:00
|
|
|
void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheetPtr &sheet, int row, int col)
|
2020-11-19 14:33:27 +01:00
|
|
|
{
|
2021-09-06 14:31:19 +02:00
|
|
|
SCASSERT(painter != nullptr)
|
|
|
|
SCASSERT(printer != nullptr)
|
|
|
|
|
2021-08-17 17:49:28 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if(layout.isNull())
|
|
|
|
{
|
2021-09-06 14:31:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sheet.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int nbCol = ColNb(sheet);
|
|
|
|
const int nbRow = RowNb(sheet);
|
|
|
|
|
|
|
|
if (row < 0 || row > nbRow || col < 0 || col > nbCol)
|
|
|
|
{
|
|
|
|
return;
|
2021-08-17 17:49:28 +02:00
|
|
|
}
|
2021-09-06 14:31:19 +02:00
|
|
|
|
2021-08-17 17:49:28 +02:00
|
|
|
QMarginsF tilesMargins = layout->LayoutSettings().GetTilesMargins();
|
|
|
|
QPen penTileInfos = QPen(QColor(180,180,180), m_commonSettings->WidthHairLine(), Qt::DashLine, Qt::RoundCap,
|
|
|
|
Qt::RoundJoin);
|
|
|
|
QPen penTileDrawing = QPen(Qt::black, m_commonSettings->WidthMainLine(), Qt::SolidLine, Qt::RoundCap,
|
|
|
|
Qt::RoundJoin);
|
2020-11-19 14:33:27 +01:00
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
// paint the content of the page
|
|
|
|
QRectF source = QRectF(col*m_drawingAreaWidth,
|
|
|
|
row*m_drawingAreaHeight,
|
|
|
|
m_drawingAreaWidth + m_infoStripeWidth,
|
|
|
|
m_drawingAreaHeight + m_infoStripeWidth
|
|
|
|
);
|
|
|
|
|
|
|
|
painter->setPen(penTileDrawing);
|
|
|
|
|
|
|
|
sheet->SceneData()->Scene()->render(painter, VPrintLayout::SceneTargetRect(printer, source), source,
|
|
|
|
Qt::IgnoreAspectRatio);
|
|
|
|
|
|
|
|
QScopedPointer<QSvgRenderer> svgRenderer(new QSvgRenderer());
|
2020-11-19 14:33:27 +01:00
|
|
|
|
2020-11-21 16:47:05 +01:00
|
|
|
// ------------- prepare triangles for position marks
|
|
|
|
QRectF rectBasic = QRectF(-UnitConvertor(0.5, Unit::Cm, Unit::Px),
|
|
|
|
0,
|
2020-11-19 14:33:27 +01:00
|
|
|
UnitConvertor(1, Unit::Cm, Unit::Px),
|
|
|
|
UnitConvertor(0.5, Unit::Cm, Unit::Px)
|
|
|
|
);
|
2020-11-21 16:47:05 +01:00
|
|
|
QPainterPath triangleBasic;
|
|
|
|
triangleBasic.moveTo(rectBasic.topLeft());
|
|
|
|
triangleBasic.lineTo(rectBasic.topRight());
|
|
|
|
triangleBasic.lineTo(rectBasic.left() + (rectBasic.width() / 2), rectBasic.bottom());
|
|
|
|
triangleBasic.lineTo(rectBasic.topLeft());
|
2020-11-19 14:33:27 +01:00
|
|
|
|
|
|
|
QBrush triangleBush = QBrush(QColor(200,200,200));
|
|
|
|
|
|
|
|
// add the tiles decorations (cutting and gluing lines, scissors, infos etc.)
|
|
|
|
painter->setPen(penTileInfos);
|
|
|
|
|
|
|
|
if(row > 0)
|
|
|
|
{
|
|
|
|
// add top triangle
|
2020-11-21 16:47:05 +01:00
|
|
|
QPainterPath triangleTop =
|
|
|
|
QTransform()
|
|
|
|
.translate(tilesMargins.left()+m_drawingAreaWidth/2, tilesMargins.top())
|
|
|
|
.map(triangleBasic);
|
2020-11-19 14:33:27 +01:00
|
|
|
painter->fillPath(triangleTop, triangleBush);
|
|
|
|
|
|
|
|
// scissors along the top line
|
|
|
|
svgRenderer->load(QStringLiteral("://puzzleicon/svg/icon_scissors_horizontal.svg"));
|
|
|
|
svgRenderer->render(painter, QRectF(tilesMargins.left() + m_drawingAreaWidth,
|
2021-09-06 14:31:19 +02:00
|
|
|
tilesMargins.top(),
|
|
|
|
UnitConvertor(1, Unit::Cm, Unit::Px),
|
|
|
|
UnitConvertor(0.56, Unit::Cm, Unit::Px)));
|
2020-11-19 14:33:27 +01:00
|
|
|
|
|
|
|
// dashed top line (for cutting)
|
|
|
|
penTileInfos.setStyle(Qt::DashLine);
|
|
|
|
painter->setPen(penTileInfos);
|
|
|
|
painter->drawLine(QPointF(tilesMargins.left(),
|
2021-09-06 14:31:19 +02:00
|
|
|
tilesMargins.top()),
|
|
|
|
QPointF(tilesMargins.left() + m_drawingAreaWidth + m_infoStripeWidth,
|
|
|
|
tilesMargins.top()));
|
2020-11-19 14:33:27 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// solid top line stopping at the edge
|
|
|
|
penTileInfos.setStyle(Qt::SolidLine);
|
|
|
|
painter->setPen(penTileInfos);
|
|
|
|
painter->drawLine(QPointF(tilesMargins.left(),
|
2021-09-06 14:31:19 +02:00
|
|
|
tilesMargins.top()),
|
|
|
|
QPointF(tilesMargins.left() + m_drawingAreaWidth + ((col < nbCol-1)? m_infoStripeWidth : 0),
|
|
|
|
tilesMargins.top()));
|
2020-11-19 14:33:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(col > 0)
|
|
|
|
{
|
|
|
|
// add left triangle
|
2020-11-21 16:47:05 +01:00
|
|
|
QPainterPath triangleLeft =
|
|
|
|
QTransform()
|
|
|
|
.translate(tilesMargins.left(), tilesMargins.top()+ m_drawingAreaHeight/2)
|
|
|
|
.rotate(-90)
|
|
|
|
.map(triangleBasic);
|
2020-11-19 14:33:27 +01:00
|
|
|
painter->fillPath(triangleLeft, triangleBush);
|
|
|
|
|
|
|
|
// scissors along the left line
|
|
|
|
svgRenderer->load(QStringLiteral("://puzzleicon/svg/icon_scissors_vertical.svg"));
|
|
|
|
svgRenderer->render(painter, QRectF(tilesMargins.left(),
|
|
|
|
tilesMargins.top()+m_drawingAreaHeight,
|
|
|
|
UnitConvertor(0.56, Unit::Cm, Unit::Px),
|
|
|
|
UnitConvertor(1, Unit::Cm, Unit::Px)
|
|
|
|
));
|
|
|
|
|
|
|
|
// dashed left line (for cutting)
|
|
|
|
penTileInfos.setStyle(Qt::DashLine);
|
|
|
|
painter->setPen(penTileInfos);
|
|
|
|
painter->drawLine(QPointF(tilesMargins.left(),
|
|
|
|
tilesMargins.top()),
|
|
|
|
QPointF(tilesMargins.left(),
|
|
|
|
tilesMargins.top() + m_drawingAreaHeight + m_infoStripeWidth)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// solid left line at the edge
|
|
|
|
penTileInfos.setStyle(Qt::SolidLine);
|
|
|
|
painter->setPen(penTileInfos);
|
|
|
|
painter->drawLine(QPointF(tilesMargins.left(),
|
|
|
|
tilesMargins.top()),
|
|
|
|
QPointF(tilesMargins.left(),
|
2021-09-06 14:31:19 +02:00
|
|
|
tilesMargins.top() + m_drawingAreaHeight + ((row < nbRow-1)? m_infoStripeWidth : 0))
|
2020-11-19 14:33:27 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
if(row < nbRow-1)
|
2020-11-19 14:33:27 +01:00
|
|
|
{
|
|
|
|
// add bottom triangle
|
2020-11-21 16:47:05 +01:00
|
|
|
QPainterPath triangleBottom =
|
|
|
|
QTransform()
|
|
|
|
.translate(tilesMargins.left()+ m_drawingAreaWidth/2, tilesMargins.top()+ m_drawingAreaHeight)
|
|
|
|
.rotate(180)
|
|
|
|
.map(triangleBasic);
|
|
|
|
|
2020-11-19 14:33:27 +01:00
|
|
|
painter->fillPath(triangleBottom, triangleBush);
|
|
|
|
|
|
|
|
// dotted bottom line (for glueing)
|
|
|
|
penTileInfos.setStyle(Qt::DotLine);
|
|
|
|
painter->setPen(penTileInfos);
|
|
|
|
painter->drawLine(QPointF(tilesMargins.left(),
|
|
|
|
tilesMargins.top() + m_drawingAreaHeight),
|
|
|
|
QPointF(tilesMargins.left() + m_drawingAreaWidth + m_infoStripeWidth,
|
|
|
|
tilesMargins.top() + m_drawingAreaHeight)
|
|
|
|
);
|
2021-09-06 14:31:19 +02:00
|
|
|
}
|
|
|
|
else
|
2020-11-19 14:33:27 +01:00
|
|
|
{
|
|
|
|
// solid bottom line at the edge
|
|
|
|
penTileInfos.setStyle(Qt::SolidLine);
|
|
|
|
painter->setPen(penTileInfos);
|
|
|
|
painter->drawLine(QPointF(tilesMargins.left(),
|
|
|
|
tilesMargins.top() + m_drawingAreaHeight),
|
2021-09-06 14:31:19 +02:00
|
|
|
QPointF(tilesMargins.left() + m_drawingAreaWidth + ((col < nbCol-1)? m_infoStripeWidth : 0),
|
2020-11-19 14:33:27 +01:00
|
|
|
tilesMargins.top() + m_drawingAreaHeight)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
if(col < nbCol-1)
|
2020-11-19 14:33:27 +01:00
|
|
|
{
|
|
|
|
// add right triangle
|
2020-11-21 16:47:05 +01:00
|
|
|
QPainterPath triangleRight =
|
|
|
|
QTransform()
|
|
|
|
.translate(tilesMargins.left()+ m_drawingAreaWidth, tilesMargins.top()+ m_drawingAreaHeight/2)
|
|
|
|
.rotate(90)
|
|
|
|
.map(triangleBasic);
|
2020-11-19 14:33:27 +01:00
|
|
|
painter->fillPath(triangleRight, triangleBush);
|
|
|
|
|
|
|
|
// dotted right line (for glueing)
|
|
|
|
penTileInfos.setStyle(Qt::DotLine);
|
|
|
|
painter->setPen(penTileInfos);
|
|
|
|
painter->drawLine(QPointF(tilesMargins.left() + m_drawingAreaWidth,
|
|
|
|
tilesMargins.top()),
|
|
|
|
QPointF(tilesMargins.left() + m_drawingAreaWidth,
|
|
|
|
tilesMargins.top()+ m_drawingAreaHeight + m_infoStripeWidth)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// solid right line at the edge
|
|
|
|
penTileInfos.setStyle(Qt::SolidLine);
|
|
|
|
painter->setPen(penTileInfos);
|
|
|
|
painter->drawLine(QPointF(tilesMargins.left() + m_drawingAreaWidth,
|
|
|
|
tilesMargins.top()),
|
|
|
|
QPointF(tilesMargins.left() + m_drawingAreaWidth,
|
2021-09-06 14:31:19 +02:00
|
|
|
tilesMargins.top()+ m_drawingAreaHeight + ((row < nbRow-1) ? m_infoStripeWidth : 0))
|
2020-11-19 14:33:27 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// prepare the painting for the text information
|
|
|
|
QTextDocument td;
|
2020-11-19 15:08:45 +01:00
|
|
|
td.setPageSize(QSizeF(
|
|
|
|
m_drawingAreaWidth - UnitConvertor(2, Unit::Cm, Unit::Px),
|
|
|
|
m_drawingAreaHeight
|
|
|
|
));
|
2020-11-19 14:33:27 +01:00
|
|
|
|
|
|
|
// paint the grid information
|
|
|
|
const QString grid = tr("Grid ( %1 , %2 )").arg(row+1).arg(col+1);
|
|
|
|
|
|
|
|
td.setHtml(QString("<table width='100%' style='color:rgb(180,180,180);'>"
|
|
|
|
"<tr>"
|
|
|
|
"<td align='center'>%1</td>"
|
|
|
|
"</tr>"
|
|
|
|
"</table>")
|
|
|
|
.arg(grid));
|
|
|
|
painter->setPen(penTileInfos);
|
|
|
|
painter->save();
|
|
|
|
painter->translate(QPointF(tilesMargins.left()+ UnitConvertor(1, Unit::Cm, Unit::Px),
|
|
|
|
m_drawingAreaHeight + tilesMargins.top()
|
|
|
|
));
|
|
|
|
td.drawContents(painter);
|
|
|
|
painter->restore();
|
|
|
|
|
|
|
|
// paint the page information
|
2021-09-06 14:31:19 +02:00
|
|
|
const QString page = tr("Page %1 of %2").arg(row*nbCol+col+1).arg(nbCol*nbRow);
|
2020-11-19 14:33:27 +01:00
|
|
|
|
|
|
|
td.setPageSize(QSizeF(m_drawingAreaHeight - UnitConvertor(2, Unit::Cm, Unit::Px), m_drawingAreaWidth));
|
2021-09-06 14:31:19 +02:00
|
|
|
|
|
|
|
QFontMetrics metrix = QFontMetrics(td.defaultFont());
|
|
|
|
QString clippedSheetName = metrix.elidedText(sheet->GetName(), Qt::ElideMiddle,
|
|
|
|
metrix.width(QString().fill('z', 50)));
|
|
|
|
|
2020-11-19 14:33:27 +01:00
|
|
|
td.setHtml(QString("<table width='100%' style='color:rgb(180,180,180);'>"
|
|
|
|
"<tr>"
|
|
|
|
"<td align='center'>%1 - %2</td>"
|
|
|
|
"</tr>"
|
|
|
|
"</table>")
|
2021-09-06 14:31:19 +02:00
|
|
|
.arg(page).arg(clippedSheetName));
|
2020-11-19 14:33:27 +01:00
|
|
|
painter->save();
|
|
|
|
painter->rotate(-90);
|
|
|
|
painter->translate(QPointF(-(m_drawingAreaHeight+tilesMargins.top()) + UnitConvertor(1, Unit::Cm, Unit::Px),
|
|
|
|
m_drawingAreaWidth + tilesMargins.left()
|
|
|
|
));
|
|
|
|
td.drawContents(painter);
|
|
|
|
painter->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-06 14:31:19 +02:00
|
|
|
auto VPTileFactory::RowNb(const VPSheetPtr &sheet) const -> int
|
2020-11-19 14:33:27 +01:00
|
|
|
{
|
2021-09-06 14:31:19 +02:00
|
|
|
if (sheet.isNull())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
QSizeF sheetSize = sheet->GetSheetSize();
|
|
|
|
return qCeil(sheetSize.height() / m_drawingAreaHeight);
|
2020-11-19 14:33:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-06 14:31:19 +02:00
|
|
|
auto VPTileFactory::ColNb(const VPSheetPtr &sheet) const -> int
|
2020-11-19 14:33:27 +01:00
|
|
|
{
|
2021-09-06 14:31:19 +02:00
|
|
|
if (sheet.isNull())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
QSizeF sheetSize = sheet->GetSheetSize();
|
|
|
|
return qCeil(sheetSize.width() / m_drawingAreaWidth);
|
2020-11-19 14:33:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-06 14:31:19 +02:00
|
|
|
auto VPTileFactory::DrawingAreaHeight() const -> qreal
|
2020-11-19 14:33:27 +01:00
|
|
|
{
|
|
|
|
return m_drawingAreaHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-06 14:31:19 +02:00
|
|
|
auto VPTileFactory::DrawingAreaWidth() const -> qreal
|
2020-11-19 14:33:27 +01:00
|
|
|
{
|
|
|
|
return m_drawingAreaWidth;
|
|
|
|
}
|