Commit 2d908b55 authored by dt's avatar dt
Browse files

Add text formatting to the TaskDelegate

Reviewed-By: hunger
parent 5b2f8921
......@@ -36,7 +36,7 @@
using namespace ProjectExplorer;
LinuxIccParser::LinuxIccParser()
: m_expectFirstLine(true)
: m_expectFirstLine(true), m_indent(0)
{
// main.cpp(53): error #308: function \"AClass::privatefunc\" (declared at line 4 of \"main.h\") is inaccessible
......@@ -78,12 +78,26 @@ void LinuxIccParser::stdError(const QString &line)
m_expectFirstLine = false;
} else if (!m_expectFirstLine && m_caretLine.indexIn(line) != -1) {
// TODO do something
// Format the last line as code
QTextLayout::FormatRange fr;
fr.start = m_temporary.description.lastIndexOf('\n') + 1;
fr.length = m_temporary.description.length() - fr.start;
fr.format.setFontItalic(true);
m_temporary.formats.append(fr);
QTextLayout::FormatRange fr2;
fr2.start = fr.start + line.indexOf('^') - m_indent;
fr2.length = 1;
fr2.format.setFontWeight(QFont::Bold);
m_temporary.formats.append(fr2);
} else if (!m_expectFirstLine && line.trimmed().isEmpty()) { // last Line
m_expectFirstLine = true;
emit addTask(m_temporary);
} else if (!m_expectFirstLine && m_continuationLines.indexIn(line) != -1) {
m_temporary.description.append("\n");
m_indent = 0;
while (m_indent < line.length() && line.at(m_indent).isSpace())
m_indent++;
m_temporary.description.append(m_continuationLines.cap(1).trimmed());
} else {
IOutputParser::stdError(line);
......
......@@ -50,6 +50,7 @@ private:
QRegExp m_caretLine;
bool m_expectFirstLine;
int m_indent;
ProjectExplorer::Task m_temporary;
};
......
......@@ -122,7 +122,7 @@ public:
int sizeOfLineNumber();
void setFileNotFound(const QModelIndex &index, bool b);
enum Roles { File = Qt::UserRole, Line, Description, FileNotFound, Type, Category };
enum Roles { File = Qt::UserRole, Line, Description, FileNotFound, Type, Category, Task_t };
QIcon iconFor(Task::TaskType type);
......@@ -337,6 +337,8 @@ QVariant TaskModel::data(const QModelIndex &index, int role) const
return (int)m_tasks.at(index.row()).type;
} else if (role == TaskModel::Category) {
return m_tasks.at(index.row()).category;
} else if (role == TaskModel::Task_t) {
return QVariant::fromValue(m_tasks.at(index.row()));
}
return QVariant();
}
......@@ -879,6 +881,7 @@ void TaskDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
int height = 0;
description.replace('\n', QChar::LineSeparator);
QTextLayout tl(description);
tl.setAdditionalFormats(index.data(TaskModel::Task_t).value<ProjectExplorer::Task>().formats);
tl.beginLayout();
while (true) {
QTextLine line = tl.createLine();
......
......@@ -38,6 +38,7 @@
#include <QtCore/QModelIndex>
#include <QtGui/QAction>
#include <QtGui/QToolButton>
#include <QtGui/QTextLayout>
namespace ProjectExplorer {
......@@ -65,7 +66,7 @@ struct PROJECTEXPLORER_EXPORT Task {
{ }
Task(const Task &source) :
type(source.type), description(source.description), file(source.file),
line(source.line), category(source.category)
line(source.line), category(source.category), formats(source.formats)
{ }
~Task()
{ }
......@@ -75,6 +76,16 @@ struct PROJECTEXPLORER_EXPORT Task {
QString file;
int line;
QString category;
// Having a QList<QTextLayout> in Task
// isn't that great
// It would be cleaner to split up the text into
// the logical hunks and then assemble them again
// (That is diffrent consumers of tasks could show them in
// different ways!)
// But then again, the wording of the text most likely
// doesn't work if you split it up, nor are our parsers
// anywhere near being that good
QList<QTextLayout::FormatRange> formats;
};
class PROJECTEXPLORER_EXPORT TaskWindow : public Core::IOutputPane
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment