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

Method paint

plugins/projectmanagerview/projectmodelitemdelegate.cpp:46–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44}
45
46void ProjectModelItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& opt, const QModelIndex& index) const
47{
48 // Qt5.5 HiDPI Fix part (1/2)
49 // This fix is based on how Qt5.5's QItemDelegate::paint implementation deals with the same issue
50 // Unfortunately, there doesn't seem to be a clean way to use the base implementation
51 // and have the added functionality this class provides
52 QPixmap decoData;
53 QRect decorationRect;
54 QIcon icon;
55 QIcon::Mode mode = QIcon::Mode::Disabled;
56 QIcon::State state = QIcon::State::Off;
57 {
58 QVariant value;
59 value = index.data(Qt::DecorationRole);
60 if (value.isValid()) {
61 decoData = decoration(opt, value);
62
63 if (value.typeId() == qMetaTypeId<QIcon>()) {
64 icon = qvariant_cast<QIcon>(value);
65 mode = IconMode(opt.state);
66 state = IconState(opt.state);
67 QSize size = icon.actualSize( opt.decorationSize, mode, state );
68 if (size.isEmpty()) {
69 // For items with an empty icon, set size to opt.decorationSize to make them have the same indent as items with a valid icon
70 size = opt.decorationSize;
71 }
72 decorationRect = QRect(QPoint(0, 0), size);
73 } else {
74 decorationRect = QRect(QPoint(0, 0), decoData.size());
75 }
76 } else {
77 decorationRect = QRect();
78 }
79 }
80
81
82 QRect checkRect; //unused in practice
83
84 QRect spaceLeft = opt.rect;
85 spaceLeft.setLeft(decorationRect.right());
86 QString displayData = index.data(Qt::DisplayRole).toString();
87 QRect displayRect = textRectangle(painter, spaceLeft, opt.font, displayData);
88 displayRect.setLeft(spaceLeft.left());
89
90 QRect branchNameRect(displayRect.topRight(), opt.rect.bottomRight());
91
92 doLayout(opt, &checkRect, &decorationRect, &displayRect, false);
93 branchNameRect.setLeft(branchNameRect.left() + displayRect.left());
94 branchNameRect.setTop(displayRect.top());
95
96 drawStyledBackground(painter, opt);
97// drawCheck(painter, opt, checkRect, checkState);
98
99 // Qt5.5 HiDPI Fix part (2/2)
100 // use the QIcon from above if possible
101 if (!icon.isNull()) {
102 icon.paint(painter, decorationRect, opt.decorationAlignment, mode, state );
103 } else {

Callers

nothing calls this directly

Calls 12

IconModeFunction · 0.85
IconStateFunction · 0.85
QRectClass · 0.85
topMethod · 0.80
isNullMethod · 0.80
QPointClass · 0.50
dataMethod · 0.45
isValidMethod · 0.45
typeIdMethod · 0.45
isEmptyMethod · 0.45
sizeMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected