MCPcopy Create free account
hub / github.com/MultiMC/Launcher / paintInfoLabel

Method paintInfoLabel

launcher/ui/widgets/VersionListView.cpp:124–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122
123
124void VersionListView::paintInfoLabel(QPaintEvent *event) const
125{
126 QString emptyString = currentEmptyString();
127
128 //calculate the rect for the overlay
129 QPainter painter(viewport());
130 painter.setRenderHint(QPainter::Antialiasing, true);
131 QFont font("sans", 20);
132 font.setBold(true);
133
134 QRect bounds = viewport()->geometry();
135 bounds.moveTop(0);
136 auto innerBounds = bounds;
137 innerBounds.adjust(10, 10, -10, -10);
138
139 QColor background = QApplication::palette().color(QPalette::Foreground);
140 QColor foreground = QApplication::palette().color(QPalette::Base);
141 foreground.setAlpha(190);
142 painter.setFont(font);
143 auto fontMetrics = painter.fontMetrics();
144 auto textRect = fontMetrics.boundingRect(innerBounds, Qt::AlignHCenter | Qt::TextWordWrap, emptyString);
145 textRect.moveCenter(bounds.center());
146
147 auto wrapRect = textRect;
148 wrapRect.adjust(-10, -10, 10, 10);
149
150 //check if we are allowed to draw in our area
151 if (!event->rect().intersects(wrapRect)) {
152 return;
153 }
154
155 painter.setBrush(QBrush(background));
156 painter.setPen(foreground);
157 painter.drawRoundedRect(wrapRect, 5.0, 5.0);
158
159 painter.setPen(foreground);
160 painter.setFont(font);
161 painter.drawText(textRect, Qt::AlignHCenter | Qt::TextWordWrap, emptyString);
162}

Callers

nothing calls this directly

Calls 2

setFontMethod · 0.80
rectMethod · 0.80

Tested by

no test coverage detected