Plasma::Svg
#include <Plasma/Svg>

Public Types | |
enum | Status { Normal = 0, Selected, Inactive } |
Properties | |
Plasma::Theme::ColorGroup | colorGroup |
bool | fromCurrentTheme |
QString | imagePath |
bool | multipleImages |
QSize | size |
Plasma::Svg::Status | status |
bool | usingRenderingCache |
![]() | |
objectName | |
Signals | |
void | colorGroupChanged () |
void | colorHintChanged () |
void | fromCurrentThemeChanged (bool fromCurrentTheme) |
void | imagePathChanged () |
void | repaintNeeded () |
void | sizeChanged () |
void | statusChanged (Plasma::Svg::Status status) |
Public Member Functions | |
Plasma::Theme::ColorGroup | colorGroup () const |
bool | containsMultipleImages () const |
qreal | devicePixelRatio () |
Q_INVOKABLE QRectF | elementRect (const QString &elementId) const |
QRectF | elementRect (QStringView elementId) const |
Q_INVOKABLE QSize | elementSize (const QString &elementId) const |
QSize | elementSize (QStringView elementId) const |
bool | fromCurrentTheme () const |
Q_INVOKABLE bool | hasElement (const QString &elementId) const |
bool | hasElement (QStringView elementId) const |
Q_INVOKABLE QImage | image (const QSize &size, const QString &elementID=QString()) |
QString | imagePath () const |
bool | isUsingRenderingCache () const |
Q_INVOKABLE bool | isValid () const |
Q_INVOKABLE void | paint (QPainter *painter, const QPointF &point, const QString &elementID=QString()) |
Q_INVOKABLE void | paint (QPainter *painter, const QRectF &rect, const QString &elementID=QString()) |
Q_INVOKABLE void | paint (QPainter *painter, int x, int y, const QString &elementID=QString()) |
Q_INVOKABLE void | paint (QPainter *painter, int x, int y, int width, int height, const QString &elementID=QString()) |
Q_INVOKABLE QPixmap | pixmap (const QString &elementID=QString()) |
Q_INVOKABLE void | resize () |
Q_INVOKABLE void | resize (const QSizeF &size) |
Q_INVOKABLE void | resize (qreal width, qreal height) |
qreal | scaleFactor () const |
void | setColorGroup (Plasma::Theme::ColorGroup group) |
void | setContainsMultipleImages (bool multiple) |
void | setDevicePixelRatio (qreal ratio) |
virtual void | setImagePath (const QString &svgFilePath) |
void | setScaleFactor (qreal factor) |
void | setStatus (Svg::Status status) |
void | setTheme (Plasma::Theme *theme) |
void | setUseSystemColors (bool system) |
void | setUsingRenderingCache (bool useCache) |
QSize | size () const |
Svg::Status | status () const |
Theme * | theme () const |
bool | useSystemColors () const |
![]() | |
QObject (QObject *parent) | |
bool | blockSignals (bool block) |
const QObjectList & | children () const const |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const |
void | deleteLater () |
void | destroyed (QObject *obj) |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) const const |
bool | disconnect (const QObject *receiver, const char *method) const const |
void | dumpObjectInfo () |
void | dumpObjectInfo () const const |
void | dumpObjectTree () |
void | dumpObjectTree () const const |
QList< QByteArray > | dynamicPropertyNames () const const |
virtual bool | event (QEvent *e) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegExp ®Exp, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QString &name, Qt::FindChildOptions options) const const |
bool | inherits (const char *className) const const |
void | installEventFilter (QObject *filterObj) |
bool | isWidgetType () const const |
bool | isWindowType () const const |
void | killTimer (int id) |
virtual const QMetaObject * | metaObject () const const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const const |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
QVariant | property (const char *name) const const |
Q_CLASSINFO (Name, Value) | |
Q_DISABLE_COPY (Class) | |
Q_DISABLE_COPY_MOVE (Class) | |
Q_DISABLE_MOVE (Class) | |
Q_EMIT Q_EMIT | |
Q_ENUM (...) | |
Q_ENUM_NS (...) | |
Q_ENUMS (...) | |
Q_FLAG (...) | |
Q_FLAG_NS (...) | |
Q_FLAGS (...) | |
Q_GADGET Q_GADGET | |
Q_INTERFACES (...) | |
Q_INVOKABLE Q_INVOKABLE | |
Q_NAMESPACE Q_NAMESPACE | |
Q_NAMESPACE_EXPORT (EXPORT_MACRO) | |
Q_OBJECT Q_OBJECT | |
Q_PROPERTY (...) | |
Q_REVISION Q_REVISION | |
Q_SET_OBJECT_NAME (Object) | |
Q_SIGNAL Q_SIGNAL | |
Q_SIGNALS Q_SIGNALS | |
Q_SLOT Q_SLOT | |
Q_SLOTS Q_SLOTS | |
T | qFindChild (const QObject *obj, const QString &name) |
QList< T > | qFindChildren (const QObject *obj, const QRegExp ®Exp) |
QList< T > | qFindChildren (const QObject *obj, const QString &name) |
T | qobject_cast (const QObject *object) |
T | qobject_cast (QObject *object) |
QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT | |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const char *name, const QVariant &value) |
bool | signalsBlocked () const const |
int | startTimer (int interval, Qt::TimerType timerType) |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType) |
QThread * | thread () const const |
Related Functions | |
(Note that these are not member functions.) | |
Svg (QObject *parent=nullptr) | |
Additional Inherited Members | |
![]() | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
bool | disconnect (const QMetaObject::Connection &connection) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
![]() | |
typedef | QObjectList |
![]() | |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
bool | isSignalConnected (const QMetaMethod &signal) const const |
int | receivers (const char *signal) const const |
QObject * | sender () const const |
int | senderSignalIndex () const const |
virtual void | timerEvent (QTimerEvent *event) |
Detailed Description
A theme aware image-centric SVG class.
Plasma::Svg provides a class for rendering SVG images to a QPainter in a convenient manner. Unless an absolute path to a file is provided, it loads the SVG document using Plasma::Theme. It also provides a number of internal optimizations to help lower the cost of painting SVGs, such as caching.
- See also
- Plasma::FrameSvg
Member Function Documentation
◆ colorGroup()
Plasma::Theme::ColorGroup Plasma::Svg::colorGroup | ( | ) | const |
- Returns
- the color group for this Svg
◆ colorGroupChanged
|
signal |
Emitted whenever the color group has changed.
◆ colorHintChanged
|
signal |
Emitted whenever the color hint has changed.
◆ containsMultipleImages()
bool Plasma::Svg::containsMultipleImages | ( | ) | const |
Whether the SVG contains multiple images.
If this is true
, the SVG will be treated as a collection of related images, rather than a consistent drawing.
- Returns
true
if the SVG will be treated as containing multiple images,false
if it will be treated as a coherent image.
◆ devicePixelRatio()
qreal Plasma::Svg::devicePixelRatio | ( | ) |
◆ elementRect()
The bounding rect of a given element.
This is the bounding rect of the element with ID elementId
after the SVG has been scaled (see resize()). Note that this is unaffected by the containsMultipleImages property.
- Parameters
-
elementId the id of the element to check
- Returns
- the current rect of a given element, given the current size of the SVG
◆ elementSize()
Find the size of a given element.
This is the size of the element with ID elementId
after the SVG has been scaled (see resize()). Note that this is unaffected by the containsMultipleImages property.
- Parameters
-
elementId the id of the element to check
- Returns
- the size of a given element, given the current size of the SVG
◆ fromCurrentTheme()
bool Plasma::Svg::fromCurrentTheme | ( | ) | const |
Whether the current theme has this Svg, without any fallback to the default theme involved.
- Returns
- true if the svg is loaded from the current theme
- See also
- Theme::currentThemeHasImage
◆ fromCurrentThemeChanged
|
signal |
Emitted when fromCurrentTheme() value has changed.
◆ hasElement()
bool Plasma::Svg::hasElement | ( | const QString & | elementId | ) | const |
◆ image()
Returns an image of the SVG represented by this object.
The size of the image will be the size of this Svg object (size()) if containsMultipleImages is true
; otherwise, it will be the size of the requested element after the whole SVG has been scaled to size().
- Parameters
-
elementId the ID string of the element to render, or an empty string for the whole SVG (the default)
- Returns
- a QPixmap of the rendered SVG
◆ imagePath()
QString Plasma::Svg::imagePath | ( | ) | const |
The SVG file to render.
If this SVG is themed, this will be a relative path, and will not include a file extension.
- Returns
- either an absolute path to an SVG file, or an image name
- See also
- Theme::imagePath()
◆ imagePathChanged
|
signal |
Emitted whenever the image path of the Svg is changed.
◆ isUsingRenderingCache()
bool Plasma::Svg::isUsingRenderingCache | ( | ) | const |
◆ isValid()
bool Plasma::Svg::isValid | ( | ) | const |
◆ paint() [1/4]
void Plasma::Svg::paint | ( | QPainter * | painter, |
const QPointF & | point, | ||
const QString & | elementID = QString() |
||
) |
Paints all or part of the SVG represented by this object.
The size of the painted area will be the size of this Svg object (size()) if containsMultipleImages is true
; otherwise, it will be the size of the requested element after the whole SVG has been scaled to size().
- Parameters
-
painter the QPainter to use point the position to start drawing; the entire svg will be drawn starting at this point. elementId the ID string of the element to render, or an empty string for the whole SVG (the default)
◆ paint() [2/4]
void Plasma::Svg::paint | ( | QPainter * | painter, |
const QRectF & | rect, | ||
const QString & | elementID = QString() |
||
) |
Paints all or part of the SVG represented by this object.
- Parameters
-
painter the QPainter to use rect the rect to draw into; if smaller than the current size the drawing is starting at this point. elementId the ID string of the element to render, or an empty string for the whole SVG (the default)
◆ paint() [3/4]
Paints all or part of the SVG represented by this object.
The size of the painted area will be the size of this Svg object (size()) if containsMultipleImages is true
; otherwise, it will be the size of the requested element after the whole SVG has been scaled to size().
- Parameters
-
painter the QPainter to use x the horizontal coordinate to start painting from y the vertical coordinate to start painting from elementId the ID string of the element to render, or an empty string for the whole SVG (the default)
◆ paint() [4/4]
void Plasma::Svg::paint | ( | QPainter * | painter, |
int | x, | ||
int | y, | ||
int | width, | ||
int | height, | ||
const QString & | elementID = QString() |
||
) |
Paints all or part of the SVG represented by this object.
- Parameters
-
painter the QPainter to use x the horizontal coordinate to start painting from y the vertical coordinate to start painting from width the width of the element to draw height the height of the element do draw elementId the ID string of the element to render, or an empty string for the whole SVG (the default)
◆ pixmap()
Returns a pixmap of the SVG represented by this object.
The size of the pixmap will be the size of this Svg object (size()) if containsMultipleImages is true
; otherwise, it will be the size of the requested element after the whole SVG has been scaled to size().
- Parameters
-
elementId the ID string of the element to render, or an empty string for the whole SVG (the default)
- Returns
- a QPixmap of the rendered SVG
◆ repaintNeeded
|
signal |
Emitted whenever the SVG data has changed in such a way that a repaint is required.
Any usage of an Svg object that does the painting itself must connect to this signal and respond by updating the painting. Note that connected to Theme::themeChanged is incorrect in such a use case as the Svg itself may not be updated yet nor may theme change be the only case when a repaint is needed. Also note that classes or QML code which take Svg objects as parameters for their own painting all respond to this signal so that in those cases manually responding to the signal is unnecessary; ONLY when direct, manual painting with an Svg object is done in application code is this signal used.
◆ resize() [1/3]
void Plasma::Svg::resize | ( | ) |
◆ resize() [2/3]
void Plasma::Svg::resize | ( | const QSizeF & | size | ) |
Resizes the rendered image.
Rendering will actually take place on the next call to paint.
If containsMultipleImages is true
, each element of the SVG will be rendered at this size by default; otherwise, the entire image will be scaled to this size and each element will be scaled appropriately.
- Parameters
-
size the new size of the image
◆ resize() [3/3]
void Plasma::Svg::resize | ( | qreal | width, |
qreal | height | ||
) |
Resizes the rendered image.
Rendering will actually take place on the next call to paint.
If containsMultipleImages is true
, each element of the SVG will be rendered at this size by default; otherwise, the entire image will be scaled to this size and each element will be scaled appropriately.
- Parameters
-
width the new width height the new height
◆ scaleFactor()
qreal Plasma::Svg::scaleFactor | ( | ) | const |
◆ setColorGroup()
void Plasma::Svg::setColorGroup | ( | Plasma::Theme::ColorGroup | group | ) |
◆ setContainsMultipleImages()
void Plasma::Svg::setContainsMultipleImages | ( | bool | multiple | ) |
Set whether the SVG contains a single image or multiple ones.
If this is set to true
, the SVG will be treated as a collection of related images, rather than a consistent drawing.
In particular, when individual elements are rendered, this affects whether the elements are resized to size() by default. See paint() and pixmap().
- Parameters
-
multiple true if the svg contains multiple images
◆ setDevicePixelRatio()
void Plasma::Svg::setDevicePixelRatio | ( | qreal | ratio | ) |
Set the device pixel ratio for the Svg.
This is the ratio between image pixels and device-independent pixels. The Svg will produce pixmaps scaled by devicePixelRatio, but all the sizes and element rects will not be altered. The default value is 1.0 and the scale will be done rounded to the floor integer Setting it to something more, will make all the elements of this svg appear bigger.
◆ setImagePath()
|
virtual |
Set the SVG file to render.
Relative paths are looked for in the current Plasma theme, and should not include the file extension (.svg and .svgz files will be searched for). See Theme::imagePath().
If the parent object of this Svg is a Plasma::Applet, relative paths will be searched for in the applet's package first.
- Parameters
-
svgFilePath either an absolute path to an SVG file, or an image name
Reimplemented in Plasma::FrameSvg.
◆ setScaleFactor()
void Plasma::Svg::setScaleFactor | ( | qreal | factor | ) |
Setting a scale factor greater than one it will result in final images scaled by it.
Unlike devicePixelRatio, every size and element rect will be scaled accordingly. The default value is 1.0 and the scale will be done rounded to the floor integer.
- Parameters
-
how much to scale the Svg
◆ setStatus()
void Plasma::Svg::setStatus | ( | Svg::Status | status | ) |
Sets the image in a selected status.
Svgs can be colored with system color themes, if the status is selected, the TextColor will become HighlightedText color and BackgroundColor will become HighlightColor, making the svg graphics (for instance an icon) will look correct together selected text Supported statuses as of 5.23 are Normal and Selected
- Since
- 5.23
◆ setTheme()
void Plasma::Svg::setTheme | ( | Plasma::Theme * | theme | ) |
Sets the Plasma::Theme to use with this Svg object.
By default, Svg objects use Plasma::Theme::default().
This determines how relative image paths are interpreted.
- Parameters
-
theme the theme object to use
- Since
- 4.3
◆ setUseSystemColors()
void Plasma::Svg::setUseSystemColors | ( | bool | system | ) |
◆ setUsingRenderingCache()
void Plasma::Svg::setUsingRenderingCache | ( | bool | useCache | ) |
Sets whether or not to cache the results of rendering to pixmaps.
If the SVG is resized and re-rendered often (and does not keep using the same small set of pixmap dimensions), then it may be less efficient to do disk caching. A good example might be a progress meter that uses an Svg object to paint itself: the meter will be changing often enough, with enough unpredictability and without re-use of the previous pixmaps to not get a gain from caching.
Most Svg objects should use the caching feature, however. Therefore, the default is to use the render cache.
- Parameters
-
useCache true to cache rendered pixmaps
- Since
- 4.3
◆ size()
QSize Plasma::Svg::size | ( | ) | const |
The size of the SVG.
If the SVG has been resized with resize(), that size will be returned; otherwise, the natural size of the SVG will be returned.
If containsMultipleImages is true
, each element of the SVG will be rendered at this size by default.
- Returns
- the current size of the SVG
◆ sizeChanged
|
signal |
◆ status()
Svg::Status Plasma::Svg::status | ( | ) | const |
- Returns
- the status of the Svg
- Since
- 5.23
◆ statusChanged
|
signal |
Emitted when the status changes.
- Since
- 5.23
◆ theme()
Theme * Plasma::Svg::theme | ( | ) | const |
The Plasma::Theme used by this Svg object.
This determines how relative image paths are interpreted.
- Returns
- the theme used by this Svg
◆ useSystemColors()
bool Plasma::Svg::useSystemColors | ( | ) | const |
Friends And Related Function Documentation
◆ Svg()
|
related |
Constructs an SVG object that implicitly shares and caches rendering.
Unlike QSvgRenderer, which this class uses internally, Plasma::Svg represents an image generated from an SVG. As such, it has a related size and transform matrix (the latter being provided by the painter used to paint the image).
The size is initialized to be the SVG's native size.
- Parameters
-
parent options QObject to parent this to
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Mar 23 2023 04:18:18 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.