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

147 lines
4.9 KiB
C
Raw Normal View History

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
2020-11-22 12:45:38 +01:00
#include <QCursor>
2023-06-21 09:24:51 +02:00
#include <QGraphicsItem>
2020-05-05 07:44:20 +02:00
2021-08-18 19:33:47 +02:00
#include "../layout/layoutdef.h"
2023-06-21 09:24:51 +02:00
#include "scenedef.h"
2020-05-05 07:44:20 +02:00
2021-08-27 17:23:27 +02:00
class VTextManager;
class VGraphicsFillItem;
2021-08-27 17:23:27 +02:00
2020-05-23 14:50:22 +02:00
class VPGraphicsPiece : public QGraphicsObject
2020-05-05 07:44:20 +02:00
{
2022-02-18 16:21:43 +01:00
Q_OBJECT // NOLINT
2023-06-21 09:24:51 +02:00
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);
2022-02-18 16:21:43 +01:00
~VPGraphicsPiece() override = default;
2021-07-31 11:32:23 +02:00
/**
* @brief GetPiece Returns the piece that corresponds to the graphics piece
* @return the piece
*/
auto GetPiece() const -> VPPiecePtr;
2021-07-31 15:00:32 +02:00
2023-06-21 09:24:51 +02:00
auto type() const -> int 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);
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);
2022-02-18 16:57:41 +01:00
void PieceZValueChanged(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
2023-06-21 09:24:51 +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;
2022-02-18 16:21:43 +01:00
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *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
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
2020-05-05 07:44:20 +02:00
private:
2022-08-08 14:25:14 +02:00
// cppcheck-suppress unknownMacro
2022-02-18 16:21:43 +01:00
Q_DISABLE_COPY_MOVE(VPGraphicsPiece) // NOLINT
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{};
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
2022-08-12 17:50:13 +02:00
bool m_allowChangeMerge{false};
2021-08-18 19:33:47 +02:00
2021-08-30 17:45:27 +02:00
QVector<QPointF> m_stickyPoints{};
QPainterPath m_stickyPath{};
2024-01-06 13:20:56 +01:00
QPainterPath m_foldLineMarkPath{};
QPainterPath m_foldLineLabelPath{};
2021-08-30 17:45:27 +02:00
bool m_hasStickyPosition{false};
qreal m_stickyTranslateX{0};
qreal m_stickyTranslateY{0};
bool m_textAsPaths{false};
2022-02-18 16:21:43 +01:00
bool m_hoverMode{false};
VGraphicsFillItem *m_grainlineItem{nullptr};
QVector<QGraphicsPathItem *> m_labelPathItems{};
QVector<QGraphicsSimpleTextItem *> m_labelTextItems{};
2024-01-06 13:20:56 +01:00
QGraphicsSimpleTextItem *m_foldLineLabelText{nullptr};
void InitLabels();
2023-06-22 17:30:43 +02:00
void InitPieceLabelSVGFont(const QVector<QPointF> &labelShape, const VTextManager &tm);
void InitPieceLabelOutlineFont(const QVector<QPointF> &labelShape, const VTextManager &tm);
void InitPieceLabel(const QVector<QPointF> &labelShape, const VTextManager &tm);
void InitGrainlineItem();
2023-06-21 09:24:51 +02:00
void PaintPiece(QPainter *painter = nullptr);
2022-08-12 17:50:13 +02:00
void PaintSeamLine(QPainter *painter, const VPPiecePtr &piece);
void PaintCuttingLine(QPainter *painter, const VPPiecePtr &piece);
void PaintInternalPaths(QPainter *painter, const VPPiecePtr &piece);
void PaintPassmarks(QPainter *painter, const VPPiecePtr &piece);
void PaintPlaceLabels(QPainter *painter, const VPPiecePtr &piece);
void PaintStickyPath(QPainter *painter);
void PaintMirrorLine(QPainter *painter, const VPPiecePtr &piece) const;
2024-01-06 13:20:56 +01:00
void PaintFoldLine(QPainter *painter, const VPPiecePtr &piece);
2021-08-09 14:09:10 +02:00
void GroupMove(const QPointF &pos);
2022-02-18 16:21:43 +01:00
auto PieceColor() const -> QColor;
2022-08-12 17:50:13 +02:00
auto NoBrush() const -> QBrush;
2020-05-05 07:44:20 +02:00
};
2020-05-23 14:50:22 +02:00
#endif // VPGRAPHICSPIECE_H