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

Method paint

kdevplatform/vcs/widgets/vcsannotationitemdelegate.cpp:233–299  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231}
232
233void VcsAnnotationItemDelegate::paint(QPainter* painter, const KTextEditor::StyleOptionAnnotationItem& option,
234 KTextEditor::AnnotationModel* model, int line) const
235{
236 Q_ASSERT(painter);
237 // we cannot use custom roles and data() API (cmp. VcsAnnotationModel dox), so accessing custom API instead
238 auto* vcsModel = qobject_cast<VcsAnnotationModel*>(model);
239 Q_ASSERT(vcsModel);
240 if (!painter || !vcsModel) {
241 return;
242 }
243 // test of line just for sake of completeness skipped here
244
245 // Fetch data from the model
246 const VcsAnnotationLine annotationLine = vcsModel->annotationLine(line);
247
248 if (annotationLine.revision().revisionType() == VcsRevision::Invalid) {
249 return;
250 }
251
252 // prepare
253 painter->save();
254
255 renderBackground(painter, option, annotationLine);
256
257 // We use the normal UI font here, which usually is a proportimal one,
258 // so more text fits into the available space.
259 // Though we do this at the cost of not adapting to any scaled content font size,
260 // as there is no zooming state info available, so we cannot adapt.
261 // Tooltip font also is not scaled, and annotations could be considered to fall into
262 // that category, so might be fine.
263 painter->setFont(option.view->font());
264
265 if (option.visibleWrappedLineInGroup == 0) {
266 QRect ageRect;
267 QString ageText;
268 const auto date = annotationLine.date();
269 if (date.isValid()) {
270 ageText = ageOfDate(date.date());
271 ageRect = QRect(QPoint(0, 0), QSize(option.fontMetrics.horizontalAdvance(ageText), option.rect.height()));
272 }
273
274 const auto messageText = annotationLine.commitMessage();
275 // messageRect must be valid, so its width must be positive
276 const auto messageRectWidth = messageText.isEmpty() ? 1 : option.fontMetrics.horizontalAdvance(messageText);
277 auto messageRect = QRect(QPoint(0, 0), QSize{messageRectWidth, option.rect.height()});
278
279 doMessageLineLayout(option, &messageRect, &ageRect);
280
281 renderMessageAndAge(painter, option, messageRect, messageText, ageRect, ageText);
282 } else if (option.visibleWrappedLineInGroup == 1) {
283 const auto author = annotationLine.author();
284 if (!author.isEmpty()) {
285 const auto authorText = i18nc("By: commit author", "By: %1", author);
286 auto authorRect =
287 QRect(QPoint(0, 0), QSize(option.fontMetrics.horizontalAdvance(authorText), option.rect.height()));
288
289 doAuthorLineLayout(option, &authorRect);
290

Callers

nothing calls this directly

Calls 12

ageOfDateFunction · 0.85
QRectClass · 0.85
annotationLineMethod · 0.80
revisionTypeMethod · 0.80
QPointClass · 0.50
revisionMethod · 0.45
saveMethod · 0.45
dateMethod · 0.45
isValidMethod · 0.45
commitMessageMethod · 0.45
isEmptyMethod · 0.45
authorMethod · 0.45

Tested by

no test coverage detected