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

Method drawHeader

launcher/ui/instanceview/VisualGroup.cpp:146–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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