* Svg::pixmap
* ++apidox * clean up SvgPrivate::findInCache a bit svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=862695
This commit is contained in:
parent
1f7f9b95ed
commit
e99497b67f
37
svg.cpp
37
svg.cpp
@ -119,9 +119,8 @@ class SvgPrivate
|
|||||||
ids.clear();
|
ids.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void findInCache(QPixmap& p, const QString& elementId, const QPainter *itemPainter, const QSizeF &s = QSizeF())
|
QPixmap findInCache(const QString &elementId, const QSizeF &s = QSizeF())
|
||||||
{
|
{
|
||||||
Q_UNUSED( itemPainter );
|
|
||||||
createRenderer();
|
createRenderer();
|
||||||
|
|
||||||
QSize size;
|
QSize size;
|
||||||
@ -132,8 +131,7 @@ class SvgPrivate
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!size.isValid()) {
|
if (!size.isValid()) {
|
||||||
p = QPixmap();
|
return QPixmap();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString id = QString::fromLatin1("%3_%2_%1_").arg(size.width())
|
QString id = QString::fromLatin1("%3_%2_%1_").arg(size.width())
|
||||||
@ -149,9 +147,11 @@ class SvgPrivate
|
|||||||
ids.append(id);
|
ids.append(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPixmap p;
|
||||||
|
|
||||||
if (QPixmapCache::find(id, p)) {
|
if (QPixmapCache::find(id, p)) {
|
||||||
//kDebug() << "found cached version of " << id;
|
//kDebug() << "found cached version of " << id;
|
||||||
return;
|
return p;
|
||||||
} else {
|
} else {
|
||||||
//kDebug() << "didn't find cached version of " << id << ", so re-rendering";
|
//kDebug() << "didn't find cached version of " << id << ", so re-rendering";
|
||||||
}
|
}
|
||||||
@ -182,6 +182,8 @@ class SvgPrivate
|
|||||||
if (!QPixmapCache::insert(id, p)) {
|
if (!QPixmapCache::insert(id, p)) {
|
||||||
//kDebug() << "pixmap cache is too small for inserting" << id << "of size" << s;
|
//kDebug() << "pixmap cache is too small for inserting" << id << "of size" << s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void createRenderer()
|
void createRenderer()
|
||||||
@ -317,15 +319,19 @@ Svg::~Svg()
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPixmap Svg::pixmap(const QString &elementID)
|
||||||
|
{
|
||||||
|
if (elementID.isNull()) {
|
||||||
|
return d->findInCache(elementID, size());
|
||||||
|
} else {
|
||||||
|
return d->findInCache(elementID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Svg::paint(QPainter* painter, const QPointF& point, const QString& elementID)
|
void Svg::paint(QPainter* painter, const QPointF& point, const QString& elementID)
|
||||||
{
|
{
|
||||||
QPixmap pix;
|
QPixmap pix(elementID.isNull() ? d->findInCache(elementID, size()) :
|
||||||
|
d->findInCache(elementID));
|
||||||
if (elementID.isNull()) {
|
|
||||||
d->findInCache(pix, elementID, painter, size());
|
|
||||||
} else {
|
|
||||||
d->findInCache(pix, elementID, painter);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pix.isNull()) {
|
if (pix.isNull()) {
|
||||||
return;
|
return;
|
||||||
@ -341,8 +347,7 @@ void Svg::paint(QPainter* painter, int x, int y, const QString& elementID)
|
|||||||
|
|
||||||
void Svg::paint(QPainter* painter, const QRectF& rect, const QString& elementID)
|
void Svg::paint(QPainter* painter, const QRectF& rect, const QString& elementID)
|
||||||
{
|
{
|
||||||
QPixmap pix;
|
QPixmap pix(d->findInCache(elementID, rect.size()));
|
||||||
d->findInCache(pix, elementID, painter, rect.size());
|
|
||||||
painter->drawPixmap(rect, pix, QRectF(QPointF(0,0), pix.size()));
|
painter->drawPixmap(rect, pix, QRectF(QPointF(0,0), pix.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,6 +391,9 @@ bool Svg::hasElement(const QString& elementId) const
|
|||||||
|
|
||||||
QString Svg::elementAtPoint(const QPoint &point) const
|
QString Svg::elementAtPoint(const QPoint &point) const
|
||||||
{
|
{
|
||||||
|
return QString();
|
||||||
|
/*
|
||||||
|
FIXME: implement when Qt can support us!
|
||||||
d->createRenderer();
|
d->createRenderer();
|
||||||
QSizeF naturalSize = d->renderer->defaultSize();
|
QSizeF naturalSize = d->renderer->defaultSize();
|
||||||
qreal dx = d->size.width() / naturalSize.width();
|
qreal dx = d->size.width() / naturalSize.width();
|
||||||
@ -393,6 +401,7 @@ QString Svg::elementAtPoint(const QPoint &point) const
|
|||||||
//kDebug() << point << "is really" << QPoint(point.x() *dx, naturalSize.height() - point.y() * dy);
|
//kDebug() << point << "is really" << QPoint(point.x() *dx, naturalSize.height() - point.y() * dy);
|
||||||
|
|
||||||
return QString(); // d->renderer->elementAtPoint(QPoint(point.x() *dx, naturalSize.height() - point.y() * dy));
|
return QString(); // d->renderer->elementAtPoint(QPoint(point.x() *dx, naturalSize.height() - point.y() * dy));
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Svg::isValid() const
|
bool Svg::isValid() const
|
||||||
|
35
svg.h
35
svg.h
@ -21,6 +21,7 @@
|
|||||||
#define PLASMA_SVG_H
|
#define PLASMA_SVG_H
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
#include <QtGui/QPixmap>
|
||||||
|
|
||||||
#include <plasma/plasma_export.h>
|
#include <plasma/plasma_export.h>
|
||||||
|
|
||||||
@ -78,33 +79,47 @@ class PLASMA_EXPORT Svg : public QObject
|
|||||||
~Svg();
|
~Svg();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a pixmap of the SVG represented by this object.
|
||||||
|
*
|
||||||
|
* @arg elelementId the ID string of the element to render, or an empty
|
||||||
|
* string for the whole SVG (the default)
|
||||||
|
* @return a QPixmap of the rendered SVG
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE QPixmap pixmap(const QString &elementID = QString());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paints the SVG represented by this object
|
* Paints the SVG represented by this object
|
||||||
* @arg painter the QPainter to use
|
* @arg painter the QPainter to use
|
||||||
* @arg point the position to start drawing; the entire svg will be
|
* @arg point the position to start drawing; the entire svg will be
|
||||||
* drawn starting at this point.
|
* drawn starting at this point.
|
||||||
|
* @arg elelementId the ID string of the element to render, or an empty
|
||||||
|
* string for the whole SVG (the default)
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE void paint(QPainter* painter, const QPointF& point,
|
Q_INVOKABLE void paint(QPainter *painter, const QPointF &point,
|
||||||
const QString& elementID = QString());
|
const QString &elementID = QString());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paints the SVG represented by this object
|
* Paints the SVG represented by this object
|
||||||
* @arg painter the QPainter to use
|
* @arg painter the QPainter to use
|
||||||
* @arg x the horizontal coordinate to start painting from
|
* @arg x the horizontal coordinate to start painting from
|
||||||
* @arg y the vertical coordinate to start painting from
|
* @arg y the vertical coordinate to start painting from
|
||||||
|
* @arg elelementId the ID string of the element to render, or an empty
|
||||||
|
* string for the whole SVG (the default)
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE void paint(QPainter* painter, int x, int y,
|
Q_INVOKABLE void paint(QPainter *painter, int x, int y,
|
||||||
const QString& elementID = QString());
|
const QString &elementID = QString());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paints the SVG represented by this object
|
* Paints the SVG represented by this object
|
||||||
* @arg painter the QPainter to use
|
* @arg painter the QPainter to use
|
||||||
* @arg rect the rect to draw into; if small than the current size
|
* @arg rect the rect to draw into; if smaller than the current size
|
||||||
* of the
|
* the drawing is starting at this point.
|
||||||
* drawn starting at this point.
|
* @arg elelementId the ID string of the element to render, or an empty
|
||||||
|
* string for the whole SVG (the default)
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE void paint(QPainter* painter, const QRectF& rect,
|
Q_INVOKABLE void paint(QPainter *painter, const QRectF &rect,
|
||||||
const QString& elementID = QString());
|
const QString &elementID = QString());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Currently set size of the SVG
|
* Currently set size of the SVG
|
||||||
@ -118,7 +133,7 @@ class PLASMA_EXPORT Svg : public QObject
|
|||||||
* @arg width the new width
|
* @arg width the new width
|
||||||
* @arg height the new height
|
* @arg height the new height
|
||||||
**/
|
**/
|
||||||
Q_INVOKABLE void resize( qreal width, qreal height );
|
Q_INVOKABLE void resize(qreal width, qreal height);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resizes the rendered image. Rendering will actually take place on
|
* Resizes the rendered image. Rendering will actually take place on
|
||||||
|
Loading…
Reference in New Issue
Block a user