From 1d91df5216ff1049b618da7ace9e7799484a3363 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 27 Feb 2017 14:30:02 +0200 Subject: [PATCH] Preparetions to be able to control moving actions: rotation and resizing. --HG-- branch : feature --- src/libs/vtools/tools/vtoolseamallowance.cpp | 62 ++++++++++++++------ src/libs/vtools/tools/vtoolseamallowance.h | 6 +- src/libs/vwidgets/vgrainlineitem.cpp | 2 +- src/libs/vwidgets/vpieceitem.cpp | 13 ++++ src/libs/vwidgets/vpieceitem.h | 14 +++-- src/libs/vwidgets/vtextgraphicsitem.cpp | 2 +- 6 files changed, 72 insertions(+), 27 deletions(-) diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 37463f6e2..681d9b28c 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -54,6 +54,7 @@ #include "../undocommands/togglepieceinlayout.h" #include "../vwidgets/vmaingraphicsview.h" #include "../vwidgets/vnobrushscalepathitem.h" +#include "../qmuparser/qmutokenparser.h" #include #include @@ -484,7 +485,8 @@ void VToolSeamAllowance::UpdateLabel() QPointF pos; qreal labelWidth = 0; qreal labelHeight = 0; - FindLabelGeometry(labelData, labelWidth, labelHeight, pos); + const VTextGraphicsItem::MoveType type = FindLabelGeometry(labelData, labelWidth, labelHeight, pos); + m_dataLabel->SetMoveType(type); QFont fnt = qApp->font(); { @@ -532,7 +534,8 @@ void VToolSeamAllowance::UpdatePatternInfo() QPointF pos; qreal labelWidth = 0; qreal labelHeight = 0; - FindLabelGeometry(geom, labelWidth, labelHeight, pos); + const VTextGraphicsItem::MoveType type = FindLabelGeometry(geom, labelWidth, labelHeight, pos); + m_patternInfo->SetMoveType(type); QFont fnt = qApp->font(); int iFS = geom.GetFontSize(); @@ -583,12 +586,14 @@ void VToolSeamAllowance::UpdateGrainline() qreal dRotation = 0; qreal dLength = 0; - if ( not FindGrainlineGeometry(geom, dLength, dRotation, pos)) + const VGrainlineItem::MoveType type = FindGrainlineGeometry(geom, dLength, dRotation, pos); + if (type == VGrainlineItem::Error) { m_grainLine->hide(); return; } + m_grainLine->SetMoveType(type); m_grainLine->UpdateGeometry(pos, dRotation, ToPixel(dLength, *VDataTool::data.GetPatternUnit()), geom.GetArrowType()); m_grainLine->show(); @@ -735,7 +740,7 @@ void VToolSeamAllowance::SaveResizeGrainline(qreal dLength) VPiece newDet = oldDet; dLength = FromPixel(dLength, *VDataTool::data.GetPatternUnit()); - newDet.GetGrainlineGeometry().SetLength(qApp->LocaleToString(dLength)); + newDet.GetGrainlineGeometry().SetLength(QString().setNum(dLength)); SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, id); resizeCommand->setText(tr("resize grainline")); connect(resizeCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); @@ -749,7 +754,7 @@ void VToolSeamAllowance::SaveRotateGrainline(qreal dRot, const QPointF& ptPos) VPiece newDet = oldDet; dRot = qRadiansToDegrees(dRot); - newDet.GetGrainlineGeometry().SetRotation(qApp->LocaleToString(dRot)); + newDet.GetGrainlineGeometry().SetRotation(QString().setNum(dRot)); newDet.GetGrainlineGeometry().SetPos(ptPos); SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, id); rotateCommand->setText(tr("rotate grainline")); @@ -1152,8 +1157,8 @@ void VToolSeamAllowance::SaveDialogChange() } //--------------------------------------------------------------------------------------------------------------------- -void VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, qreal &labelWidth, qreal &labelHeight, - QPointF &pos) +VPieceItem::MoveType VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, qreal &labelWidth, + qreal &labelHeight, QPointF &pos) { const quint32 topLeftPin = labelData.TopLeftPin(); const quint32 bottomRightPin = labelData.BottomRightPin(); @@ -1171,7 +1176,7 @@ void VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, q pos = labelRect.topLeft(); - return; + return VTextGraphicsItem::OnlyRotatable; } catch(const VExceptionBadId &) { @@ -1182,11 +1187,12 @@ void VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, q labelWidth = labelData.GetLabelWidth(); labelHeight = labelData.GetLabelHeight(); pos = labelData.GetPos(); + return VTextGraphicsItem::Movable; } //--------------------------------------------------------------------------------------------------------------------- -bool VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData& geom, qreal &length, qreal &rotationAngle, - QPointF &pos) +VPieceItem::MoveType VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData& geom, qreal &length, + qreal &rotationAngle, QPointF &pos) { const quint32 topPin = geom.TopPin(); const quint32 bottomPin = geom.BottomPin(); @@ -1209,7 +1215,7 @@ bool VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData& geom, qreal pos = grainline.p1(); - return true; + return VPieceItem::OnlyRotatable; } catch(const VExceptionBadId &) { @@ -1217,27 +1223,45 @@ bool VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData& geom, qreal } } + bool isResizable = false; + bool isRotatable = false; try { - QString qsFormula = geom.GetRotation().replace("\n", " "); - qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); + isRotatable = qmu::QmuTokenParser::IsSingle(geom.GetRotation()); Calculator cal1; - rotationAngle = cal1.EvalFormula(VAbstractTool::data.PlainVariables(), qsFormula); + rotationAngle = cal1.EvalFormula(VAbstractTool::data.PlainVariables(), geom.GetRotation()); + + isResizable = qmu::QmuTokenParser::IsSingle(geom.GetLength()); - qsFormula = geom.GetLength().replace("\n", " "); - qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); Calculator cal2; - length = cal2.EvalFormula(VAbstractTool::data.PlainVariables(), qsFormula); + length = cal2.EvalFormula(VAbstractTool::data.PlainVariables(), geom.GetLength()); } catch(qmu::QmuParserError &e) { Q_UNUSED(e); - return false; + return VPieceItem::Error; } pos = geom.GetPos(); - return true; + + if (isResizable && isRotatable) + { + return VPieceItem::Movable; + } + else + { + if (isResizable) + { + return VPieceItem::OnlyResizable; + } + + if (isRotatable) + { + return VPieceItem::OnlyRotatable; + } + } + return VPieceItem::NotMovable; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index fc948e1ae..f402721dc 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -151,8 +151,10 @@ private: void RefreshGeometry(); void SaveDialogChange(); - void FindLabelGeometry(const VPatternLabelData &labelData, qreal &labelWidth, qreal &labelHeight, QPointF &pos); - bool FindGrainlineGeometry(const VGrainlineData &geom, qreal &length, qreal &rotationAngle, QPointF &pos); + VPieceItem::MoveType FindLabelGeometry(const VPatternLabelData &labelData, qreal &labelWidth, qreal &labelHeight, + QPointF &pos); + VPieceItem::MoveType 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 54574cdec..c0cb1b87e 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -308,7 +308,7 @@ bool VGrainlineItem::IsContained(const QPointF& pt, qreal dRot, qreal &dX, qreal */ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME) { - if (pME->button() == Qt::LeftButton) + if (pME->button() == Qt::LeftButton && pME->type() != QEvent::GraphicsSceneMouseDoubleClick) { m_ptStartPos = pos(); m_ptStartMove = pME->scenePos(); diff --git a/src/libs/vwidgets/vpieceitem.cpp b/src/libs/vwidgets/vpieceitem.cpp index f7f969fed..7319a59a0 100644 --- a/src/libs/vwidgets/vpieceitem.cpp +++ b/src/libs/vwidgets/vpieceitem.cpp @@ -38,6 +38,7 @@ VPieceItem::VPieceItem(QGraphicsItem *pParent) m_eMode(VPieceItem::mNormal), m_bReleased(false), m_ptRotCenter(), + m_moveType(Movable), m_inactiveZ(1) { m_rectBoundingBox.setTopLeft(QPointF(0, 0)); @@ -106,3 +107,15 @@ double VPieceItem::GetAngle(const QPointF &pt) const } } +//--------------------------------------------------------------------------------------------------------------------- +VPieceItem::MoveType VPieceItem::GetMoveType() const +{ + return m_moveType; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPieceItem::SetMoveType(const MoveType &moveType) +{ + m_moveType = moveType; +} + diff --git a/src/libs/vwidgets/vpieceitem.h b/src/libs/vwidgets/vpieceitem.h index 7b3306044..32509f5f6 100644 --- a/src/libs/vwidgets/vpieceitem.h +++ b/src/libs/vwidgets/vpieceitem.h @@ -36,6 +36,8 @@ class VPieceItem : public QGraphicsObject { Q_OBJECT public: + enum MoveType {Movable, OnlyResizable, OnlyRotatable, NotMovable, Error}; + explicit VPieceItem(QGraphicsItem* pParent = nullptr); virtual ~VPieceItem(); @@ -48,6 +50,9 @@ public: double GetAngle(const QPointF &pt) const; + MoveType GetMoveType() const; + void SetMoveType(const MoveType &moveType); + signals: void SignalMoved(const QPointF &ptPos); @@ -59,10 +64,11 @@ protected: mResize, mRotate }; - QRectF m_rectBoundingBox; - Mode m_eMode; - bool m_bReleased; - QPointF m_ptRotCenter; + QRectF m_rectBoundingBox; + Mode m_eMode; + bool m_bReleased; + QPointF m_ptRotCenter; + MoveType m_moveType; qreal m_inactiveZ; diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index 842bcdeaa..463b7506f 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -401,7 +401,7 @@ int VTextGraphicsItem::GetFontSize() const */ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) { - if (pME->button() == Qt::LeftButton) + if (pME->button() == Qt::LeftButton && pME->type() != QEvent::GraphicsSceneMouseDoubleClick) { // record the parameters of the mouse press. Specially record the position // of the press as the origin for the following operations