Fix bug with simple curve. It should be hovered only if mouse pointer above a

path.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-07-27 17:15:53 +03:00
parent d0e2facf94
commit 185636a550
3 changed files with 26 additions and 3 deletions

View File

@ -35,14 +35,28 @@
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VCurvePathItem::VCurvePathItem(QGraphicsItem *parent) VCurvePathItem::VCurvePathItem(QGraphicsItem *parent)
: QGraphicsPathItem(parent), : QGraphicsPathItem(parent),
m_directionArrows() m_directionArrows(),
m_points()
{ {
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QPainterPath VCurvePathItem::shape() const 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, const QPainterPath arrowsPath = VAbstractCurve::ShowDirection(m_directionArrows,
ScaleWidth(VAbstractCurve::lengthCurveDirectionArrow, ScaleWidth(VAbstractCurve::lengthCurveDirectionArrow,
@ -50,8 +64,8 @@ QPainterPath VCurvePathItem::shape() const
if (arrowsPath != QPainterPath()) if (arrowsPath != QPainterPath())
{ {
itemPath.addPath(arrowsPath); 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 // 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() // if we pass a value of 0.0 to QPainterPathStroker::setWidth()
@ -111,6 +125,12 @@ void VCurvePathItem::SetDirectionArrows(const QVector<QPair<QLineF, QLineF> > &a
m_directionArrows = arrows; m_directionArrows = arrows;
} }
//---------------------------------------------------------------------------------------------------------------------
void VCurvePathItem::SetPoints(const QVector<QPointF> &points)
{
m_points = points;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VCurvePathItem::ScalePenWidth() void VCurvePathItem::ScalePenWidth()
{ {

View File

@ -49,12 +49,14 @@ public:
enum { Type = UserType + static_cast<int>(Vis::CurvePathItem)}; enum { Type = UserType + static_cast<int>(Vis::CurvePathItem)};
void SetDirectionArrows(const QVector<QPair<QLineF, QLineF>> &arrows); void SetDirectionArrows(const QVector<QPair<QLineF, QLineF>> &arrows);
void SetPoints(const QVector<QPointF> &points);
protected: protected:
virtual void ScalePenWidth(); virtual void ScalePenWidth();
private: private:
Q_DISABLE_COPY(VCurvePathItem) Q_DISABLE_COPY(VCurvePathItem)
QVector<QPair<QLineF, QLineF>> m_directionArrows; QVector<QPair<QLineF, QLineF>> m_directionArrows;
QVector<QPointF> m_points;
}; };
#endif // VCURVEPATHITEM_H #endif // VCURVEPATHITEM_H

View File

@ -66,6 +66,7 @@ void VSimpleCurve::RefreshGeometry(const QSharedPointer<VAbstractCurve> &curve)
{ {
m_isHovered ? SetDirectionArrows(m_curve->DirectionArrows()) : SetDirectionArrows(QVector<DirectionArrow>()); m_isHovered ? SetDirectionArrows(m_curve->DirectionArrows()) : SetDirectionArrows(QVector<DirectionArrow>());
setPath(m_curve->GetPath()); setPath(m_curve->GetPath());
SetPoints(m_curve->GetPoints());
} }
else else
{ {