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

KDE's Doxygen guidelines are available online.