Use font's height.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-12-15 08:46:45 +02:00
parent 8d526d2ebc
commit 97d76957e3
4 changed files with 24 additions and 21 deletions

View file

@ -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)
{

View file

@ -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;
}

View file

@ -57,7 +57,6 @@ struct TextLine
QFont::Weight m_eFontWeight;
QFont::Style m_eStyle;
Qt::Alignment m_eAlign;
int m_iHeight;
TextLine();
};

View file

@ -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