Plasma

svgitem.h
1 /*
2  SPDX-FileCopyrightText: 2010 Marco Martin <[email protected]>
3  SPDX-FileCopyrightText: 2014 David Edmundson <[email protected]>
4 
5  SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 #ifndef SVGITEM_P
8 #define SVGITEM_P
9 
10 #include <QQuickItem>
11 #include <QImage>
12 
13 #include "units.h"
14 
15 namespace Plasma
16 {
17 
18 class Svg;
19 
20 /**
21  * @class SvgItem
22  * @short Displays an SVG or an element from an SVG file
23  */
24 class SvgItem : public QQuickItem
25 {
26  Q_OBJECT
27 
28  /**
29  * The sub element of the svg we want to render. If empty the whole svg document will be painted.
30  */
31  Q_PROPERTY(QString elementId READ elementId WRITE setElementId NOTIFY elementIdChanged)
32 
33  /**
34  * Svg class that is the source of the image, use it like that:
35  * @code
36  * SvgItem {
37  * svg: Svg {imagePath: "widgets/arrows"}
38  * elementId: "arrow-left"
39  * }
40  * @endcode
41  * Instead of a Svg declaration it can also be the id of a Svg declared elsewhere, useful to share Svg instances.
42  */
43  Q_PROPERTY(Plasma::Svg *svg READ svg WRITE setSvg NOTIFY svgChanged)
44 
45  /**
46  * The natural, unscaled size of the svg document or the element. useful if a pixel perfect rendering of outlines is needed.
47  */
48  Q_PROPERTY(QSizeF naturalSize READ naturalSize NOTIFY naturalSizeChanged)
49 
50 public:
51 /// @cond INTERNAL_DOCS
52 
53  explicit SvgItem(QQuickItem *parent = nullptr);
54  ~SvgItem() override;
55 
56  void setElementId(const QString &elementID);
57  QString elementId() const;
58 
59  void setSvg(Plasma::Svg *svg);
60  Plasma::Svg *svg() const;
61 
62  QSizeF naturalSize() const;
63 
64  QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override;
65 /// @endcond
66 
67 Q_SIGNALS:
68  void elementIdChanged();
69  void svgChanged();
70  void naturalSizeChanged();
71 
72 protected Q_SLOTS:
73 /// @cond INTERNAL_DOCS
74  void updateNeeded();
75  void updateDevicePixelRatio();
76 /// @endcond
77 
78 private:
79  void scheduleImageUpdate();
80  void updatePolish() override;
81  void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
82 
83  QPointer<Plasma::Svg> m_svg;
84  QString m_elementID;
85  bool m_textureChanged;
86  QImage m_image;
87 };
88 }
89 
90 #endif
Plasma::Svg svg
Svg class that is the source of the image, use it like that:
Definition: svgitem.h:43
Q_SIGNALSQ_SIGNALS
QSizeF naturalSize
The natural, unscaled size of the svg document or the element.
Definition: svgitem.h:48
Namespace for everything in libplasma.
Definition: datamodel.cpp:14
Q_OBJECTQ_OBJECT
QString elementId
The sub element of the svg we want to render.
Definition: svgitem.h:31
Displays an SVG or an element from an SVG file.
Definition: svgitem.h:24
Q_PROPERTY(...)
virtual QSGNode * updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *updatePaintNodeData)
Q_SLOTSQ_SLOTS
QObject * parent() const const
A theme aware image-centric SVG class.
Definition: svg.h:43
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Mar 8 2021 22:41:15 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.