MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / paintItemIcon

Method paintItemIcon

src/plugins/core/gui/pluginitemdelegate.cpp:104–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102}
103
104QRectF PluginItemDelegate::paintItemIcon(QPainter *painter,
105 const QStyleOptionViewItem &option,
106 const QModelIndex &index) const
107{
108 Q_UNUSED(index);
109
110 painter->save();
111
112 if (!parent() || !parent()->parent())
113 return QRect();
114
115
116 // draw icon
117 QRectF iconRect = option.rect;
118 iconRect.setSize(QSize(kIconWidth, kIconHeight));
119 iconRect.moveTopLeft(QPoint(kIconLeftMargin, qRound(iconRect.top() + (option.rect.bottom() - iconRect.bottom()) / 2)));
120
121 // Copy of QStyle::alignedRect
122 Qt::Alignment alignment = Qt::AlignCenter;
123 alignment = visualAlignment(painter->layoutDirection(), alignment);
124 const qreal pixelRatio = painter->device()->devicePixelRatioF();
125
126 bool isEnabled = option.state & QStyle::State_Enabled;
127 const QPixmap &px = getIconPixmap(option.icon, iconRect.size().toSize(), pixelRatio, isEnabled ? QIcon::Normal : QIcon::Disabled, QIcon::Off);
128 qreal x = iconRect.x();
129 qreal y = iconRect.y();
130 qreal w = px.width() / px.devicePixelRatio();
131 qreal h = px.height() / px.devicePixelRatio();
132 if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter)
133 y += (iconRect.size().height() - h) / 2.0;
134 else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom)
135 y += iconRect.size().height() - h;
136 if ((alignment & Qt::AlignRight) == Qt::AlignRight)
137 x += iconRect.size().width() - w;
138 else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter)
139 x += (iconRect.size().width() - w) / 2.0;
140
141 painter->drawPixmap(qRound(x), qRound(y), px);
142 painter->restore();
143
144 return iconRect;
145}
146
147QPixmap PluginItemDelegate::getIconPixmap(const QIcon &icon,
148 const QSize &size,

Callers

nothing calls this directly

Calls 9

topMethod · 0.80
bottomMethod · 0.80
widthMethod · 0.80
restoreMethod · 0.80
QPointClass · 0.50
saveMethod · 0.45
parentMethod · 0.45
setSizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected