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

Method paintInfoLabel

launcher/ui/widgets/VersionListView.cpp:144–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142
143
144void VersionListView::paintInfoLabel(QPaintEvent *event) const
145{
146 QString emptyString = currentEmptyString();
147
148 //calculate the rect for the overlay
149 QPainter painter(viewport());
150 painter.setRenderHint(QPainter::Antialiasing, true);
151 QFont font("sans", 20);
152 font.setBold(true);
153
154 QRect bounds = viewport()->geometry();
155 bounds.moveTop(0);
156 auto innerBounds = bounds;
157 innerBounds.adjust(10, 10, -10, -10);
158
159 QColor background = QApplication::palette().color(QPalette::WindowText);
160 QColor foreground = QApplication::palette().color(QPalette::Base);
161 foreground.setAlpha(190);
162 painter.setFont(font);
163 auto fontMetrics = painter.fontMetrics();
164 auto textRect = fontMetrics.boundingRect(innerBounds, Qt::AlignHCenter | Qt::TextWordWrap, emptyString);
165 textRect.moveCenter(bounds.center());
166
167 auto wrapRect = textRect;
168 wrapRect.adjust(-10, -10, 10, 10);
169
170 //check if we are allowed to draw in our area
171 if (!event->rect().intersects(wrapRect)) {
172 return;
173 }
174
175 painter.setBrush(QBrush(background));
176 painter.setPen(foreground);
177 painter.drawRoundedRect(wrapRect, 5.0, 5.0);
178
179 painter.setPen(foreground);
180 painter.setFont(font);
181 painter.drawText(textRect, Qt::AlignHCenter | Qt::TextWordWrap, emptyString);
182}

Callers

nothing calls this directly

Calls 2

setFontMethod · 0.80
rectMethod · 0.80

Tested by

no test coverage detected