| 46 | |
| 47 | |
| 48 | void AnimeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
| 49 | { |
| 50 | QStyleOptionViewItem viewOption(option); |
| 51 | initStyleOption(&viewOption,index); |
| 52 | Anime *anime = (Anime *)index.data(AnimeRole).value<void *>(); |
| 53 | |
| 54 | painter->save(); |
| 55 | painter->setRenderHint(QPainter::Antialiasing, true); |
| 56 | painter->setRenderHint(QPainter::SmoothPixmapTransform, true); |
| 57 | |
| 58 | QRect coverRect(option.rect.x(), option.rect.y(), AnimeItemDelegate::CoverWidth, AnimeItemDelegate::CoverHeight); |
| 59 | coverRect.adjust(6, 6, -6, -6); |
| 60 | QPixmap coverPixmap(anime->cover(blockCoverFetch)); |
| 61 | painter->drawPixmap(coverRect, coverPixmap.isNull() ? nullCoverPixmap : coverPixmap); |
| 62 | if (anime->refreshing()) |
| 63 | { |
| 64 | painter->save(); |
| 65 | painter->setPen(Qt::NoPen); |
| 66 | painter->setBrush(QColor(0, 0, 0, 150)); |
| 67 | painter->drawRoundedRect(coverRect, 6, 6); |
| 68 | painter->restore(); |
| 69 | } |
| 70 | else |
| 71 | { |
| 72 | if (viewOption.state.testFlag(QStyle::State_MouseOver)) |
| 73 | { |
| 74 | painter->save(); |
| 75 | painter->setPen(borderPen); |
| 76 | painter->setBrush(Qt::NoBrush); |
| 77 | painter->drawRoundedRect(coverRect, 8, 8); |
| 78 | painter->restore(); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | QRect titleRect(option.rect.x(), option.rect.y() + AnimeItemDelegate::CoverHeight, AnimeItemDelegate::CoverWidth, AnimeItemDelegate::TitleHeight); |
| 83 | titleRect.adjust(6, 0, -6, 0); |
| 84 | painter->setFont(titleFont); |
| 85 | painter->setPen(titleColor); |
| 86 | QString drawText = index.data(Qt::DisplayRole).toString(); |
| 87 | if (painter->fontMetrics().horizontalAdvance(drawText) > titleRect.width()) |
| 88 | { |
| 89 | drawText = painter->fontMetrics().elidedText(drawText, Qt::ElideRight, titleRect.width()); |
| 90 | } |
| 91 | painter->drawText(titleRect, Qt::AlignCenter, drawText); |
| 92 | painter->restore(); |
| 93 | } |
| 94 | |
| 95 | bool AnimeItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) |
| 96 | { |