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
|
|
|
|
|
|
|
#include <QPen>
|
|
|
|
#include <QBrush>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
2020-05-05 17:40:36 +02:00
|
|
|
#include <QStyleOptionGraphicsItem>
|
2020-05-09 09:54:56 +02:00
|
|
|
#include <QGraphicsSceneContextMenuEvent>
|
|
|
|
#include <QMenu>
|
2020-05-09 14:45:36 +02:00
|
|
|
#include <QtMath>
|
|
|
|
#include <QGraphicsScene>
|
2020-11-22 12:45:38 +01:00
|
|
|
#include <QApplication>
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2021-08-09 14:09:10 +02:00
|
|
|
#include "../layout/vppiece.h"
|
|
|
|
#include "../layout/vplayout.h"
|
|
|
|
#include "../layout/vpsheet.h"
|
2020-05-05 17:40:36 +02:00
|
|
|
|
2021-08-27 17:23:27 +02:00
|
|
|
#include "../vlayout/vtextmanager.h"
|
|
|
|
|
2020-11-19 16:32:47 +01:00
|
|
|
#include "vlayoutpiecepath.h"
|
2020-11-20 17:05:56 +01:00
|
|
|
#include "vplacelabelitem.h"
|
2020-11-19 16:32:47 +01:00
|
|
|
|
2021-08-18 19:33:47 +02:00
|
|
|
#include "undocommands/vpundopiecemove.h"
|
2021-08-19 14:13:54 +02:00
|
|
|
#include "undocommands/vpundomovepieceonsheet.h"
|
2021-08-18 19:33:47 +02:00
|
|
|
|
2020-05-05 17:40:36 +02:00
|
|
|
#include <QLoggingCategory>
|
|
|
|
Q_LOGGING_CATEGORY(pGraphicsPiece, "p.graphicsPiece")
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2021-08-09 14:09:10 +02:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
constexpr qreal penWidth = 1;
|
2021-08-27 17:27:38 +02:00
|
|
|
|
|
|
|
QColor mainColor = Qt::black;
|
|
|
|
QColor errorColor = Qt::red;
|
2021-08-09 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2020-05-05 07:44:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-18 19:33:47 +02:00
|
|
|
VPGraphicsPiece::VPGraphicsPiece(const VPPiecePtr &piece, QGraphicsItem *parent) :
|
2020-05-05 17:40:36 +02:00
|
|
|
QGraphicsObject(parent),
|
2021-07-31 11:32:23 +02:00
|
|
|
m_piece(piece)
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
2020-11-22 12:45:38 +01:00
|
|
|
QPixmap cursor_pixmap = QIcon("://puzzleicon/svg/cursor_rotate.svg").pixmap(QSize(32,32));
|
|
|
|
m_rotateCursor= QCursor(cursor_pixmap, 16, 16);
|
|
|
|
|
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
|
|
|
|
2021-08-09 14:09:10 +02:00
|
|
|
PaintPiece();
|
2021-09-03 10:32:07 +02:00
|
|
|
InitLabels();
|
2020-05-05 07:44:20 +02:00
|
|
|
}
|
|
|
|
|
2020-05-08 23:49:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-18 19:33:47 +02:00
|
|
|
auto VPGraphicsPiece::GetPiece() -> VPPiecePtr
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
2021-08-25 15:58:50 +02:00
|
|
|
return m_piece.toStrongRef();
|
2020-05-08 23:49:41 +02:00
|
|
|
}
|
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
|
|
|
{
|
2021-08-18 19:47:49 +02:00
|
|
|
QPainterPath shape;
|
|
|
|
shape.addPath(m_seamLine);
|
|
|
|
shape.addPath(m_cuttingLine);
|
|
|
|
shape.addPath(m_grainline);
|
|
|
|
shape.addPath(m_internalPaths);
|
|
|
|
shape.addPath(m_passmarks);
|
|
|
|
shape.addPath(m_placeLabels);
|
2021-08-30 17:45:27 +02:00
|
|
|
shape.addPath(m_stickyPath);
|
2021-08-18 19:47:49 +02:00
|
|
|
|
2021-08-09 14:09:10 +02:00
|
|
|
constexpr qreal halfPenWidth = penWidth/2.;
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2021-08-18 19:47:49 +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
|
|
|
{
|
|
|
|
if(!m_cuttingLine.isEmpty())
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2021-08-27 17:27:38 +02:00
|
|
|
QPen pen(PieceColor(), penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
|
2020-05-05 07:44:20 +02:00
|
|
|
painter->setPen(pen);
|
2020-05-08 23:49:41 +02:00
|
|
|
|
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
|
|
|
{
|
|
|
|
//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
|
|
|
|
if((event->button() == Qt::LeftButton))
|
|
|
|
{
|
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();
|
2021-08-18 19:33:47 +02:00
|
|
|
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
|
|
|
{
|
|
|
|
//perform the default behaviour
|
|
|
|
QGraphicsItem::mouseReleaseEvent(event);
|
|
|
|
|
|
|
|
// change the cursor when clicking left button
|
2020-05-06 15:05:01 +02:00
|
|
|
if (event->button() == Qt::LeftButton)
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
2020-05-06 15:05:01 +02:00
|
|
|
setCursor(Qt::OpenHandCursor);
|
2021-08-09 14:09:10 +02:00
|
|
|
emit HideTransformationHandles(false);
|
2021-08-30 17:45:27 +02:00
|
|
|
|
|
|
|
VPPiecePtr piece = m_piece.toStrongRef();
|
|
|
|
if (not piece.isNull())
|
|
|
|
{
|
|
|
|
VPLayoutPtr layout = piece->Layout();
|
|
|
|
if (not layout.isNull())
|
|
|
|
{
|
|
|
|
if (layout->LayoutSettings().GetStickyEdges() && m_hasStickyPosition)
|
|
|
|
{
|
|
|
|
auto *command = new VPUndoPieceMove(piece, m_stickyTranslateX, m_stickyTranslateY,
|
|
|
|
allowChangeMerge);
|
|
|
|
layout->UndoStack()->push(command);
|
|
|
|
|
|
|
|
SetStickyPoints(QVector<QPointF>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-18 19:33:47 +02:00
|
|
|
allowChangeMerge = false;
|
2021-08-30 17:45:27 +02:00
|
|
|
m_hasStickyPosition = false;
|
2020-05-06 15:05:01 +02:00
|
|
|
}
|
2020-05-05 07:44:20 +02:00
|
|
|
}
|
|
|
|
|
2020-05-09 09:54:56 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:50:22 +02:00
|
|
|
void VPGraphicsPiece::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
2020-05-09 09:54:56 +02:00
|
|
|
{
|
2021-08-18 19:33:47 +02:00
|
|
|
VPPiecePtr piece = m_piece.toStrongRef();
|
|
|
|
if (piece.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2020-05-23 17:47:04 +02:00
|
|
|
|
2021-08-18 19:33:47 +02:00
|
|
|
VPLayoutPtr layout = piece->Layout();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMenu menu;
|
|
|
|
QList<VPSheetPtr> sheets = layout->GetSheets();
|
|
|
|
sheets.removeAll(piece->Sheet());
|
2020-05-23 17:47:04 +02:00
|
|
|
|
2021-07-31 15:00:32 +02:00
|
|
|
QVector<QAction*> moveToActions;
|
2020-05-09 09:54:56 +02:00
|
|
|
|
2021-07-31 15:00:32 +02:00
|
|
|
if (not sheets.isEmpty())
|
|
|
|
{
|
|
|
|
QMenu *moveMenu = menu.addMenu(tr("Move to"));
|
2020-05-09 09:54:56 +02:00
|
|
|
|
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())
|
|
|
|
{
|
|
|
|
QAction* moveToSheet = moveMenu->addAction(sheet->GetName());
|
|
|
|
moveToSheet->setData(QVariant::fromValue(sheet));
|
|
|
|
moveToActions.append(moveToSheet);
|
|
|
|
}
|
2021-07-31 15:00:32 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-09 09:54:56 +02:00
|
|
|
|
2021-07-31 15:00:32 +02:00
|
|
|
// remove from layout action
|
|
|
|
QAction *removeAction = menu.addAction(tr("Remove from Sheet"));
|
2020-05-09 09:54:56 +02:00
|
|
|
|
2021-07-31 15:00:32 +02:00
|
|
|
QAction *selectedAction = menu.exec(event->screenPos());
|
2020-05-09 09:54:56 +02:00
|
|
|
|
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
|
|
|
}
|
2020-05-09 09:54:56 +02:00
|
|
|
}
|
|
|
|
|
2021-09-03 10:32:07 +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();
|
|
|
|
|
|
|
|
VPPiecePtr 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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-09-03 10:32:07 +02:00
|
|
|
void VPGraphicsPiece::InitPieceLabel(const QVector<QPointF> &labelShape, const VTextManager &tm)
|
2021-08-27 17:23:27 +02:00
|
|
|
{
|
|
|
|
VPPiecePtr piece = m_piece.toStrongRef();
|
|
|
|
if (piece.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (labelShape.count() > 2)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
qreal dY = 0;
|
|
|
|
QColor color = PieceColor();
|
|
|
|
|
|
|
|
for (int i = 0; i < tm.GetSourceLinesCount(); ++i)
|
|
|
|
{
|
|
|
|
const TextLine& tl = tm.GetSourceLine(i);
|
|
|
|
QFont fnt = tm.GetFont();
|
|
|
|
fnt.setPixelSize(tm.GetFont().pixelSize() + tl.m_iFontSize);
|
|
|
|
fnt.setBold(tl.m_bold);
|
|
|
|
fnt.setItalic(tl.m_italic);
|
|
|
|
|
|
|
|
QFontMetrics fm(fnt);
|
|
|
|
|
2021-09-03 10:32:07 +02:00
|
|
|
if (m_textAsPaths)
|
|
|
|
{
|
|
|
|
dY += fm.height();
|
|
|
|
}
|
|
|
|
|
2021-08-27 17:23:27 +02:00
|
|
|
if (dY > dH)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString qsText = tl.m_qsText;
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
|
|
|
if (fm.horizontalAdvance(qsText) > dW)
|
|
|
|
#else
|
|
|
|
if (fm.width(qsText) > dW)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast<int>(dW));
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal dX = 0;
|
|
|
|
if (tl.m_eAlign == 0 || (tl.m_eAlign & Qt::AlignLeft) > 0)
|
|
|
|
{
|
|
|
|
dX = 0;
|
|
|
|
}
|
|
|
|
else if ((tl.m_eAlign & Qt::AlignHCenter) > 0)
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
|
|
|
dX = (dW - fm.horizontalAdvance(qsText))/2;
|
|
|
|
#else
|
|
|
|
dX = (dW - fm.width(qsText))/2;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if ((tl.m_eAlign & Qt::AlignRight) > 0)
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
|
|
|
dX = dW - fm.horizontalAdvance(qsText);
|
|
|
|
#else
|
|
|
|
dX = dW - fm.width(qsText);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up the rotation around top-left corner matrix
|
|
|
|
QTransform labelMatrix;
|
|
|
|
labelMatrix.translate(labelShape.at(0).x(), labelShape.at(0).y());
|
|
|
|
if (piece->IsMirror())
|
|
|
|
{
|
|
|
|
labelMatrix.scale(-1, 1);
|
|
|
|
labelMatrix.rotate(-angle);
|
|
|
|
labelMatrix.translate(-dW, 0);
|
|
|
|
labelMatrix.translate(dX, dY); // Each string has own position
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
labelMatrix.rotate(angle);
|
|
|
|
labelMatrix.translate(dX, dY); // Each string has own position
|
|
|
|
}
|
|
|
|
|
|
|
|
labelMatrix *= piece->GetMatrix();
|
|
|
|
|
2021-09-03 10:32:07 +02:00
|
|
|
if (m_textAsPaths)
|
2021-08-27 17:23:27 +02:00
|
|
|
{
|
2021-09-03 10:32:07 +02:00
|
|
|
QPainterPath path;
|
|
|
|
path.addText(0, - static_cast<qreal>(fm.ascent())/6., fnt, qsText);
|
|
|
|
|
|
|
|
auto* item = new QGraphicsPathItem(this);
|
|
|
|
item->setPath(path);
|
|
|
|
item->setBrush(QBrush(color));
|
|
|
|
item->setTransform(labelMatrix);
|
|
|
|
m_labelPathItems.append(item);
|
|
|
|
|
|
|
|
dY += tm.GetSpacing();
|
2021-08-27 17:23:27 +02:00
|
|
|
}
|
2021-09-03 10:32:07 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
auto* item = new QGraphicsSimpleTextItem(this);
|
|
|
|
item->setFont(fnt);
|
|
|
|
item->setText(qsText);
|
2021-09-08 10:15:01 +02:00
|
|
|
item->setBrush(QBrush(color));
|
2021-09-03 10:32:07 +02:00
|
|
|
item->setTransform(labelMatrix);
|
|
|
|
m_labelTextItems.append(item);
|
2021-08-27 17:23:27 +02:00
|
|
|
|
2021-09-03 10:32:07 +02:00
|
|
|
dY += (fm.height() + tm.GetSpacing());
|
|
|
|
}
|
2021-08-27 17:23:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2021-08-09 14:09:10 +02:00
|
|
|
QBrush noBrush(Qt::NoBrush);
|
|
|
|
QBrush selectionBrush(QColor(255,160,160,60));
|
2020-05-05 17:40:36 +02:00
|
|
|
|
2021-08-18 19:47:49 +02:00
|
|
|
m_seamLine = QPainterPath();
|
|
|
|
m_cuttingLine = QPainterPath();
|
|
|
|
m_grainline = QPainterPath();
|
|
|
|
m_internalPaths = QPainterPath();
|
|
|
|
m_passmarks = QPainterPath();
|
|
|
|
m_placeLabels = QPainterPath();
|
2021-08-30 17:45:27 +02:00
|
|
|
m_stickyPath = QPainterPath();
|
2021-08-18 19:47:49 +02:00
|
|
|
|
2021-08-18 19:33:47 +02:00
|
|
|
VPPiecePtr piece = m_piece.toStrongRef();
|
|
|
|
if (piece.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-08-09 14:09:10 +02:00
|
|
|
|
|
|
|
// initialises the seam line
|
2021-08-31 13:12:46 +02:00
|
|
|
if (not piece->IsHideMainPath() || not piece->IsSeamAllowance())
|
2021-08-09 14:09:10 +02:00
|
|
|
{
|
2021-08-31 13:12:46 +02:00
|
|
|
QVector<QPointF> seamLinePoints = piece->GetMappedContourPoints();
|
|
|
|
if(!seamLinePoints.isEmpty())
|
2021-08-09 14:09:10 +02:00
|
|
|
{
|
2021-08-31 13:12:46 +02:00
|
|
|
m_seamLine.moveTo(seamLinePoints.first());
|
|
|
|
for (int i = 1; i < seamLinePoints.size(); i++)
|
|
|
|
{
|
|
|
|
m_seamLine.lineTo(seamLinePoints.at(i));
|
|
|
|
}
|
2021-08-09 14:09:10 +02:00
|
|
|
|
2021-08-31 13:12:46 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// initiliases the cutting line
|
2021-08-31 13:12:46 +02:00
|
|
|
if (piece->IsSeamAllowance() && not piece->IsSeamAllowanceBuiltIn())
|
2021-08-09 14:09:10 +02:00
|
|
|
{
|
2021-08-31 13:12:46 +02:00
|
|
|
QVector<QPointF> cuttingLinepoints = piece->GetMappedSeamAllowancePoints();
|
|
|
|
if(!cuttingLinepoints.isEmpty())
|
2021-08-09 14:09:10 +02:00
|
|
|
{
|
2021-08-31 13:12:46 +02:00
|
|
|
m_cuttingLine.moveTo(cuttingLinepoints.first());
|
|
|
|
for (int i = 1; i < cuttingLinepoints.size(); i++)
|
|
|
|
{
|
|
|
|
m_cuttingLine.lineTo(cuttingLinepoints.at(i));
|
|
|
|
}
|
2021-08-09 14:09:10 +02:00
|
|
|
|
2021-08-31 13:12:46 +02:00
|
|
|
if (painter != nullptr)
|
|
|
|
{
|
|
|
|
painter->save();
|
|
|
|
painter->setBrush(isSelected() ? selectionBrush : noBrush);
|
|
|
|
painter->drawPath(m_cuttingLine);
|
|
|
|
painter->restore();
|
|
|
|
}
|
2021-08-09 14:09:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialises the grainline
|
2021-08-18 19:33:47 +02:00
|
|
|
if(piece->IsGrainlineEnabled())
|
2021-08-09 14:09:10 +02:00
|
|
|
{
|
2021-08-18 19:33:47 +02:00
|
|
|
QVector<QPointF> grainLinepoints = piece->GetMappedGrainline();
|
2021-08-09 14:09:10 +02:00
|
|
|
if(!grainLinepoints.isEmpty())
|
|
|
|
{
|
2021-08-18 19:47:49 +02:00
|
|
|
m_grainline.moveTo(grainLinepoints.first());
|
2021-08-09 14:09:10 +02:00
|
|
|
for (int i = 1; i < grainLinepoints.size(); i++)
|
|
|
|
{
|
2021-08-18 19:47:49 +02:00
|
|
|
m_grainline.lineTo(grainLinepoints.at(i));
|
2021-08-09 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (painter != nullptr)
|
|
|
|
{
|
|
|
|
painter->save();
|
|
|
|
// here to fill the grainlines arrow. Not wanted for mvp
|
|
|
|
// later maybe if it's configurable
|
|
|
|
// painter->setBrush(blackBrush);
|
|
|
|
|
|
|
|
painter->setBrush(noBrush);
|
2021-08-18 19:47:49 +02:00
|
|
|
painter->drawPath(m_grainline);
|
2021-08-09 14:09:10 +02:00
|
|
|
painter->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialises the internal paths
|
2021-08-18 19:33:47 +02:00
|
|
|
QVector<VLayoutPiecePath> internalPaths = piece->GetInternalPaths();
|
2021-08-09 14:09:10 +02:00
|
|
|
for (const auto& piecePath : internalPaths)
|
|
|
|
{
|
2021-08-18 19:33:47 +02:00
|
|
|
QPainterPath path = piece->GetMatrix().map(piecePath.GetPainterPath());
|
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();
|
|
|
|
}
|
2021-08-18 19:47:49 +02:00
|
|
|
m_internalPaths.addPath(path);
|
2021-08-09 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// initialises the passmarks
|
2021-08-18 19:33:47 +02:00
|
|
|
QVector<VLayoutPassmark> passmarks = piece->GetMappedPassmarks();
|
2021-08-09 14:09:10 +02:00
|
|
|
for(auto &passmark : passmarks)
|
|
|
|
{
|
|
|
|
QPainterPath passmarkPath;
|
|
|
|
for (auto &line : passmark.lines)
|
|
|
|
{
|
|
|
|
passmarkPath.moveTo(line.p1());
|
|
|
|
passmarkPath.lineTo(line.p2());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (painter != nullptr)
|
|
|
|
{
|
|
|
|
painter->save();
|
|
|
|
painter->setBrush(noBrush);
|
|
|
|
painter->drawPath(passmarkPath);
|
|
|
|
painter->restore();
|
|
|
|
}
|
2021-08-18 19:47:49 +02:00
|
|
|
|
|
|
|
m_passmarks.addPath(passmarkPath);
|
2021-08-09 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// initialises the place labels (buttons etc)
|
2021-08-18 19:33:47 +02:00
|
|
|
QVector<VLayoutPlaceLabel> placeLabels = piece->GetMappedPlaceLabels();
|
2021-08-09 14:09:10 +02:00
|
|
|
for(auto &placeLabel : placeLabels)
|
|
|
|
{
|
|
|
|
QPainterPath path = VPlaceLabelItem::LabelShapePath(placeLabel.shape);
|
|
|
|
|
|
|
|
if (painter != nullptr)
|
|
|
|
{
|
|
|
|
painter->save();
|
|
|
|
painter->setBrush(noBrush);
|
|
|
|
painter->drawPath(path);
|
|
|
|
painter->restore();
|
|
|
|
}
|
2021-08-18 19:47:49 +02:00
|
|
|
|
|
|
|
m_placeLabels.addPath(path);
|
2021-08-09 14:09:10 +02:00
|
|
|
}
|
|
|
|
|
2021-08-30 17:45:27 +02:00
|
|
|
if (not m_stickyPoints.isEmpty())
|
|
|
|
{
|
|
|
|
m_stickyPath.moveTo(m_stickyPoints.first());
|
|
|
|
for (int i = 1; i < m_stickyPoints.size(); i++)
|
|
|
|
{
|
|
|
|
m_stickyPath.lineTo(m_stickyPoints.at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (painter != nullptr)
|
|
|
|
{
|
|
|
|
painter->save();
|
|
|
|
painter->setBrush(QBrush(Qt::BDiagPattern));
|
|
|
|
|
|
|
|
QPen pen = painter->pen();
|
|
|
|
pen.setStyle(Qt::DashLine);
|
|
|
|
pen.setColor(mainColor);
|
|
|
|
painter->setPen(pen);
|
|
|
|
|
|
|
|
painter->drawPath(m_stickyPath);
|
|
|
|
painter->restore();
|
|
|
|
}
|
|
|
|
}
|
2020-05-05 17:40:36 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2021-08-25 15:58:50 +02:00
|
|
|
VPPiecePtr piece = m_piece.toStrongRef();
|
|
|
|
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
|
|
|
|
2021-08-25 15:58:50 +02:00
|
|
|
VPLayoutPtr layout = piece->Layout();
|
|
|
|
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
|
|
|
|
2021-08-25 15:58:50 +02:00
|
|
|
VPSheetPtr sheet = layout->GetFocusedSheet();
|
|
|
|
if (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
|
|
|
|
2021-08-25 15:58:50 +02:00
|
|
|
QList<VPPiecePtr> pieces = PreparePieces();
|
|
|
|
QPointF 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)
|
|
|
|
{
|
2021-08-30 17:45:27 +02:00
|
|
|
VPPiecePtr p = pieces.first();
|
|
|
|
auto *command = new VPUndoPieceMove(piece, newPos.x(), newPos.y(), allowChangeMerge);
|
2021-08-25 15:58:50 +02:00
|
|
|
layout->UndoStack()->push(command);
|
2021-08-30 17:45:27 +02:00
|
|
|
|
|
|
|
if (layout->LayoutSettings().GetStickyEdges())
|
|
|
|
{
|
|
|
|
QVector<QPointF> path;
|
|
|
|
if (not p.isNull() && p->StickyPosition(m_stickyTranslateX, m_stickyTranslateY))
|
|
|
|
{
|
|
|
|
path = p->GetMappedExternalContourPoints();
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
auto *command = new VPUndoPiecesMove(pieces, newPos.x(), newPos.y(), allowChangeMerge);
|
|
|
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-30 19:00:10 +02:00
|
|
|
auto VPGraphicsPiece::PieceColor() const -> QColor
|
2021-08-27 17:27:38 +02:00
|
|
|
{
|
|
|
|
VPPiecePtr piece = m_piece.toStrongRef();
|
|
|
|
if (piece.isNull())
|
|
|
|
{
|
|
|
|
return mainColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
VPLayoutPtr layout = piece->Layout();
|
|
|
|
if (layout.isNull())
|
|
|
|
{
|
|
|
|
return mainColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool outOfBound = false;
|
|
|
|
if (layout->LayoutSettings().GetWarningPiecesOutOfBound())
|
|
|
|
{
|
|
|
|
outOfBound = piece->OutOfBound();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool superposition = false;
|
|
|
|
if (layout->LayoutSettings().GetWarningSuperpositionOfPieces())
|
|
|
|
{
|
|
|
|
superposition = piece->HasSuperpositionWithPieces();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outOfBound || superposition)
|
|
|
|
{
|
|
|
|
return errorColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mainColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-18 19:33:47 +02:00
|
|
|
void VPGraphicsPiece::on_RefreshPiece(const VPPiecePtr &piece)
|
2020-11-10 21:29:23 +01:00
|
|
|
{
|
2021-08-18 19:33:47 +02:00
|
|
|
if (m_piece == piece)
|
2020-11-10 21:29:23 +01:00
|
|
|
{
|
2021-08-09 14:09:10 +02:00
|
|
|
prepareGeometryChange();
|
2021-08-18 19:33:47 +02:00
|
|
|
PaintPiece(); // refresh shapes
|
2021-09-03 10:32:07 +02:00
|
|
|
InitLabels();
|
2021-08-18 19:33:47 +02:00
|
|
|
emit PieceTransformationChanged();
|
2020-11-10 21:29:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2020-05-05 17:40:36 +02:00
|
|
|
if(change == ItemSelectedHasChanged)
|
|
|
|
{
|
2021-08-18 19:33:47 +02:00
|
|
|
VPPiecePtr piece = m_piece.toStrongRef();
|
|
|
|
if (not piece.isNull())
|
|
|
|
{
|
|
|
|
piece->SetSelected(value.toBool());
|
2021-08-25 15:58:50 +02:00
|
|
|
|
|
|
|
VPLayoutPtr layout = piece->Layout();
|
|
|
|
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);
|
|
|
|
}
|
2020-05-05 07:44:20 +02:00
|
|
|
|