From 8683b69f13b188b2583ebdff76ae42bc0ad36a34 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 11 Feb 2016 13:05:08 +0200 Subject: [PATCH 01/10] Select an item inside mousePressEvent() instead mouseReleaseEvent(). --HG-- branch : feature --- .../tools/drawTools/toolcurve/vabstractspline.cpp | 6 +++--- .../vtools/tools/drawTools/toolcurve/vabstractspline.h | 2 +- .../toolpoint/toolsinglepoint/vtoolsinglepoint.cpp | 6 +++--- .../toolpoint/toolsinglepoint/vtoolsinglepoint.h | 2 +- src/libs/vtools/tools/vtooldetail.cpp | 10 +++++++--- src/libs/vwidgets/vgraphicssimpletextitem.cpp | 8 ++++---- src/libs/vwidgets/vsimplepoint.cpp | 4 ++-- src/libs/vwidgets/vsimplepoint.h | 2 +- 8 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index 2648fc3b1..ca01fb50b 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -204,16 +204,16 @@ void VAbstractSpline::keyReleaseEvent(QKeyEvent *event) //--------------------------------------------------------------------------------------------------------------------- /** - * @brief mouseReleaseEvent handle mouse release events. + * @brief mousePressEvent handle mouse press events. * @param event mouse release event. */ -void VAbstractSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void VAbstractSpline::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { emit ChoosedTool(id, sceneType); } - QGraphicsItem::mouseReleaseEvent(event); + QGraphicsPathItem::mousePressEvent(event); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h index 61aca125e..54129b110 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h @@ -88,7 +88,7 @@ protected: virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE; virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; + virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; QPainterPath ToolPath(PathDirection direction = PathDirection::Hide) const; virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index 63d995980..d0cf96a75 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -177,16 +177,16 @@ void VToolSinglePoint::FullUpdateFromFile() //--------------------------------------------------------------------------------------------------------------------- /** - * @brief mouseReleaseEvent handle mouse release events. + * @brief mousePressEvent handle mouse press events. * @param event mouse release event. */ -void VToolSinglePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { PointChoosed(); } - QGraphicsEllipseItem::mouseReleaseEvent(event); + QGraphicsEllipseItem::mousePressEvent(event); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h index 112285ee8..0a1c7f809 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h @@ -73,7 +73,7 @@ protected: QGraphicsLineItem *lineName; virtual void UpdateNamePosition(quint32 id) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; + virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void RefreshPointGeometry(const VPointF &point); diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index b3f222d32..7262c5258 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -446,9 +446,14 @@ void VToolDetail::mousePressEvent(QGraphicsSceneMouseEvent *event) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { SetOverrideCursor(cursorArrowCloseHand, 1, 1); - event->accept(); } } + + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) + { + emit ChoosedTool(id, SceneObject::Detail); + } + VNoBrushScalePathItem::mousePressEvent(event); } @@ -461,11 +466,10 @@ void VToolDetail::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { - emit ChoosedTool(id, SceneObject::Detail); //Disable cursor-arrow-closehand RestoreOverrideCursor(cursorArrowCloseHand); } - QGraphicsItem::mouseReleaseEvent(event); + VNoBrushScalePathItem::mouseReleaseEvent(event); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index 5a92bac76..21b13359f 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -217,6 +217,9 @@ void VGraphicsSimpleTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) SetOverrideCursor(cursorArrowCloseHand, 1, 1); } } + + emit PointChoosed(); + QGraphicsSimpleTextItem::mousePressEvent(event); } @@ -231,10 +234,7 @@ void VGraphicsSimpleTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) RestoreOverrideCursor(cursorArrowCloseHand); } } - else - { - emit PointChoosed(); - } + QGraphicsSimpleTextItem::mouseReleaseEvent(event); } diff --git a/src/libs/vwidgets/vsimplepoint.cpp b/src/libs/vwidgets/vsimplepoint.cpp index 5cca38fdd..51447b629 100644 --- a/src/libs/vwidgets/vsimplepoint.cpp +++ b/src/libs/vwidgets/vsimplepoint.cpp @@ -173,13 +173,13 @@ void VSimplePoint::ContextMenu(QGraphicsSceneContextMenuEvent *event) } //--------------------------------------------------------------------------------------------------------------------- -void VSimplePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +void VSimplePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { emit Choosed(id); } - QGraphicsEllipseItem::mouseReleaseEvent(event); + QGraphicsEllipseItem::mousePressEvent(event); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vsimplepoint.h b/src/libs/vwidgets/vsimplepoint.h index 84d8fee0b..ffb45f869 100644 --- a/src/libs/vwidgets/vsimplepoint.h +++ b/src/libs/vwidgets/vsimplepoint.h @@ -75,7 +75,7 @@ public slots: void ContextMenu(QGraphicsSceneContextMenuEvent * event); protected: - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; + virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; From 791d874c9a781816f4271fc4c87c47211c2c482d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 12 Feb 2016 15:49:59 +0200 Subject: [PATCH 02/10] Little refactoring. --HG-- branch : feature --- src/app/valentina/mainwindow.cpp | 8 ++++++++ src/app/valentina/mainwindow.h | 15 +++++++-------- src/libs/vtools/dialogs/tools/dialogendline.cpp | 2 +- src/libs/vtools/tools/drawTools/vdrawtool.h | 2 -- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 80eefb518..122b2b302 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -48,6 +48,12 @@ #include "../ifc/xml/vvstconverter.h" #include "../ifc/xml/vvitconverter.h" #include "../vwidgets/vwidgetpopup.h" +#include "../vwidgets/vmaingraphicsscene.h" +#include "tools/drawTools/drawtools.h" +#include "../vtools/dialogs/tooldialogs.h" +#include "tools/vtooldetail.h" +#include "tools/vtooluniondetails.h" +#include "dialogs/dialogs.h" #include #include @@ -66,6 +72,8 @@ #include #include #include +#include +#include #if defined(Q_OS_MAC) #include diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 17d776d30..e3cfc6140 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -30,17 +30,10 @@ #define MAINWINDOW_H #include "mainwindowsnogui.h" -#include "../vwidgets/vmaingraphicsview.h" -#include "../vtools/dialogs/tooldialogs.h" -#include "dialogs/dialogs.h" -#include "tools/vtooldetail.h" -#include "tools/vtooluniondetails.h" -#include "tools/drawTools/drawtools.h" #include "core/vcmdexport.h" #include "../vmisc/vlockguard.h" -#include -#include +#include namespace Ui { @@ -49,6 +42,12 @@ namespace Ui class VToolOptionsPropertyBrowser; class VMeasurements; +class VMainGraphicsScene; +class QFileSystemWatcher; +class QLabel; +class DialogIncrements; +class DialogTool; +class DialogHistory; /** * @brief The MainWindow class main windows. diff --git a/src/libs/vtools/dialogs/tools/dialogendline.cpp b/src/libs/vtools/dialogs/tools/dialogendline.cpp index 668fc5a92..6f6f3df63 100644 --- a/src/libs/vtools/dialogs/tools/dialogendline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogendline.cpp @@ -279,7 +279,7 @@ void DialogEndLine::ShowDialog(bool click) { if (click) { - /*We will ignore click if poinet is in point circle*/ + /*We will ignore click if pointer is in point circle*/ VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); SCASSERT(scene != nullptr); const QSharedPointer point = data->GeometricObject(GetBasePointId()); diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 530cf4e17..5c6512247 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -31,12 +31,10 @@ #include "../vabstracttool.h" #include "../../dialogs/tools/dialogtool.h" -#include "../vwidgets/vmaingraphicsscene.h" #include "../vwidgets/vmaingraphicsview.h" #include #include -#include /** * @brief The VDrawTool abstract class for all draw tool. From 0f747ede7ef1d667946d90a6513bb66ef780afc0 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 12 Feb 2016 20:10:01 +0200 Subject: [PATCH 03/10] The first implementation for tool Spline. --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 1 + .../vtools/dialogs/tools/dialogspline.cpp | 64 +++++++----- src/libs/vtools/dialogs/tools/dialogspline.h | 1 + .../vtools/dialogs/tools/dialogsplinepath.cpp | 14 +-- src/libs/vtools/dialogs/tools/dialogtool.h | 1 + .../drawTools/toolcurve/vabstractspline.cpp | 2 + .../drawTools/toolcurve/vabstractspline.h | 12 +-- .../tools/drawTools/toolcurve/vtoolspline.cpp | 42 ++++---- .../tools/drawTools/toolcurve/vtoolspline.h | 2 + .../drawTools/toolcurve/vtoolsplinepath.cpp | 41 ++++---- .../drawTools/toolcurve/vtoolsplinepath.h | 4 + .../vtools/visualization/vistoolspline.cpp | 99 +++++++++++++++++-- src/libs/vtools/visualization/vistoolspline.h | 19 ++++ .../visualization/vistoolsplinepath.cpp | 15 +-- .../vtools/visualization/vistoolsplinepath.h | 5 - .../vtools/visualization/visualization.cpp | 25 ++++- src/libs/vtools/visualization/visualization.h | 6 ++ src/libs/vwidgets/vcontrolpointspline.cpp | 69 +++++++++---- src/libs/vwidgets/vcontrolpointspline.h | 18 +++- src/libs/vwidgets/vmaingraphicsscene.cpp | 16 ++- src/libs/vwidgets/vmaingraphicsscene.h | 10 +- 21 files changed, 323 insertions(+), 143 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 9a1fdcb42..4c8f714de 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -42,6 +42,7 @@ #include "../vmisc/vsettings.h" #include "../qmuparser/qmuparsererror.h" #include "../vgeometry/varc.h" +#include "../vgeometry/vsplinepath.h" #include "../core/vapplication.h" #include "../vpatterndb/calculator.h" diff --git a/src/libs/vtools/dialogs/tools/dialogspline.cpp b/src/libs/vtools/dialogs/tools/dialogspline.cpp index 0af494282..ed6913d19 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogspline.cpp @@ -30,8 +30,10 @@ #include "ui_dialogspline.h" #include "../vgeometry/vpointf.h" +#include "../vgeometry/vspline.h" #include "../vpatterndb/vcontainer.h" #include "../../visualization/vistoolspline.h" + #include //--------------------------------------------------------------------------------------------------------------------- @@ -41,8 +43,7 @@ * @param parent parent widget */ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogSpline), angle1(0), angle2(0), kAsm1(1), kAsm2(1), - kCurve(1) + :DialogTool(data, toolId, parent), ui(new Ui::DialogSpline), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1) { ui->setupUi(this); InitOkCancelApply(ui); @@ -57,6 +58,13 @@ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidge this, &DialogSpline::PointNameChanged); vis = new VisToolSpline(data); + auto path = qobject_cast(vis); + SCASSERT(path != nullptr); + + auto scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + connect(scene, &VMainGraphicsScene::MouseLeftPressed, path, &VisToolSpline::MouseLeftPressed); + connect(scene, &VMainGraphicsScene::MouseLeftReleased, path, &VisToolSpline::MouseLeftReleased); } //--------------------------------------------------------------------------------------------------------------------- @@ -88,7 +96,7 @@ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type) { if (type == SceneObject::Point) { - VisToolSpline *path = qobject_cast(vis); + auto *path = qobject_cast(vis); SCASSERT(path != nullptr); switch (number) @@ -96,7 +104,7 @@ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type) case 0: if (SetObject(id, ui->comboBoxP1, tr("Select last point of curve"))) { - number++; + ++number; path->VisualMode(id); } break; @@ -104,29 +112,13 @@ void DialogSpline::ChosenObject(quint32 id, const SceneObject &type) { if (getCurrentObjectId(ui->comboBoxP1) != id) { - const QSharedPointer point = data->GeometricObject(id); - qint32 index = ui->comboBoxP4->findText(point->name()); - if ( index != -1 ) - { // -1 for not found - ui->comboBoxP4->setCurrentIndex(index); - emit ToolTip(""); - index = ui->comboBoxP1->currentIndex(); - quint32 p1Id = qvariant_cast(ui->comboBoxP1->itemData(index)); - - QPointF p1 = data->GeometricObject(p1Id)->toQPointF(); - QPointF p4 = data->GeometricObject(id)->toQPointF(); - - ui->spinBoxAngle1->setValue(static_cast(QLineF(p1, p4).angle())); - ui->spinBoxAngle2->setValue(static_cast(QLineF(p4, p1).angle())); + if (SetObject(id, ui->comboBoxP4, "")) + { + ++number; path->setObject4Id(id); path->RefreshGeometry(); prepare = true; - DialogAccepted(); - } - else - { - qWarning()<<"Can't find object by name"<name(); } } break; @@ -183,6 +175,32 @@ void DialogSpline::PointNameChanged() CheckState(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::ShowDialog(bool click) +{ + if (prepare && click) + { + const auto p1 = data->GeometricObject(getCurrentObjectId(ui->comboBoxP1)); + const auto p4 = data->GeometricObject(getCurrentObjectId(ui->comboBoxP4)); + + auto *path = qobject_cast(vis); + SCASSERT(path != nullptr); + + const QPointF p2 = path->GetP2(); + const QPointF p3 = path->GetP3(); + + VSpline spline(*p1, p2, p3, *p4, kCurve); + + ui->spinBoxAngle1->setValue(static_cast(spline.GetStartAngle())); + ui->spinBoxAngle2->setValue(static_cast(spline.GetEndAngle())); + + ui->doubleSpinBoxKasm1->setValue(spline.GetKasm1()); + ui->doubleSpinBoxKasm2->setValue(spline.GetKasm2()); + + DialogAccepted(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSpline::ShowVisualization() { diff --git a/src/libs/vtools/dialogs/tools/dialogspline.h b/src/libs/vtools/dialogs/tools/dialogspline.h index ce36e4bb0..2d899aa64 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.h +++ b/src/libs/vtools/dialogs/tools/dialogspline.h @@ -72,6 +72,7 @@ public: public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; virtual void PointNameChanged() Q_DECL_OVERRIDE; + virtual void ShowDialog(bool click) Q_DECL_OVERRIDE; protected: virtual void ShowVisualization() Q_DECL_OVERRIDE; /** diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp index 57b9a0bfd..2bb688d12 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp @@ -271,19 +271,7 @@ void DialogSplinePath::PathUpdated(const VSplinePath &path) //--------------------------------------------------------------------------------------------------------------------- void DialogSplinePath::ShowVisualization() { - if (prepare == false) - { - VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); - SCASSERT(scene != nullptr); - - VisToolSplinePath *visPath = qobject_cast(vis); - SCASSERT(visPath != nullptr); - - connect(scene, &VMainGraphicsScene::NewFactor, visPath, &Visualization::SetFactor); - scene->addItem(visPath); - visPath->setMode(Mode::Show); - visPath->RefreshGeometry(); - } + AddVisualization(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index c2cdec515..c95109718 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -349,6 +349,7 @@ inline void DialogTool::AddVisualization() scene->addItem(toolVis); } + toolVis->SetMode(Mode::Show); toolVis->RefreshGeometry(); } } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index ca01fb50b..6c32892c1 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -27,6 +27,8 @@ *************************************************************************/ #include "vabstractspline.h" +#include "../vwidgets/vcontrolpointspline.h" + #include const QString VAbstractSpline::TagName = QStringLiteral("spline"); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h index 54129b110..e6ca060ba 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h @@ -30,10 +30,11 @@ #define VABSTRACTSPLINE_H #include "../vdrawtool.h" -#include "../vwidgets/vcontrolpointspline.h" #include +class VControlPointSpline; + class VAbstractSpline:public VDrawTool, public QGraphicsPathItem { Q_OBJECT @@ -56,15 +57,6 @@ public slots: virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; void DetailsMode(bool mode); signals: - /** - * @brief RefreshLine refresh control line. - * @param indexSpline position spline in spline list. - * @param pos position point in spline. - * @param controlPoint new position control point. - * @param splinePoint new position spline point. - */ - void RefreshLine(const qint32 &indexSpline, SplinePointPosition pos, - const QPointF &controlPoint, const QPointF &splinePoint); /** * @brief setEnabledPoint disable control points. * @param enable enable or diasable points. diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp index b2ef1b955..729b8b804 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp @@ -31,6 +31,7 @@ #include "../../../dialogs/tools/dialogspline.h" #include "../../../undocommands/movespline.h" #include "../../../visualization/vistoolspline.h" +#include "../vwidgets/vcontrolpointspline.h" #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) # include "../vmisc/vmath.h" @@ -64,23 +65,20 @@ VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, co this->setAcceptHoverEvents(true); this->setPath(ToolPath()); - const QSharedPointer spl = VAbstractTool::data.GeometricObject(id); - VControlPointSpline *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, spl->GetP2(), - spl->GetP1().toQPointF(), *data->GetPatternUnit(), - this); + const auto spl = VAbstractTool::data.GeometricObject(id); + + auto *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, spl->GetP2(), + spl->GetP1().toQPointF(), *data->GetPatternUnit(), this); connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this, &VToolSpline::ControlPointChangePosition); - connect(this, &VToolSpline::RefreshLine, controlPoint1, &VControlPointSpline::RefreshLine); connect(this, &VToolSpline::setEnabledPoint, controlPoint1, &VControlPointSpline::setEnabledPoint); connect(controlPoint1, &VControlPointSpline::ShowContextMenu, this, &VToolSpline::contextMenuEvent); controlPoints.append(controlPoint1); - VControlPointSpline *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, spl->GetP3(), - spl->GetP4().toQPointF(), *data->GetPatternUnit(), - this); + auto *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, spl->GetP3(), + spl->GetP4().toQPointF(), *data->GetPatternUnit(), this); connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this, &VToolSpline::ControlPointChangePosition); - connect(this, &VToolSpline::RefreshLine, controlPoint2, &VControlPointSpline::RefreshLine); connect(this, &VToolSpline::setEnabledPoint, controlPoint2, &VControlPointSpline::setEnabledPoint); connect(controlPoint2, &VControlPointSpline::ShowContextMenu, this, &VToolSpline::contextMenuEvent); controlPoints.append(controlPoint2); @@ -488,6 +486,7 @@ void VToolSpline::SetVisualization() visual->SetKAsm1(spl->GetKasm1()); visual->SetKAsm2(spl->GetKasm2()); visual->SetKCurve(spl->GetKcurve()); + visual->SetMode(Mode::Show); visual->RefreshGeometry(); } } @@ -499,7 +498,7 @@ void VToolSpline::SetVisualization() void VToolSpline::RefreshGeometry() { // Very important to disable control points. Without it the pogram can't move the curve. - foreach (VControlPointSpline *point, controlPoints) + foreach (auto *point, controlPoints) { point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); } @@ -515,26 +514,27 @@ void VToolSpline::RefreshGeometry() this->setPath(ToolPath()); } - const QSharedPointer spl = VAbstractTool::data.GeometricObject(id); - QPointF splinePoint = VAbstractTool::data.GeometricObject(spl->GetP1().id())->toQPointF(); - QPointF controlPoint = spl->GetP2(); - emit RefreshLine(1, SplinePointPosition::FirstPoint, controlPoint, splinePoint); - splinePoint = VAbstractTool::data.GeometricObject(spl->GetP4().id())->toQPointF(); - controlPoint = spl->GetP3(); - emit RefreshLine(1, SplinePointPosition::LastPoint, controlPoint, splinePoint); - controlPoints[0]->blockSignals(true); controlPoints[1]->blockSignals(true); - controlPoints[0]->setPos(spl->GetP2()); - controlPoints[1]->setPos(spl->GetP3()); + const auto spl = VAbstractTool::data.GeometricObject(id); + + { + const QPointF splinePoint = VAbstractTool::data.GeometricObject(spl->GetP1().id())->toQPointF(); + controlPoints[0]->RefreshCtrlPoint(1, SplinePointPosition::FirstPoint, spl->GetP2(), splinePoint); + } + + { + const QPointF splinePoint = VAbstractTool::data.GeometricObject(spl->GetP4().id())->toQPointF(); + controlPoints[1]->RefreshCtrlPoint(1, SplinePointPosition::LastPoint, spl->GetP3(), splinePoint); + } controlPoints[0]->blockSignals(false); controlPoints[1]->blockSignals(false); SetVisualization(); - foreach (VControlPointSpline *point, controlPoints) + foreach (auto *point, controlPoints) { point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h index 19d4a937f..0204e4c69 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h @@ -31,6 +31,8 @@ #include "vabstractspline.h" +class VSpline; + /** * @brief The VToolSpline class tool for creation spline. I mean bezier curve. */ diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp index adef7f429..04ec5fcb0 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -30,6 +30,7 @@ #include "../../../dialogs/tools/dialogsplinepath.h" #include "../../../undocommands/movesplinepath.h" #include "../../../visualization/vistoolsplinepath.h" +#include "../vwidgets/vcontrolpointspline.h" #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) # include "../vmisc/vmath.h" @@ -66,12 +67,10 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3 for (qint32 i = 1; i<=splPath->Count(); ++i) { VSpline spl = splPath->GetSpline(i); - VControlPointSpline *controlPoint = new VControlPointSpline(i, SplinePointPosition::FirstPoint, spl.GetP2(), - spl.GetP1().toQPointF(), *data->GetPatternUnit(), - this); + auto *controlPoint = new VControlPointSpline(i, SplinePointPosition::FirstPoint, spl.GetP2(), + spl.GetP1().toQPointF(), *data->GetPatternUnit(), this); connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this, &VToolSplinePath::ControlPointChangePosition); - connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine); connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint); connect(controlPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSplinePath::contextMenuEvent); controlPoints.append(controlPoint); @@ -80,7 +79,6 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3 *data->GetPatternUnit(), this); connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this, &VToolSplinePath::ControlPointChangePosition); - connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine); connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint); connect(controlPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSplinePath::contextMenuEvent); controlPoints.append(controlPoint); @@ -559,7 +557,7 @@ void VToolSplinePath::SetVisualization() QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); visual->setPath(*splPath.data()); - visual->setMode(Mode::Show); + visual->SetMode(Mode::Show); visual->RefreshGeometry(); } } @@ -571,7 +569,7 @@ void VToolSplinePath::SetVisualization() void VToolSplinePath::RefreshGeometry() { // Very important to disable control points. Without it the pogram can't move the curve. - foreach (VControlPointSpline *point, controlPoints) + foreach (auto *point, controlPoints) { point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); } @@ -584,26 +582,29 @@ void VToolSplinePath::RefreshGeometry() { this->setPath(ToolPath()); } + this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); - const QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); + + const auto splPath = VAbstractTool::data.GeometricObject(id); for (qint32 i = 1; i<=splPath->Count(); ++i) { - VSpline spl = splPath->GetSpline(i); - QPointF splinePoint = spl.GetP1().toQPointF(); - QPointF controlPoint = spl.GetP2(); - emit RefreshLine(i, SplinePointPosition::FirstPoint, controlPoint, splinePoint); - splinePoint = spl.GetP4().toQPointF(); - controlPoint = spl.GetP3(); - emit RefreshLine(i, SplinePointPosition::LastPoint, controlPoint, splinePoint); - - qint32 j = i*2; + const qint32 j = i*2; controlPoints[j-2]->blockSignals(true); controlPoints[j-1]->blockSignals(true); - controlPoints[j-2]->setPos(spl.GetP2()); - controlPoints[j-1]->setPos(spl.GetP3()); + const auto spl = splPath->GetSpline(i); + + { + const auto splinePoint = spl.GetP1().toQPointF(); + controlPoints[j-2]->RefreshCtrlPoint(i, SplinePointPosition::FirstPoint, spl.GetP2(), splinePoint); + } + + { + const auto splinePoint = spl.GetP4().toQPointF(); + controlPoints[j-1]->RefreshCtrlPoint(i, SplinePointPosition::LastPoint, spl.GetP3(), splinePoint); + } controlPoints[j-2]->blockSignals(false); controlPoints[j-1]->blockSignals(false); @@ -611,7 +612,7 @@ void VToolSplinePath::RefreshGeometry() SetVisualization(); - foreach (VControlPointSpline *point, controlPoints) + foreach (auto *point, controlPoints) { point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h index f09e09233..ab6ca7db6 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h @@ -31,6 +31,10 @@ #include "vabstractspline.h" +class VSplinePath; +class VSplinePoint; +class VSpline; + /** * @brief The VToolSplinePath class tool for creation spline path. */ diff --git a/src/libs/vtools/visualization/vistoolspline.cpp b/src/libs/vtools/visualization/vistoolspline.cpp index 229c959ed..91ebe9da6 100644 --- a/src/libs/vtools/visualization/vistoolspline.cpp +++ b/src/libs/vtools/visualization/vistoolspline.cpp @@ -30,17 +30,40 @@ #include "../../vgeometry/vpointf.h" #include "../../vgeometry/vspline.h" #include "../../vpatterndb/vcontainer.h" +#include "../vwidgets/vcontrolpointspline.h" const int EMPTY_ANGLE = -1; //--------------------------------------------------------------------------------------------------------------------- VisToolSpline::VisToolSpline(const VContainer *data, QGraphicsItem *parent) - : VisPath(data, parent), object4Id(NULL_ID), lineP1(nullptr), lineP4(nullptr), line(nullptr), angle1(EMPTY_ANGLE), - angle2(EMPTY_ANGLE), kAsm1(1), kAsm2(1), kCurve(1) + : VisPath(data, parent), + object4Id(NULL_ID), + lineP1(nullptr), + lineP4(nullptr), + line(nullptr), + angle1(EMPTY_ANGLE), + angle2(EMPTY_ANGLE), + kAsm1(1), + kAsm2(1), + kCurve(1), + isLeftMousePressed(false), + p2Selected(false), + p3Selected(false), + p2(), + p3(), + controlPoints() { lineP1 = InitPoint(supportColor, this); lineP4 = InitPoint(supportColor, this); //-V656 line = InitItem(mainColor, this); + + auto *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, *data->GetPatternUnit(), this); + controlPoint1->hide(); + controlPoints.append(controlPoint1); + + auto *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, *data->GetPatternUnit(), this); + controlPoint2->hide(); + controlPoints.append(controlPoint2); } //--------------------------------------------------------------------------------------------------------------------- @@ -52,21 +75,54 @@ void VisToolSpline::RefreshGeometry() { if (object1Id > NULL_ID) { - const QSharedPointer first = Visualization::data->GeometricObject(object1Id); + const auto first = Visualization::data->GeometricObject(object1Id); DrawPoint(lineP1, first->toQPointF(), supportColor); + if (mode == Mode::Creation) + { + if (isLeftMousePressed && not p2Selected) + { + p2 = Visualization::scenePos; + controlPoints[0]->RefreshCtrlPoint(1, SplinePointPosition::FirstPoint, p2, first->toQPointF()); + controlPoints[0]->show(); + } + else + { + p2Selected = true; + } + } + if (object4Id <= NULL_ID) { - DrawLine(line, QLineF(first->toQPointF(), Visualization::scenePos), mainColor); + VSpline spline(*first, p2, Visualization::scenePos, VPointF(Visualization::scenePos), kCurve); + DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); } else { - const QSharedPointer second = Visualization::data->GeometricObject(object4Id); + const auto second = Visualization::data->GeometricObject(object4Id); DrawPoint(lineP4, second->toQPointF(), supportColor); + if (mode == Mode::Creation) + { + if (isLeftMousePressed && not p3Selected) + { + QLineF ctrlLine (second->toQPointF(), Visualization::scenePos); + ctrlLine.setAngle(ctrlLine.angle()+180); + p3 = ctrlLine.p2(); + + controlPoints[1]->RefreshCtrlPoint(1, SplinePointPosition::LastPoint, p3, second->toQPointF()); + controlPoints[1]->show(); + } + else + { + p3Selected = true; + } + } + if (qFuzzyCompare(angle1, EMPTY_ANGLE) || qFuzzyCompare(angle2, EMPTY_ANGLE)) { - DrawLine(line, QLineF(first->toQPointF(), second->toQPointF()), mainColor); + VSpline spline(*first, p2, p3, *second, kCurve); + DrawPath(this, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); } else { @@ -112,3 +168,34 @@ void VisToolSpline::SetKCurve(const qreal &value) { kCurve = value; } + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VisToolSpline::GetP2() const +{ + return p2; +} + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VisToolSpline::GetP3() const +{ + return p3; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSpline::MouseLeftPressed() +{ + if (mode == Mode::Creation) + { + isLeftMousePressed = true; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSpline::MouseLeftReleased() +{ + if (mode == Mode::Creation) + { + isLeftMousePressed = false; + RefreshGeometry(); + } +} diff --git a/src/libs/vtools/visualization/vistoolspline.h b/src/libs/vtools/visualization/vistoolspline.h index fb6f780d3..ebd193cc8 100644 --- a/src/libs/vtools/visualization/vistoolspline.h +++ b/src/libs/vtools/visualization/vistoolspline.h @@ -31,6 +31,8 @@ #include "vispath.h" +class VControlPointSpline; + class VisToolSpline : public VisPath { Q_OBJECT @@ -47,8 +49,16 @@ public: void SetKAsm2(const qreal &value); void SetKCurve(const qreal &value); + QPointF GetP2() const; + QPointF GetP3() const; + virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolSpline)}; + +public slots: + void MouseLeftPressed(); + void MouseLeftReleased(); + protected: Q_DISABLE_COPY(VisToolSpline) quint32 object4Id; @@ -60,6 +70,15 @@ protected: qreal kAsm1; qreal kAsm2; qreal kCurve; + + bool isLeftMousePressed; + bool p2Selected; + bool p3Selected; + + QPointF p2; + QPointF p3; + + QVector controlPoints; }; #endif // VISTOOLSPLINE_H diff --git a/src/libs/vtools/visualization/vistoolsplinepath.cpp b/src/libs/vtools/visualization/vistoolsplinepath.cpp index d0f42833b..0e1af6107 100644 --- a/src/libs/vtools/visualization/vistoolsplinepath.cpp +++ b/src/libs/vtools/visualization/vistoolsplinepath.cpp @@ -30,8 +30,7 @@ //--------------------------------------------------------------------------------------------------------------------- VisToolSplinePath::VisToolSplinePath(const VContainer *data, QGraphicsItem *parent) - : VisPath(data, parent), points(QVector()), line(nullptr), path(VSplinePath()), - mode(Mode::Creation) + : VisPath(data, parent), points(QVector()), line(nullptr), path(VSplinePath()) { line = InitItem(mainColor, this); } @@ -107,18 +106,6 @@ VSplinePath VisToolSplinePath::getPath() return path; } -//--------------------------------------------------------------------------------------------------------------------- -Mode VisToolSplinePath::getMode() const -{ - return mode; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolSplinePath::setMode(const Mode &value) -{ - mode = value; -} - //--------------------------------------------------------------------------------------------------------------------- QGraphicsEllipseItem *VisToolSplinePath::getPoint(quint32 i) { diff --git a/src/libs/vtools/visualization/vistoolsplinepath.h b/src/libs/vtools/visualization/vistoolsplinepath.h index b1f69fb5d..d37178326 100644 --- a/src/libs/vtools/visualization/vistoolsplinepath.h +++ b/src/libs/vtools/visualization/vistoolsplinepath.h @@ -32,8 +32,6 @@ #include "vispath.h" #include "../../vgeometry/vsplinepath.h" -enum class Mode : char {Creation, Show}; - class VisToolSplinePath : public VisPath { Q_OBJECT @@ -49,8 +47,6 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolSplinePath)}; - Mode getMode() const; - void setMode(const Mode &value); signals: void PathChanged(const VSplinePath &path); @@ -59,7 +55,6 @@ protected: QVector points; QGraphicsLineItem *line; VSplinePath path; - Mode mode; QGraphicsEllipseItem * getPoint(quint32 i); }; diff --git a/src/libs/vtools/visualization/visualization.cpp b/src/libs/vtools/visualization/visualization.cpp index 021fe639a..a9f872d80 100644 --- a/src/libs/vtools/visualization/visualization.cpp +++ b/src/libs/vtools/visualization/visualization.cpp @@ -37,8 +37,16 @@ Q_LOGGING_CATEGORY(vVis, "v.visualization") //--------------------------------------------------------------------------------------------------------------------- Visualization::Visualization(const VContainer *data) - :QObject(), data(data), factor(VDrawTool::factor), scenePos(QPointF()), - mainColor(Qt::red), supportColor(Qt::magenta), lineStyle(Qt::SolidLine), object1Id(NULL_ID), toolTip(QString()) + :QObject(), + data(data), + factor(VDrawTool::factor), + scenePos(QPointF()), + mainColor(Qt::red), + supportColor(Qt::magenta), + lineStyle(Qt::SolidLine), + object1Id(NULL_ID), + toolTip(QString()), + mode(Mode::Creation) {} //--------------------------------------------------------------------------------------------------------------------- @@ -196,3 +204,16 @@ void Visualization::DrawPath(QGraphicsPathItem *pathItem, const QPainterPath &pa pathItem->setPath(path); pathItem->setVisible(true); } + + +//--------------------------------------------------------------------------------------------------------------------- +Mode Visualization::GetMode() const +{ + return mode; +} + +//--------------------------------------------------------------------------------------------------------------------- +void Visualization::SetMode(const Mode &value) +{ + mode = value; +} diff --git a/src/libs/vtools/visualization/visualization.h b/src/libs/vtools/visualization/visualization.h index a43f0bd36..e2cff633c 100644 --- a/src/libs/vtools/visualization/visualization.h +++ b/src/libs/vtools/visualization/visualization.h @@ -39,6 +39,8 @@ Q_DECLARE_LOGGING_CATEGORY(vVis) +enum class Mode : char {Creation, Show}; + class Visualization : public QObject { Q_OBJECT @@ -53,6 +55,9 @@ public: void setScenePos(const QPointF &value); virtual void VisualMode(const quint32 &pointId); void setMainColor(const QColor &value); + + Mode GetMode() const; + void SetMode(const Mode &value); signals: void ToolTip(const QString &toolTip); public slots: @@ -67,6 +72,7 @@ protected: Qt::PenStyle lineStyle; quint32 object1Id; QString toolTip; + Mode mode; virtual void InitPen()=0; virtual void AddOnScene()=0; diff --git a/src/libs/vwidgets/vcontrolpointspline.cpp b/src/libs/vwidgets/vcontrolpointspline.cpp index 1047608e9..2ed632242 100644 --- a/src/libs/vwidgets/vcontrolpointspline.cpp +++ b/src/libs/vwidgets/vcontrolpointspline.cpp @@ -36,6 +36,19 @@ #include "vmaingraphicsview.h" #include "vmaingraphicsscene.h" +//--------------------------------------------------------------------------------------------------------------------- +VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, Unit patternUnit, + QGraphicsItem *parent) + :QGraphicsEllipseItem(parent), + radius(CircleRadius()), + controlLine(nullptr), + indexSpline(indexSpline), + position(position), + patternUnit(patternUnit) +{ + Init(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VControlPointSpline constructor. @@ -48,28 +61,22 @@ VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, const QPointF &controlPoint, const QPointF &splinePoint, Unit patternUnit, QGraphicsItem *parent) - :QGraphicsEllipseItem(parent), radius(0), controlLine(nullptr), indexSpline(indexSpline), position(position), + :QGraphicsEllipseItem(parent), + radius(CircleRadius()), + controlLine(nullptr), + indexSpline(indexSpline), + position(position), patternUnit(patternUnit) { - //create circle - radius = (1.5/*mm*/ / 25.4) * PrintDPI; - QRectF rec = QRectF(0, 0, radius*2, radius*2); - rec.translate(-rec.center().x(), -rec.center().y()); - this->setRect(rec); - this->setPen(QPen(Qt::black, ToPixel(WidthHairLine(patternUnit), patternUnit))); - this->setBrush(QBrush(Qt::NoBrush)); + Init(); + this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setAcceptHoverEvents(true); this->setPos(controlPoint); - this->setZValue(100); - QPointF p1, p2; - VGObject::LineIntersectCircle(QPointF(), radius, QLineF( QPointF(), splinePoint-controlPoint), p1, p2); - controlLine = new QGraphicsLineItem(QLineF(splinePoint-controlPoint, p1), this); - controlLine->setPen(QPen(Qt::red, ToPixel(WidthHairLine(patternUnit), patternUnit))); - controlLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); + SetCtrlLine(controlPoint, splinePoint); } //--------------------------------------------------------------------------------------------------------------------- @@ -196,22 +203,44 @@ void VControlPointSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event emit ShowContextMenu(event); } +//--------------------------------------------------------------------------------------------------------------------- +void VControlPointSpline::Init() +{ + auto rec = QRectF(0, 0, radius*2, radius*2); + rec.translate(-rec.center().x(), -rec.center().y()); + this->setRect(rec); + this->setPen(QPen(Qt::black, ToPixel(WidthHairLine(patternUnit), patternUnit))); + this->setBrush(QBrush(Qt::NoBrush)); + this->setZValue(100); + + controlLine = new QGraphicsLineItem(this); + controlLine->setPen(QPen(Qt::red, ToPixel(WidthHairLine(patternUnit), patternUnit))); + controlLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VControlPointSpline::SetCtrlLine(const QPointF &controlPoint, const QPointF &splinePoint) +{ + QPointF p1, p2; + VGObject::LineIntersectCircle(QPointF(), radius, QLineF( QPointF(), splinePoint-controlPoint), p1, p2); + controlLine->setLine(QLineF(splinePoint-controlPoint, p1)); +} + //--------------------------------------------------------------------------------------------------------------------- /** - * @brief RefreshLine refresh line control point. + * @brief RefreshCtrlPoint refresh the control point. * @param indexSpline index spline in list. * @param pos position point in spline. * @param controlPoint control point. * @param splinePoint spline point. */ -void VControlPointSpline::RefreshLine(const qint32 &indexSpline, SplinePointPosition pos, - const QPointF &controlPoint, const QPointF &splinePoint) +void VControlPointSpline::RefreshCtrlPoint(const qint32 &indexSpline, SplinePointPosition pos, + const QPointF &controlPoint, const QPointF &splinePoint) { if (this->indexSpline == indexSpline && this->position == pos) { - QPointF p1, p2; - VGObject::LineIntersectCircle(QPointF(), radius, QLineF( QPointF(), splinePoint-controlPoint), p1, p2); - controlLine->setLine(QLineF(splinePoint-controlPoint, p1)); + this->setPos(controlPoint); + SetCtrlLine(controlPoint, splinePoint); } } diff --git a/src/libs/vwidgets/vcontrolpointspline.h b/src/libs/vwidgets/vcontrolpointspline.h index 21b9eb629..a15e33756 100644 --- a/src/libs/vwidgets/vcontrolpointspline.h +++ b/src/libs/vwidgets/vcontrolpointspline.h @@ -41,6 +41,8 @@ class VControlPointSpline : public QObject, public QGraphicsEllipseItem { Q_OBJECT public: + VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, Unit patternUnit, + QGraphicsItem * parent = nullptr); VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, const QPointF &controlPoint, const QPointF &splinePoint, Unit patternUnit, QGraphicsItem * parent = nullptr); virtual ~VControlPointSpline() Q_DECL_OVERRIDE; @@ -63,12 +65,12 @@ signals: */ void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); public slots: - void RefreshLine(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint, - const QPointF &splinePoint); + void RefreshCtrlPoint(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint, + const QPointF &splinePoint); void setEnabledPoint(bool enable); protected: /** @brief radius radius circle. */ - qreal radius; + const qreal radius; /** @brief controlLine pointer to line control point. */ QGraphicsLineItem *controlLine; @@ -88,6 +90,16 @@ private: SplinePointPosition position; Unit patternUnit; + + inline qreal CircleRadius() const; + void Init(); + void SetCtrlLine(const QPointF &controlPoint, const QPointF &splinePoint); }; +//--------------------------------------------------------------------------------------------------------------------- +qreal VControlPointSpline::CircleRadius() const +{ + return (1.5/*mm*/ / 25.4) * PrintDPI; +} + #endif // VCONTROLPOINTSPLINE_H diff --git a/src/libs/vwidgets/vmaingraphicsscene.cpp b/src/libs/vwidgets/vmaingraphicsscene.cpp index 2642ddc4f..b0c6f709a 100644 --- a/src/libs/vwidgets/vmaingraphicsscene.cpp +++ b/src/libs/vwidgets/vmaingraphicsscene.cpp @@ -74,7 +74,11 @@ void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event) */ void VMainGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { - emit mousePress(event->scenePos()); + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) + { + emit MouseLeftPressed(); + } + QGraphicsScene::mousePressEvent(event); if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier) { @@ -86,6 +90,16 @@ void VMainGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event) } } +//--------------------------------------------------------------------------------------------------------------------- +void VMainGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) + { + emit MouseLeftReleased(); + } + QGraphicsScene::mouseReleaseEvent(event); +} + //--------------------------------------------------------------------------------------------------------------------- void VMainGraphicsScene::InitOrigins() { diff --git a/src/libs/vwidgets/vmaingraphicsscene.h b/src/libs/vwidgets/vmaingraphicsscene.h index faa9fbd4b..20526b9d2 100644 --- a/src/libs/vwidgets/vmaingraphicsscene.h +++ b/src/libs/vwidgets/vmaingraphicsscene.h @@ -61,17 +61,17 @@ public slots: protected: virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE; virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE; signals: /** * @brief mouseMove send new mouse position. * @param scenePos new mouse position. */ void mouseMove(const QPointF &scenePos); - /** - * @brief mousePress send new mouse press position. - * @param scenePos new mouse press position. - */ - void mousePress(QPointF scenePos); + + void MouseLeftPressed(); + void MouseLeftReleased(); + /** * @brief ChoosedObject send option choosed object. * @param id object id. From 6dd26ddd73a266058b95b56bd8968ab910b9446f Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 12 Feb 2016 20:31:08 +0200 Subject: [PATCH 04/10] Refactoring. Use qFuzzyIsNull. --HG-- branch : feature --- src/libs/vtools/visualization/vistoolendline.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/vtools/visualization/vistoolendline.cpp b/src/libs/vtools/visualization/vistoolendline.cpp index 779bf342e..dcdde7a83 100644 --- a/src/libs/vtools/visualization/vistoolendline.cpp +++ b/src/libs/vtools/visualization/vistoolendline.cpp @@ -51,7 +51,7 @@ void VisToolEndLine::RefreshGeometry() { const QSharedPointer first = Visualization::data->GeometricObject(object1Id); QLineF line; - if (qFuzzyCompare(1 + length, 1 + 0)) + if (qFuzzyIsNull(length)) { line = QLineF(first->toQPointF(), Ray(first->toQPointF())); } From 1924b30f6f57231857a8953a780378d7a91ee1e7 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 12 Feb 2016 20:32:31 +0200 Subject: [PATCH 05/10] Don't show control points if too close to start and end points. --HG-- branch : feature --- .../vtools/visualization/vistoolspline.cpp | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/libs/vtools/visualization/vistoolspline.cpp b/src/libs/vtools/visualization/vistoolspline.cpp index 91ebe9da6..6f276e644 100644 --- a/src/libs/vtools/visualization/vistoolspline.cpp +++ b/src/libs/vtools/visualization/vistoolspline.cpp @@ -73,6 +73,9 @@ VisToolSpline::~VisToolSpline() //--------------------------------------------------------------------------------------------------------------------- void VisToolSpline::RefreshGeometry() { + //Radius of point circle, but little bigger. Need handle with hover sizes. + const static qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; + if (object1Id > NULL_ID) { const auto first = Visualization::data->GeometricObject(object1Id); @@ -84,7 +87,14 @@ void VisToolSpline::RefreshGeometry() { p2 = Visualization::scenePos; controlPoints[0]->RefreshCtrlPoint(1, SplinePointPosition::FirstPoint, p2, first->toQPointF()); - controlPoints[0]->show(); + + if (not controlPoints[0]->isVisible()) + { + if (QLineF(first->toQPointF(), p2).length() > radius) + { + controlPoints[0]->show(); + } + } } else { @@ -109,9 +119,15 @@ void VisToolSpline::RefreshGeometry() QLineF ctrlLine (second->toQPointF(), Visualization::scenePos); ctrlLine.setAngle(ctrlLine.angle()+180); p3 = ctrlLine.p2(); - controlPoints[1]->RefreshCtrlPoint(1, SplinePointPosition::LastPoint, p3, second->toQPointF()); - controlPoints[1]->show(); + + if (not controlPoints[1]->isVisible()) + { + if (QLineF(second->toQPointF(), p3).length() > radius) + { + controlPoints[1]->show(); + } + } } else { From 0405a54bf8f867f0ca31337bcbb31b945ab2008b Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 12 Feb 2016 21:43:33 +0200 Subject: [PATCH 06/10] Removed unused QGraphicsLineItem item. --HG-- branch : feature --- src/libs/vtools/visualization/vistoolspline.cpp | 14 ++++++-------- src/libs/vtools/visualization/vistoolspline.h | 5 ++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/libs/vtools/visualization/vistoolspline.cpp b/src/libs/vtools/visualization/vistoolspline.cpp index 6f276e644..2b731e44d 100644 --- a/src/libs/vtools/visualization/vistoolspline.cpp +++ b/src/libs/vtools/visualization/vistoolspline.cpp @@ -38,9 +38,8 @@ const int EMPTY_ANGLE = -1; VisToolSpline::VisToolSpline(const VContainer *data, QGraphicsItem *parent) : VisPath(data, parent), object4Id(NULL_ID), - lineP1(nullptr), - lineP4(nullptr), - line(nullptr), + point1(nullptr), + point4(nullptr), angle1(EMPTY_ANGLE), angle2(EMPTY_ANGLE), kAsm1(1), @@ -53,9 +52,8 @@ VisToolSpline::VisToolSpline(const VContainer *data, QGraphicsItem *parent) p3(), controlPoints() { - lineP1 = InitPoint(supportColor, this); - lineP4 = InitPoint(supportColor, this); //-V656 - line = InitItem(mainColor, this); + point1 = InitPoint(supportColor, this); + point4 = InitPoint(supportColor, this); //-V656 auto *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, *data->GetPatternUnit(), this); controlPoint1->hide(); @@ -79,7 +77,7 @@ void VisToolSpline::RefreshGeometry() if (object1Id > NULL_ID) { const auto first = Visualization::data->GeometricObject(object1Id); - DrawPoint(lineP1, first->toQPointF(), supportColor); + DrawPoint(point1, first->toQPointF(), supportColor); if (mode == Mode::Creation) { @@ -110,7 +108,7 @@ void VisToolSpline::RefreshGeometry() else { const auto second = Visualization::data->GeometricObject(object4Id); - DrawPoint(lineP4, second->toQPointF(), supportColor); + DrawPoint(point4, second->toQPointF(), supportColor); if (mode == Mode::Creation) { diff --git a/src/libs/vtools/visualization/vistoolspline.h b/src/libs/vtools/visualization/vistoolspline.h index ebd193cc8..531619efc 100644 --- a/src/libs/vtools/visualization/vistoolspline.h +++ b/src/libs/vtools/visualization/vistoolspline.h @@ -62,9 +62,8 @@ public slots: protected: Q_DISABLE_COPY(VisToolSpline) quint32 object4Id; - QGraphicsEllipseItem *lineP1; - QGraphicsEllipseItem *lineP4; - QGraphicsLineItem *line; + QGraphicsEllipseItem *point1; + QGraphicsEllipseItem *point4; qreal angle1; qreal angle2; qreal kAsm1; From e68c64e8f1856491eb80e11a390d5eebb5a69193 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 13 Feb 2016 18:24:32 +0200 Subject: [PATCH 07/10] Implementation for tool Spline path. --HG-- branch : feature --- .../vtools/dialogs/tools/dialogsplinepath.cpp | 9 +- .../visualization/vistoolsplinepath.cpp | 213 +++++++++++++++--- .../vtools/visualization/vistoolsplinepath.h | 16 +- 3 files changed, 203 insertions(+), 35 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp index 2bb688d12..f53504de0 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp @@ -61,6 +61,13 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, const quint32 &toolId this, &DialogSplinePath::KAsm2Changed); vis = new VisToolSplinePath(data); + auto path = qobject_cast(vis); + SCASSERT(path != nullptr); + + auto scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + connect(scene, &VMainGraphicsScene::MouseLeftPressed, path, &VisToolSplinePath::MouseLeftPressed); + connect(scene, &VMainGraphicsScene::MouseLeftReleased, path, &VisToolSplinePath::MouseLeftReleased); } //--------------------------------------------------------------------------------------------------------------------- @@ -126,7 +133,7 @@ void DialogSplinePath::ChosenObject(quint32 id, const SceneObject &type) SavePath(); - VisToolSplinePath *visPath = qobject_cast(vis); + auto visPath = qobject_cast(vis); SCASSERT(visPath != nullptr); visPath->setPath(path); diff --git a/src/libs/vtools/visualization/vistoolsplinepath.cpp b/src/libs/vtools/visualization/vistoolsplinepath.cpp index 0e1af6107..3618257d9 100644 --- a/src/libs/vtools/visualization/vistoolsplinepath.cpp +++ b/src/libs/vtools/visualization/vistoolsplinepath.cpp @@ -27,18 +27,27 @@ *************************************************************************/ #include "vistoolsplinepath.h" +#include "../vwidgets/vcontrolpointspline.h" //--------------------------------------------------------------------------------------------------------------------- VisToolSplinePath::VisToolSplinePath(const VContainer *data, QGraphicsItem *parent) - : VisPath(data, parent), points(QVector()), line(nullptr), path(VSplinePath()) + : VisPath(data, parent), + points(QVector()), + ctrlPoints(QVector()), + newCurveSegment(nullptr), + path(VSplinePath()), + isLeftMousePressed(false), + pointSelected(false), + ctrlPoint() { - line = InitItem(mainColor, this); + newCurveSegment = InitItem(mainColor, this); } //--------------------------------------------------------------------------------------------------------------------- VisToolSplinePath::~VisToolSplinePath() { - qDeleteAll(points.begin(), points.end()); + qDeleteAll(ctrlPoints); + qDeleteAll(points); } //--------------------------------------------------------------------------------------------------------------------- @@ -46,41 +55,25 @@ void VisToolSplinePath::RefreshGeometry() { if (path.CountPoint() > 0) { - QVector pathPoints = path.GetSplinePath(); - if (path.CountPoint() == 1) + const QVector pathPoints = path.GetSplinePath(); + const int size = pathPoints.size(); + + for (int i = 0; i < size; ++i) { - QGraphicsEllipseItem *point = this->getPoint(0); - DrawPoint(point, pathPoints.at(0).P().toQPointF(), supportColor); - - if (mode == Mode::Creation) - { - QLineF sceneLine = QLineF(pathPoints.at(0).P().toQPointF(), Visualization::scenePos); - DrawLine(line, sceneLine, mainColor, lineStyle); - - path[0].SetAngle2(sceneLine.angle()); - emit PathChanged(path); - } + QGraphicsEllipseItem *point = this->getPoint(static_cast(i)); + DrawPoint(point, pathPoints.at(i).P().toQPointF(), supportColor); } - else + + if (mode == Mode::Creation) { - for (int i = 0; i < pathPoints.size(); ++i) - { - QGraphicsEllipseItem *point = this->getPoint(static_cast(i)); - DrawPoint(point, pathPoints.at(i).P().toQPointF(), supportColor); - } - - if (mode == Mode::Creation) - { - QLineF sceneLine = QLineF(pathPoints.at(pathPoints.size() - 1).P().toQPointF(), - Visualization::scenePos); - DrawLine(line, sceneLine, mainColor, lineStyle); - - path[pathPoints.size() - 1].SetAngle2(sceneLine.angle()); - emit PathChanged(path); - } + Creating(pathPoints.at(size-1).P().toQPointF(), size); + } + if (size > 1) + { DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); } + if (path.CountPoint() < 3) { Visualization::toolTip = tr("Curved path: select three or more points"); @@ -106,6 +99,25 @@ VSplinePath VisToolSplinePath::getPath() return path; } +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSplinePath::MouseLeftPressed() +{ + if (mode == Mode::Creation) + { + isLeftMousePressed = true; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSplinePath::MouseLeftReleased() +{ + if (mode == Mode::Creation) + { + isLeftMousePressed = false; + RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- QGraphicsEllipseItem *VisToolSplinePath::getPoint(quint32 i) { @@ -115,9 +127,144 @@ QGraphicsEllipseItem *VisToolSplinePath::getPoint(quint32 i) } else { - QGraphicsEllipseItem * point = InitPoint(supportColor, this); + pointSelected = false; + + auto point = InitPoint(supportColor, this); points.append(point); + + if (points.size() == 1) + { + auto *controlPoint1 = new VControlPointSpline(points.size(), SplinePointPosition::FirstPoint, + *Visualization::data->GetPatternUnit(), + this); + controlPoint1->hide(); + ctrlPoints.append(controlPoint1); + } + else + { + auto *controlPoint1 = new VControlPointSpline(points.size()-1, SplinePointPosition::LastPoint, + *Visualization::data->GetPatternUnit(), + this); + controlPoint1->hide(); + ctrlPoints.append(controlPoint1); + + auto *controlPoint2 = new VControlPointSpline(points.size(), SplinePointPosition::FirstPoint, + *Visualization::data->GetPatternUnit(), + this); + controlPoint2->hide(); + ctrlPoints.append(controlPoint2); + } + return point; } return nullptr; } + +//--------------------------------------------------------------------------------------------------------------------- +QSharedPointer VisToolSplinePath::NewCurveSegmen(const QPointF &pSpl, int size) +{ + auto spline = QSharedPointer(new VSpline(VPointF(pSpl), ctrlPoint, Visualization::scenePos, + VPointF(Visualization::scenePos), path.GetKCurve())); + + if (size == 1) + { + path[size-1].SetAngle2(spline->GetStartAngle()); + path[size-1].SetKAsm2(spline->GetKasm1()); + emit PathChanged(path); + } + else + { + path[size-1].SetAngle2(spline->GetStartAngle()); + path[size-1].SetKAsm1(spline->GetKasm1()); + path[size-1].SetKAsm2(spline->GetKasm1()); + emit PathChanged(path); + } + + return spline; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSplinePath::Creating(const QPointF &pSpl, int size) +{ + //Radius of point circle, but little bigger. Need handle with hover sizes. + const static qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; + + int lastPoint = 0; + int preLastPoint = 0; + + if (size > 1) + { + lastPoint = (size - 1) * 2; + preLastPoint = lastPoint - 1; + } + + if (isLeftMousePressed && not pointSelected) + { + newCurveSegment->hide(); + + ctrlPoint = Visualization::scenePos; + + if (not ctrlPoints[lastPoint]->isVisible()) + { + if (QLineF(pSpl, ctrlPoint).length() > radius) + { + if (size == 1) + { + ctrlPoints[lastPoint]->show(); + } + else + { + ctrlPoints[preLastPoint]->show(); + ctrlPoints[lastPoint]->show(); + } + } + else + { + ctrlPoint = pSpl; + } + } + + if (size == 1) + { + ctrlPoints[lastPoint]->RefreshCtrlPoint(size, SplinePointPosition::FirstPoint, ctrlPoint, pSpl); + } + else + { + QLineF ctrlLine (pSpl, Visualization::scenePos); + ctrlLine.setAngle(ctrlLine.angle()+180); + + ctrlPoints[preLastPoint]->RefreshCtrlPoint(size-1, SplinePointPosition::LastPoint, ctrlLine.p2(), pSpl); + ctrlPoints[lastPoint]->RefreshCtrlPoint(size, SplinePointPosition::FirstPoint, ctrlPoint, pSpl); + } + + VSpline spline(VPointF(pSpl), ctrlPoint, Visualization::scenePos, + VPointF(Visualization::scenePos), path.GetKCurve()); + + if (size == 1) + { + path[size-1].SetAngle2(spline.GetStartAngle()); + path[size-1].SetKAsm2(spline.GetKasm1()); + emit PathChanged(path); + } + else + { + path[size-1].SetAngle2(spline.GetStartAngle()); + path[size-1].SetKAsm1(spline.GetKasm1()); + path[size-1].SetKAsm2(spline.GetKasm1()); + emit PathChanged(path); + } + } + else + { + pointSelected = true; + + VSpline spline(VPointF(pSpl), ctrlPoint, Visualization::scenePos, + VPointF(Visualization::scenePos), path.GetKCurve()); + + path[size-1].SetAngle2(spline.GetStartAngle()); + path[size-1].SetKAsm2(spline.GetKasm1()); + emit PathChanged(path); + + DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); + } +} diff --git a/src/libs/vtools/visualization/vistoolsplinepath.h b/src/libs/vtools/visualization/vistoolsplinepath.h index d37178326..309f57127 100644 --- a/src/libs/vtools/visualization/vistoolsplinepath.h +++ b/src/libs/vtools/visualization/vistoolsplinepath.h @@ -32,6 +32,8 @@ #include "vispath.h" #include "../../vgeometry/vsplinepath.h" +class VControlPointSpline; + class VisToolSplinePath : public VisPath { Q_OBJECT @@ -50,13 +52,25 @@ public: signals: void PathChanged(const VSplinePath &path); +public slots: + void MouseLeftPressed(); + void MouseLeftReleased(); + protected: Q_DISABLE_COPY(VisToolSplinePath) QVector points; - QGraphicsLineItem *line; + QVector ctrlPoints; + QGraphicsPathItem *newCurveSegment; VSplinePath path; + bool isLeftMousePressed; + bool pointSelected; + + QPointF ctrlPoint; + QGraphicsEllipseItem * getPoint(quint32 i); + QSharedPointer NewCurveSegmen(const QPointF &pSpl, int size); + void Creating(const QPointF &pSpl, int size); }; #endif // VISTOOLSPLINEPATH_H From b124b8402e88f2cb2607ed8234270dc83cd759e8 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 13 Feb 2016 18:30:21 +0200 Subject: [PATCH 08/10] The control point should be on some distance before we will begin count this distance. --HG-- branch : feature --- src/libs/vtools/visualization/vistoolspline.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libs/vtools/visualization/vistoolspline.cpp b/src/libs/vtools/visualization/vistoolspline.cpp index 2b731e44d..8ac602a4e 100644 --- a/src/libs/vtools/visualization/vistoolspline.cpp +++ b/src/libs/vtools/visualization/vistoolspline.cpp @@ -92,6 +92,10 @@ void VisToolSpline::RefreshGeometry() { controlPoints[0]->show(); } + else + { + p2 = first->toQPointF(); + } } } else @@ -125,6 +129,10 @@ void VisToolSpline::RefreshGeometry() { controlPoints[1]->show(); } + else + { + p3 = second->toQPointF(); + } } } else From 35b9dea4b2ab3950f993f44f5bcb23cb159742d3 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 13 Feb 2016 23:39:47 +0200 Subject: [PATCH 09/10] Fixes creating spline path. --HG-- branch : feature --- src/libs/vgeometry/vsplinepoint.cpp | 4 +- .../vtools/dialogs/tools/dialogspline.cpp | 3 +- .../vtools/dialogs/tools/dialogsplinepath.cpp | 5 +- .../visualization/vistoolsplinepath.cpp | 79 ++++++++++++------- .../vtools/visualization/vistoolsplinepath.h | 1 - 5 files changed, 56 insertions(+), 36 deletions(-) diff --git a/src/libs/vgeometry/vsplinepoint.cpp b/src/libs/vgeometry/vsplinepoint.cpp index 0168b0312..3f89f2805 100644 --- a/src/libs/vgeometry/vsplinepoint.cpp +++ b/src/libs/vgeometry/vsplinepoint.cpp @@ -87,7 +87,7 @@ void VSplinePoint::SetAngle1(const qreal &value) line.setAngle(value); d->angle1 = line.angle(); - line.setAngle(value+180); + line.setAngle(d->angle1+180); d->angle2 = line.angle(); } @@ -102,7 +102,7 @@ void VSplinePoint::SetAngle2(const qreal &value) line.setAngle(value); d->angle2 = line.angle(); - line.setAngle(value-180); + line.setAngle(d->angle2+180); d->angle1 = line.angle(); } diff --git a/src/libs/vtools/dialogs/tools/dialogspline.cpp b/src/libs/vtools/dialogs/tools/dialogspline.cpp index ed6913d19..cf91e8bf0 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogspline.cpp @@ -139,7 +139,7 @@ void DialogSpline::SaveData() kAsm2 = ui->doubleSpinBoxKasm2->value(); kCurve = ui->doubleSpinBoxKcurve->value(); - VisToolSpline *path = qobject_cast(vis); + auto path = qobject_cast(vis); SCASSERT(path != nullptr); path->setObject1Id(GetP1()); @@ -149,6 +149,7 @@ void DialogSpline::SaveData() path->SetKAsm1(kAsm1); path->SetKAsm2(kAsm2); path->SetKCurve(kCurve); + path->SetMode(Mode::Show); path->RefreshGeometry(); } diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp index f53504de0..dde11226a 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp @@ -95,7 +95,7 @@ void DialogSplinePath::SetPath(const VSplinePath &value) ui->listWidget->setFocus(Qt::OtherFocusReason); ui->doubleSpinBoxKcurve->setValue(path.GetKCurve()); - VisToolSplinePath *visPath = qobject_cast(vis); + auto visPath = qobject_cast(vis); SCASSERT(visPath != nullptr); visPath->setPath(path); ui->listWidget->blockSignals(false); @@ -155,9 +155,10 @@ void DialogSplinePath::SaveData() { SavePath(); - VisToolSplinePath *visPath = qobject_cast(vis); + auto visPath = qobject_cast(vis); SCASSERT(visPath != nullptr); visPath->setPath(path); + visPath->SetMode(Mode::Show); visPath->RefreshGeometry(); } diff --git a/src/libs/vtools/visualization/vistoolsplinepath.cpp b/src/libs/vtools/visualization/vistoolsplinepath.cpp index 3618257d9..c1b388ecb 100644 --- a/src/libs/vtools/visualization/vistoolsplinepath.cpp +++ b/src/libs/vtools/visualization/vistoolsplinepath.cpp @@ -66,6 +66,22 @@ void VisToolSplinePath::RefreshGeometry() if (mode == Mode::Creation) { + if (size > 1) + { + for (qint32 i = 1; i<=path.Count(); ++i) + { + const int preLastPoint = (path.Count() - 1) * 2; + const int lastPoint = preLastPoint + 1; + + VSpline spl = path.GetSpline(i); + + ctrlPoints[preLastPoint]->RefreshCtrlPoint(i, SplinePointPosition::FirstPoint, spl.GetP2(), + spl.GetP1().toQPointF()); + ctrlPoints[lastPoint]->RefreshCtrlPoint(i, SplinePointPosition::LastPoint, spl.GetP3(), + spl.GetP4().toQPointF()); + } + } + Creating(pathPoints.at(size-1).P().toQPointF(), size); } @@ -160,29 +176,6 @@ QGraphicsEllipseItem *VisToolSplinePath::getPoint(quint32 i) return nullptr; } -//--------------------------------------------------------------------------------------------------------------------- -QSharedPointer VisToolSplinePath::NewCurveSegmen(const QPointF &pSpl, int size) -{ - auto spline = QSharedPointer(new VSpline(VPointF(pSpl), ctrlPoint, Visualization::scenePos, - VPointF(Visualization::scenePos), path.GetKCurve())); - - if (size == 1) - { - path[size-1].SetAngle2(spline->GetStartAngle()); - path[size-1].SetKAsm2(spline->GetKasm1()); - emit PathChanged(path); - } - else - { - path[size-1].SetAngle2(spline->GetStartAngle()); - path[size-1].SetKAsm1(spline->GetKasm1()); - path[size-1].SetKAsm2(spline->GetKasm1()); - emit PathChanged(path); - } - - return spline; -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolSplinePath::Creating(const QPointF &pSpl, int size) { @@ -224,15 +217,15 @@ void VisToolSplinePath::Creating(const QPointF &pSpl, int size) } } + QLineF ctrlLine (pSpl, Visualization::scenePos); + ctrlLine.setAngle(ctrlLine.angle()+180); + if (size == 1) { ctrlPoints[lastPoint]->RefreshCtrlPoint(size, SplinePointPosition::FirstPoint, ctrlPoint, pSpl); } else { - QLineF ctrlLine (pSpl, Visualization::scenePos); - ctrlLine.setAngle(ctrlLine.angle()+180); - ctrlPoints[preLastPoint]->RefreshCtrlPoint(size-1, SplinePointPosition::LastPoint, ctrlLine.p2(), pSpl); ctrlPoints[lastPoint]->RefreshCtrlPoint(size, SplinePointPosition::FirstPoint, ctrlPoint, pSpl); } @@ -243,14 +236,32 @@ void VisToolSplinePath::Creating(const QPointF &pSpl, int size) if (size == 1) { path[size-1].SetAngle2(spline.GetStartAngle()); - path[size-1].SetKAsm2(spline.GetKasm1()); + if (ctrlPoint != pSpl) + { + path[size-1].SetKAsm2(spline.GetKasm1()); + } + else + { + path[size-1].SetKAsm2(0); + } emit PathChanged(path); } else { + const VSpline spl = path.GetSpline(size - 1); + VSpline preSpl(spl.GetP1(), spl.GetP2(), ctrlLine.p2(), VPointF(pSpl), path.GetKCurve()); + path[size-1].SetAngle2(spline.GetStartAngle()); - path[size-1].SetKAsm1(spline.GetKasm1()); - path[size-1].SetKAsm2(spline.GetKasm1()); + if (ctrlPoint != pSpl) + { + path[size-1].SetKAsm1(preSpl.GetKasm2()); + path[size-1].SetKAsm2(spline.GetKasm1()); + } + else + { + path[size-1].SetKAsm1(0); + path[size-1].SetKAsm2(0); + } emit PathChanged(path); } } @@ -262,7 +273,15 @@ void VisToolSplinePath::Creating(const QPointF &pSpl, int size) VPointF(Visualization::scenePos), path.GetKCurve()); path[size-1].SetAngle2(spline.GetStartAngle()); - path[size-1].SetKAsm2(spline.GetKasm1()); + + if (ctrlPoint != pSpl) + { + path[size-1].SetKAsm2(spline.GetKasm1()); + } + else + { + path[size-1].SetKAsm2(0); + } emit PathChanged(path); DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); diff --git a/src/libs/vtools/visualization/vistoolsplinepath.h b/src/libs/vtools/visualization/vistoolsplinepath.h index 309f57127..cbddfef70 100644 --- a/src/libs/vtools/visualization/vistoolsplinepath.h +++ b/src/libs/vtools/visualization/vistoolsplinepath.h @@ -69,7 +69,6 @@ protected: QPointF ctrlPoint; QGraphicsEllipseItem * getPoint(quint32 i); - QSharedPointer NewCurveSegmen(const QPointF &pSpl, int size); void Creating(const QPointF &pSpl, int size); }; From 6350d78ce460c9953ed62a559a8398c705437b5e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 13 Feb 2016 23:41:12 +0200 Subject: [PATCH 10/10] Changelog. --HG-- branch : feature --- ChangeLog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index e9b004218..442eafb15 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,5 @@ # Version 0.5.0 +- [#216] Better powerful way creation curved path. - Improved exporting to dxf. QPainterPath export as Polyline. - Show additional message dialog if measurements was changed. Related to issue [#440]. - [#132] Intersect Curves.