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

Method renderBackground

kdevplatform/vcs/widgets/vcsannotationitemdelegate.cpp:141–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139}
140
141void VcsAnnotationItemDelegate::renderBackground(QPainter* painter,
142 const KTextEditor::StyleOptionAnnotationItem& option,
143 const VcsAnnotationLine& annotationLine) const
144{
145 Q_UNUSED(option);
146
147 const auto revision = annotationLine.revision();
148 auto brushIt = m_backgrounds.find(revision);
149 if (brushIt == m_backgrounds.end()) {
150 const auto normalStyle = option.view->defaultStyleAttribute(KSyntaxHighlighting::Theme::TextStyle::Normal);
151 const auto background = (normalStyle->hasProperty(QTextFormat::BackgroundBrush)) ? normalStyle->background().color() : QColor(Qt::white);
152 const int background_y = background.red()*0.299 + 0.587*background.green()
153 + 0.114*background.blue();
154 // get random, but reproducible 8-bit values from last two bytes of the revision hash
155 const auto revisionHash = qHash(revision);
156 const int u = static_cast<int>((0xFF & revisionHash));
157 const int v = static_cast<int>((0xFF00 & revisionHash) >> 8);
158 const int r = qRound(qMin(255.0, qMax(0.0, background_y + 1.402*(v-128))));
159 const int g = qRound(qMin(255.0, qMax(0.0, background_y - 0.344*(u-128) - 0.714*(v-128))));
160 const int b = qRound(qMin(255.0, qMax(0.0, background_y + 1.772*(u-128))));
161 brushIt = m_backgrounds.insert(revision, QBrush(QColor(r, g, b)));
162 }
163
164 painter->fillRect(option.rect, brushIt.value());
165}
166
167void VcsAnnotationItemDelegate::renderMessageAndAge(QPainter* painter,
168 const KTextEditor::StyleOptionAnnotationItem& option,

Callers

nothing calls this directly

Calls 8

QColorClass · 0.85
hasPropertyMethod · 0.80
qHashFunction · 0.50
revisionMethod · 0.45
findMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected