From 21445db240e563379bcdb9471c49417b519a2db4 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Fri, 2 Dec 2016 00:44:28 +0100 Subject: [PATCH] Fixed the hangup bug because of very long label words --HG-- branch : feature --- src/libs/vlayout/vtextmanager.cpp | 15 +++++++++++++++ src/libs/vtools/tools/vtextgraphicsitem.cpp | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index f14d05114..d50cc381a 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -445,6 +445,21 @@ QStringList VTextManager::SplitString(const QString &qs, qreal fW, const QFontMe } } qslLines << qsCurrent; + + int i = 0; + int iHorSp = fm.width(" "); + while (i < qslLines.count()) { + if (fm.width(qslLines[i]) + iHorSp > fW) { + int iPos = qslLines[i].length() >> 1; + QString qs1 = qslLines[i].left(iPos); + QString qs2 = qslLines[i].mid(iPos); + qslLines[i] = qs1; + qslLines.insert(i + 1, qs2); + } else { + ++i; + } + } + return qslLines; } diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 3a49598e2..9189d4004 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -232,6 +232,7 @@ void VTextGraphicsItem::Clear() */ 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) { @@ -255,6 +256,7 @@ void VTextGraphicsItem::SetSize(qreal fW, qreal fH) fH = m_iMinH; } + qDebug() << "Actual size set to" << fW; m_rectBoundingBox.setTopLeft(QPointF(0, 0)); m_rectBoundingBox.setWidth(fW); m_rectBoundingBox.setHeight(fH); @@ -599,6 +601,7 @@ void VTextGraphicsItem::CorrectLabel() { ++iFS; } + // decrease the font size until the bounding rect is big enough while (m_tm.IsBigEnough(m_rectBoundingBox.width(), m_rectBoundingBox.height(), iFS, fMinW, fMinH) == false) { @@ -610,6 +613,8 @@ void VTextGraphicsItem::CorrectLabel() { SetSize(fMinW, fMinH); } + + qDebug() << "DEC FONT" << iFS << m_rectBoundingBox.width() << fMinW; } qreal dX; qreal dY;