2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
2010-10-14 14:05:55 +02:00
|
|
|
* Copyright 2008-2010 Marco Martin <notmart@gmail.com>
|
2008-11-04 00:08:39 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "svg.h"
|
2010-10-14 13:43:01 +02:00
|
|
|
#include "private/svg_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-02-15 21:36:35 +01:00
|
|
|
#include <cmath>
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QDir>
|
2010-10-01 18:04:34 +02:00
|
|
|
#include <QDomDocument>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QMatrix>
|
|
|
|
#include <QPainter>
|
2010-09-22 09:47:15 +02:00
|
|
|
#include <QStringBuilder>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kcolorscheme.h>
|
|
|
|
#include <kconfiggroup.h>
|
|
|
|
#include <kdebug.h>
|
2010-10-01 18:04:34 +02:00
|
|
|
#include <kfilterdev.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kiconeffect.h>
|
|
|
|
#include <kglobalsettings.h>
|
|
|
|
#include <ksharedptr.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-01-06 04:45:44 +01:00
|
|
|
#include "applet.h"
|
|
|
|
#include "package.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "theme.h"
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
SharedSvgRenderer::SharedSvgRenderer(QObject *parent)
|
|
|
|
: QSvgRenderer(parent)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2010-10-14 13:43:01 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-30 00:14:18 +02:00
|
|
|
SharedSvgRenderer::SharedSvgRenderer(
|
|
|
|
const QString &filename,
|
|
|
|
const QString &styleSheet,
|
2010-12-18 09:54:17 +01:00
|
|
|
QHash<QString, QRectF> &interestingElements,
|
2010-10-30 00:14:18 +02:00
|
|
|
QObject *parent)
|
2010-10-01 18:04:34 +02:00
|
|
|
: QSvgRenderer(parent)
|
|
|
|
{
|
|
|
|
QIODevice *file = KFilterDev::deviceForFile(filename, "application/x-gzip");
|
|
|
|
if (!file->open(QIODevice::ReadOnly)) {
|
|
|
|
delete file;
|
|
|
|
return;
|
|
|
|
}
|
2010-12-18 09:54:17 +01:00
|
|
|
load(file->readAll(), styleSheet, interestingElements);
|
2010-10-01 18:04:34 +02:00
|
|
|
delete file;
|
|
|
|
}
|
|
|
|
|
2010-10-30 00:14:18 +02:00
|
|
|
SharedSvgRenderer::SharedSvgRenderer(
|
|
|
|
const QByteArray &contents,
|
|
|
|
const QString &styleSheet,
|
2010-12-18 09:54:17 +01:00
|
|
|
QHash<QString, QRectF> &interestingElements,
|
2010-10-30 00:14:18 +02:00
|
|
|
QObject *parent)
|
2010-10-01 18:04:34 +02:00
|
|
|
: QSvgRenderer(parent)
|
|
|
|
{
|
2010-12-18 09:54:17 +01:00
|
|
|
load(contents, styleSheet, interestingElements);
|
2010-10-01 18:04:34 +02:00
|
|
|
}
|
|
|
|
|
2010-10-30 00:14:18 +02:00
|
|
|
bool SharedSvgRenderer::load(
|
|
|
|
const QByteArray &contents,
|
|
|
|
const QString &styleSheet,
|
2010-12-18 09:54:17 +01:00
|
|
|
QHash<QString, QRectF> &interestingElements)
|
2010-10-01 18:04:34 +02:00
|
|
|
{
|
2010-12-18 09:54:17 +01:00
|
|
|
// Apply the style sheet.
|
|
|
|
if (!styleSheet.isEmpty() && contents.contains("current-color-scheme")) {
|
|
|
|
QDomDocument svg;
|
|
|
|
if (!svg.setContent(contents)) {
|
|
|
|
return false;
|
2010-10-30 00:14:18 +02:00
|
|
|
}
|
|
|
|
|
2010-12-18 09:54:17 +01:00
|
|
|
QDomNode defs = svg.elementsByTagName("defs").item(0);
|
2010-10-30 00:14:18 +02:00
|
|
|
|
2010-12-18 09:54:17 +01:00
|
|
|
for (QDomElement style = defs.firstChildElement("style"); !style.isNull();
|
|
|
|
style = style.nextSiblingElement("style")) {
|
|
|
|
if (style.attribute("id") == "current-color-scheme") {
|
|
|
|
QDomElement colorScheme = svg.createElement("style");
|
|
|
|
colorScheme.setAttribute("type", "text/css");
|
|
|
|
colorScheme.setAttribute("id", "current-color-scheme");
|
|
|
|
defs.replaceChild(colorScheme, style);
|
|
|
|
colorScheme.appendChild(svg.createCDATASection(styleSheet));
|
|
|
|
|
|
|
|
interestingElements.insert("current-color-scheme", QRect(0,0,1,1));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!QSvgRenderer::load(svg.toByteArray(-1))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (!QSvgRenderer::load(contents)) {
|
2010-10-01 18:04:34 +02:00
|
|
|
return false;
|
|
|
|
}
|
2010-10-30 00:14:18 +02:00
|
|
|
|
2010-12-18 09:54:17 +01:00
|
|
|
// Search the SVG to find and store all ids that contain size hints.
|
|
|
|
const QString contentsAsString(QString::fromLatin1(contents));
|
|
|
|
QRegExp idExpr("id\\s*=\\s*(['\"])(\\d+-\\d+-.*)\\1");
|
|
|
|
idExpr.setMinimal(true);
|
|
|
|
|
|
|
|
int pos = 0;
|
|
|
|
while ((pos = idExpr.indexIn(contentsAsString, pos)) != -1) {
|
|
|
|
QString elementId = idExpr.cap(2);
|
2010-10-01 18:04:34 +02:00
|
|
|
|
2010-12-18 09:54:17 +01:00
|
|
|
QRectF elementRect = boundsOnElement(elementId);
|
|
|
|
if (elementRect.isValid()) {
|
|
|
|
interestingElements.insert(elementId, elementRect);
|
2010-10-01 18:04:34 +02:00
|
|
|
}
|
|
|
|
|
2010-12-18 09:54:17 +01:00
|
|
|
pos += idExpr.matchedLength();
|
2010-10-01 18:04:34 +02:00
|
|
|
}
|
2010-12-18 09:54:17 +01:00
|
|
|
|
|
|
|
return true;
|
2010-10-01 18:04:34 +02:00
|
|
|
}
|
|
|
|
|
2010-10-04 23:51:27 +02:00
|
|
|
#define QLSEP QLatin1Char('_')
|
2010-12-03 18:10:13 +01:00
|
|
|
#define CACHE_ID_WITH_SIZE(size, id) QString::number(int(size.width())) % QLSEP % QString::number(int(size.height())) % QLSEP % id
|
2010-10-30 00:14:18 +02:00
|
|
|
#define CACHE_ID_NATURAL_SIZE(id) QLatin1Literal("Natural") % QLSEP % id
|
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
SvgPrivate::SvgPrivate(Svg *svg)
|
|
|
|
: q(svg),
|
|
|
|
renderer(0),
|
|
|
|
styleCrc(0),
|
|
|
|
lastModified(0),
|
|
|
|
multipleImages(false),
|
|
|
|
themed(false),
|
|
|
|
applyColors(false),
|
|
|
|
usesColors(false),
|
|
|
|
cacheRendering(true),
|
|
|
|
themeFailed(false)
|
|
|
|
{
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
SvgPrivate::~SvgPrivate()
|
|
|
|
{
|
|
|
|
eraseRenderer();
|
|
|
|
}
|
2008-12-05 20:50:01 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
//This function is meant for the rects cache
|
|
|
|
QString SvgPrivate::cacheId(const QString &elementId)
|
|
|
|
{
|
|
|
|
if (size.isValid() && size != naturalSize) {
|
|
|
|
return CACHE_ID_WITH_SIZE(size, elementId);
|
|
|
|
} else {
|
2010-10-30 00:14:18 +02:00
|
|
|
return CACHE_ID_NATURAL_SIZE(elementId);
|
2010-10-14 13:43:01 +02:00
|
|
|
}
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
//This function is meant for the pixmap cache
|
|
|
|
QString SvgPrivate::cachePath(const QString &path, const QSize &size)
|
|
|
|
{
|
|
|
|
return CACHE_ID_WITH_SIZE(size, path);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
bool SvgPrivate::setImagePath(const QString &imagePath)
|
|
|
|
{
|
|
|
|
const bool isThemed = !QDir::isAbsolutePath(imagePath);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
// lets check to see if we're already set to this file
|
|
|
|
if (isThemed == themed &&
|
2010-12-03 18:10:13 +01:00
|
|
|
((themed && themePath == imagePath) ||
|
|
|
|
(!themed && path == imagePath))) {
|
2010-10-14 13:43:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
2009-05-18 15:20:52 +02:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
eraseRenderer();
|
2009-05-18 15:43:49 +02:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
// if we don't have any path right now and are going to set one,
|
|
|
|
// then lets not schedule a repaint because we are just initializing!
|
|
|
|
bool updateNeeded = true; //!path.isEmpty() || !themePath.isEmpty();
|
2009-05-18 15:43:49 +02:00
|
|
|
|
2010-12-03 18:10:13 +01:00
|
|
|
QObject::disconnect(actualTheme(), SIGNAL(themeChanged()), q, SLOT(themeChanged()));
|
2010-12-07 21:16:43 +01:00
|
|
|
if (isThemed && !themed && s_systemColorsCache) {
|
|
|
|
// catch the case where we weren't themed, but now we are, and the colors cache was set up
|
|
|
|
// ensure we are not connected to that theme previously
|
|
|
|
QObject::disconnect(s_systemColorsCache.data(), 0, q, 0);
|
|
|
|
}
|
2009-05-18 15:43:49 +02:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
themed = isThemed;
|
|
|
|
path.clear();
|
|
|
|
themePath.clear();
|
|
|
|
localRectCache.clear();
|
2010-10-30 00:14:18 +02:00
|
|
|
elementsWithSizeHints.clear();
|
2010-10-14 13:43:01 +02:00
|
|
|
|
|
|
|
if (themed) {
|
|
|
|
themePath = imagePath;
|
|
|
|
themeFailed = false;
|
|
|
|
QObject::connect(actualTheme(), SIGNAL(themeChanged()), q, SLOT(themeChanged()));
|
|
|
|
} else if (QFile::exists(imagePath)) {
|
2010-12-07 21:16:43 +01:00
|
|
|
QObject::connect(cacheAndColorsTheme(), SIGNAL(themeChanged()), q, SLOT(themeChanged()), Qt::UniqueConnection);
|
2010-10-14 13:43:01 +02:00
|
|
|
path = imagePath;
|
|
|
|
} else {
|
|
|
|
kDebug() << "file '" << path << "' does not exist!";
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
// check if svg wants colorscheme applied
|
|
|
|
checkColorHints();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
// also images with absolute path needs to have a natural size initialized,
|
|
|
|
// even if looks a bit weird using Theme to store non-themed stuff
|
|
|
|
if (themed || QFile::exists(imagePath)) {
|
|
|
|
QRectF rect;
|
2010-12-03 18:10:13 +01:00
|
|
|
if (cacheAndColorsTheme()->findInRectsCache(path, "_Natural", rect)) {
|
|
|
|
naturalSize = rect.size();
|
|
|
|
} else {
|
2010-10-14 13:43:01 +02:00
|
|
|
createRenderer();
|
|
|
|
naturalSize = renderer->defaultSize();
|
|
|
|
//kDebug() << "natural size for" << path << "from renderer is" << naturalSize;
|
2010-12-03 18:10:13 +01:00
|
|
|
cacheAndColorsTheme()->insertIntoRectsCache(path, "_Natural", QRectF(QPointF(0,0), naturalSize));
|
2010-10-14 13:43:01 +02:00
|
|
|
//kDebug() << "natural size for" << path << "from cache is" << naturalSize;
|
2009-05-18 15:20:52 +02:00
|
|
|
}
|
2010-10-14 13:43:01 +02:00
|
|
|
}
|
2009-05-18 15:20:52 +02:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
if (!themed) {
|
|
|
|
QFile f(imagePath);
|
|
|
|
QFileInfo info(f);
|
|
|
|
lastModified = info.lastModified().toTime_t();
|
|
|
|
}
|
2010-02-15 23:49:19 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
return updateNeeded;
|
|
|
|
}
|
2010-02-15 23:49:19 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
Theme *SvgPrivate::actualTheme()
|
|
|
|
{
|
|
|
|
if (!theme) {
|
|
|
|
theme = Plasma::Theme::defaultTheme();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
return theme.data();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-12-03 18:10:13 +01:00
|
|
|
Theme *SvgPrivate::cacheAndColorsTheme()
|
|
|
|
{
|
2010-12-07 21:16:43 +01:00
|
|
|
if (themed) {
|
|
|
|
return actualTheme();
|
|
|
|
} else {
|
|
|
|
// use a separate cache source for unthemed svg's
|
2010-12-03 18:10:13 +01:00
|
|
|
if (!s_systemColorsCache) {
|
|
|
|
//FIXME: reference count this, so that it is deleted when no longer in use
|
|
|
|
s_systemColorsCache = new Plasma::Theme("internal-system-colors");
|
|
|
|
}
|
|
|
|
|
|
|
|
return s_systemColorsCache.data();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
QPixmap SvgPrivate::findInCache(const QString &elementId, const QSizeF &s)
|
|
|
|
{
|
|
|
|
QSize size;
|
2010-10-30 00:14:18 +02:00
|
|
|
QString actualElementId;
|
|
|
|
|
|
|
|
if (elementsWithSizeHints.isEmpty()) {
|
|
|
|
// Fetch all size hinted element ids from the theme's rect cache
|
|
|
|
// and store them locally.
|
|
|
|
QRegExp sizeHintedKeyExpr(CACHE_ID_NATURAL_SIZE("(\\d+)-(\\d+)-(.+)"));
|
|
|
|
|
2010-12-03 18:10:13 +01:00
|
|
|
foreach (const QString &key, cacheAndColorsTheme()->listCachedRectKeys(path)) {
|
2010-10-30 00:14:18 +02:00
|
|
|
if (sizeHintedKeyExpr.exactMatch(key)) {
|
|
|
|
QString baseElementId = sizeHintedKeyExpr.cap(3);
|
2010-12-03 18:10:13 +01:00
|
|
|
QSize sizeHint(sizeHintedKeyExpr.cap(1).toInt(),
|
|
|
|
sizeHintedKeyExpr.cap(2).toInt());
|
2010-10-30 00:14:18 +02:00
|
|
|
|
|
|
|
if (sizeHint.isValid()) {
|
|
|
|
elementsWithSizeHints.insertMulti(baseElementId, sizeHint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (elementsWithSizeHints.isEmpty()) {
|
|
|
|
// Make sure we won't query the theme unnecessarily.
|
|
|
|
elementsWithSizeHints.insert(QString(), QSize());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look at the size hinted elements and try to find the smallest one with an
|
|
|
|
// identical aspect ratio.
|
|
|
|
if (s.isValid() && !elementId.isEmpty()) {
|
|
|
|
QList<QSize> elementSizeHints = elementsWithSizeHints.values(elementId);
|
|
|
|
|
|
|
|
if (!elementSizeHints.isEmpty()) {
|
|
|
|
QSize bestFit(-1, -1);
|
|
|
|
|
|
|
|
Q_FOREACH(const QSize &hint, elementSizeHints) {
|
|
|
|
|
|
|
|
if (hint.width() >= s.width() && hint.height() >= s.height() &&
|
|
|
|
(!bestFit.isValid() ||
|
2010-12-03 18:10:13 +01:00
|
|
|
(bestFit.width() * bestFit.height()) > (hint.width() * hint.height()))) {
|
2010-10-30 00:14:18 +02:00
|
|
|
bestFit = hint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bestFit.isValid()) {
|
2010-12-03 18:10:13 +01:00
|
|
|
actualElementId = QString::number(bestFit.width()) % "-" %
|
|
|
|
QString::number(bestFit.height()) % "-" % elementId;
|
2010-10-30 00:14:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
if (elementId.isEmpty() || !q->hasElement(actualElementId)) {
|
|
|
|
actualElementId = elementId;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
if (elementId.isEmpty() || (multipleImages && s.isValid())) {
|
|
|
|
size = s.toSize();
|
|
|
|
} else {
|
|
|
|
size = elementRect(actualElementId).size().toSize();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
if (size.isEmpty()) {
|
|
|
|
return QPixmap();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
QString id = cachePath(path, size);
|
2009-05-18 15:20:52 +02:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
if (!actualElementId.isEmpty()) {
|
|
|
|
id.append(actualElementId);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
//kDebug() << "id is " << id;
|
2010-02-15 21:36:35 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
QPixmap p;
|
2010-12-03 18:10:13 +01:00
|
|
|
if (cacheRendering && cacheAndColorsTheme()->findInCache(id, p, lastModified)) {
|
|
|
|
//kDebug() << "found cached version of " << id << p.size();
|
|
|
|
return p;
|
2010-10-14 13:43:01 +02:00
|
|
|
}
|
2010-02-15 21:36:35 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
//kDebug() << "didn't find cached version of " << id << ", so re-rendering";
|
2010-02-15 21:36:35 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
//kDebug() << "size for " << actualElementId << " is " << s;
|
|
|
|
// we have to re-render this puppy
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
createRenderer();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
QRectF finalRect = makeUniform(renderer->boundsOnElement(actualElementId), QRect(QPoint(0,0), size));
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
//don't alter the pixmap size or it won't match up properly to, e.g., FrameSvg elements
|
|
|
|
//makeUniform should never change the size so much that it gains or loses a whole pixel
|
|
|
|
p = QPixmap(size);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
p.fill(Qt::transparent);
|
|
|
|
QPainter renderPainter(&p);
|
2008-12-07 13:44:10 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
if (actualElementId.isEmpty()) {
|
|
|
|
renderer->render(&renderPainter, finalRect);
|
|
|
|
} else {
|
|
|
|
renderer->render(&renderPainter, actualElementId, finalRect);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
renderPainter.end();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
// Apply current color scheme if the svg asks for it
|
|
|
|
if (applyColors) {
|
|
|
|
QImage itmp = p.toImage();
|
2010-12-03 18:10:13 +01:00
|
|
|
KIconEffect::colorize(itmp, cacheAndColorsTheme()->color(Theme::BackgroundColor), 1.0);
|
2010-10-14 13:43:01 +02:00
|
|
|
p = p.fromImage(itmp);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
if (cacheRendering) {
|
2010-12-03 18:10:13 +01:00
|
|
|
cacheAndColorsTheme()->insertIntoCache(id, p, QString::number((qint64)q, 16) % QLSEP % actualElementId);
|
2010-10-14 13:43:01 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
return p;
|
|
|
|
}
|
2010-10-01 18:04:34 +02:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
void SvgPrivate::createRenderer()
|
|
|
|
{
|
|
|
|
if (renderer) {
|
|
|
|
return;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
//kDebug() << kBacktrace();
|
|
|
|
if (themed && path.isEmpty() && !themeFailed) {
|
|
|
|
Applet *applet = qobject_cast<Applet*>(q->parent());
|
|
|
|
if (applet && applet->package()) {
|
|
|
|
path = applet->package()->filePath("images", themePath + ".svg");
|
2009-09-28 22:41:37 +02:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
if (path.isEmpty()) {
|
|
|
|
path = applet->package()->filePath("images", themePath + ".svgz");
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2010-10-14 13:43:01 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
if (path.isEmpty()) {
|
|
|
|
path = actualTheme()->imagePath(themePath);
|
|
|
|
themeFailed = path.isEmpty();
|
|
|
|
if (themeFailed) {
|
|
|
|
kWarning() << "No image path found for" << themePath;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
2010-10-14 13:43:01 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
//kDebug() << "********************************";
|
|
|
|
//kDebug() << "FAIL! **************************";
|
|
|
|
//kDebug() << path << "**";
|
2009-05-18 15:20:52 +02:00
|
|
|
|
2010-12-18 09:54:17 +01:00
|
|
|
QString styleSheet = cacheAndColorsTheme()->styleSheet("SVG");
|
|
|
|
styleCrc = qChecksum(styleSheet.toUtf8(), styleSheet.size());
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
QHash<QString, SharedSvgRenderer::Ptr>::const_iterator it = s_renderers.constFind(styleCrc + path);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
if (it != s_renderers.constEnd()) {
|
|
|
|
//kDebug() << "gots us an existing one!";
|
|
|
|
renderer = it.value();
|
|
|
|
} else {
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
renderer = new SharedSvgRenderer();
|
|
|
|
} else {
|
2010-12-18 09:54:17 +01:00
|
|
|
QHash<QString, QRectF> interestingElements;
|
|
|
|
renderer = new SharedSvgRenderer(path, styleSheet, interestingElements);
|
2010-10-30 00:14:18 +02:00
|
|
|
|
2010-12-18 09:54:17 +01:00
|
|
|
// Add interesting elements to the theme's rect cache.
|
|
|
|
QHashIterator<QString, QRectF> i(interestingElements);
|
2010-10-30 00:14:18 +02:00
|
|
|
|
|
|
|
while (i.hasNext()) {
|
|
|
|
i.next();
|
2010-12-18 09:54:17 +01:00
|
|
|
const QString &elementId = i.key();
|
|
|
|
const QRectF &elementRect = i.value();
|
2010-10-30 00:14:18 +02:00
|
|
|
|
2010-12-18 09:54:17 +01:00
|
|
|
const QString cacheId = CACHE_ID_NATURAL_SIZE(elementId);
|
|
|
|
localRectCache.insert(cacheId, elementRect);
|
|
|
|
cacheAndColorsTheme()->insertIntoRectsCache(path, cacheId, elementRect);
|
|
|
|
}
|
2010-10-14 13:43:01 +02:00
|
|
|
}
|
2009-09-28 22:41:37 +02:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
s_renderers[styleCrc + path] = renderer;
|
|
|
|
}
|
2009-09-28 22:41:37 +02:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
if (size == QSizeF()) {
|
|
|
|
size = renderer->defaultSize();
|
|
|
|
}
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
void SvgPrivate::eraseRenderer()
|
|
|
|
{
|
|
|
|
if (renderer && renderer.count() == 2) {
|
|
|
|
// this and the cache reference it
|
|
|
|
s_renderers.erase(s_renderers.find(styleCrc + path));
|
2008-12-01 19:07:20 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
if (theme) {
|
|
|
|
theme.data()->releaseRectsCache(path);
|
|
|
|
}
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
renderer = 0;
|
|
|
|
styleCrc = 0;
|
|
|
|
localRectCache.clear();
|
2010-10-30 00:14:18 +02:00
|
|
|
elementsWithSizeHints.clear();
|
2010-10-14 13:43:01 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
QRectF SvgPrivate::elementRect(const QString &elementId)
|
|
|
|
{
|
|
|
|
if (themed && path.isEmpty()) {
|
|
|
|
if (themeFailed) {
|
|
|
|
return QRectF();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
path = actualTheme()->imagePath(themePath);
|
|
|
|
themeFailed = path.isEmpty();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
if (themeFailed) {
|
|
|
|
return QRectF();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2010-10-14 13:43:01 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
QString id = cacheId(elementId);
|
|
|
|
if (localRectCache.contains(id)) {
|
|
|
|
return localRectCache.value(id);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
QRectF rect;
|
2010-12-03 18:10:13 +01:00
|
|
|
if (cacheAndColorsTheme()->findInRectsCache(path, id, rect)) {
|
2010-10-14 13:43:01 +02:00
|
|
|
localRectCache.insert(id, rect);
|
|
|
|
return rect;
|
|
|
|
}
|
2010-02-15 21:36:35 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
return findAndCacheElementRect(elementId);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF SvgPrivate::findAndCacheElementRect(const QString &elementId)
|
|
|
|
{
|
|
|
|
createRenderer();
|
2010-12-18 09:54:17 +01:00
|
|
|
|
|
|
|
// createRenderer() can insert some interesting rects in the cache, so check it
|
|
|
|
const QString id = cacheId(elementId);
|
|
|
|
if (localRectCache.contains(id)) {
|
|
|
|
return localRectCache.value(id);
|
|
|
|
}
|
2010-10-14 13:43:01 +02:00
|
|
|
QRectF elementRect = renderer->elementExists(elementId) ?
|
|
|
|
renderer->boundsOnElement(elementId) : QRectF();
|
|
|
|
naturalSize = renderer->defaultSize();
|
|
|
|
//kDebug() << "natural size for" << path << "is" << naturalSize;
|
|
|
|
qreal dx = size.width() / naturalSize.width();
|
|
|
|
qreal dy = size.height() / naturalSize.height();
|
|
|
|
|
|
|
|
elementRect = QRectF(elementRect.x() * dx, elementRect.y() * dy,
|
|
|
|
elementRect.width() * dx, elementRect.height() * dy);
|
|
|
|
|
2010-12-18 09:54:17 +01:00
|
|
|
cacheAndColorsTheme()->insertIntoRectsCache(path, id, elementRect);
|
2010-10-14 13:43:01 +02:00
|
|
|
return elementRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMatrix SvgPrivate::matrixForElement(const QString &elementId)
|
|
|
|
{
|
|
|
|
createRenderer();
|
|
|
|
return renderer->matrixForElement(elementId);
|
|
|
|
}
|
2010-02-15 21:36:35 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
void SvgPrivate::checkColorHints()
|
|
|
|
{
|
|
|
|
if (elementRect("hint-apply-color-scheme").isValid()) {
|
|
|
|
applyColors = true;
|
|
|
|
usesColors = true;
|
|
|
|
} else if (elementRect("current-color-scheme").isValid()) {
|
|
|
|
applyColors = false;
|
|
|
|
usesColors = true;
|
|
|
|
} else {
|
|
|
|
applyColors = false;
|
|
|
|
usesColors = false;
|
|
|
|
}
|
2010-12-03 18:10:13 +01:00
|
|
|
|
|
|
|
// check to see if we are using colors, but the theme isn't being used or isn't providing
|
|
|
|
// a colorscheme
|
|
|
|
if (usesColors && (!themed || !actualTheme()->colorScheme())) {
|
|
|
|
QObject::connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
|
2010-12-07 21:16:43 +01:00
|
|
|
q, SLOT(colorsChanged()), Qt::UniqueConnection);
|
2010-12-03 18:10:13 +01:00
|
|
|
} else {
|
|
|
|
QObject::disconnect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
|
|
|
|
q, SLOT(colorsChanged()));
|
|
|
|
}
|
2010-10-14 13:43:01 +02:00
|
|
|
}
|
2010-02-15 21:36:35 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
//Folowing two are utility functions to snap rendered elements to the pixel grid
|
|
|
|
//to and from are always 0 <= val <= 1
|
|
|
|
qreal SvgPrivate::closestDistance(qreal to, qreal from)
|
|
|
|
{
|
|
|
|
qreal a = to - from;
|
|
|
|
if (qFuzzyCompare(to, from))
|
|
|
|
return 0;
|
|
|
|
else if ( to > from ) {
|
|
|
|
qreal b = to - from - 1;
|
|
|
|
return (qAbs(a) > qAbs(b)) ? b : a;
|
|
|
|
} else {
|
|
|
|
qreal b = 1 + to - from;
|
|
|
|
return (qAbs(a) > qAbs(b)) ? b : a;
|
|
|
|
}
|
|
|
|
}
|
2010-02-15 21:36:35 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
QRectF SvgPrivate::makeUniform(const QRectF &orig, const QRectF &dst)
|
|
|
|
{
|
|
|
|
if (qFuzzyIsNull(orig.x()) || qFuzzyIsNull(orig.y())) {
|
|
|
|
return dst;
|
|
|
|
}
|
2010-02-15 21:36:35 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
QRectF res(dst);
|
|
|
|
qreal div_w = dst.width() / orig.width();
|
|
|
|
qreal div_h = dst.height() / orig.height();
|
2010-02-15 21:36:35 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
qreal div_x = dst.x() / orig.x();
|
|
|
|
qreal div_y = dst.y() / orig.y();
|
2009-05-18 15:43:49 +02:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
//horizontal snap
|
|
|
|
if (!qFuzzyIsNull(div_x) && !qFuzzyCompare(div_w, div_x)) {
|
|
|
|
qreal rem_orig = orig.x() - (floor(orig.x()));
|
|
|
|
qreal rem_dst = dst.x() - (floor(dst.x()));
|
|
|
|
qreal offset = closestDistance(rem_dst, rem_orig);
|
|
|
|
res.translate(offset + offset*div_w, 0);
|
|
|
|
res.setWidth(res.width() + offset);
|
|
|
|
}
|
|
|
|
//vertical snap
|
|
|
|
if (!qFuzzyIsNull(div_y) && !qFuzzyCompare(div_h, div_y)) {
|
|
|
|
qreal rem_orig = orig.y() - (floor(orig.y()));
|
|
|
|
qreal rem_dst = dst.y() - (floor(dst.y()));
|
|
|
|
qreal offset = closestDistance(rem_dst, rem_orig);
|
|
|
|
res.translate(0, offset + offset*div_h);
|
|
|
|
res.setHeight(res.height() + offset);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
//kDebug()<<"Aligning Rects, origin:"<<orig<<"destination:"<<dst<<"result:"<<res;
|
|
|
|
return res;
|
|
|
|
}
|
2009-05-01 18:28:10 +02:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
void SvgPrivate::themeChanged()
|
|
|
|
{
|
2010-12-07 21:16:43 +01:00
|
|
|
if (q->imagePath().isEmpty()) {
|
2010-10-14 13:43:01 +02:00
|
|
|
return;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-12-07 21:16:43 +01:00
|
|
|
if (themed) {
|
|
|
|
// check if new theme svg wants colorscheme applied
|
|
|
|
checkColorHints();
|
|
|
|
}
|
|
|
|
|
2010-12-12 11:39:27 +01:00
|
|
|
QString currentPath = themed ? themePath : path;
|
2010-10-14 13:43:01 +02:00
|
|
|
themePath.clear();
|
|
|
|
eraseRenderer();
|
|
|
|
setImagePath(currentPath);
|
|
|
|
|
|
|
|
//kDebug() << themePath << ">>>>>>>>>>>>>>>>>> theme changed";
|
|
|
|
emit q->repaintNeeded();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-10-14 13:43:01 +02:00
|
|
|
void SvgPrivate::colorsChanged()
|
|
|
|
{
|
|
|
|
if (!usesColors) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
eraseRenderer();
|
|
|
|
//kDebug() << "repaint needed from colorsChanged";
|
|
|
|
emit q->repaintNeeded();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
QHash<QString, SharedSvgRenderer::Ptr> SvgPrivate::s_renderers;
|
2010-12-03 18:10:13 +01:00
|
|
|
QWeakPointer<Theme> SvgPrivate::s_systemColorsCache;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
Svg::Svg(QObject *parent)
|
|
|
|
: QObject(parent),
|
|
|
|
d(new SvgPrivate(this))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Svg::~Svg()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap Svg::pixmap(const QString &elementID)
|
|
|
|
{
|
|
|
|
if (elementID.isNull() || d->multipleImages) {
|
|
|
|
return d->findInCache(elementID, size());
|
|
|
|
} else {
|
|
|
|
return d->findInCache(elementID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Svg::paint(QPainter *painter, const QPointF &point, const QString &elementID)
|
|
|
|
{
|
2010-09-20 21:42:38 +02:00
|
|
|
QPixmap pix((elementID.isNull() || d->multipleImages) ? d->findInCache(elementID, size()) :
|
|
|
|
d->findInCache(elementID));
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
if (pix.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
painter->drawPixmap(QRectF(point, pix.size()), pix, QRectF(QPointF(0, 0), pix.size()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Svg::paint(QPainter *painter, int x, int y, const QString &elementID)
|
|
|
|
{
|
|
|
|
paint(painter, QPointF(x, y), elementID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Svg::paint(QPainter *painter, const QRectF &rect, const QString &elementID)
|
|
|
|
{
|
|
|
|
QPixmap pix(d->findInCache(elementID, rect.size()));
|
2009-03-18 19:06:56 +01:00
|
|
|
painter->drawPixmap(QRectF(rect.topLeft(), pix.size()), pix, QRectF(QPointF(0, 0), pix.size()));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Svg::paint(QPainter *painter, int x, int y, int width, int height, const QString &elementID)
|
|
|
|
{
|
|
|
|
QPixmap pix(d->findInCache(elementID, QSizeF(width, height)));
|
|
|
|
painter->drawPixmap(x, y, pix, 0, 0, pix.size().width(), pix.size().height());
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize Svg::size() const
|
|
|
|
{
|
2009-01-16 19:43:26 +01:00
|
|
|
if (d->size.isEmpty()) {
|
2009-01-16 20:14:38 +01:00
|
|
|
d->size = d->naturalSize;
|
2009-01-16 19:43:26 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
return d->size.toSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Svg::resize(qreal width, qreal height)
|
|
|
|
{
|
|
|
|
resize(QSize(width, height));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Svg::resize(const QSizeF &size)
|
|
|
|
{
|
2008-12-01 22:40:13 +01:00
|
|
|
if (qFuzzyCompare(size.width(), d->size.width()) &&
|
|
|
|
qFuzzyCompare(size.height(), d->size.height())) {
|
2008-12-01 22:10:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
d->size = size;
|
2008-12-01 22:10:33 +01:00
|
|
|
d->localRectCache.clear();
|
2010-12-06 22:54:29 +01:00
|
|
|
emit sizeChanged();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Svg::resize()
|
|
|
|
{
|
2009-01-16 18:41:49 +01:00
|
|
|
if (qFuzzyCompare(d->naturalSize.width(), d->size.width()) &&
|
|
|
|
qFuzzyCompare(d->naturalSize.height(), d->size.height())) {
|
2008-12-01 22:10:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-16 18:41:49 +01:00
|
|
|
d->size = d->naturalSize;
|
2008-12-01 22:10:33 +01:00
|
|
|
d->localRectCache.clear();
|
2010-12-06 22:54:29 +01:00
|
|
|
emit sizeChanged();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QSize Svg::elementSize(const QString &elementId) const
|
|
|
|
{
|
|
|
|
return d->elementRect(elementId).size().toSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF Svg::elementRect(const QString &elementId) const
|
|
|
|
{
|
|
|
|
return d->elementRect(elementId);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Svg::hasElement(const QString &elementId) const
|
|
|
|
{
|
|
|
|
if (d->path.isNull() && d->themePath.isNull()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-05-18 15:43:49 +02:00
|
|
|
return d->elementRect(elementId).isValid();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Svg::elementAtPoint(const QPoint &point) const
|
|
|
|
{
|
2008-12-01 15:35:02 +01:00
|
|
|
Q_UNUSED(point)
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
return QString();
|
|
|
|
/*
|
|
|
|
FIXME: implement when Qt can support us!
|
|
|
|
d->createRenderer();
|
|
|
|
QSizeF naturalSize = d->renderer->defaultSize();
|
|
|
|
qreal dx = d->size.width() / naturalSize.width();
|
|
|
|
qreal dy = d->size.height() / naturalSize.height();
|
|
|
|
//kDebug() << point << "is really"
|
|
|
|
// << QPoint(point.x() *dx, naturalSize.height() - point.y() * dy);
|
|
|
|
|
|
|
|
return QString(); // d->renderer->elementAtPoint(QPoint(point.x() *dx, naturalSize.height() - point.y() * dy));
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Svg::isValid() const
|
|
|
|
{
|
|
|
|
if (d->path.isNull() && d->themePath.isNull()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->createRenderer();
|
|
|
|
return d->renderer->isValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Svg::setContainsMultipleImages(bool multiple)
|
|
|
|
{
|
|
|
|
d->multipleImages = multiple;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Svg::containsMultipleImages() const
|
|
|
|
{
|
|
|
|
return d->multipleImages;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Svg::setImagePath(const QString &svgFilePath)
|
|
|
|
{
|
2010-10-14 13:43:01 +02:00
|
|
|
//BIC FIXME: setImagePath should be virtual, or call an internal virtual protected method
|
|
|
|
if (FrameSvg *frame = qobject_cast<FrameSvg *>(this)) {
|
|
|
|
frame->setImagePath(svgFilePath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-02 08:00:00 +02:00
|
|
|
d->setImagePath(svgFilePath);
|
|
|
|
//kDebug() << "repaintNeeded";
|
2008-12-01 19:07:20 +01:00
|
|
|
emit repaintNeeded();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Svg::imagePath() const
|
|
|
|
{
|
|
|
|
return d->themed ? d->themePath : d->path;
|
|
|
|
}
|
|
|
|
|
2009-05-13 18:13:56 +02:00
|
|
|
void Svg::setUsingRenderingCache(bool useCache)
|
2009-05-13 18:07:58 +02:00
|
|
|
{
|
|
|
|
d->cacheRendering = useCache;
|
|
|
|
}
|
|
|
|
|
2009-05-13 18:13:56 +02:00
|
|
|
bool Svg::isUsingRenderingCache() const
|
2009-05-13 18:07:58 +02:00
|
|
|
{
|
|
|
|
return d->cacheRendering;
|
|
|
|
}
|
|
|
|
|
2009-05-18 15:43:49 +02:00
|
|
|
void Svg::setTheme(Plasma::Theme *theme)
|
2009-05-18 14:26:57 +02:00
|
|
|
{
|
2010-12-07 21:16:43 +01:00
|
|
|
if (!theme || theme == d->theme.data()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-18 15:20:52 +02:00
|
|
|
if (d->theme) {
|
2009-10-13 23:43:35 +02:00
|
|
|
disconnect(d->theme.data(), 0, this, 0);
|
2009-05-18 14:26:57 +02:00
|
|
|
}
|
|
|
|
|
2009-05-18 15:20:52 +02:00
|
|
|
d->theme = theme;
|
2010-12-07 21:16:43 +01:00
|
|
|
connect(theme, SIGNAL(themeChanged()), this, SLOT(themeChanged()));
|
|
|
|
d->themeChanged();
|
2009-05-18 14:26:57 +02:00
|
|
|
}
|
|
|
|
|
2009-05-18 15:43:49 +02:00
|
|
|
Theme *Svg::theme() const
|
2009-05-18 14:26:57 +02:00
|
|
|
{
|
2009-10-13 23:43:35 +02:00
|
|
|
return d->theme ? d->theme.data() : Theme::defaultTheme();
|
2009-05-18 14:26:57 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#include "svg.moc"
|
|
|
|
|