Labels now cannot go outside the detail bounding box with any operation (move, resize or rotate)
--HG-- branch : feature
This commit is contained in:
parent
f7ebda3c6e
commit
634d8773de
|
@ -194,6 +194,39 @@ void VTextGraphicsItem::Update()
|
||||||
UpdateBox();
|
UpdateBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool VTextGraphicsItem::IsContained(QRectF rectBB, qreal dRot, qreal &dX, qreal &dY) const
|
||||||
|
{
|
||||||
|
QRectF rectParent = parentItem()->boundingRect();
|
||||||
|
rectBB = GetBoundingRect(rectBB, dRot);
|
||||||
|
dX = 0;
|
||||||
|
dY = 0;
|
||||||
|
|
||||||
|
if (rectParent.contains(rectBB) == false)
|
||||||
|
{
|
||||||
|
if (rectParent.left() - rectBB.left() > fabs(dX))
|
||||||
|
{
|
||||||
|
dX = rectParent.left() - rectBB.left();
|
||||||
|
}
|
||||||
|
else if (rectBB.right() - rectParent.right() > fabs(dX))
|
||||||
|
{
|
||||||
|
dX = rectParent.right() - rectBB.right();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rectParent.top() - rectBB.top() > fabs(dY))
|
||||||
|
{
|
||||||
|
dY = rectParent.top() - rectBB.top();
|
||||||
|
}
|
||||||
|
else if (rectBB.bottom() - rectParent.bottom() > fabs(dY))
|
||||||
|
{
|
||||||
|
dY = rectParent.bottom() - rectBB.bottom();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
int VTextGraphicsItem::GetFontSize() const
|
int VTextGraphicsItem::GetFontSize() const
|
||||||
{
|
{
|
||||||
|
@ -238,33 +271,38 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
|
void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
|
||||||
{
|
{
|
||||||
|
qreal dX;
|
||||||
|
qreal dY;
|
||||||
|
QRectF rectBB;
|
||||||
QPointF ptDiff = pME->scenePos() - m_ptStart;
|
QPointF ptDiff = pME->scenePos() - m_ptStart;
|
||||||
if (m_eMode == mMove)
|
if (m_eMode == mMove)
|
||||||
{
|
{
|
||||||
QPointF pt = m_ptStartPos + ptDiff;
|
QPointF pt = m_ptStartPos + ptDiff;
|
||||||
pt.setX(pt.x() + m_rectBoundingBox.width()/2);
|
rectBB.setTopLeft(pt);
|
||||||
pt.setY(pt.y() + m_rectBoundingBox.height()/2);
|
rectBB.setWidth(m_rectBoundingBox.width());
|
||||||
QRectF rectBB = parentItem()->boundingRect();
|
rectBB.setHeight(m_rectBoundingBox.height());
|
||||||
if (rectBB.contains(pt) == false)
|
if (IsContained(rectBB, rotation(), dX, dY) == false)
|
||||||
{
|
{
|
||||||
pt.setX(qMin(rectBB.right(), qMax(pt.x(), rectBB.left())));
|
pt.setX(pt.x() + dX);
|
||||||
pt.setY(qMin(rectBB.bottom(), qMax(pt.y(), rectBB.top())));
|
pt.setY(pt.y() + dY);
|
||||||
}
|
}
|
||||||
pt.setX(pt.x() - m_rectBoundingBox.width()/2);
|
|
||||||
pt.setY(pt.y() - m_rectBoundingBox.height()/2);
|
|
||||||
setPos(pt);
|
setPos(pt);
|
||||||
UpdateBox();
|
UpdateBox();
|
||||||
}
|
}
|
||||||
else if (m_eMode == mResize)
|
else if (m_eMode == mResize)
|
||||||
{
|
{
|
||||||
QPointF pt = m_ptStartPos;
|
QPointF pt = m_ptStartPos;
|
||||||
pt.setX(pt.x() + (m_szStart.width() + ptDiff.x())/2);
|
rectBB.setTopLeft(pt);
|
||||||
pt.setY(pt.y() + (m_szStart.height() + ptDiff.y())/2);
|
QSize sz(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y());
|
||||||
if (parentItem()->boundingRect().contains(pt) == true) {
|
rectBB.setSize(sz);
|
||||||
SetSize(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y());
|
if (IsContained(rectBB, rotation(), dX, dY) == false) {
|
||||||
Update();
|
sz.setWidth(sz.width() + dX);
|
||||||
emit SignalShrink();
|
sz.setHeight(sz.height() + dY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetSize(sz.width(), sz.height());
|
||||||
|
Update();
|
||||||
|
emit SignalShrink();
|
||||||
}
|
}
|
||||||
else if (m_eMode == mRotate)
|
else if (m_eMode == mRotate)
|
||||||
{
|
{
|
||||||
|
@ -274,9 +312,14 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
double dAng = 180*(GetAngle(pME->scenePos()) - m_dAngle)/M_PI;
|
double dAng = 180*(GetAngle(pME->scenePos()) - m_dAngle)/M_PI;
|
||||||
setRotation(m_dRotation + dAng);
|
rectBB.setTopLeft(m_ptStartPos);
|
||||||
//emit SignalRotated(rotation());
|
rectBB.setWidth(m_rectBoundingBox.width());
|
||||||
Update();
|
rectBB.setHeight(m_rectBoundingBox.height());
|
||||||
|
if (IsContained(rectBB, m_dRotation + dAng, dX, dY) == true)
|
||||||
|
{
|
||||||
|
setRotation(m_dRotation + dAng);
|
||||||
|
Update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,3 +464,53 @@ double VTextGraphicsItem::GetAngle(QPointF pt) const
|
||||||
else
|
else
|
||||||
return atan2(dY, dX);
|
return atan2(dY, dX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QRectF VTextGraphicsItem::GetBoundingRect(QRectF rectBB, qreal dRot) const
|
||||||
|
{
|
||||||
|
QPointF apt[4] = { rectBB.topLeft(), rectBB.topRight(), rectBB.bottomLeft(), rectBB.bottomRight() };
|
||||||
|
QPointF ptCenter = rectBB.center();
|
||||||
|
|
||||||
|
qreal dX1 = 0;
|
||||||
|
qreal dX2 = 0;
|
||||||
|
qreal dY1 = 0;
|
||||||
|
qreal dY2 = 0;
|
||||||
|
|
||||||
|
double dAng = M_PI*dRot/180;
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
QPointF pt = apt[i] - ptCenter;
|
||||||
|
qreal dX = pt.x()*cos(dAng) + pt.y()*sin(dAng);
|
||||||
|
qreal dY = -pt.x()*sin(dAng) + pt.y()*cos(dAng);
|
||||||
|
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
dX1 = dX2 = dX;
|
||||||
|
dY1 = dY2 = dY;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (dX < dX1)
|
||||||
|
{
|
||||||
|
dX1 = dX;
|
||||||
|
}
|
||||||
|
else if (dX > dX2)
|
||||||
|
{
|
||||||
|
dX2 = dX;
|
||||||
|
}
|
||||||
|
if (dY < dY1)
|
||||||
|
{
|
||||||
|
dY1 = dY;
|
||||||
|
}
|
||||||
|
else if (dY > dY2)
|
||||||
|
{
|
||||||
|
dY2 = dY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QRectF rect;
|
||||||
|
rect.setTopLeft(ptCenter + QPointF(dX1, dY1));
|
||||||
|
rect.setWidth(dX2 - dX1);
|
||||||
|
rect.setHeight(dY2 - dY1);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
|
@ -71,6 +71,7 @@ public:
|
||||||
void Clear();
|
void Clear();
|
||||||
void SetSize(qreal fW, qreal fH);
|
void SetSize(qreal fW, qreal fH);
|
||||||
void Update();
|
void Update();
|
||||||
|
bool IsContained(QRectF rectBB, qreal dRot, qreal& dX, qreal& dY) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent* pME);
|
void mousePressEvent(QGraphicsSceneMouseEvent* pME);
|
||||||
|
@ -104,6 +105,8 @@ private:
|
||||||
QFont m_font;
|
QFont m_font;
|
||||||
QList<TextLine> m_liLines;
|
QList<TextLine> m_liLines;
|
||||||
QList<TextLine> m_liOutput;
|
QList<TextLine> m_liOutput;
|
||||||
|
|
||||||
|
QRectF GetBoundingRect(QRectF rectBB, qreal dRot) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VTEXTGRAPHICSITEM_H
|
#endif // VTEXTGRAPHICSITEM_H
|
||||||
|
|
|
@ -714,20 +714,19 @@ void VToolDetail::UpdateLabel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF pt = data.GetPos() + QPointF(data.GetLabelWidth()/2, data.GetLabelHeight()/2);
|
QPointF pt = data.GetPos();
|
||||||
// check if center is inside
|
QRectF rectBB;
|
||||||
if (boundingRect().contains(pt) == false)
|
rectBB.setTopLeft(pt);
|
||||||
|
rectBB.setWidth(data.GetLabelWidth());
|
||||||
|
rectBB.setHeight(data.GetLabelHeight());
|
||||||
|
qreal dX;
|
||||||
|
qreal dY;
|
||||||
|
if (dataLabel->IsContained(rectBB, data.GetRotation(), dX, dY) == false)
|
||||||
{
|
{
|
||||||
QRectF rect = boundingRect();
|
pt.setX(pt.x() + dX);
|
||||||
pt.setX(qMin(rect.right(), qMax(pt.x(), rect.left())));
|
pt.setY(pt.y() + dY);
|
||||||
pt.setY(qMin(rect.bottom(), qMax(pt.y(), rect.top())));
|
|
||||||
pt.setX(pt.x() - data.GetLabelWidth()/2);
|
|
||||||
pt.setY(pt.y() - data.GetLabelHeight()/2);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pt = data.GetPos();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dataLabel->setPos(pt);
|
dataLabel->setPos(pt);
|
||||||
dataLabel->setRotation(data.GetRotation());
|
dataLabel->setRotation(data.GetRotation());
|
||||||
dataLabel->Update();
|
dataLabel->Update();
|
||||||
|
@ -792,20 +791,19 @@ void VToolDetail::UpdatePatternInfo()
|
||||||
tl.m_qsText = qslDate.last();
|
tl.m_qsText = qslDate.last();
|
||||||
patternInfo->AddLine(tl);
|
patternInfo->AddLine(tl);
|
||||||
|
|
||||||
// check if center is inside
|
QPointF pt = geom.GetPos();
|
||||||
QPointF pt = geom.GetPos() + QPointF(geom.GetLabelWidth()/2, geom.GetLabelHeight()/2);
|
QRectF rectBB;
|
||||||
if (boundingRect().contains(pt) == false)
|
rectBB.setTopLeft(pt);
|
||||||
|
rectBB.setWidth(geom.GetLabelWidth());
|
||||||
|
rectBB.setHeight(geom.GetLabelHeight());
|
||||||
|
qreal dX;
|
||||||
|
qreal dY;
|
||||||
|
if (patternInfo->IsContained(rectBB, geom.GetRotation(), dX, dY) == false)
|
||||||
{
|
{
|
||||||
QRectF rect = boundingRect();
|
pt.setX(pt.x() + dX);
|
||||||
pt.setX(qMin(rect.right(), qMax(pt.x(), rect.left())));
|
pt.setY(pt.y() + dY);
|
||||||
pt.setY(qMin(rect.bottom(), qMax(pt.y(), rect.top())));
|
|
||||||
pt.setX(pt.x() - geom.GetLabelWidth()/2);
|
|
||||||
pt.setY(pt.y() - geom.GetLabelHeight()/2);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pt = geom.GetPos();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
patternInfo->setPos(pt);
|
patternInfo->setPos(pt);
|
||||||
patternInfo->setRotation(geom.GetRotation());
|
patternInfo->setRotation(geom.GetRotation());
|
||||||
patternInfo->Update();
|
patternInfo->Update();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user