Skip to content

Commit

Permalink
MythUIText: Fix a fringe case when a single line of text is *just* the
Browse files Browse the repository at this point in the history
wrong size, and is being cutdown.

QFontMetrics seems to think more 'text' fits in a given width, than
QTextLine.  I don't know how to determine exactly what the difference is, so
tell QFontMetrics that the width is averageCharWidth() less than it really
is.

Also force the text to be rendered, even when QTextLine thinks it doesn't
fit, in case averageCharWidth() is too small.  This may result in not all of
the '...' from being rendered, but it is better than rendering no text at
all.
  • Loading branch information
jpoet committed Jan 25, 2012
1 parent daa9f1d commit afcda5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions mythtv/libs/libmythui/mythuitext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ void MythUIText::DrawSelf(MythPainter *p, int xoffset, int yoffset,

bool MythUIText::Layout(QString & paragraph, QTextLayout *layout,
bool & overflow, qreal width, qreal & height,
qreal & last_line_width,
bool force, qreal & last_line_width,
QRectF & min_rect, int & num_lines)
{
int last_line = 0;
Expand All @@ -392,12 +392,13 @@ bool MythUIText::Layout(QString & paragraph, QTextLayout *layout,
// Try "visible" width first, so alignment works
line.setLineWidth(width);

if (!m_MultiLine && line.textLength() < paragraph.size())
if (!force && !m_MultiLine && line.textLength() < paragraph.size())
{
if (m_Cutdown != Qt::ElideNone)
{
QFontMetrics fm(GetFontProperties()->face());
paragraph = fm.elidedText(paragraph, m_Cutdown, width - 1);
paragraph = fm.elidedText(paragraph, m_Cutdown,
width - fm.averageCharWidth());
return false;
}
// If text does not fit, then expand so canvas size is correct
Expand All @@ -424,8 +425,10 @@ bool MythUIText::Layout(QString & paragraph, QTextLayout *layout,
if (m_Cutdown != Qt::ElideNone)
{
QFontMetrics fm(GetFontProperties()->face());
QString cut_line = fm.elidedText(paragraph.mid(last_line),
Qt::ElideRight, width - 1);
QString cut_line = fm.elidedText
(paragraph.mid(last_line),
Qt::ElideRight,
width - fm.averageCharWidth());
paragraph = paragraph.left(last_line) + cut_line;
if (last_line == 0)
min_rect |= line.naturalTextRect();
Expand Down Expand Up @@ -477,13 +480,13 @@ bool MythUIText::LayoutParagraphs(const QStringList & paragraphs,
para = *Ipara;
saved_height = height;
saved_rect = min_rect;
if (!Layout(para, layout, overflow, width, height,
if (!Layout(para, layout, overflow, width, height, false,
last_line_width, min_rect, num_lines))
{
// Again, with cut down
min_rect = saved_rect;
height = saved_height;
Layout(para, layout, overflow, width, height,
Layout(para, layout, overflow, width, height, true,
last_line_width, min_rect, num_lines);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/mythuitext.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class MUI_PUBLIC MythUIText : public MythUIType, public StorageUser
void ShiftCanvas(int x, int y);

bool Layout(QString & paragraph, QTextLayout *layout,
bool & overflow, qreal width, qreal & height,
bool & overflow, qreal width, qreal & height, bool force,
qreal & last_line_width, QRectF & min_rect, int & num_lines);
bool LayoutParagraphs(const QStringList & paragraphs,
const QTextOption & textoption,
Expand Down

0 comments on commit afcda5e

Please sign in to comment.