Cleaning code.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-12-14 11:59:21 +02:00
parent 62d3d5283a
commit 4eb9b2da83
4 changed files with 12 additions and 49 deletions

View File

@ -148,15 +148,10 @@ void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& da
// generate text // generate text
d->m_tmDetail.SetFont(font); d->m_tmDetail.SetFont(font);
int iFS = data.GetFontSize(); d->m_tmDetail.SetFontSize(data.GetFontSize());
if (iFS < MIN_FONT_SIZE)
{
iFS = MIN_FONT_SIZE;
}
d->m_tmDetail.SetFontSize(iFS);
d->m_tmDetail.Update(qsName, data); d->m_tmDetail.Update(qsName, data);
// this will generate the lines of text // 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()); d->m_tmDetail.FitFontSize(data.GetLabelWidth(), data.GetLabelHeight());
} }
@ -180,17 +175,12 @@ void VLayoutDetail::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternI
// Generate text // Generate text
d->m_tmPattern.SetFont(font); d->m_tmPattern.SetFont(font);
int iFS = geom.GetFontSize(); d->m_tmPattern.SetFontSize(geom.GetFontSize());
if (iFS < MIN_FONT_SIZE)
{
iFS = MIN_FONT_SIZE;
}
d->m_tmPattern.SetFontSize(iFS);
d->m_tmPattern.Update(pDoc, dSize, dHeight); d->m_tmPattern.Update(pDoc, dSize, dHeight);
// generate lines of text // generate lines of text
d->m_tmPattern.SetFontSize(iFS); d->m_tmPattern.SetFontSize(geom.GetFontSize());
d->m_tmPattern.FitFontSize(geom.GetLabelWidth(), geom.GetLabelHeight()); d->m_tmPattern.FitFontSize(geom.GetLabelWidth(), geom.GetLabelHeight());
} }
@ -592,7 +582,7 @@ void VLayoutDetail::CreateTextItems()
QString qsText = tl.m_qsText; QString qsText = tl.m_qsText;
if (fm.width(qsText) > dW) if (fm.width(qsText) > dW)
{ {
qsText = fm.elidedText(qsText, Qt::ElideRight, dW); qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast<int>(dW));
} }
// find the correct horizontal offset, depending on the alignment flag // find the correct horizontal offset, depending on the alignment flag
if ((tl.m_eAlign & Qt::AlignLeft) > 0) if ((tl.m_eAlign & Qt::AlignLeft) > 0)
@ -646,7 +636,7 @@ void VLayoutDetail::CreateTextItems()
QString qsText = tl.m_qsText; QString qsText = tl.m_qsText;
if (fm.width(qsText) > dW) if (fm.width(qsText) > dW)
{ {
qsText = fm.elidedText(qsText, Qt::ElideRight, dW); qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast<int>(dW));
} }
if ((tl.m_eAlign & Qt::AlignLeft) > 0) if ((tl.m_eAlign & Qt::AlignLeft) > 0)
{ {

View File

@ -32,11 +32,11 @@
#include <QLatin1String> #include <QLatin1String>
#include <QRegularExpression> #include <QRegularExpression>
#include <QApplication> #include <QApplication>
#include <QtMath>
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../vpatterndb/vpatternpiecedata.h" #include "../vpatterndb/vpatternpiecedata.h"
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
#include "../vmisc/vmath.h"
#include "vtextmanager.h" #include "vtextmanager.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -117,14 +117,7 @@ const QFont& VTextManager::GetFont() const
*/ */
void VTextManager::SetFontSize(int iFS) void VTextManager::SetFontSize(int iFS)
{ {
if (iFS < MIN_FONT_SIZE) iFS < MIN_FONT_SIZE ? m_font.setPixelSize(MIN_FONT_SIZE) : m_font.setPixelSize(iFS);
{
m_font.setPixelSize(MIN_FONT_SIZE);
}
else
{
m_font.setPixelSize(iFS);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -172,7 +165,7 @@ const TextLine& VTextManager::GetSourceLine(int i) const
{ {
Q_ASSERT(i >= 0); Q_ASSERT(i >= 0);
Q_ASSERT(i < m_liLines.count()); Q_ASSERT(i < m_liLines.count());
return m_liLines[i]; return m_liLines.at(i);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -125,7 +125,7 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
QFontMetrics fm(fnt); QFontMetrics fm(fnt);
if (fm.width(qsText) > iW) if (fm.width(qsText) > iW)
{ {
qsText = fm.elidedText(qsText, Qt::ElideRight, iW); qsText = fm.elidedText(qsText, Qt::ElideMiddle, iW);
} }
painter->setFont(fnt); painter->setFont(fnt);
@ -209,24 +209,6 @@ bool VTextGraphicsItem::IsIdle() const
void VTextGraphicsItem::AddLine(const TextLine& tl) void VTextGraphicsItem::AddLine(const TextLine& tl)
{ {
m_tm.AddSourceLine(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);
}
*/
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -837,12 +837,10 @@ void VToolDetail::UpdateLabel()
if (data.IsVisible() == true) if (data.IsVisible() == true)
{ {
QFont fnt = qApp->font(); 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->SetFont(fnt);
dataLabel->SetSize(data.GetLabelWidth(), data.GetLabelHeight()); dataLabel->SetSize(data.GetLabelWidth(), data.GetLabelHeight());
dataLabel->UpdateData(detail.getName(), data); dataLabel->UpdateData(detail.getName(), data);