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

1207 lines
38 KiB
C++
Raw Normal View History

2020-05-05 07:44:20 +02:00
/************************************************************************
**
2020-05-23 14:50:22 +02:00
** @file vpgraphicspiece.cpp
2020-05-05 07:44:20 +02:00
** @author Ronan Le Tiec
** @date 4 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:50:22 +02:00
#include "vpgraphicspiece.h"
2020-05-05 07:44:20 +02:00
2023-05-22 16:27:15 +02:00
#include <QApplication>
2020-05-05 07:44:20 +02:00
#include <QBrush>
2023-05-22 16:27:15 +02:00
#include <QGraphicsScene>
#include <QGraphicsSceneContextMenuEvent>
2023-05-22 16:27:15 +02:00
#include <QGraphicsSceneMouseEvent>
#include <QMenu>
2023-05-22 16:27:15 +02:00
#include <QPainter>
#include <QPen>
#include <QStyleOptionGraphicsItem>
2020-05-09 14:45:36 +02:00
#include <QtMath>
2020-05-05 07:44:20 +02:00
2021-08-09 14:09:10 +02:00
#include "../layout/vplayout.h"
2023-05-22 16:27:15 +02:00
#include "../layout/vppiece.h"
2021-08-09 14:09:10 +02:00
#include "../layout/vpsheet.h"
2023-06-21 09:24:51 +02:00
#include "../vformat/vsinglelineoutlinechar.h"
#include "../vgeometry/vlayoutplacelabel.h"
#include "../vlayout/vboundary.h"
2024-01-06 13:20:56 +01:00
#include "../vlayout/vfoldline.h"
#include "../vlayout/vgraphicsfillitem.h"
2023-06-21 09:24:51 +02:00
#include "../vlayout/vlayoutpiecepath.h"
2023-05-22 16:27:15 +02:00
#include "../vlayout/vtextmanager.h"
2024-01-10 10:19:59 +01:00
#include "../vmisc/compatibility.h"
2023-06-21 09:24:51 +02:00
#include "../vmisc/svgfont/vsvgfont.h"
#include "../vmisc/svgfont/vsvgfontdatabase.h"
#include "../vmisc/svgfont/vsvgfontengine.h"
#include "../vmisc/theme/vscenestylesheet.h"
2022-02-09 16:49:14 +01:00
#include "../vpapplication.h"
2024-01-06 13:20:56 +01:00
#include "../vpatterndb/vpiecepath.h"
2021-08-19 14:13:54 +02:00
#include "undocommands/vpundomovepieceonsheet.h"
2023-05-22 16:27:15 +02:00
#include "undocommands/vpundopiecemove.h"
2023-05-02 16:38:02 +02:00
#include "vpiecegrainline.h"
2021-08-18 19:33:47 +02:00
2020-05-05 17:40:36 +02:00
#include <QLoggingCategory>
2022-08-12 17:50:13 +02:00
QT_WARNING_PUSH
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
QT_WARNING_DISABLE_INTEL(1418)
Q_LOGGING_CATEGORY(pGraphicsPiece, "p.graphicsPiece") // NOLINT
QT_WARNING_POP
2020-05-05 07:44:20 +02:00
2021-08-09 14:09:10 +02:00
namespace
{
2022-02-19 20:17:51 +01:00
//---------------------------------------------------------------------------------------------------------------------
2023-05-22 16:27:15 +02:00
inline auto LineFont(const TextLine &tl, const QFont &base) -> QFont
2022-02-19 20:17:51 +01:00
{
QFont fnt = base;
fnt.setPointSize(qMax(base.pointSize() + tl.m_iFontSize, 1));
2022-02-19 20:17:51 +01:00
fnt.setBold(tl.m_bold);
fnt.setItalic(tl.m_italic);
return fnt;
2021-08-09 14:09:10 +02:00
}
2023-06-22 17:30:43 +02:00
//---------------------------------------------------------------------------------------------------------------------
inline auto LineFont(const TextLine &tl, const VSvgFont &base) -> VSvgFont
{
VSvgFont fnt = base;
fnt.SetPointSize(base.PointSize() + tl.m_iFontSize);
fnt.SetBold(tl.m_bold);
fnt.SetItalic(tl.m_italic);
return fnt;
}
2022-02-19 20:17:51 +01:00
//---------------------------------------------------------------------------------------------------------------------
2023-05-22 16:27:15 +02:00
inline auto LineAlign(const TextLine &tl, const QString &text, const QFontMetrics &fm, qreal width) -> qreal
2022-02-19 20:17:51 +01:00
{
const int lineWidth = fm.horizontalAdvance(text);
2022-02-19 20:17:51 +01:00
qreal dX = 0;
if (tl.m_eAlign == 0 || (tl.m_eAlign & Qt::AlignLeft) > 0)
{
dX = 0;
}
else if ((tl.m_eAlign & Qt::AlignHCenter) > 0)
{
2023-05-22 16:27:15 +02:00
dX = (width - lineWidth) / 2;
2022-02-19 20:17:51 +01:00
}
else if ((tl.m_eAlign & Qt::AlignRight) > 0)
{
dX = width - lineWidth;
}
return dX;
}
2022-08-12 17:50:13 +02:00
2023-06-22 17:30:43 +02:00
//---------------------------------------------------------------------------------------------------------------------
inline auto LineAlign(const TextLine &tl, const QString &text, const VSvgFontEngine &engine, qreal width,
qreal penWidth) -> qreal
{
const int lineWidth = qRound(engine.TextWidth(text, penWidth));
qreal dX = 0;
if (tl.m_eAlign == 0 || (tl.m_eAlign & Qt::AlignLeft) > 0)
{
dX = 0;
}
else if ((tl.m_eAlign & Qt::AlignHCenter) > 0)
{
dX = (width - lineWidth) / 2;
}
else if ((tl.m_eAlign & Qt::AlignRight) > 0)
{
dX = width - lineWidth;
}
return dX;
}
2022-08-12 17:50:13 +02:00
//---------------------------------------------------------------------------------------------------------------------
inline auto SelectionBrush() -> QBrush
{
2024-01-06 13:20:56 +01:00
return {VSceneStylesheet::ManualLayoutStyle().PieceSelectionBrushColor()};
2023-11-29 15:40:36 +01:00
}
2023-05-22 16:27:15 +02:00
} // namespace
2022-02-19 20:17:51 +01:00
2020-05-05 07:44:20 +02:00
//---------------------------------------------------------------------------------------------------------------------
2023-05-22 16:27:15 +02:00
VPGraphicsPiece::VPGraphicsPiece(const VPPiecePtr &piece, QGraphicsItem *parent)
: QGraphicsObject(parent),
2021-07-31 11:32:23 +02:00
m_piece(piece)
2020-05-05 07:44:20 +02:00
{
// set some infos
2021-08-09 14:09:10 +02:00
setFlags(ItemIsSelectable | ItemSendsGeometryChanges);
2020-05-09 14:45:36 +02:00
setAcceptHoverEvents(true);
2021-08-09 14:09:10 +02:00
setCursor(Qt::OpenHandCursor);
2020-11-20 17:05:56 +01:00
2022-02-18 16:57:41 +01:00
if (not piece.isNull())
{
setZValue(piece->ZValue());
}
2021-08-09 14:09:10 +02:00
PaintPiece();
InitLabels();
InitGrainlineItem();
2020-05-05 07:44:20 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
auto VPGraphicsPiece::GetPiece() const -> VPPiecePtr
{
2021-08-25 15:58:50 +02:00
return m_piece.toStrongRef();
}
2020-05-05 07:44:20 +02:00
//---------------------------------------------------------------------------------------------------------------------
2021-07-31 11:32:23 +02:00
auto VPGraphicsPiece::boundingRect() const -> QRectF
2020-05-05 07:44:20 +02:00
{
QPainterPath shape;
shape.addPath(m_seamLine);
shape.addPath(m_cuttingLine);
shape.addPath(m_internalPaths);
shape.addPath(m_passmarks);
shape.addPath(m_placeLabels);
2021-08-30 17:45:27 +02:00
shape.addPath(m_stickyPath);
2024-01-06 13:20:56 +01:00
shape.addPath(m_foldLineMarkPath);
shape.addPath(m_foldLineLabelPath);
2022-02-09 16:49:14 +01:00
VPSettings *settings = VPApplication::VApp()->PuzzleSettings();
2023-05-22 16:27:15 +02:00
const qreal halfPenWidth = settings->GetLayoutLineWidth() / 2.;
2020-05-05 07:44:20 +02:00
return shape.boundingRect().adjusted(-halfPenWidth, -halfPenWidth, halfPenWidth, halfPenWidth);
2020-05-05 07:44:20 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
2021-07-31 11:32:23 +02:00
auto VPGraphicsPiece::shape() const -> QPainterPath
2020-05-05 07:44:20 +02:00
{
2023-05-22 16:27:15 +02:00
if (!m_cuttingLine.isEmpty())
2020-05-05 07:44:20 +02:00
{
return m_cuttingLine;
}
return m_seamLine;
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 14:50:22 +02:00
void VPGraphicsPiece::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
2020-05-05 07:44:20 +02:00
{
Q_UNUSED(widget);
2020-05-05 17:40:36 +02:00
Q_UNUSED(option);
2020-05-05 07:44:20 +02:00
2022-02-09 16:49:14 +01:00
VPSettings *settings = VPApplication::VApp()->PuzzleSettings();
2024-01-06 13:20:56 +01:00
QPen const pen(PieceColor(), settings->GetLayoutLineWidth(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
2020-05-05 07:44:20 +02:00
painter->setPen(pen);
2021-08-09 14:09:10 +02:00
PaintPiece(painter);
2020-05-05 07:44:20 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 14:50:22 +02:00
void VPGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event)
2020-05-05 07:44:20 +02:00
{
2023-05-22 16:27:15 +02:00
// perform the default behaviour
2021-07-31 15:00:32 +02:00
QGraphicsObject::mousePressEvent(event);
2020-05-05 07:44:20 +02:00
2020-11-22 12:45:38 +01:00
// change the cursor when clicking the left button
2023-05-22 16:27:15 +02:00
if (event->button() == Qt::LeftButton)
2020-11-22 12:45:38 +01:00
{
2021-08-09 14:09:10 +02:00
setCursor(Qt::ClosedHandCursor);
2020-05-09 14:45:36 +02:00
2021-08-09 14:09:10 +02:00
m_moveStartPoint = event->pos();
emit HideTransformationHandles(true);
2021-08-30 17:45:27 +02:00
m_hasStickyPosition = false;
2020-05-09 14:45:36 +02:00
}
}
//---------------------------------------------------------------------------------------------------------------------
2021-08-09 14:09:10 +02:00
void VPGraphicsPiece::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
2020-05-09 14:45:36 +02:00
{
2021-08-09 14:09:10 +02:00
QGraphicsObject::mouseMoveEvent(event);
2020-05-09 14:45:36 +02:00
2021-08-09 14:09:10 +02:00
GroupMove(event->pos());
2020-05-09 14:45:36 +02:00
2021-08-09 14:09:10 +02:00
m_moveStartPoint = event->pos();
2022-08-12 17:50:13 +02:00
m_allowChangeMerge = true;
2020-05-05 07:44:20 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 14:50:22 +02:00
void VPGraphicsPiece::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
2020-05-05 07:44:20 +02:00
{
2023-05-22 16:27:15 +02:00
// perform the default behaviour
2020-05-05 07:44:20 +02:00
QGraphicsItem::mouseReleaseEvent(event);
// change the cursor when clicking left button
if (event->button() == Qt::LeftButton)
2020-05-05 07:44:20 +02:00
{
setCursor(Qt::OpenHandCursor);
2021-08-09 14:09:10 +02:00
emit HideTransformationHandles(false);
2021-08-30 17:45:27 +02:00
if (VPPiecePtr const piece = m_piece.toStrongRef(); not piece.isNull())
2021-08-30 17:45:27 +02:00
{
if (VPLayoutPtr const layout = piece->Layout(); not layout.isNull())
2021-08-30 17:45:27 +02:00
{
2024-04-06 17:52:43 +02:00
if (layout->LayoutSettings().IsStickyEdges() && m_hasStickyPosition)
2021-08-30 17:45:27 +02:00
{
2023-05-22 16:27:15 +02:00
auto *command =
new VPUndoPieceMove(piece, m_stickyTranslateX, m_stickyTranslateY, m_allowChangeMerge);
2021-08-30 17:45:27 +02:00
layout->UndoStack()->push(command);
SetStickyPoints(QVector<QPointF>());
}
}
}
2022-08-12 17:50:13 +02:00
m_allowChangeMerge = false;
2021-08-30 17:45:27 +02:00
m_hasStickyPosition = false;
}
2020-05-05 07:44:20 +02:00
}
2022-02-18 16:21:43 +01:00
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
m_hoverMode = true;
QGraphicsObject::hoverEnterEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
m_hoverMode = false;
QGraphicsObject::hoverLeaveEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
2020-05-23 14:50:22 +02:00
void VPGraphicsPiece::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
2024-02-19 17:09:56 +01:00
VPPiecePtr const piece = m_piece.toStrongRef();
2021-08-18 19:33:47 +02:00
if (piece.isNull())
{
return;
}
2024-02-19 17:09:56 +01:00
VPLayoutPtr const layout = piece->Layout();
2021-08-18 19:33:47 +02:00
if (layout.isNull())
{
return;
}
QMenu menu;
QList<VPSheetPtr> sheets = layout->GetSheets();
sheets.removeAll(piece->Sheet());
2023-05-22 16:27:15 +02:00
QVector<QAction *> moveToActions;
2021-07-31 15:00:32 +02:00
if (not sheets.isEmpty())
{
QMenu *moveMenu = menu.addMenu(tr("Move to"));
2021-08-18 19:33:47 +02:00
for (const auto &sheet : sheets)
2021-07-31 15:00:32 +02:00
{
2021-08-18 19:33:47 +02:00
if (not sheet.isNull())
{
2023-05-22 16:27:15 +02:00
QAction *moveToSheet = moveMenu->addAction(sheet->GetName());
2021-08-18 19:33:47 +02:00
moveToSheet->setData(QVariant::fromValue(sheet));
moveToActions.append(moveToSheet);
}
2021-07-31 15:00:32 +02:00
}
}
2021-07-31 15:00:32 +02:00
// remove from layout action
QAction *removeAction = menu.addAction(tr("Remove from Sheet"));
2021-07-31 15:00:32 +02:00
QAction *selectedAction = menu.exec(event->screenPos());
2021-07-31 15:00:32 +02:00
if (moveToActions.contains(selectedAction))
{
2021-08-19 14:13:54 +02:00
auto *command = new VPUndoMovePieceOnSheet(qvariant_cast<VPSheetPtr>(selectedAction->data()), piece);
layout->UndoStack()->push(command);
2021-07-31 15:00:32 +02:00
}
else if (selectedAction == removeAction)
{
2021-08-19 14:13:54 +02:00
auto *command = new VPUndoMovePieceOnSheet(VPSheetPtr(), piece);
layout->UndoStack()->push(command);
2021-07-31 15:00:32 +02:00
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::SetTextAsPaths(bool newTextAsPaths)
{
m_textAsPaths = newTextAsPaths;
InitLabels();
}
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::InitLabels()
{
qDeleteAll(m_labelPathItems);
qDeleteAll(m_labelTextItems);
m_labelPathItems.clear();
m_labelTextItems.clear();
2024-01-06 13:20:56 +01:00
VPPiecePtr const piece = m_piece.toStrongRef();
if (piece.isNull())
{
return;
}
InitPieceLabel(piece->GetPieceLabelRect(), piece->GetPieceLabelData());
InitPieceLabel(piece->GetPatternLabelRect(), piece->GetPatternLabelData());
}
2021-08-30 17:45:27 +02:00
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::SetStickyPoints(const QVector<QPointF> &newStickyPoint)
{
m_stickyPoints = newStickyPoint;
prepareGeometryChange();
PaintPiece(); // refresh shapes
}
2021-08-27 17:23:27 +02:00
//---------------------------------------------------------------------------------------------------------------------
2023-06-22 17:30:43 +02:00
void VPGraphicsPiece::InitPieceLabelSVGFont(const QVector<QPointF> &labelShape, const VTextManager &tm)
2021-08-27 17:23:27 +02:00
{
2024-01-06 13:20:56 +01:00
VPPiecePtr const piece = m_piece.toStrongRef();
2021-08-27 17:23:27 +02:00
if (piece.isNull())
{
return;
}
2022-02-19 20:17:51 +01:00
if (labelShape.count() <= 2)
2021-08-27 17:23:27 +02:00
{
2022-02-19 20:17:51 +01:00
return;
}
2021-08-27 17:23:27 +02:00
2023-06-22 17:30:43 +02:00
VSvgFontDatabase *db = VAbstractApplication::VApp()->SVGFontDatabase();
VSvgFontEngine engine =
db->FontEngine(tm.GetSVGFontFamily(), SVGFontStyle::Normal, SVGFontWeight::Normal, tm.GetSVGFontPointSize());
2024-01-06 13:20:56 +01:00
VSvgFont const svgFont = engine.Font();
2023-06-22 17:30:43 +02:00
if (!svgFont.IsValid())
{
2024-01-06 13:20:56 +01:00
QString const errorMsg = QStringLiteral("Invalid SVG font '%1'. Fallback to outline font.").arg(svgFont.Name());
2023-06-22 17:30:43 +02:00
qDebug() << errorMsg;
InitPieceLabelOutlineFont(labelShape, tm);
return;
}
2024-01-06 13:20:56 +01:00
qreal const penWidth = VPApplication::VApp()->PuzzleSettings()->GetLayoutLineWidth();
2023-06-22 17:30:43 +02:00
2022-02-19 20:17:51 +01:00
const qreal dW = QLineF(labelShape.at(0), labelShape.at(1)).length();
const qreal dH = QLineF(labelShape.at(1), labelShape.at(2)).length();
2023-05-22 16:27:15 +02:00
const qreal angle = -QLineF(labelShape.at(0), labelShape.at(1)).angle();
2022-02-19 20:17:51 +01:00
const QColor color = PieceColor();
2023-06-22 17:30:43 +02:00
qreal dY = penWidth;
const QVector<TextLine> labelLines = tm.GetLabelSourceLines(qFloor(dW), svgFont, penWidth);
for (const auto &tl : labelLines)
{
const VSvgFont fnt = LineFont(tl, svgFont);
engine = db->FontEngine(fnt);
if (dY + engine.FontHeight() + penWidth > dH)
{
break;
}
const QString qsText = tl.m_qsText;
const qreal dX = LineAlign(tl, qsText, engine, dW, penWidth);
// set up the rotation around top-left corner matrix
const QTransform lineMatrix = piece->LineMatrix(labelShape.at(0), angle, QPointF(dX, dY), dW);
2023-06-22 17:30:43 +02:00
auto *item = new QGraphicsPathItem(this);
item->setPath(engine.DrawPath(QPointF(), qsText));
QPen itemPen = item->pen();
itemPen.setColor(color);
itemPen.setCapStyle(Qt::RoundCap);
itemPen.setJoinStyle(Qt::RoundJoin);
itemPen.setWidthF(penWidth);
item->setPen(itemPen);
item->setBrush(QBrush(Qt::NoBrush));
item->setTransform(lineMatrix);
m_labelPathItems.append(item);
2024-01-06 13:20:56 +01:00
dY += engine.FontHeight() - penWidth * 2 + tm.GetSpacing();
2023-06-22 17:30:43 +02:00
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::InitPieceLabelOutlineFont(const QVector<QPointF> &labelShape, const VTextManager &tm)
{
2024-02-19 17:09:56 +01:00
VPPiecePtr const piece = m_piece.toStrongRef();
2023-06-22 17:30:43 +02:00
if (piece.isNull())
{
return;
}
if (labelShape.count() <= 2)
{
return;
}
const qreal dW = QLineF(labelShape.at(0), labelShape.at(1)).length();
const qreal dH = QLineF(labelShape.at(1), labelShape.at(2)).length();
const qreal angle = -QLineF(labelShape.at(0), labelShape.at(1)).angle();
const QColor color = PieceColor();
2024-02-19 17:09:56 +01:00
qreal const penWidth = VPApplication::VApp()->PuzzleSettings()->GetLayoutLineWidth();
2022-02-19 20:17:51 +01:00
qreal dY = 0;
2021-08-27 17:23:27 +02:00
2023-06-22 17:30:43 +02:00
VCommonSettings *settings = VAbstractApplication::VApp()->Settings();
bool textAsPaths = m_textAsPaths;
if (settings->GetSingleStrokeOutlineFont())
{
textAsPaths = true;
dY += penWidth;
}
2023-05-22 16:30:18 +02:00
const QVector<TextLine> labelLines = tm.GetLabelSourceLines(qFloor(dW), tm.GetFont());
for (const auto &tl : labelLines)
2022-02-19 20:17:51 +01:00
{
const QFont fnt = LineFont(tl, tm.GetFont());
2024-01-06 13:20:56 +01:00
QFontMetrics const fm(fnt);
2023-06-22 17:30:43 +02:00
if (dY + fm.height() > dH)
2022-02-19 20:17:51 +01:00
{
2023-06-22 17:30:43 +02:00
break;
2022-02-19 20:17:51 +01:00
}
2021-08-27 17:23:27 +02:00
2024-01-06 13:20:56 +01:00
const qreal dX = LineAlign(tl, tl.m_qsText, fm, dW);
2022-02-19 20:17:51 +01:00
// set up the rotation around top-left corner matrix
const QTransform lineMatrix = piece->LineMatrix(labelShape.at(0), angle, QPointF(dX, dY), dW);
2021-08-27 17:23:27 +02:00
2023-06-22 17:30:43 +02:00
if (textAsPaths)
2022-02-19 20:17:51 +01:00
{
QPainterPath path;
2023-06-22 17:30:43 +02:00
if (settings->GetSingleStrokeOutlineFont())
{
2024-01-06 13:20:56 +01:00
VSingleLineOutlineChar const corrector(fnt);
if (!corrector.IsPopulated())
{
corrector.LoadCorrections(settings->GetPathFontCorrections());
}
2023-06-22 17:30:43 +02:00
int w = 0;
2024-01-06 13:20:56 +01:00
for (auto c : qAsConst(tl.m_qsText))
2023-06-22 17:30:43 +02:00
{
path.addPath(corrector.DrawChar(w, static_cast<qreal>(fm.ascent()), c));
w += fm.horizontalAdvance(c);
2023-06-22 17:30:43 +02:00
}
}
else
{
2024-01-06 13:20:56 +01:00
path.addText(0, static_cast<qreal>(fm.ascent()), fnt, tl.m_qsText);
2023-06-22 17:30:43 +02:00
}
2023-05-22 16:27:15 +02:00
auto *item = new QGraphicsPathItem(this);
2022-02-19 20:17:51 +01:00
item->setPath(path);
2023-06-22 17:30:43 +02:00
QPen itemPen = item->pen();
itemPen.setColor(color);
itemPen.setCapStyle(Qt::RoundCap);
itemPen.setJoinStyle(Qt::RoundJoin);
itemPen.setWidthF(penWidth);
item->setPen(itemPen);
item->setBrush(settings->GetSingleStrokeOutlineFont() ? QBrush(Qt::NoBrush) : QBrush(color));
2022-02-19 20:17:51 +01:00
item->setTransform(lineMatrix);
m_labelPathItems.append(item);
2024-01-06 13:20:56 +01:00
dY += fm.height() + penWidth + MmToPixel(1.5) + tm.GetSpacing();
2022-02-19 20:17:51 +01:00
}
else
{
2023-05-22 16:27:15 +02:00
auto *item = new QGraphicsSimpleTextItem(this);
2022-02-19 20:17:51 +01:00
item->setFont(fnt);
2024-01-06 13:20:56 +01:00
item->setText(tl.m_qsText);
2022-02-19 20:17:51 +01:00
item->setBrush(QBrush(color));
item->setTransform(lineMatrix);
m_labelTextItems.append(item);
2024-01-06 13:20:56 +01:00
dY += (fm.height() + MmToPixel(1.5) + tm.GetSpacing());
2021-08-27 17:23:27 +02:00
}
}
}
2023-06-22 17:30:43 +02:00
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::InitPieceLabel(const QVector<QPointF> &labelShape, const VTextManager &tm)
{
VCommonSettings *settings = VAbstractApplication::VApp()->Settings();
if (settings->GetSingleLineFonts())
{
InitPieceLabelSVGFont(labelShape, tm);
}
else
{
InitPieceLabelOutlineFont(labelShape, tm);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::InitGrainlineItem()
{
delete m_grainlineItem;
2024-02-19 17:09:56 +01:00
VPPiecePtr const piece = m_piece.toStrongRef();
if (piece.isNull())
{
return;
}
2023-05-22 16:27:15 +02:00
if (piece->IsGrainlineEnabled())
{
m_grainlineItem = new VGraphicsFillItem(this);
2023-05-02 16:38:02 +02:00
m_grainlineItem->setPath(VLayoutPiece::GrainlinePath(piece->GetMappedGrainlineShape()));
VPSettings *settings = VPApplication::VApp()->PuzzleSettings();
2024-02-19 17:09:56 +01:00
QPen const pen(PieceColor(), settings->GetLayoutLineWidth(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
m_grainlineItem->SetCustomPen(true);
m_grainlineItem->setPen(pen);
}
}
2020-05-05 17:40:36 +02:00
//---------------------------------------------------------------------------------------------------------------------
2021-08-09 14:09:10 +02:00
void VPGraphicsPiece::PaintPiece(QPainter *painter)
2020-05-05 17:40:36 +02:00
{
m_seamLine = QPainterPath();
m_cuttingLine = QPainterPath();
m_internalPaths = QPainterPath();
m_passmarks = QPainterPath();
m_placeLabels = QPainterPath();
2021-08-30 17:45:27 +02:00
m_stickyPath = QPainterPath();
2024-01-06 13:20:56 +01:00
m_foldLineMarkPath = QPainterPath();
m_foldLineLabelPath = QPainterPath();
2024-01-06 13:20:56 +01:00
VPPiecePtr const piece = m_piece.toStrongRef();
2021-08-18 19:33:47 +02:00
if (piece.isNull())
{
return;
}
2021-08-09 14:09:10 +02:00
// initialises the seam line
2022-08-12 17:50:13 +02:00
PaintSeamLine(painter, piece);
// initiliases the cutting line
PaintCuttingLine(painter, piece);
// initialises the internal paths
PaintInternalPaths(painter, piece);
// initialises the passmarks
PaintPassmarks(painter, piece);
// initialises the place labels (buttons etc)
PaintPlaceLabels(painter, piece);
2024-01-06 13:20:56 +01:00
PaintMirrorLine(painter, piece);
PaintFoldLine(painter, piece);
2022-08-12 17:50:13 +02:00
PaintStickyPath(painter);
}
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::PaintSeamLine(QPainter *painter, const VPPiecePtr &piece)
{
2024-01-06 13:20:56 +01:00
if (piece->IsHideMainPath() && piece->IsSeamAllowance() && not piece->IsSeamAllowanceBuiltIn())
2021-08-09 14:09:10 +02:00
{
2024-01-06 13:20:56 +01:00
return;
}
2024-01-06 13:20:56 +01:00
QVector<VLayoutPoint> const seamLinePoints = piece->GetMappedFullContourPoints();
2021-08-09 14:09:10 +02:00
2024-01-06 13:20:56 +01:00
if (seamLinePoints.isEmpty())
{
return;
}
2024-01-06 13:20:56 +01:00
VPLayoutPtr const layout = piece->Layout();
if (layout.isNull())
{
return;
}
2024-01-06 13:20:56 +01:00
if (layout->LayoutSettings().IsBoundaryTogetherWithNotches())
{
QVector<VLayoutPassmark> const passmarks = piece->GetMappedPassmarks();
2024-01-06 13:20:56 +01:00
bool const seamAllowance = piece->IsSeamAllowance() && piece->IsSeamAllowanceBuiltIn();
bool const builtInSeamAllowance = piece->IsSeamAllowance() && piece->IsSeamAllowanceBuiltIn();
2024-01-06 13:20:56 +01:00
VBoundary boundary(seamLinePoints, seamAllowance, builtInSeamAllowance);
boundary.SetPieceName(piece->GetName());
if (piece->IsShowFullPiece())
{
2024-01-06 13:20:56 +01:00
boundary.SetMirrorLine(piece->GetMappedSeamMirrorLine());
}
2024-01-06 13:20:56 +01:00
const QList<VBoundarySequenceItemData> sequence = boundary.Combine(passmarks, false, false);
2024-01-06 13:20:56 +01:00
QVector<QPointF> combinedBoundary;
for (const auto &item : sequence)
{
2024-01-06 13:20:56 +01:00
const auto path = item.item.value<VLayoutPiecePath>().Points();
QVector<QPointF> convertedPoints;
CastTo(path, convertedPoints);
combinedBoundary += convertedPoints;
2021-08-09 14:09:10 +02:00
}
2024-01-06 13:20:56 +01:00
m_seamLine.addPolygon(QPolygonF(combinedBoundary));
m_seamLine.closeSubpath();
}
else
{
QVector<QPointF> convertedPoints;
CastTo(seamLinePoints, convertedPoints);
m_seamLine.addPolygon(QPolygonF(convertedPoints));
m_seamLine.closeSubpath();
}
if (painter != nullptr)
{
painter->save();
painter->setBrush(piece->IsSelected() ? SelectionBrush() : NoBrush());
painter->drawPath(m_seamLine);
painter->restore();
2021-08-09 14:09:10 +02:00
}
2022-08-12 17:50:13 +02:00
}
2021-08-09 14:09:10 +02:00
2022-08-12 17:50:13 +02:00
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::PaintCuttingLine(QPainter *painter, const VPPiecePtr &piece)
{
2021-08-31 13:12:46 +02:00
if (piece->IsSeamAllowance() && not piece->IsSeamAllowanceBuiltIn())
2021-08-09 14:09:10 +02:00
{
2024-02-19 17:09:56 +01:00
QVector<VLayoutPoint> const cuttingLinepoints = piece->GetMappedFullSeamAllowancePoints();
if (cuttingLinepoints.isEmpty())
2021-08-09 14:09:10 +02:00
{
return;
}
2021-08-09 14:09:10 +02:00
2024-02-19 17:09:56 +01:00
VPLayoutPtr const layout = piece->Layout();
if (layout.isNull())
{
return;
}
if (layout->LayoutSettings().IsBoundaryTogetherWithNotches())
{
const QVector<VLayoutPassmark> passmarks = piece->GetMappedPassmarks();
2024-02-19 17:09:56 +01:00
bool const seamAllowance = piece->IsSeamAllowance() && !piece->IsSeamAllowanceBuiltIn();
bool const builtInSeamAllowance = piece->IsSeamAllowance() && piece->IsSeamAllowanceBuiltIn();
VBoundary boundary(cuttingLinepoints, seamAllowance, builtInSeamAllowance);
boundary.SetPieceName(piece->GetName());
2024-01-06 13:20:56 +01:00
if (piece->IsShowFullPiece())
{
boundary.SetMirrorLine(piece->GetMappedSeamAllowanceMirrorLine());
}
const QList<VBoundarySequenceItemData> sequence = boundary.Combine(passmarks, false, false);
QVector<QPointF> combinedBoundary;
for (const auto &item : sequence)
2021-08-31 13:12:46 +02:00
{
const auto path = item.item.value<VLayoutPiecePath>().Points();
QVector<QPointF> convertedPoints;
CastTo(path, convertedPoints);
combinedBoundary += convertedPoints;
2021-08-31 13:12:46 +02:00
}
m_cuttingLine.addPolygon(QPolygonF(combinedBoundary));
m_cuttingLine.closeSubpath();
}
else
{
QVector<QPointF> convertedPoints;
CastTo(cuttingLinepoints, convertedPoints);
m_cuttingLine.addPolygon(QPolygonF(convertedPoints));
m_cuttingLine.closeSubpath();
}
if (painter != nullptr)
{
painter->save();
painter->setBrush(piece->IsSelected() ? SelectionBrush() : NoBrush());
painter->drawPath(m_cuttingLine);
painter->restore();
2021-08-09 14:09:10 +02:00
}
}
2022-08-12 17:50:13 +02:00
}
2021-08-09 14:09:10 +02:00
2022-08-12 17:50:13 +02:00
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::PaintInternalPaths(QPainter *painter, const VPPiecePtr &piece)
{
2024-01-06 13:20:56 +01:00
QVector<VLayoutPiecePath> const internalPaths = piece->GetInternalPaths();
2023-05-22 16:27:15 +02:00
for (const auto &piecePath : internalPaths)
2021-08-09 14:09:10 +02:00
{
2021-08-18 19:33:47 +02:00
QPainterPath path = piece->GetMatrix().map(piecePath.GetPainterPath());
2021-08-09 14:09:10 +02:00
2024-01-06 13:20:56 +01:00
if (!piecePath.IsNotMirrored() && piece->IsShowFullPiece() && !piece->GetSeamMirrorLine().isNull())
{
QVector<VLayoutPoint> points = piecePath.Points();
const QTransform matrix = VGObject::FlippingMatrix(piece->GetSeamMirrorLine());
std::transform(points.begin(), points.end(), points.begin(),
[&matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); });
2024-01-06 13:20:56 +01:00
QVector<QPointF> casted;
CastTo(points, casted);
path.addPath(piece->GetMatrix().map(VPiecePath::MakePainterPath(casted)));
}
2021-08-09 14:09:10 +02:00
if (painter != nullptr)
{
painter->save();
2021-09-08 10:15:01 +02:00
QPen pen = painter->pen();
pen.setStyle(piecePath.PenStyle());
painter->setPen(pen);
2021-08-09 14:09:10 +02:00
painter->drawPath(path);
painter->restore();
}
m_internalPaths.addPath(path);
2021-08-09 14:09:10 +02:00
}
2022-08-12 17:50:13 +02:00
}
2021-08-09 14:09:10 +02:00
2022-08-12 17:50:13 +02:00
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::PaintPassmarks(QPainter *painter, const VPPiecePtr &piece)
{
2024-01-06 13:20:56 +01:00
VPLayoutPtr const layout = piece->Layout();
if (layout.isNull())
{
return;
}
if (layout->LayoutSettings().IsBoundaryTogetherWithNotches())
{
return;
}
2024-01-06 13:20:56 +01:00
QVector<VLayoutPassmark> const passmarks = piece->GetMappedPassmarks();
for (const auto &passmark : passmarks)
2021-08-09 14:09:10 +02:00
{
if (piece->IsHideMainPath() && passmark.isBuiltIn)
{
continue;
}
2021-08-09 14:09:10 +02:00
QPainterPath passmarkPath;
2024-01-06 13:20:56 +01:00
for (const auto &line : passmark.lines)
2021-08-09 14:09:10 +02:00
{
passmarkPath.moveTo(line.p1());
passmarkPath.lineTo(line.p2());
}
2024-01-06 13:20:56 +01:00
m_passmarks.addPath(passmarkPath);
if (QLineF const seamAllowanceMirrorLine = piece->GetMappedSeamAllowanceMirrorLine();
!seamAllowanceMirrorLine.isNull() && piece->IsShowFullPiece() &&
!VGObject::IsPointOnLineviaPDP(passmark.baseLine.p1(), seamAllowanceMirrorLine.p1(),
seamAllowanceMirrorLine.p2()))
2024-01-06 13:20:56 +01:00
{
QPainterPath mirroredPassmaksPath;
for (const auto &line : passmark.lines)
{
mirroredPassmaksPath.moveTo(line.p1());
mirroredPassmaksPath.lineTo(line.p2());
}
const QTransform matrix = VGObject::FlippingMatrix(seamAllowanceMirrorLine);
m_passmarks.addPath(matrix.map(mirroredPassmaksPath));
2024-01-06 13:20:56 +01:00
}
2021-08-09 14:09:10 +02:00
if (painter != nullptr)
{
painter->save();
2022-08-12 17:50:13 +02:00
painter->setBrush(NoBrush());
2024-01-06 13:20:56 +01:00
painter->drawPath(m_passmarks);
2021-08-09 14:09:10 +02:00
painter->restore();
}
}
2022-08-12 17:50:13 +02:00
}
2021-08-09 14:09:10 +02:00
2022-08-12 17:50:13 +02:00
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::PaintPlaceLabels(QPainter *painter, const VPPiecePtr &piece)
{
2024-01-06 13:20:56 +01:00
QVector<VLayoutPlaceLabel> const placeLabels = piece->GetPlaceLabels();
for (const auto &placeLabel : placeLabels)
2021-08-09 14:09:10 +02:00
{
2022-10-28 15:16:02 +02:00
QPainterPath path =
VAbstractPiece::LabelShapePath(piece->MapPlaceLabelShape(VAbstractPiece::PlaceLabelShape(placeLabel)));
2021-08-09 14:09:10 +02:00
2024-01-06 13:20:56 +01:00
if (!placeLabel.IsNotMirrored() && piece->IsShowFullPiece() && !piece->GetSeamMirrorLine().isNull())
{
PlaceLabelImg shape = VAbstractPiece::PlaceLabelShape(placeLabel);
const QTransform matrix = VGObject::FlippingMatrix(piece->GetSeamMirrorLine());
for (auto &points : shape)
{
std::transform(points.begin(), points.end(), points.begin(),
[&matrix](const VLayoutPoint &point)
{ return VAbstractPiece::MapPoint(point, matrix); });
2024-01-06 13:20:56 +01:00
}
path.addPath(VAbstractPiece::LabelShapePath(piece->MapPlaceLabelShape(shape)));
}
2021-08-09 14:09:10 +02:00
if (painter != nullptr)
{
painter->save();
2022-08-12 17:50:13 +02:00
painter->setBrush(NoBrush());
2021-08-09 14:09:10 +02:00
painter->drawPath(path);
painter->restore();
}
m_placeLabels.addPath(path);
2021-08-09 14:09:10 +02:00
}
2022-08-12 17:50:13 +02:00
}
2021-08-09 14:09:10 +02:00
2022-08-12 17:50:13 +02:00
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::PaintStickyPath(QPainter *painter)
{
2021-08-30 17:45:27 +02:00
if (not m_stickyPoints.isEmpty())
{
m_stickyPath.moveTo(m_stickyPoints.constFirst());
2021-08-30 17:45:27 +02:00
for (int i = 1; i < m_stickyPoints.size(); i++)
{
m_stickyPath.lineTo(m_stickyPoints.at(i));
}
if (painter != nullptr)
{
painter->save();
painter->setBrush(QBrush(VSceneStylesheet::ManualLayoutStyle().PieceOkColor(), Qt::BDiagPattern));
2021-08-30 17:45:27 +02:00
QPen pen = painter->pen();
pen.setStyle(Qt::DashLine);
pen.setColor(VSceneStylesheet::ManualLayoutStyle().PieceOkColor());
2021-08-30 17:45:27 +02:00
painter->setPen(pen);
painter->drawPath(m_stickyPath);
painter->restore();
}
}
2020-05-05 17:40:36 +02:00
}
2024-01-06 13:20:56 +01:00
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::PaintMirrorLine(QPainter *painter, const VPPiecePtr &piece) const
2024-01-06 13:20:56 +01:00
{
if (piece->IsShowFullPiece())
{
bool mirrorFlag = false;
QPainterPath mirrorLinePath;
if (not piece->IsSeamAllowance() || piece->IsSeamAllowanceBuiltIn())
{
QLineF const seamMirrorLine = piece->GetMappedSeamMirrorLine();
if (!seamMirrorLine.isNull() && piece->IsShowMirrorLine())
2024-01-06 13:20:56 +01:00
{
QPainterPath mirrorPath;
mirrorPath.moveTo(seamMirrorLine.p1());
mirrorPath.lineTo(seamMirrorLine.p2());
mirrorLinePath.addPath(mirrorPath);
mirrorFlag = true;
}
}
else if (not piece->IsSeamAllowanceBuiltIn())
{
QLineF const seamAllowanceMirrorLine = piece->GetMappedSeamAllowanceMirrorLine();
if (!seamAllowanceMirrorLine.isNull() && piece->IsShowMirrorLine())
2024-01-06 13:20:56 +01:00
{
QPainterPath mirrorPath;
mirrorPath.moveTo(seamAllowanceMirrorLine.p1());
mirrorPath.lineTo(seamAllowanceMirrorLine.p2());
mirrorLinePath.addPath(mirrorPath);
mirrorFlag = true;
}
}
if (mirrorFlag && painter != nullptr)
{
painter->save();
QPen pen = painter->pen();
pen.setStyle(Qt::DashDotLine);
painter->setPen(pen);
painter->drawPath(mirrorLinePath);
painter->restore();
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::PaintFoldLine(QPainter *painter, const VPPiecePtr &piece)
{
if (piece->GetFoldLineType() == FoldLineType::None)
{
return;
}
VFoldLine const fLine = piece->FoldLine();
QVector<QPainterPath> const shape = fLine.FoldLinePath();
if (shape.isEmpty())
{
return;
}
VCommonSettings *settings = VAbstractApplication::VApp()->Settings();
if (!m_textAsPaths && !settings->GetSingleStrokeOutlineFont() && !settings->GetSingleLineFonts())
{
if (m_foldLineLabelText == nullptr)
{
m_foldLineLabelText = new QGraphicsSimpleTextItem(this);
}
fLine.UpdateFoldLineLabel(m_foldLineLabelText);
2024-04-08 14:58:09 +02:00
m_foldLineLabelText->setBrush(QBrush(PieceColor()));
2024-01-06 13:20:56 +01:00
}
else
{
if (m_foldLineLabelText != nullptr)
{
m_foldLineLabelText->setVisible(false);
}
}
const bool singleLineFont = settings->GetSingleStrokeOutlineFont() || settings->GetSingleLineFonts();
if (piece->GetFoldLineType() == FoldLineType::ThreeDots || piece->GetFoldLineType() == FoldLineType::ThreeX ||
piece->GetFoldLineType() == FoldLineType::TwoArrows)
{
m_foldLineMarkPath.addPath(shape.constFirst());
}
else if (piece->GetFoldLineType() == FoldLineType::Text)
{
if (singleLineFont || m_textAsPaths)
{
m_foldLineLabelPath.addPath(shape.constFirst());
}
}
else
{
m_foldLineMarkPath.addPath(shape.constFirst());
if (shape.size() > 1 && (singleLineFont || m_textAsPaths))
{
m_foldLineLabelPath.addPath(shape.constLast());
}
}
if (painter != nullptr)
{
painter->save();
painter->setBrush(Qt::SolidPattern);
painter->drawPath(m_foldLineMarkPath);
painter->restore();
qreal const penWidth = VPApplication::VApp()->PuzzleSettings()->GetLayoutLineWidth();
painter->save();
QPen pen = painter->pen();
pen.setWidthF(penWidth * qMin(piece->GetXScale(), piece->GetYScale()));
2024-04-08 14:58:09 +02:00
pen.setColor(PieceColor());
pen.setCapStyle(Qt::RoundCap);
pen.setJoinStyle(Qt::RoundJoin);
2024-01-06 13:20:56 +01:00
painter->setPen(pen);
painter->setBrush(singleLineFont ? Qt::NoBrush : Qt::SolidPattern);
painter->drawPath(m_foldLineLabelPath);
painter->restore();
}
}
2020-05-09 11:13:29 +02:00
//---------------------------------------------------------------------------------------------------------------------
2021-08-09 14:09:10 +02:00
void VPGraphicsPiece::GroupMove(const QPointF &pos)
2020-05-09 11:13:29 +02:00
{
2024-02-19 17:09:56 +01:00
VPPiecePtr const piece = m_piece.toStrongRef();
2021-08-25 15:58:50 +02:00
if (piece.isNull())
2021-08-09 14:09:10 +02:00
{
2021-08-25 15:58:50 +02:00
return;
}
2021-08-18 19:33:47 +02:00
2024-02-19 17:09:56 +01:00
VPLayoutPtr const layout = piece->Layout();
2021-08-25 15:58:50 +02:00
if (layout.isNull())
{
return;
}
2021-08-18 19:33:47 +02:00
2021-08-25 15:58:50 +02:00
auto PreparePieces = [layout]()
{
QList<VPPiecePtr> pieces;
2021-08-18 19:33:47 +02:00
if (VPSheetPtr const sheet = layout->GetFocusedSheet(); not sheet.isNull())
2021-08-18 19:33:47 +02:00
{
2021-08-25 15:58:50 +02:00
return sheet->GetSelectedPieces();
2021-08-18 19:33:47 +02:00
}
2021-08-25 15:58:50 +02:00
return pieces;
};
2021-08-18 19:33:47 +02:00
2024-02-19 17:09:56 +01:00
QList<VPPiecePtr> const pieces = PreparePieces();
QPointF const newPos = pos - m_moveStartPoint;
2021-08-18 19:33:47 +02:00
2021-08-25 15:58:50 +02:00
if (qFuzzyIsNull(newPos.x()) && qFuzzyIsNull(newPos.y()))
{
return;
}
2021-08-18 19:33:47 +02:00
2021-08-25 15:58:50 +02:00
if (pieces.size() == 1)
{
const VPPiecePtr &p = pieces.constFirst();
2022-08-12 17:50:13 +02:00
auto *command = new VPUndoPieceMove(piece, newPos.x(), newPos.y(), m_allowChangeMerge);
2021-08-25 15:58:50 +02:00
layout->UndoStack()->push(command);
2021-08-30 17:45:27 +02:00
2024-04-06 17:52:43 +02:00
if (layout->LayoutSettings().IsStickyEdges())
2021-08-30 17:45:27 +02:00
{
QVector<QPointF> path;
if (not p.isNull() && p->StickyPosition(m_stickyTranslateX, m_stickyTranslateY))
{
2022-10-28 12:55:24 +02:00
CastTo(p->GetMappedExternalContourPoints(), path);
2021-08-30 17:45:27 +02:00
QTransform m;
m.translate(m_stickyTranslateX, m_stickyTranslateY);
path = m.map(path);
m_hasStickyPosition = true;
}
else
{
m_hasStickyPosition = false;
}
SetStickyPoints(path);
}
2021-08-25 15:58:50 +02:00
}
else if (pieces.size() > 1)
{
2022-08-12 17:50:13 +02:00
auto *command = new VPUndoPiecesMove(pieces, newPos.x(), newPos.y(), m_allowChangeMerge);
2021-08-25 15:58:50 +02:00
layout->UndoStack()->push(command);
2021-08-09 14:09:10 +02:00
}
2020-05-09 11:13:29 +02:00
}
2020-11-10 21:29:23 +01:00
//---------------------------------------------------------------------------------------------------------------------
auto VPGraphicsPiece::PieceColor() const -> QColor
{
2024-02-19 17:09:56 +01:00
VPPiecePtr const piece = m_piece.toStrongRef();
if (piece.isNull())
{
return VSceneStylesheet::ManualLayoutStyle().PieceOkColor();
}
2024-02-19 17:09:56 +01:00
VPLayoutPtr const layout = piece->Layout();
if (layout.isNull())
{
return VSceneStylesheet::ManualLayoutStyle().PieceOkColor();
}
bool outOfBound = false;
if (layout->LayoutSettings().GetWarningPiecesOutOfBound())
{
outOfBound = piece->OutOfBound();
}
bool superposition = false;
if (layout->LayoutSettings().GetWarningSuperpositionOfPieces())
{
superposition = piece->HasSuperpositionWithPieces();
}
2024-04-08 15:26:09 +02:00
bool pieceGape = false;
if (layout->LayoutSettings().GetWarningPieceGapePosition())
{
pieceGape = piece->HasInvalidPieceGapPosition();
}
if (outOfBound || superposition || pieceGape)
{
return VSceneStylesheet::ManualLayoutStyle().PieceErrorColor();
}
return VSceneStylesheet::ManualLayoutStyle().PieceOkColor();
2022-08-12 17:50:13 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
auto VPGraphicsPiece::NoBrush() const -> QBrush
{
return m_hoverMode ? QBrush(VSceneStylesheet::ManualLayoutStyle().PieceHoverColor()) : QBrush(Qt::NoBrush);
}
//---------------------------------------------------------------------------------------------------------------------
2021-08-18 19:33:47 +02:00
void VPGraphicsPiece::on_RefreshPiece(const VPPiecePtr &piece)
2020-11-10 21:29:23 +01:00
{
2024-02-19 17:09:56 +01:00
VPPiecePtr const p = m_piece.toStrongRef();
2022-02-18 16:57:41 +01:00
if (p.isNull())
2020-11-10 21:29:23 +01:00
{
2022-02-18 16:57:41 +01:00
return;
}
if (p->GetUniqueID() == piece->GetUniqueID())
{
if (not piece.isNull())
{
setZValue(piece->ZValue());
}
2021-08-09 14:09:10 +02:00
prepareGeometryChange();
2021-08-18 19:33:47 +02:00
PaintPiece(); // refresh shapes
InitLabels();
InitGrainlineItem();
2021-08-18 19:33:47 +02:00
emit PieceTransformationChanged();
2020-11-10 21:29:23 +01:00
}
}
2022-02-18 16:57:41 +01:00
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::PieceZValueChanged(const VPPiecePtr &piece)
{
2024-02-19 17:09:56 +01:00
VPPiecePtr const p = m_piece.toStrongRef();
2022-02-18 16:57:41 +01:00
if (p.isNull() || piece.isNull())
{
return;
}
if (p->GetUniqueID() == piece->GetUniqueID())
{
setZValue(piece->ZValue());
}
}
2020-05-05 17:40:36 +02:00
//---------------------------------------------------------------------------------------------------------------------
2021-07-31 11:32:23 +02:00
auto VPGraphicsPiece::itemChange(GraphicsItemChange change, const QVariant &value) -> QVariant
2020-05-05 17:40:36 +02:00
{
2021-07-31 11:32:23 +02:00
if (scene() != nullptr)
{
2023-05-22 16:27:15 +02:00
if (change == ItemSelectedHasChanged)
2020-05-05 17:40:36 +02:00
{
2024-02-19 17:09:56 +01:00
VPPiecePtr const piece = m_piece.toStrongRef();
2021-08-18 19:33:47 +02:00
if (not piece.isNull())
{
piece->SetSelected(value.toBool());
2021-08-25 15:58:50 +02:00
2024-02-19 17:09:56 +01:00
VPLayoutPtr const layout = piece->Layout();
2021-08-25 15:58:50 +02:00
if (not layout.isNull())
{
emit layout->PieceSelectionChanged(piece);
}
2021-08-18 19:33:47 +02:00
}
2020-05-05 17:40:36 +02:00
}
}
return QGraphicsObject::itemChange(change, value);
}