From 7be1d35d8f35488c33427274bfcd7612bd18c581 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 1 Aug 2018 19:21:49 +0300 Subject: [PATCH] Fixed issue #869. Pattern piece label size limited. --HG-- branch : develop --- ChangeLog.txt | 1 + src/libs/vwidgets/vtextgraphicsitem.cpp | 63 +++++++++++++------------ 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 2d83b844c..7318396e6 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -54,6 +54,7 @@ - [#865] New feature. Dynamic Way to define Material in piece label. - [#867] Visibility control for place labels. - [#868] New feature. Connect internal path with cutting contour. +- [#869] Pattern piece label size limited. # Version 0.5.1 (unreleased) - [#683] Tool Seam allowance's dialog is off screen on small resolutions. diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index 9bcf2daf4..19eab5d2d 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -244,24 +244,6 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem */ 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(); m_rectBoundingBox.setTopLeft(QPointF(0, 0)); m_rectBoundingBox.setWidth(fW); @@ -388,8 +370,8 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) m_ptStartPos = pos(); m_ptStart = pME->scenePos(); m_szStart = m_rectBoundingBox.size(); - m_ptRotCenter = mapToScene(m_rectBoundingBox.center()); - m_dAngle = GetAngle(pME->scenePos()); + m_ptRotCenter = mapToParent(m_rectBoundingBox.center()); + m_dAngle = GetAngle(mapToParent(pME->pos())); m_dRotation = rotation(); // in rotation mode, do not do any changes here, because user might want to // rotate the label more. @@ -471,9 +453,9 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) qreal dX; qreal dY; QRectF rectBB; - const QPointF ptDiff = pME->scenePos() - m_ptStart; 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 QPointF pt = m_ptStartPos + ptDiff; rectBB.setTopLeft(pt); @@ -490,34 +472,53 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) } 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 QPointF pt; + QSizeF sz; 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; + sz = QSizeF(newWidth, newHeight); } else { - pt = m_ptRotCenter - QRectF(0, 0, m_szStart.width() + ptDiff.x(), - m_szStart.height() + ptDiff.y()).center(); + const qreal newWidth = m_szStart.width() + ptDiff.x()*2.0; + 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); - QSizeF sz(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y()); rectBB.setSize(sz); // 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) - { - sz = QSizeF(sz.width()+dX, sz.height()+dY); - } - else + if (IsContained(rectBB, rotation(), dX, dY)) { if (not (m_moveType & IsMovable)) { setPos(pt); } } + else + { + return; + } SetSize(sz.width(), sz.height()); Update(); @@ -529,11 +530,11 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) // new angle will be the starting angle for rotation if (fabs(m_dAngle) < 0.01) { - m_dAngle = GetAngle(pME->scenePos()); + m_dAngle = GetAngle(mapToParent(pME->pos())); return; } // 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.setWidth(m_rectBoundingBox.width()); rectBB.setHeight(m_rectBoundingBox.height());