valentina/src/app/puzzle/scene/vpgraphicstilegrid.cpp

131 lines
4.9 KiB
C++
Raw Normal View History

#include "vpgraphicstilegrid.h"
2021-08-09 14:09:10 +02:00
#include "../vptilefactory.h"
#include "../layout/vplayout.h"
2021-09-07 19:26:35 +02:00
#include "../layout/vpsheet.h"
2021-09-11 18:39:38 +02:00
#include <QFileInfo>
#include <QImageReader>
#include <QPixmapCache>
#include <QSvgRenderer>
2021-09-06 14:31:19 +02:00
namespace
{
constexpr qreal penWidth = 1;
2021-09-11 18:39:38 +02:00
} // namespace
2021-09-06 14:31:19 +02:00
//---------------------------------------------------------------------------------------------------------------------
2021-09-06 14:31:19 +02:00
VPGraphicsTileGrid::VPGraphicsTileGrid(const VPLayoutPtr &layout, const QUuid &sheetUuid, QGraphicsItem *parent):
QGraphicsItem(parent),
2021-09-06 14:31:19 +02:00
m_layout(layout),
m_sheetUuid(sheetUuid)
{
}
//---------------------------------------------------------------------------------------------------------------------
2021-08-25 15:58:50 +02:00
auto VPGraphicsTileGrid::boundingRect() const -> QRectF
{
2021-08-18 19:33:47 +02:00
VPLayoutPtr layout = m_layout.toStrongRef();
if(not layout.isNull() && layout->LayoutSettings().GetShowTiles())
{
2021-09-06 14:31:19 +02:00
VPSheetPtr sheet = layout->GetSheet(m_sheetUuid);
2021-09-07 19:26:35 +02:00
QMarginsF sheetMargins;
if (not sheet.isNull() && not sheet->IgnoreMargins())
{
sheetMargins = sheet->GetSheetMargins();
}
2021-09-06 15:56:56 +02:00
qreal xScale = layout->LayoutSettings().HorizontalScale();
qreal yScale = layout->LayoutSettings().VerticalScale();
2021-09-07 19:26:35 +02:00
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));
2021-09-06 14:31:19 +02:00
constexpr qreal halfPenWidth = penWidth/2.;
return rect.adjusted(-halfPenWidth, -halfPenWidth, halfPenWidth, halfPenWidth);
}
2021-07-29 16:11:18 +02:00
return {};
}
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsTileGrid::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget);
Q_UNUSED(option);
2021-08-18 19:33:47 +02:00
VPLayoutPtr layout = m_layout.toStrongRef();
if(not layout.isNull() && layout->LayoutSettings().GetShowTiles())
{
2021-09-06 14:31:19 +02:00
VPSheetPtr sheet = layout->GetSheet(m_sheetUuid);
2021-09-07 19:26:35 +02:00
QMarginsF sheetMargins;
if (not sheet.isNull() && not sheet->IgnoreMargins())
{
sheetMargins = sheet->GetSheetMargins();
}
2021-09-06 14:31:19 +02:00
QPen pen(QColor(255,0,0,127), penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
pen.setCosmetic(true);
pen.setStyle(Qt::DashLine);
QBrush noBrush(Qt::NoBrush);
painter->setPen(pen);
painter->setBrush(noBrush);
2021-09-06 15:56:56 +02:00
qreal xScale = layout->LayoutSettings().HorizontalScale();
qreal yScale = layout->LayoutSettings().VerticalScale();
2021-09-07 19:26:35 +02:00
const qreal width = (layout->TileFactory()->DrawingAreaWidth() - VPTileFactory::tileStripeWidth) / xScale;
const qreal height = (layout->TileFactory()->DrawingAreaHeight() - VPTileFactory::tileStripeWidth) / yScale;
const int nbCol = layout->TileFactory()->ColNb(sheet);
const int nbRow = layout->TileFactory()->RowNb(sheet);
2021-09-06 15:56:56 +02:00
2021-09-11 18:39:38 +02:00
VWatermarkData watermarkData = layout->TileFactory()->WatermarkData();
2021-09-07 19:26:35 +02:00
for(int j=0;j<=nbRow;++j)
{
2021-09-07 19:26:35 +02:00
// horizontal lines
painter->drawLine(QPointF(sheetMargins.left(), sheetMargins.top()+j*height),
QPointF(sheetMargins.left()+nbCol*width, sheetMargins.top()+j*height));
2021-09-11 18:39:38 +02:00
for(int i=0;i<=nbCol;++i)
{
// vertical lines
painter->drawLine(QPointF(sheetMargins.left()+i*width, sheetMargins.top()),
QPointF(sheetMargins.left()+i*width, sheetMargins.top() + nbRow*height));
if (j < nbRow && i < nbCol)
{
QRectF img(sheetMargins.left()+i*width, sheetMargins.top()+j*height,
width, height);
if (not layout->LayoutSettings().WatermarkPath().isEmpty() &&
layout->LayoutSettings().GetShowWatermark())
{
if (watermarkData.opacity > 0)
{
if (watermarkData.showImage && not watermarkData.path.isEmpty())
{
VPTileFactory::PaintWatermarkImage(painter, img, watermarkData,
layout->LayoutSettings().WatermarkPath());
}
if (watermarkData.showText && not watermarkData.text.isEmpty())
{
VPTileFactory::PaintWatermarkText(painter, img, watermarkData);
}
}
}
}
}
}
}
}