when asking to render an element, search before for one with a width-height- prefix. if not found, fallback to the usual one

svn path=/trunk/KDE/kdelibs/; revision=1090743
This commit is contained in:
Marco Martin 2010-02-15 22:49:19 +00:00
parent 9d7a9b3e70
commit de832d5e60

24
svg.cpp
View File

@ -188,10 +188,18 @@ class SvgPrivate
QPixmap findInCache(const QString &elementId, const QSizeF &s = QSizeF()) QPixmap findInCache(const QString &elementId, const QSizeF &s = QSizeF())
{ {
QSize size; QSize size;
QString actualElementId;
if (elementId.isEmpty() || !q->hasElement(actualElementId)) {
actualElementId = elementId;
} else {
actualElementId = QString("%1-%2-%3").arg(qRound(s.width())).arg( qRound(s.height())).arg(elementId);
}
if (elementId.isEmpty() || (multipleImages && s.isValid())) { if (elementId.isEmpty() || (multipleImages && s.isValid())) {
size = s.toSize(); size = s.toSize();
} else { } else {
size = elementRect(elementId).size().toSize(); size = elementRect(actualElementId).size().toSize();
} }
if (size.isEmpty()) { if (size.isEmpty()) {
@ -200,8 +208,8 @@ class SvgPrivate
QString id = cachePath(path, size); QString id = cachePath(path, size);
if (!elementId.isEmpty()) { if (!actualElementId.isEmpty()) {
id.append(elementId); id.append(actualElementId);
} }
//kDebug() << "id is " << id; //kDebug() << "id is " << id;
@ -216,12 +224,12 @@ class SvgPrivate
//kDebug() << "didn't find cached version of " << id << ", so re-rendering"; //kDebug() << "didn't find cached version of " << id << ", so re-rendering";
//kDebug() << "size for " << elementId << " is " << s; //kDebug() << "size for " << actualElementId << " is " << s;
// we have to re-render this puppy // we have to re-render this puppy
createRenderer(); createRenderer();
QRectF finalRect = makeUniform(renderer->boundsOnElement(elementId), QRect(QPoint(0,0), size)); QRectF finalRect = makeUniform(renderer->boundsOnElement(actualElementId), QRect(QPoint(0,0), size));
//don't alter the pixmap size or it won't connect animre different parts of framesvg //don't alter the pixmap size or it won't connect animre different parts of framesvg
@ -231,10 +239,10 @@ class SvgPrivate
p.fill(Qt::transparent); p.fill(Qt::transparent);
QPainter renderPainter(&p); QPainter renderPainter(&p);
if (elementId.isEmpty()) { if (actualElementId.isEmpty()) {
renderer->render(&renderPainter, finalRect); renderer->render(&renderPainter, finalRect);
} else { } else {
renderer->render(&renderPainter, elementId, finalRect); renderer->render(&renderPainter, actualElementId, finalRect);
} }
renderPainter.end(); renderPainter.end();
@ -247,7 +255,7 @@ class SvgPrivate
} }
if (cacheRendering) { if (cacheRendering) {
actualTheme()->insertIntoCache(id, p, QString::number((qint64)q, 16)+elementId); actualTheme()->insertIntoCache(id, p, QString::number((qint64)q, 16)+actualElementId);
} }
return p; return p;