MCPcopy Create free account
hub / github.com/PrismLauncher/PrismLauncher / drawHeader

Method drawHeader

launcher/ui/instanceview/VisualGroup.cpp:142–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140}
141
142void VisualGroup::drawHeader(QPainter* painter, const QStyleOptionViewItem& option) const
143{
144 QRect optRect = option.rect;
145 optRect.setTop(optRect.top() + 7);
146 QFont font(QApplication::font());
147 font.setBold(true);
148 const QFontMetrics fontMetrics = QFontMetrics(font);
149 painter->setFont(font);
150
151 QPen pen;
152 pen.setWidth(2);
153 QColor penColor = option.palette.text().color();
154 penColor.setAlphaF(0.6f);
155 pen.setColor(penColor);
156 painter->setPen(pen);
157 painter->setRenderHint(QPainter::Antialiasing);
158
159 // sizes and offsets, to keep things consistent below
160 const int arrowOffsetLeft = fontMetrics.height() / 2 + 7;
161 const int textOffsetLeft = arrowOffsetLeft * 2;
162 const int centerHeight = optRect.top() + fontMetrics.height() / 2;
163 const QString& textToDraw = text.isEmpty() ? QObject::tr("Ungrouped") : text;
164
165 // BEGIN: arrow
166 {
167 constexpr int arrowSize = 6;
168 QPolygon arrowPolygon;
169 if (collapsed) {
170 arrowPolygon << QPoint(arrowOffsetLeft - arrowSize / 2, centerHeight - arrowSize)
171 << QPoint(arrowOffsetLeft + arrowSize / 2, centerHeight)
172 << QPoint(arrowOffsetLeft - arrowSize / 2, centerHeight + arrowSize);
173 painter->drawPolyline(arrowPolygon);
174 } else {
175 arrowPolygon << QPoint(arrowOffsetLeft - arrowSize, centerHeight - arrowSize / 2)
176 << QPoint(arrowOffsetLeft, centerHeight + arrowSize / 2)
177 << QPoint(arrowOffsetLeft + arrowSize, centerHeight - arrowSize / 2);
178 painter->drawPolyline(arrowPolygon);
179 }
180 }
181 // END: arrow
182
183 // BEGIN: text
184 {
185 QRect textRect(optRect);
186 textRect.setTop(textRect.top());
187 textRect.setLeft(textOffsetLeft);
188 textRect.setHeight(fontMetrics.height());
189 textRect.setRight(textRect.right() - 7);
190
191 painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, textToDraw);
192 }
193 // END: text
194
195 // BEGIN: horizontal line
196 {
197 penColor.setAlphaF(0.05f);
198 pen.setColor(penColor);
199 painter->setPen(pen);

Callers 1

paintEventMethod · 0.80

Calls 4

setFontMethod · 0.80
textMethod · 0.45
isEmptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected