2020-05-05 07:44:20 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
2020-05-23 14:50:22 +02:00
|
|
|
** @file vpgraphicspiece.h
|
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
|
|
|
#ifndef VPGRAPHICSPIECE_H
|
|
|
|
#define VPGRAPHICSPIECE_H
|
2020-05-05 07:44:20 +02:00
|
|
|
|
|
|
|
#include <QGraphicsItem>
|
2020-11-22 12:45:38 +01:00
|
|
|
#include <QCursor>
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2021-08-09 14:09:10 +02:00
|
|
|
#include "scenedef.h"
|
2021-08-18 19:33:47 +02:00
|
|
|
#include "../layout/layoutdef.h"
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2021-08-27 17:23:27 +02:00
|
|
|
class VTextManager;
|
|
|
|
|
2020-05-23 14:50:22 +02:00
|
|
|
class VPGraphicsPiece : public QGraphicsObject
|
2020-05-05 07:44:20 +02:00
|
|
|
{
|
2020-05-05 17:40:36 +02:00
|
|
|
Q_OBJECT
|
2020-05-05 07:44:20 +02:00
|
|
|
public:
|
2021-08-18 19:33:47 +02:00
|
|
|
explicit VPGraphicsPiece(const VPPiecePtr &piece, QGraphicsItem *parent = nullptr);
|
2021-07-31 11:32:23 +02:00
|
|
|
~VPGraphicsPiece() = default;
|
|
|
|
|
2020-05-08 23:49:41 +02:00
|
|
|
/**
|
|
|
|
* @brief GetPiece Returns the piece that corresponds to the graphics piece
|
|
|
|
* @return the piece
|
|
|
|
*/
|
2021-08-18 19:33:47 +02:00
|
|
|
auto GetPiece() -> VPPiecePtr;
|
2021-07-31 15:00:32 +02:00
|
|
|
|
2021-08-09 14:09:10 +02:00
|
|
|
virtual int type() const override {return Type;}
|
|
|
|
enum { Type = UserType + static_cast<int>(PGraphicsItem::Piece)};
|
2020-05-05 17:40:36 +02:00
|
|
|
|
2021-08-30 17:45:27 +02:00
|
|
|
void SetStickyPoints(const QVector<QPointF> &newStickyPoint);
|
|
|
|
|
2021-09-03 10:32:07 +02:00
|
|
|
void SetTextAsPaths(bool newTextAsPaths);
|
|
|
|
|
2021-08-09 14:09:10 +02:00
|
|
|
signals:
|
|
|
|
void HideTransformationHandles(bool hide);
|
2021-08-18 19:33:47 +02:00
|
|
|
void PieceTransformationChanged();
|
2020-05-09 11:13:29 +02:00
|
|
|
|
2021-08-09 14:09:10 +02:00
|
|
|
public slots:
|
2021-08-18 19:33:47 +02:00
|
|
|
void on_RefreshPiece(const VPPiecePtr &piece);
|
2020-11-10 21:29:23 +01:00
|
|
|
|
2020-05-05 07:44:20 +02:00
|
|
|
protected:
|
2021-07-31 11:32:23 +02:00
|
|
|
auto boundingRect() const -> QRectF override;
|
|
|
|
auto shape() const -> QPainterPath override;
|
2020-11-10 15:14:51 +01:00
|
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
2020-05-05 07:44:20 +02:00
|
|
|
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent * event) override;
|
2021-08-09 14:09:10 +02:00
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
2020-05-05 07:44:20 +02:00
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
|
|
|
|
2021-07-31 11:32:23 +02:00
|
|
|
auto itemChange(GraphicsItemChange change, const QVariant &value) -> QVariant override;
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2020-05-09 09:54:56 +02:00
|
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
|
|
|
|
2020-05-05 07:44:20 +02:00
|
|
|
private:
|
2020-05-23 14:50:22 +02:00
|
|
|
Q_DISABLE_COPY(VPGraphicsPiece)
|
2021-08-18 19:33:47 +02:00
|
|
|
VPPieceWeakPtr m_piece;
|
2020-05-05 07:44:20 +02:00
|
|
|
|
2021-07-31 11:32:23 +02:00
|
|
|
QPainterPath m_cuttingLine{};
|
|
|
|
QPainterPath m_seamLine{};
|
2021-08-18 19:47:49 +02:00
|
|
|
QPainterPath m_grainline{};
|
|
|
|
QPainterPath m_internalPaths{};
|
|
|
|
QPainterPath m_passmarks{};
|
|
|
|
QPainterPath m_placeLabels{};
|
2020-11-20 17:05:56 +01:00
|
|
|
|
2021-08-09 14:09:10 +02:00
|
|
|
QPointF m_moveStartPoint{};
|
2021-07-31 11:32:23 +02:00
|
|
|
QPointF m_rotationStartPoint{};
|
2020-11-22 12:45:38 +01:00
|
|
|
|
2021-07-31 11:32:23 +02:00
|
|
|
QCursor m_rotateCursor{};
|
2021-08-09 14:09:10 +02:00
|
|
|
|
2021-08-18 19:33:47 +02:00
|
|
|
bool allowChangeMerge{false};
|
|
|
|
|
2021-08-30 17:45:27 +02:00
|
|
|
QVector<QPointF> m_stickyPoints{};
|
|
|
|
QPainterPath m_stickyPath{};
|
|
|
|
|
|
|
|
bool m_hasStickyPosition{false};
|
|
|
|
qreal m_stickyTranslateX{0};
|
|
|
|
qreal m_stickyTranslateY{0};
|
|
|
|
|
2021-09-03 10:32:07 +02:00
|
|
|
bool m_textAsPaths{false};
|
|
|
|
|
|
|
|
QVector<QGraphicsPathItem *> m_labelPathItems{};
|
|
|
|
QVector<QGraphicsSimpleTextItem *> m_labelTextItems{};
|
|
|
|
|
|
|
|
void InitLabels();
|
|
|
|
void InitPieceLabel(const QVector<QPointF> &labelShape, const VTextManager &tm);
|
2021-08-09 14:09:10 +02:00
|
|
|
void PaintPiece(QPainter *painter=nullptr);
|
|
|
|
|
|
|
|
void GroupMove(const QPointF &pos);
|
2021-08-27 17:27:38 +02:00
|
|
|
|
|
|
|
QColor PieceColor() const;
|
2020-05-05 07:44:20 +02:00
|
|
|
};
|
|
|
|
|
2020-05-23 14:50:22 +02:00
|
|
|
#endif // VPGRAPHICSPIECE_H
|