Refactoring.

This commit is contained in:
Roman Telezhynskyi 2022-02-12 12:01:07 +02:00
parent 7494b05b92
commit 2e56a61bb6
2 changed files with 346 additions and 205 deletions

View File

@ -4,6 +4,7 @@
#include "../vwidgets/vmaingraphicsscene.h" #include "../vwidgets/vmaingraphicsscene.h"
#include "layout/vpsheet.h" #include "layout/vpsheet.h"
#include "qobject.h"
#include "scene/vpmaingraphicsview.h" #include "scene/vpmaingraphicsview.h"
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "../vmisc/vcommonsettings.h" #include "../vmisc/vcommonsettings.h"
@ -11,7 +12,8 @@
namespace namespace
{ {
const QColor tileColor(180, 180, 180); Q_GLOBAL_STATIC_WITH_ARGS(QColor, tileColor, (180, 180, 180)) // NOLINT
Q_GLOBAL_STATIC_WITH_ARGS(QBrush, triangleBush, (QColor(200,200,200))) // NOLINT
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto Grayscale(QImage image) -> QImage auto Grayscale(QImage image) -> QImage
@ -22,7 +24,7 @@ auto Grayscale(QImage image) -> QImage
int depth = 4; int depth = 4;
for (int jj = 0; jj < image.width(); jj++) for (int jj = 0; jj < image.width(); jj++)
{ {
QRgb* rgbpixel = reinterpret_cast<QRgb*>(scan + jj * depth); auto* rgbpixel = reinterpret_cast<QRgb*>(scan + jj * depth); // NOLINT
int gray = qGray(*rgbpixel); int gray = qGray(*rgbpixel);
*rgbpixel = QColor(gray, gray, gray, qAlpha(*rgbpixel)).rgba(); *rgbpixel = QColor(gray, gray, gray, qAlpha(*rgbpixel)).rgba();
} }
@ -37,7 +39,7 @@ auto WatermarkImageFromCache(const VWatermarkData &watermarkData, const QString
{ {
QPixmap pixmap; QPixmap pixmap;
QString imagePath = AbsoluteMPath(watermarkPath, watermarkData.path); QString imagePath = AbsoluteMPath(watermarkPath, watermarkData.path);
QString imageCacheKey = QString("puzzle=path%1+rotation%3+grayscale%4+xscale%5+yxcale%6") QString imageCacheKey = QStringLiteral("puzzle=path%1+rotation%3+grayscale%4+xscale%5+yxcale%6")
.arg(imagePath, QString::number(watermarkData.imageRotation), .arg(imagePath, QString::number(watermarkData.imageRotation),
watermarkData.grayscale ? trueStr : falseStr ).arg(xScale).arg(yScale); watermarkData.grayscale ? trueStr : falseStr ).arg(xScale).arg(yScale);
@ -72,10 +74,28 @@ auto WatermarkImageFromCache(const VWatermarkData &watermarkData, const QString
} }
return pixmap; return pixmap;
} }
//---------------------------------------------------------------------------------------------------------------------
// ------------- prepare triangles for position marks
auto TriangleBasic() -> QPainterPath
{
// ------------- prepare triangles for position marks
QRectF rectBasic = QRectF(-UnitConvertor(0.5, Unit::Cm, Unit::Px),
0,
UnitConvertor(1, Unit::Cm, Unit::Px),
UnitConvertor(0.5, Unit::Cm, Unit::Px));
QPainterPath triangleBasic;
triangleBasic.moveTo(rectBasic.topLeft());
triangleBasic.lineTo(rectBasic.topRight());
triangleBasic.lineTo(rectBasic.left() + (rectBasic.width() / 2.), rectBasic.bottom());
triangleBasic.lineTo(rectBasic.topLeft());
return triangleBasic;
}
} // namespace } // namespace
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPTileFactory::VPTileFactory(const VPLayoutPtr &layout, VCommonSettings *commonSettings): VPTileFactory::VPTileFactory(const VPLayoutPtr &layout, VCommonSettings *commonSettings, QObject *parent):
QObject(parent),
m_layout(layout), m_layout(layout),
m_commonSettings(commonSettings) m_commonSettings(commonSettings)
{ {
@ -127,12 +147,6 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
return; return;
} }
QMarginsF sheetMargins;
if (not sheet->IgnoreMargins())
{
sheetMargins = sheet->GetSheetMargins();
}
const int nbCol = ColNb(sheet); const int nbCol = ColNb(sheet);
const int nbRow = RowNb(sheet); const int nbRow = RowNb(sheet);
@ -141,153 +155,52 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
return; return;
} }
QPen penTileInfos = QPen(tileColor, m_commonSettings->WidthHairLine(), Qt::DashLine, Qt::RoundCap, DrawTilePageContent(painter, sheet, row, col, printer);
Qt::RoundJoin);
QPen penTileDrawing = QPen(Qt::black, m_commonSettings->WidthMainLine(), Qt::SolidLine, Qt::RoundCap,
Qt::RoundJoin);
painter->setPen(penTileDrawing);
// paint the content of the page
qreal xScale = layout->LayoutSettings().HorizontalScale();
qreal yScale = layout->LayoutSettings().VerticalScale();
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(0,
0,
m_drawingAreaWidth,
m_drawingAreaHeight);
sheet->SceneData()->Scene()->render(painter, VPrintLayout::SceneTargetRect(printer, target), source,
Qt::IgnoreAspectRatio);
QScopedPointer<QSvgRenderer> svgRenderer(new QSvgRenderer());
// ------------- prepare triangles for position marks
QRectF rectBasic = QRectF(-UnitConvertor(0.5, Unit::Cm, Unit::Px),
0,
UnitConvertor(1, Unit::Cm, Unit::Px),
UnitConvertor(0.5, Unit::Cm, Unit::Px)
);
QPainterPath triangleBasic;
triangleBasic.moveTo(rectBasic.topLeft());
triangleBasic.lineTo(rectBasic.topRight());
triangleBasic.lineTo(rectBasic.left() + (rectBasic.width() / 2), rectBasic.bottom());
triangleBasic.lineTo(rectBasic.topLeft());
QBrush triangleBush = QBrush(QColor(200,200,200));
// add the tiles decorations (cutting and gluing lines, scissors, infos etc.) // add the tiles decorations (cutting and gluing lines, scissors, infos etc.)
painter->setPen(penTileInfos); painter->setPen(PenTileInfos());
if(row > 0) if(row > 0)
{ {
// add top triangle // add top triangle
QPainterPath triangleTop = DrawTopTriangle(painter);
QTransform() // scissors along the top line
.translate(m_drawingAreaWidth/2, 0) DrawTopLineScissors(painter);
.map(triangleBasic);
painter->fillPath(triangleTop, triangleBush);
// scissors along the top line
svgRenderer->load(QStringLiteral("://puzzleicon/svg/icon_scissors_horizontal.svg"));
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) // dashed top line (for cutting)
penTileInfos.setStyle(Qt::DashLine); DrawTopCuttingLine(painter);
painter->setPen(penTileInfos);
painter->drawLine(QPointF(), QPointF(m_drawingAreaWidth, 0));
} }
else else
{ {
// solid top line stopping at the edge // solid top line stopping at the edge
penTileInfos.setStyle(Qt::SolidLine); DrawSolidTopLine(painter, col, nbCol);
painter->setPen(penTileInfos);
if(col < nbCol - 1)
{
painter->drawLine(QPointF(), QPointF(m_drawingAreaWidth, 0));
}
else
{
painter->drawLine(QPointF(), QPointF(m_drawingAreaWidth - tileStripeWidth, 0));
}
} }
if(col > 0) if(col > 0)
{ {
// add left triangle // add left triangle
QPainterPath triangleLeft = DrawLeftTriangle(painter);
QTransform() // scissors along the left line
.translate(0, m_drawingAreaHeight/2) DrawLeftLineScissors(painter);
.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(0, m_drawingAreaHeight - tileStripeWidth,
UnitConvertor(0.56, Unit::Cm, Unit::Px),
UnitConvertor(0.95, Unit::Cm, Unit::Px)));
// dashed left line (for cutting) // dashed left line (for cutting)
penTileInfos.setStyle(Qt::DashLine); DrawLeftCuttingLine(painter);
painter->setPen(penTileInfos);
painter->drawLine(QPointF(), QPointF(0, m_drawingAreaHeight));
} }
else else
{ {
// solid left line at the edge // solid left line at the edge
penTileInfos.setStyle(Qt::SolidLine); DrawSolidLeftLine(painter, row, nbRow);
painter->setPen(penTileInfos);
if(row < nbRow - 1)
{
painter->drawLine(QPointF(), QPointF(0, m_drawingAreaHeight));
}
else
{
painter->drawLine(QPointF(), QPointF(0, m_drawingAreaHeight - tileStripeWidth));
}
} }
if(row < nbRow-1) if(row < nbRow-1)
{ {
// add bottom triangle // add bottom triangle
QPainterPath triangleBottom = DrawBottomTriangle(painter);
QTransform()
.translate(m_drawingAreaWidth/2, m_drawingAreaHeight - tileStripeWidth)
.rotate(180)
.map(triangleBasic);
painter->fillPath(triangleBottom, triangleBush);
// dotted bottom line (for glueing) // dotted bottom line (for glueing)
penTileInfos.setStyle(Qt::DotLine); DrawBottomCuttingLine(painter);
painter->setPen(penTileInfos);
painter->drawLine(QPointF(0, m_drawingAreaHeight - tileStripeWidth),
QPointF(m_drawingAreaWidth, m_drawingAreaHeight - tileStripeWidth));
} }
else else
{ {
// solid bottom line at the edge // solid bottom line at the edge
penTileInfos.setStyle(Qt::SolidLine); DrawSolidBottomLine(painter, col, nbCol);
painter->setPen(penTileInfos);
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));;
}
} }
DrawRuler(painter); DrawRuler(painter);
@ -296,82 +209,18 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
if(col < nbCol-1) if(col < nbCol-1)
{ {
// add right triangle // add right triangle
QPainterPath triangleRight = DrawRightTriangle(painter);
QTransform()
.translate(m_drawingAreaWidth - tileStripeWidth, m_drawingAreaHeight/2)
.rotate(90)
.map(triangleBasic);
painter->fillPath(triangleRight, triangleBush);
// dotted right line (for glueing) // dotted right line (for glueing)
penTileInfos.setStyle(Qt::DotLine); DrawRightCuttingLine(painter);
painter->setPen(penTileInfos);
painter->drawLine(QPointF(m_drawingAreaWidth - tileStripeWidth, 0),
QPointF(m_drawingAreaWidth - tileStripeWidth, m_drawingAreaHeight));
} }
else else
{ {
// solid right line at the edge // solid right line at the edge
penTileInfos.setStyle(Qt::SolidLine); DrawSolidRightLine(painter, row, nbRow);
painter->setPen(penTileInfos);
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 // prepare the painting for the text information
QTextDocument td; DrawTextInformation(painter, row, col, nbRow, nbCol, sheet->GetName());
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);
const QString tileColorStr = QString("%1,%2,%3").arg(tileColor.red()).arg(tileColor.green()).arg(tileColor.blue());
td.setHtml(QString("<table width='100%' style='color:rgb(%1);'>"
"<tr>"
"<td align='center'>%2</td>"
"</tr>"
"</table>")
.arg(tileColorStr, grid));
painter->setPen(penTileInfos);
painter->save();
painter->translate(QPointF(UnitConvertor(1, Unit::Cm, Unit::Px), m_drawingAreaHeight - tileStripeWidth/1.3));
td.drawContents(painter);
painter->restore();
// paint the page information
const QString page = tr("Page %1 of %2").arg(row*nbCol+col+1).arg(nbCol*nbRow);
td.setPageSize(QSizeF(m_drawingAreaHeight - UnitConvertor(2, Unit::Cm, Unit::Px), m_drawingAreaWidth));
QFontMetrics metrix = QFontMetrics(td.defaultFont());
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
int maxWidth = metrix.horizontalAdvance(QString().fill('z', 50));
#else
int maxWidth = metrix.width(QString().fill('z', 50));
#endif
QString clippedSheetName = metrix.elidedText(sheet->GetName(), Qt::ElideMiddle, maxWidth);
td.setHtml(QString("<table width='100%' style='color:rgb(%1);'>"
"<tr>"
"<td align='center'>%2 - %3</td>"
"</tr>"
"</table>")
.arg(tileColorStr).arg(page).arg(clippedSheetName));
painter->save();
painter->rotate(-90);
painter->translate(QPointF(-(m_drawingAreaHeight) + UnitConvertor(1, Unit::Cm, Unit::Px),
m_drawingAreaWidth - tileStripeWidth));
td.drawContents(painter);
painter->restore();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -431,7 +280,7 @@ auto VPTileFactory::WatermarkData() const -> const VWatermarkData &
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawRuler(QPainter *painter) void VPTileFactory::DrawRuler(QPainter *painter) const
{ {
VPLayoutPtr layout = m_layout.toStrongRef(); VPLayoutPtr layout = m_layout.toStrongRef();
if(layout.isNull()) if(layout.isNull())
@ -439,7 +288,7 @@ void VPTileFactory::DrawRuler(QPainter *painter)
return; return;
} }
QPen rulePen(tileColor, 1, Qt::SolidLine); QPen rulePen(*tileColor, 1, Qt::SolidLine);
painter->save(); painter->save();
painter->setPen(rulePen); painter->setPen(rulePen);
@ -488,7 +337,7 @@ void VPTileFactory::DrawRuler(QPainter *painter)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawWatermark(QPainter *painter) void VPTileFactory::DrawWatermark(QPainter *painter) const
{ {
SCASSERT(painter != nullptr) SCASSERT(painter != nullptr)
@ -517,6 +366,269 @@ void VPTileFactory::DrawWatermark(QPainter *painter)
} }
} }
//---------------------------------------------------------------------------------------------------------------------
inline auto VPTileFactory::PenTileInfos() const -> QPen
{
return {*tileColor, m_commonSettings->WidthHairLine(), Qt::DashLine, Qt::RoundCap, Qt::RoundJoin};
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawTilePageContent(QPainter *painter, const VPSheetPtr &sheet, int row, int col,
QPrinter *printer) const
{
VPLayoutPtr layout = m_layout.toStrongRef();
if(layout.isNull())
{
return;
}
QMarginsF sheetMargins;
if (not sheet->IgnoreMargins())
{
sheetMargins = sheet->GetSheetMargins();
}
QPen penTileDrawing = QPen(Qt::black, m_commonSettings->WidthMainLine(), Qt::SolidLine, Qt::RoundCap,
Qt::RoundJoin);
painter->setPen(penTileDrawing);
// paint the content of the page
const qreal xScale = layout->LayoutSettings().HorizontalScale();
const qreal yScale = layout->LayoutSettings().VerticalScale();
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(0,
0,
m_drawingAreaWidth,
m_drawingAreaHeight);
sheet->SceneData()->Scene()->render(painter, VPrintLayout::SceneTargetRect(printer, target), source,
Qt::IgnoreAspectRatio);
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawTopTriangle(QPainter *painter) const
{
QPainterPath triangleTop =
QTransform()
.translate(m_drawingAreaWidth/2, 0)
.map(TriangleBasic());
painter->fillPath(triangleTop, *triangleBush);
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawLeftTriangle(QPainter *painter) const
{
QPainterPath triangleLeft =
QTransform()
.translate(0, m_drawingAreaHeight/2)
.rotate(-90)
.map(TriangleBasic());
painter->fillPath(triangleLeft, *triangleBush);
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawBottomTriangle(QPainter *painter) const
{
QPainterPath triangleBottom =
QTransform()
.translate(m_drawingAreaWidth/2, m_drawingAreaHeight - tileStripeWidth)
.rotate(180)
.map(TriangleBasic());
painter->fillPath(triangleBottom, *triangleBush);
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawRightTriangle(QPainter *painter) const
{
QPainterPath triangleRight =
QTransform()
.translate(m_drawingAreaWidth - tileStripeWidth, m_drawingAreaHeight/2)
.rotate(90)
.map(TriangleBasic());
painter->fillPath(triangleRight, *triangleBush);
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawTopLineScissors(QPainter *painter) const
{
QSvgRenderer svgRenderer(QStringLiteral("://puzzleicon/svg/icon_scissors_horizontal.svg"));
svgRenderer.render(painter, QRectF(m_drawingAreaWidth - tileStripeWidth, 0,
UnitConvertor(0.95, Unit::Cm, Unit::Px),
UnitConvertor(0.56, Unit::Cm, Unit::Px)));
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawLeftLineScissors(QPainter *painter) const
{
QSvgRenderer svgRenderer(QStringLiteral("://puzzleicon/svg/icon_scissors_vertical.svg"));
svgRenderer.render(painter, QRectF(0, m_drawingAreaHeight - tileStripeWidth,
UnitConvertor(0.56, Unit::Cm, Unit::Px),
UnitConvertor(0.95, Unit::Cm, Unit::Px)));
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawTopCuttingLine(QPainter *painter) const
{
QPen penTileInfos = PenTileInfos();
penTileInfos.setStyle(Qt::DashLine);
painter->setPen(penTileInfos);
painter->drawLine(QPointF(), QPointF(m_drawingAreaWidth, 0));
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawLeftCuttingLine(QPainter *painter) const
{
QPen penTileInfos = PenTileInfos();
penTileInfos.setStyle(Qt::DashLine);
painter->setPen(penTileInfos);
painter->drawLine(QPointF(), QPointF(0, m_drawingAreaHeight));
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawBottomCuttingLine(QPainter *painter) const
{
QPen penTileInfos = PenTileInfos();
penTileInfos.setStyle(Qt::DotLine);
painter->setPen(penTileInfos);
painter->drawLine(QPointF(0, m_drawingAreaHeight - tileStripeWidth),
QPointF(m_drawingAreaWidth, m_drawingAreaHeight - tileStripeWidth));
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawRightCuttingLine(QPainter *painter) const
{
QPen penTileInfos = PenTileInfos();
penTileInfos.setStyle(Qt::DotLine);
painter->setPen(penTileInfos);
painter->drawLine(QPointF(m_drawingAreaWidth - tileStripeWidth, 0),
QPointF(m_drawingAreaWidth - tileStripeWidth, m_drawingAreaHeight));
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawSolidTopLine(QPainter *painter, int col, int nbCol) const
{
QPen penTileInfos = PenTileInfos();
penTileInfos.setStyle(Qt::SolidLine);
painter->setPen(penTileInfos);
if(col < nbCol - 1)
{
painter->drawLine(QPointF(), QPointF(m_drawingAreaWidth, 0));
}
else
{
painter->drawLine(QPointF(), QPointF(m_drawingAreaWidth - tileStripeWidth, 0));
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawSolidLeftLine(QPainter *painter, int row, int nbRow) const
{
QPen penTileInfos = PenTileInfos();
penTileInfos.setStyle(Qt::SolidLine);
painter->setPen(penTileInfos);
if(row < nbRow - 1)
{
painter->drawLine(QPointF(), QPointF(0, m_drawingAreaHeight));
}
else
{
painter->drawLine(QPointF(), QPointF(0, m_drawingAreaHeight - tileStripeWidth));
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawSolidBottomLine(QPainter *painter, int col, int nbCol) const
{
QPen penTileInfos = PenTileInfos();
penTileInfos.setStyle(Qt::SolidLine);
painter->setPen(penTileInfos);
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));;
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawSolidRightLine(QPainter *painter, int row, int nbRow) const
{
QPen penTileInfos = PenTileInfos();
penTileInfos.setStyle(Qt::SolidLine);
painter->setPen(penTileInfos);
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));
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawTextInformation(QPainter *painter, int row, int col, int nbRow, int nbCol,
const QString &sheetName) const
{
QTextDocument td;
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);
const QString tileColorStr = QStringLiteral("%1,%2,%3")
.arg(tileColor->red()).arg(tileColor->green()).arg(tileColor->blue());
td.setHtml(QString("<table width='100%' style='color:rgb(%1);'>"
"<tr>"
"<td align='center'>%2</td>"
"</tr>"
"</table>")
.arg(tileColorStr, grid));
painter->setPen(PenTileInfos());
painter->save();
painter->translate(QPointF(UnitConvertor(1, Unit::Cm, Unit::Px), m_drawingAreaHeight - tileStripeWidth/1.3));
td.drawContents(painter);
painter->restore();
// paint the page information
const QString page = tr("Page %1 of %2").arg(row * nbCol + col + 1).arg(nbCol * nbRow);
td.setPageSize(QSizeF(m_drawingAreaHeight - UnitConvertor(2, Unit::Cm, Unit::Px), m_drawingAreaWidth));
QFontMetrics metrix = QFontMetrics(td.defaultFont());
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
int maxWidth = metrix.horizontalAdvance(QString().fill('z', 50));
#else
int maxWidth = metrix.width(QString().fill('z', 50));
#endif
QString clippedSheetName = metrix.elidedText(sheetName, Qt::ElideMiddle, maxWidth);
td.setHtml(QStringLiteral("<table width='100%' style='color:rgb(%1);'>"
"<tr>"
"<td align='center'>%2 - %3</td>"
"</tr>"
"</table>").arg(tileColorStr, page, clippedSheetName));
painter->save();
painter->rotate(-90);
painter->translate(QPointF(-(m_drawingAreaHeight) + UnitConvertor(1, Unit::Cm, Unit::Px),
m_drawingAreaWidth - tileStripeWidth));
td.drawContents(painter);
painter->restore();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::PaintWatermarkText(QPainter *painter, const QRectF &img, const VWatermarkData &watermarkData, void VPTileFactory::PaintWatermarkText(QPainter *painter, const QRectF &img, const VWatermarkData &watermarkData,
@ -568,7 +680,7 @@ void VPTileFactory::PaintWatermarkImage(QPainter *painter, const QRectF &img, co
auto BrokenImage = [img, watermarkData, watermarkPath, opacity]() auto BrokenImage = [img, watermarkData, watermarkPath, opacity]()
{ {
QPixmap watermark; QPixmap watermark;
QString imagePath = QString("puzzle=path%1+opacity%2_broken") QString imagePath = QStringLiteral("puzzle=path%1+opacity%2_broken")
.arg(AbsoluteMPath(watermarkPath, watermarkData.path), QString::number(opacity)); .arg(AbsoluteMPath(watermarkPath, watermarkData.path), QString::number(opacity));
if (not QPixmapCache::find(imagePath, &watermark)) if (not QPixmapCache::find(imagePath, &watermark))
@ -644,7 +756,8 @@ void VPTileFactory::PaintWatermarkImage(QPainter *painter, const QRectF &img, co
} }
QPixmap watermark; QPixmap watermark;
if (f.suffix() == "png" || f.suffix() == "jpg" || f.suffix() == "jpeg" || f.suffix() == "bmp") if (f.suffix() == QLatin1String("png") || f.suffix() == QLatin1String("jpg") ||
f.suffix() == QLatin1String("jpeg") || f.suffix() == QLatin1String("bmp"))
{ {
QString error; QString error;
watermark = WatermarkImageFromCache(watermarkData, watermarkPath, xScale, yScale, error); watermark = WatermarkImageFromCache(watermarkData, watermarkPath, xScale, yScale, error);

View File

@ -35,18 +35,22 @@
#include "layout/vplayout.h" #include "layout/vplayout.h"
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
#include "../vmisc/defglobal.h"
#endif // QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
class QGraphicsScene; class QGraphicsScene;
class VCommonSettings; class VCommonSettings;
class QPainter; class QPainter;
class VPTileFactory : QObject class VPTileFactory : QObject
{ {
Q_OBJECT Q_OBJECT // NOLINT
public: public:
VPTileFactory(const VPLayoutPtr &layout, VCommonSettings *commonSettings); VPTileFactory(const VPLayoutPtr &layout, VCommonSettings *commonSettings, QObject *parent = nullptr);
virtual ~VPTileFactory() = default; ~VPTileFactory() override = default;
/** /**
* @brief drawTile draws the tile of given coordinate (row, col) from the * @brief drawTile draws the tile of given coordinate (row, col) from the
@ -99,7 +103,7 @@ public:
const QString &watermarkPath, qreal xScale = 1.0, qreal yScale = 1.0); const QString &watermarkPath, qreal xScale = 1.0, qreal yScale = 1.0);
private: private:
Q_DISABLE_COPY(VPTileFactory) Q_DISABLE_COPY_MOVE(VPTileFactory) // NOLINT
VPLayoutWeakPtr m_layout; VPLayoutWeakPtr m_layout;
VCommonSettings *m_commonSettings{nullptr}; VCommonSettings *m_commonSettings{nullptr};
@ -116,8 +120,32 @@ private:
VWatermarkData m_watermarkData{}; VWatermarkData m_watermarkData{};
void DrawRuler(QPainter *painter); void DrawRuler(QPainter *painter) const;
void DrawWatermark(QPainter *painter); void DrawWatermark(QPainter *painter) const;
auto PenTileInfos() const -> QPen;
void DrawTilePageContent(QPainter *painter, const VPSheetPtr &sheet, int row, int col, QPrinter *printer) const;
void DrawTopTriangle(QPainter *painter) const;
void DrawLeftTriangle(QPainter *painter) const;
void DrawBottomTriangle(QPainter *painter) const;
void DrawRightTriangle(QPainter *painter) const;
void DrawTopLineScissors(QPainter *painter) const;
void DrawLeftLineScissors(QPainter *painter) const;
void DrawTopCuttingLine(QPainter *painter) const;
void DrawLeftCuttingLine(QPainter *painter) const;
void DrawBottomCuttingLine(QPainter *painter) const;
void DrawRightCuttingLine(QPainter *painter) const;
void DrawSolidTopLine(QPainter *painter, int col, int nbCol) const;
void DrawSolidLeftLine(QPainter *painter, int row, int nbRow) const;
void DrawSolidBottomLine(QPainter *painter, int col, int nbCol) const;
void DrawSolidRightLine(QPainter *painter, int row, int nbRow) const;
void DrawTextInformation(QPainter *painter, int row, int col, int nbRow, int nbCol, const QString &sheetName) const;
}; };
#endif // VPTILEFACTORY_H #endif // VPTILEFACTORY_H