From af3735ea23c8ed93bd269e91ddea752d2136d790 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 10 Mar 2017 16:22:19 +0200 Subject: [PATCH] Grainline now can be controlled by center pin point. --HG-- branch : feature --- .../dialogs/tools/dialogseamallowance.cpp | 1 + .../dialogs/tools/dialogseamallowance.ui | 9 ++ src/libs/vtools/tools/vtoolseamallowance.cpp | 65 +++++---- src/libs/vtools/tools/vtoolseamallowance.h | 8 +- src/libs/vwidgets/vgrainlineitem.cpp | 137 ++++++++++++------ src/libs/vwidgets/vgrainlineitem.h | 4 + src/libs/vwidgets/vpieceitem.cpp | 4 +- src/libs/vwidgets/vpieceitem.h | 27 +++- src/libs/vwidgets/vtextgraphicsitem.cpp | 4 +- 9 files changed, 176 insertions(+), 83 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 08c66d379..8265dab82 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -1907,6 +1907,7 @@ void DialogSeamAllowance::InitPinsTab() //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::InitAllPinComboboxes() { + InitPinPoint(ui->comboBoxGrainlineCenterPin); InitPinPoint(ui->comboBoxGrainlineTopPin); InitPinPoint(ui->comboBoxGrainlineBottomPin); diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui index 3ed545f5e..bee0149c9 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui @@ -1523,6 +1523,9 @@ + + QFormLayout::ExpandingFieldsGrow + @@ -1544,6 +1547,9 @@ + + QFormLayout::ExpandingFieldsGrow + @@ -1575,6 +1581,9 @@ + + QFormLayout::ExpandingFieldsGrow + diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 369847097..6618fc8db 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -495,7 +495,7 @@ void VToolSeamAllowance::UpdateLabel() QPointF pos; qreal labelWidth = 0; qreal labelHeight = 0; - const VTextGraphicsItem::MoveType type = FindLabelGeometry(labelData, labelWidth, labelHeight, pos); + const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(labelData, labelWidth, labelHeight, pos); m_dataLabel->SetMoveType(type); QFont fnt = qApp->font(); @@ -544,7 +544,7 @@ void VToolSeamAllowance::UpdatePatternInfo() QPointF pos; qreal labelWidth = 0; qreal labelHeight = 0; - const VTextGraphicsItem::MoveType type = FindLabelGeometry(geom, labelWidth, labelHeight, pos); + const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(geom, labelWidth, labelHeight, pos); m_patternInfo->SetMoveType(type); QFont fnt = qApp->font(); @@ -596,8 +596,8 @@ void VToolSeamAllowance::UpdateGrainline() qreal dRotation = 0; qreal dLength = 0; - const VGrainlineItem::MoveType type = FindGrainlineGeometry(geom, dLength, dRotation, pos); - if (type == VGrainlineItem::Error) + const VGrainlineItem::MoveTypes type = FindGrainlineGeometry(geom, dLength, dRotation, pos); + if (type & VGrainlineItem::Error) { m_grainLine->hide(); return; @@ -1167,7 +1167,7 @@ void VToolSeamAllowance::SaveDialogChange() } //--------------------------------------------------------------------------------------------------------------------- -VPieceItem::MoveType VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, qreal &labelWidth, +VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, qreal &labelWidth, qreal &labelHeight, QPointF &pos) { const quint32 topLeftPin = labelData.TopLeftPin(); @@ -1186,7 +1186,7 @@ VPieceItem::MoveType VToolSeamAllowance::FindLabelGeometry(const VPatternLabelDa pos = labelRect.topLeft(); - return VTextGraphicsItem::OnlyRotatable; + return VTextGraphicsItem::IsRotatable; } catch(const VExceptionBadId &) { @@ -1201,7 +1201,7 @@ VPieceItem::MoveType VToolSeamAllowance::FindLabelGeometry(const VPatternLabelDa } //--------------------------------------------------------------------------------------------------------------------- -VPieceItem::MoveType VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData& geom, qreal &length, +VPieceItem::MoveTypes VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData& geom, qreal &length, qreal &rotationAngle, QPointF &pos) { const quint32 topPin = geom.TopPin(); @@ -1233,16 +1233,21 @@ VPieceItem::MoveType VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineD } } - bool isResizable = false; - bool isRotatable = false; + VPieceItem::MoveTypes restrictions = VPieceItem::AllModifications; try { - isRotatable = qmu::QmuTokenParser::IsSingle(geom.GetRotation()); + if (not qmu::QmuTokenParser::IsSingle(geom.GetRotation())) + { + restrictions &= ~ VPieceItem::IsRotatable; + } Calculator cal1; rotationAngle = cal1.EvalFormula(VAbstractTool::data.PlainVariables(), geom.GetRotation()); - isResizable = qmu::QmuTokenParser::IsSingle(geom.GetLength()); + if (not qmu::QmuTokenParser::IsSingle(geom.GetLength())) + { + restrictions &= ~ VPieceItem::IsResizable; + } Calculator cal2; length = cal2.EvalFormula(VAbstractTool::data.PlainVariables(), geom.GetLength()); @@ -1253,25 +1258,35 @@ VPieceItem::MoveType VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineD return VPieceItem::Error; } - pos = geom.GetPos(); - - if (isResizable && isRotatable) + const quint32 centerPin = geom.CenterPin(); + if (centerPin != NULL_ID) { - return VPieceItem::AllModifications; + try + { + const auto centerPinPoint = VAbstractTool::data.GeometricObject(centerPin); + + const qreal cLength = ToPixel(length, *VDataTool::data.GetPatternUnit()); + QLineF grainline(centerPinPoint->x(), centerPinPoint->y(), + centerPinPoint->x() + cLength / 2.0, centerPinPoint->y()); + + grainline.setAngle(rotationAngle); + grainline = QLineF(grainline.p2(), grainline.p1()); + grainline.setLength(cLength); + + pos = grainline.p2(); + restrictions &= ~ VPieceItem::IsMovable; + } + catch(const VExceptionBadId &) + { + pos = geom.GetPos(); + } } else { - if (isResizable) - { - return VPieceItem::OnlyResizable; - } - - if (isRotatable) - { - return VPieceItem::OnlyRotatable; - } + pos = geom.GetPos(); } - return VPieceItem::OnlyMovable; + + return restrictions; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index 82b7c5498..ab77960d9 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -152,10 +152,10 @@ private: void RefreshGeometry(); void SaveDialogChange(); - VPieceItem::MoveType FindLabelGeometry(const VPatternLabelData &labelData, qreal &labelWidth, qreal &labelHeight, - QPointF &pos); - VPieceItem::MoveType FindGrainlineGeometry(const VGrainlineData &geom, qreal &length, qreal &rotationAngle, - QPointF &pos); + VPieceItem::MoveTypes FindLabelGeometry(const VPatternLabelData &labelData, qreal &labelWidth, qreal &labelHeight, + QPointF &pos); + VPieceItem::MoveTypes FindGrainlineGeometry(const VGrainlineData &geom, qreal &length, qreal &rotationAngle, + QPointF &pos); void InitNodes(const VPiece &detail, VMainGraphicsScene *scene); void InitCSAPaths(const VPiece &detail); diff --git a/src/libs/vwidgets/vgrainlineitem.cpp b/src/libs/vwidgets/vgrainlineitem.cpp index 124093cd3..b09599902 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -292,51 +292,66 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME) m_dAngle = GetAngle(mapToParent(pME->pos())); m_ptRotCenter = m_ptCenter; - if (m_moveType == OnlyRotatable) + if ((m_moveType & AllModifications ) == AllModifications) { - if (m_eMode != mRotate) + AllUserModifications(pME->pos()); + setZValue(ACTIVE_Z); + Update(); + } + else if (m_moveType & IsRotatable) + { + if (m_moveType & IsResizable) + { + AllUserModifications(pME->pos()); + } + else if (m_moveType & IsMovable) + { + UserRotateAndMove(); + } + else + { + m_eMode = mRotate; + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } + setZValue(ACTIVE_Z); + Update(); + } + else if (m_moveType & IsResizable) + { + if (m_moveType & IsRotatable) + { + AllUserModifications(pME->pos()); + } + else if (m_moveType & IsMovable) + { + UserMoveAndResize(pME->pos()); + } + setZValue(ACTIVE_Z); + Update(); + } + else if (m_moveType & IsMovable) + { + if (m_moveType & IsRotatable) + { + UserRotateAndMove(); + } + else if (m_moveType & IsResizable) + { + UserMoveAndResize(pME->pos()); + } + else { m_eMode = mMove; SetOverrideCursor(cursorArrowCloseHand, 1, 1); } - else - { - SetOverrideCursor(cursorArrowCloseHand, 1, 1); - } setZValue(ACTIVE_Z); Update(); } - else if (m_moveType == OnlyMovable) + else { - m_eMode = mMove; - SetOverrideCursor(cursorArrowCloseHand, 1, 1); - - setZValue(ACTIVE_Z); - Update(); - } - else // All modifications - { - if (m_eMode != mRotate) - { - if (m_polyResize.containsPoint(pME->pos(), Qt::OddEvenFill) == true) - { - m_eMode = mResize; - SetOverrideCursor(Qt::SizeFDiagCursor); - } - else - { - m_eMode = mMove; - SetOverrideCursor(cursorArrowCloseHand, 1, 1); - } - } - else - { - SetOverrideCursor(cursorArrowCloseHand, 1, 1); - } - - setZValue(ACTIVE_Z); - Update(); + pME->ignore(); + return; } } } @@ -351,7 +366,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) QPointF ptDiff = pME->scenePos() - m_ptStartMove; qreal dX; qreal dY; - if (m_eMode == mMove) + if (m_eMode == mMove && m_moveType & IsMovable) { QPointF pt = m_ptStartPos + ptDiff; if (IsContained(pt, m_dRotation, dX, dY) == false) @@ -362,7 +377,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) setPos(pt); Update(); } - else if (m_eMode == mResize) + else if (m_eMode == mResize && m_moveType & IsResizable) { qreal dLen = qSqrt(ptDiff.x()*ptDiff.x() + ptDiff.y()*ptDiff.y()); qreal dAng = qAtan2(-ptDiff.y(), ptDiff.x()); @@ -379,7 +394,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) UpdateRectangle(); Update(); } - else if (m_eMode == mRotate) + else if (m_eMode == mRotate && m_moveType & IsRotatable) { // prevent strange angle changes due to singularities qreal dLen = qSqrt(ptDiff.x()*ptDiff.x() + ptDiff.y()*ptDiff.y()); @@ -433,7 +448,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { if (bShort == true) { - if (m_bReleased == true && m_moveType != OnlyResizable && m_moveType != OnlyMovable) + if (m_bReleased == true && m_moveType & IsRotatable) { m_eMode = mRotate; Update(); @@ -441,11 +456,11 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) } else { - if (m_eMode == mMove) + if (m_eMode == mMove && m_moveType & IsMovable) { emit SignalMoved(pos()); } - else + else if (m_moveType & IsResizable) { emit SignalResized(m_dLength); } @@ -458,7 +473,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { m_eMode = mMove; } - else + else if (m_moveType & IsRotatable) { emit SignalRotated(m_dRotation, m_ptStart); } @@ -687,3 +702,41 @@ QPainterPath VGrainlineItem::MainShape() const } return path; } + +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineItem::AllUserModifications(const QPointF &pos) +{ + if (m_eMode != mRotate) + { + UserMoveAndResize(pos); + } + else + { + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineItem::UserRotateAndMove() +{ + if (m_eMode != mRotate) + { + m_eMode = mMove; + } + SetOverrideCursor(cursorArrowCloseHand, 1, 1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineItem::UserMoveAndResize(const QPointF &pos) +{ + if (m_polyResize.containsPoint(pos, Qt::OddEvenFill) == true) + { + m_eMode = mResize; + SetOverrideCursor(Qt::SizeFDiagCursor); + } + else + { + m_eMode = mMove; // block later if need + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } +} diff --git a/src/libs/vwidgets/vgrainlineitem.h b/src/libs/vwidgets/vgrainlineitem.h index e0fd31fe2..565719f03 100644 --- a/src/libs/vwidgets/vgrainlineitem.h +++ b/src/libs/vwidgets/vgrainlineitem.h @@ -89,6 +89,10 @@ private: QPolygonF SecondArrow(qreal dArrLen) const; QPainterPath MainShape() const; + + void AllUserModifications(const QPointF &pos); + void UserRotateAndMove(); + void UserMoveAndResize(const QPointF &pos); }; #endif // VGRAINLINEITEM_H diff --git a/src/libs/vwidgets/vpieceitem.cpp b/src/libs/vwidgets/vpieceitem.cpp index 5117b8c8c..375f5be9c 100644 --- a/src/libs/vwidgets/vpieceitem.cpp +++ b/src/libs/vwidgets/vpieceitem.cpp @@ -108,13 +108,13 @@ double VPieceItem::GetAngle(const QPointF &pt) const } //--------------------------------------------------------------------------------------------------------------------- -VPieceItem::MoveType VPieceItem::GetMoveType() const +VPieceItem::MoveTypes VPieceItem::GetMoveType() const { return m_moveType; } //--------------------------------------------------------------------------------------------------------------------- -void VPieceItem::SetMoveType(const MoveType &moveType) +void VPieceItem::SetMoveType(const VPieceItem::MoveTypes &moveType) { m_moveType = moveType; setAcceptHoverEvents(m_moveType != NotMovable); diff --git a/src/libs/vwidgets/vpieceitem.h b/src/libs/vwidgets/vpieceitem.h index b97a95fb3..103158d6e 100644 --- a/src/libs/vwidgets/vpieceitem.h +++ b/src/libs/vwidgets/vpieceitem.h @@ -36,7 +36,16 @@ class VPieceItem : public QGraphicsObject { Q_OBJECT public: - enum MoveType {AllModifications, OnlyResizable, OnlyRotatable, OnlyMovable, NotMovable, Error}; + enum MoveType + { + NotMovable = 0x0, + IsRotatable = 0x1, // 0001 + IsResizable = 0x2, // 0010 + IsMovable = 0x4, // 0100 + AllModifications = IsRotatable | IsResizable | IsMovable, + Error = 0x8 // 1000 + }; + Q_DECLARE_FLAGS(MoveTypes, MoveType) explicit VPieceItem(QGraphicsItem* pParent = nullptr); virtual ~VPieceItem(); @@ -48,8 +57,8 @@ public: void Reset(); bool IsIdle() const; - MoveType GetMoveType() const; - void SetMoveType(const MoveType &moveType); + VPieceItem::MoveTypes GetMoveType() const; + void SetMoveType(const VPieceItem::MoveTypes &moveType); signals: void SignalMoved(const QPointF &ptPos); @@ -62,11 +71,11 @@ protected: mResize, mRotate }; - QRectF m_rectBoundingBox; - Mode m_eMode; - bool m_bReleased; - QPointF m_ptRotCenter; - MoveType m_moveType; + QRectF m_rectBoundingBox; + Mode m_eMode; + bool m_bReleased; + QPointF m_ptRotCenter; + VPieceItem::MoveTypes m_moveType; qreal m_inactiveZ; @@ -76,4 +85,6 @@ private: Q_DISABLE_COPY(VPieceItem) }; +Q_DECLARE_OPERATORS_FOR_FLAGS(VPieceItem::MoveTypes) + #endif // VPIECEITEM_H diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index 150562ddf..be206cbe8 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -414,7 +414,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) // in rotation mode, do not do any changes here, because user might want to // rotate the label more. - if (m_moveType == OnlyRotatable) + if (m_moveType & IsRotatable) { if (m_eMode != mRotate) { @@ -572,7 +572,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { // in rotate mode, if user did just press/release, switch to move mode if (bShort == true) { - if (m_moveType != OnlyRotatable) + if (not (m_moveType & IsRotatable)) { m_eMode = mMove; }