Fix results output for long output

For non-selected output use elided text if necessary and
for selected add additional line breaks to make sure the
text fits into the width of the output area.

Additionally removed different style of lines coming after
the first one as it does not make sense at all.

Change-Id: Ifdd8cb076151ce3e0d895c702921d8f4d2a2b15a
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
Christian Stenger
2015-03-18 16:11:00 +01:00
parent adb40d4bd5
commit d0de2fdbbc

View File

@@ -119,25 +119,16 @@ void TestResultDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
output = output.split(QLatin1Char('\n')).first(); output = output.split(QLatin1Char('\n')).first();
} }
QColor mix;
mix.setRgb( static_cast<int>(0.7 * foreground.red() + 0.3 * background.red()),
static_cast<int>(0.7 * foreground.green() + 0.3 * background.green()),
static_cast<int>(0.7 * foreground.blue() + 0.3 * background.blue()));
if (selected) { if (selected) {
int height = 0; int height = 0;
int leading = fm.leading(); int leading = fm.leading();
int firstLineBreak = output.indexOf(QLatin1Char('\n')); int fontHeight = fm.height();
output.replace(QLatin1Char('\n'), QChar::LineSeparator); output.replace(QLatin1Char('\n'), QChar::LineSeparator);
QTextLayout tl(output); QTextLayout tl(output);
if (firstLineBreak != -1) { tl.setFont(painter->font());
QTextLayout::FormatRange fr; QTextOption txtOption;
fr.start = firstLineBreak; txtOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
fr.length = output.length() - firstLineBreak; tl.setTextOption(txtOption);
fr.format.setFontStyleHint(QFont::Monospace);
fr.format.setForeground(mix);
tl.setAdditionalFormats(QList<QTextLayout::FormatRange>() << fr);
}
tl.beginLayout(); tl.beginLayout();
while (true) { while (true) {
QTextLine tLine = tl.createLine(); QTextLine tLine = tl.createLine();
@@ -146,18 +137,14 @@ void TestResultDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
tLine.setLineWidth(positions.textAreaWidth()); tLine.setLineWidth(positions.textAreaWidth());
height += leading; height += leading;
tLine.setPosition(QPoint(0, height)); tLine.setPosition(QPoint(0, height));
height += fm.ascent() + fm.descent(); height += fontHeight;
} }
tl.endLayout(); tl.endLayout();
tl.draw(painter, QPoint(positions.textAreaLeft(), positions.top())); tl.draw(painter, QPoint(positions.textAreaLeft(), positions.top()));
painter->setPen(mix);
int bottomLine = positions.top() + fm.ascent() + height + leading;
painter->drawText(positions.textAreaLeft(), bottomLine, testResult.fileName());
} else { } else {
painter->setClipRect(positions.textArea()); painter->setClipRect(positions.textArea());
painter->drawText(positions.textAreaLeft(), positions.top() + fm.ascent(), output); painter->drawText(positions.textAreaLeft(), positions.top() + fm.ascent(),
fm.elidedText(output, Qt::ElideRight, positions.textAreaWidth()));
} }
QString file = testResult.fileName(); QString file = testResult.fileName();
@@ -236,18 +223,23 @@ QSize TestResultDelegate::sizeHint(const QStyleOptionViewItem &option, const QMo
int height = 0; int height = 0;
int leading = fm.leading(); int leading = fm.leading();
QTextLayout tl(output); QTextLayout tl(output);
tl.setFont(opt.font);
QTextOption txtOption;
txtOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
tl.setTextOption(txtOption);
tl.beginLayout(); tl.beginLayout();
while (true) { while (true) {
QTextLine line = tl.createLine(); QTextLine line = tl.createLine();
if (!line.isValid()) if (!line.isValid())
break; break;
line.setLineWidth(positions.textAreaWidth());
height += leading; height += leading;
line.setPosition(QPoint(0, height)); line.setPosition(QPoint(0, height));
height += fm.ascent() + fm.descent(); height += fontHeight;
} }
tl.endLayout(); tl.endLayout();
s.setHeight(height + leading + 3 + (testResult.fileName().isEmpty() ? 0 : fontHeight)); s.setHeight(height + 3);
} else { } else {
s.setHeight(fontHeight + 3); s.setHeight(fontHeight + 3);
} }