From daa539378f5ef223050e7289a8d9411ce1a47f52 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 3 Oct 2017 13:01:56 +0300 Subject: [PATCH] Resolved issue #765. New feature. Free curve mode. --HG-- branch : develop --- ChangeLog.txt | 1 + .../preferencesconfigurationpage.cpp | 3 + .../preferencesconfigurationpage.ui | 15 ++- src/libs/vmisc/vcommonsettings.cpp | 13 ++ src/libs/vmisc/vcommonsettings.h | 3 + .../tools/drawTools/toolcurve/vtoolspline.cpp | 103 ++++++++++++--- .../tools/drawTools/toolcurve/vtoolspline.h | 9 ++ .../drawTools/toolcurve/vtoolsplinepath.cpp | 125 ++++++++++++++---- .../drawTools/toolcurve/vtoolsplinepath.h | 11 +- src/libs/vtools/undocommands/movespline.cpp | 4 +- src/libs/vtools/undocommands/movespline.h | 2 +- src/libs/vwidgets/vcontrolpointspline.cpp | 1 + src/libs/vwidgets/vcontrolpointspline.h | 1 + 13 files changed, 238 insertions(+), 53 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 8d1922bc2..27066b045 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -24,6 +24,7 @@ - [#758] Intersection Passmark - select which side is shown. - New math parser function "r2cm". Round to up to 1 decimal. - Two new shortcut sequences: Ctrl+PgDown and Ctrl+PgUp to switch to next and previous pattern piece. +- [#765] New feature. Free curve mode. # Version 0.5.1 - [#683] Tool Seam allowance's dialog is off screen on small resolutions. diff --git a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp index fe76551e7..3cddff29b 100644 --- a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp @@ -108,6 +108,8 @@ PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent) settings->SetConfirmFormatRewriting(true); }); + ui->checkBoxFreeCurve->setChecked(qApp->ValentinaSettings()->IsFreeCurveMode()); + //----------------------- Toolbar ui->toolBarStyleCheck->setChecked(qApp->ValentinaSettings()->GetToolBarStyle()); } @@ -132,6 +134,7 @@ void PreferencesConfigurationPage::Apply() settings->SetOsSeparator(ui->osOptionCheck->isChecked()); settings->SetToolBarStyle(ui->toolBarStyleCheck->isChecked()); + settings->SetFreeCurveMode(ui->checkBoxFreeCurve->isChecked()); if (m_langChanged || m_systemChanged) { diff --git a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.ui b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.ui index 4323eb3c0..1e73fc4a2 100644 --- a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.ui +++ b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.ui @@ -7,7 +7,7 @@ 0 0 501 - 559 + 582 @@ -187,6 +187,19 @@ + + + + Update a pattern only after a curve release + + + Free curve mode + + + true + + + diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index cc3a410ba..213a0ff56 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -61,6 +61,7 @@ const QString settingConfigurationUnit = QStringLiteral("confi const QString settingConfigurationConfirmItemDeletion = QStringLiteral("configuration/confirm_item_deletion"); const QString settingConfigurationConfirmFormatRewriting = QStringLiteral("configuration/confirm_format_rewriting"); const QString settingConfigurationToolBarStyle = QStringLiteral("configuration/tool_bar_style"); +const QString settingConfigurationFreeCurveMode = QStringLiteral("configuration/freeCurveMode"); const QString settingPatternUndo = QStringLiteral("pattern/undo"); const QString settingPatternForbidFlipping = QStringLiteral("pattern/forbidFlipping"); @@ -478,6 +479,18 @@ void VCommonSettings::SetToolBarStyle(const bool &value) setValue(settingConfigurationToolBarStyle, value); } +//--------------------------------------------------------------------------------------------------------------------- +bool VCommonSettings::IsFreeCurveMode() const +{ + return value(settingConfigurationFreeCurveMode, 1).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetFreeCurveMode(bool value) +{ + setValue(settingConfigurationFreeCurveMode, value); +} + //--------------------------------------------------------------------------------------------------------------------- int VCommonSettings::GetUndoCount() const { diff --git a/src/libs/vmisc/vcommonsettings.h b/src/libs/vmisc/vcommonsettings.h index 4460dbb53..a0b882848 100644 --- a/src/libs/vmisc/vcommonsettings.h +++ b/src/libs/vmisc/vcommonsettings.h @@ -99,6 +99,9 @@ public: bool GetToolBarStyle() const; void SetToolBarStyle(const bool &value); + bool IsFreeCurveMode() const; + void SetFreeCurveMode(bool value); + int GetUndoCount() const; void SetUndoCount(const int &value); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp index 06733933c..4ce28a175 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp @@ -58,7 +58,6 @@ #include "../vgeometry/vabstractcurve.h" #include "../vgeometry/vgobject.h" #include "../vgeometry/vpointf.h" -#include "../vgeometry/vspline.h" #include "../vmisc/vabstractapplication.h" #include "../vmisc/vmath.h" #include "../vpatterndb/vcontainer.h" @@ -79,7 +78,10 @@ const QString VToolSpline::OldToolType = QStringLiteral("simple"); */ VToolSpline::VToolSpline(VToolSplineInitData initData, QGraphicsItem *parent) : VAbstractSpline(initData.doc, initData.data, initData.id, parent), - oldPosition() + oldPosition(), + moved(false), + oldMoveSpline(), + newMoveSpline() { sceneType = SceneObject::Spline; @@ -88,6 +90,16 @@ VToolSpline::VToolSpline(VToolSplineInitData initData, QGraphicsItem *parent) const auto spl = VAbstractTool::data.GeometricObject(initData.id); + auto InitControlPoint = [this](VControlPointSpline* cPoint) + { + connect(cPoint, &VControlPointSpline::ControlPointChangePosition, this, + &VToolSpline::ControlPointChangePosition); + connect(this, &VToolSpline::setEnabledPoint, cPoint, &VControlPointSpline::setEnabledPoint); + connect(cPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSpline::contextMenuEvent); + connect(cPoint, &VControlPointSpline::Released, this, &VToolSpline::CurveReleased); + controlPoints.append(cPoint); + }; + const bool freeAngle1 = qmu::QmuTokenParser::IsSingle(spl->GetStartAngleFormula()); const bool freeLength1 = qmu::QmuTokenParser::IsSingle(spl->GetC1LengthFormula()); @@ -95,11 +107,7 @@ VToolSpline::VToolSpline(VToolSplineInitData initData, QGraphicsItem *parent) static_cast(spl->GetP2()), static_cast(spl->GetP1()), freeAngle1, freeLength1, this); - connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this, - &VToolSpline::ControlPointChangePosition); - connect(this, &VToolSpline::setEnabledPoint, controlPoint1, &VControlPointSpline::setEnabledPoint); - connect(controlPoint1, &VControlPointSpline::ShowContextMenu, this, &VToolSpline::contextMenuEvent); - controlPoints.append(controlPoint1); + InitControlPoint(controlPoint1); const bool freeAngle2 = qmu::QmuTokenParser::IsSingle(spl->GetEndAngleFormula()); const bool freeLength2 = qmu::QmuTokenParser::IsSingle(spl->GetC2LengthFormula()); @@ -108,11 +116,7 @@ VToolSpline::VToolSpline(VToolSplineInitData initData, QGraphicsItem *parent) static_cast(spl->GetP3()), static_cast(spl->GetP4()), freeAngle2, freeLength2, this); - connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this, - &VToolSpline::ControlPointChangePosition); - connect(this, &VToolSpline::setEnabledPoint, controlPoint2, &VControlPointSpline::setEnabledPoint); - connect(controlPoint2, &VControlPointSpline::ShowContextMenu, this, &VToolSpline::contextMenuEvent); - controlPoints.append(controlPoint2); + InitControlPoint(controlPoint2); ShowHandles(false); @@ -267,11 +271,30 @@ void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, const Sp { Q_UNUSED(indexSpline) const QSharedPointer spline = VAbstractTool::data.GeometricObject(m_id); + + if (qApp->Settings()->IsFreeCurveMode() && not moved) + { + oldMoveSpline = spline; + moved = true; + } + const VSpline spl = CorrectedSpline(*spline, position, pos); - MoveSpline *moveSpl = new MoveSpline(doc, spline.data(), spl, m_id); - connect(moveSpl, &MoveSpline::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); - qApp->getUndoStack()->push(moveSpl); + if (not qApp->Settings()->IsFreeCurveMode()) + { + UndoCommandMove(*spline, spl); + } + else + { + newMoveSpline = QSharedPointer(new VSpline(spl)); + VAbstractTool::data.UpdateGObject(m_id, newMoveSpline); + RefreshGeometry(); + + if (QGraphicsScene *sc = scene()) + { + VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView()); + } + } } //--------------------------------------------------------------------------------------------------------------------- @@ -355,6 +378,8 @@ void VToolSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if (IsMovable()) { SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); + + CurveReleased(); } } } @@ -375,6 +400,13 @@ void VToolSpline::mouseMoveEvent(QGraphicsSceneMouseEvent *event) // among the handles; 0 = front handle only, 1 = back handle only. const auto spline = VAbstractTool::data.GeometricObject(m_id); + + if (qApp->Settings()->IsFreeCurveMode() && not moved) + { + oldMoveSpline = spline; + moved = true; + } + const qreal t = spline->ParamT(oldPosition); if (qFloor(t) == -1) @@ -409,11 +441,22 @@ void VToolSpline::mouseMoveEvent(QGraphicsSceneMouseEvent *event) oldPosition = event->scenePos(); // Now mouse here - VSpline spl = VSpline(spline->GetP1(), p2, p3, spline->GetP4()); + newMoveSpline = QSharedPointer(new VSpline(spline->GetP1(), p2, p3, spline->GetP4())); - MoveSpline *moveSpl = new MoveSpline(doc, spline.data(), spl, m_id); - connect(moveSpl, &MoveSpline::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); - qApp->getUndoStack()->push(moveSpl); + if (not qApp->Settings()->IsFreeCurveMode()) + { + UndoCommandMove(*spline, *newMoveSpline); + } + else + { + VAbstractTool::data.UpdateGObject(m_id, newMoveSpline); + RefreshGeometry(); + + if (QGraphicsScene *sc = scene()) + { + VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView()); + } + } // Each time we move something we call recalculation scene rect. In some cases this can cause moving // objects positions. And this cause infinite redrawing. That's why we wait the finish of saving the last move. @@ -543,6 +586,20 @@ void VToolSpline::RefreshCtrlPoints() } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSpline::CurveReleased() +{ + if (qApp->Settings()->IsFreeCurveMode() && moved) + { + UndoCommandMove(*oldMoveSpline, *newMoveSpline); + + oldMoveSpline.clear(); + newMoveSpline.clear(); + + moved = false; + } +} + //--------------------------------------------------------------------------------------------------------------------- void VToolSpline::ShowContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 id) { @@ -598,3 +655,11 @@ void VToolSpline::SetSplineAttributes(QDomElement &domElement, const VSpline &sp domElement.removeAttribute(AttrKAsm2); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSpline::UndoCommandMove(const VSpline &oldSpl, const VSpline &newSpl) +{ + MoveSpline *moveSpl = new MoveSpline(doc, oldSpl, newSpl, m_id); + connect(moveSpl, &MoveSpline::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(moveSpl); +} diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h index c2c2a6791..0ff52790c 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h @@ -41,6 +41,7 @@ #include "../vmisc/def.h" #include "../ifc/xml/vabstractpattern.h" #include "vabstractspline.h" +#include "../vgeometry/vspline.h" template class QSharedPointer; @@ -105,14 +106,22 @@ protected: virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; virtual void RefreshCtrlPoints() Q_DECL_OVERRIDE; +private slots: + void CurveReleased(); private: Q_DISABLE_COPY(VToolSpline) QPointF oldPosition; + bool moved; + QSharedPointer oldMoveSpline; + QSharedPointer newMoveSpline; + VToolSpline (VToolSplineInitData initData, QGraphicsItem *parent = nullptr ); bool IsMovable() const; void SetSplineAttributes(QDomElement &domElement, const VSpline &spl); + + void UndoCommandMove(const VSpline &oldSpl, const VSpline &newSpl); }; #endif // VTOOLSPLINE_H diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp index de35e2bcf..df02f17c7 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -85,13 +85,25 @@ const QString VToolSplinePath::OldToolType = QStringLiteral("path"); VToolSplinePath::VToolSplinePath(const VToolSplinePathInitData &initData, QGraphicsItem *parent) : VAbstractSpline(initData.doc, initData.data, initData.id, parent), oldPosition(), - splIndex(-1) + splIndex(-1), + moved(false), + oldMoveSplinePath(), + newMoveSplinePath() { sceneType = SceneObject::SplinePath; this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus + auto InitControlPoint = [this](VControlPointSpline* cPoint) + { + connect(cPoint, &VControlPointSpline::ControlPointChangePosition, this, + &VToolSplinePath::ControlPointChangePosition); + connect(this, &VToolSplinePath::setEnabledPoint, cPoint, &VControlPointSpline::setEnabledPoint); + connect(cPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSplinePath::contextMenuEvent); + controlPoints.append(cPoint); + }; + const QSharedPointer splPath = initData.data->GeometricObject(initData.id); for (qint32 i = 1; i<=splPath->CountSubSpl(); ++i) { @@ -104,22 +116,14 @@ VToolSplinePath::VToolSplinePath(const VToolSplinePathInitData &initData, QGraph static_cast(spl.GetP2()), static_cast(spl.GetP1()), freeAngle1, freeLength1, this); - connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); - connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint); - connect(controlPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSplinePath::contextMenuEvent); - controlPoints.append(controlPoint); + InitControlPoint(controlPoint); const bool freeAngle2 = qmu::QmuTokenParser::IsSingle(spl.GetEndAngleFormula()); const bool freeLength2 = qmu::QmuTokenParser::IsSingle(spl.GetC2LengthFormula()); controlPoint = new VControlPointSpline(i, SplinePointPosition::LastPoint, static_cast(spl.GetP3()), static_cast(spl.GetP4()), freeAngle2, freeLength2, this); - connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); - connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint); - connect(controlPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSplinePath::contextMenuEvent); - controlPoints.append(controlPoint); + InitControlPoint(controlPoint); } ShowHandles(false); @@ -258,14 +262,34 @@ VToolSplinePath *VToolSplinePath::Create(VToolSplinePathInitData &initData) void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, const SplinePointPosition &position, const QPointF &pos) { - const VSplinePath oldSplPath = *VAbstractTool::data.GeometricObject(m_id); - VSplinePath newSplPath = oldSplPath; - const VSpline spl = CorrectedSpline(newSplPath.GetSpline(indexSpline), position, pos); + const QSharedPointer oldSplPath = VAbstractTool::data.GeometricObject(m_id); + + if (qApp->Settings()->IsFreeCurveMode() && not moved) + { + oldMoveSplinePath = oldSplPath; + moved = true; + } + + QSharedPointer newSplPath = oldSplPath; + const VSpline spl = CorrectedSpline(newSplPath->GetSpline(indexSpline), position, pos); + UpdateControlPoints(spl, newSplPath, indexSpline); - MoveSplinePath *moveSplPath = new MoveSplinePath(doc, oldSplPath, newSplPath, m_id); - connect(moveSplPath, &VUndoCommand::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); - qApp->getUndoStack()->push(moveSplPath); + if (not qApp->Settings()->IsFreeCurveMode()) + { + UndoCommandMove(*oldSplPath, *newSplPath); + } + else + { + newMoveSplinePath = newSplPath; + VAbstractTool::data.UpdateGObject(m_id, newMoveSplinePath); + RefreshGeometry(); + + if (QGraphicsScene *sc = scene()) + { + VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView()); + } + } } //--------------------------------------------------------------------------------------------------------------------- @@ -296,17 +320,18 @@ void VToolSplinePath::ShowContextMenu(QGraphicsSceneContextMenuEvent *event, qui * @param splPath spline path. * @param indexSpline index spline in spline path. */ -void VToolSplinePath::UpdateControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline) const +void VToolSplinePath::UpdateControlPoints(const VSpline &spl, QSharedPointer &splPath, + qint32 indexSpline) const { - VSplinePoint p = splPath.GetSplinePoint(indexSpline, SplinePointPosition::FirstPoint); + VSplinePoint p = splPath->GetSplinePoint(indexSpline, SplinePointPosition::FirstPoint); p.SetAngle2(spl.GetStartAngle(), spl.GetStartAngleFormula()); p.SetLength2(spl.GetC1Length(), spl.GetC1LengthFormula()); - splPath.UpdatePoint(indexSpline, SplinePointPosition::FirstPoint, p); + splPath->UpdatePoint(indexSpline, SplinePointPosition::FirstPoint, p); - p = splPath.GetSplinePoint(indexSpline, SplinePointPosition::LastPoint); + p = splPath->GetSplinePoint(indexSpline, SplinePointPosition::LastPoint); p.SetAngle1(spl.GetEndAngle(), spl.GetEndAngleFormula()); p.SetLength1(spl.GetC2Length(), spl.GetC2LengthFormula()); - splPath.UpdatePoint(indexSpline, SplinePointPosition::LastPoint, p); + splPath->UpdatePoint(indexSpline, SplinePointPosition::LastPoint, p); } //--------------------------------------------------------------------------------------------------------------------- @@ -334,6 +359,14 @@ void VToolSplinePath::SetSplinePathAttributes(QDomElement &domElement, const VSp UpdatePathPoints(doc, domElement, path); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSplinePath::UndoCommandMove(const VSplinePath &oldPath, const VSplinePath &newPath) +{ + MoveSplinePath *moveSplPath = new MoveSplinePath(doc, oldPath, newPath, m_id); + connect(moveSplPath, &VUndoCommand::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(moveSplPath); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief UpdatePathPoints update spline path in pattern file. @@ -491,6 +524,8 @@ void VToolSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { oldPosition = event->scenePos(); SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); + + CurveReleased(); } } VAbstractSpline::mouseReleaseEvent(event); @@ -505,10 +540,17 @@ void VToolSplinePath::mouseMoveEvent(QGraphicsSceneMouseEvent *event) if (IsMovable(splIndex)) { - VSplinePath oldSplPath = *VAbstractTool::data.GeometricObject(m_id); - VSplinePath newSplPath = oldSplPath; + const auto oldSplPath = VAbstractTool::data.GeometricObject(m_id); - VSpline spline = newSplPath.GetSpline(splIndex); + if (qApp->Settings()->IsFreeCurveMode() && not moved) + { + oldMoveSplinePath = oldSplPath; + moved = true; + } + + newMoveSplinePath = oldSplPath; + + VSpline spline = newMoveSplinePath->GetSpline(splIndex); const qreal t = spline.ParamT(oldPosition); if (qFloor(t) == -1) @@ -549,11 +591,22 @@ void VToolSplinePath::mouseMoveEvent(QGraphicsSceneMouseEvent *event) const VSpline spl = VSpline(spline.GetP1(), p2, p3, spline.GetP4()); - UpdateControlPoints(spl, newSplPath, splIndex); + UpdateControlPoints(spl, newMoveSplinePath, splIndex); - MoveSplinePath *moveSplPath = new MoveSplinePath(doc, oldSplPath, newSplPath, m_id); - connect(moveSplPath, &VUndoCommand::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); - qApp->getUndoStack()->push(moveSplPath); + if (not qApp->Settings()->IsFreeCurveMode()) + { + UndoCommandMove(*oldSplPath, *newMoveSplinePath); + } + else + { + VAbstractTool::data.UpdateGObject(m_id, newMoveSplinePath); + RefreshGeometry(); + + if (QGraphicsScene *sc = scene()) + { + VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView()); + } + } // Each time we move something we call recalculation scene rect. In some cases this can cause moving // objects positions. And this cause infinite redrawing. That's why we wait the finish of saving the last move. @@ -688,3 +741,17 @@ void VToolSplinePath::RefreshCtrlPoints() point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSplinePath::CurveReleased() +{ + if (qApp->Settings()->IsFreeCurveMode() && moved) + { + UndoCommandMove(*oldMoveSplinePath, *newMoveSplinePath); + + oldMoveSplinePath.clear(); + newMoveSplinePath.clear(); + + moved = false; + } +} diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h index cf4fc2ee1..48d258b69 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h @@ -117,17 +117,26 @@ protected: virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; virtual void RefreshCtrlPoints() Q_DECL_OVERRIDE; +private slots: + void CurveReleased(); private: Q_DISABLE_COPY(VToolSplinePath) QPointF oldPosition; int splIndex; + bool moved; + QSharedPointer oldMoveSplinePath; + QSharedPointer newMoveSplinePath; + VToolSplinePath(const VToolSplinePathInitData &initData, QGraphicsItem *parent = nullptr); bool IsMovable(int index) const; static void AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VSplinePoint &splPoint); - void UpdateControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline) const; + void UpdateControlPoints(const VSpline &spl, QSharedPointer &splPath, + qint32 indexSpline) const; void SetSplinePathAttributes(QDomElement &domElement, const VSplinePath &path); + + void UndoCommandMove(const VSplinePath &oldPath, const VSplinePath &newPath); }; #endif // VTOOLSPLINEPATH_H diff --git a/src/libs/vtools/undocommands/movespline.cpp b/src/libs/vtools/undocommands/movespline.cpp index c22830e1a..6f25c5b8a 100644 --- a/src/libs/vtools/undocommands/movespline.cpp +++ b/src/libs/vtools/undocommands/movespline.cpp @@ -41,10 +41,10 @@ #include "vundocommand.h" //--------------------------------------------------------------------------------------------------------------------- -MoveSpline::MoveSpline(VAbstractPattern *doc, const VSpline *oldSpl, const VSpline &newSpl, const quint32 &id, +MoveSpline::MoveSpline(VAbstractPattern *doc, const VSpline &oldSpl, const VSpline &newSpl, const quint32 &id, QUndoCommand *parent) : VUndoCommand(QDomElement(), doc, parent), - oldSpline(*oldSpl), + oldSpline(oldSpl), newSpline(newSpl), scene(qApp->getCurrentScene()) { diff --git a/src/libs/vtools/undocommands/movespline.h b/src/libs/vtools/undocommands/movespline.h index 1f1f25a87..9461c34ff 100644 --- a/src/libs/vtools/undocommands/movespline.h +++ b/src/libs/vtools/undocommands/movespline.h @@ -44,7 +44,7 @@ class MoveSpline : public VUndoCommand { Q_OBJECT public: - MoveSpline(VAbstractPattern *doc, const VSpline *oldSpl, const VSpline &newSpl, const quint32 &id, + MoveSpline(VAbstractPattern *doc, const VSpline &oldSpl, const VSpline &newSpl, const quint32 &id, QUndoCommand *parent = nullptr); virtual ~MoveSpline() Q_DECL_OVERRIDE; virtual void undo() Q_DECL_OVERRIDE; diff --git a/src/libs/vwidgets/vcontrolpointspline.cpp b/src/libs/vwidgets/vcontrolpointspline.cpp index f55fa2203..80987a81f 100644 --- a/src/libs/vwidgets/vcontrolpointspline.cpp +++ b/src/libs/vwidgets/vcontrolpointspline.cpp @@ -234,6 +234,7 @@ void VControlPointSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if (freeAngle || freeLength) { SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); + emit Released(); } } VScenePoint::mouseReleaseEvent(event); diff --git a/src/libs/vwidgets/vcontrolpointspline.h b/src/libs/vwidgets/vcontrolpointspline.h index 2c337903d..a7b5fac98 100644 --- a/src/libs/vwidgets/vcontrolpointspline.h +++ b/src/libs/vwidgets/vcontrolpointspline.h @@ -74,6 +74,7 @@ signals: * @param event context menu event. */ void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); + void Released(); public slots: void RefreshCtrlPoint(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint, const QPointF &splinePoint, bool freeAngle = true, bool freeLength = true);