From d0de2fdbbc10a916567e1fc332f307e64f18e306 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Wed, 18 Mar 2015 16:11:00 +0100 Subject: 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 --- plugins/autotest/testresultdelegate.cpp | 38 +++++++++++++-------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/plugins/autotest/testresultdelegate.cpp b/plugins/autotest/testresultdelegate.cpp index 32aa33df5e..51226270e7 100644 --- a/plugins/autotest/testresultdelegate.cpp +++ b/plugins/autotest/testresultdelegate.cpp @@ -119,25 +119,16 @@ void TestResultDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op output = output.split(QLatin1Char('\n')).first(); } - QColor mix; - mix.setRgb( static_cast(0.7 * foreground.red() + 0.3 * background.red()), - static_cast(0.7 * foreground.green() + 0.3 * background.green()), - static_cast(0.7 * foreground.blue() + 0.3 * background.blue())); - if (selected) { int height = 0; int leading = fm.leading(); - int firstLineBreak = output.indexOf(QLatin1Char('\n')); + int fontHeight = fm.height(); output.replace(QLatin1Char('\n'), QChar::LineSeparator); QTextLayout tl(output); - if (firstLineBreak != -1) { - QTextLayout::FormatRange fr; - fr.start = firstLineBreak; - fr.length = output.length() - firstLineBreak; - fr.format.setFontStyleHint(QFont::Monospace); - fr.format.setForeground(mix); - tl.setAdditionalFormats(QList() << fr); - } + tl.setFont(painter->font()); + QTextOption txtOption; + txtOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); + tl.setTextOption(txtOption); tl.beginLayout(); while (true) { QTextLine tLine = tl.createLine(); @@ -146,18 +137,14 @@ void TestResultDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op tLine.setLineWidth(positions.textAreaWidth()); height += leading; tLine.setPosition(QPoint(0, height)); - height += fm.ascent() + fm.descent(); + height += fontHeight; } tl.endLayout(); 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 { 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(); @@ -236,18 +223,23 @@ QSize TestResultDelegate::sizeHint(const QStyleOptionViewItem &option, const QMo int height = 0; int leading = fm.leading(); QTextLayout tl(output); + tl.setFont(opt.font); + QTextOption txtOption; + txtOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); + tl.setTextOption(txtOption); tl.beginLayout(); while (true) { QTextLine line = tl.createLine(); if (!line.isValid()) break; + line.setLineWidth(positions.textAreaWidth()); height += leading; line.setPosition(QPoint(0, height)); - height += fm.ascent() + fm.descent(); + height += fontHeight; } tl.endLayout(); - s.setHeight(height + leading + 3 + (testResult.fileName().isEmpty() ? 0 : fontHeight)); + s.setHeight(height + 3); } else { s.setHeight(fontHeight + 3); } -- cgit v1.2.1