18#include <private/qquicktranslate_p.h>
19#include <private/qquickitem_p.h>
20#include <private/qsvgnode_p.h>
22#include <private/qquadpath_p.h>
23#include <private/qsvgvisitor_p.h>
44 auto xformProp = transform();
45 xformProp.clear(&xformProp);
46 bool translate = !qFuzzyIsNull(m_viewBox.x()) || !qFuzzyIsNull(m_viewBox.y());
48 auto *tr =
new QQuickTranslate(
this);
49 tr->setX(-m_viewBox.x());
50 tr->setY(-m_viewBox.y());
51 xformProp.append(&xformProp, tr);
53 if (!m_viewBox.isEmpty() && width() && height()) {
54 auto *scale =
new QQuickScale(
this);
55 qreal sx = width() / m_viewBox.width();
56 qreal sy = height() / m_viewBox.height();
60 xformProp.append(&xformProp, scale);
72 for (
const auto &p : poly) {
87 QTextStream str(&res);
88 auto flags = qp.pathHints();
94#define CHECK_PATH_HINT(flagName)
95 if (flags.testFlag(QQuadPath::flagName)) {
99 str << " ShapePath." #flagName;
123 QRect pixelRect(objModeRect.x() * boundingRect.width() + boundingRect.left(),
124 objModeRect.y() * boundingRect.height() + boundingRect.top(),
125 objModeRect.width() * boundingRect.width(),
126 objModeRect.height() * boundingRect.height());
128 if (pixelRect.isEmpty())
131 double w = boundingRect.width();
132 double h = boundingRect.height();
133 double objModeSlope = objModeRect.height() / objModeRect.width();
134 double a = objModeSlope * w / h;
137 double x2 = pixelRect.width();
138 double y2 = pixelRect.height();
139 double x = (x2 + a * y2) / (1 + a * a);
140 double y = y2 - (x - x2)/a;
142 return QRectF(pixelRect.topLeft(), QSizeF(x,y));
147 QString svgPathString;
148 QTextStream strm(&svgPathString);
150 for (
int i = 0; i < path.elementCount(); ++i) {
151 QPainterPath::Element element = path.elementAt(i);
152 if (element.isMoveTo()) {
153 strm <<
"M " << element.x <<
" " << element.y <<
" ";
154 }
else if (element.isLineTo()) {
155 strm <<
"L " << element.x <<
" " << element.y <<
" ";
156 }
else if (element.isCurveTo()) {
157 QPointF c1(element.x, element.y);
159 element = path.elementAt(i);
161 QPointF c2(element.x, element.y);
163 element = path.elementAt(i);
164 QPointF ep(element.x, element.y);
176 return svgPathString;
181 QString svgPathString;
182 QTextStream strm(&svgPathString);
183 path.iterateElements([&](
const QQuadPath::Element &e,
int) {
184 if (e.isSubpathStart())
185 strm <<
"M " << e.startPoint().x() <<
" " << e.startPoint().y() <<
" ";
187 strm <<
"L " << e.endPoint().x() <<
" " << e.endPoint().y() <<
" ";
189 strm <<
"Q " << e.controlPoint().x() <<
" " << e.controlPoint().y() <<
" "
190 << e.endPoint().x() <<
" " << e.endPoint().y() <<
" ";
193 return svgPathString;
199 switch (strokeCapStyle) {
201 capStyle = QStringLiteral(
"ShapePath.FlatCap");
204 capStyle = QStringLiteral(
"ShapePath.SquareCap");
207 capStyle = QStringLiteral(
"ShapePath.RoundCap");
220 switch (strokeJoinStyle) {
222 joinStyle = QStringLiteral(
"ShapePath.MiterJoin");
225 joinStyle = QStringLiteral(
"ShapePath.BevelJoin");
228 joinStyle = QStringLiteral(
"ShapePath.RoundJoin");
243 return QStringLiteral(
"[]");
246 QTextStream stream(&listString);
249 if (list.length() > 1) {
250 for (
int i = 0; i < list.length() - 1; i++) {
256 stream << list.last() <<
"]";
ViewBoxItem(const QRectF viewBox, QQuickItem *parent=nullptr)
void geometryChange(const QRectF &, const QRectF &) override
QPainterPath polygonToPath(const QPolygonF &poly, bool closed)
QString strokeJoinStyleString(Qt::PenJoinStyle strokeJoinStyle)
QString strokeCapStyleString(Qt::PenCapStyle strokeCapStyle)
QRectF mapToQtLogicalMode(const QRectF &objModeRect, const QRectF &boundingRect)
QString listString(QList< T > list)
QString pathHintString(const QQuadPath &qp)
QString toSvgString(const QPainterPath &path)
QString toSvgString(const QQuadPath &path)
Combined button and popup list for selecting options.
static QString sanitizeString(const QString &input)
static int processAnimationTime(int time)
#define CHECK_PATH_HINT(flagName)