Resolved issue #969. Fix length to label after soom.

--HG--
branch : develop
merge-requests/1/merge
Roman Telezhynskyi 2019-05-05 17:31:45 +03:00
parent 41850e3b80
commit 218ef45d1e
6 changed files with 58 additions and 16 deletions

View File

@ -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.

View File

@ -341,9 +341,7 @@ void VToolSinglePoint::ChangeLabelPosition(quint32 id, const QPointF &pos)
QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(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())

View File

@ -143,9 +143,7 @@ void VNodePoint::ChangeLabelPosition(quint32 id, const QPointF &pos)
QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(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())
{

View File

@ -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<QGraphicsView *> 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;
}
}

View File

@ -1,4 +1,4 @@
/************************************************************************
/************************************************************************
**
** @file vgraphicssimpletextitem.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
@ -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();
};
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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();
}