Svg Class Reference
from PyKDE4.plasma import *
Inherits: QObject
Namespace: Plasma
Detailed Description
Svg plasma/svg.h <Plasma/Svg>
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
Signals | |
repaintNeeded () | |
sizeChanged () | |
Methods | |
__init__ (self, QObject parent=0) | |
bool | containsMultipleImages (self) |
QString | elementAtPoint (self, QPoint point) |
QRectF | elementRect (self, QString elementId) |
QSize | elementSize (self, QString elementId) |
bool | hasElement (self, QString elementId) |
QString | imagePath (self) |
bool | isUsingRenderingCache (self) |
bool | isValid (self) |
paint (self, QPainter painter, QPointF point, QString elementID=QString()) | |
paint (self, QPainter painter, int x, int y, QString elementID=QString()) | |
paint (self, QPainter painter, QRectF rect, QString elementID=QString()) | |
paint (self, QPainter painter, int x, int y, int width, int height, QString elementID=QString()) | |
QPixmap | pixmap (self, QString elementID=QString()) |
resize (self, float width, float height) | |
resize (self, QSizeF size) | |
resize (self) | |
setContainsMultipleImages (self, bool multiple) | |
setImagePath (self, QString svgFilePath) | |
setTheme (self, Plasma.Theme theme) | |
setUsingRenderingCache (self, bool useCache) | |
QSize | size (self) |
Plasma.Theme | theme (self) |
Signal Documentation
repaintNeeded | ( | ) |
- Signal syntax:
QObject.connect(source, SIGNAL("repaintNeeded()"), target_slot)
sizeChanged | ( | ) |
- Signal syntax:
QObject.connect(source, SIGNAL("sizeChanged()"), target_slot)
Method Documentation
__init__ | ( | self, | ||
QObject | parent=0 | |||
) |
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
@related Plasma.Theme
bool containsMultipleImages | ( | self ) |
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.
QString elementAtPoint | ( | self, | ||
QPoint | point | |||
) |
Returns the element (by id) at the given point.
An empty string is returned if there no element is at point.
NOTE: not implemented! This will currently return an empty string!
- Parameters:
-
point a point in SVG co-ordinates
- Returns:
- an empty string
QRectF elementRect | ( | self, | ||
QString | elementId | |||
) |
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
QSize elementSize | ( | self, | ||
QString | elementId | |||
) |
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
bool hasElement | ( | self, | ||
QString | elementId | |||
) |
Check whether an element exists in the loaded SVG.
- Parameters:
-
elementId the id of the element to check for
- Returns:
- true if the element is defined in the SVG, otherwise false
QString imagePath | ( | self ) |
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()
bool isUsingRenderingCache | ( | self ) |
Whether the rendering cache is being used.
- Returns:
- true if the Svg object is using caching for rendering results
- Since:
- 4.3
bool isValid | ( | self ) |
Check whether this object is backed by a valid SVG file.
This method can be expensive as it causes disk access.
- Returns:
- true if the SVG file exists and the document is valid, otherwise false.
paint | ( | self, | ||
QPainter | painter, | |||
QPointF | point, | |||
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)
paint | ( | self, | ||
QPainter | painter, | |||
int | x, | |||
int | y, | |||
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)
paint | ( | self, | ||
QPainter | painter, | |||
QRectF | rect, | |||
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)
paint | ( | self, | ||
QPainter | painter, | |||
int | x, | |||
int | y, | |||
int | width, | |||
int | height, | |||
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)
QPixmap pixmap | ( | self, | ||
QString | elementID=QString() | |||
) |
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
resize | ( | self, | ||
float | width, | |||
float | height | |||
) |
Resizes the rendered image to the natural size of the SVG.
Rendering will actually take place on the next call to paint.
resize | ( | self, | ||
QSizeF | size | |||
) |
Resizes the rendered image to the natural size of the SVG.
Rendering will actually take place on the next call to paint.
resize | ( | self ) |
Resizes the rendered image to the natural size of the SVG.
Rendering will actually take place on the next call to paint.
setContainsMultipleImages | ( | self, | ||
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
setImagePath | ( | self, | ||
QString | svgFilePath | |||
) |
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
setTheme | ( | self, | ||
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
setUsingRenderingCache | ( | self, | ||
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
QSize size | ( | self ) |
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
Plasma.Theme theme | ( | self ) |
The Plasma.Theme used by this Svg object.
This determines how relative image paths are interpreted.
- Returns:
- the theme used by this Svg