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

Method drawDisplay

plugins/quickopen/expandingtree/expandingdelegate.cpp:156–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154}
155
156void ExpandingDelegate::drawDisplay(QPainter* painter, const QStyleOptionViewItem& option, const QRect& _rect, const QString& text) const
157{
158 QRect rect(_rect);
159
160 adjustRect(rect);
161
162 QTextLayout layout(text, option.font, painter->device());
163
164 QVector<QTextLayout::FormatRange> additionalFormats;
165
166 int missingFormats = text.length();
167
168 for (int i = 0; i < m_cachedHighlights.count(); ++i) {
169 if (m_cachedHighlights[i].start + m_cachedHighlights[i].length <= m_currentColumnStart) {
170 continue;
171 }
172
173 if (additionalFormats.isEmpty()) {
174 if (i != 0 && m_cachedHighlights[i - 1].start + m_cachedHighlights[i - 1].length > m_currentColumnStart) {
175 QTextLayout::FormatRange before;
176 before.start = 0;
177 before.length = m_cachedHighlights[i - 1].start + m_cachedHighlights[i - 1].length - m_currentColumnStart;
178 before.format = m_cachedHighlights[i - 1].format;
179 additionalFormats.append(before);
180 }
181 }
182
183 QTextLayout::FormatRange format;
184 format.start = m_cachedHighlights[i].start - m_currentColumnStart;
185 format.length = m_cachedHighlights[i].length;
186 format.format = m_cachedHighlights[i].format;
187
188 additionalFormats.append(format);
189 }
190
191 if (!additionalFormats.isEmpty()) {
192 missingFormats = text.length() - (additionalFormats.back().length + additionalFormats.back().start);
193 }
194
195 if (missingFormats > 0) {
196 QTextLayout::FormatRange format;
197 format.start = text.length() - missingFormats;
198 format.length = missingFormats;
199 QTextCharFormat fm;
200 fm.setForeground(option.palette.text());
201 format.format = fm;
202 additionalFormats.append(format);
203 }
204
205 if (m_backgroundColor.isValid()) {
206 QColor background = m_backgroundColor;
207// qCDebug(PLUGIN_QUICKOPEN) << text << "background:" << background.name();
208 //Now go through the formats, and make sure the contrast background/foreground is readable
209 for (auto& additionalFormat : additionalFormats) {
210 QColor currentBackground = background;
211 if (additionalFormat.format.hasProperty(QTextFormat::BackgroundBrush)) {
212 currentBackground = additionalFormat.format.background().color();
213 }

Callers

nothing calls this directly

Calls 11

readabilityContrastFunction · 0.85
hasPropertyMethod · 0.80
QPointClass · 0.50
lengthMethod · 0.45
countMethod · 0.45
isEmptyMethod · 0.45
appendMethod · 0.45
backMethod · 0.45
textMethod · 0.45
isValidMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected