MCPcopy Create free account
hub / github.com/KDAB/GammaRay / paint

Method paint

plugins/quickinspector/quickitemdelegate.cpp:33–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31}
32
33void QuickItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
34 const QModelIndex &index) const
35{
36 painter->save();
37 int flags = index.data(QuickItemModelRole::ItemFlags).value<int>();
38
39 QStyleOptionViewItem opt = option;
40 initStyleOption(&opt, index);
41
42 // Disable foreground painting so we can do ourself
43 opt.text.clear();
44 opt.icon = QIcon();
45
46 QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter);
47
48 QRect drawRect = option.rect;
49 painter->setClipRect(option.rect);
50 painter->setClipping(true); // avoid the icons leaking into the next column
51
52 const auto foregroundData = index.data(Qt::ForegroundRole);
53 const auto inactiveColor = foregroundData.isNull() ? option.palette.text().color() : foregroundData.value<QColor>();
54 const auto base = option.state
55 & QStyle::State_Selected
56 ? option.palette.highlightedText().color()
57 : inactiveColor;
58
59 if (m_colors.contains(index.sibling(index.row(), 0))) {
60 QColor blend = m_colors.value(index.sibling(index.row(), 0));
61 QColor blended = QColor::fromRgbF(
62 base.redF() * (1 - blend.alphaF()) + blend.redF() * blend.alphaF(),
63 base.greenF() * (1 - blend.alphaF()) + blend.greenF() * blend.alphaF(),
64 base.blueF() * (1 - blend.alphaF()) + blend.blueF() * blend.alphaF());
65 painter->setPen(blended);
66 } else {
67 painter->setPen(base);
68 }
69
70 if (index.column() == 0) {
71 auto deco = index.data(Qt::DecorationRole);
72 QVector<QPixmap> icons;
73 if (deco.canConvert<QPixmap>())
74 icons.push_back(deco.value<QPixmap>());
75 else if (deco.canConvert<QIcon>())
76 icons.push_back(deco.value<QIcon>().pixmap(16, 16));
77
78 if ((flags & QuickItemModelRole::PartiallyOutOfView) && (~flags & QuickItemModelRole::Invisible))
79 icons << UIResources::themedIcon(QStringLiteral("warning.png")).pixmap(16, 16);
80
81 if (flags & QuickItemModelRole::HasActiveFocus)
82 icons << UIResources::themedIcon(QStringLiteral("active-focus.png")).pixmap(16, 16);
83
84 if (flags & QuickItemModelRole::HasFocus && ~flags & QuickItemModelRole::HasActiveFocus)
85 icons << UIResources::themedIcon(QStringLiteral("focus.png")).pixmap(16, 16);
86
87 for (int i = 0; i < icons.size() && drawRect.left() < opt.rect.right(); i++) {
88 painter->drawPixmap(drawRect.topLeft(), icons.at(i));
89 drawRect.setTopLeft(drawRect.topLeft() + QPoint(20, 0));
90 }

Callers 3

setQObjectMethod · 0.45
foreachFunction · 0.45
setQObjectMethod · 0.45

Calls 13

QPointClass · 0.85
saveMethod · 0.80
textMethod · 0.80
rowMethod · 0.80
columnMethod · 0.80
leftMethod · 0.80
rightMethod · 0.80
dataMethod · 0.45
clearMethod · 0.45
isNullMethod · 0.45
valueMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected