2021-08-18 19:33:47 +02:00
|
|
|
/*******************************************************************
|
2020-05-05 07:44:20 +02:00
|
|
|
**
|
2020-05-23 14:48:31 +02:00
|
|
|
** @file vpgraphicssheet.cpp
|
2020-05-05 07:44:20 +02:00
|
|
|
** @author Ronan Le Tiec
|
|
|
|
** @date 3 5, 2020
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentina project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2020 Valentina project
|
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
2020-05-23 14:48:31 +02:00
|
|
|
#include "vpgraphicssheet.h"
|
2021-08-09 14:09:10 +02:00
|
|
|
#include "../layout/vplayout.h"
|
|
|
|
#include "../layout/vpsheet.h"
|
|
|
|
|
2020-11-14 17:31:34 +01:00
|
|
|
#include <QtMath>
|
2020-05-05 07:44:20 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-18 19:33:47 +02:00
|
|
|
VPGraphicsSheet::VPGraphicsSheet(const VPLayoutPtr &layout, QGraphicsItem *parent):
|
2020-05-05 07:44:20 +02:00
|
|
|
QGraphicsItem(parent),
|
2021-08-14 14:19:28 +02:00
|
|
|
m_layout(layout),
|
2020-05-23 17:47:04 +02:00
|
|
|
m_boundingRect(GetSheetRect())
|
2021-08-14 14:19:28 +02:00
|
|
|
{}
|
2020-05-05 07:44:20 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:48:31 +02:00
|
|
|
void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(widget);
|
|
|
|
Q_UNUSED(option);
|
|
|
|
|
|
|
|
QPen pen(QColor(0,179,255), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
|
|
|
|
pen.setCosmetic(true);
|
|
|
|
QBrush noBrush(Qt::NoBrush);
|
|
|
|
painter->setPen(pen);
|
|
|
|
painter->setBrush(noBrush);
|
|
|
|
|
2021-03-14 14:27:45 +01:00
|
|
|
QRectF sheetRect = GetSheetRect();
|
|
|
|
|
2020-11-14 12:37:43 +01:00
|
|
|
if(m_showMargin)
|
|
|
|
{
|
|
|
|
painter->drawRect(GetMarginsRect());
|
|
|
|
}
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2020-11-14 12:37:43 +01:00
|
|
|
if(m_showBorder)
|
|
|
|
{
|
|
|
|
pen.setColor(Qt::black);
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2020-11-14 12:37:43 +01:00
|
|
|
painter->setPen(pen);
|
2021-03-14 14:27:45 +01:00
|
|
|
painter->drawRect(sheetRect);
|
2020-11-14 12:37:43 +01:00
|
|
|
}
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2021-08-18 19:33:47 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
|
|
|
|
if(not layout.isNull() && layout->LayoutSettings().GetShowGrid())
|
2021-03-14 14:27:45 +01:00
|
|
|
{
|
|
|
|
pen.setColor(QColor(204,204,204));
|
|
|
|
painter->setPen(pen);
|
|
|
|
|
2021-08-18 19:33:47 +02:00
|
|
|
qreal colWidth = layout->LayoutSettings().GetGridColWidth();
|
2021-03-14 14:27:45 +01:00
|
|
|
if(colWidth > 0)
|
|
|
|
{
|
|
|
|
qreal colX = colWidth;
|
|
|
|
while (colX < sheetRect.right())
|
|
|
|
{
|
|
|
|
QLineF line = QLineF(colX, 0, colX, sheetRect.bottom());
|
|
|
|
painter->drawLine(line);
|
|
|
|
colX += colWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-18 19:33:47 +02:00
|
|
|
qreal rowHeight = layout->LayoutSettings().GetGridRowHeight();
|
2021-03-14 14:27:45 +01:00
|
|
|
if(rowHeight > 0)
|
|
|
|
{
|
|
|
|
qreal rowY = rowHeight;
|
|
|
|
|
|
|
|
while (rowY < sheetRect.bottom())
|
|
|
|
{
|
|
|
|
QLineF line = QLineF(0, rowY, sheetRect.right(), rowY);
|
|
|
|
painter->drawLine(line);
|
|
|
|
rowY += rowHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_boundingRect = sheetRect;
|
2020-05-05 07:44:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-18 19:33:47 +02:00
|
|
|
auto VPGraphicsSheet::GetSheetRect() const -> QRectF
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
2021-08-18 19:33:47 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2020-06-25 16:59:48 +02:00
|
|
|
QPoint topLeft = QPoint(0,0);
|
2021-08-18 19:33:47 +02:00
|
|
|
QSizeF size = layout->LayoutSettings().GetSheetSize();
|
2020-06-25 16:59:48 +02:00
|
|
|
QRectF rect = QRectF(topLeft, size);
|
2020-05-05 07:44:20 +02:00
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-18 19:33:47 +02:00
|
|
|
auto VPGraphicsSheet::GetMarginsRect() const -> QRectF
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
2021-08-18 19:33:47 +02:00
|
|
|
VPLayoutPtr layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF size = layout->LayoutSettings().GetSheetSize();
|
2020-06-25 16:59:48 +02:00
|
|
|
|
2021-08-25 15:58:50 +02:00
|
|
|
if (not layout->LayoutSettings().IgnoreMargins())
|
2020-06-25 16:59:48 +02:00
|
|
|
{
|
2021-08-25 15:58:50 +02:00
|
|
|
QMarginsF margins = layout->LayoutSettings().GetSheetMargins();
|
|
|
|
QRectF rect = QRectF(QPointF(margins.left(), margins.top()),
|
|
|
|
QPointF(size.width()-margins.right(), size.height()-margins.bottom()));
|
|
|
|
return rect;
|
2020-06-25 16:59:48 +02:00
|
|
|
}
|
|
|
|
|
2021-08-25 15:58:50 +02:00
|
|
|
return QRectF(0, 0, size.width(), size.height());
|
2020-05-05 07:44:20 +02:00
|
|
|
}
|
|
|
|
|
2020-11-14 12:37:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPGraphicsSheet::SetShowMargin(bool value)
|
|
|
|
{
|
|
|
|
m_showMargin = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPGraphicsSheet::SetShowBorder(bool value)
|
|
|
|
{
|
2021-08-18 19:33:47 +02:00
|
|
|
m_showBorder = value;
|
2020-11-14 12:37:43 +01:00
|
|
|
}
|
|
|
|
|
2020-05-05 07:44:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-18 19:33:47 +02:00
|
|
|
auto VPGraphicsSheet::boundingRect() const -> QRectF
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
|
|
|
return m_boundingRect;
|
|
|
|
}
|