Seamly2D
Code documentation
pattern_piece_tool.h
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file pattern_piece_tool.h
3  ** @author Douglas S Caskey
4  ** @date Dec 11, 2022
5  **
6  ** @copyright
7  ** Copyright (C) 2017 - 2022 Seamly, LLC
8  ** https://github.com/fashionfreedom/seamly2d
9  **
10  ** @brief
11  ** Seamly2D is free software: you can redistribute it and/or modify
12  ** it under the terms of the GNU General Public License as published by
13  ** the Free Software Foundation, either version 3 of the License, or
14  ** (at your option) any later version.
15  **
16  ** Seamly2D is distributed in the hope that it will be useful,
17  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  ** GNU General Public License for more details.
20  **
21  ** You should have received a copy of the GNU General Public License
22  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
23  **************************************************************************/
24 
25 /************************************************************************
26  **
27  ** @file vtoolseamallowance.h
28  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
29  ** @date 6 11, 2016
30  **
31  ** @brief
32  ** @copyright
33  ** This source code is part of the Valentina project, a pattern making
34  ** program, whose allow create and modeling patterns of clothing.
35  ** Copyright (C) 2016 Valentina project
36  ** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
37  **
38  ** Valentina is free software: you can redistribute it and/or modify
39  ** it under the terms of the GNU General Public License as published by
40  ** the Free Software Foundation, either version 3 of the License, or
41  ** (at your option) any later version.
42  **
43  ** Valentina is distributed in the hope that it will be useful,
44  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
45  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46  ** GNU General Public License for more details.
47  **
48  ** You should have received a copy of the GNU General Public License
49  ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
50  **
51  *************************************************************************/
52 
53 #ifndef PATTERNPIECE_TOOL_H
54 #define PATTERNPIECE_TOOL_H
55 
56 #include <QtGlobal>
57 #include <qcompilerdetection.h>
58 #include <QObject>
59 #include <QGraphicsPathItem>
60 
61 #include "vinteractivetool.h"
62 
63 #include "../vwidgets/vtextgraphicsitem.h"
64 #include "../vwidgets/vgrainlineitem.h"
65 
66 class DialogTool;
68 
69 class PatternPieceTool : public VInteractiveTool, public QGraphicsPathItem
70 {
71  Q_OBJECT
72 public:
73  virtual ~PatternPieceTool() Q_DECL_EQ_DEFAULT;
76 
77  static PatternPieceTool *Create(quint32 id, VPiece newPiece, QString &width, VMainGraphicsScene *scene,
78  VAbstractPattern *doc, VContainer *data, const Document &parse,
79  const Source &typeCreation, const QString &blockName = QString());
80 
81  static const quint8 pieceVersion;
82  static const QString TagCSA;
83  static const QString TagRecord;
84  static const QString TagIPaths;
85  static const QString TagAnchors;
86  static const QString AttrVersion;
87  static const QString AttrForbidFlipping;
88  static const QString AttrPieceColor;
89  static const QString AttrPieceFill;
90  static const QString AttrPieceLock;
91  static const QString AttrSeamAllowance;
92  static const QString AttrHideSeamLine;
93  static const QString AttrSeamAllowanceBuiltIn;
94  static const QString AttrHeight;
95  static const QString AttrUnited;
96  static const QString AttrFont;
97  static const QString AttrTopLeftAnchor;
98  static const QString AttrBottomRightAnchor;
99  static const QString AttrCenterAnchor;
100  static const QString AttrTopAnchorPoint;
101  static const QString AttrBottomAnchorPoint;
102 
103  void Remove(bool ask);
104 
105  static void insertNodes(const QVector<VPieceNode> &nodes, quint32 pieceId, VMainGraphicsScene *scene,
107 
108  static void AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiece &piece);
109  static void AddCSARecord(VAbstractPattern *doc, QDomElement &domElement, const CustomSARecord &record);
110  static void AddCSARecords(VAbstractPattern *doc, QDomElement &domElement, const QVector<CustomSARecord> &records);
111  static void AddInternalPaths(VAbstractPattern *doc, QDomElement &domElement, const QVector<quint32> &paths);
112  static void addAnchors(VAbstractPattern *doc, QDomElement &domElement, const QVector<quint32> &anchors);
113  static void AddPatternPieceData(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
114  static void AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
115  static void AddGrainline(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece);
116 
117  void RefreshGeometry();
118 
119  virtual int type() const Q_DECL_OVERRIDE {return Type;}
120  enum { Type = UserType + static_cast<int>(Tool::Piece)};
121 
122  virtual QString getTagName() const Q_DECL_OVERRIDE;
123  virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE;
124  virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE;
125  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
126  QWidget *widget) Q_DECL_OVERRIDE;
127 
128  virtual QRectF boundingRect() const Q_DECL_OVERRIDE;
129  virtual QPainterPath shape() const Q_DECL_OVERRIDE;
130 
131 public slots:
132  virtual void FullUpdateFromFile () Q_DECL_OVERRIDE;
133  void EnableToolMove(bool move);
134  void pieceLockedChanged(quint32 id, bool lock);
135  virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE;
136  virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE;
137  virtual void ResetChildren(QGraphicsItem* pItem);
138  virtual void UpdateAll();
139  virtual void retranslateUi();
140  void Highlight(quint32 id);
141  void updatePieceDetails();
142  void UpdatePieceLabel();
143  void UpdatePatternLabel();
144  void UpdateGrainline();
145  void editPieceProperties();
146 
147 protected slots:
148  void saveMovePiece(const QPointF &ptPos);
149  void saveResizePiece(qreal dLabelW, int iFontSize);
150  void savePieceRotation(qreal dRot);
151  void SaveMovePattern(const QPointF& ptPos);
152  void SaveResizePattern(qreal dLabelW, int iFontSize);
153  void SaveRotationPattern(qreal dRot);
154  void SaveMoveGrainline(const QPointF& ptPos);
155  void SaveResizeGrainline(qreal dLength);
156  void SaveRotateGrainline(qreal dRot, const QPointF& ptPos);
157 
158 protected:
159  virtual void AddToFile () Q_DECL_OVERRIDE;
160  virtual void RefreshDataInFile() Q_DECL_OVERRIDE;
161  virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE;
162  virtual void mousePressEvent( QGraphicsSceneMouseEvent * event) Q_DECL_OVERRIDE;
163  virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE;
164  virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
165  virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
166  virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE;
167  virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE;
168  virtual void SetVisualization() Q_DECL_OVERRIDE {}
169  virtual void deleteTool(bool ask = true) Q_DECL_OVERRIDE;
170  virtual void ToolCreation(const Source &typeCreation) Q_DECL_OVERRIDE;
171  virtual void SetDialog() Q_DECL_FINAL;
172  virtual void SaveDialogChange() Q_DECL_FINAL;
173 
174 private:
175  Q_DISABLE_COPY(PatternPieceTool)
176 
177  QPainterPath m_mainPath; // Must be first to prevent crash
178  QRectF m_pieceRect;
179  QPainterPath m_cutPath;
180  VMainGraphicsScene *m_pieceScene; /** @brief pieceScene pointer to the scene. */
181  QString m_blockName;
187  QGraphicsPathItem *m_notches;
188 
189  PatternPieceTool(VAbstractPattern *doc, VContainer *data, const quint32 &id,
190  const Source &typeCreation, VMainGraphicsScene *scene,
191  const QString &blockName, QGraphicsItem * parent = nullptr);
192 
193  void UpdateExcludeState();
194  VPieceItem::MoveTypes FindLabelGeometry(const VPatternLabelData &labelData, qreal &rotationAngle, qreal &labelWidth,
195  qreal &labelHeight, QPointF &pos);
196 
197  VPieceItem::MoveTypes FindGrainlineGeometry(const VGrainlineData &geom, qreal &length, qreal &rotationAngle,
198  QPointF &pos);
199 
200  void initializeNodes(const VPiece &piece, VMainGraphicsScene *scene);
201  static void initializeNode(const VPieceNode &node, VMainGraphicsScene *scene, VContainer *data,
203 
204  void InitCSAPaths(const VPiece &piece);
205  void InitInternalPaths(const VPiece &piece);
206  void initializeAnchorPoints(const VPiece &piece);
207  bool PrepareLabelData(const VPatternLabelData &labelData, VTextGraphicsItem *labelItem,
208  QPointF &pos, qreal &labelAngle);
209 
210  void UpdateLabelItem(VTextGraphicsItem *labelItem, QPointF pos, qreal labelAngle);
211 
212  void toggleInLayout(bool checked);
213  void togglePieceLock(bool checked);
214  void toggleFlipping(bool checked);
215  void toggleSeamLine(bool checked);
216  void toggleSeamAllowance(bool checked);
217  void toggleGrainline(bool checked);
218  void togglePatternLabel(bool checked);
219  void togglePieceLabel(bool checked);
220  void renamePiece(VPiece piece);
221  void showStatus(QString toolTip);
222  void raiseItemToTop(QGraphicsItem *item);
223  void lowerItemToBottom(QGraphicsItem *item);
224 };
225 
226 #endif // PATTERNPIECE_TOOL_H
The DialogTool class parent for all dialog of tools.
Definition: dialogtool.h:107
static const QString TagCSA
virtual QString getTagName() const Q_DECL_OVERRIDE
void raiseItemToTop(QGraphicsItem *item)
static void AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
static PatternPieceTool * Create(QSharedPointer< DialogTool > dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data)
virtual void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE
static const QString AttrSeamAllowance
virtual QRectF boundingRect() const Q_DECL_OVERRIDE
static const QString AttrHideSeamLine
void saveMovePiece(const QPointF &ptPos)
saveMovePiece saves the move piece operation to the undo stack
virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE
virtual int type() const Q_DECL_OVERRIDE
void lowerItemToBottom(QGraphicsItem *item)
virtual void UpdateAll()
virtual void SaveDialogChange() Q_DECL_FINAL
QString m_blockName
pieceScene pointer to the scene.
static const QString AttrUnited
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
virtual QPainterPath shape() const Q_DECL_OVERRIDE
static void AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiece &piece)
static const QString AttrPieceColor
void InitInternalPaths(const VPiece &piece)
virtual void retranslateUi()
void pieceLockedChanged(quint32 id, bool lock)
void saveResizePiece(qreal dLabelW, int iFontSize)
saveResizePiece saves the resize piece label operation to the undo stack
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
static void AddCSARecords(VAbstractPattern *doc, QDomElement &domElement, const QVector< CustomSARecord > &records)
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE
VToolDetail::paint draws a bounding box around piece, if one of its text or grainline items is not id...
void SaveMovePattern(const QPointF &ptPos)
SaveMovePattern saves the pattern label position.
void togglePieceLock(bool checked)
togglePieceLock - routine to toggle if pattern piece is locked and editiable.
static const quint8 pieceVersion
static const QString AttrCenterAnchor
QPainterPath m_cutPath
void SaveResizeGrainline(qreal dLength)
static const QString AttrHeight
VTextGraphicsItem * m_dataLabel
void toggleInLayout(bool checked)
toggleInLayout - routine to toggle if pattern piece is included and visible in layout.
void toggleSeamAllowance(bool checked)
toggleSeamAllowance - routine to toggle the visibility of the seam allowance.
static void AddInternalPaths(VAbstractPattern *doc, QDomElement &domElement, const QVector< quint32 > &paths)
static const QString AttrBottomAnchorPoint
static const QString AttrVersion
static void AddPatternPieceData(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
static void AddGrainline(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
VMainGraphicsScene * m_pieceScene
void UpdatePieceLabel()
UpdateLabel updates the text label, making it just big enough for the text to fit it.
static const QString AttrPieceLock
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
void toggleGrainline(bool checked)
toggleGrainline - routine to toggle the visibility of the piece grainline.
void togglePieceLabel(bool checked)
togglePieceLabel - routine to toggle the visibility of the piece label.
static const QString AttrFont
VPieceItem::MoveTypes FindGrainlineGeometry(const VGrainlineData &geom, qreal &length, qreal &rotationAngle, QPointF &pos)
static const QString TagRecord
void initializeNodes(const VPiece &piece, VMainGraphicsScene *scene)
static const QString AttrTopLeftAnchor
virtual void ToolCreation(const Source &typeCreation) Q_DECL_OVERRIDE
VTextGraphicsItem * m_patternInfo
void SaveRotateGrainline(qreal dRot, const QPointF &ptPos)
virtual ~PatternPieceTool() Q_DECL_EQ_DEFAULT
VPieceItem::MoveTypes FindLabelGeometry(const VPatternLabelData &labelData, qreal &rotationAngle, qreal &labelWidth, qreal &labelHeight, QPointF &pos)
virtual void FullUpdateFromFile() Q_DECL_OVERRIDE
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) Q_DECL_OVERRIDE
virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE
virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE
void savePieceRotation(qreal dRot)
savePieceRotation saves the rotation piece label operation to the undo stack
static void AddCSARecord(VAbstractPattern *doc, QDomElement &domElement, const CustomSARecord &record)
void EnableToolMove(bool move)
QGraphicsPathItem * m_notches
static void addAnchors(VAbstractPattern *doc, QDomElement &domElement, const QVector< quint32 > &anchors)
static const QString AttrTopAnchorPoint
bool PrepareLabelData(const VPatternLabelData &labelData, VTextGraphicsItem *labelItem, QPointF &pos, qreal &labelAngle)
void InitCSAPaths(const VPiece &piece)
static void insertNodes(const QVector< VPieceNode > &nodes, quint32 pieceId, VMainGraphicsScene *scene, VContainer *data, VAbstractPattern *doc)
virtual void deleteTool(bool ask=true) Q_DECL_OVERRIDE
deleteTool full delete object form scene and file.
NonScalingFillPathItem * m_seamLine
void togglePatternLabel(bool checked)
togglePatternLabel - routine to toggle the visibility of the pattern label.
static const QString AttrSeamAllowanceBuiltIn
void UpdateGrainline()
VToolDetail::UpdateGrainline updates the grain line item.
virtual void SetDialog() Q_DECL_FINAL
static const QString TagAnchors
void UpdatePatternLabel()
UpdatePatternLabel updates the pattern info label.
static const QString TagIPaths
virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE
static const QString AttrPieceFill
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) Q_DECL_OVERRIDE
void renamePiece(VPiece piece)
renamePiece - routine to rename pattern piece.
void SaveResizePattern(qreal dLabelW, int iFontSize)
: SaveResizePattern saves the pattern label width and font size
static const QString AttrBottomRightAnchor
void editPieceProperties()
editPieceProperties - routine to edit pattern piece properties .
static const QString AttrForbidFlipping
void SaveRotationPattern(qreal dRot)
QPainterPath m_mainPath
virtual void ResetChildren(QGraphicsItem *pItem)
void SaveMoveGrainline(const QPointF &ptPos)
VGrainlineItem * m_grainLine
void UpdateLabelItem(VTextGraphicsItem *labelItem, QPointF pos, qreal labelAngle)
void toggleFlipping(bool checked)
toggleFlipping - routine to toggle forbidding flipping.
void Highlight(quint32 id)
static void initializeNode(const VPieceNode &node, VMainGraphicsScene *scene, VContainer *data, VAbstractPattern *doc, PatternPieceTool *parent)
void showStatus(QString toolTip)
NonScalingFillPathItem * m_cutLine
virtual void SetVisualization() Q_DECL_OVERRIDE
void toggleSeamLine(bool checked)
toggleSeamLine - routine to toggle the visibility of the seam line.
void initializeAnchorPoints(const VPiece &piece)
virtual void RefreshDataInFile() Q_DECL_OVERRIDE
RefreshDataInFile refresh attributes in file. If attributes don't exist create them.
virtual void AddToFile() Q_DECL_OVERRIDE
AddToFile add tag with Information about tool into file.
VAbstractPattern * doc
doc dom document container
The VContainer class container of all variables.
Definition: vcontainer.h:141
VContainer data
data container with data
Definition: vdatatool.h:84
The VGrainlineData class holds information about a grainline like position, size, rotation and visibi...
The VMainGraphicsScene class main scene.
The VPatternLabelData class holds the information about pattern info label geometry.
Definition: vpiece.h:88
The VTextGraphicsItem class. This class implements text graphics item, which can be dragged around,...
Source
Definition: def.h:106
The CustomSA struct contains record about custom seam allowanse (SA).
Definition: def.h:510
Document