From 4eb9b2da837824b9d80f0271aba13de749727fc9 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 14 Dec 2016 11:59:21 +0200 Subject: [PATCH] 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);