* @brief Renders the given draw callback as a coloured drop shadow. */
| 1788 | * @brief Renders the given draw callback as a coloured drop shadow. |
| 1789 | */ |
| 1790 | void 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. |
nothing calls this directly
no test coverage detected