| 124 | } |
| 125 | |
| 126 | void drawBadges(QPainter* painter, const QStyleOptionViewItem& option, BaseInstance* instance, QIcon::Mode mode, QIcon::State state) |
| 127 | { |
| 128 | QList<QString> pixmaps; |
| 129 | if (instance->isRunning()) { |
| 130 | pixmaps.append("status-running"); |
| 131 | } else if (instance->hasCrashed() || instance->hasVersionBroken()) { |
| 132 | pixmaps.append("status-bad"); |
| 133 | } |
| 134 | if (instance->hasUpdateAvailable()) { |
| 135 | pixmaps.append("checkupdate"); |
| 136 | } |
| 137 | |
| 138 | static const int itemSide = 24; |
| 139 | static const int spacing = 1; |
| 140 | const int itemsPerRow = qMax(1, qFloor(double(option.rect.width() + spacing) / double(itemSide + spacing))); |
| 141 | const int rows = qCeil((double)pixmaps.size() / (double)itemsPerRow); |
| 142 | QListIterator<QString> it(pixmaps); |
| 143 | painter->translate(option.rect.topLeft()); |
| 144 | for (int y = 0; y < rows; ++y) { |
| 145 | for (int x = 0; x < itemsPerRow; ++x) { |
| 146 | if (!it.hasNext()) { |
| 147 | return; |
| 148 | } |
| 149 | // FIXME: inject this. |
| 150 | auto icon = QIcon::fromTheme(it.next()); |
| 151 | // opt.icon.paint(painter, iconbox, Qt::AlignCenter, mode, state); |
| 152 | const QPixmap pixmap; |
| 153 | // itemSide |
| 154 | QRect badgeRect(option.rect.width() - x * itemSide + qMax(x - 1, 0) * spacing - itemSide, |
| 155 | y * itemSide + qMax(y - 1, 0) * spacing, itemSide, itemSide); |
| 156 | icon.paint(painter, badgeRect, Qt::AlignCenter, mode, state); |
| 157 | } |
| 158 | } |
| 159 | painter->translate(-option.rect.topLeft()); |
| 160 | } |
| 161 | |
| 162 | static QSize viewItemTextSize(const QStyleOptionViewItem* option) |
| 163 | { |
no test coverage detected