From 62d3d5283aaef03f0e32d9242a8b96f72473a66a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 14 Dec 2016 11:32:22 +0200 Subject: [PATCH 1/9] Cppcheck warning. --HG-- branch : feature --- src/libs/vlayout/vtextmanager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 486dd6972..586a6b719 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -193,7 +193,6 @@ void VTextManager::FitFontSize(qreal fW, qreal fH) // get ratio between char width and height int iMaxLen = 0; - int iTW; QFont fnt; for (int i = 0; i < GetSourceLinesCount(); ++i) { @@ -203,7 +202,7 @@ void VTextManager::FitFontSize(qreal fW, qreal fH) fnt.setWeight(tl.m_eFontWeight); fnt.setStyle(tl.m_eStyle); QFontMetrics fm(fnt); - iTW = fm.width(GetSourceLine(i).m_qsText); + const int iTW = fm.width(GetSourceLine(i).m_qsText); if (iTW > iMaxLen) { iMaxLen = iTW; From 4eb9b2da837824b9d80f0271aba13de749727fc9 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 14 Dec 2016 11:59:21 +0200 Subject: [PATCH 2/9] Cleaning code. --HG-- branch : feature --- src/libs/vlayout/vlayoutdetail.cpp | 22 ++++++--------------- src/libs/vlayout/vtextmanager.cpp | 13 +++--------- src/libs/vtools/tools/vtextgraphicsitem.cpp | 20 +------------------ src/libs/vtools/tools/vtooldetail.cpp | 6 ++---- 4 files changed, 12 insertions(+), 49 deletions(-) diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index 0c61540d3..eeb1a91ff 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -148,15 +148,10 @@ void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& da // generate text d->m_tmDetail.SetFont(font); - int iFS = data.GetFontSize(); - if (iFS < MIN_FONT_SIZE) - { - iFS = MIN_FONT_SIZE; - } - d->m_tmDetail.SetFontSize(iFS); + d->m_tmDetail.SetFontSize(data.GetFontSize()); d->m_tmDetail.Update(qsName, data); // this will generate the lines of text - d->m_tmDetail.SetFontSize(iFS); + d->m_tmDetail.SetFontSize(data.GetFontSize()); d->m_tmDetail.FitFontSize(data.GetLabelWidth(), data.GetLabelHeight()); } @@ -180,17 +175,12 @@ void VLayoutDetail::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternI // Generate text d->m_tmPattern.SetFont(font); - int iFS = geom.GetFontSize(); - if (iFS < MIN_FONT_SIZE) - { - iFS = MIN_FONT_SIZE; - } - d->m_tmPattern.SetFontSize(iFS); + d->m_tmPattern.SetFontSize(geom.GetFontSize()); d->m_tmPattern.Update(pDoc, dSize, dHeight); // generate lines of text - d->m_tmPattern.SetFontSize(iFS); + d->m_tmPattern.SetFontSize(geom.GetFontSize()); d->m_tmPattern.FitFontSize(geom.GetLabelWidth(), geom.GetLabelHeight()); } @@ -592,7 +582,7 @@ void VLayoutDetail::CreateTextItems() QString qsText = tl.m_qsText; if (fm.width(qsText) > dW) { - qsText = fm.elidedText(qsText, Qt::ElideRight, dW); + qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast(dW)); } // find the correct horizontal offset, depending on the alignment flag if ((tl.m_eAlign & Qt::AlignLeft) > 0) @@ -646,7 +636,7 @@ void VLayoutDetail::CreateTextItems() QString qsText = tl.m_qsText; if (fm.width(qsText) > dW) { - qsText = fm.elidedText(qsText, Qt::ElideRight, dW); + qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast(dW)); } if ((tl.m_eAlign & Qt::AlignLeft) > 0) { diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 586a6b719..cba5d18b1 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -32,11 +32,11 @@ #include #include #include -#include #include "../ifc/xml/vabstractpattern.h" #include "../vpatterndb/vpatternpiecedata.h" #include "../vmisc/vabstractapplication.h" +#include "../vmisc/vmath.h" #include "vtextmanager.h" //--------------------------------------------------------------------------------------------------------------------- @@ -117,14 +117,7 @@ const QFont& VTextManager::GetFont() const */ void VTextManager::SetFontSize(int iFS) { - if (iFS < MIN_FONT_SIZE) - { - m_font.setPixelSize(MIN_FONT_SIZE); - } - else - { - m_font.setPixelSize(iFS); - } + iFS < MIN_FONT_SIZE ? m_font.setPixelSize(MIN_FONT_SIZE) : m_font.setPixelSize(iFS); } //--------------------------------------------------------------------------------------------------------------------- @@ -172,7 +165,7 @@ const TextLine& VTextManager::GetSourceLine(int i) const { Q_ASSERT(i >= 0); Q_ASSERT(i < m_liLines.count()); - return m_liLines[i]; + return m_liLines.at(i); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index f83751aba..88b55fbdf 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -125,7 +125,7 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem QFontMetrics fm(fnt); if (fm.width(qsText) > iW) { - qsText = fm.elidedText(qsText, Qt::ElideRight, iW); + qsText = fm.elidedText(qsText, Qt::ElideMiddle, iW); } painter->setFont(fnt); @@ -209,24 +209,6 @@ bool VTextGraphicsItem::IsIdle() const void VTextGraphicsItem::AddLine(const TextLine& tl) { m_tm.AddSourceLine(tl); - /* - qreal fW = MIN_W; - qreal fH = m_iMinH; - qreal fMinW; - qreal fMinH; - while (m_tm.IsBigEnough(fW, fH, MIN_FONT_SIZE, fMinW, fMinH) == false) - { - SetSize(fMinW, fMinH); - fW = m_rectBoundingBox.width(); - fH = m_rectBoundingBox.height(); - } - qreal dX; - qreal dY; - if (IsContained(m_rectBoundingBox, rotation(), dX, dY) == false) - { - setPos(m_rectBoundingBox.left() + dX, m_rectBoundingBox.top() + dY); - } - */ } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 5a526e6c9..3ebd5d434 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -837,12 +837,10 @@ void VToolDetail::UpdateLabel() if (data.IsVisible() == true) { QFont fnt = qApp->font(); - int iFS = data.GetFontSize(); - if (iFS < MIN_FONT_SIZE) { - iFS = MIN_FONT_SIZE; + const int iFS = data.GetFontSize(); + iFS < MIN_FONT_SIZE ? fnt.setPixelSize(MIN_FONT_SIZE) : fnt.setPixelSize(iFS); } - fnt.setPixelSize(iFS); dataLabel->SetFont(fnt); dataLabel->SetSize(data.GetLabelWidth(), data.GetLabelHeight()); dataLabel->UpdateData(detail.getName(), data); From 8d526d2ebcd88e9ed5bb6bea5cd0e4418d7a928a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 14 Dec 2016 12:09:59 +0200 Subject: [PATCH 3/9] Set min font size to 5. --HG-- branch : feature --- src/libs/vlayout/vtextmanager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/vlayout/vtextmanager.h b/src/libs/vlayout/vtextmanager.h index d3b3d7297..a4ac5a751 100644 --- a/src/libs/vlayout/vtextmanager.h +++ b/src/libs/vlayout/vtextmanager.h @@ -44,7 +44,7 @@ class QFontMetrics; class VAbstractPattern; class VPatternPieceData; -#define MIN_FONT_SIZE 12 +#define MIN_FONT_SIZE 5 #define MAX_FONT_SIZE 128 /** From 97d76957e3fe79e95097fb6563145ecb077d1bc7 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 15 Dec 2016 08:46:45 +0200 Subject: [PATCH 4/9] Use font's height. --HG-- branch : feature --- src/libs/vlayout/vlayoutdetail.cpp | 12 ++++++++---- src/libs/vlayout/vtextmanager.cpp | 15 ++++++--------- src/libs/vlayout/vtextmanager.h | 1 - src/libs/vtools/tools/vtextgraphicsitem.cpp | 17 ++++++++++------- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index eeb1a91ff..08e6ea135 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -571,14 +571,16 @@ void VLayoutDetail::CreateTextItems() fnt.setPixelSize(d->m_tmDetail.GetFont().pixelSize() + tl.m_iFontSize); fnt.setWeight(tl.m_eFontWeight); fnt.setStyle(tl.m_eStyle); - dY += tl.m_iHeight; + + QFontMetrics fm(fnt); + + dY += fm.height(); // check if the next line will go out of bounds if (dY > dH) { break; } - QFontMetrics fm(fnt); QString qsText = tl.m_qsText; if (fm.width(qsText) > dW) { @@ -626,13 +628,15 @@ void VLayoutDetail::CreateTextItems() fnt.setPixelSize(d->m_tmPattern.GetFont().pixelSize() + tl.m_iFontSize); fnt.setWeight(tl.m_eFontWeight); fnt.setStyle(tl.m_eStyle); - dY += tl.m_iHeight; + + QFontMetrics fm(fnt); + + dY += fm.height(); if (dY > dH) { break; } - QFontMetrics fm(fnt); QString qsText = tl.m_qsText; if (fm.width(qsText) > dW) { diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index cba5d18b1..16a4ef771 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -44,8 +44,11 @@ * @brief TextLine::TextLine default constructor */ TextLine::TextLine() - :m_qsText(), m_iFontSize(MIN_FONT_SIZE), m_eFontWeight(QFont::Normal), m_eStyle(QFont::StyleNormal), - m_eAlign(Qt::AlignCenter), m_iHeight(0) + : m_qsText(), + m_iFontSize(MIN_FONT_SIZE), + m_eFontWeight(QFont::Normal), + m_eStyle(QFont::StyleNormal), + m_eAlign(Qt::AlignCenter) {} //--------------------------------------------------------------------------------------------------------------------- @@ -53,7 +56,7 @@ TextLine::TextLine() * @brief VTextManager::VTextManager constructor */ VTextManager::VTextManager() - :m_font(), m_liLines() + : m_font(), m_liLines() {} //--------------------------------------------------------------------------------------------------------------------- @@ -205,13 +208,7 @@ void VTextManager::FitFontSize(qreal fW, qreal fH) { iFS = qFloor(iFS*fW/iMaxLen); } - iFS = qMax(MIN_FONT_SIZE, iFS); - int iH = 4*iFS/3; SetFontSize(iFS); - for (int i = 0; i < GetSourceLinesCount(); ++i) - { - m_liLines[i].m_iHeight = iH; - } qDebug() << "Font size" << GetSourceLinesCount() << iFS; } diff --git a/src/libs/vlayout/vtextmanager.h b/src/libs/vlayout/vtextmanager.h index a4ac5a751..01f01aedf 100644 --- a/src/libs/vlayout/vtextmanager.h +++ b/src/libs/vlayout/vtextmanager.h @@ -57,7 +57,6 @@ struct TextLine QFont::Weight m_eFontWeight; QFont::Style m_eStyle; Qt::Alignment m_eAlign; - int m_iHeight; TextLine(); }; diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 88b55fbdf..c55b4df2a 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -112,25 +112,28 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem for (int i = 0; i < m_tm.GetSourceLinesCount(); ++i) { const TextLine& tl = m_tm.GetSourceLine(i); - // check if the next line will go out of bounds - if (iY + tl.m_iHeight > boundingRect().height()) - { - break; - } + fnt.setPixelSize(m_tm.GetFont().pixelSize() + tl.m_iFontSize); fnt.setWeight(tl.m_eFontWeight); fnt.setStyle(tl.m_eStyle); QString qsText = tl.m_qsText; QFontMetrics fm(fnt); + + // check if the next line will go out of bounds + if (iY + fm.height() > boundingRect().height()) + { + break; + } + if (fm.width(qsText) > iW) { qsText = fm.elidedText(qsText, Qt::ElideMiddle, iW); } painter->setFont(fnt); - painter->drawText(0, iY, iW, tl.m_iHeight, tl.m_eAlign, qsText); - iY += tl.m_iHeight + m_tm.GetSpacing(); + painter->drawText(0, iY, iW, fm.height(), tl.m_eAlign, qsText); + iY += fm.height() + m_tm.GetSpacing(); } // now draw the features specific to non-normal modes From 227e4f0ba0cc859abe67380051b072e25bd412d1 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 15 Dec 2016 08:50:25 +0200 Subject: [PATCH 5/9] Better way to find maximally suitable font size. --HG-- branch : feature --- src/libs/vlayout/vtextmanager.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 16a4ef771..55408a285 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -189,6 +189,7 @@ void VTextManager::FitFontSize(qreal fW, qreal fH) // get ratio between char width and height int iMaxLen = 0; + TextLine maxLine; QFont fnt; for (int i = 0; i < GetSourceLinesCount(); ++i) { @@ -198,15 +199,28 @@ void VTextManager::FitFontSize(qreal fW, qreal fH) fnt.setWeight(tl.m_eFontWeight); fnt.setStyle(tl.m_eStyle); QFontMetrics fm(fnt); - const int iTW = fm.width(GetSourceLine(i).m_qsText); + const int iTW = fm.width(tl.m_qsText); if (iTW > iMaxLen) { iMaxLen = iTW; + maxLine = tl; } } if (iMaxLen > fW) { - iFS = qFloor(iFS*fW/iMaxLen); + QFont fnt = m_font; + fnt.setWeight(maxLine.m_eFontWeight); + fnt.setStyle(maxLine.m_eStyle); + + int lineLength = 0; + do + { + --iFS; + fnt.setPixelSize(iFS + maxLine.m_iFontSize); + QFontMetrics fm(fnt); + lineLength = fm.width(maxLine.m_qsText); + } + while (lineLength > fW && iFS > MIN_FONT_SIZE); } SetFontSize(iFS); qDebug() << "Font size" << GetSourceLinesCount() << iFS; From a3f7b9f60f6d33d0c8474536ff73c168ddaa111d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 15 Dec 2016 08:52:23 +0200 Subject: [PATCH 6/9] Fix drawing artifacts. --HG-- branch : feature --- src/libs/vtools/tools/vtextgraphicsitem.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index c55b4df2a..ae6ad5a22 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -101,7 +101,8 @@ void VTextGraphicsItem::SetFont(const QFont& fnt) void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(widget); - painter->fillRect(option->rect, QColor(251, 251, 175)); + Q_UNUSED(option); + painter->fillRect(m_rectBoundingBox, QColor(251, 251, 175)); painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); painter->setPen(Qt::black); @@ -148,13 +149,13 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem // draw the resize square painter->setPen(Qt::black); painter->setBrush(Qt::black); - painter->drawRect(m_rectResize); + painter->drawRect(m_rectResize.adjusted(-1, -1, -1, -1)); if (m_eMode == mResize) { // draw the resize diagonal lines - painter->drawLine(0, 0, qRound(m_rectBoundingBox.width()), qRound(m_rectBoundingBox.height())); - painter->drawLine(0, qRound(m_rectBoundingBox.height()), qRound(m_rectBoundingBox.width()), 0); + painter->drawLine(1, 1, qFloor(m_rectBoundingBox.width())-1, qFloor(m_rectBoundingBox.height())-1); + painter->drawLine(1, qFloor(m_rectBoundingBox.height())-1, qFloor(m_rectBoundingBox.width())-1, 1); } } else @@ -256,6 +257,7 @@ void VTextGraphicsItem::SetSize(qreal fW, qreal fH) fH = m_iMinH; } + prepareGeometryChange(); qDebug() << "Actual size set to" << fW; m_rectBoundingBox.setTopLeft(QPointF(0, 0)); m_rectBoundingBox.setWidth(fW); @@ -264,7 +266,6 @@ void VTextGraphicsItem::SetSize(qreal fW, qreal fH) m_rectResize.setWidth(RESIZE_SQUARE); m_rectResize.setHeight(RESIZE_SQUARE); setTransformOriginPoint(m_rectBoundingBox.center()); - prepareGeometryChange(); } //--------------------------------------------------------------------------------------------------------------------- From b16ee3a4d100f14f26ed7acd76d94f250f3d5b2c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 15 Dec 2016 08:54:52 +0200 Subject: [PATCH 7/9] Minore changes for VTextGraphicsItem. Clearing code. Changed size for control objects. --HG-- branch : feature --- src/libs/vtools/tools/vtextgraphicsitem.cpp | 73 +++++++++++---------- src/libs/vtools/tools/vtextgraphicsitem.h | 16 ++--- 2 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index ae6ad5a22..e87cd3595 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -49,12 +49,12 @@ class QWidget; class VAbstractPattern; class VPatternPieceData; -#define RESIZE_SQUARE 30 -#define ROTATE_CIRCLE 20 +const qreal resizeSquare = (3./*mm*/ / 25.4) * PrintDPI; +const qreal rotateCircle = (2./*mm*/ / 25.4) * PrintDPI; #define ROTATE_RECT 60 #define ROTATE_ARC 50 -#define MIN_W 120 -#define MIN_H 60 +const qreal minW = (4./*mm*/ / 25.4) * PrintDPI + resizeSquare; +const qreal minH = (4./*mm*/ / 25.4) * PrintDPI + resizeSquare; #define INACTIVE_Z 2 #define ACTIVE_Z 10 @@ -64,12 +64,21 @@ class VPatternPieceData; * @param pParent pointer to the parent item */ VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) - :QGraphicsObject(pParent), m_eMode(VTextGraphicsItem::mNormal), m_bReleased(false), - m_ptStartPos(), m_ptStart(), m_ptRotCenter(), m_szStart(), m_dRotation(0), m_dAngle(0), - m_rectResize(), m_iMinH(MIN_H), m_rectBoundingBox(), m_tm() + : QGraphicsObject(pParent), + m_eMode(VTextGraphicsItem::mNormal), + m_bReleased(false), + m_ptStartPos(), + m_ptStart(), + m_ptRotCenter(), + m_szStart(), + m_dRotation(0), + m_dAngle(0), + m_rectResize(), + m_rectBoundingBox(), + m_tm() { m_rectBoundingBox.setTopLeft(QPointF(0, 0)); - SetSize(MIN_W, m_iMinH); + SetSize(minW, minH); setZValue(INACTIVE_Z); setAcceptHoverEvents(true); } @@ -165,20 +174,23 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem painter->setBrush(Qt::black); painter->drawEllipse( QPointF(m_rectBoundingBox.width()/2, m_rectBoundingBox.height()/2), - ROTATE_CIRCLE, - ROTATE_CIRCLE + rotateCircle, + rotateCircle ); - painter->setPen(QPen(Qt::black, 3)); - painter->setBrush(Qt::NoBrush); - // and then draw the arc in each of the corners - int iTop = ROTATE_RECT - ROTATE_ARC; - int iLeft = ROTATE_RECT - ROTATE_ARC; - int iRight = qRound(m_rectBoundingBox.width()) - ROTATE_RECT; - int iBottom = qRound(m_rectBoundingBox.height()) - ROTATE_RECT; - painter->drawArc(iLeft, iTop, ROTATE_ARC, ROTATE_ARC, 180*16, -90*16); - painter->drawArc(iRight, iTop, ROTATE_ARC, ROTATE_ARC, 90*16, -90*16); - painter->drawArc(iLeft, iBottom, ROTATE_ARC, ROTATE_ARC, 270*16, -90*16); - painter->drawArc(iRight, iBottom, ROTATE_ARC, ROTATE_ARC, 0*16, -90*16); + if (m_rectBoundingBox.width() > minW*3 && m_rectBoundingBox.height() > minH*3) + { + painter->setPen(QPen(Qt::black, 3)); + painter->setBrush(Qt::NoBrush); + // and then draw the arc in each of the corners + int iTop = ROTATE_RECT - ROTATE_ARC; + int iLeft = ROTATE_RECT - ROTATE_ARC; + int iRight = qRound(m_rectBoundingBox.width()) - ROTATE_RECT; + int iBottom = qRound(m_rectBoundingBox.height()) - ROTATE_RECT; + painter->drawArc(iLeft, iTop, ROTATE_ARC, ROTATE_ARC, 180*16, -90*16); + painter->drawArc(iRight, iTop, ROTATE_ARC, ROTATE_ARC, 90*16, -90*16); + painter->drawArc(iLeft, iBottom, ROTATE_ARC, ROTATE_ARC, 270*16, -90*16); + painter->drawArc(iRight, iBottom, ROTATE_ARC, ROTATE_ARC, 0*16, -90*16); + } } } } @@ -235,26 +247,21 @@ void VTextGraphicsItem::SetSize(qreal fW, qreal fH) { qDebug() << "Setting size to" << fW << parentItem()->boundingRect().width(); // don't allow resize under specific size - if (fW < MIN_W || fH < m_iMinH) - { - return; - } - if (fW > parentItem()->boundingRect().width()) { fW = parentItem()->boundingRect().width(); } - if (fW < MIN_W) + if (fW < minW) { - fW = MIN_W; + fW = minW; } if (fH > parentItem()->boundingRect().height()) { fH = parentItem()->boundingRect().height(); } - if (fH < m_iMinH) + if (fH < minH) { - fH = m_iMinH; + fH = minH; } prepareGeometryChange(); @@ -262,9 +269,9 @@ void VTextGraphicsItem::SetSize(qreal fW, qreal fH) m_rectBoundingBox.setTopLeft(QPointF(0, 0)); m_rectBoundingBox.setWidth(fW); m_rectBoundingBox.setHeight(fH); - m_rectResize.setTopLeft(QPointF(fW - RESIZE_SQUARE, fH - RESIZE_SQUARE)); - m_rectResize.setWidth(RESIZE_SQUARE); - m_rectResize.setHeight(RESIZE_SQUARE); + m_rectResize.setTopLeft(QPointF(fW - resizeSquare, fH - resizeSquare)); + m_rectResize.setWidth(resizeSquare); + m_rectResize.setHeight(resizeSquare); setTransformOriginPoint(m_rectBoundingBox.center()); } diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 88e0eb460..923b91ac2 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -75,13 +75,14 @@ public: virtual ~VTextGraphicsItem(); void SetFont(const QFont& fnt); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget) Q_DECL_OVERRIDE; void Reset(); bool IsIdle() const; int GetFontSize() const; - QRectF boundingRect() const; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; void AddLine(const TextLine& tl); void Clear(); void SetSize(qreal fW, qreal fH); @@ -92,11 +93,11 @@ public: int GetTextLines() const; protected: - void mousePressEvent(QGraphicsSceneMouseEvent* pME); - void mouseMoveEvent(QGraphicsSceneMouseEvent* pME); - void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME); - void hoverMoveEvent(QGraphicsSceneHoverEvent* pHE); - void hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE); + virtual void mousePressEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE; + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) Q_DECL_OVERRIDE; + virtual void hoverMoveEvent(QGraphicsSceneHoverEvent* pHE) Q_DECL_OVERRIDE; + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE) Q_DECL_OVERRIDE; void UpdateBox(); void CorrectLabel(); @@ -118,7 +119,6 @@ private: double m_dRotation; double m_dAngle; QRectF m_rectResize; - int m_iMinH; QRectF m_rectBoundingBox; VTextManager m_tm; From cda54a62eca964aa1ca3797d8acd835b2352e43d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 15 Dec 2016 09:00:16 +0200 Subject: [PATCH 8/9] Updated ChangeLog.txt. --HG-- branch : feature --- ChangeLog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index b48a7cbbe..737dba10c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -47,6 +47,7 @@ - [#580] Extend the list of heights. - [#582] Issue with standard path to shared data on Linux. - [#595] GapWidth affecting to the margins. +- [#589] Valentina lock up if not enough space for label. # Version 0.4.6 - [#594] Broken export on Mac. From d45a04feb001d0ff91ce91f01517a395ad1f9953 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 15 Dec 2016 09:33:01 +0200 Subject: [PATCH 9/9] Correct label size according to parent's bounding rect. --HG-- branch : feature --- src/libs/vtools/tools/vtextgraphicsitem.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index e87cd3595..850c87abc 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -433,7 +433,7 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) qreal dX; qreal dY; QRectF rectBB; - QPointF ptDiff = pME->scenePos() - m_ptStart; + const QPointF ptDiff = pME->scenePos() - m_ptStart; if (m_eMode == mMove) { // in move mode move the label along the mouse move from the origin @@ -458,12 +458,14 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) 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) == true) + if (IsContained(rectBB, rotation(), dX, dY) == false) { - SetSize(sz.width(), sz.height()); - Update(); - emit SignalShrink(); + sz = QSizeF(sz.width()+dX, sz.height()+dY); } + + SetSize(sz.width(), sz.height()); + Update(); + emit SignalShrink(); } else if (m_eMode == mRotate) { @@ -651,7 +653,7 @@ QRectF VTextGraphicsItem::GetBoundingRect(QRectF rectBB, qreal dRot) const qreal dY1 = 0; qreal dY2 = 0; - double dAng = qDegreesToRadians(dRot); + double dAng = qDegreesToRadians(dRot); for (int i = 0; i < 4; ++i) { QPointF pt = apt[i] - ptCenter;