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