MCPcopy Create free account
hub / github.com/KDE/kdevelop / paint

Method paint

plugins/grepview/grepoutputdelegate.cpp:44–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44void GrepOutputDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
45{
46 // there is no function in QString to left-trim. A call to remove this regexp does the job
47 static const QRegularExpression leftspaces(QStringLiteral("^\\s*"));
48
49 // rich text component
50 const auto* model = qobject_cast<const GrepOutputModel*>(index.model());
51 const auto *item = dynamic_cast<const GrepOutputItem *>(model->itemFromIndex(index));
52
53 QStyleOptionViewItem options = option;
54 initStyleOption(&options, index);
55
56 // building item representation
57 QTextDocument doc;
58 QTextCursor cur(&doc);
59
60 QPalette::ColorGroup cg = (options.state & QStyle::State_Enabled)
61 ? QPalette::Normal : QPalette::Disabled;
62 QPalette::ColorRole cr = (options.state & QStyle::State_Selected)
63 ? QPalette::HighlightedText : QPalette::Text;
64 QTextCharFormat fmt = cur.charFormat();
65 fmt.setFont(options.font);
66
67 if(item && item->isText())
68 {
69 // Use custom manual highlighting
70
71 const KTextEditor::Range rng = item->change()->m_range;
72
73 // the line number appears grayed
74 fmt.setForeground(options.palette.brush(QPalette::Disabled, cr));
75 cur.insertText(i18n("Line %1: ",item->lineNumber()), fmt);
76
77 // switch to normal color
78 fmt.setForeground(options.palette.brush(cg, cr));
79 cur.insertText(item->text().left(rng.start().column()).remove(leftspaces), fmt);
80
81 fmt.setFontWeight(QFont::Bold);
82 if ( !(options.state & QStyle::State_Selected) ) {
83 QColor bgHighlight = option.palette.color(QPalette::AlternateBase);
84 fmt.setBackground(bgHighlight);
85 }
86 cur.insertText(item->text().mid(rng.start().column(), rng.end().column() - rng.start().column()), fmt);
87 fmt.clearBackground();
88
89 fmt.setFontWeight(QFont::Normal);
90 cur.insertText(item->text().mid(rng.end().column()), fmt);
91 }else{
92 QString text;
93 if(item)
94 text = item->text();
95 else
96 text = index.data().toString();
97 // Simply insert the text as html. We use this for the titles.
98 doc.setHtml(text);
99 }
100
101 painter->save();

Callers

nothing calls this directly

Calls 15

isTextMethod · 0.80
changeMethod · 0.80
midMethod · 0.80
setHtmlMethod · 0.80
styleMethod · 0.80
QStringClass · 0.50
QPointClass · 0.50
modelMethod · 0.45
itemFromIndexMethod · 0.45
lineNumberMethod · 0.45
removeMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected