unbreak svg element loading as button icon

svn path=/trunk/KDE/kdelibs/; revision=1028676
This commit is contained in:
Marco Martin 2009-09-27 21:26:46 +00:00
parent 65a85e7a3d
commit f99025da70
2 changed files with 15 additions and 17 deletions

View File

@ -68,30 +68,29 @@ public:
}
KMimeType::Ptr mime = KMimeType::findByPath(absImagePath);
QPixmap pm(q->size().toSize());
pm.fill(Qt::transparent);
QPixmap pm;
if (mime->is("image/svg+xml") || mime->is("image/svg+xml-compressed")) {
if (!svg || svg->imagePath() != imagePath) {
if (!svg || svg->imagePath() != absImagePath) {
delete svg;
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
if (!svgElement.isNull()) {
svg->setContainsMultipleImages(true);
}
}
QPainter p(&pm);
//QPainter p(&pm);
if (!svgElement.isNull() && svg->hasElement(svgElement)) {
QSizeF elementSize = svg->elementSize(svgElement);
float scale = pm.width() / qMax(elementSize.width(), elementSize.height());
svg->resize(svg->size() * scale);
QRectF elementRect(QPointF(0,0), svg->elementSize(svgElement));
elementRect.moveCenter(q->rect().center());
svg->paint(&p, elementRect, svgElement);
pm = svg->pixmap(svgElement);
} else {
svg->resize(pm.size());
svg->paint(&p, pm.rect());
pm = svg->pixmap();
}
} else {
delete svg;

View File

@ -68,8 +68,7 @@ public:
}
KMimeType::Ptr mime = KMimeType::findByPath(absImagePath);
QPixmap pm(q->size().toSize());
pm.fill(Qt::transparent);
QPixmap pm;
if (mime->is("image/svg+xml") || mime->is("image/svg+xml-compressed")) {
if (!svg || svg->imagePath() != absImagePath) {
@ -77,21 +76,21 @@ public:
svg = new Svg();
svg->setImagePath(imagePath);
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
if (!svgElement.isNull()) {
svg->setContainsMultipleImages(true);
}
}
QPainter p(&pm);
//QPainter p(&pm);
if (!svgElement.isNull() && svg->hasElement(svgElement)) {
QSizeF elementSize = svg->elementSize(svgElement);
float scale = pm.width() / qMax(elementSize.width(), elementSize.height());
svg->resize(svg->size() * scale);
QRectF elementRect(QPointF(0,0), svg->elementSize(svgElement));
elementRect.moveCenter(q->rect().center());
svg->paint(&p, elementRect, svgElement);
pm = svg->pixmap(svgElement);
} else {
svg->resize(pm.size());
svg->paint(&p, pm.rect());
pm = svg->pixmap();
}
} else {
delete svg;