Fixed issue #869. Pattern piece label size limited.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-08-01 19:21:49 +03:00
parent c8b43c56d2
commit 7be1d35d8f
2 changed files with 33 additions and 31 deletions

View File

@ -54,6 +54,7 @@
- [#865] New feature. Dynamic Way to define Material in piece label. - [#865] New feature. Dynamic Way to define Material in piece label.
- [#867] Visibility control for place labels. - [#867] Visibility control for place labels.
- [#868] New feature. Connect internal path with cutting contour. - [#868] New feature. Connect internal path with cutting contour.
- [#869] Pattern piece label size limited.
# Version 0.5.1 (unreleased) # Version 0.5.1 (unreleased)
- [#683] Tool Seam allowance's dialog is off screen on small resolutions. - [#683] Tool Seam allowance's dialog is off screen on small resolutions.

View File

@ -244,24 +244,6 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
*/ */
void VTextGraphicsItem::SetSize(qreal fW, qreal fH) void VTextGraphicsItem::SetSize(qreal fW, qreal fH)
{ {
// don't allow resize under specific size
if (fW > parentItem()->boundingRect().width())
{
fW = parentItem()->boundingRect().width();
}
if (fW < minW)
{
fW = minW;
}
if (fH > parentItem()->boundingRect().height())
{
fH = parentItem()->boundingRect().height();
}
if (fH < minH)
{
fH = minH;
}
prepareGeometryChange(); prepareGeometryChange();
m_rectBoundingBox.setTopLeft(QPointF(0, 0)); m_rectBoundingBox.setTopLeft(QPointF(0, 0));
m_rectBoundingBox.setWidth(fW); m_rectBoundingBox.setWidth(fW);
@ -388,8 +370,8 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME)
m_ptStartPos = pos(); m_ptStartPos = pos();
m_ptStart = pME->scenePos(); m_ptStart = pME->scenePos();
m_szStart = m_rectBoundingBox.size(); m_szStart = m_rectBoundingBox.size();
m_ptRotCenter = mapToScene(m_rectBoundingBox.center()); m_ptRotCenter = mapToParent(m_rectBoundingBox.center());
m_dAngle = GetAngle(pME->scenePos()); m_dAngle = GetAngle(mapToParent(pME->pos()));
m_dRotation = rotation(); m_dRotation = rotation();
// in rotation mode, do not do any changes here, because user might want to // in rotation mode, do not do any changes here, because user might want to
// rotate the label more. // rotate the label more.
@ -471,9 +453,9 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
qreal dX; qreal dX;
qreal dY; qreal dY;
QRectF rectBB; QRectF rectBB;
const QPointF ptDiff = pME->scenePos() - m_ptStart;
if (m_eMode == mMove && m_moveType & IsMovable) if (m_eMode == mMove && m_moveType & IsMovable)
{ {
const QPointF ptDiff = pME->scenePos() - m_ptStart;
// in move mode move the label along the mouse move from the origin // in move mode move the label along the mouse move from the origin
QPointF pt = m_ptStartPos + ptDiff; QPointF pt = m_ptStartPos + ptDiff;
rectBB.setTopLeft(pt); rectBB.setTopLeft(pt);
@ -490,34 +472,53 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
} }
else if (m_eMode == mResize && m_moveType & IsResizable) else if (m_eMode == mResize && m_moveType & IsResizable)
{ {
QLineF vectorDiff(m_ptStart, pME->scenePos());
vectorDiff.setAngle(vectorDiff.angle() + m_dRotation);
const QPointF ptDiff = vectorDiff.p2() - m_ptStart;
// in resize mode, resize the label along the mouse move from the origin // in resize mode, resize the label along the mouse move from the origin
QPointF pt; QPointF pt;
QSizeF sz;
if (m_moveType & IsMovable) if (m_moveType & IsMovable)
{ {
const qreal newWidth = m_szStart.width() + ptDiff.x();
const qreal newHeight = m_szStart.height() + ptDiff.y();
if (newWidth <= minW || newHeight <= minH)
{
return;
}
pt = m_ptStartPos; pt = m_ptStartPos;
sz = QSizeF(newWidth, newHeight);
} }
else else
{ {
pt = m_ptRotCenter - QRectF(0, 0, m_szStart.width() + ptDiff.x(), const qreal newWidth = m_szStart.width() + ptDiff.x()*2.0;
m_szStart.height() + ptDiff.y()).center(); const qreal newHeight = m_szStart.height() + ptDiff.y()*2.0;
if (newWidth <= minW || newHeight <= minH)
{
return;
}
pt = QPointF(m_ptRotCenter.x() - newWidth/2.0, m_ptRotCenter.y() - newHeight/2.0);
sz = QSizeF(m_szStart.width() + ptDiff.x()*2.0, m_szStart.height() + ptDiff.y()*2.0);
} }
rectBB.setTopLeft(pt); rectBB.setTopLeft(pt);
QSizeF sz(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y());
rectBB.setSize(sz); rectBB.setSize(sz);
// before resizing the label to a new size, check if it will still be inside the parent item // before resizing the label to a new size, check if it will still be inside the parent item
if (IsContained(rectBB, rotation(), dX, dY) == false) if (IsContained(rectBB, rotation(), dX, dY))
{
sz = QSizeF(sz.width()+dX, sz.height()+dY);
}
else
{ {
if (not (m_moveType & IsMovable)) if (not (m_moveType & IsMovable))
{ {
setPos(pt); setPos(pt);
} }
} }
else
{
return;
}
SetSize(sz.width(), sz.height()); SetSize(sz.width(), sz.height());
Update(); Update();
@ -529,11 +530,11 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
// new angle will be the starting angle for rotation // new angle will be the starting angle for rotation
if (fabs(m_dAngle) < 0.01) if (fabs(m_dAngle) < 0.01)
{ {
m_dAngle = GetAngle(pME->scenePos()); m_dAngle = GetAngle(mapToParent(pME->pos()));
return; return;
} }
// calculate the angle difference from the starting angle // calculate the angle difference from the starting angle
double dAng = qRadiansToDegrees(GetAngle(pME->scenePos()) - m_dAngle); double dAng = qRadiansToDegrees(GetAngle(mapToParent(pME->pos())) - m_dAngle);
rectBB.setTopLeft(m_ptStartPos); rectBB.setTopLeft(m_ptStartPos);
rectBB.setWidth(m_rectBoundingBox.width()); rectBB.setWidth(m_rectBoundingBox.width());
rectBB.setHeight(m_rectBoundingBox.height()); rectBB.setHeight(m_rectBoundingBox.height());