From e87fe2244c2cd7010986041b2888d3b4882bad86 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 16 Jan 2009 20:14:05 +0000 Subject: [PATCH] backport the last chunks of svg fixes, namely now resize() and size() always behave as expected and the natural svg size is cached on disk svn path=/branches/KDE/4.2/kdelibs/; revision=912162 --- svg.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/svg.cpp b/svg.cpp index 60207ce98..7a6c3ede1 100644 --- a/svg.cpp +++ b/svg.cpp @@ -139,6 +139,17 @@ class SvgPrivate QObject::connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), q, SLOT(colorsChanged())); } + + QRectF rect; + bool found = Theme::defaultTheme()->findInRectsCache(path, "_Natural", rect); + + if (found && !rect.isValid()) { + createRenderer(); + naturalSize = renderer->defaultSize(); + Theme::defaultTheme()->insertIntoRectsCache(path, "_Natural", QRectF(QPointF(0,0), naturalSize)); + } else { + naturalSize = rect.size(); + } } else if (QFile::exists(imagePath)) { path = imagePath; } else { @@ -454,6 +465,10 @@ void Svg::paint(QPainter *painter, int x, int y, int width, int height, const QS QSize Svg::size() const { + if (d->size.isEmpty()) { + d->size = d->naturalSize; + } + return d->size.toSize(); } @@ -475,17 +490,12 @@ void Svg::resize(const QSizeF &size) void Svg::resize() { - QSizeF newSize; - if (d->renderer) { - newSize = d->renderer->defaultSize(); - } - - if (qFuzzyCompare(newSize.width(), d->size.width()) && - qFuzzyCompare(newSize.height(), d->size.height())) { + if (qFuzzyCompare(d->naturalSize.width(), d->size.width()) && + qFuzzyCompare(d->naturalSize.height(), d->size.height())) { return; } - d->size = newSize; + d->size = d->naturalSize; d->localRectCache.clear(); } @@ -514,11 +524,11 @@ bool Svg::hasElement(const QString &elementId) const bool found = Theme::defaultTheme()->findInRectsCache(d->path, id, elementRect); if (found) { + d->localRectCache.insert(id, elementRect); return elementRect.isValid(); } else { // kDebug() << "** ** *** !!!!!!!! *** ** ** creating renderer due to hasElement miss" << d->path << elementId; - d->findAndCacheElementRect(elementId); - return d->renderer->elementExists(elementId); + return d->findAndCacheElementRect(elementId).isValid(); } }