| 102 | } |
| 103 | |
| 104 | QRectF 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 | |
| 147 | QPixmap PluginItemDelegate::getIconPixmap(const QIcon &icon, |
| 148 | const QSize &size, |