Fix generation tiles.
This commit is contained in:
parent
22da66e4d8
commit
048035db79
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "../vptilefactory.h"
|
||||
#include "../layout/vplayout.h"
|
||||
#include "../layout/vpsheet.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -24,12 +25,21 @@ auto VPGraphicsTileGrid::boundingRect() const -> QRectF
|
|||
{
|
||||
VPSheetPtr sheet = layout->GetSheet(m_sheetUuid);
|
||||
|
||||
QMarginsF sheetMargins;
|
||||
if (not sheet.isNull() && not sheet->IgnoreMargins())
|
||||
{
|
||||
sheetMargins = sheet->GetSheetMargins();
|
||||
}
|
||||
|
||||
qreal xScale = layout->LayoutSettings().HorizontalScale();
|
||||
qreal yScale = layout->LayoutSettings().VerticalScale();
|
||||
|
||||
QRectF rect(0, 0,
|
||||
layout->TileFactory()->ColNb(sheet) * (layout->TileFactory()->DrawingAreaWidth() / xScale),
|
||||
layout->TileFactory()->RowNb(sheet) * (layout->TileFactory()->DrawingAreaHeight() / yScale));
|
||||
qreal width = layout->TileFactory()->DrawingAreaWidth() - VPTileFactory::tileStripeWidth;
|
||||
qreal height = layout->TileFactory()->DrawingAreaHeight() - VPTileFactory::tileStripeWidth;
|
||||
|
||||
QRectF rect(sheetMargins.left(), sheetMargins.top(),
|
||||
layout->TileFactory()->ColNb(sheet) * (width / xScale),
|
||||
layout->TileFactory()->RowNb(sheet) * (height / yScale));
|
||||
|
||||
constexpr qreal halfPenWidth = penWidth/2.;
|
||||
|
||||
|
@ -50,6 +60,12 @@ void VPGraphicsTileGrid::paint(QPainter *painter, const QStyleOptionGraphicsItem
|
|||
{
|
||||
VPSheetPtr sheet = layout->GetSheet(m_sheetUuid);
|
||||
|
||||
QMarginsF sheetMargins;
|
||||
if (not sheet.isNull() && not sheet->IgnoreMargins())
|
||||
{
|
||||
sheetMargins = sheet->GetSheetMargins();
|
||||
}
|
||||
|
||||
QPen pen(QColor(255,0,0,127), penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
|
||||
pen.setCosmetic(true);
|
||||
pen.setStyle(Qt::DashLine);
|
||||
|
@ -60,19 +76,24 @@ void VPGraphicsTileGrid::paint(QPainter *painter, const QStyleOptionGraphicsItem
|
|||
qreal xScale = layout->LayoutSettings().HorizontalScale();
|
||||
qreal yScale = layout->LayoutSettings().VerticalScale();
|
||||
|
||||
const qreal drawingAreaWidth = layout->TileFactory()->DrawingAreaWidth() / xScale;
|
||||
const qreal drawingAreaHeight = layout->TileFactory()->DrawingAreaHeight() / yScale;
|
||||
const qreal width = (layout->TileFactory()->DrawingAreaWidth() - VPTileFactory::tileStripeWidth) / xScale;
|
||||
const qreal height = (layout->TileFactory()->DrawingAreaHeight() - VPTileFactory::tileStripeWidth) / yScale;
|
||||
|
||||
for(int i=0;i<=layout->TileFactory()->ColNb(sheet);i++)
|
||||
const int nbCol = layout->TileFactory()->ColNb(sheet);
|
||||
const int nbRow = layout->TileFactory()->RowNb(sheet);
|
||||
|
||||
for(int i=0;i<=nbCol;++i)
|
||||
{
|
||||
painter->drawLine(QPointF(i*drawingAreaWidth, 0),
|
||||
QPointF(i*drawingAreaWidth, layout->TileFactory()->RowNb(sheet)*drawingAreaHeight));
|
||||
// vertical lines
|
||||
painter->drawLine(QPointF(sheetMargins.left()+i*width, sheetMargins.top()),
|
||||
QPointF(sheetMargins.left()+i*width, sheetMargins.top() + nbRow*height));
|
||||
}
|
||||
|
||||
for(int j=0;j<=layout->TileFactory()->RowNb(sheet);j++)
|
||||
for(int j=0;j<=nbRow;++j)
|
||||
{
|
||||
painter->drawLine(QPointF(0, j*drawingAreaHeight),
|
||||
QPointF(layout->TileFactory()->ColNb(sheet)*drawingAreaWidth, j*drawingAreaHeight));
|
||||
// horizontal lines
|
||||
painter->drawLine(QPointF(sheetMargins.left(), sheetMargins.top()+j*height),
|
||||
QPointF(sheetMargins.left()+nbCol*width, sheetMargins.top()+j*height));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,7 @@
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPTileFactory::VPTileFactory(const VPLayoutPtr &layout, VCommonSettings *commonSettings):
|
||||
m_layout(layout),
|
||||
m_commonSettings(commonSettings),
|
||||
m_infoStripeWidth(UnitConvertor(1, Unit::Cm, Unit::Px))
|
||||
m_commonSettings(commonSettings)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -31,11 +30,7 @@ void VPTileFactory::refreshTileInfos()
|
|||
|
||||
if (not layout->LayoutSettings().IgnoreTilesMargins())
|
||||
{
|
||||
m_drawingAreaHeight -= tilesMargins.top() + tilesMargins.bottom() + m_infoStripeWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_drawingAreaHeight += m_infoStripeWidth;
|
||||
m_drawingAreaHeight -= tilesMargins.top() + tilesMargins.bottom();
|
||||
}
|
||||
|
||||
// sets the drawing width
|
||||
|
@ -43,11 +38,7 @@ void VPTileFactory::refreshTileInfos()
|
|||
|
||||
if (not layout->LayoutSettings().IgnoreTilesMargins())
|
||||
{
|
||||
m_drawingAreaWidth -= tilesMargins.left() + tilesMargins.right() + m_infoStripeWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_drawingAreaWidth += m_infoStripeWidth;
|
||||
m_drawingAreaWidth -= tilesMargins.left() + tilesMargins.right();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +60,12 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
|
|||
return;
|
||||
}
|
||||
|
||||
QMarginsF sheetMargins;
|
||||
if (not sheet->IgnoreMargins())
|
||||
{
|
||||
sheetMargins = sheet->GetSheetMargins();
|
||||
}
|
||||
|
||||
const int nbCol = ColNb(sheet);
|
||||
const int nbRow = RowNb(sheet);
|
||||
|
||||
|
@ -88,17 +85,15 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
|
|||
// paint the content of the page
|
||||
qreal xScale = layout->LayoutSettings().HorizontalScale();
|
||||
qreal yScale = layout->LayoutSettings().VerticalScale();
|
||||
QRectF source = QRectF(col*m_drawingAreaWidth / xScale,
|
||||
row*m_drawingAreaHeight / yScale,
|
||||
m_drawingAreaWidth / xScale + m_infoStripeWidth,
|
||||
m_drawingAreaHeight / yScale + m_infoStripeWidth
|
||||
);
|
||||
QRectF source = QRectF(sheetMargins.left() + col*(m_drawingAreaWidth - tileStripeWidth) / xScale,
|
||||
sheetMargins.top() + row*(m_drawingAreaHeight - tileStripeWidth) / yScale,
|
||||
m_drawingAreaWidth / xScale,
|
||||
m_drawingAreaHeight / yScale);
|
||||
|
||||
QRectF target = QRectF(col*m_drawingAreaWidth,
|
||||
row*m_drawingAreaHeight,
|
||||
m_drawingAreaWidth + m_infoStripeWidth,
|
||||
m_drawingAreaHeight + m_infoStripeWidth
|
||||
);
|
||||
QRectF target = QRectF(0,
|
||||
0,
|
||||
m_drawingAreaWidth,
|
||||
m_drawingAreaHeight);
|
||||
sheet->SceneData()->Scene()->render(painter, VPrintLayout::SceneTargetRect(printer, target), source,
|
||||
Qt::IgnoreAspectRatio);
|
||||
|
||||
|
@ -126,34 +121,35 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
|
|||
// add top triangle
|
||||
QPainterPath triangleTop =
|
||||
QTransform()
|
||||
.translate(tilesMargins.left()+m_drawingAreaWidth/2, tilesMargins.top())
|
||||
.translate(m_drawingAreaWidth/2, 0)
|
||||
.map(triangleBasic);
|
||||
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,
|
||||
tilesMargins.top(),
|
||||
UnitConvertor(1, Unit::Cm, Unit::Px),
|
||||
svgRenderer->render(painter, QRectF(m_drawingAreaWidth - tileStripeWidth, 0,
|
||||
UnitConvertor(0.95, Unit::Cm, Unit::Px),
|
||||
UnitConvertor(0.56, Unit::Cm, Unit::Px)));
|
||||
|
||||
// dashed top line (for cutting)
|
||||
penTileInfos.setStyle(Qt::DashLine);
|
||||
painter->setPen(penTileInfos);
|
||||
painter->drawLine(QPointF(tilesMargins.left(),
|
||||
tilesMargins.top()),
|
||||
QPointF(tilesMargins.left() + m_drawingAreaWidth + m_infoStripeWidth,
|
||||
tilesMargins.top()));
|
||||
painter->drawLine(QPointF(), QPointF(m_drawingAreaWidth, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
// solid top line stopping at the edge
|
||||
penTileInfos.setStyle(Qt::SolidLine);
|
||||
painter->setPen(penTileInfos);
|
||||
painter->drawLine(QPointF(tilesMargins.left(),
|
||||
tilesMargins.top()),
|
||||
QPointF(tilesMargins.left() + m_drawingAreaWidth + ((col < nbCol-1)? m_infoStripeWidth : 0),
|
||||
tilesMargins.top()));
|
||||
|
||||
if(col < nbCol - 1)
|
||||
{
|
||||
painter->drawLine(QPointF(), QPointF(m_drawingAreaWidth, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->drawLine(QPointF(), QPointF(m_drawingAreaWidth - tileStripeWidth, 0));
|
||||
}
|
||||
}
|
||||
|
||||
if(col > 0)
|
||||
|
@ -161,38 +157,36 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
|
|||
// add left triangle
|
||||
QPainterPath triangleLeft =
|
||||
QTransform()
|
||||
.translate(tilesMargins.left(), tilesMargins.top()+ m_drawingAreaHeight/2)
|
||||
.translate(0, m_drawingAreaHeight/2)
|
||||
.rotate(-90)
|
||||
.map(triangleBasic);
|
||||
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)
|
||||
));
|
||||
svgRenderer->render(painter, QRectF(0, m_drawingAreaHeight - tileStripeWidth,
|
||||
UnitConvertor(0.56, Unit::Cm, Unit::Px),
|
||||
UnitConvertor(0.95, 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)
|
||||
);
|
||||
painter->drawLine(QPointF(), QPointF(0, m_drawingAreaHeight));
|
||||
}
|
||||
else
|
||||
{
|
||||
// solid left line at the edge
|
||||
penTileInfos.setStyle(Qt::SolidLine);
|
||||
painter->setPen(penTileInfos);
|
||||
painter->drawLine(QPointF(tilesMargins.left(),
|
||||
tilesMargins.top()),
|
||||
QPointF(tilesMargins.left(),
|
||||
tilesMargins.top() + m_drawingAreaHeight + ((row < nbRow-1)? m_infoStripeWidth : 0))
|
||||
);
|
||||
|
||||
if(row < nbRow - 1)
|
||||
{
|
||||
painter->drawLine(QPointF(), QPointF(0, m_drawingAreaHeight));
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->drawLine(QPointF(), QPointF(0, m_drawingAreaHeight - tileStripeWidth));
|
||||
}
|
||||
}
|
||||
|
||||
if(row < nbRow-1)
|
||||
|
@ -200,7 +194,7 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
|
|||
// add bottom triangle
|
||||
QPainterPath triangleBottom =
|
||||
QTransform()
|
||||
.translate(tilesMargins.left()+ m_drawingAreaWidth/2, tilesMargins.top()+ m_drawingAreaHeight)
|
||||
.translate(m_drawingAreaWidth/2, m_drawingAreaHeight - tileStripeWidth)
|
||||
.rotate(180)
|
||||
.map(triangleBasic);
|
||||
|
||||
|
@ -209,22 +203,25 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
|
|||
// 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)
|
||||
);
|
||||
painter->drawLine(QPointF(0, m_drawingAreaHeight - tileStripeWidth),
|
||||
QPointF(m_drawingAreaWidth, m_drawingAreaHeight - tileStripeWidth));
|
||||
}
|
||||
else
|
||||
{
|
||||
// solid bottom line at the edge
|
||||
penTileInfos.setStyle(Qt::SolidLine);
|
||||
painter->setPen(penTileInfos);
|
||||
painter->drawLine(QPointF(tilesMargins.left(),
|
||||
tilesMargins.top() + m_drawingAreaHeight),
|
||||
QPointF(tilesMargins.left() + m_drawingAreaWidth + ((col < nbCol-1)? m_infoStripeWidth : 0),
|
||||
tilesMargins.top() + m_drawingAreaHeight)
|
||||
);
|
||||
|
||||
if(col < nbCol - 1)
|
||||
{
|
||||
painter->drawLine(QPointF(0, m_drawingAreaHeight - tileStripeWidth),
|
||||
QPointF(m_drawingAreaWidth, m_drawingAreaHeight - tileStripeWidth));
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->drawLine(QPointF(0, m_drawingAreaHeight - tileStripeWidth),
|
||||
QPointF(m_drawingAreaWidth - tileStripeWidth, m_drawingAreaHeight - tileStripeWidth));;
|
||||
}
|
||||
}
|
||||
|
||||
if(col < nbCol-1)
|
||||
|
@ -232,7 +229,7 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
|
|||
// add right triangle
|
||||
QPainterPath triangleRight =
|
||||
QTransform()
|
||||
.translate(tilesMargins.left()+ m_drawingAreaWidth, tilesMargins.top()+ m_drawingAreaHeight/2)
|
||||
.translate(m_drawingAreaWidth - tileStripeWidth, m_drawingAreaHeight/2)
|
||||
.rotate(90)
|
||||
.map(triangleBasic);
|
||||
painter->fillPath(triangleRight, triangleBush);
|
||||
|
@ -240,30 +237,30 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
|
|||
// 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)
|
||||
);
|
||||
painter->drawLine(QPointF(m_drawingAreaWidth - tileStripeWidth, 0),
|
||||
QPointF(m_drawingAreaWidth - tileStripeWidth, m_drawingAreaHeight));
|
||||
}
|
||||
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,
|
||||
tilesMargins.top()+ m_drawingAreaHeight + ((row < nbRow-1) ? m_infoStripeWidth : 0))
|
||||
);
|
||||
|
||||
if(row < nbRow - 1)
|
||||
{
|
||||
painter->drawLine(QPointF(m_drawingAreaWidth - tileStripeWidth, 0),
|
||||
QPointF(m_drawingAreaWidth - tileStripeWidth, m_drawingAreaHeight));
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->drawLine(QPointF(m_drawingAreaWidth - tileStripeWidth, 0),
|
||||
QPointF(m_drawingAreaWidth - tileStripeWidth, m_drawingAreaHeight - tileStripeWidth));
|
||||
}
|
||||
}
|
||||
|
||||
// prepare the painting for the text information
|
||||
QTextDocument td;
|
||||
td.setPageSize(QSizeF(
|
||||
m_drawingAreaWidth - UnitConvertor(2, Unit::Cm, Unit::Px),
|
||||
m_drawingAreaHeight
|
||||
));
|
||||
td.setPageSize(QSizeF(m_drawingAreaWidth - UnitConvertor(2, Unit::Cm, Unit::Px), m_drawingAreaHeight));
|
||||
|
||||
// paint the grid information
|
||||
const QString grid = tr("Grid ( %1 , %2 )").arg(row+1).arg(col+1);
|
||||
|
@ -276,9 +273,7 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
|
|||
.arg(grid));
|
||||
painter->setPen(penTileInfos);
|
||||
painter->save();
|
||||
painter->translate(QPointF(tilesMargins.left()+ UnitConvertor(1, Unit::Cm, Unit::Px),
|
||||
m_drawingAreaHeight + tilesMargins.top()
|
||||
));
|
||||
painter->translate(QPointF(UnitConvertor(1, Unit::Cm, Unit::Px), m_drawingAreaHeight - tileStripeWidth));
|
||||
td.drawContents(painter);
|
||||
painter->restore();
|
||||
|
||||
|
@ -299,9 +294,8 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
|
|||
.arg(page).arg(clippedSheetName));
|
||||
painter->save();
|
||||
painter->rotate(-90);
|
||||
painter->translate(QPointF(-(m_drawingAreaHeight+tilesMargins.top()) + UnitConvertor(1, Unit::Cm, Unit::Px),
|
||||
m_drawingAreaWidth + tilesMargins.left()
|
||||
));
|
||||
painter->translate(QPointF(-(m_drawingAreaHeight) + UnitConvertor(1, Unit::Cm, Unit::Px),
|
||||
m_drawingAreaWidth - tileStripeWidth));
|
||||
td.drawContents(painter);
|
||||
painter->restore();
|
||||
}
|
||||
|
@ -322,7 +316,7 @@ auto VPTileFactory::RowNb(const VPSheetPtr &sheet) const -> int
|
|||
}
|
||||
|
||||
QSizeF sheetSize = sheet->GetSheetSize();
|
||||
return qCeil(sheetSize.height() * yScale / m_drawingAreaHeight);
|
||||
return qCeil(sheetSize.height() * yScale / (m_drawingAreaHeight - tileStripeWidth));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -341,7 +335,7 @@ auto VPTileFactory::ColNb(const VPSheetPtr &sheet) const -> int
|
|||
}
|
||||
|
||||
QSizeF sheetSize = sheet->GetSheetSize();
|
||||
return qCeil(sheetSize.width() * xScale / m_drawingAreaWidth);
|
||||
return qCeil(sheetSize.width() * xScale / (m_drawingAreaWidth - tileStripeWidth));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -85,6 +85,11 @@ public:
|
|||
*/
|
||||
auto DrawingAreaWidth() const -> qreal;
|
||||
|
||||
/**
|
||||
* @brief tileStripeWidth the width of the info / glueing stripe in Px
|
||||
*/
|
||||
static constexpr qreal tileStripeWidth = UnitConvertor(1, Unit::Cm, Unit::Px);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VPTileFactory)
|
||||
|
||||
|
@ -101,11 +106,6 @@ private:
|
|||
*/
|
||||
qreal m_drawingAreaWidth{0};
|
||||
|
||||
/**
|
||||
* @brief m_infoStripeWidth the width of the info / glueing stripe in Px
|
||||
*/
|
||||
qreal m_infoStripeWidth;
|
||||
|
||||
};
|
||||
|
||||
#endif // VPTILEFACTORY_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user