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

Method renderWithShadow

app/src/UI/Widgets/PainterContext.cpp:1790–1823  ·  view source on GitHub ↗

* @brief Renders the given draw callback as a coloured drop shadow. */

Source from the content-addressed store, hash-verified

1788 * @brief Renders the given draw callback as a coloured drop shadow.
1789 */
1790void Widgets::PainterContext::renderWithShadow(const std::function<void(QPainter*)>& draw,
1791 const QRectF& bounds)
1792{
1793 if (!active() || bounds.isEmpty())
1794 return;
1795
1796 const qreal pad = qMax<qreal>(2.0, m_state.shadowBlur);
1797 QRectF padded = bounds.adjusted(-pad, -pad, pad, pad);
1798 const QSize sz(qMax(1, int(std::ceil(padded.width()))), qMax(1, int(std::ceil(padded.height()))));
1799
1800 QImage shadow(sz, QImage::Format_ARGB32_Premultiplied);
1801 shadow.fill(Qt::transparent);
1802
1803 {
1804 QPainter sp(&shadow);
1805 sp.setRenderHint(QPainter::Antialiasing, true);
1806 sp.translate(-padded.topLeft());
1807 draw(&sp);
1808
1809 sp.setCompositionMode(QPainter::CompositionMode_SourceIn);
1810 sp.fillRect(shadow.rect(), m_state.shadowColor);
1811 }
1812
1813 if (m_state.shadowBlur > 0.0) {
1814 const int radius = qBound(1, int(std::ceil(m_state.shadowBlur)), 32);
1815 applyBoxBlur(shadow, radius);
1816 }
1817
1818 m_painter->save();
1819 m_painter->setOpacity(m_state.globalAlpha);
1820 m_painter->drawImage(padded.topLeft() + QPointF(m_state.shadowOffsetX, m_state.shadowOffsetY),
1821 shadow);
1822 m_painter->restore();
1823}
1824
1825/**
1826 * @brief Pushes the current fill brush onto the active painter.

Callers

nothing calls this directly

Calls 13

ceilFunction · 0.85
drawFunction · 0.85
applyBoxBlurFunction · 0.85
isEmptyMethod · 0.80
widthMethod · 0.80
heightMethod · 0.80
translateMethod · 0.80
fillRectMethod · 0.80
rectMethod · 0.80
saveMethod · 0.80
drawImageMethod · 0.80
fillMethod · 0.45

Tested by

no test coverage detected