From 218ef45d1e5681f1e146a1c38b51c8b2de0b5ab6 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 5 May 2019 17:31:45 +0300 Subject: [PATCH] Resolved issue #969. Fix length to label after soom. --HG-- branch : develop --- ChangeLog.txt | 1 + .../toolsinglepoint/vtoolsinglepoint.cpp | 4 +- .../vtools/tools/nodeDetails/vnodepoint.cpp | 4 +- src/libs/vwidgets/vgraphicssimpletextitem.cpp | 47 ++++++++++++++++--- src/libs/vwidgets/vgraphicssimpletextitem.h | 9 +++- src/libs/vwidgets/vscenepoint.cpp | 9 ++-- 6 files changed, 58 insertions(+), 16 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index c314a4f69..bf1736077 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -16,6 +16,7 @@ - [#965] Control passmark length with formula. - New placelabel shape Circle. - Two new passmark types: U and Box. +- [#969] Fix length to label after soom. # Version 0.6.2 (unreleased) - [#903] Bug in tool Cut Spline path. diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index 0fe7ac621..b8da54a51 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -341,9 +341,7 @@ void VToolSinglePoint::ChangeLabelPosition(quint32 id, const QPointF &pos) QSharedPointer point = VAbstractTool::data.GeometricObject(id); point->setMx(pos.x()); point->setMy(pos.y()); - m_namePoint->blockSignals(true); - m_namePoint->setPos(pos); - m_namePoint->blockSignals(false); + m_namePoint->SetRealPos(pos); RefreshLine(); if (QGraphicsScene *sc = scene()) diff --git a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp index 8e0c02bcb..498b83657 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp @@ -143,9 +143,7 @@ void VNodePoint::ChangeLabelPosition(quint32 id, const QPointF &pos) QSharedPointer point = VAbstractTool::data.GeometricObject(id); point->setMx(pos.x()); point->setMy(pos.y()); - m_namePoint->blockSignals(true); - m_namePoint->setPos(pos); - m_namePoint->blockSignals(false); + m_namePoint->SetRealPos(pos); RefreshLine(); if (QGraphicsScene *sc = scene()) { diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index 8ce8c76a1..2e6a609f3 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -96,17 +96,15 @@ void VGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphic const qreal scale = SceneScale(scene); if (scale > 1 && not VFuzzyComparePossibleNulls(m_oldScale, scale)) { - const QRectF nameRec = boundingRect(); - setTransformOriginPoint(nameRec.center()); setScale(1/scale); + CorrectLabelPosition(); UpdateLine(); m_oldScale = scale; } else if (scale <= 1 && not VFuzzyComparePossibleNulls(m_oldScale, 1.0)) { - const QRectF nameRec = boundingRect(); - setTransformOriginPoint(nameRec.center()); setScale(1); + CorrectLabelPosition(); UpdateLine(); m_oldScale = 1; } @@ -145,6 +143,34 @@ void VGraphicsSimpleTextItem::SetShowParentTooltip(bool show) m_showParentTooltip = show; } +//--------------------------------------------------------------------------------------------------------------------- +void VGraphicsSimpleTextItem::SetRealPos(QPointF pos) +{ + m_realPos = pos; + + CorrectLabelPosition(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VGraphicsSimpleTextItem::CorrectLabelPosition() +{ + const qreal scale = SceneScale(scene()); + QPointF newPos = m_realPos; + + if (scale > 1) + { + QLineF line(QPointF(), m_realPos); + line.setLength(line.length() / scale); + newPos = line.p2(); + } + + blockSignals(true); + setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); + setPos(newPos); + setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); + blockSignals(false); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief itemChange handle item change. @@ -162,8 +188,6 @@ QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QV if (changeFinished) { changeFinished = false; - QPointF newPos = value.toPointF() + this->parentItem()->pos(); - emit NameChangePosition(newPos); if (scene()) { const QList viewList = scene()->views(); @@ -198,6 +222,17 @@ QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QV } } } + + m_realPos = value.toPointF(); + const qreal scale = SceneScale(scene()); + if (scale > 1) + { + QLineF line(QPointF(), m_realPos); + line.setLength(line.length() * scale); + m_realPos = line.p2(); + } + emit NameChangePosition(m_realPos + this->parentItem()->pos()); + changeFinished = true; } } diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.h b/src/libs/vwidgets/vgraphicssimpletextitem.h index b2ab41689..c70b53957 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.h +++ b/src/libs/vwidgets/vgraphicssimpletextitem.h @@ -1,4 +1,4 @@ -/************************************************************************ +/************************************************************************ ** ** @file vgraphicssimpletextitem.h ** @author Roman Telezhynskyi @@ -63,6 +63,10 @@ public: void LabelSelectionType(const SelectionType &type); void SetShowParentTooltip(bool show); + + void SetRealPos(QPointF pos); + + signals: /** * @brief NameChangePosition emit when label change position. @@ -91,8 +95,11 @@ private: SelectionType selectionType; qreal m_oldScale; bool m_showParentTooltip; + QPointF m_realPos{}; void Init(); + + void CorrectLabelPosition(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vscenepoint.cpp b/src/libs/vwidgets/vscenepoint.cpp index fe221b3d0..26316ce37 100644 --- a/src/libs/vwidgets/vscenepoint.cpp +++ b/src/libs/vwidgets/vscenepoint.cpp @@ -105,11 +105,14 @@ void VScenePoint::RefreshPointGeometry(const VPointF &point) m_showLabel = point.IsShowLabel(); m_namePoint->blockSignals(true); - m_namePoint->setText(point.name()); - m_namePoint->setPos(QPointF(point.mx(), point.my())); - m_namePoint->setVisible(m_showLabel); + m_namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); + m_namePoint->SetRealPos(QPointF(point.mx(), point.my())); + m_namePoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); m_namePoint->blockSignals(false); + m_namePoint->setText(point.name()); + m_namePoint->setVisible(m_showLabel); + RefreshLine(); }