Add text formatting to the TaskDelegate

Reviewed-By: hunger
This commit is contained in:
dt
2010-04-09 18:46:34 +02:00
parent 5b2f892190
commit 2d908b558a
4 changed files with 33 additions and 4 deletions

View File

@@ -36,7 +36,7 @@
using namespace ProjectExplorer; using namespace ProjectExplorer;
LinuxIccParser::LinuxIccParser() 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 // 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; m_expectFirstLine = false;
} else if (!m_expectFirstLine && m_caretLine.indexIn(line) != -1) { } 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 } else if (!m_expectFirstLine && line.trimmed().isEmpty()) { // last Line
m_expectFirstLine = true; m_expectFirstLine = true;
emit addTask(m_temporary); emit addTask(m_temporary);
} else if (!m_expectFirstLine && m_continuationLines.indexIn(line) != -1) { } else if (!m_expectFirstLine && m_continuationLines.indexIn(line) != -1) {
m_temporary.description.append("\n"); 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()); m_temporary.description.append(m_continuationLines.cap(1).trimmed());
} else { } else {
IOutputParser::stdError(line); IOutputParser::stdError(line);

View File

@@ -50,6 +50,7 @@ private:
QRegExp m_caretLine; QRegExp m_caretLine;
bool m_expectFirstLine; bool m_expectFirstLine;
int m_indent;
ProjectExplorer::Task m_temporary; ProjectExplorer::Task m_temporary;
}; };

View File

@@ -122,7 +122,7 @@ public:
int sizeOfLineNumber(); int sizeOfLineNumber();
void setFileNotFound(const QModelIndex &index, bool b); 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); 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; return (int)m_tasks.at(index.row()).type;
} else if (role == TaskModel::Category) { } else if (role == TaskModel::Category) {
return m_tasks.at(index.row()).category; return m_tasks.at(index.row()).category;
} else if (role == TaskModel::Task_t) {
return QVariant::fromValue(m_tasks.at(index.row()));
} }
return QVariant(); return QVariant();
} }
@@ -879,6 +881,7 @@ void TaskDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
int height = 0; int height = 0;
description.replace('\n', QChar::LineSeparator); description.replace('\n', QChar::LineSeparator);
QTextLayout tl(description); QTextLayout tl(description);
tl.setAdditionalFormats(index.data(TaskModel::Task_t).value<ProjectExplorer::Task>().formats);
tl.beginLayout(); tl.beginLayout();
while (true) { while (true) {
QTextLine line = tl.createLine(); QTextLine line = tl.createLine();

View File

@@ -38,6 +38,7 @@
#include <QtCore/QModelIndex> #include <QtCore/QModelIndex>
#include <QtGui/QAction> #include <QtGui/QAction>
#include <QtGui/QToolButton> #include <QtGui/QToolButton>
#include <QtGui/QTextLayout>
namespace ProjectExplorer { namespace ProjectExplorer {
@@ -65,7 +66,7 @@ struct PROJECTEXPLORER_EXPORT Task {
{ } { }
Task(const Task &source) : Task(const Task &source) :
type(source.type), description(source.description), file(source.file), 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() ~Task()
{ } { }
@@ -75,6 +76,16 @@ struct PROJECTEXPLORER_EXPORT Task {
QString file; QString file;
int line; int line;
QString category; 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 class PROJECTEXPLORER_EXPORT TaskWindow : public Core::IOutputPane