| 18 | { |
| 19 | } |
| 20 | |
| 21 | void T_IconDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const |
| 22 | { |
| 23 | QStyleOptionViewItem viewOption(option); |
| 24 | initStyleOption(&viewOption, index); |
| 25 | |
| 26 | if (option.state.testFlag(QStyle::State_HasFocus)) |
| 27 | { |
| 28 | viewOption.state &= ~QStyle::State_HasFocus; |
| 29 | } |
| 30 | QStyledItemDelegate::paint(painter, viewOption, index); |
| 31 | QStringList iconList = index.data(Qt::UserRole).toStringList(); |
| 32 | if (iconList.count() != 2) |
| 33 | { |
| 34 | return; |
| 35 | } |
| 36 | QString iconName = iconList.at(0); |
| 37 | QString iconValue = iconList.at(1); |
| 38 | painter->save(); |
| 39 | painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); |
| 40 | QFont iconFont("ElaAwesome"); |
| 41 | iconFont.setPixelSize(28); |
| 42 | painter->setFont(iconFont); |
| 43 | painter->setPen(ElaThemeColor(_themeMode, BasicText)); |
| 44 | painter->drawText(QRect(option.rect.x(), option.rect.y() + 12, option.rect.width(), 36), Qt::AlignCenter, iconValue); |
| 45 | QFont labelFont = option.font; |
| 46 | labelFont.setPixelSize(12); |
| 47 | painter->setFont(labelFont); |
| 48 | const QRect labelRect(option.rect.x() + 6, option.rect.y() + 58, option.rect.width() - 12, 20); |
| 49 | painter->drawText(labelRect, Qt::AlignCenter, painter->fontMetrics().elidedText(iconName, Qt::ElideRight, labelRect.width())); |
| 50 | painter->restore(); |
| 51 | } |
| 52 | |
| 53 | QSize T_IconDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const |
| 54 | { |
| 55 | return QSize(104, 88); |
| 56 | } |