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"
|
2024-01-06 13:20:56 +01:00
|
|
|
#include "../vlayout/vlayoutpiece.h"
|
|
|
|
#include "../vmisc/theme/vscenestylesheet.h"
|
|
|
|
#include "../vptilefactory.h"
|
|
|
|
#include "../vwidgets/vpiecegrainline.h"
|
|
|
|
#include "scenedef.h"
|
2021-08-09 14:09:10 +02:00
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QFontMetrics>
|
2020-11-14 17:31:34 +01:00
|
|
|
#include <QtMath>
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
constexpr qreal foldArrowMargin = 20;
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto SwapRect(const QRectF &rect) -> QRectF
|
|
|
|
{
|
|
|
|
return {rect.center().x() - rect.height() / 2.0, rect.center().y() - rect.width() / 2.0, rect.height(),
|
|
|
|
rect.width()};
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void PaintVerticalFoldShadow(QPainter *painter, const QRectF &sheetRect)
|
|
|
|
{
|
|
|
|
QLineF shadowLine(sheetRect.topLeft(), sheetRect.bottomLeft());
|
|
|
|
shadowLine.setLength(shadowLine.length() * 0.97);
|
|
|
|
shadowLine.setAngle(shadowLine.angle() - 1.5);
|
|
|
|
|
|
|
|
QPointF const shadowP =
|
|
|
|
VGObject::ClosestPoint(QLineF(sheetRect.topLeft(), sheetRect.bottomLeft()), shadowLine.p2());
|
|
|
|
|
|
|
|
painter->drawLine(shadowLine);
|
|
|
|
painter->drawLine(QLineF(shadowLine.p2(), shadowP));
|
|
|
|
|
2024-01-10 10:19:59 +01:00
|
|
|
QPolygonF const shadow({sheetRect.topLeft(), shadowLine.p2(), shadowP, sheetRect.topLeft()});
|
2024-01-06 13:20:56 +01:00
|
|
|
|
|
|
|
painter->setBrush(QBrush(VSceneStylesheet::ManualLayoutStyle().SheetFoldShadowColor()));
|
|
|
|
painter->drawPolygon(shadow);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void PaintHorizontalFoldShadow(QPainter *painter, const QRectF &sheetRect)
|
|
|
|
{
|
|
|
|
QLineF shadowLine(sheetRect.topRight(), sheetRect.topLeft());
|
|
|
|
shadowLine.setLength(shadowLine.length() * 0.97);
|
|
|
|
shadowLine.setAngle(shadowLine.angle() - 1.5);
|
|
|
|
|
|
|
|
QPointF const shadowP = VGObject::ClosestPoint(QLineF(sheetRect.topRight(), sheetRect.topLeft()), shadowLine.p2());
|
|
|
|
|
|
|
|
painter->drawLine(shadowLine);
|
|
|
|
painter->drawLine(QLineF(shadowLine.p2(), shadowP));
|
|
|
|
|
2024-01-10 10:40:46 +01:00
|
|
|
QPolygonF const shadow({sheetRect.topRight(), shadowLine.p2(), shadowP, sheetRect.topRight()});
|
2024-01-06 13:20:56 +01:00
|
|
|
|
|
|
|
painter->setBrush(QBrush(VSceneStylesheet::ManualLayoutStyle().SheetFoldShadowColor()));
|
|
|
|
painter->drawPolygon(shadow);
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2020-05-05 07:44:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-08-05 16:51:23 +02:00
|
|
|
VPGraphicsSheet::VPGraphicsSheet(const VPLayoutPtr &layout, QGraphicsItem *parent)
|
|
|
|
: QGraphicsItem(parent),
|
2021-09-11 13:01:29 +02:00
|
|
|
m_layout(layout)
|
2023-08-05 16:51:23 +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);
|
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
PaintMargins(painter);
|
|
|
|
PaintBorder(painter);
|
|
|
|
PaintFold(painter);
|
|
|
|
PaintGrid(painter);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPGraphicsSheet::GetSheetRect() const -> QRectF
|
|
|
|
{
|
|
|
|
VPLayoutPtr const layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
VPSheetPtr const sheet = layout->GetFocusedSheet();
|
|
|
|
if (sheet.isNull())
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
return sheet->GetSheetRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VPGraphicsSheet::GetMarginsRect() const -> QRectF
|
|
|
|
{
|
|
|
|
VPLayoutPtr const layout = m_layout.toStrongRef();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
VPSheetPtr const sheet = layout->GetFocusedSheet();
|
|
|
|
if (sheet.isNull())
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
return sheet->GetMarginsRect();
|
|
|
|
}
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPGraphicsSheet::SetShowMargin(bool value)
|
|
|
|
{
|
|
|
|
m_showMargin = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPGraphicsSheet::SetShowBorder(bool value)
|
|
|
|
{
|
|
|
|
m_showBorder = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPGraphicsSheet::RefreshBoundingRect()
|
|
|
|
{
|
|
|
|
prepareGeometryChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPGraphicsSheet::PaintVerticalFold(QPainter *painter, const QRectF &sheetRect) const
|
|
|
|
{
|
2024-03-30 17:02:45 +01:00
|
|
|
if (VPLayoutPtr const layout = m_layout.toStrongRef();
|
|
|
|
not layout.isNull() && layout->LayoutSettings().IsCutOnFold())
|
2024-01-06 13:20:56 +01:00
|
|
|
{
|
|
|
|
QString const foldText = FoldText();
|
|
|
|
painter->save();
|
|
|
|
QFont font = QApplication::font();
|
|
|
|
font.setPointSize(foldFontSize);
|
|
|
|
painter->setFont(font);
|
|
|
|
QRectF textRect = painter->fontMetrics().boundingRect(foldText);
|
|
|
|
int const textDescent = painter->fontMetrics().descent();
|
|
|
|
QPointF const textPosition(sheetRect.center().x() - textRect.width() / 2.,
|
|
|
|
sheetRect.topLeft().y() - foldTextMargin - textDescent);
|
|
|
|
painter->drawText(textPosition, foldText);
|
|
|
|
textRect.translate(sheetRect.center() - textRect.center());
|
|
|
|
textRect.translate(0, -(sheetRect.center().y() - sheetRect.topLeft().y()) - foldTextMargin -
|
|
|
|
textRect.height() / 2.);
|
|
|
|
// painter->drawRect(textRect); // uncomment for debug
|
|
|
|
painter->restore();
|
|
|
|
|
|
|
|
if (sheetRect.width() >= textRect.width() * 2)
|
|
|
|
{
|
|
|
|
qreal const baseY = textRect.center().y();
|
|
|
|
qreal const arrowMargin = foldArrowMargin + textRect.width() / 2.;
|
|
|
|
|
|
|
|
QLineF const leftLine(QPointF(sheetRect.topLeft().x(), baseY),
|
|
|
|
QPointF(sheetRect.center().x() - arrowMargin, baseY));
|
|
|
|
VPieceGrainline const leftArrow(leftLine, GrainlineArrowDirection::oneWayDown);
|
|
|
|
QPainterPath leftArrowPath = VLayoutPiece::GrainlinePath(leftArrow.Shape());
|
|
|
|
leftArrowPath.setFillRule(Qt::WindingFill);
|
|
|
|
|
|
|
|
painter->save();
|
|
|
|
QPen pen = painter->pen();
|
|
|
|
pen.setCapStyle(Qt::RoundCap);
|
|
|
|
pen.setJoinStyle(Qt::RoundJoin);
|
|
|
|
painter->setPen(pen);
|
|
|
|
painter->setBrush(QBrush(pen.color(), Qt::SolidPattern));
|
|
|
|
painter->drawPath(leftArrowPath);
|
|
|
|
painter->restore();
|
|
|
|
|
|
|
|
QLineF const rightLine(QPointF(sheetRect.center().x() + arrowMargin, baseY),
|
|
|
|
QPointF(sheetRect.topRight().x(), baseY));
|
|
|
|
VPieceGrainline const rightArrow(rightLine, GrainlineArrowDirection::oneWayUp);
|
|
|
|
QPainterPath rightArrowPath = VLayoutPiece::GrainlinePath(rightArrow.Shape());
|
|
|
|
rightArrowPath.setFillRule(Qt::WindingFill);
|
|
|
|
|
|
|
|
painter->save();
|
|
|
|
pen = painter->pen();
|
|
|
|
pen.setCapStyle(Qt::RoundCap);
|
|
|
|
pen.setJoinStyle(Qt::RoundJoin);
|
|
|
|
painter->setPen(pen);
|
|
|
|
painter->setBrush(QBrush(pen.color(), Qt::SolidPattern));
|
|
|
|
painter->drawPath(rightArrowPath);
|
|
|
|
painter->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPGraphicsSheet::PaintHorizontalFold(QPainter *painter, const QRectF &sheetRect) const
|
|
|
|
{
|
2024-03-30 17:02:45 +01:00
|
|
|
if (VPLayoutPtr const layout = m_layout.toStrongRef();
|
|
|
|
not layout.isNull() && layout->LayoutSettings().IsCutOnFold())
|
2023-08-05 16:51:23 +02:00
|
|
|
{
|
2024-01-06 13:20:56 +01:00
|
|
|
QString const foldText = FoldText();
|
|
|
|
painter->save();
|
|
|
|
QFont font = QApplication::font();
|
|
|
|
font.setPointSize(foldFontSize);
|
|
|
|
painter->setFont(font);
|
|
|
|
QRectF const textRect = painter->fontMetrics().boundingRect(foldText);
|
|
|
|
// int const textAscent = painter->fontMetrics().ascent();
|
|
|
|
int const textDescent = painter->fontMetrics().descent();
|
|
|
|
QPointF const textPosition(sheetRect.center().x() - textRect.width() / 2.,
|
|
|
|
sheetRect.center().y() - sheetRect.width() / 2. - foldTextMargin - textDescent);
|
|
|
|
painter->translate(sheetRect.center());
|
|
|
|
painter->rotate(90);
|
|
|
|
painter->translate(-sheetRect.center());
|
|
|
|
painter->drawText(textPosition, foldText);
|
|
|
|
painter->restore();
|
|
|
|
|
|
|
|
QRectF swappedRect = SwapRect(textRect);
|
|
|
|
swappedRect.translate(sheetRect.center() - swappedRect.center());
|
|
|
|
swappedRect.translate(
|
|
|
|
(sheetRect.topRight().x() - sheetRect.center().x()) + foldTextMargin + textRect.height() / 2., 0);
|
|
|
|
// painter->drawRect(swappedRect); // uncomment for debug
|
|
|
|
|
|
|
|
if (sheetRect.height() >= textRect.width() * 2)
|
2023-08-05 16:51:23 +02:00
|
|
|
{
|
2024-01-06 13:20:56 +01:00
|
|
|
// qreal const baseX = sheetRect.topRight().x() + foldTextMargin + textDescent + textAscent / 2.;
|
|
|
|
qreal const baseX = swappedRect.center().x();
|
|
|
|
qreal const arrowMargin = foldArrowMargin + textRect.width() / 2.;
|
|
|
|
QLineF const leftLine(QPointF(baseX, sheetRect.topRight().y()),
|
|
|
|
QPointF(baseX, sheetRect.center().y() - arrowMargin));
|
|
|
|
|
|
|
|
VPieceGrainline const leftArrow(leftLine, GrainlineArrowDirection::oneWayDown);
|
|
|
|
QPainterPath leftArrowPath = VLayoutPiece::GrainlinePath(leftArrow.Shape());
|
|
|
|
leftArrowPath.setFillRule(Qt::WindingFill);
|
|
|
|
|
|
|
|
painter->save();
|
|
|
|
QPen pen = painter->pen();
|
|
|
|
pen.setCapStyle(Qt::RoundCap);
|
|
|
|
pen.setJoinStyle(Qt::RoundJoin);
|
|
|
|
painter->setPen(pen);
|
|
|
|
painter->setBrush(QBrush(pen.color(), Qt::SolidPattern));
|
|
|
|
painter->drawPath(leftArrowPath);
|
|
|
|
painter->restore();
|
|
|
|
|
|
|
|
QLineF const rightLine(QPointF(baseX, sheetRect.center().y() + arrowMargin),
|
|
|
|
QPointF(baseX, sheetRect.bottomRight().y()));
|
|
|
|
VPieceGrainline const rightArrow(rightLine, GrainlineArrowDirection::oneWayUp);
|
|
|
|
QPainterPath rightArrowPath = VLayoutPiece::GrainlinePath(rightArrow.Shape());
|
|
|
|
rightArrowPath.setFillRule(Qt::WindingFill);
|
|
|
|
|
|
|
|
painter->save();
|
|
|
|
pen = painter->pen();
|
|
|
|
pen.setCapStyle(Qt::RoundCap);
|
|
|
|
pen.setJoinStyle(Qt::RoundJoin);
|
|
|
|
painter->setPen(pen);
|
|
|
|
painter->setBrush(QBrush(pen.color(), Qt::SolidPattern));
|
|
|
|
painter->drawPath(rightArrowPath);
|
|
|
|
painter->restore();
|
2023-08-05 16:51:23 +02:00
|
|
|
}
|
|
|
|
}
|
2024-01-06 13:20:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPGraphicsSheet::PaintMargins(QPainter *painter) const
|
|
|
|
{
|
|
|
|
VPLayoutPtr const layout = m_layout.toStrongRef();
|
|
|
|
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ignoreMargins = true;
|
2024-03-30 17:02:45 +01:00
|
|
|
if (VPSheetPtr const sheet = layout->GetFocusedSheet(); !sheet.isNull())
|
2024-01-06 13:20:56 +01:00
|
|
|
{
|
|
|
|
ignoreMargins = sheet->IgnoreMargins();
|
|
|
|
}
|
2021-03-14 14:27:45 +01:00
|
|
|
|
2023-08-05 16:51:23 +02:00
|
|
|
if (m_showMargin && !ignoreMargins)
|
2020-11-14 12:37:43 +01:00
|
|
|
{
|
2023-08-05 16:51:23 +02:00
|
|
|
QPen pen(VSceneStylesheet::ManualLayoutStyle().SheetMarginColor(), 1.5, Qt::SolidLine, Qt::RoundCap,
|
|
|
|
Qt::RoundJoin);
|
|
|
|
pen.setCosmetic(true);
|
|
|
|
|
|
|
|
painter->save();
|
|
|
|
painter->setPen(pen);
|
2020-11-14 12:37:43 +01:00
|
|
|
painter->drawRect(GetMarginsRect());
|
2023-08-05 16:51:23 +02:00
|
|
|
painter->restore();
|
2020-11-14 12:37:43 +01:00
|
|
|
}
|
2024-01-06 13:20:56 +01:00
|
|
|
}
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPGraphicsSheet::PaintBorder(QPainter *painter) const
|
|
|
|
{
|
|
|
|
QRectF const sheetRect = GetSheetRect();
|
2023-08-05 16:51:23 +02:00
|
|
|
|
|
|
|
if (m_showBorder)
|
2020-11-14 12:37:43 +01:00
|
|
|
{
|
2023-08-05 16:51:23 +02:00
|
|
|
QPen pen(VSceneStylesheet::ManualLayoutStyle().SheetBorderColor(), 1.5, Qt::SolidLine, Qt::RoundCap,
|
|
|
|
Qt::RoundJoin);
|
|
|
|
pen.setCosmetic(true);
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2023-08-05 16:51:23 +02:00
|
|
|
painter->save();
|
2020-11-14 12:37:43 +01:00
|
|
|
painter->setPen(pen);
|
2021-03-14 14:27:45 +01:00
|
|
|
painter->drawRect(sheetRect);
|
2024-01-06 13:20:56 +01:00
|
|
|
|
2024-03-30 17:02:45 +01:00
|
|
|
if (VPLayoutPtr const layout = m_layout.toStrongRef();
|
|
|
|
!layout.isNull() && layout->LayoutSettings().IsCutOnFold())
|
2024-01-06 13:20:56 +01:00
|
|
|
{
|
|
|
|
if (sheetRect.width() >= sheetRect.height())
|
|
|
|
{
|
|
|
|
PaintVerticalFoldShadow(painter, sheetRect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PaintHorizontalFoldShadow(painter, sheetRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-05 16:51:23 +02:00
|
|
|
painter->restore();
|
2020-11-14 12:37:43 +01:00
|
|
|
}
|
2024-01-06 13:20:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPGraphicsSheet::PaintFold(QPainter *painter) const
|
|
|
|
{
|
2024-03-30 17:02:45 +01:00
|
|
|
if (VPLayoutPtr const layout = m_layout.toStrongRef(); !layout.isNull() && layout->LayoutSettings().IsCutOnFold())
|
2024-01-06 13:20:56 +01:00
|
|
|
{
|
|
|
|
QRectF const sheetRect = GetSheetRect();
|
|
|
|
QRectF const foldField = m_showBorder ? sheetRect : FoldField(GetMarginsRect());
|
|
|
|
|
|
|
|
if (sheetRect.width() >= sheetRect.height())
|
|
|
|
{
|
|
|
|
PaintVerticalFold(painter, foldField);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PaintHorizontalFold(painter, foldField);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VPGraphicsSheet::PaintGrid(QPainter *painter) const
|
|
|
|
{
|
|
|
|
VPLayoutPtr const layout = m_layout.toStrongRef();
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2023-08-05 16:51:23 +02:00
|
|
|
if (not layout.isNull() && layout->LayoutSettings().GetShowGrid())
|
2021-03-14 14:27:45 +01:00
|
|
|
{
|
2023-08-05 16:51:23 +02:00
|
|
|
QPen pen(VSceneStylesheet::ManualLayoutStyle().SheetGridColor(), 1.5, Qt::SolidLine, Qt::RoundCap,
|
|
|
|
Qt::RoundJoin);
|
|
|
|
pen.setCosmetic(true);
|
|
|
|
|
|
|
|
painter->save();
|
2021-03-14 14:27:45 +01:00
|
|
|
painter->setPen(pen);
|
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
QRectF const sheetRect = GetSheetRect();
|
|
|
|
|
2024-03-30 17:02:45 +01:00
|
|
|
if (qreal const colWidth = layout->LayoutSettings().GetGridColWidth(); colWidth > 0)
|
2021-03-14 14:27:45 +01:00
|
|
|
{
|
|
|
|
qreal colX = colWidth;
|
|
|
|
while (colX < sheetRect.right())
|
|
|
|
{
|
2024-04-27 11:54:59 +02:00
|
|
|
auto const line = QLineF(colX, 0, colX, sheetRect.bottom());
|
2021-03-14 14:27:45 +01:00
|
|
|
painter->drawLine(line);
|
|
|
|
colX += colWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-30 17:02:45 +01:00
|
|
|
if (qreal const rowHeight = layout->LayoutSettings().GetGridRowHeight(); rowHeight > 0)
|
2021-03-14 14:27:45 +01:00
|
|
|
{
|
|
|
|
qreal rowY = rowHeight;
|
|
|
|
|
|
|
|
while (rowY < sheetRect.bottom())
|
|
|
|
{
|
2024-04-27 11:54:59 +02:00
|
|
|
auto const line = QLineF(0, rowY, sheetRect.right(), rowY);
|
2021-03-14 14:27:45 +01:00
|
|
|
painter->drawLine(line);
|
|
|
|
rowY += rowHeight;
|
|
|
|
}
|
|
|
|
}
|
2023-08-05 16:51:23 +02:00
|
|
|
painter->restore();
|
2021-03-14 14:27:45 +01:00
|
|
|
}
|
2020-05-05 07:44:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2024-01-06 13:20:56 +01:00
|
|
|
auto VPGraphicsSheet::FoldField(const QRectF &sheetRect) const -> QRectF
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
2024-01-06 13:20:56 +01:00
|
|
|
VPLayoutPtr const layout = m_layout.toStrongRef();
|
2021-09-01 08:20:58 +02:00
|
|
|
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
2024-01-06 13:20:56 +01:00
|
|
|
return sheetRect;
|
2021-09-01 08:20:58 +02:00
|
|
|
}
|
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
VPSheetPtr const sheet = layout->GetFocusedSheet();
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
qreal const xScale = layout->LayoutSettings().HorizontalScale();
|
|
|
|
qreal const yScale = layout->LayoutSettings().VerticalScale();
|
|
|
|
const int nbCol = layout->TileFactory()->ColNb(sheet);
|
|
|
|
const int nbRow = layout->TileFactory()->RowNb(sheet);
|
|
|
|
const qreal tilesWidth = (layout->TileFactory()->DrawingAreaWidth() - VPTileFactory::tileStripeWidth) / xScale;
|
|
|
|
const qreal tilesHeight = (layout->TileFactory()->DrawingAreaHeight() - VPTileFactory::tileStripeWidth) / yScale;
|
2020-11-14 12:37:43 +01:00
|
|
|
|
2024-01-06 13:20:56 +01:00
|
|
|
return {sheetRect.topLeft(), QSizeF(nbCol * tilesWidth, nbRow * tilesHeight)};
|
2020-11-14 12:37:43 +01:00
|
|
|
}
|
|
|
|
|
2021-09-11 13:01:29 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2024-01-06 13:20:56 +01:00
|
|
|
auto VPGraphicsSheet::FoldText() -> QString
|
2021-09-11 13:01:29 +02:00
|
|
|
{
|
2024-01-06 13:20:56 +01:00
|
|
|
return tr("FOLD");
|
2021-09-11 13:01:29 +02: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
|
|
|
{
|
2024-01-06 13:20:56 +01:00
|
|
|
QRectF boundingRect = GetSheetRect();
|
|
|
|
|
2024-03-30 17:02:45 +01:00
|
|
|
if (VPLayoutPtr const layout = m_layout.toStrongRef();
|
|
|
|
not layout.isNull() && layout->LayoutSettings().IsCutOnFold())
|
2024-01-06 13:20:56 +01:00
|
|
|
{
|
|
|
|
QString const foldText = FoldText();
|
|
|
|
QFont font = QApplication::font();
|
|
|
|
font.setPointSize(foldFontSize);
|
|
|
|
QFontMetrics const metric(font);
|
|
|
|
QRectF textRect = metric.boundingRect(foldText);
|
|
|
|
QRectF const foldField = m_showBorder ? boundingRect : FoldField(GetMarginsRect());
|
|
|
|
|
|
|
|
if (boundingRect.width() >= boundingRect.height())
|
|
|
|
{
|
|
|
|
textRect.translate(foldField.center() - textRect.center());
|
|
|
|
textRect.translate(0, -(foldField.center().y() - foldField.topLeft().y()) - foldTextMargin -
|
|
|
|
textRect.height() / 2.);
|
|
|
|
boundingRect = foldField.united(textRect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QRectF swappedRect = SwapRect(textRect);
|
|
|
|
swappedRect.translate(foldField.center() - swappedRect.center());
|
|
|
|
swappedRect.translate(
|
|
|
|
(foldField.topRight().x() - foldField.center().x()) + foldTextMargin + textRect.height() / 2., 0);
|
|
|
|
boundingRect = foldField.united(swappedRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return boundingRect;
|
2020-05-05 07:44:20 +02:00
|
|
|
}
|