Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsvgpaintserver.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6#include <QtSvg/private/qsvgnode_p.h>
7#include <QtSvg/private/qsvgdocument_p.h>
8
10
11QSvgPaintServer::~QSvgPaintServer()
12 = default;
13
14QSvgSolidColorPaint::QSvgSolidColorPaint(const QColor &color)
15 : m_solidColor(color)
16{
17}
18
19QSvgSolidColorPaint::~QSvgSolidColorPaint()
20 = default;
21
22QSvgGradientPaint::QSvgGradientPaint(std::unique_ptr<QGradient> grad)
23 : m_gradient(std::move(grad))
24{
25}
26
27QSvgGradientPaint::~QSvgGradientPaint()
28 = default;
29
30QBrush QSvgGradientPaint::brush(QPainter *, const QSvgNode *, QSvgExtraStates &)
31{
32 if (!m_link.isEmpty())
33 resolveStops();
34
35 // If the gradient is marked as empty, insert transparent black
36 if (!m_gradientStopsSet) {
37 m_gradient->setStops(QGradientStops() << QGradientStop(0.0, QColor(0, 0, 0, 0)));
38 m_gradientStopsSet = true;
39 }
40
41 QBrush b(*m_gradient);
42
43 if (!m_transform.isIdentity())
44 b.setTransform(m_transform);
45
46 return b;
47}
48
49void QSvgGradientPaint::resolveStops()
50{
51 QSet<QString> visited;
52 resolveStops_helper(visited);
53}
54
55void QSvgGradientPaint::resolveStops_helper(QSet<QString> &visited)
56{
57 if (!m_link.isEmpty() && m_doc) {
58 QSvgPaintServerSharedPtr paintServer = m_doc->paintServer(m_link);
59 if (paintServer && !visited.contains(m_link)) {
60 visited.insert(m_link);
61 if (paintServer->type() == QSvgPaintServer::Type::Gradient) {
62 QSvgGradientPaint *st =
63 static_cast<QSvgGradientPaint*>(paintServer.get());
64 st->resolveStops_helper(visited);
65 m_gradient->setStops(st->qgradient()->stops());
66 m_gradientStopsSet = st->gradientStopsSet();
67 }
68 } else {
69 qWarning("Could not resolve property : %s", qPrintable(m_link));
70 }
71 m_link.clear();
72 }
73}
74
75QSvgPatternPaint::QSvgPatternPaint(QSvgPattern *pattern)
76 : m_pattern(pattern)
77{
78}
79
80QSvgPatternPaint::~QSvgPatternPaint()
81 = default;
82
83QBrush QSvgPatternPaint::brush(QPainter *p, const QSvgNode *node, QSvgExtraStates &states)
84{
85 QBrush b(m_pattern->patternImage(p, states, node));
86 b.setTransform(m_pattern->appliedTransform());
87 return b;
88}
89
90QT_END_NAMESPACE
Combined button and popup list for selecting options.