Qt 4.8
|
The QSvgRenderer class is used to draw the contents of SVG files onto paint devices. More...
#include <qsvgrenderer.h>
Public Slots | |
bool | load (const QString &filename) |
Loads the SVG file specified by filename, returning true if the content was successfully parsed; otherwise returns false. More... | |
bool | load (const QByteArray &contents) |
Loads the specified SVG format contents, returning true if the content was successfully parsed; otherwise returns false. More... | |
bool | load (QXmlStreamReader *contents) |
Loads the specified SVG in contents, returning true if the content was successfully parsed; otherwise returns false. More... | |
void | render (QPainter *p) |
Renders the current document, or the current frame of an animated document, using the given painter. More... | |
void | render (QPainter *p, const QRectF &bounds) |
Renders the current document, or the current frame of an animated document, using the given painter on the specified bounds within the painter. More... | |
void | render (QPainter *p, const QString &elementId, const QRectF &bounds=QRectF()) |
Renders the given element with elementId using the given painter on the specified bounds. More... | |
Public Slots inherited from QObject | |
void | deleteLater () |
Schedules this object for deletion. More... | |
Signals | |
void | repaintNeeded () |
This signal is emitted whenever the rendering of the document needs to be updated, usually for the purposes of animation. More... | |
Signals inherited from QObject | |
void | destroyed (QObject *=0) |
This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More... | |
Public Functions | |
bool | animated () const |
Returns true if the current document contains animated elements; otherwise returns false. More... | |
int | animationDuration () const |
Returns the number of frames in the animation, or 0 if the current document is not animated. More... | |
QRectF | boundsOnElement (const QString &id) const |
Returns bounding rectangle of the item with the given id. More... | |
int | currentFrame () const |
QSize | defaultSize () const |
Returns the default size of the document contents. More... | |
bool | elementExists (const QString &id) const |
Returns true if the element with the given id exists in the currently parsed SVG file and is a renderable element. More... | |
int | framesPerSecond () const |
bool | isValid () const |
Returns true if there is a valid current document; otherwise returns false. More... | |
QMatrix | matrixForElement (const QString &id) const |
Returns the transformation matrix for the element with the given id. More... | |
QSvgRenderer (QObject *parent=0) | |
Constructs a new renderer with the given parent. More... | |
QSvgRenderer (const QString &filename, QObject *parent=0) | |
Constructs a new renderer with the given parent and loads the contents of the SVG file with the specified filename. More... | |
QSvgRenderer (const QByteArray &contents, QObject *parent=0) | |
Constructs a new renderer with the given parent and loads the SVG data from the byte array specified by contents. More... | |
QSvgRenderer (QXmlStreamReader *contents, QObject *parent=0) | |
Constructs a new renderer with the given parent and loads the SVG data using the stream reader specified by contents. More... | |
void | setCurrentFrame (int) |
void | setFramesPerSecond (int num) |
void | setViewBox (const QRect &viewbox) |
void | setViewBox (const QRectF &viewbox) |
QRect | viewBox () const |
QRectF | viewBoxF () const |
~QSvgRenderer () | |
Destroys the renderer. More... | |
Public Functions inherited from QObject | |
bool | blockSignals (bool b) |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More... | |
const QObjectList & | children () const |
Returns a list of child objects. More... | |
bool | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0) |
bool | disconnect (const QObject *receiver, const char *member=0) |
void | dumpObjectInfo () |
Dumps information about signal connections, etc. More... | |
void | dumpObjectTree () |
Dumps a tree of children to the debug output. More... | |
QList< QByteArray > | dynamicPropertyNames () const |
Returns the names of all properties that were dynamically added to the object using setProperty(). More... | |
virtual bool | event (QEvent *) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. More... | |
virtual bool | eventFilter (QObject *, QEvent *) |
Filters events if this object has been installed as an event filter for the watched object. More... | |
template<typename T > | |
T | findChild (const QString &aName=QString()) const |
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More... | |
template<typename T > | |
QList< T > | findChildren (const QString &aName=QString()) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More... | |
template<typename T > | |
QList< T > | findChildren (const QRegExp &re) const |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More... | |
void | installEventFilter (QObject *) |
Installs an event filter filterObj on this object. More... | |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false. More... | |
void | killTimer (int id) |
Kills the timer with timer identifier, id. More... | |
virtual const QMetaObject * | metaObject () const |
Returns a pointer to the meta-object of this object. More... | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. More... | |
QString | objectName () const |
QObject * | parent () const |
Returns a pointer to the parent object. More... | |
QVariant | property (const char *name) const |
Returns the value of the object's name property. More... | |
Q_INVOKABLE | QObject (QObject *parent=0) |
Constructs an object with parent object parent. More... | |
void | removeEventFilter (QObject *) |
Removes an event filter object obj from this object. More... | |
void | setObjectName (const QString &name) |
void | setParent (QObject *) |
Makes the object a child of parent. More... | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. More... | |
void | setUserData (uint id, QObjectUserData *data) |
bool | signalsBlocked () const |
Returns true if signals are blocked; otherwise returns false. More... | |
int | startTimer (int interval) |
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More... | |
QThread * | thread () const |
Returns the thread in which the object lives. More... | |
QObjectUserData * | userData (uint id) const |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. More... | |
Properties | |
int | currentFrame |
the current frame of the document's animation, or 0 if the document is not animated More... | |
int | framesPerSecond |
the number of frames per second to be shown More... | |
QRectF | viewBox |
Returns viewBoxF().toRect(). More... | |
Additional Inherited Members | |
Static Public Functions inherited from QObject | |
static bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More... | |
static bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
Disconnects signal in object sender from method in object receiver. More... | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static uint | registerUserData () |
static QString | tr (const char *sourceText, const char *comment=0, int n=-1) |
static QString | trUtf8 (const char *sourceText, const char *comment=0, int n=-1) |
Static Public Variables inherited from QObject | |
static const QMetaObject | staticMetaObject |
This variable stores the meta-object for the class. More... | |
Protected Functions inherited from QObject | |
virtual void | childEvent (QChildEvent *) |
This event handler can be reimplemented in a subclass to receive child events. More... | |
virtual void | connectNotify (const char *signal) |
This virtual function is called when something has been connected to signal in this object. More... | |
virtual void | customEvent (QEvent *) |
This event handler can be reimplemented in a subclass to receive custom events. More... | |
virtual void | disconnectNotify (const char *signal) |
This virtual function is called when something has been disconnected from signal in this object. More... | |
QObject (QObjectPrivate &dd, QObject *parent=0) | |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. More... | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More... | |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *) |
This event handler can be reimplemented in a subclass to receive timer events for the object. More... | |
Protected Variables inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Static Protected Variables inherited from QObject | |
static const QMetaObject | staticQtMetaObject |
Related Functions inherited from QObject | |
T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QRegExp ®Exp)() |
T * | qobject_cast (QObject *object) |
QObjectList | |
void * | qt_find_obj_child (QObject *parent, const char *type, const QString &name) |
Returns a pointer to the object named name that inherits type and with a given parent. More... | |
The QSvgRenderer class is used to draw the contents of SVG files onto paint devices.
Using QSvgRenderer, Scalable Vector Graphics (SVG) can be rendered onto any QPaintDevice subclass, including QWidget, QImage, and QGLWidget.
QSvgRenderer provides an API that supports basic features of SVG rendering, such as loading and rendering of static drawings, and more interactive features like animation. Since the rendering is performed using QPainter, SVG drawings can be rendered on any subclass of QPaintDevice.
SVG drawings are either loaded when an QSvgRenderer is constructed, or loaded later using the load() functions. Data is either supplied directly as serialized XML, or indirectly using a file name. If a valid file has been loaded, either when the renderer is constructed or at some later time, isValid() returns true; otherwise it returns false. QSvgRenderer provides the render() slot to render the current document, or the current frame of an animated document, using a given painter.
The defaultSize() function provides information about the amount of space that is required to render the currently loaded SVG file. This is useful for paint devices, such as QWidget, that often need to supply a size hint to their parent layout. The default size of a drawing may differ from its visible area, found using the viewBox property.
Animated SVG drawings are supported, and can be controlled with a simple collection of functions and properties:
The framesPerSecond property contains the rate at which the animation plays.
Finally, the QSvgRenderer class provides the repaintNeeded() signal which is emitted whenever the rendering of the document needs to be updated.
Definition at line 64 of file qsvgrenderer.h.
QSvgRenderer::QSvgRenderer | ( | QObject * | parent = 0 | ) |
Constructs a new renderer with the given parent.
Definition at line 131 of file qsvgrenderer.cpp.
Constructs a new renderer with the given parent and loads the contents of the SVG file with the specified filename.
Definition at line 140 of file qsvgrenderer.cpp.
QSvgRenderer::QSvgRenderer | ( | const QByteArray & | contents, |
QObject * | parent = 0 |
||
) |
Constructs a new renderer with the given parent and loads the SVG data from the byte array specified by contents.
Definition at line 150 of file qsvgrenderer.cpp.
QSvgRenderer::QSvgRenderer | ( | QXmlStreamReader * | contents, |
QObject * | parent = 0 |
||
) |
Constructs a new renderer with the given parent and loads the SVG data using the stream reader specified by contents.
Definition at line 165 of file qsvgrenderer.cpp.
QSvgRenderer::~QSvgRenderer | ( | ) |
bool QSvgRenderer::animated | ( | ) | const |
Returns true if the current document contains animated elements; otherwise returns false.
Definition at line 235 of file qsvgrenderer.cpp.
int QSvgRenderer::animationDuration | ( | ) | const |
Returns the number of frames in the animation, or 0 if the current document is not animated.
Definition at line 311 of file qsvgrenderer.cpp.
Returns bounding rectangle of the item with the given id.
The transformation matrix of parent elements is not affecting the bounds of the element.
Definition at line 467 of file qsvgrenderer.cpp.
Referenced by QGraphicsSvgItemPrivate::updateDefaultSize().
int QSvgRenderer::currentFrame | ( | ) | const |
Referenced by setFramesPerSecond().
QSize QSvgRenderer::defaultSize | ( | ) | const |
Returns the default size of the document contents.
Definition at line 191 of file qsvgrenderer.cpp.
Referenced by QSvgIconEngine::pixmap(), and QGraphicsSvgItemPrivate::updateDefaultSize().
bool QSvgRenderer::elementExists | ( | const QString & | id | ) | const |
Returns true if the element with the given id exists in the currently parsed SVG file and is a renderable element.
Note: this method returns true only for elements that can be rendered. Which implies that elements that are considered part of the fill/stroke style properties, e.g. radialGradients even tough marked with "id" attributes will not be found by this method.
Definition at line 493 of file qsvgrenderer.cpp.
int QSvgRenderer::framesPerSecond | ( | ) | const |
Referenced by animated().
bool QSvgRenderer::isValid | ( | ) | const |
Returns true if there is a valid current document; otherwise returns false.
Definition at line 182 of file qsvgrenderer.cpp.
Referenced by QSvgIconEngine::addFile(), and QSvgIconEngine::pixmap().
|
slot |
Loads the SVG file specified by filename, returning true if the content was successfully parsed; otherwise returns false.
Definition at line 358 of file qsvgrenderer.cpp.
Referenced by QSvgIOHandlerPrivate::load(), QSvgIconEnginePrivate::loadDataForModeAndState(), and QSvgRenderer().
|
slot |
Loads the specified SVG format contents, returning true if the content was successfully parsed; otherwise returns false.
Definition at line 368 of file qsvgrenderer.cpp.
|
slot |
Loads the specified SVG in contents, returning true if the content was successfully parsed; otherwise returns false.
The reader will be used from where it currently is positioned. If contents is null
, behavior is undefined.
Definition at line 383 of file qsvgrenderer.cpp.
Returns the transformation matrix for the element with the given id.
The matrix is a product of the transformation of the element's parents. The transformation of the element itself is not included.
To find the bounding rectangle of the element in logical coordinates, you can apply the matrix on the rectangle returned from boundsOnElement().
Definition at line 518 of file qsvgrenderer.cpp.
|
slot |
Renders the current document, or the current frame of an animated document, using the given painter.
Definition at line 393 of file qsvgrenderer.cpp.
Referenced by QSvgIconEngine::pixmap(), and QSvgIOHandler::read().
Renders the current document, or the current frame of an animated document, using the given painter on the specified bounds within the painter.
If the bounding rectangle is not specified the SVG file is mapped to the whole paint device.
Definition at line 431 of file qsvgrenderer.cpp.
|
slot |
Renders the given element with elementId using the given painter on the specified bounds.
If the bounding rectangle is not specified the SVG element is mapped to the whole paint device.
Definition at line 416 of file qsvgrenderer.cpp.
|
signal |
This signal is emitted whenever the rendering of the document needs to be updated, usually for the purposes of animation.
Referenced by QSvgRendererPrivate::callRepaintNeeded(), and loadDocument().
void QSvgRenderer::setCurrentFrame | ( | int | frame | ) |
Definition at line 294 of file qsvgrenderer.cpp.
void QSvgRenderer::setFramesPerSecond | ( | int | num | ) |
Definition at line 261 of file qsvgrenderer.cpp.
void QSvgRenderer::setViewBox | ( | const QRect & | viewbox | ) |
Definition at line 222 of file qsvgrenderer.cpp.
void QSvgRenderer::setViewBox | ( | const QRectF & | viewbox | ) |
Definition at line 448 of file qsvgrenderer.cpp.
QRect QSvgRenderer::viewBox | ( | ) | const |
Referenced by defaultSize().
QRectF QSvgRenderer::viewBoxF | ( | ) | const |
Definition at line 439 of file qsvgrenderer.cpp.
|
private |
the current frame of the document's animation, or 0 if the document is not animated
Definition at line 70 of file qsvgrenderer.h.
|
private |
the number of frames per second to be shown
The number of frames per second is 0 if the current document is not animated.
Definition at line 69 of file qsvgrenderer.h.
|
private |
Returns viewBoxF().toRect().
the rectangle specifying the visible area of the document in logical coordinates
Definition at line 68 of file qsvgrenderer.h.
Referenced by QSvgIOHandlerPrivate::load().