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

83 lines
3.0 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-06 14:31:19 +02:00
namespace
{
constexpr qreal penWidth = 1;
}
//---------------------------------------------------------------------------------------------------------------------
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);
QRectF rect(0, 0,
layout->TileFactory()->ColNb(sheet) * layout->TileFactory()->DrawingAreaWidth(),
layout->TileFactory()->RowNb(sheet) * layout->TileFactory()->DrawingAreaHeight() );
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);
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 14:31:19 +02:00
for(int i=0;i<=layout->TileFactory()->ColNb(sheet);i++)
{
painter->drawLine(QPointF(
2021-09-06 14:31:19 +02:00
i*layout->TileFactory()->DrawingAreaWidth(),
0),
QPointF(
2021-09-06 14:31:19 +02:00
i*layout->TileFactory()->DrawingAreaWidth(),
layout->TileFactory()->RowNb(sheet)*layout->TileFactory()->DrawingAreaHeight()
)
);
}
2021-09-06 14:31:19 +02:00
for(int j=0;j<=layout->TileFactory()->RowNb(sheet);j++)
{
painter->drawLine(QPointF(
0,
2021-09-06 14:31:19 +02:00
j*layout->TileFactory()->DrawingAreaHeight()
),
QPointF(
2021-09-06 14:31:19 +02:00
layout->TileFactory()->ColNb(sheet)*layout->TileFactory()->DrawingAreaWidth(),
j*layout->TileFactory()->DrawingAreaHeight()
)
);
}
}
}