From f99025da704af1c0fbba85ebe0ddd511b35e0497 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Sun, 27 Sep 2009 21:26:46 +0000 Subject: [PATCH] unbreak svg element loading as button icon svn path=/trunk/KDE/kdelibs/; revision=1028676 --- widgets/pushbutton.cpp | 17 ++++++++--------- widgets/toolbutton.cpp | 15 +++++++-------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/widgets/pushbutton.cpp b/widgets/pushbutton.cpp index 08fea1f5d..b334ec73d 100644 --- a/widgets/pushbutton.cpp +++ b/widgets/pushbutton.cpp @@ -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; diff --git a/widgets/toolbutton.cpp b/widgets/toolbutton.cpp index e59691c30..10804b759 100644 --- a/widgets/toolbutton.cpp +++ b/widgets/toolbutton.cpp @@ -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;