2020-11-19 14:33:27 +01:00
|
|
|
#include "vpgraphicstilegrid.h"
|
|
|
|
|
2021-08-09 14:09:10 +02:00
|
|
|
#include "../vptilefactory.h"
|
|
|
|
#include "../layout/vplayout.h"
|
2020-11-19 14:33:27 +01:00
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
constexpr qreal penWidth = 1;
|
|
|
|
}
|
|
|
|
|
2020-11-19 14:33:27 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-06 14:31:19 +02:00
|
|
|
VPGraphicsTileGrid::VPGraphicsTileGrid(const VPLayoutPtr &layout, const QUuid &sheetUuid, QGraphicsItem *parent):
|
2020-11-19 14:33:27 +01:00
|
|
|
QGraphicsItem(parent),
|
2021-09-06 14:31:19 +02:00
|
|
|
m_layout(layout),
|
|
|
|
m_sheetUuid(sheetUuid)
|
2020-11-19 14:33:27 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-25 15:58:50 +02:00
|
|
|
auto VPGraphicsTileGrid::boundingRect() const -> QRectF
|
2020-11-19 14:33:27 +01:00
|
|
|
{
|
2021-08-18 19:33:47 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if(not layout.isNull() && layout->LayoutSettings().GetShowTiles())
|
2020-11-19 14:33:27 +01:00
|
|
|
{
|
2021-09-06 14:31:19 +02:00
|
|
|
VPSheetPtr sheet = layout->GetSheet(m_sheetUuid);
|
|
|
|
|
2021-09-06 15:56:56 +02:00
|
|
|
qreal xScale = layout->LayoutSettings().HorizontalScale();
|
|
|
|
qreal yScale = layout->LayoutSettings().VerticalScale();
|
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
QRectF rect(0, 0,
|
2021-09-06 15:56:56 +02:00
|
|
|
layout->TileFactory()->ColNb(sheet) * (layout->TileFactory()->DrawingAreaWidth() / xScale),
|
|
|
|
layout->TileFactory()->RowNb(sheet) * (layout->TileFactory()->DrawingAreaHeight() / yScale));
|
2021-09-06 14:31:19 +02:00
|
|
|
|
|
|
|
constexpr qreal halfPenWidth = penWidth/2.;
|
|
|
|
|
|
|
|
return rect.adjusted(-halfPenWidth, -halfPenWidth, halfPenWidth, halfPenWidth);
|
2020-11-19 14:33:27 +01:00
|
|
|
}
|
2021-07-29 16:11:18 +02:00
|
|
|
|
|
|
|
return {};
|
2020-11-19 14:33:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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())
|
2020-11-19 14:33:27 +01:00
|
|
|
{
|
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);
|
2020-11-19 14:33:27 +01:00
|
|
|
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();
|
|
|
|
|
|
|
|
const qreal drawingAreaWidth = layout->TileFactory()->DrawingAreaWidth() / xScale;
|
|
|
|
const qreal drawingAreaHeight = layout->TileFactory()->DrawingAreaHeight() / yScale;
|
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
for(int i=0;i<=layout->TileFactory()->ColNb(sheet);i++)
|
2020-11-19 14:33:27 +01:00
|
|
|
{
|
2021-09-06 15:56:56 +02:00
|
|
|
painter->drawLine(QPointF(i*drawingAreaWidth, 0),
|
|
|
|
QPointF(i*drawingAreaWidth, layout->TileFactory()->RowNb(sheet)*drawingAreaHeight));
|
2020-11-19 14:33:27 +01:00
|
|
|
}
|
|
|
|
|
2021-09-06 14:31:19 +02:00
|
|
|
for(int j=0;j<=layout->TileFactory()->RowNb(sheet);j++)
|
2020-11-19 14:33:27 +01:00
|
|
|
{
|
2021-09-06 15:56:56 +02:00
|
|
|
painter->drawLine(QPointF(0, j*drawingAreaHeight),
|
|
|
|
QPointF(layout->TileFactory()->ColNb(sheet)*drawingAreaWidth, j*drawingAreaHeight));
|
2020-11-19 14:33:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|