MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / drawText

Method drawText

src/plugins/codeeditor/codelens/codelensdelegate.cpp:133–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131}
132
133void CodeLensDelegate::drawText(QPainter *painter, const QStyleOptionViewItem &option,
134 const QRect &rect, const QModelIndex &index) const
135{
136 const auto text = itemText(index);
137 const int termStart = index.data(CodeLensItemRole::TermStartRole).toInt();
138 const auto termEnd = index.data(CodeLensItemRole::TermEndRole).toInt();
139 int termLength = termEnd - termStart;
140 if (termStart < 0 || termStart >= text.length() || termLength < 1) {
141 QItemDelegate::drawDisplay(painter,
142 option,
143 rect,
144 QString(text).replace(QLatin1Char('\t'), tabStr));
145 return;
146 }
147
148 // clip searchTermLength to end of line
149 termLength = qMin(termLength, text.length() - termStart);
150 const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
151 const QString textBefore = text.left(termStart).replace(QLatin1Char('\t'), tabStr);
152 const QString textHighlight = text.mid(termStart, termLength).replace(QLatin1Char('\t'), tabStr);
153 const QString textAfter = text.mid(termStart + termLength).replace(QLatin1Char('\t'), tabStr);
154 int searchTermStartPixels = option.fontMetrics.horizontalAdvance(textBefore);
155 int searchTermLengthPixels = option.fontMetrics.horizontalAdvance(textHighlight);
156 int textAfterLengthPixels = option.fontMetrics.horizontalAdvance(textAfter);
157
158 // rects
159 QRect beforeHighlightRect(rect);
160 beforeHighlightRect.setRight(beforeHighlightRect.left() + searchTermStartPixels);
161
162 QRect resultHighlightRect(rect);
163 resultHighlightRect.setLeft(beforeHighlightRect.right());
164 resultHighlightRect.setRight(resultHighlightRect.left() + searchTermLengthPixels);
165
166 QRect afterHighlightRect(rect);
167 afterHighlightRect.setLeft(resultHighlightRect.right());
168 afterHighlightRect.setRight(afterHighlightRect.left() + textAfterLengthPixels);
169
170 // paint all highlight backgrounds
171 bool isSelected = option.state & QStyle::State_Selected;
172 QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
173 ? QPalette::Normal
174 : QPalette::Disabled;
175 if (cg == QPalette::Normal && !(option.state & QStyle::State_Active))
176 cg = QPalette::Inactive;
177 QStyleOptionViewItem baseOption = option;
178 baseOption.state &= ~QStyle::State_Selected;
179 if (isSelected) {
180 painter->fillRect(beforeHighlightRect.adjusted(textMargin, 0, textMargin, 0),
181 option.palette.brush(cg, QPalette::Highlight));
182 painter->fillRect(afterHighlightRect.adjusted(textMargin, 0, textMargin, 0),
183 option.palette.brush(cg, QPalette::Highlight));
184 }
185
186 QColor highlightBackground("#ffef0b");
187 if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType)
188 highlightBackground = QColor("#8a7f2c");
189 painter->fillRect(resultHighlightRect.adjusted(textMargin, 0, textMargin - 1, 0),
190 QBrush(highlightBackground));

Callers 15

paintEventMethod · 0.45
paintEventMethod · 0.45
drawToolItemMethod · 0.45
paintMethod · 0.45
paintSeparatorMethod · 0.45
paintLineNumbersMethod · 0.45
paintItemColumnMethod · 0.45
paintItemColumnMethod · 0.45
drawObjectMethod · 0.45
paintEventMethod · 0.45
paintMethod · 0.45
drawResultCountMethod · 0.45

Calls 10

itemTextFunction · 0.85
styleFunction · 0.85
leftMethod · 0.80
rightMethod · 0.80
QStringClass · 0.50
dataMethod · 0.45
lengthMethod · 0.45
replaceMethod · 0.45
colorMethod · 0.45
setColorMethod · 0.45

Tested by

no test coverage detected