| 142 | } |
| 143 | |
| 144 | void paint(QPainter *painter, const QStyleOptionViewItem &option, |
| 145 | const QModelIndex &index) const override |
| 146 | { |
| 147 | if (!index.isValid()) { |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | painter->save(); |
| 152 | |
| 153 | QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, nullptr); |
| 154 | |
| 155 | int iconSize = option.rect.height() - MARGIN * 2; |
| 156 | QIcon icon = QIcon::fromTheme(index.model()->data(index, Qt::DecorationRole).toString()); |
| 157 | icon.paint(painter, QRect(dependantLayoutValue(MARGIN + option.rect.left(), iconSize, option.rect.width()), MARGIN + option.rect.top(), iconSize, iconSize)); |
| 158 | QRect contentsRect(dependantLayoutValue(MARGIN * 2 + iconSize + option.rect.left(), option.rect.width() - MARGIN * 3 - iconSize, option.rect.width()), MARGIN + option.rect.top(), option.rect.width() - MARGIN * 3 - iconSize, option.rect.height() - MARGIN * 2); |
| 159 | |
| 160 | int lessHorizontalSpace = MARGIN * 2 + pushButton->sizeHint().width(); |
| 161 | |
| 162 | contentsRect.setWidth(contentsRect.width() - lessHorizontalSpace); |
| 163 | |
| 164 | if (option.state & QStyle::State_Selected) { |
| 165 | painter->setPen(option.palette.highlightedText().color()); |
| 166 | } |
| 167 | |
| 168 | if (itemView()->layoutDirection() == Qt::RightToLeft) { |
| 169 | contentsRect.translate(lessHorizontalSpace, 0); |
| 170 | } |
| 171 | |
| 172 | painter->save(); |
| 173 | |
| 174 | painter->save(); |
| 175 | QFont font = titleFont(option.font); |
| 176 | QFontMetrics fmTitle(font); |
| 177 | painter->setFont(font); |
| 178 | painter->drawText(contentsRect, Qt::AlignLeft | Qt::AlignTop, fmTitle.elidedText(index.model()->data(index, Qt::DisplayRole).toString(), Qt::ElideRight, contentsRect.width())); |
| 179 | painter->restore(); |
| 180 | |
| 181 | painter->drawText(contentsRect, Qt::AlignLeft | Qt::AlignBottom, option.fontMetrics.elidedText(index.model()->data(index, PluginsModel::DescriptionRole).toString(), Qt::ElideRight, contentsRect.width())); |
| 182 | |
| 183 | painter->restore(); |
| 184 | painter->restore(); |
| 185 | } |
| 186 | |
| 187 | QList<QWidget *> createItemWidgets(const QModelIndex &index) const override |
| 188 | { |