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

73 lines
2.6 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-08-18 19:33:47 +02:00
VPGraphicsTileGrid::VPGraphicsTileGrid(const VPLayoutPtr &layout, VPTileFactory *tileFactory, QGraphicsItem *parent):
QGraphicsItem(parent),
m_tileFactory(tileFactory),
m_layout(layout)
{
}
//---------------------------------------------------------------------------------------------------------------------
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())
{
return QRectF(0,
0,
m_tileFactory->getColNb()* m_tileFactory->getDrawingAreaWidth(),
m_tileFactory->getRowNb()* m_tileFactory->getDrawingAreaHeight()
);
}
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())
{
QPen pen(QColor(255,0,0,127), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
pen.setCosmetic(true);
pen.setStyle(Qt::DashLine);
QBrush noBrush(Qt::NoBrush);
painter->setPen(pen);
painter->setBrush(noBrush);
for(int i=0;i<=m_tileFactory->getColNb();i++)
{
painter->drawLine(QPointF(
i*m_tileFactory->getDrawingAreaWidth(),
0),
QPointF(
i*m_tileFactory->getDrawingAreaWidth(),
m_tileFactory->getRowNb()*m_tileFactory->getDrawingAreaHeight()
)
);
}
for(int j=0;j<=m_tileFactory->getRowNb();j++)
{
painter->drawLine(QPointF(
0,
j*m_tileFactory->getDrawingAreaHeight()
),
QPointF(
m_tileFactory->getColNb()*m_tileFactory->getDrawingAreaWidth(),
j*m_tileFactory->getDrawingAreaHeight()
)
);
}
}
}