Seamly2D
Code documentation
pattern_piece_tool.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file pattern_piece_tool.cpp
3  ** @author Douglas S Caskey
4  ** @date Dec 27, 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 PatternPieceTool.cpp
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 #include "pattern_piece_tool.h"
54 
55 #include "nodeDetails/vnodearc.h"
57 #include "nodeDetails/vnodepoint.h"
61 #include "../dialogs/tools/piece/pattern_piece_dialog.h"
62 #include "../ifc/xml/vpatternconverter.h"
63 #include "../vgeometry/varc.h"
64 #include "../vgeometry/vellipticalarc.h"
65 #include "../vgeometry/vcubicbezier.h"
66 #include "../vgeometry/vcubicbezierpath.h"
67 #include "../vgeometry/vpointf.h"
68 #include "../vgeometry/vspline.h"
69 #include "../vgeometry/vsplinepath.h"
70 #include "../vpatterndb/vpiecenode.h"
71 #include "../vpatterndb/vpiecepath.h"
72 #include "../vpatterndb/calculator.h"
73 #include "../vpatterndb/floatItemData/vpatternlabeldata.h"
74 #include "../vpatterndb/floatItemData/vpiecelabeldata.h"
75 #include "../vpatterndb/floatItemData/vgrainlinedata.h"
76 #include "../qmuparser/qmutokenparser.h"
77 #include "../undocommands/addpiece.h"
78 #include "../undocommands/deletepiece.h"
79 #include "../undocommands/movepiece.h"
80 #include "../undocommands/savepieceoptions.h"
81 #include "../undocommands/togglepieceinlayout.h"
82 #include "../undocommands/toggle_piecelock.h"
83 #include "../vwidgets/vabstractmainwindow.h"
84 #include "../vwidgets/vmaingraphicsview.h"
85 #include "../vwidgets/nonscalingfill_pathitem.h"
86 
87 #include <QGraphicsScene>
88 #include <QGraphicsSceneMouseEvent>
89 #include <QGraphicsView>
90 #include <QInputDialog>
91 #include <QKeyEvent>
92 #include <QMenu>
93 #include <QMessageBox>
94 #include <QPainterPathStroker>
95 
96 
97 // Current version of seam allowance tag need for backward compatibility
98 const quint8 PatternPieceTool::pieceVersion = 2;
99 
100 const QString PatternPieceTool::TagCSA = QStringLiteral("csa");
101 const QString PatternPieceTool::TagRecord = QStringLiteral("record");
102 const QString PatternPieceTool::TagIPaths = QStringLiteral("iPaths");
103 const QString PatternPieceTool::TagAnchors = QStringLiteral("anchors");
104 
105 const QString PatternPieceTool::AttrVersion = QStringLiteral("version");
106 const QString PatternPieceTool::AttrForbidFlipping = QStringLiteral("forbidFlipping");
107 const QString PatternPieceTool::AttrPieceColor = QStringLiteral("color");
108 const QString PatternPieceTool::AttrPieceFill = QStringLiteral("fill");
109 const QString PatternPieceTool::AttrPieceLock = QStringLiteral("locked");
110 const QString PatternPieceTool::AttrSeamAllowance = QStringLiteral("seamAllowance");
111 const QString PatternPieceTool::AttrHideSeamLine = QStringLiteral("hideMainPath");
112 const QString PatternPieceTool::AttrSeamAllowanceBuiltIn = QStringLiteral("seamAllowanceBuiltIn");
113 const QString PatternPieceTool::AttrHeight = QStringLiteral("height");
114 const QString PatternPieceTool::AttrUnited = QStringLiteral("united");
115 const QString PatternPieceTool::AttrFont = QStringLiteral("fontSize");
116 const QString PatternPieceTool::AttrTopLeftAnchor = QStringLiteral("topLeftAnchor");
117 const QString PatternPieceTool::AttrBottomRightAnchor = QStringLiteral("bottomRightAnchor");
118 const QString PatternPieceTool::AttrCenterAnchor = QStringLiteral("centerAnchor");
119 const QString PatternPieceTool::AttrTopAnchorPoint = QStringLiteral("topAnchor");
120 const QString PatternPieceTool::AttrBottomAnchorPoint = QStringLiteral("bottomAnchor");
121 
122 //---------------------------------------------------------------------------------------------------------------------
124  VAbstractPattern *doc, VContainer *data)
125 {
126  SCASSERT(not dialog.isNull());
127  QSharedPointer<PatternPieceDialog> dialogTool = dialog.objectCast<PatternPieceDialog>();
128  SCASSERT(not dialogTool.isNull())
129  VPiece piece = dialogTool->GetPiece();
130  QString width = piece.getSeamAllowanceWidthFormula();
131  qApp->getUndoStack()->beginMacro("add pattern piece");
132 
133  piece.GetPath().SetNodes(PrepareNodes(piece.GetPath(), scene, doc, data));
134 
135  PatternPieceTool *patternPiece = Create(0, piece, width, scene, doc, data, Document::FullParse, Source::FromGui);
136 
137  if (patternPiece != nullptr)
138  {
139  patternPiece->m_dialog = dialogTool;
140  }
141  return patternPiece;
142 }
143 
144 //---------------------------------------------------------------------------------------------------------------------
145 PatternPieceTool *PatternPieceTool::Create(quint32 id, VPiece newPiece, QString &width, VMainGraphicsScene *scene,
146  VAbstractPattern *doc, VContainer *data, const Document &parse,
147  const Source &typeCreation, const QString &blockName)
148 {
149  if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
150  {
152  width, true, tr("Current seam allowance")));
153  id = data->AddPiece(newPiece);
154  }
155  else
156  {
157  const qreal calcWidth = CheckFormula(id, width, data);
158  newPiece.setSeamAllowanceWidthFormula(width, calcWidth);
159 
161  width, true, tr("Current seam allowance")));
162 
163  data->UpdatePiece(id, newPiece);
164  if (parse != Document::FullParse)
165  {
166  doc->UpdateToolData(id, data);
167  }
168  }
169 
170  PatternPieceTool *patternPiece = nullptr;
171  if (parse == Document::FullParse)
172  {
174  patternPiece = new PatternPieceTool(doc, data, id, typeCreation, scene, blockName);
175  scene->addItem(patternPiece);
176  connect(patternPiece, &PatternPieceTool::chosenTool, scene, &VMainGraphicsScene::chosenItem);
179  connect(scene, &VMainGraphicsScene::highlightPiece, patternPiece, &PatternPieceTool::Highlight);
181 
182  VAbstractPattern::AddTool(id, patternPiece);
183  }
184  //Very important to delete it. Only this tool need this special variable.
186  return patternPiece;
187 }
188 
189 //---------------------------------------------------------------------------------------------------------------------
191 {
192  try
193  {
194  deleteTool(ask);
195  }
196  catch(const VExceptionToolWasDeleted &e)
197  {
198  Q_UNUSED(e);
199  return;//Leave this method immediately!!!
200  }
201 }
202 
203 //---------------------------------------------------------------------------------------------------------------------
204 void PatternPieceTool::insertNodes(const QVector<VPieceNode> &nodes, quint32 pieceId, VMainGraphicsScene *scene,
205  VContainer *data, VAbstractPattern *doc)
206 {
207  SCASSERT(scene != nullptr)
208  SCASSERT(data != nullptr)
209  SCASSERT(doc != nullptr)
210 
211  if (pieceId > NULL_ID && !nodes.isEmpty())
212  {
213  VPiece oldPiece;
214  try
215  {
216  oldPiece = data->GetPiece(pieceId);
217  }
218  catch (const VExceptionBadId &)
219  {
220  return;
221  }
222 
223  VPiece newPiece = oldPiece;
224 
225  for (auto node : nodes)
226  {
227  const quint32 id = PrepareNode(node, scene, doc, data);
228  if (id == NULL_ID)
229  {
230  return;
231  }
232 
233  node.SetId(id);
234  newPiece.GetPath().Append(node);
235 
236  // Seam allowance tool already initializated and can't init the node
237  PatternPieceTool *patternPiece = qobject_cast<PatternPieceTool*>(VAbstractPattern::getTool(pieceId));
238  SCASSERT(patternPiece != nullptr);
239 
240  initializeNode(node, scene, data, doc, patternPiece);
241  }
242 
243  SavePieceOptions *saveCommand = new SavePieceOptions(oldPiece, newPiece, doc, pieceId);
244  qApp->getUndoStack()->push(saveCommand);// First push then make a connect
245  data->UpdatePiece(pieceId, newPiece);// Update piece because first save will not call lite update
247  }
248 }
249 
250 //---------------------------------------------------------------------------------------------------------------------
251 void PatternPieceTool::AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiece &piece)
252 {
253  SCASSERT(doc != nullptr);
254 
255  doc->SetAttribute(domElement, VDomDocument::AttrId, id);
256  doc->SetAttribute(domElement, AttrName, piece.GetName());
257  doc->SetAttribute(domElement, AttrPieceColor, piece.getColor());
258  doc->SetAttribute(domElement, AttrPieceFill, piece.getFill());
259  doc->SetAttribute(domElement, AttrPieceLocked, piece.isLocked());
260  doc->SetAttribute(domElement, AttrVersion, QString().setNum(pieceVersion));
261  doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(piece.GetMx()));
262  doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(piece.GetMy()));
263  doc->SetAttribute(domElement, AttrInLayout, piece.isInLayout());
264  doc->SetAttribute(domElement, AttrForbidFlipping, piece.IsForbidFlipping());
265  doc->SetAttribute(domElement, AttrSeamAllowance, piece.IsSeamAllowance());
266  doc->SetAttribute(domElement, AttrHideSeamLine, piece.isHideSeamLine());
267 
268  const bool saBuiltIn = piece.IsSeamAllowanceBuiltIn();
269  if (saBuiltIn)
270  {
271  doc->SetAttribute(domElement, AttrSeamAllowanceBuiltIn, saBuiltIn);
272  }
273  else
274  { // For backward compatebility.
275  domElement.removeAttribute(AttrSeamAllowanceBuiltIn);
276  }
277 
279  doc->SetAttribute(domElement, AttrUnited, piece.IsUnited());
280 }
281 
282 //---------------------------------------------------------------------------------------------------------------------
283 void PatternPieceTool::AddCSARecord(VAbstractPattern *doc, QDomElement &domElement, const CustomSARecord &record)
284 {
285  QDomElement recordNode = doc->createElement(PatternPieceTool::TagRecord);
286 
288  doc->SetAttribute(recordNode, VAbstractPattern::AttrPath, record.path);
289  doc->SetAttribute(recordNode, VAbstractPattern::AttrEnd, record.endPoint);
291  doc->SetAttribute(recordNode, VAbstractPattern::AttrIncludeAs, static_cast<unsigned int>(record.includeType));
292 
293  domElement.appendChild(recordNode);
294 }
295 
296 //---------------------------------------------------------------------------------------------------------------------
297 void PatternPieceTool::AddCSARecords(VAbstractPattern *doc, QDomElement &domElement,
298  const QVector<CustomSARecord> &records)
299 {
300  if (records.size() > 0)
301  {
302  QDomElement csaRecordsElement = doc->createElement(PatternPieceTool::TagCSA);
303  for (int i = 0; i < records.size(); ++i)
304  {
305  AddCSARecord(doc, csaRecordsElement, records.at(i));
306  }
307  domElement.appendChild(csaRecordsElement);
308  }
309 }
310 
311 //---------------------------------------------------------------------------------------------------------------------
312 void PatternPieceTool::AddInternalPaths(VAbstractPattern *doc, QDomElement &domElement, const QVector<quint32> &paths)
313 {
314  if (paths.size() > 0)
315  {
316  QDomElement iPathsElement = doc->createElement(PatternPieceTool::TagIPaths);
317  for (int i = 0; i < paths.size(); ++i)
318  {
319  QDomElement recordNode = doc->createElement(PatternPieceTool::TagRecord);
320  doc->SetAttribute(recordNode, VAbstractPattern::AttrPath, paths.at(i));
321  iPathsElement.appendChild(recordNode);
322  }
323  domElement.appendChild(iPathsElement);
324  }
325 }
326 
327 //---------------------------------------------------------------------------------------------------------------------
328 void PatternPieceTool::addAnchors(VAbstractPattern *doc, QDomElement &domElement, const QVector<quint32> &anchors)
329 {
330  if (anchors.size() > 0)
331  {
332  QDomElement anchorsElement = doc->createElement(PatternPieceTool::TagAnchors);
333  for (int i = 0; i < anchors.size(); ++i)
334  {
335  QDomElement recordNode = doc->createElement(PatternPieceTool::TagRecord);
336  recordNode.appendChild(doc->createTextNode(QString().setNum(anchors.at(i))));
337  anchorsElement.appendChild(recordNode);
338  }
339  domElement.appendChild(anchorsElement);
340  }
341 }
342 
343 //---------------------------------------------------------------------------------------------------------------------
344 void PatternPieceTool::AddPatternPieceData(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
345 {
346  QDomElement domData = doc->createElement(VAbstractPattern::TagData);
347  const VPieceLabelData &data = piece.GetPatternPieceData();
348  doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter());
349  doc->SetAttribute(domData, VAbstractPattern::AttrAnnotation, data.GetAnnotation());
350  doc->SetAttribute(domData, VAbstractPattern::AttrOrientation, data.GetOrientation());
351  doc->SetAttribute(domData, VAbstractPattern::AttrRotationWay, data.GetRotationWay());
352  doc->SetAttribute(domData, VAbstractPattern::AttrTilt, data.GetTilt());
353  doc->SetAttribute(domData, VAbstractPattern::AttrFoldPosition, data.GetFoldPosition());
354  doc->SetAttribute(domData, VAbstractPattern::AttrQuantity, data.GetQuantity());
355  doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible());
356  doc->SetAttribute(domData, VAbstractPattern::AttrOnFold, data.IsOnFold());
357  doc->SetAttribute(domData, AttrMx, data.GetPos().x());
358  doc->SetAttribute(domData, AttrMy, data.GetPos().y());
359  doc->SetAttribute(domData, VAbstractPattern::AttrWidth, data.GetLabelWidth());
360  doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight());
361  doc->SetAttribute(domData, AttrFont, data.getFontSize());
362  doc->SetAttribute(domData, VAbstractPattern::AttrRotation, data.GetRotation());
363 
364  if (data.centerAnchorPoint() > NULL_ID)
365  {
366  doc->SetAttribute(domData, AttrCenterAnchor, data.centerAnchorPoint());
367  }
368  else
369  {
370  domData.removeAttribute(AttrCenterAnchor);
371  }
372 
373  if (data.topLeftAnchorPoint() > NULL_ID)
374  {
375  doc->SetAttribute(domData, AttrTopLeftAnchor, data.topLeftAnchorPoint());
376  }
377  else
378  {
379  domData.removeAttribute(AttrTopLeftAnchor);
380  }
381 
382  if (data.bottomRightAnchorPoint() > NULL_ID)
383  {
384  doc->SetAttribute(domData, AttrBottomRightAnchor, data.bottomRightAnchorPoint());
385  }
386  else
387  {
388  domData.removeAttribute(AttrBottomRightAnchor);
389  }
390 
391  doc->SetLabelTemplate(domData, data.GetLabelTemplate());
392 
393  domElement.appendChild(domData);
394 }
395 
396 //---------------------------------------------------------------------------------------------------------------------
397 void PatternPieceTool::AddPatternInfo(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
398 {
399  QDomElement domData = doc->createElement(VAbstractPattern::TagPatternInfo);
400  const VPatternLabelData &data = piece.GetPatternInfo();
401  doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible());
402  doc->SetAttribute(domData, AttrMx, data.GetPos().x());
403  doc->SetAttribute(domData, AttrMy, data.GetPos().y());
404  doc->SetAttribute(domData, VAbstractPattern::AttrWidth, data.GetLabelWidth());
405  doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight());
406  doc->SetAttribute(domData, AttrFont, data.getFontSize());
407  doc->SetAttribute(domData, VAbstractPattern::AttrRotation, data.GetRotation());
408 
409  if (data.centerAnchorPoint() > NULL_ID)
410  {
411  doc->SetAttribute(domData, AttrCenterAnchor, data.centerAnchorPoint());
412  }
413  else
414  {
415  domData.removeAttribute(AttrCenterAnchor);
416  }
417 
418  if (data.topLeftAnchorPoint() > NULL_ID)
419  {
420  doc->SetAttribute(domData, AttrTopLeftAnchor, data.topLeftAnchorPoint());
421  }
422  else
423  {
424  domData.removeAttribute(AttrTopLeftAnchor);
425  }
426 
427  if (data.bottomRightAnchorPoint() > NULL_ID)
428  {
429  doc->SetAttribute(domData, AttrBottomRightAnchor, data.bottomRightAnchorPoint());
430  }
431  else
432  {
433  domData.removeAttribute(AttrBottomRightAnchor);
434  }
435 
436  domElement.appendChild(domData);
437 }
438 
439 //---------------------------------------------------------------------------------------------------------------------
440 void PatternPieceTool::AddGrainline(VAbstractPattern *doc, QDomElement &domElement, const VPiece &piece)
441 {
442  // grainline
443  QDomElement domData = doc->createElement(VAbstractPattern::TagGrainline);
444  const VGrainlineData &data = piece.GetGrainlineGeometry();
445  doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible());
446  doc->SetAttribute(domData, AttrMx, data.GetPos().x());
447  doc->SetAttribute(domData, AttrMy, data.GetPos().y());
448  doc->SetAttribute(domData, AttrLength, data.GetLength());
449  doc->SetAttribute(domData, VAbstractPattern::AttrRotation, data.GetRotation());
450  doc->SetAttribute(domData, VAbstractPattern::AttrArrows, int(data.GetArrowType()));
451 
452  if (data.centerAnchorPoint() > NULL_ID)
453  {
454  doc->SetAttribute(domData, AttrCenterAnchor, data.centerAnchorPoint());
455  }
456  else
457  {
458  domData.removeAttribute(AttrCenterAnchor);
459  }
460 
461  if (data.topAnchorPoint() > NULL_ID)
462  {
463  doc->SetAttribute(domData, AttrTopAnchorPoint, data.topAnchorPoint());
464  }
465  else
466  {
467  domData.removeAttribute(AttrTopAnchorPoint);
468  }
469 
470  if (data.bottomAnchorPoint() > NULL_ID)
471  {
472  doc->SetAttribute(domData, AttrBottomAnchorPoint, data.bottomAnchorPoint());
473  }
474  else
475  {
476  domData.removeAttribute(AttrBottomAnchorPoint);
477  }
478 
479  domElement.appendChild(domData);
480 }
481 
482 //---------------------------------------------------------------------------------------------------------------------
484 {
486 }
487 
488 //---------------------------------------------------------------------------------------------------------------------
490 {
491  Q_UNUSED(show)
492 }
493 
494 //---------------------------------------------------------------------------------------------------------------------
495 void PatternPieceTool::GroupVisibility(quint32 object, bool visible)
496 {
497  Q_UNUSED(object);
498  Q_UNUSED(visible);
499 }
500 
501 //---------------------------------------------------------------------------------------------------------------------
503 {
505  RefreshGeometry();
506 }
507 
508 //---------------------------------------------------------------------------------------------------------------------
510 {
511  setFlag(QGraphicsItem::ItemIsMovable, move);
512  m_grainLine->setFlag(QGraphicsItem::ItemIsMovable, move);
513  m_dataLabel->setFlag(QGraphicsItem::ItemIsMovable, move);
514  m_patternInfo->setFlag(QGraphicsItem::ItemIsMovable, move);
515 
516  const VPiece piece = VAbstractTool::data.GetPiece(m_id);
517  for (int i = 0; i< piece.GetPath().CountNodes(); ++i)
518  {
519  const VPieceNode &node = piece.GetPath().at(i);
520  if (node.GetTypeTool() == Tool::NodePoint)
521  {
522  VNodePoint *tool = qobject_cast<VNodePoint*>(VAbstractPattern::getTool(node.GetId()));
523  SCASSERT(tool != nullptr);
524 
525  tool->EnableToolMove(move);
526  }
527  }
528 }
529 
530 //---------------------------------------------------------------------------------------------------------------------
531 void PatternPieceTool::pieceLockedChanged(quint32 id, bool lock)
532 {
533  if (m_id == id)
534  {
535  setFlag(QGraphicsItem::ItemIsMovable, lock);
536  m_grainLine->setFlag(QGraphicsItem::ItemIsMovable, lock);
537  m_dataLabel->setFlag(QGraphicsItem::ItemIsMovable, lock);
538  m_patternInfo->setFlag(QGraphicsItem::ItemIsMovable, lock);
539 
540  const VPiece piece = VAbstractTool::data.GetPiece(m_id);
541  for (int i = 0; i< piece.GetPath().CountNodes(); ++i)
542  {
543  const VPieceNode &node = piece.GetPath().at(i);
544  if (node.GetTypeTool() == Tool::NodePoint)
545  {
546  VNodePoint *tool = qobject_cast<VNodePoint*>(VAbstractPattern::getTool(node.GetId()));
547  SCASSERT(tool != nullptr);
548 
549  tool->EnableToolMove(lock);
550  }
551  }
552  }
553 }
554 //---------------------------------------------------------------------------------------------------------------------
556 {
557  setAcceptHoverEvents(enabled);
558 }
559 
560 //---------------------------------------------------------------------------------------------------------------------
562 {
563  setFlag(QGraphicsItem::ItemIsSelectable, enabled);
564 }
565 
566 //---------------------------------------------------------------------------------------------------------------------
567 void PatternPieceTool::ResetChildren(QGraphicsItem *pItem)
568 {
569  const bool selected = isSelected();
570  const VPiece piece = VAbstractTool::data.GetPiece(m_id);
571  VTextGraphicsItem *pVGI = qgraphicsitem_cast<VTextGraphicsItem*>(pItem);
572  if (pVGI != m_dataLabel)
573  {
574  if (piece.GetPatternPieceData().IsVisible())
575  {
576  m_dataLabel->Reset();
577  }
578  }
579  if (pVGI != m_patternInfo)
580  {
581  if (piece.GetPatternInfo().IsVisible())
582  {
583  m_patternInfo->Reset();
584  }
585  }
586  VGrainlineItem *pGLI = qgraphicsitem_cast<VGrainlineItem*>(pItem);
587  if (pGLI != m_grainLine)
588  {
589  if (piece.GetGrainlineGeometry().IsVisible())
590  {
591  m_grainLine->Reset();
592  }
593  }
594 
595  setSelected(selected);
596  update();
597 }
598 
599 //---------------------------------------------------------------------------------------------------------------------
601 {
602  m_pieceScene->update();
603  update();
604 }
605 
606 //---------------------------------------------------------------------------------------------------------------------
608 {
611 }
612 
613 //---------------------------------------------------------------------------------------------------------------------
615 {
616  setSelected(m_id == id);
617  RefreshGeometry();
618 }
619 
621 {
624  UpdateGrainline();
625 }
626 //---------------------------------------------------------------------------------------------------------------------
627 /**
628  * @brief UpdateLabel updates the text label, making it just big enough for the text to fit it
629  */
631 {
632 
633  const VPiece piece = VAbstractTool::data.GetPiece(m_id);
634  qDebug() << "Update Piece label: " << piece.GetName();
635  const VPieceLabelData &labelData = piece.GetPatternPieceData();
636 
637  if (labelData.IsVisible() & qApp->Settings()->showLabels())
638  {
639  QPointF pos;
640  qreal labelAngle = 0;
641 
642  if (PrepareLabelData(labelData, m_dataLabel, pos, labelAngle))
643  {
644  m_dataLabel->updateData(piece.GetName(), labelData);
645  UpdateLabelItem(m_dataLabel, pos, labelAngle);
646  }
647  }
648  else
649  {
650  m_dataLabel->hide();
651  }
652 }
653 
654 //---------------------------------------------------------------------------------------------------------------------
655 /**
656  * @brief UpdatePatternLabel updates the pattern info label
657  */
659 {
660  const VPiece piece = VAbstractTool::data.GetPiece(m_id);
661  qDebug() << "Update Pattern label: " << piece.GetName();
662  const VPatternLabelData &data = piece.GetPatternInfo();
663 
664  if (data.IsVisible() & qApp->Settings()->showLabels())
665  {
666  QPointF pos;
667  qreal labelAngle = 0;
668 
669  if (PrepareLabelData(data, m_patternInfo, pos, labelAngle))
670  {
672  UpdateLabelItem(m_patternInfo, pos, labelAngle);
673  }
674  }
675  else
676  {
677  m_patternInfo->hide();
678  }
679 }
680 
681 //---------------------------------------------------------------------------------------------------------------------
682 /**
683  * @brief VToolDetail::UpdateGrainline updates the grain line item
684  */
686 {
687  const VPiece piece = VAbstractTool::data.GetPiece(m_id);
688  const VGrainlineData &data = piece.GetGrainlineGeometry();
689 
690  qDebug()<<"Update Grainline IsVisible() = "<< data.IsVisible();
691 
692  if (data.IsVisible() & qApp->Settings()->showGrainlines())
693  {
694  QPointF pos;
695  qreal dRotation = 0;
696  qreal dLength = 0;
697 
698  const VGrainlineItem::MoveTypes type = FindGrainlineGeometry(data, dLength, dRotation, pos);
700  {
701  m_grainLine->hide();
702  return;
703  }
704 
706  m_grainLine->UpdateGeometry(pos, dRotation, ToPixel(dLength, *VDataTool::data.GetPatternUnit()),
707  data.GetArrowType());
708  m_grainLine->show();
709  }
710  else
711  {
712  m_grainLine->hide();
713  }
714 }
715 
716 //---------------------------------------------------------------------------------------------------------------------
717 /**
718  * @brief saveMovePiece saves the move piece operation to the undo stack
719  */
720 void PatternPieceTool::saveMovePiece(const QPointF &ptPos)
721 {
723  VPiece newPiece = oldPiece;
724  newPiece.GetPatternPieceData().SetPos(ptPos);
725 
726  SavePieceOptions *moveCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
727  moveCommand->setText(tr("move pattern piece label"));
729  qApp->getUndoStack()->push(moveCommand);
730 }
731 
732 //---------------------------------------------------------------------------------------------------------------------
733 /**
734  * @brief saveResizePiece saves the resize piece label operation to the undo stack
735  */
736 void PatternPieceTool::saveResizePiece(qreal dLabelW, int iFontSize)
737 {
739  VPiece newPiece = oldPiece;
740 
741  dLabelW = FromPixel(dLabelW, *VDataTool::data.GetPatternUnit());
742  newPiece.GetPatternPieceData().SetLabelWidth(QString().setNum(dLabelW));
743  const qreal height = FromPixel(m_dataLabel->boundingRect().height(), *VDataTool::data.GetPatternUnit());
744  newPiece.GetPatternPieceData().SetLabelHeight(QString().setNum(height));
745  newPiece.GetPatternPieceData().SetFontSize(iFontSize);
746 
747  SavePieceOptions *resizeCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
748  resizeCommand->setText(tr("resize pattern piece label"));
750  qApp->getUndoStack()->push(resizeCommand);
751 }
752 
753 //---------------------------------------------------------------------------------------------------------------------
754 /**
755  * @brief savePieceRotation saves the rotation piece label operation to the undo stack
756  */
758 {
760  VPiece newPiece = oldPiece;
761  newPiece.GetPatternPieceData().SetPos(m_dataLabel->pos());
763 
764  // Tranform angle to anticlockwise
765  QLineF line(0, 0, 100, 0);
766  line.setAngle(-dRot);
767  newPiece.GetPatternPieceData().SetRotation(QString().setNum(line.angle()));
768 
769  SavePieceOptions *rotateCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
770  rotateCommand->setText(tr("rotate pattern piece label"));
772  qApp->getUndoStack()->push(rotateCommand);
773 }
774 
775 
776 //---------------------------------------------------------------------------------------------------------------------
777 /**
778  * @brief SaveMovePattern saves the pattern label position
779  */
780 void PatternPieceTool::SaveMovePattern(const QPointF &ptPos)
781 {
783  VPiece newPiece = oldPiece;
784  newPiece.GetPatternInfo().SetPos(ptPos);
785 
786  SavePieceOptions *moveCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
787  moveCommand->setText(tr("move pattern info label"));
789  qApp->getUndoStack()->push(moveCommand);
790 }
791 
792 //---------------------------------------------------------------------------------------------------------------------
793 /**
794  * @brief: SaveResizePattern saves the pattern label width and font size
795  */
796 void PatternPieceTool::SaveResizePattern(qreal dLabelW, int iFontSize)
797 {
799  VPiece newPiece = oldPiece;
800 
801  dLabelW = FromPixel(dLabelW, *VDataTool::data.GetPatternUnit());
802  newPiece.GetPatternInfo().SetLabelWidth(QString().setNum(dLabelW));
803  qreal height = FromPixel(m_patternInfo->boundingRect().height(), *VDataTool::data.GetPatternUnit());
804  newPiece.GetPatternInfo().SetLabelHeight(QString().setNum(height));
805  newPiece.GetPatternInfo().SetFontSize(iFontSize);
806 
807  SavePieceOptions *resizeCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
808  resizeCommand->setText(tr("resize pattern info label"));
810  qApp->getUndoStack()->push(resizeCommand);
811 }
812 
813 //---------------------------------------------------------------------------------------------------------------------
815 {
817  VPiece newPiece = oldPiece;
818 
819  newPiece.GetPatternInfo().SetPos(m_patternInfo->pos());
821 
822  // Tranform angle to anticlockwise
823  QLineF line(0, 0, 100, 0);
824  line.setAngle(-dRot);
825  newPiece.GetPatternInfo().SetRotation(QString().setNum(line.angle()));
826 
827  SavePieceOptions *rotateCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
828  rotateCommand->setText(tr("rotate pattern info label"));
830  qApp->getUndoStack()->push(rotateCommand);
831 }
832 
833 
834 //---------------------------------------------------------------------------------------------------------------------
835 void PatternPieceTool::SaveMoveGrainline(const QPointF &ptPos)
836 {
838  VPiece newPiece = oldPiece;
839  newPiece.GetGrainlineGeometry().SetPos(ptPos);
840  qDebug() << "******* new grainline pos" << ptPos;
841 
842  SavePieceOptions *moveCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
843  moveCommand->setText(tr("move grainline"));
845  qApp->getUndoStack()->push(moveCommand);
846 }
847 
848 //---------------------------------------------------------------------------------------------------------------------
850 {
852  VPiece newPiece = oldPiece;
853 
854  dLength = FromPixel(dLength, *VDataTool::data.GetPatternUnit());
855  newPiece.GetGrainlineGeometry().SetPos(m_grainLine->pos());
856  newPiece.GetGrainlineGeometry().SetLength(QString().setNum(dLength));
857  SavePieceOptions *resizeCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
858  resizeCommand->setText(tr("resize grainline"));
860  qApp->getUndoStack()->push(resizeCommand);
861 }
862 
863 //---------------------------------------------------------------------------------------------------------------------
864 void PatternPieceTool::SaveRotateGrainline(qreal dRot, const QPointF &ptPos)
865 {
867  VPiece newPiece = oldPiece;
868 
869  newPiece.GetGrainlineGeometry().SetRotation(QString().setNum(qRadiansToDegrees(dRot)));
870  newPiece.GetGrainlineGeometry().SetPos(ptPos);
871  SavePieceOptions *rotateCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
872  rotateCommand->setText(tr("rotate grainline"));
874  qApp->getUndoStack()->push(rotateCommand);
875 }
876 
877 //---------------------------------------------------------------------------------------------------------------------
878 /**
879  * @brief VToolDetail::paint draws a bounding box around piece, if one of its text or grainline items is not idle.
880  */
881 void PatternPieceTool::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
882 {
883  QColor color;
884  QString lineType;
885  qreal lineWeight;
886 
887  //set cutline pen
888  color = QColor(qApp->Settings()->getDefaultCutColor());
889  lineType = qApp->Settings()->getDefaultCutLinetype();
890  lineWeight = ToPixel(qApp->Settings()->getDefaultCutLineweight(), Unit::Mm);
891 
892  m_cutLine->setPen(QPen(color, scaleWidth(lineWeight, sceneScale(scene())),
893  lineTypeToPenStyle(lineType), Qt::RoundCap, Qt::RoundJoin));
894  m_cutLine->setZValue(-10);
895 
896  //set seamline pen
897  const VPiece piece = VAbstractTool::data.GetPiece(m_id);
898 
899  if (qApp->Settings()->showSeamAllowances())
900  {
901  if (piece.IsSeamAllowance() && !piece.IsSeamAllowanceBuiltIn())
902  {
903  color = QColor(qApp->Settings()->getDefaultSeamColor());
904  lineType = qApp->Settings()->getDefaultSeamLinetype();
905  lineWeight = ToPixel(qApp->Settings()->getDefaultSeamLineweight(), Unit::Mm);
906  }
907  else
908  {
909  color = QColor(qApp->Settings()->getDefaultCutColor());
910  lineType = qApp->Settings()->getDefaultCutLinetype();
911  lineWeight = ToPixel(qApp->Settings()->getDefaultCutLineweight(), Unit::Mm);
912  }
913 
914  m_seamLine->setPen(QPen(color, scaleWidth(lineWeight, sceneScale(scene())),
915  lineTypeToPenStyle(lineType), Qt::RoundCap, Qt::RoundJoin));
916 
917  QBrush brush = QBrush(QColor(piece.getColor()));
918  brush.setStyle(static_cast<Qt::BrushStyle>(fills().indexOf(QRegExp(piece.getFill()))));
919  brush.setTransform(brush.transform().scale(150.0, 150.0));
920  brush.setTransform(painter->combinedTransform().inverted());
921  m_seamLine->setBrush(brush);
922  this->setBrush(brush);
923  }
924 
925  //set notches pen
926  color = QColor(qApp->Settings()->getDefaultNotchColor());
927  m_notches->setPen(QPen(color, scaleWidth(lineWeight, sceneScale(scene())),
928  Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
929 
930 
931  if ((m_dataLabel->IsIdle() == false
932  || m_patternInfo->IsIdle() == false
933  || m_grainLine->IsIdle() == false) && not isSelected())
934  {
935  setSelected(true);
936  }
937  QGraphicsPathItem::paint(painter, option, widget);
938 }
939 
940 //---------------------------------------------------------------------------------------------------------------------
942 {
943  if (m_pieceRect.isNull())
944  {
945  return QGraphicsPathItem::boundingRect();
946  }
947  else
948  {
949  return m_pieceRect;
950  }
951 }
952 
953 //---------------------------------------------------------------------------------------------------------------------
954 QPainterPath PatternPieceTool::shape() const
955 {
956  if (m_mainPath == QPainterPath() && m_cutPath == QPainterPath())
957  {
958  return QGraphicsPathItem::shape();
959  }
960  else
961  {
962  return ItemShapeFromPath(m_mainPath + m_cutPath, pen());
963  }
964 }
965 
966 //---------------------------------------------------------------------------------------------------------------------
968 {
969  const VPiece piece = VAbstractTool::data.GetPiece(m_id);
970 
971  QDomElement domElement = doc->createElement(getTagName());
972 
973  AddAttributes(doc, domElement, m_id, piece);
974  AddPatternPieceData(doc, domElement, piece);
975  AddPatternInfo(doc, domElement, piece);
976  AddGrainline(doc, domElement, piece);
977 
978  // nodes
979  AddNodes(doc, domElement, piece);
980  //custom seam allowance
981  AddCSARecords(doc, domElement, piece.GetCustomSARecords());
982  AddInternalPaths(doc, domElement, piece.GetInternalPaths());
983  addAnchors(doc, domElement, piece.getAnchors());
984 
985  AddPiece *cmd = new AddPiece(domElement, doc, piece, m_blockName);
987  qApp->getUndoStack()->push(cmd);
988 }
989 
990 //---------------------------------------------------------------------------------------------------------------------
992 {
993  QDomElement domElement = doc->elementById(m_id, getTagName());
994  if (domElement.isElement())
995  {
996  // Refresh only parts that we possibly need to update
997  {
998  // TODO. Delete if minimal supported version is 0.4.0
999  Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 0),
1000  "Time to refactor the code.");
1001 
1002  const uint version = doc->GetParametrUInt(domElement, PatternPieceTool::AttrVersion, "1");
1003  if (version == 1)
1004  {
1005  const VPiece piece = VAbstractTool::data.GetPiece(m_id);
1006 
1007  doc->SetAttribute(domElement, AttrVersion, QString().setNum(pieceVersion));
1008 
1009  doc->RemoveAllChildren(domElement);//Very important to clear before rewrite
1010  AddPatternPieceData(doc, domElement, piece);
1011  AddPatternInfo(doc, domElement, piece);
1012  AddGrainline(doc, domElement, piece);
1013  AddNodes(doc, domElement, piece);
1014  AddCSARecords(doc, domElement, piece.GetCustomSARecords());
1015  AddInternalPaths(doc, domElement, piece.GetInternalPaths());
1016  addAnchors(doc, domElement, piece.getAnchors());
1017  }
1018  }
1019  }
1020 }
1021 
1022 //---------------------------------------------------------------------------------------------------------------------
1023 QVariant PatternPieceTool::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
1024 {
1025  if (change == ItemPositionChange && scene())
1026  {
1027  // Each time we move something we call recalculation scene rect. In some cases this can cause moving
1028  // objects positions. And this cause infinite redrawing. That's why we wait the finish of saving the last move.
1029  static bool changeFinished = true;
1030  if (changeFinished)
1031  {
1032  changeFinished = false;
1033 
1034  // value - this is new position.
1035  const QPointF newPos = value.toPointF();
1036 
1037  MovePiece *cmd = new MovePiece(doc, newPos.x(), newPos.y(), m_id, scene());
1038  //connect(moveDet, &MovePiece::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
1039  qApp->getUndoStack()->push(cmd);
1040 
1041  const QList<QGraphicsView *> viewList = scene()->views();
1042  if (not viewList.isEmpty())
1043  {
1044  if (VMainGraphicsView *view = qobject_cast<VMainGraphicsView *>(viewList.at(0)))
1045  {
1046  const qreal scale = sceneScale(scene());
1047  const int xmargin = 50;
1048  const int ymargin = 50;
1049 
1050  const QRectF viewRect = VMainGraphicsView::SceneVisibleArea(view);
1051  const QRectF itemRect = mapToScene(boundingRect()|childrenBoundingRect()).boundingRect();
1052 
1053  // If item's rect is bigger than view's rect ensureVisible works very unstable.
1054  if (itemRect.height() + 2*ymargin < viewRect.height() &&
1055  itemRect.width() + 2*xmargin < viewRect.width())
1056  {
1057  view->ensureVisible(itemRect, xmargin, ymargin);
1058  }
1059  else
1060  {
1061  // Ensure visible only small rect around a cursor
1062  VMainGraphicsScene *currentScene = qobject_cast<VMainGraphicsScene *>(scene());
1063  SCASSERT(currentScene);
1064  const QPointF cursorPosition = currentScene->getScenePos();
1065  view->ensureVisible(QRectF(cursorPosition.x()-5/scale, cursorPosition.y()-5/scale,
1066  10/scale, 10/scale));
1067  }
1068  }
1069  }
1070 
1071  // Don't forget to update geometry, because first change never call full parse
1073  piece.SetMx(newPos.x());
1074  piece.SetMy(newPos.y());
1076 
1077  RefreshGeometry();
1078 
1079  changeFinished = true;
1080  }
1081  }
1082 
1083  if (change == QGraphicsItem::ItemSelectedChange)
1084  {
1085  if (value == true)
1086  {
1087  // do stuff if selected
1088  this->setFocus();
1089  }
1090  else
1091  {
1092  // do stuff if not selected
1093  }
1094  }
1095 
1096  return QGraphicsPathItem::itemChange(change, value);
1097 }
1098 
1099 //---------------------------------------------------------------------------------------------------------------------
1100 void PatternPieceTool::mousePressEvent(QGraphicsSceneMouseEvent *event)
1101 {
1102  // Special for not selectable item first need to call standard mousePressEvent then accept event
1103  QGraphicsPathItem::mousePressEvent(event);
1104 
1105  // Somehow clicking on notselectable object do not clean previous selections.
1106  if (not (flags() & ItemIsSelectable) && scene())
1107  {
1108  scene()->clearSelection();
1109  }
1110 
1111  if (flags() & QGraphicsItem::ItemIsMovable)
1112  {
1113  if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
1114  {
1116  }
1117  }
1118 
1119  if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
1120  {
1123  }
1124 
1125  event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event
1126 }
1127 
1128 //---------------------------------------------------------------------------------------------------------------------
1129 void PatternPieceTool::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
1130 {
1131  if (event->button() == Qt::LeftButton)
1132  {
1134  }
1135  QGraphicsPathItem::mouseReleaseEvent(event);
1136 }
1137 
1138 //---------------------------------------------------------------------------------------------------------------------
1139 void PatternPieceTool::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
1140 {
1141  if (flags() & QGraphicsItem::ItemIsMovable)
1142  {
1144  }
1145  QGraphicsPathItem::hoverEnterEvent(event);
1146 }
1147 
1148 //---------------------------------------------------------------------------------------------------------------------
1149 void PatternPieceTool::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
1150 {
1151  //Disable cursor-arrow-openhand
1152  if (flags() & QGraphicsItem::ItemIsMovable)
1153  {
1154  setCursor(QCursor());
1155  }
1156  QGraphicsPathItem::hoverLeaveEvent(event);
1157 }
1158 
1159 //---------------------------------------------------------------------------------------------------------------------
1160 void PatternPieceTool::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
1161 {
1163  {
1164  return;
1165  }
1166 
1168  bool lock = !piece.isLocked();
1169 
1170  QMenu menu;
1171  QAction *editProperties = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Properties") + "\tP");
1172  editProperties->setEnabled(lock);
1173 
1174  QAction *actionLockPiece = menu.addAction(tr("Lock Pattern Piece") + "\tCtrl + L");
1175  actionLockPiece->setCheckable(true);
1176  actionLockPiece->setChecked(piece.isLocked());
1177 
1178  QAction *separator = new QAction(this);
1179  separator->setSeparator(true);
1180  menu.addAction(separator);
1181 
1182  QAction *inLayoutOption = menu.addAction(tr("Include in Layout") + "\tI");
1183  inLayoutOption->setCheckable(true);
1184  inLayoutOption->setChecked(piece.isInLayout());
1185  inLayoutOption->setEnabled(lock);
1186 
1187  QAction *forbidFlipping = menu.addAction(tr("Forbid Flipping") + "\tF");
1188  forbidFlipping->setCheckable(true);
1189  forbidFlipping->setChecked(piece.IsForbidFlipping());
1190  forbidFlipping->setEnabled(lock);
1191 
1192  separator = new QAction(this);
1193  separator->setSeparator(true);
1194  menu.addAction(separator);
1195 
1196  QAction *raiseToTop = menu.addAction(tr("Raise to top") + "\tCtrl + Home");
1197  QAction *lowerToBottom = menu.addAction(tr("Lower to bottom") + "\tCtrl + End");
1198 
1199  separator = new QAction(this);
1200  separator->setSeparator(true);
1201  menu.addAction(separator);
1202 
1203  QAction *hideMainPath = menu.addAction(tr("Hide Seam Line") + "\t|");
1204  hideMainPath->setCheckable(true);
1205  hideMainPath->setChecked(piece.isHideSeamLine());
1206  hideMainPath->setEnabled(piece.IsSeamAllowance() && qApp->Settings()->showSeamAllowances());
1207 
1208  QAction *showSeamAllowance = menu.addAction(QIcon("://icon/32x32/seam_allowance.png"),
1209  tr("Show Seam Allowance") + "\tS");
1210  showSeamAllowance->setCheckable(true);
1211  showSeamAllowance->setChecked(piece.IsSeamAllowance());
1212 
1213  QAction *showGrainline = menu.addAction(QIcon("://icon/32x32/grainline.png"), tr("Show Grainline") + "\tG");
1214  showGrainline->setCheckable(true);
1215  qDebug()<<"Grainline IsVisible() = "<< piece.GetGrainlineGeometry().IsVisible();
1216  showGrainline->setChecked(piece.GetGrainlineGeometry().IsVisible());
1217 
1218  QAction *showPatternLabel = menu.addAction(QIcon("://icon/32x32/pattern_label.png"), tr("Show Pattern Label") + "\t[");
1219  showPatternLabel->setCheckable(true);
1220  showPatternLabel->setChecked(piece.GetPatternInfo().IsVisible());
1221 
1222  QAction *showPieceLabel = menu.addAction(QIcon("://icon/32x32/piece_label.png"), tr("Show Piece Label") + "\t]");
1223  showPieceLabel->setCheckable(true);
1224  showPieceLabel->setChecked(piece.GetPatternPieceData().IsVisible());
1225 
1226  separator = new QAction(this);
1227  separator->setSeparator(true);
1228  menu.addAction(separator);
1229 
1230  QAction *rename = menu.addAction(tr("Rename...") + "\tF2");
1231  rename->setEnabled(lock);
1232 
1233  QAction *deletePiece = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete") + "\tDel");
1234  _referens > 1 ? deletePiece->setEnabled(false) : deletePiece->setEnabled(true);
1235  deletePiece->setEnabled(lock);
1236 
1237  QAction *selectedAction = menu.exec(event->screenPos());
1238  if (selectedAction == editProperties)
1239  {
1241  }
1242  else if (selectedAction == actionLockPiece)
1243  {
1244  togglePieceLock(selectedAction->isChecked());
1245  }
1246  else if (selectedAction == inLayoutOption)
1247  {
1248  toggleInLayout(selectedAction->isChecked());
1249  }
1250  else if (selectedAction == forbidFlipping)
1251  {
1252  toggleFlipping(selectedAction->isChecked());
1253  }
1254  else if (selectedAction == raiseToTop)
1255  {
1256  raiseItemToTop(focusItem());
1257  }
1258  else if (selectedAction == lowerToBottom)
1259  {
1260  lowerItemToBottom(focusItem());
1261  }
1262  else if (selectedAction == hideMainPath)
1263  {
1264  toggleSeamLine(selectedAction->isChecked());
1265  }
1266  else if (selectedAction == showSeamAllowance)
1267  {
1268  toggleSeamAllowance(selectedAction->isChecked());
1269  }
1270  else if (selectedAction == showGrainline)
1271  {
1272  toggleGrainline(selectedAction->isChecked());
1273  }
1274  else if (selectedAction == showPatternLabel)
1275  {
1276  togglePatternLabel(selectedAction->isChecked());
1277  }
1278  else if (selectedAction == showPieceLabel)
1279  {
1280  togglePieceLabel(selectedAction->isChecked());
1281  }
1282  else if (selectedAction == rename)
1283  {
1284  renamePiece(piece);
1285  }
1286  else if (selectedAction == deletePiece)
1287  {
1288  try
1289  {
1290  deleteTool();
1291  }
1292  catch(const VExceptionToolWasDeleted &e)
1293  {
1294  Q_UNUSED(e);
1295  return;//Leave this method immediately!!!
1296  }
1297  return; //Leave this method immediately after call!!!
1298  }
1299 }
1300 
1301 //---------------------------------------------------------------------------------------------------------------------
1303 {
1305  switch (event->key())
1306  {
1307  case Qt::Key_Delete:
1308  if (!piece.isLocked())
1309  {
1310  try
1311  {
1312  deleteTool();
1313  }
1314  catch(const VExceptionToolWasDeleted &e)
1315  {
1316  Q_UNUSED(e);
1317  return;//Leave this method immediately!!!
1318  }
1319  }
1320  break;
1321 
1322  case Qt::Key_P:
1323  {
1324  if (!piece.isLocked())
1325  {
1327  }
1328  break;
1329  }
1330 
1331  case Qt::Key_L:
1332  {
1333  if (event->modifiers() & Qt::ControlModifier)
1334  {
1335  togglePieceLock(!piece.isLocked());
1336  }
1337  break;
1338  }
1339 
1340  case Qt::Key_I:
1341  {
1342  if (!piece.isLocked())
1343  {
1344  toggleInLayout(!piece.isInLayout());
1345  }
1346  break;
1347  }
1348 
1349  case Qt::Key_F:
1350  {
1351  if (!piece.isLocked())
1352  {
1353  toggleFlipping(!piece.IsForbidFlipping());
1354  }
1355  break;
1356  }
1357 
1358  case Qt::Key_Bar:
1359  {
1360  if (piece.IsSeamAllowance() && qApp->Settings()->showSeamAllowances())
1361  {
1362  toggleSeamLine(!piece.isHideSeamLine()); //Seam line is only valid if there is a seam allowance
1363  }
1364  break;
1365  }
1366 
1367  case Qt::Key_S:
1368  {
1370  break;
1371  }
1372 
1373  case Qt::Key_G:
1374  {
1376  break;
1377  }
1378 
1379  case Qt::Key_BracketLeft:
1380  {
1382  break;
1383  }
1384 
1385  case Qt::Key_BracketRight:
1386  {
1388  break;
1389  }
1390 
1391  case Qt::Key_F2:
1392  {
1393  if (!piece.isLocked())
1394  {
1395  renamePiece(piece);
1396  }
1397  break;
1398  }
1399  case Qt::Key_Home:
1400  {
1401  if (event->modifiers() & Qt::ControlModifier)
1402  {
1403  raiseItemToTop(focusItem());
1404  }
1405  break;
1406  }
1407  case Qt::Key_End:
1408  {
1409  if (event->modifiers() & Qt::ControlModifier)
1410  {
1411  lowerItemToBottom(focusItem());
1412  }
1413  break;
1414  }
1415  default:
1416  break;
1417  }
1418 
1419  QGraphicsPathItem::keyReleaseEvent(event);
1420 }
1421 
1422 //---------------------------------------------------------------------------------------------------------------------
1424 {
1425  SCASSERT(not m_dialog.isNull());
1427  SCASSERT(not dialogTool.isNull())
1428  dialogTool->SetPiece(VAbstractTool::data.GetPiece(m_id));
1429  dialogTool->enableApply(true);
1430 }
1431 
1432 //---------------------------------------------------------------------------------------------------------------------
1434  const Source &typeCreation, VMainGraphicsScene *scene,
1435  const QString &blockName, QGraphicsItem *parent)
1436  : VInteractiveTool(doc, data, id)
1437  , QGraphicsPathItem(parent)
1438  , m_mainPath()
1439  , m_pieceRect()
1440  , m_cutPath()
1441  , m_pieceScene(scene)
1442  , m_blockName(blockName)
1443  , m_cutLine(new NonScalingFillPathItem(this))
1444  , m_seamLine(new NonScalingFillPathItem(this))
1445  , m_dataLabel(new VTextGraphicsItem(this))
1446  , m_patternInfo(new VTextGraphicsItem(this))
1447  , m_grainLine(new VGrainlineItem(this))
1448  , m_notches(new QGraphicsPathItem(this))
1449 {
1450  VPiece piece = data->GetPiece(id);
1451  initializeNodes(piece, scene);
1452  InitCSAPaths(piece);
1453  InitInternalPaths(piece);
1454  initializeAnchorPoints(piece);
1455  EnableToolMove(!piece.isLocked());
1456  this->setFlag(QGraphicsItem::ItemIsSelectable, true);
1457  RefreshGeometry();
1458 
1459  this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
1460  this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
1461 
1464  ToolCreation(typeCreation);
1465  setAcceptHoverEvents(true);
1466 
1470 
1474 
1478 
1481 
1484 
1486 }
1487 
1488 //---------------------------------------------------------------------------------------------------------------------
1490 {
1491  const VPiece piece = VAbstractTool::data.GetPiece(m_id);
1492  for (int i = 0; i< piece.GetPath().CountNodes(); ++i)
1493  {
1494  const VPieceNode &node = piece.GetPath().at(i);
1495  if (node.GetTypeTool() == Tool::NodePoint)
1496  {
1497  VNodePoint *tool = qobject_cast<VNodePoint*>(VAbstractPattern::getTool(node.GetId()));
1498  SCASSERT(tool != nullptr);
1499 
1500  tool->SetExluded(node.isExcluded());
1501  tool->setVisible(not node.isExcluded());//Hide excluded point
1502  }
1503  }
1504 }
1505 
1506 //---------------------------------------------------------------------------------------------------------------------
1508 {
1509  this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
1510  m_cutLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
1511 
1512  const VPiece piece = VAbstractTool::data.GetPiece(m_id);
1513 
1514  QPainterPath path = piece.MainPathPath(this->getData());
1515 
1516  if (!piece.isHideSeamLine() || !piece.IsSeamAllowance() || piece.IsSeamAllowanceBuiltIn())
1517  {
1518  m_mainPath = QPainterPath();
1519  m_seamLine->setPath(m_mainPath);
1520  m_cutLine->setBrush(QBrush(QColor(qApp->Settings()->getDefaultCutColor()), Qt::Dense7Pattern));
1521  }
1522  else
1523  {
1524  m_mainPath = path; // need for returning a bounding rect when main path is not visible
1525  path = QPainterPath();
1526  m_seamLine->setPath(QPainterPath());
1527  m_cutLine->setBrush(QBrush(Qt::NoBrush)); // Disable if the main path was hidden
1528  }
1529 
1530  this->setPath(path);
1531 
1532  QVector<QPointF> seamAllowancePoints;
1533 
1534  if (piece.IsSeamAllowance())
1535  {
1536  seamAllowancePoints = piece.SeamAllowancePoints(this->getData());
1537  }
1538 
1539  m_notches->setPath(piece.getNotchesPath(this->getData(), seamAllowancePoints));
1540 
1541  if (piece.IsSeamAllowance() && !piece.IsSeamAllowanceBuiltIn() && qApp->Settings()->showSeamAllowances())
1542  {
1543  path.addPath(piece.SeamAllowancePath(seamAllowancePoints));
1544  path.setFillRule(Qt::OddEvenFill);
1545  m_cutPath = path;
1546  m_cutLine->setPath(m_cutPath);
1547  if (piece.isHideSeamLine())
1548  {
1549  m_seamLine->setPath(QPainterPath());
1550  }
1551  else
1552  {
1553  m_seamLine->setPath(m_mainPath);
1554  }
1555  }
1556  else
1557  {
1558  m_cutLine->setPath(QPainterPath());
1559  }
1560 
1561  m_pieceRect = path.boundingRect();
1562  this->setPos(piece.GetMx(), piece.GetMy());
1563  this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
1564 }
1565 
1566 //---------------------------------------------------------------------------------------------------------------------
1568 {
1569  SCASSERT(not m_dialog.isNull());
1570  PatternPieceDialog *dialogTool = qobject_cast<PatternPieceDialog*>(m_dialog.data());
1571  SCASSERT(dialogTool != nullptr);
1572  const VPiece newPiece = dialogTool->GetPiece();
1573  const VPiece oldPiece = VAbstractTool::data.GetPiece(m_id);
1574 
1575  SavePieceOptions *saveCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
1577  qApp->getUndoStack()->push(saveCommand);
1578  UpdatePieceLabel();
1579 }
1580 
1581 //---------------------------------------------------------------------------------------------------------------------
1582 VPieceItem::MoveTypes PatternPieceTool::FindLabelGeometry(const VPatternLabelData &labelData, qreal &rotationAngle,
1583  qreal &labelWidth, qreal &labelHeight, QPointF &pos)
1584 {
1585  qDebug() << "Find label Geometery";
1586  VPieceItem::MoveTypes restrictions = VPieceItem::AllModifications;
1587  try
1588  {
1589  if (not qmu::QmuTokenParser::IsSingle(labelData.GetRotation()))
1590  {
1591  restrictions &= ~ VPieceItem::IsRotatable;
1592  }
1593 
1594  Calculator cal1;
1595  rotationAngle = cal1.EvalFormula(VAbstractTool::data.DataVariables(), labelData.GetRotation());
1596  }
1597  catch(qmu::QmuParserError &e)
1598  {
1599  Q_UNUSED(e);
1600  return VPieceItem::Error;
1601  }
1602 
1603  const quint32 topLeftAnchorPoint = labelData.topLeftAnchorPoint();
1604  const quint32 bottomRightAnchorPoint = labelData.bottomRightAnchorPoint();
1605 
1606  if (topLeftAnchorPoint != NULL_ID && bottomRightAnchorPoint != NULL_ID)
1607  {
1608  try
1609  {
1610  const auto topLeftAnchorPointPoint = VAbstractTool::data.GeometricObject<VPointF>(topLeftAnchorPoint);
1611  const auto bottomRightAnchorPointPoint = VAbstractTool::data.GeometricObject<VPointF>(bottomRightAnchorPoint);
1612 
1613  const QRectF labelRect = QRectF(static_cast<QPointF>(*topLeftAnchorPointPoint),
1614  static_cast<QPointF>(*bottomRightAnchorPointPoint));
1615  labelWidth = FromPixel(qAbs(labelRect.width()), *VDataTool::data.GetPatternUnit());
1616  labelHeight = FromPixel(qAbs(labelRect.height()), *VDataTool::data.GetPatternUnit());
1617 
1618  pos = labelRect.topLeft();
1619 
1620  restrictions &= ~ VPieceItem::IsMovable;
1621  restrictions &= ~ VPieceItem::IsResizable;
1622 
1623  return restrictions;
1624  }
1625  catch(const VExceptionBadId &)
1626  {
1627  // do nothing.
1628  }
1629  }
1630 
1631  try
1632  {
1633  const bool widthIsSingle = qmu::QmuTokenParser::IsSingle(labelData.GetLabelWidth());
1634 
1635  Calculator cal1;
1636  labelWidth = cal1.EvalFormula(VAbstractTool::data.DataVariables(), labelData.GetLabelWidth());
1637  qDebug() << " Label width: " << labelWidth;
1638  qDebug() << " Label width is single: " << widthIsSingle;
1639  const bool heightIsSingle = qmu::QmuTokenParser::IsSingle(labelData.GetLabelHeight());
1640 
1641  Calculator cal2;
1642  labelHeight = cal2.EvalFormula(VAbstractTool::data.DataVariables(), labelData.GetLabelHeight());
1643  qDebug() << " Label height: " << labelHeight;
1644  qDebug() << " Label height is single: " << heightIsSingle;
1645  if (not widthIsSingle || not heightIsSingle)
1646  {
1647  restrictions &= ~ VPieceItem::IsResizable;
1648  }
1649  }
1650  catch(qmu::QmuParserError &e)
1651  {
1652  Q_UNUSED(e);
1653  return VPieceItem::Error;
1654  }
1655 
1656  const quint32 centerAnchor = labelData.centerAnchorPoint();
1657  if (centerAnchor != NULL_ID)
1658  {
1659  try
1660  {
1661  const auto centerAnchorPoint = VAbstractTool::data.GeometricObject<VPointF>(centerAnchor);
1662  qDebug() << " Anchor center point: " << centerAnchorPoint;
1663  const qreal lWidth = ToPixel(labelWidth, *VDataTool::data.GetPatternUnit());
1664  const qreal lHeight = ToPixel(labelHeight, *VDataTool::data.GetPatternUnit());
1665  qDebug() << " Label pixel width: " << lWidth;
1666  qDebug() << " Label pixel height: " << lHeight;
1667  pos = static_cast<QPointF>(*centerAnchorPoint) - QRectF(0, 0, lWidth, lHeight).center();
1668  qDebug() << " Anchor point position: " << pos;
1669  restrictions &= ~ VPieceItem::IsMovable;
1670  }
1671  catch(const VExceptionBadId &)
1672  {
1673  pos = labelData.GetPos();
1674  }
1675  }
1676  else
1677  {
1678  pos = labelData.GetPos();
1679  }
1680 
1681  return restrictions;
1682 }
1683 
1684 //---------------------------------------------------------------------------------------------------------------------
1685 VPieceItem::MoveTypes PatternPieceTool::FindGrainlineGeometry(const VGrainlineData &data, qreal &length,
1686  qreal &rotationAngle, QPointF &pos)
1687 {
1688  const quint32 topAnchorPoint = data.topAnchorPoint();
1689  const quint32 bottomAnchorPoint = data.bottomAnchorPoint();
1690 
1691  if (topAnchorPoint != NULL_ID && bottomAnchorPoint != NULL_ID)
1692  {
1693  try
1694  {
1695  const auto topAnchor_Point = VAbstractTool::data.GeometricObject<VPointF>(topAnchorPoint);
1696  const auto bottomAnchor_Point = VAbstractTool::data.GeometricObject<VPointF>(bottomAnchorPoint);
1697 
1698  QLineF grainline(static_cast<QPointF>(*bottomAnchor_Point), static_cast<QPointF>(*topAnchor_Point));
1699  length = FromPixel(grainline.length(), *VDataTool::data.GetPatternUnit());
1700  rotationAngle = grainline.angle();
1701 
1702  if (not VFuzzyComparePossibleNulls(rotationAngle, 0))
1703  {
1704  grainline.setAngle(0);
1705  }
1706 
1707  pos = grainline.p1();
1708 
1709  return VPieceItem::NotMovable;
1710  }
1711  catch(const VExceptionBadId &)
1712  {
1713  // do nothing.
1714  }
1715  }
1716 
1717  VPieceItem::MoveTypes restrictions = VPieceItem::AllModifications;
1718  try
1719  {
1720  if (not qmu::QmuTokenParser::IsSingle(data.GetRotation()))
1721  {
1722  restrictions &= ~ VPieceItem::IsRotatable;
1723  }
1724 
1725  Calculator cal1;
1726  rotationAngle = cal1.EvalFormula(VAbstractTool::data.DataVariables(), data.GetRotation());
1727 
1728  if (not qmu::QmuTokenParser::IsSingle(data.GetLength()))
1729  {
1730  restrictions &= ~ VPieceItem::IsResizable;
1731  }
1732 
1733  Calculator cal2;
1734  length = cal2.EvalFormula(VAbstractTool::data.DataVariables(), data.GetLength());
1735  }
1736  catch(qmu::QmuParserError &e)
1737  {
1738  Q_UNUSED(e);
1739  return VPieceItem::Error;
1740  }
1741 
1742  const quint32 centerAnchor = data.centerAnchorPoint();
1743  if (centerAnchor != NULL_ID)
1744  {
1745  try
1746  {
1747  const auto centerAnchorPoint = VAbstractTool::data.GeometricObject<VPointF>(centerAnchor);
1748 
1749  const qreal cLength = ToPixel(length, *VDataTool::data.GetPatternUnit());
1750  QLineF grainline(centerAnchorPoint->x(), centerAnchorPoint->y(),
1751  centerAnchorPoint->x() + cLength / 2.0, centerAnchorPoint->y());
1752 
1753  grainline.setAngle(rotationAngle);
1754  grainline = QLineF(grainline.p2(), grainline.p1());
1755  grainline.setLength(cLength);
1756 
1757  pos = grainline.p2();
1758  restrictions &= ~ VPieceItem::IsMovable;
1759  }
1760  catch(const VExceptionBadId &)
1761  {
1762  pos = data.GetPos();
1763  }
1764  }
1765  else
1766  {
1767  pos = data.GetPos();
1768  }
1769 
1770  return restrictions;
1771 }
1772 
1773 //---------------------------------------------------------------------------------------------------------------------
1775 {
1776  for (int i = 0; i< piece.GetPath().CountNodes(); ++i)
1777  {
1778  initializeNode(piece.GetPath().at(i), scene, &(VAbstractTool::data), doc, this);
1779  }
1780 }
1781 
1782 //---------------------------------------------------------------------------------------------------------------------
1784  VAbstractPattern *doc, PatternPieceTool *parent)
1785 {
1786  SCASSERT(scene != nullptr)
1787  SCASSERT(data != nullptr)
1788  SCASSERT(doc != nullptr)
1789  SCASSERT(parent != nullptr)
1790 
1791  switch (node.GetTypeTool())
1792  {
1793  case (Tool::NodePoint):
1794  {
1795  VNodePoint *tool = qobject_cast<VNodePoint*>(VAbstractPattern::getTool(node.GetId()));
1796  SCASSERT(tool != nullptr);
1797 
1798  connect(tool, &VNodePoint::chosenTool, scene, &VMainGraphicsScene::chosenItem, Qt::UniqueConnection);
1799  tool->setParentItem(parent);
1801  tool->SetExluded(node.isExcluded());
1802  tool->setVisible(not node.isExcluded());//Hide excluded point
1803  doc->IncrementReferens(node.GetId());
1804  break;
1805  }
1806  case (Tool::NodeArc):
1807  case (Tool::NodeElArc):
1808  case (Tool::NodeSpline):
1809  case (Tool::NodeSplinePath):
1810  doc->IncrementReferens(data->GetGObject(node.GetId())->getIdTool());
1811  break;
1812  default:
1813  qDebug()<<"Get wrong tool type. Ignore.";
1814  break;
1815  }
1816 }
1817 
1818 //---------------------------------------------------------------------------------------------------------------------
1820 {
1821  for (int i = 0; i < piece.GetCustomSARecords().size(); ++i)
1822  {
1823  doc->IncrementReferens(piece.GetCustomSARecords().at(i).path);
1824  }
1825 }
1826 
1827 //---------------------------------------------------------------------------------------------------------------------
1829 {
1830  const QVector<quint32> pathIds = piece.GetInternalPaths();
1831  for (int i = 0; i < pathIds.size(); ++i)
1832  {
1833  const VPiecePath path = this->getData()->GetPiecePath(pathIds.at(i));
1834  QColor color;
1835  if (path.IsCutPath())
1836  {
1837  color = QColor(qApp->Settings()->getDefaultCutoutColor());
1838  }
1839  else
1840  {
1841  color = QColor(qApp->Settings()->getDefaultInternalColor());
1842  }
1843  Qt::PenStyle lineType = path.GetPenType();
1844  qreal lineWeight = ToPixel(qApp->Settings()->getDefaultInternalLineweight(), Unit::Mm);
1845 
1846  auto *tool = qobject_cast<VToolInternalPath*>(VAbstractPattern::getTool(pathIds.at(i)));
1847  SCASSERT(tool != nullptr);
1848  tool->setParentItem(this);
1849  tool->SetParentType(ParentType::Item);
1850  tool->setPen(QPen(color, scaleWidth(lineWeight, sceneScale(scene())), lineType, Qt::RoundCap, Qt::RoundJoin));
1851  tool->show();
1852  doc->IncrementReferens(piece.GetInternalPaths().at(i));
1853  }
1854 }
1855 
1856 //---------------------------------------------------------------------------------------------------------------------
1858 {
1859  for (int i = 0; i < piece.getAnchors().size(); ++i)
1860  {
1861  doc->IncrementReferens(piece.getAnchors().at(i));
1862  }
1863 }
1864 
1865 //---------------------------------------------------------------------------------------------------------------------
1867 {
1868  QScopedPointer<DeletePiece> cmd(new DeletePiece(doc, m_id, VAbstractTool::data.GetPiece(m_id)));
1869  if (ask)
1870  {
1871  if (ConfirmDeletion() == QMessageBox::No)
1872  {
1873  return;
1874  }
1875  /* If Union tool delete piece no need emit FullParsing.*/
1877  }
1878 
1879  // If Union tool delete the piece this object will be deleted only after full parse.
1880  // Deleting inside Union could cause crash.
1881  // Because this object should be inactive from no one we disconnect all signals that may cause a crash
1882  // KEEP THIS LIST ACTUALL!!!
1883  disconnect(doc, nullptr, this, nullptr);
1884  if (QGraphicsScene *toolScene = scene())
1885  {
1886  disconnect(toolScene, nullptr, this, nullptr);
1887  }
1888  disconnect(m_dataLabel, nullptr, this, nullptr);
1889  disconnect(m_patternInfo, nullptr, this, nullptr);
1890  disconnect(m_grainLine, nullptr, this, nullptr);
1891  disconnect(m_pieceScene, nullptr, this, nullptr);
1892 
1893  hide();// User shouldn't see this object
1894 
1895  qApp->getUndoStack()->push(cmd.take());
1896 
1897  // Throw exception, this will help prevent case when we forget to immediately quit function.
1898  VExceptionToolWasDeleted e("Tool was used after deleting.");
1899  throw e;
1900 }
1901 
1902 //---------------------------------------------------------------------------------------------------------------------
1903 void PatternPieceTool::ToolCreation(const Source &typeCreation)
1904 {
1905  if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
1906  {
1907  AddToFile();
1908  if (typeCreation != Source::FromTool)
1909  {
1910  qApp->getUndoStack()->endMacro();
1911  }
1912  }
1913  else
1914  {
1916  }
1917 }
1918 
1919 //---------------------------------------------------------------------------------------------------------------------
1921  QPointF &pos, qreal &labelAngle)
1922 {
1923  SCASSERT(labelItem != nullptr)
1924 
1925  qDebug() << "Prepare Label Data";
1926 
1927  qreal labelWidth = 0;
1928  qreal labelHeight = 0;
1929  const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(labelData, labelAngle, labelWidth, labelHeight, pos);
1931  {
1932  labelItem->hide();
1933  return false;
1934  }
1935  labelItem->SetMoveType(type);
1936 
1937  QFont fnt = qApp->Settings()->getLabelFont();
1938  {
1939  const int iFS = labelData.getFontSize();
1940  qDebug() << " Label Font Size = " << iFS;
1941  iFS < MIN_FONT_SIZE ? fnt.setPixelSize(MIN_FONT_SIZE) : fnt.setPixelSize(iFS);
1942  if (iFS < MIN_FONT_SIZE)
1943  {
1944  qDebug() << " Label Font Pixel Size = " << MIN_FONT_SIZE;
1945  }
1946  else {
1947  qDebug() << " Label Font Pixel Size = " << iFS;
1948  }
1949  }
1950  labelItem->setFont(fnt);
1951  labelItem->setSize(ToPixel(labelWidth, *VDataTool::data.GetPatternUnit()),
1952  ToPixel(labelHeight, *VDataTool::data.GetPatternUnit()));
1953 
1954  return true;
1955 }
1956 
1957 //---------------------------------------------------------------------------------------------------------------------
1958 void PatternPieceTool::UpdateLabelItem(VTextGraphicsItem *labelItem, QPointF pos, qreal labelAngle)
1959 {
1960  SCASSERT(labelItem != nullptr)
1961 
1962  QRectF rectBB;
1963  rectBB.setTopLeft(pos);
1964  rectBB.setWidth(labelItem->boundingRect().width());
1965  rectBB.setHeight(labelItem->boundingRect().height());
1966  qreal dX;
1967  qreal dY;
1968  if (labelItem->isContained(rectBB, labelAngle, dX, dY) == false)
1969  {
1970  pos.setX(pos.x() + dX);
1971  pos.setY(pos.y() + dY);
1972  }
1973 
1974  labelItem->setPos(pos);
1975  labelItem->setRotation(-labelAngle);// expects clockwise direction
1976  labelItem->Update();
1977  labelItem->getTextLines() > 0 ? labelItem->show() : labelItem->hide();
1978 }
1979 
1980 /**
1981  * @brief editPieceProperties - routine to edit pattern piece properties .
1982  */
1984 {
1986  m_id, qApp->getMainWindow()));
1987  dialog->enableApply(true);
1988  m_dialog = dialog;
1989  m_dialog->setModal(true);
1992  SetDialog();
1993  m_dialog->show();
1994 }
1995 
1996 /**
1997  * @brief toggleInLayout - routine to toggle if pattern piece is included and visible in layout.
1998  * @param checked - true if piece is included.
1999  */
2001 {
2004  qApp->getUndoStack()->push(cmd);
2005 }
2006 
2007 /**
2008  * @brief togglePieceLock - routine to toggle if pattern piece is locked and editiable.
2009  * @param checked - true if piece is locked.
2010  */
2012 {
2013  TogglePieceLock *cmd = new TogglePieceLock(m_id, checked, &(VAbstractTool::data), doc);
2015  qApp->getUndoStack()->push(cmd);
2016 
2017  EnableToolMove(!checked);
2018 }
2019 
2020 /**
2021  * @brief toggleFlipping - routine to toggle forbidding flipping.
2022  * @param checked - true if flipping is forbidden.
2023  */
2025 {
2027  VPiece newPiece = oldPiece;
2028  newPiece.SetForbidFlipping(checked);
2029 
2030  SavePieceOptions *undoCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
2031  undoCommand->setText(tr("Forbid Flipping"));
2033  qApp->getUndoStack()->push(undoCommand);
2034 
2035  showStatus(tr("Forbid Flipping changed: ") + (checked ? tr("Enabled") : tr("Disabled")));
2036 }
2037 
2038 /**
2039  * @brief toggleSeamLine - routine to toggle the visibility of the seam line.
2040  * @param checked - true if seam line is visible.
2041  */
2043 {
2045  VPiece newPiece = oldPiece;
2046  newPiece.setHideSeamLine(checked);
2047 
2048  SavePieceOptions *undoCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
2049  undoCommand->setText(tr("Hide Seam Line"));
2051  qApp->getUndoStack()->push(undoCommand);
2052 
2053  showStatus(tr("Seam line visibility changed: ") + (checked ? tr("Hide") : tr("Show")));
2054 }
2055 
2056 /**
2057  * @brief toggleSeamAllowance - routine to toggle the visibility of the seam allowance.
2058  * @param checked - true if seam allowance is visible.
2059  */
2061 {
2063  VPiece newPiece = oldPiece;
2064  newPiece.SetSeamAllowance(checked);
2065 
2066  SavePieceOptions *undoCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
2067  undoCommand->setText(tr("Show seam allowance"));
2069  qApp->getUndoStack()->push(undoCommand);
2070 
2071  showStatus(tr("Seam allowance visibility changed: ") + (checked ? tr("Show") : tr("Hide")));
2072 }
2073 
2074 /**
2075  * @brief toggleGrainline - routine to toggle the visibility of the piece grainline.
2076  * @param checked - true if grainline is visible.
2077  */
2079 {
2081  VPiece newPiece = oldPiece;
2082  newPiece.GetGrainlineGeometry().SetVisible(checked);
2083 
2084  SavePieceOptions *undoCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
2085  undoCommand->setText(tr("Show grainline"));
2087  qApp->getUndoStack()->push(undoCommand);
2088 
2089  showStatus(tr("Grainline visibility changed: ") + (checked ? tr("Show") : tr("Hide")));
2090 }
2091 
2092 /**
2093  * @brief togglePatternLabel - routine to toggle the visibility of the pattern label.
2094  * @param checked - true if pattern label is visible.
2095  */
2097 {
2099  VPiece newPiece = oldPiece;
2100  newPiece.GetPatternInfo().SetVisible(checked);
2101 
2102  SavePieceOptions *undoCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
2103  undoCommand->setText(tr("Show pattern label"));
2105  qApp->getUndoStack()->push(undoCommand);
2106 
2107  showStatus(tr("Pattern label visibility changed: ") + (checked ? tr("Show") : tr("Hide")));
2108 }
2109 
2110 /**
2111  * @brief togglePieceLabel - routine to toggle the visibility of the piece label.
2112  * @param checked - true if piece label is visible.
2113  */
2115 {
2117  VPiece newPiece = oldPiece;
2118  newPiece.GetPatternPieceData().SetVisible(checked);
2119 
2120  SavePieceOptions *undoCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
2121  undoCommand->setText(tr("Show piece label"));
2123  qApp->getUndoStack()->push(undoCommand);
2124 
2125  showStatus(tr("Piece label visibility changed: ") + (checked ? tr("Show") : tr("Hide")));
2126 }
2127 
2128 //---------------------------------------------------------------------------------------------------------------------
2129 /**
2130  * @brief renamePiece - routine to rename pattern piece.
2131  */
2133 {
2134  QInputDialog *dialog = new QInputDialog(nullptr);
2135  dialog->setInputMode( QInputDialog::TextInput );
2136  dialog->setLabelText(tr("Piece name:"));
2137  dialog->setTextEchoMode(QLineEdit::Normal);
2138  dialog->setWindowTitle(tr("Rename Pattern Piece"));
2139  dialog->setWindowIcon(QIcon());
2140  dialog->setWindowFlags(dialog->windowFlags() & ~Qt::WindowContextHelpButtonHint
2141  & ~Qt::WindowMaximizeButtonHint
2142  & ~Qt::WindowMinimizeButtonHint);
2143  dialog->resize(300, 100);
2144  dialog->setTextValue(piece.GetName());
2145  QString pieceName;
2146  const bool result = dialog->exec();
2147  pieceName = dialog->textValue();
2148 
2149  if (result == true && !pieceName.isEmpty())
2150  {
2152  VPiece newPiece = oldPiece;
2153  newPiece.SetName(pieceName);
2154 
2155  SavePieceOptions *undoCommand = new SavePieceOptions(oldPiece, newPiece, doc, m_id);
2156  undoCommand->setText(tr("Rename pattern piece"));
2158  qApp->getUndoStack()->push(undoCommand);
2159 
2160  showStatus(tr("Piece renamed to: ") + pieceName);
2161  }
2162 }
2163 
2164 void PatternPieceTool::showStatus(QString toolTip)
2165 {
2166  VAbstractMainWindow *window = qobject_cast<VAbstractMainWindow *>(qApp->getMainWindow());
2167  SCASSERT(window != nullptr)
2168 
2169  window->ShowToolTip(toolTip);
2170 }
2171 
2172 
2173 void PatternPieceTool::raiseItemToTop(QGraphicsItem *item)
2174 {
2175  if (item)
2176  {
2177  m_pieceScene->removeItem(item);
2178  m_pieceScene->addItem(item);
2179  }
2180 }
2181 
2182 void PatternPieceTool::lowerItemToBottom(QGraphicsItem *item)
2183 {
2184  if (item != nullptr)
2185  {
2186  QList<QGraphicsItem *> items = m_pieceScene->items();
2187  if (!items.isEmpty())
2188  {
2189  for (int i = 0; i < items.count(); ++i)
2190  {
2191  if (items.at(i)->parentItem() == nullptr)
2192  {
2193  item->stackBefore(items.at(i));
2194  }
2195  }
2196  }
2197  }
2198 }
The Calculator class for calculation formula.
Definition: calculator.h:84
qreal EvalFormula(const QHash< QString, QSharedPointer< VInternalVariable > > *vars, const QString &formula)
eval calculate formula.
Definition: calculator.cpp:96
void DialogClosed(int result)
DialogClosed signal dialog closed.
void DialogApplied()
DialogApplied emit signal dialog apply changes.
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
PatternPieceTool(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation, VMainGraphicsScene *scene, const QString &blockName, QGraphicsItem *parent=nullptr)
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)
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
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.
void updateList(quint32 m_id)
void updateList(quint32 m_id)
void SetPos(const QPointF &ptPos)
virtual void ShowToolTip(const QString &toolTip)=0
void SetExluded(bool exluded)
void SetParentType(const ParentType &value)
void updatePieceList(quint32 id)
static const QString AttrLetter
static const QString AttrEnd
virtual void LiteParseTree(const Document &parse)=0
static const QString TagData
static const QString AttrAnnotation
static const QString AttrTilt
static const QString AttrRotation
virtual void UpdateToolData(const quint32 &id, VContainer *data)=0
static const QString AttrFoldPosition
static const QString AttrStart
static const QString AttrOnFold
virtual void IncrementReferens(quint32 id) const =0
static void AddTool(quint32 id, VDataTool *tool)
AddTool add tool to list tools.
static const QString AttrWidth
static const QString AttrPath
static const QString TagPatternInfo
static const QString AttrQuantity
static const QString AttrRotationWay
void UpdatePatternLabel()
static const QString AttrOrientation
void selectedPiece(quint32 id)
static VDataTool * getTool(quint32 id)
getTool return tool from tool list.
static const QString AttrArrows
static const QString AttrIncludeAs
static const QString AttrNodeReverse
static const QString TagPiece
static const QString TagGrainline
static const QString AttrVisible
bool IsSeamAllowanceBuiltIn() const
bool IsSeamAllowance() const
bool isHideSeamLine() const
void SetMx(qreal value)
qreal GetSAWidth() const
QString getColor() const
qreal GetMx() const
void SetForbidFlipping(bool value)
void setHideSeamLine(bool value)
void SetName(const QString &value)
void SetSeamAllowance(bool value)
QString GetName() const
qreal GetMy() const
QString getFill() const
bool IsForbidFlipping() const
void SetMy(qreal value)
static void AddNodes(VAbstractPattern *doc, QDomElement &domElement, const VPiecePath &path)
VAbstractPattern * doc
doc dom document container
static bool m_suppressContextMenu
Definition: vabstracttool.h:87
static QVector< VPieceNode > PrepareNodes(const VPiecePath &path, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data)
const VContainer * getData() const
getData return pointer to data container.
void chosenTool(quint32 id, SceneObject type)
chosenTool emit if object was clicked.
static int ConfirmDeletion()
static void AddRecord(const quint32 id, const Tool &toolType, VAbstractPattern *doc)
AddRecord add record about tool in history.
static const QStringList fills()
static qreal CheckFormula(const quint32 &toolId, QString &formula, VContainer *data)
CheckFormula check formula.
const quint32 m_id
id object id.
static quint32 PrepareNode(const VPieceNode &node, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data)
The VContainer class container of all variables.
Definition: vcontainer.h:141
void AddVariable(const QString &name, T *var)
Definition: vcontainer.h:327
void UpdatePiece(quint32 id, const VPiece &piece)
Definition: vcontainer.cpp:510
void RemoveVariable(const QString &name)
Definition: vcontainer.cpp:481
const QSharedPointer< VGObject > GetGObject(quint32 id) const
GetGObject returns a point by id.
Definition: vcontainer.cpp:150
quint32 AddPiece(const VPiece &piece)
Definition: vcontainer.cpp:225
const QSharedPointer< T > GeometricObject(const quint32 &id) const
Definition: vcontainer.h:266
VPiecePath GetPiecePath(quint32 id) const
Definition: vcontainer.cpp:198
const Unit * GetPatternUnit() const
Definition: vcontainer.cpp:599
VPiece GetPiece(quint32 id) const
Definition: vcontainer.cpp:185
quint32 _referens
_referens keep count tools what use this tool. If value more than 1 you can't delete tool.
Definition: vdatatool.h:87
VContainer data
data container with data
Definition: vdatatool.h:84
QDomElement elementById(quint32 id, const QString &tagName=QString())
void SetLabelTemplate(QDomElement &element, const QVector< VLabelTemplateLine > &lines)
static quint32 GetParametrUInt(const QDomElement &domElement, const QString &name, const QString &defValue)
Returns the long long value of the given attribute. RENAME: GetParameterLongLong?
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const
SetAttribute set attribute in pattern file. Replace "," by ".".
Definition: vdomdocument.h:185
static const QString AttrId
Definition: vdomdocument.h:108
static void RemoveAllChildren(QDomElement &domElement)
RemoveAllChildren remove all children from file.
The VExceptionBadId class for exception bad id.
The VGrainlineData class holds information about a grainline like position, size, rotation and visibi...
void SetRotation(const QString &qsRot)
void SetLength(const QString &qsLen)
void itemResized(qreal dLength)
void UpdateGeometry(const QPointF &ptPos, qreal dRotation, qreal dLength, ArrowType eAT)
VGrainlineItem::UpdateGeometry updates the item with grainline parameters.
void itemRotated(qreal dRot, const QPointF &ptNewPos)
The VIncrement class keep data row of increment table.
Definition: vincrement.h:70
void FullUpdateFromGuiApply()
FullUpdateFromGuiApply refresh tool data after change in options but do not delete dialog.
QSharedPointer< DialogTool > m_dialog
m_dialog tool's dialog options.
void FullUpdateFromGuiOk(int result)
FullUpdateFromGuiOk refresh tool data after change in options.
The VMainGraphicsScene class main scene.
void chosenItem(quint32 id, const SceneObject &type)
chosenItem emit ChosenObject signal.
QPointF getScenePos() const
void ItemClicked(QGraphicsItem *pItem)
void EnableDetailItemHover(bool enabled)
void EnableDetailItemSelection(bool enabled)
void EnableToolMove(bool move)
void pieceLockedChanged(quint32 id, bool lock)
void highlightPiece(quint32 id)
The VMainGraphicsView class main scene view.
static QRectF SceneVisibleArea(QGraphicsView *view)
The VNodePoint class point detail node.
Definition: vnodepoint.h:73
void EnableToolMove(bool move)
Definition: vnodepoint.cpp:346
static Q_DECL_CONSTEXPR const int PatternMinVer
The VPatternLabelData class holds the information about pattern info label geometry.
void SetLabelHeight(const QString &dLabelH)
void SetFontSize(int iSize)
quint32 centerAnchorPoint() const
void SetRotation(const QString &dRot)
quint32 topLeftAnchorPoint() const
QString GetLabelWidth() const
void SetLabelWidth(const QString &dLabelW)
QString GetRotation() const
quint32 bottomRightAnchorPoint() const
QString GetLabelHeight() const
@ AllModifications
Definition: vpieceitem.h:70
bool IsIdle() const
IsIdle returns the idle flag.
Definition: vpieceitem.cpp:107
virtual QRectF boundingRect() const Q_DECL_OVERRIDE
boundingRect returns the item bounding box
Definition: vpieceitem.cpp:81
void itemMoved(const QPointF &ptPos)
void Reset()
Reset resets the item, putting the mode and z coordinate to normal and redraws it.
Definition: vpieceitem.cpp:90
void SetMoveType(const VPieceItem::MoveTypes &moveType)
Definition: vpieceitem.cpp:140
The VPieceLabelData class holds some information about a single piece like letter,...
Tool GetTypeTool() const
Definition: vpiecenode.cpp:161
quint32 GetId() const
Definition: vpiecenode.cpp:149
bool isExcluded() const
Definition: vpiecenode.cpp:411
void Append(const VPieceNode &node)
Definition: vpiecepath.cpp:197
Qt::PenStyle GetPenType() const
Definition: vpiecepath.cpp:263
const VPieceNode & at(int indx) const
Definition: vpiecepath.cpp:221
bool IsCutPath() const
Definition: vpiecepath.cpp:275
Definition: vpiece.h:88
QPainterPath SeamAllowancePath(const VContainer *data) const
Definition: vpiece.cpp:323
VPieceLabelData & GetPatternPieceData()
Returns full access to the pattern piece data object.
Definition: vpiece.cpp:532
QVector< CustomSARecord > GetCustomSARecords() const
Definition: vpiece.cpp:444
QString getSeamAllowanceWidthFormula() const
Definition: vpiece.cpp:412
QPainterPath getNotchesPath(const VContainer *data, const QVector< QPointF > &seamAllowance=QVector< QPointF >()) const
Definition: vpiece.cpp:352
bool isInLayout() const
Definition: vpiece.cpp:376
QVector< quint32 > GetInternalPaths() const
Definition: vpiece.cpp:426
QVector< quint32 > getAnchors() const
Definition: vpiece.cpp:462
QVector< QPointF > SeamAllowancePoints(const VContainer *data) const
Definition: vpiece.cpp:188
QPainterPath MainPathPath(const VContainer *data) const
Definition: vpiece.cpp:303
void setSeamAllowanceWidthFormula(const QString &formula, qreal value)
Definition: vpiece.cpp:418
bool IsUnited() const
Definition: vpiece.cpp:400
VGrainlineData & GetGrainlineGeometry()
VDetail::GetGrainlineGeometry full access to the grainline geometry object.
Definition: vpiece.cpp:578
VPatternLabelData & GetPatternInfo()
Returns full access to the pattern info geometry object.
Definition: vpiece.cpp:558
bool isLocked() const
Definition: vpiece.cpp:388
VPiecePath GetPath() const
Definition: vpiece.cpp:156
The VPointF class keep data of point.
Definition: vpointf.h:75
The VTextGraphicsItem class. This class implements text graphics item, which can be dragged around,...
void itemRotated(qreal angle)
void itemResized(qreal width, int fontSize)
int getFontSize() const
VTextGraphicsItem::getFontSize returns the currentextLiney used text base font size.
int getTextLines() const
VTextGraphicsItem::getTextLines returns the number of lines of text to show.
void updateData(const QString &name, const VPieceLabelData &data)
VTextGraphicsItem::updateData Updates the detail label.
void setFont(const QFont &font)
VTextGraphicsItem::SetFont sets the item font.
void setSize(qreal width, qreal height)
VTextGraphicsItem::setSize Tries to set the label size to (width, height). If either of those is too ...
virtual void Update() Q_DECL_OVERRIDE
VTextGraphicsItem::Update sets the correct size and font size and redraws the label.
bool isContained(QRectF rectBB, qreal rotation, qreal &xPos, qreal &yPos) const
VTextGraphicsItem::isContained checks if the bounding box around rotated rectBB is contained in the p...
void NeedFullParsing()
void NeedLiteParsing(const Document &parse)
Error class of the parser.
static bool IsSingle(const QString &formula)
IsSingle test formula and return true if it contain only one number.
const QString cursorArrowOpenHand
Definition: def.cpp:191
double ToPixel(double val, const Unit &unit)
Definition: def.cpp:231
void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int hotX, int hotY)
Definition: def.cpp:206
const QString cursorArrowCloseHand
Definition: def.cpp:192
double FromPixel(double pix, const Unit &unit)
Definition: def.cpp:250
#define SCASSERT(cond)
Definition: def.h:317
static Q_REQUIRED_RESULT bool VFuzzyComparePossibleNulls(double p1, double p2)
Definition: def.h:490
@ NodeSplinePath
@ NodeSpline
@ NodeElArc
@ NodeArc
@ NodePoint
Source
Definition: def.h:106
qreal sceneScale(QGraphicsScene *scene)
Definition: global.cpp:63
QPainterPath ItemShapeFromPath(const QPainterPath &path, const QPen &pen)
Definition: global.cpp:140
qreal scaleWidth(qreal width, qreal scale)
Definition: global.cpp:130
const QString AttrName
Definition: ifcdef.cpp:76
const QString AttrLength
Definition: ifcdef.cpp:94
const QString AttrMx
Definition: ifcdef.cpp:74
const QString currentSeamAllowance
Definition: ifcdef.cpp:442
const QString AttrPieceLocked
Definition: ifcdef.cpp:150
const QString AttrInLayout
Definition: ifcdef.cpp:149
const QString AttrMy
Definition: ifcdef.cpp:75
Qt::PenStyle lineTypeToPenStyle(const QString &lineType)
LineStyle return pen style for current line style.
Definition: ifcdef.cpp:183
#define NULL_ID
Definition: ifcdef.h:76
The CustomSA struct contains record about custom seam allowanse (SA).
Definition: def.h:510
quint32 endPoint
Definition: def.h:521
quint32 path
Definition: def.h:520
quint32 startPoint
Definition: def.h:519
bool reverse
Definition: def.h:522
PiecePathIncludeType includeType
Definition: def.h:523
#define CONVERTER_VERSION_CHECK(major, minor, patch)
Document
#define qApp
Definition: vapplication.h:67
#define MIN_FONT_SIZE
Definition: vtextmanager.h:44