From d07c27a96c40a185b40214042e9538228c180f79 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 11 May 2019 18:37:08 +0300 Subject: [PATCH] Allow setting destination point. Destination point is anchor to which connected a label. --HG-- branch : develop --- src/libs/vwidgets/vgraphicssimpletextitem.cpp | 8 +++++++- src/libs/vwidgets/vgraphicssimpletextitem.h | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index f4c72d183..0259e6a77 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -164,7 +164,7 @@ void VGraphicsSimpleTextItem::CorrectLabelPosition() if (scale > 1) { - QLineF line(QPointF(), m_realPos); + QLineF line(m_destination, m_realPos); line.setLength(line.length() / scale); newPos = line.p2(); } @@ -364,6 +364,12 @@ void VGraphicsSimpleTextItem::keyReleaseEvent(QKeyEvent *event) QGraphicsSimpleTextItem::keyReleaseEvent ( event ); } +//--------------------------------------------------------------------------------------------------------------------- +void VGraphicsSimpleTextItem::SetDestination(const QPointF &destination) +{ + m_destination = destination; +} + //--------------------------------------------------------------------------------------------------------------------- QColor VGraphicsSimpleTextItem::BaseColor() const { diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.h b/src/libs/vwidgets/vgraphicssimpletextitem.h index a072e8836..3ba9075b9 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.h +++ b/src/libs/vwidgets/vgraphicssimpletextitem.h @@ -68,6 +68,8 @@ public: QColor BaseColor() const; void SetBaseColor(const QColor &baseColor); + void SetDestination(const QPointF &destination); + signals: /** * @brief NameChangePosition emit when label change position. @@ -96,6 +98,7 @@ private: bool m_showParentTooltip; QPointF m_realPos{}; QColor m_baseColor{Qt::black}; + QPointF m_destination{}; void Init();