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
This commit is contained in:
parent
3e1acc8e02
commit
e87fe2244c
30
svg.cpp
30
svg.cpp
@ -139,6 +139,17 @@ class SvgPrivate
|
|||||||
QObject::connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
|
QObject::connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
|
||||||
q, SLOT(colorsChanged()));
|
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)) {
|
} else if (QFile::exists(imagePath)) {
|
||||||
path = imagePath;
|
path = imagePath;
|
||||||
} else {
|
} else {
|
||||||
@ -454,6 +465,10 @@ void Svg::paint(QPainter *painter, int x, int y, int width, int height, const QS
|
|||||||
|
|
||||||
QSize Svg::size() const
|
QSize Svg::size() const
|
||||||
{
|
{
|
||||||
|
if (d->size.isEmpty()) {
|
||||||
|
d->size = d->naturalSize;
|
||||||
|
}
|
||||||
|
|
||||||
return d->size.toSize();
|
return d->size.toSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,17 +490,12 @@ void Svg::resize(const QSizeF &size)
|
|||||||
|
|
||||||
void Svg::resize()
|
void Svg::resize()
|
||||||
{
|
{
|
||||||
QSizeF newSize;
|
if (qFuzzyCompare(d->naturalSize.width(), d->size.width()) &&
|
||||||
if (d->renderer) {
|
qFuzzyCompare(d->naturalSize.height(), d->size.height())) {
|
||||||
newSize = d->renderer->defaultSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qFuzzyCompare(newSize.width(), d->size.width()) &&
|
|
||||||
qFuzzyCompare(newSize.height(), d->size.height())) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->size = newSize;
|
d->size = d->naturalSize;
|
||||||
d->localRectCache.clear();
|
d->localRectCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -514,11 +524,11 @@ bool Svg::hasElement(const QString &elementId) const
|
|||||||
bool found = Theme::defaultTheme()->findInRectsCache(d->path, id, elementRect);
|
bool found = Theme::defaultTheme()->findInRectsCache(d->path, id, elementRect);
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
|
d->localRectCache.insert(id, elementRect);
|
||||||
return elementRect.isValid();
|
return elementRect.isValid();
|
||||||
} else {
|
} else {
|
||||||
// kDebug() << "** ** *** !!!!!!!! *** ** ** creating renderer due to hasElement miss" << d->path << elementId;
|
// kDebug() << "** ** *** !!!!!!!! *** ** ** creating renderer due to hasElement miss" << d->path << elementId;
|
||||||
d->findAndCacheElementRect(elementId);
|
return d->findAndCacheElementRect(elementId).isValid();
|
||||||
return d->renderer->elementExists(elementId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user