From 185636a550341b4b7ce23d78ea75d3db12d677e3 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 27 Jul 2017 17:15:53 +0300 Subject: [PATCH] Fix bug with simple curve. It should be hovered only if mouse pointer above a path. --HG-- branch : develop --- src/libs/vwidgets/vcurvepathitem.cpp | 26 +++++++++++++++++++++++--- src/libs/vwidgets/vcurvepathitem.h | 2 ++ src/libs/vwidgets/vsimplecurve.cpp | 1 + 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/libs/vwidgets/vcurvepathitem.cpp b/src/libs/vwidgets/vcurvepathitem.cpp index 8891af042..f007e0466 100644 --- a/src/libs/vwidgets/vcurvepathitem.cpp +++ b/src/libs/vwidgets/vcurvepathitem.cpp @@ -35,14 +35,28 @@ //--------------------------------------------------------------------------------------------------------------------- VCurvePathItem::VCurvePathItem(QGraphicsItem *parent) : QGraphicsPathItem(parent), - m_directionArrows() + m_directionArrows(), + m_points() { } //--------------------------------------------------------------------------------------------------------------------- QPainterPath VCurvePathItem::shape() const { - QPainterPath itemPath = path(); + QPainterPath itemPath; + + if (not m_points.isEmpty()) + { + for (qint32 i = 0; i < m_points.count()-1; ++i) + { + itemPath.moveTo(m_points.at(i)); + itemPath.lineTo(m_points.at(i+1)); + } + } + else + { + itemPath = path(); + } const QPainterPath arrowsPath = VAbstractCurve::ShowDirection(m_directionArrows, ScaleWidth(VAbstractCurve::lengthCurveDirectionArrow, @@ -50,8 +64,8 @@ QPainterPath VCurvePathItem::shape() const if (arrowsPath != QPainterPath()) { itemPath.addPath(arrowsPath); - itemPath.setFillRule(Qt::WindingFill); } + itemPath.setFillRule(Qt::WindingFill); // We unfortunately need this hack as QPainterPathStroker will set a width of 1.0 // if we pass a value of 0.0 to QPainterPathStroker::setWidth() @@ -111,6 +125,12 @@ void VCurvePathItem::SetDirectionArrows(const QVector > &a m_directionArrows = arrows; } +//--------------------------------------------------------------------------------------------------------------------- +void VCurvePathItem::SetPoints(const QVector &points) +{ + m_points = points; +} + //--------------------------------------------------------------------------------------------------------------------- void VCurvePathItem::ScalePenWidth() { diff --git a/src/libs/vwidgets/vcurvepathitem.h b/src/libs/vwidgets/vcurvepathitem.h index b33b245c3..78843637c 100644 --- a/src/libs/vwidgets/vcurvepathitem.h +++ b/src/libs/vwidgets/vcurvepathitem.h @@ -49,12 +49,14 @@ public: enum { Type = UserType + static_cast(Vis::CurvePathItem)}; void SetDirectionArrows(const QVector> &arrows); + void SetPoints(const QVector &points); protected: virtual void ScalePenWidth(); private: Q_DISABLE_COPY(VCurvePathItem) QVector> m_directionArrows; + QVector m_points; }; #endif // VCURVEPATHITEM_H diff --git a/src/libs/vwidgets/vsimplecurve.cpp b/src/libs/vwidgets/vsimplecurve.cpp index f7a813916..7c59fe3fd 100644 --- a/src/libs/vwidgets/vsimplecurve.cpp +++ b/src/libs/vwidgets/vsimplecurve.cpp @@ -66,6 +66,7 @@ void VSimpleCurve::RefreshGeometry(const QSharedPointer &curve) { m_isHovered ? SetDirectionArrows(m_curve->DirectionArrows()) : SetDirectionArrows(QVector()); setPath(m_curve->GetPath()); + SetPoints(m_curve->GetPoints()); } else {