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

96 lines
2.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
#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"
2020-05-23 15:42:51 +02:00
class VPPiece;
2020-05-05 07:44:20 +02:00
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-07-31 11:32:23 +02:00
explicit VPGraphicsPiece(VPPiece *piece, QGraphicsItem *parent = nullptr);
~VPGraphicsPiece() = default;
/**
* @brief GetPiece Returns the piece that corresponds to the graphics piece
* @return the piece
*/
2021-07-31 11:32:23 +02:00
auto GetPiece() -> VPPiece*;
2021-08-09 14:09:10 +02:00
void TranslatePiece(const QPointF &p);
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-09 14:09:10 +02:00
signals:
void PieceSelectionChanged();
void HideTransformationHandles(bool hide);
void PiecePositionChanged();
2020-05-09 11:13:29 +02:00
2021-08-09 14:09:10 +02:00
public slots:
void on_Rotate(const QPointF &center, qreal angle);
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
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)
2020-05-23 15:42:51 +02:00
VPPiece *m_piece;
2020-05-05 07:44:20 +02:00
2021-07-31 11:32:23 +02:00
QPainterPath m_cuttingLine{};
QPainterPath m_seamLine{};
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
void PaintPiece(QPainter *painter=nullptr);
void GroupMove(const QPointF &pos);
2020-05-05 07:44:20 +02:00
};
2020-05-23 14:50:22 +02:00
#endif // VPGRAPHICSPIECE_H