MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / drawBadges

Function drawBadges

launcher/ui/instanceview/InstanceDelegate.cpp:126–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124}
125
126void 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
162static QSize viewItemTextSize(const QStyleOptionViewItem* option)
163{

Callers 1

paintMethod · 0.85

Calls 8

appendMethod · 0.80
hasCrashedMethod · 0.80
hasVersionBrokenMethod · 0.80
hasUpdateAvailableMethod · 0.80
translateMethod · 0.80
isRunningMethod · 0.45
sizeMethod · 0.45
paintMethod · 0.45

Tested by

no test coverage detected