MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / drawButton

Method drawButton

app/src/Platform/CSD.cpp:597–631  ·  view source on GitHub ↗

* @brief Draws a window control button with an SVG icon. */

Source from the content-addressed store, hash-verified

595 * @brief Draws a window control button with an SVG icon.
596 */
597void Titlebar::drawButton(QPainter* painter, Button button, const QString& svgPath)
598{
599 const QRectF iconRect = buttonRect(button);
600 const bool hovered = (m_hoveredButton == button);
601 const bool pressed = (m_pressedButton == button);
602
603 drawButtonHoverBackground(painter, button, hovered, pressed);
604 const QColor iconColor = buttonIconColor(button, hovered, pressed);
605
606 const qreal dpr = qApp->devicePixelRatio();
607 const QSize pixelSize(qRound(iconRect.width() * dpr), qRound(iconRect.height() * dpr));
608 const QRectF logicalRect(0, 0, iconRect.width(), iconRect.height());
609
610 if (pixelSize.isEmpty())
611 return;
612
613 const QString cacheKey = QStringLiteral("%1|%2|%3x%4|%5")
614 .arg(svgPath)
615 .arg(QString::number(iconColor.rgba(), 16))
616 .arg(pixelSize.width())
617 .arg(pixelSize.height())
618 .arg(QString::number(dpr, 'f', 3));
619 auto cacheIt = m_iconCache.constFind(cacheKey);
620 if (cacheIt != m_iconCache.cend()) {
621 painter->drawPixmap(iconRect.topLeft(), cacheIt.value());
622 return;
623 }
624
625 const QPixmap colorized = renderColorizedSvg(svgPath, pixelSize, logicalRect, dpr, iconColor);
626 if (colorized.isNull())
627 return;
628
629 m_iconCache.insert(cacheKey, colorized);
630 painter->drawPixmap(iconRect.topLeft(), colorized);
631}
632
633/**
634 * @brief Handles loss of mouse grab.

Callers

nothing calls this directly

Calls 5

widthMethod · 0.80
heightMethod · 0.80
isEmptyMethod · 0.80
cendMethod · 0.80
valueMethod · 0.45

Tested by

no test coverage detected