| 31 | } |
| 32 | |
| 33 | void QuickItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, |
| 34 | const QModelIndex &index) const |
| 35 | { |
| 36 | painter->save(); |
| 37 | int flags = index.data(QuickItemModelRole::ItemFlags).value<int>(); |
| 38 | |
| 39 | QStyleOptionViewItem opt = option; |
| 40 | initStyleOption(&opt, index); |
| 41 | |
| 42 | // Disable foreground painting so we can do ourself |
| 43 | opt.text.clear(); |
| 44 | opt.icon = QIcon(); |
| 45 | |
| 46 | QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter); |
| 47 | |
| 48 | QRect drawRect = option.rect; |
| 49 | painter->setClipRect(option.rect); |
| 50 | painter->setClipping(true); // avoid the icons leaking into the next column |
| 51 | |
| 52 | const auto foregroundData = index.data(Qt::ForegroundRole); |
| 53 | const auto inactiveColor = foregroundData.isNull() ? option.palette.text().color() : foregroundData.value<QColor>(); |
| 54 | const auto base = option.state |
| 55 | & QStyle::State_Selected |
| 56 | ? option.palette.highlightedText().color() |
| 57 | : inactiveColor; |
| 58 | |
| 59 | if (m_colors.contains(index.sibling(index.row(), 0))) { |
| 60 | QColor blend = m_colors.value(index.sibling(index.row(), 0)); |
| 61 | QColor blended = QColor::fromRgbF( |
| 62 | base.redF() * (1 - blend.alphaF()) + blend.redF() * blend.alphaF(), |
| 63 | base.greenF() * (1 - blend.alphaF()) + blend.greenF() * blend.alphaF(), |
| 64 | base.blueF() * (1 - blend.alphaF()) + blend.blueF() * blend.alphaF()); |
| 65 | painter->setPen(blended); |
| 66 | } else { |
| 67 | painter->setPen(base); |
| 68 | } |
| 69 | |
| 70 | if (index.column() == 0) { |
| 71 | auto deco = index.data(Qt::DecorationRole); |
| 72 | QVector<QPixmap> icons; |
| 73 | if (deco.canConvert<QPixmap>()) |
| 74 | icons.push_back(deco.value<QPixmap>()); |
| 75 | else if (deco.canConvert<QIcon>()) |
| 76 | icons.push_back(deco.value<QIcon>().pixmap(16, 16)); |
| 77 | |
| 78 | if ((flags & QuickItemModelRole::PartiallyOutOfView) && (~flags & QuickItemModelRole::Invisible)) |
| 79 | icons << UIResources::themedIcon(QStringLiteral("warning.png")).pixmap(16, 16); |
| 80 | |
| 81 | if (flags & QuickItemModelRole::HasActiveFocus) |
| 82 | icons << UIResources::themedIcon(QStringLiteral("active-focus.png")).pixmap(16, 16); |
| 83 | |
| 84 | if (flags & QuickItemModelRole::HasFocus && ~flags & QuickItemModelRole::HasActiveFocus) |
| 85 | icons << UIResources::themedIcon(QStringLiteral("focus.png")).pixmap(16, 16); |
| 86 | |
| 87 | for (int i = 0; i < icons.size() && drawRect.left() < opt.rect.right(); i++) { |
| 88 | painter->drawPixmap(drawRect.topLeft(), icons.at(i)); |
| 89 | drawRect.setTopLeft(drawRect.topLeft() + QPoint(20, 0)); |
| 90 | } |