KSvg

svgitem.h
1/*
2 SPDX-FileCopyrightText: 2010 Marco Martin <mart@kde.org>
3 SPDX-FileCopyrightText: 2014 David Edmundson <davidedmundson@kde.org>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7#ifndef SVGITEM_P
8#define SVGITEM_P
9
10#include <QImage>
11#include <QQuickItem>
12
13#include <qqmlregistration.h>
14
15namespace Kirigami
16{
17namespace Platform
18{
19class PlatformTheme;
20}
21};
22
23namespace KSvg
24{
25class Svg;
26
27/**
28 * @class SvgItem
29 * @short Displays an SVG or an element from an SVG file
30 */
31class SvgItem : public QQuickItem
32{
34 QML_ELEMENT
35
36 /**
37 * @brief This property specifies the relative path of the Svg in the theme.
38 *
39 * Example: "widgets/background"
40 *
41 * @property QString imagePath
42 */
43 Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath NOTIFY imagePathChanged)
44
45 /**
46 * @brief This property specifies the sub-element of the SVG to be
47 * rendered.
48 *
49 * If this is empty, the whole SVG document will be rendered.
50 *
51 * @property QString elementId
52 */
53 Q_PROPERTY(QString elementId READ elementId WRITE setElementId NOTIFY elementIdChanged)
54
55 /**
56 * @brief This property holds the SVG's natural, unscaled size.
57 *
58 * This is useful if a pixel-perfect rendering of outlines is needed.
59 *
60 * @property QSizeF naturalSize
61 */
62 Q_PROPERTY(QSizeF naturalSize READ naturalSize NOTIFY naturalSizeChanged)
63
64 /**
65 * @brief This property holds the rectangle of the selected elementId
66 * relative to the unscaled size of the SVG document.
67 *
68 * Note that this property will holds the entire SVG if element id is not
69 * selected.
70 *
71 * @property QRectF elementRect
72 */
73 Q_PROPERTY(QRectF elementRect READ elementRect NOTIFY elementRectChanged)
74
75 /**
76 * @brief This property holds the internal SVG instance.
77 *
78 * Usually, specifying just the imagePath is enough. Use this if you have
79 * many items taking the same SVG as source, and you want to share the
80 * internal SVG object.
81 *
82 * @property KSvg::Svg svg
83 */
84 Q_PROPERTY(KSvg::Svg *svg READ svg WRITE setSvg NOTIFY svgChanged)
85
86public:
87 /// @cond INTERNAL_DOCS
88
89 explicit SvgItem(QQuickItem *parent = nullptr);
90 ~SvgItem() override;
91
92 void setImagePath(const QString &path);
93 QString imagePath() const;
94
95 void setElementId(const QString &elementID);
96 QString elementId() const;
97
98 void setSvg(KSvg::Svg *svg);
99 KSvg::Svg *svg() const;
100
101 QSizeF naturalSize() const;
102
103 QRectF elementRect() const;
104
105 QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override;
106 /// @endcond
107
108 void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) override;
109
110protected:
111 void componentComplete() override;
112
114 void imagePathChanged();
115 void elementIdChanged();
116 void svgChanged();
117 void naturalSizeChanged();
118 void elementRectChanged();
119
120protected Q_SLOTS:
121 /// @cond INTERNAL_DOCS
122 void updateNeeded();
123 /// @endcond
124
125private:
126 void updateDevicePixelRatio();
127 void scheduleImageUpdate();
128 void updatePolish() override;
129 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
130
131 QPointer<KSvg::Svg> m_svg;
132 Kirigami::Platform::PlatformTheme *m_kirigamiTheme;
133 QString m_elementID;
134 QImage m_image;
135 bool m_textureChanged;
136};
137}
138
139#endif
Displays an SVG or an element from an SVG file.
Definition svgitem.h:32
QString elementId
This property specifies the sub-element of the SVG to be rendered.
Definition svgitem.h:53
QRectF elementRect
This property holds the rectangle of the selected elementId relative to the unscaled size of the SVG ...
Definition svgitem.h:73
QString imagePath
This property specifies the relative path of the Svg in the theme.
Definition svgitem.h:43
KSvg::Svg * svg
This property holds the internal SVG instance.
Definition svgitem.h:84
QSizeF naturalSize
This property holds the SVG's natural, unscaled size.
Definition svgitem.h:62
A theme aware image-centric SVG class.
Definition svg.h:46
The KSvg namespace.
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
virtual QSGNode * updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:13:51 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.