Commit 75a222b6 authored by David Redondo's avatar David Redondo

Grepview - Introduce a new intermediate level corresponding to lines

Summary: Add items that correspond to whole lines which is useful if a line contains multiple matches.

Test Plan:
{F6868680}
Tests pass

Reviewers: #kdevelop, apol

Reviewed By: #kdevelop, apol

Subscribers: kdevelop-devel

Tags: #kdevelop

Differential Revision: https://phabricator.kde.org/D21580
parent 6be8e8ae
Pipeline #4263 failed with stage
in 60 minutes and 1 second
......@@ -78,28 +78,50 @@ void GrepOutputDelegate::paint( QPainter* painter, const QStyleOptionViewItem& o
if(item && item->isText())
{
// Use custom manual highlighting
const KTextEditor::Range rng = item->change()->m_range;
// the line number appears grayed
fmt.setForeground(options.palette.brush(QPalette::Disabled, cr));
cur.insertText(i18n("Line %1: ",item->lineNumber()), fmt);
// switch to normal color
fmt.setForeground(options.palette.brush(cg, cr));
cur.insertText(item->text().left(rng.start().column()).remove(leftspaces), fmt);
fmt.setFontWeight(QFont::Bold);
if ( !(options.state & QStyle::State_Selected) ) {
QColor bgHighlight = option.palette.color(QPalette::AlternateBase);
fmt.setBackground(bgHighlight);
if (item->hasChildren()) {
// the line number appears grayed
fmt.setForeground(options.palette.brush(QPalette::Disabled, cr));
cur.insertText(i18n("Line %1: ",item->lineNumber()), fmt);
fmt.setForeground(options.palette.brush(cg, cr));
int firstStart = static_cast<GrepOutputItem*>(item->child(0))->change()->m_range.start().column();
cur.insertText(item->text().left(firstStart).remove(leftspaces), fmt);
KTextEditor::Range previousRange(item->lineNumber(), 0, item->lineNumber(), firstStart);
for (int i = 0; i < item->rowCount(); ++i) {
const KTextEditor::Range range = static_cast<GrepOutputItem*>(item->child(i))->change()->m_range;
fmt.setForeground(options.palette.brush(cg, cr));
cur.insertText(item->text().mid(previousRange.end().column(), range.start().column() - previousRange.end().column()), fmt);
fmt.setFontWeight(QFont::Bold);
if ( !(options.state & QStyle::State_Selected) ) {
QColor bgHighlight = option.palette.color(QPalette::AlternateBase);
fmt.setBackground(bgHighlight);
}
cur.insertText(item->text().mid(range.start().column(), range.columnWidth()), fmt);
fmt.clearBackground();
previousRange = range;
}
fmt.setFontWeight(QFont::Normal);
cur.insertText(item->text().mid(previousRange.end().column()), fmt);
} else {
// Use custom manual highlighting
const KTextEditor::Range rng = item->change()->m_range;
// switch to normal color
fmt.setForeground(options.palette.brush(cg, cr));
cur.insertText(item->text().left(rng.start().column()).remove(leftspaces), fmt);
fmt.setFontWeight(QFont::Bold);
if ( !(options.state & QStyle::State_Selected) ) {
QColor bgHighlight = option.palette.color(QPalette::AlternateBase);
fmt.setBackground(bgHighlight);
}
cur.insertText(item->text().mid(rng.start().column(), rng.end().column() - rng.start().column()), fmt);
fmt.clearBackground();
fmt.setFontWeight(QFont::Normal);
cur.insertText(item->text().mid(rng.end().column()), fmt);
}
cur.insertText(item->text().mid(rng.start().column(), rng.end().column() - rng.start().column()), fmt);
fmt.clearBackground();
fmt.setFontWeight(QFont::Normal);
cur.insertText(item->text().mid(rng.end().column()), fmt);
}else{
QString text;
if(item)
......@@ -146,15 +168,25 @@ QSize GrepOutputDelegate::sizeHint(const QStyleOptionViewItem& option, const QMo
QFontMetrics metrics(font);
font.setBold(true);
QFontMetrics bMetrics(font);
const KTextEditor::Range rng = item->change()->m_range;
int width = metrics.width(item->text().left(rng.start().column())) +
metrics.width(item->text().mid(rng.end().column())) +
bMetrics.width(item->text().mid(rng.start().column(), rng.end().column() - rng.start().column())) +
option.fontMetrics.width(i18n("Line %1: ",item->lineNumber())) +
std::max(option.decorationSize.width(), 0);
ret.setWidth(width);
if (item->hasChildren()) {
int bWidth = 0;
for (int i = 0; i < item->rowCount(); ++i) {
bWidth += static_cast<GrepOutputItem*>(item->child(i))->change()->m_range.columnWidth();
}
int width = option.fontMetrics.width(i18n("Line %1: ",item->lineNumber())) +
metrics.width(item->text().length() - bWidth) + bMetrics.width(bWidth) +
std::max(option.decorationSize.width(), 0);
ret.setWidth(width);
} else {
const KTextEditor::Range rng = item->change()->m_range;
int width = metrics.width(item->text().left(rng.start().column())) +
metrics.width(item->text().mid(rng.end().column())) +
bMetrics.width(item->text().mid(rng.start().column(), rng.end().column() - rng.start().column())) +
std::max(option.decorationSize.width(), 0);
ret.setWidth(width);
}
}else{
// This is only used for titles, so not very performance critical
QString text;
......
This diff is collapsed.
......@@ -34,6 +34,7 @@ public:
GrepOutputItem(const KDevelop::DocumentChangePointer& change, const QString& text, bool checkable);
GrepOutputItem(const QString &filename, const QString &text, bool checkable);
GrepOutputItem(const QString &filename, const QString &text, int line, bool checkable);
~GrepOutputItem() override;
QString filename() const ;
......
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