From cbf3e4d5dfc4a4f85e21c9d1012cd9e2ea2c21ec Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 30 Oct 2017 08:34:18 +0200 Subject: [PATCH] When create group selecting a control point should also select a curve. --HG-- branch : develop --- .../tools/drawTools/toolcurve/vabstractspline.cpp | 15 ++++++++++++++- .../tools/drawTools/toolcurve/vabstractspline.h | 2 ++ .../tools/drawTools/toolcurve/vtoolspline.cpp | 1 + .../tools/drawTools/toolcurve/vtoolsplinepath.cpp | 1 + .../tooldoublepoint/vtooldoublepoint.cpp | 2 +- .../toolsinglepoint/vtoolsinglepoint.cpp | 14 ++++++++++---- src/libs/vtools/tools/drawTools/vtoolline.cpp | 2 +- src/libs/vtools/tools/vtoolseamallowance.cpp | 2 +- src/libs/vwidgets/vcontrolpointspline.cpp | 3 +++ src/libs/vwidgets/vcontrolpointspline.h | 1 + src/libs/vwidgets/vgraphicssimpletextitem.cpp | 5 +++-- src/libs/vwidgets/vscenepoint.cpp | 3 ++- src/libs/vwidgets/vscenepoint.h | 2 ++ src/libs/vwidgets/vsimplecurve.cpp | 2 +- src/libs/vwidgets/vsimplepoint.cpp | 2 +- 15 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index c760fdd19..c8b2236ab 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -258,7 +258,7 @@ void VAbstractSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) */ QVariant VAbstractSpline::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { - if (change == QGraphicsItem::ItemSelectedChange) + if (change == QGraphicsItem::ItemSelectedHasChanged) { emit ChangedToolSelection(value.toBool(), m_id, m_id); } @@ -418,6 +418,19 @@ VSpline VAbstractSpline::CorrectedSpline(const VSpline &spline, const SplinePoin return spl; } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractSpline::CurveSelected(bool selected) +{ + setSelected(selected); + + foreach (auto *point, controlPoints) + { + point->blockSignals(true); + point->setSelected(selected); + point->blockSignals(false); + } +} + //--------------------------------------------------------------------------------------------------------------------- void VAbstractSpline::InitDefShape() { diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h index a94e98a83..14a02a721 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h @@ -103,6 +103,8 @@ signals: * @param enable enable or diasable points. */ void setEnabledPoint(bool enable); +protected slots: + void CurveSelected(bool selected); protected: /** * @brief controlPoints list pointers of control points. diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp index 3dff8fb29..1cc52ecca 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp @@ -97,6 +97,7 @@ VToolSpline::VToolSpline(VToolSplineInitData initData, QGraphicsItem *parent) connect(this, &VToolSpline::setEnabledPoint, cPoint, &VControlPointSpline::setEnabledPoint); connect(cPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSpline::contextMenuEvent); connect(cPoint, &VControlPointSpline::Released, this, &VToolSpline::CurveReleased); + connect(cPoint, &VControlPointSpline::Selected, this, &VToolSpline::CurveSelected); controlPoints.append(cPoint); }; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp index ec84a0f26..eae3b0b2a 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -102,6 +102,7 @@ VToolSplinePath::VToolSplinePath(const VToolSplinePathInitData &initData, QGraph connect(this, &VToolSplinePath::setEnabledPoint, cPoint, &VControlPointSpline::setEnabledPoint); connect(cPoint, &VControlPointSpline::ShowContextMenu, this, &VToolSplinePath::contextMenuEvent); connect(cPoint, &VControlPointSpline::Released, this, &VToolSplinePath::CurveReleased); + connect(cPoint, &VControlPointSpline::Selected, this, &VToolSplinePath::CurveSelected); controlPoints.append(cPoint); }; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp index 3432468f8..794b374e1 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp @@ -314,7 +314,7 @@ void VToolDoublePoint::UpdateNamePosition(quint32 id, const QPointF &pos) */ QVariant VToolDoublePoint::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { - if (change == QGraphicsItem::ItemSelectedChange) + if (change == QGraphicsItem::ItemSelectedHasChanged) { if (value == true) { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index a02276b2d..3533322fe 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -214,7 +214,9 @@ void VToolSinglePoint::PointChoosed() //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::PointSelected(bool selected) { + m_selectedFromChild = true; setSelected(selected); + m_selectedFromChild = false; } //--------------------------------------------------------------------------------------------------------------------- @@ -261,11 +263,15 @@ void VToolSinglePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event) */ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { - if (change == QGraphicsItem::ItemSelectedChange) + if (change == QGraphicsItem::ItemSelectedHasChanged) { - m_namePoint->blockSignals(true); - m_namePoint->setSelected(value.toBool()); - m_namePoint->blockSignals(false); + if (not m_selectedFromChild) + { + m_namePoint->blockSignals(true); + m_namePoint->setSelected(value.toBool()); + m_namePoint->blockSignals(false); + } + emit ChangedToolSelection(value.toBool(), m_id, m_id); } diff --git a/src/libs/vtools/tools/drawTools/vtoolline.cpp b/src/libs/vtools/tools/drawTools/vtoolline.cpp index 6e4453989..89a08f2e1 100644 --- a/src/libs/vtools/tools/drawTools/vtoolline.cpp +++ b/src/libs/vtools/tools/drawTools/vtoolline.cpp @@ -326,7 +326,7 @@ void VToolLine::RemoveReferens() */ QVariant VToolLine::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { - if (change == QGraphicsItem::ItemSelectedChange) + if (change == QGraphicsItem::ItemSelectedHasChanged) { emit ChangedToolSelection(value.toBool(), m_id, m_id); } diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 69d98e104..4aec2865f 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -1060,7 +1060,7 @@ QVariant VToolSeamAllowance::itemChange(QGraphicsItem::GraphicsItemChange change } } - if (change == QGraphicsItem::ItemSelectedChange) + if (change == QGraphicsItem::ItemSelectedHasChanged) { if (value == true) { diff --git a/src/libs/vwidgets/vcontrolpointspline.cpp b/src/libs/vwidgets/vcontrolpointspline.cpp index 8fd7e969f..02563e995 100644 --- a/src/libs/vwidgets/vcontrolpointspline.cpp +++ b/src/libs/vwidgets/vcontrolpointspline.cpp @@ -210,6 +210,9 @@ QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange chang } break; } + case QGraphicsItem::ItemSelectedHasChanged: + emit Selected(value.toBool()); + break; default: break; } diff --git a/src/libs/vwidgets/vcontrolpointspline.h b/src/libs/vwidgets/vcontrolpointspline.h index c1c381218..b85970c13 100644 --- a/src/libs/vwidgets/vcontrolpointspline.h +++ b/src/libs/vwidgets/vcontrolpointspline.h @@ -75,6 +75,7 @@ signals: */ void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); void Released(); + void Selected(bool selected); public slots: void RefreshCtrlPoint(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint, const QPointF &splinePoint, bool freeAngle = true, bool freeLength = true); diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index ee7e91335..26489f3db 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -192,11 +192,12 @@ QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QV changeFinished = true; } } - if (change == QGraphicsItem::ItemSelectedChange) + if (change == QGraphicsItem::ItemSelectedHasChanged) { + setFlag(QGraphicsItem::ItemIsFocusable, value.toBool()); emit PointSelected(value.toBool()); } - return QGraphicsItem::itemChange(change, value); + return QGraphicsSimpleTextItem::itemChange(change, value); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vscenepoint.cpp b/src/libs/vwidgets/vscenepoint.cpp index 3e5654ba1..6a6f1f07d 100644 --- a/src/libs/vwidgets/vscenepoint.cpp +++ b/src/libs/vwidgets/vscenepoint.cpp @@ -48,7 +48,8 @@ VScenePoint::VScenePoint(QGraphicsItem *parent) m_onlyPoint(false), m_isHovered(false), m_showLabel(true), - m_baseColor(Qt::black) + m_baseColor(Qt::black), + m_selectedFromChild(false) { m_namePoint = new VGraphicsSimpleTextItem(this); m_lineName = new VScaledLine(this); diff --git a/src/libs/vwidgets/vscenepoint.h b/src/libs/vwidgets/vscenepoint.h index 55be9e34e..08b019bb5 100644 --- a/src/libs/vwidgets/vscenepoint.h +++ b/src/libs/vwidgets/vscenepoint.h @@ -67,6 +67,8 @@ protected: /** @brief m_baseColor base color of point. */ QColor m_baseColor; + bool m_selectedFromChild; + virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE; virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE; diff --git a/src/libs/vwidgets/vsimplecurve.cpp b/src/libs/vwidgets/vsimplecurve.cpp index 86bbeb2f8..d1ffc0f07 100644 --- a/src/libs/vwidgets/vsimplecurve.cpp +++ b/src/libs/vwidgets/vsimplecurve.cpp @@ -146,7 +146,7 @@ void VSimpleCurve::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) //--------------------------------------------------------------------------------------------------------------------- QVariant VSimpleCurve::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { - if (change == QGraphicsItem::ItemSelectedChange) + if (change == QGraphicsItem::ItemSelectedHasChanged) { emit Selected(value.toBool(), id); } diff --git a/src/libs/vwidgets/vsimplepoint.cpp b/src/libs/vwidgets/vsimplepoint.cpp index 72b9ed871..be2e92d96 100644 --- a/src/libs/vwidgets/vsimplepoint.cpp +++ b/src/libs/vwidgets/vsimplepoint.cpp @@ -220,7 +220,7 @@ void VSimplePoint::keyReleaseEvent(QKeyEvent *event) //--------------------------------------------------------------------------------------------------------------------- QVariant VSimplePoint::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { - if (change == QGraphicsItem::ItemSelectedChange) + if (change == QGraphicsItem::ItemSelectedHasChanged) { m_namePoint->blockSignals(true); m_namePoint->setSelected(value.toBool());