• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Plasma

  • Plasma
  • Svg
Signals | Public Member Functions | Properties | Related Functions | List of all members
Plasma::Svg Class Reference

#include <Plasma/Svg>

Inheritance diagram for Plasma::Svg:
Inheritance graph
[legend]

Signals

void repaintNeeded ()
 
void sizeChanged ()
 

Public Member Functions

 ~Svg ()
 
bool containsMultipleImages () const
 
Q_INVOKABLE QString elementAtPoint (const QPoint &point) const
 
Q_INVOKABLE QRectF elementRect (const QString &elementId) const
 
Q_INVOKABLE QSize elementSize (const QString &elementId) const
 
Q_INVOKABLE bool hasElement (const QString &elementId) const
 
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, int x, int y, 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, int width, int height, const QString &elementID=QString())
 
Q_INVOKABLE QPixmap pixmap (const QString &elementID=QString())
 
Q_INVOKABLE void resize (qreal width, qreal height)
 
Q_INVOKABLE void resize (const QSizeF &size)
 
Q_INVOKABLE void resize ()
 
void setContainsMultipleImages (bool multiple)
 
void setImagePath (const QString &svgFilePath)
 
void setTheme (Plasma::Theme *theme)
 
void setUsingRenderingCache (bool useCache)
 
QSize size () const
 
Theme * theme () const
 

Properties

QString imagePath
 
bool multipleImages
 
QSize size
 
bool usingRenderingCache
 

Related Functions

(Note that these are not member functions.)

 Svg (QObject *parent=0)
 

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

Definition at line 56 of file svg.h.

Constructor & Destructor Documentation

Plasma::Svg::~Svg ( )

Definition at line 641 of file svg.cpp.

Member Function Documentation

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.

Definition at line 774 of file svg.cpp.

QString Plasma::Svg::elementAtPoint ( const QPoint &  point) const

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
pointa point in SVG co-ordinates
Returns
an empty string

Definition at line 741 of file svg.cpp.

QRectF Plasma::Svg::elementRect ( const QString &  elementId) const

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
elementIdthe id of the element to check
Returns
the current rect of a given element, given the current size of the SVG

Definition at line 727 of file svg.cpp.

QSize Plasma::Svg::elementSize ( const QString &  elementId) const

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
elementIdthe id of the element to check
Returns
the size of a given element, given the current size of the SVG

Definition at line 722 of file svg.cpp.

bool Plasma::Svg::hasElement ( const QString &  elementId) const

Check whether an element exists in the loaded SVG.

Parameters
elementIdthe id of the element to check for
Returns
true if the element is defined in the SVG, otherwise false

Definition at line 732 of file svg.cpp.

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()
bool Plasma::Svg::isUsingRenderingCache ( ) const

Whether the rendering cache is being used.

Returns
true if the Svg object is using caching for rendering results
Since
4.3

Definition at line 802 of file svg.cpp.

bool Plasma::Svg::isValid ( ) const

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.

Definition at line 759 of file svg.cpp.

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
painterthe QPainter to use
pointthe position to start drawing; the entire svg will be drawn starting at this point.
elementIdthe ID string of the element to render, or an empty string for the whole SVG (the default)

Definition at line 655 of file svg.cpp.

void Plasma::Svg::paint ( QPainter *  painter,
int  x,
int  y,
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
painterthe QPainter to use
xthe horizontal coordinate to start painting from
ythe vertical coordinate to start painting from
elementIdthe ID string of the element to render, or an empty string for the whole SVG (the default)

Definition at line 667 of file svg.cpp.

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
painterthe QPainter to use
rectthe rect to draw into; if smaller than the current size the drawing is starting at this point.
elementIdthe ID string of the element to render, or an empty string for the whole SVG (the default)

Definition at line 672 of file svg.cpp.

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
painterthe QPainter to use
xthe horizontal coordinate to start painting from
ythe vertical coordinate to start painting from
widththe width of the element to draw
heightthe height of the element do draw
elementIdthe ID string of the element to render, or an empty string for the whole SVG (the default)

Definition at line 678 of file svg.cpp.

QPixmap Plasma::Svg::pixmap ( const 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
elementIdthe ID string of the element to render, or an empty string for the whole SVG (the default)
Returns
a QPixmap of the rendered SVG

Definition at line 646 of file svg.cpp.

void Plasma::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.

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
widththe new width
heightthe new height

Definition at line 693 of file svg.cpp.

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
sizethe new size of the image

Definition at line 698 of file svg.cpp.

void Plasma::Svg::resize ( )

Resizes the rendered image to the natural size of the SVG.

Rendering will actually take place on the next call to paint.

Definition at line 710 of file svg.cpp.

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
multipletrue if the svg contains multiple images

Definition at line 769 of file svg.cpp.

void Plasma::Svg::setImagePath ( const 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
svgFilePatheither an absolute path to an SVG file, or an image name

Definition at line 779 of file svg.cpp.

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
themethe theme object to use
Since
4.3

Definition at line 807 of file svg.cpp.

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
useCachetrue to cache rendered pixmaps
Since
4.3

Definition at line 797 of file svg.cpp.

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
void Plasma::Svg::sizeChanged ( )
signal

Emitted whenever the size of the Svg is changed.

See also
resize()
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

Definition at line 822 of file svg.cpp.

Friends And Related Function Documentation

Plasma::Svg::Svg ( QObject *  parent = 0)
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
parentoptions QObject to parent this to

Definition at line 635 of file svg.cpp.

Property Documentation

QString Plasma::Svg::imagePath
readwrite

Definition at line 62 of file svg.h.

bool Plasma::Svg::multipleImages
readwrite

Definition at line 61 of file svg.h.

QSize Plasma::Svg::size
readwrite

Definition at line 60 of file svg.h.

bool Plasma::Svg::usingRenderingCache
readwrite

Definition at line 63 of file svg.h.


The documentation for this class was generated from the following files:
  • svg.h
  • svg.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:35 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal