MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / drawBadges

Function drawBadges

launcher/ui/instanceview/InstanceDelegate.cpp:134–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134void drawBadges(QPainter *painter, const QStyleOptionViewItem &option, BaseInstance *instance, QIcon::Mode mode, QIcon::State state)
135{
136 QList<QString> pixmaps;
137 if (instance->isRunning())
138 {
139 pixmaps.append("status-running");
140 }
141 else if (instance->hasCrashed() || instance->hasVersionBroken())
142 {
143 pixmaps.append("status-bad");
144 }
145 if (instance->hasUpdateAvailable())
146 {
147 pixmaps.append("checkupdate");
148 }
149
150 static const int itemSide = 24;
151 static const int spacing = 1;
152 const int itemsPerRow = qMax(1, qFloor(double(option.rect.width() + spacing) / double(itemSide + spacing)));
153 const int rows = qCeil((double)pixmaps.size() / (double)itemsPerRow);
154 QListIterator<QString> it(pixmaps);
155 painter->translate(option.rect.topLeft());
156 for (int y = 0; y < rows; ++y)
157 {
158 for (int x = 0; x < itemsPerRow; ++x)
159 {
160 if (!it.hasNext())
161 {
162 return;
163 }
164 // FIXME: inject this.
165 auto icon = QIcon::fromTheme(it.next());
166 // opt.icon.paint(painter, iconbox, Qt::AlignCenter, mode, state);
167 const QPixmap pixmap;
168 // itemSide
169 QRect badgeRect(
170 option.rect.width() - x * itemSide + qMax(x - 1, 0) * spacing - itemSide,
171 y * itemSide + qMax(y - 1, 0) * spacing,
172 itemSide,
173 itemSide
174 );
175 icon.paint(painter, badgeRect, Qt::AlignCenter, mode, state);
176 }
177 }
178 painter->translate(-option.rect.topLeft());
179}
180
181static QSize viewItemTextSize(const QStyleOptionViewItem *option)
182{

Callers 1

paintMethod · 0.85

Calls 9

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

Tested by

no test coverage detected