2010-10-14 13:43:01 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2006-2010 Aaron Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLASMA_SVG_P_H
|
|
|
|
#define PLASMA_SVG_P_H
|
|
|
|
|
|
|
|
#include <QHash>
|
|
|
|
#include <QSharedData>
|
|
|
|
#include <QSvgRenderer>
|
|
|
|
|
2010-10-14 14:16:56 +02:00
|
|
|
#include "ksharedptr.h"
|
2010-10-14 13:43:01 +02:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class Svg;
|
|
|
|
|
|
|
|
class SharedSvgRenderer : public QSvgRenderer, public QSharedData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef KSharedPtr<SharedSvgRenderer> Ptr;
|
|
|
|
|
|
|
|
SharedSvgRenderer(QObject *parent = 0);
|
2010-10-30 00:14:18 +02:00
|
|
|
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 = 0);
|
|
|
|
|
|
|
|
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 = 0);
|
2010-10-14 13:43:01 +02:00
|
|
|
|
|
|
|
private:
|
2010-10-30 00:14:18 +02:00
|
|
|
bool load(
|
|
|
|
const QByteArray &contents,
|
|
|
|
const QString &styleSheet,
|
2010-12-18 09:54:17 +01:00
|
|
|
QHash<QString, QRectF> &interestingElements);
|
2010-10-14 13:43:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class SvgPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SvgPrivate(Svg *svg);
|
|
|
|
~SvgPrivate();
|
|
|
|
|
|
|
|
//This function is meant for the rects cache
|
|
|
|
QString cacheId(const QString &elementId);
|
|
|
|
|
|
|
|
//This function is meant for the pixmap cache
|
|
|
|
QString cachePath(const QString &path, const QSize &size);
|
|
|
|
|
|
|
|
bool setImagePath(const QString &imagePath);
|
|
|
|
|
|
|
|
Theme *actualTheme();
|
2010-12-03 18:10:13 +01:00
|
|
|
Theme *cacheAndColorsTheme();
|
2010-10-14 13:43:01 +02:00
|
|
|
|
|
|
|
QPixmap findInCache(const QString &elementId, const QSizeF &s = QSizeF());
|
|
|
|
|
|
|
|
void createRenderer();
|
|
|
|
void eraseRenderer();
|
|
|
|
|
|
|
|
QRectF elementRect(const QString &elementId);
|
|
|
|
QRectF findAndCacheElementRect(const QString &elementId);
|
|
|
|
QMatrix matrixForElement(const QString &elementId);
|
|
|
|
|
|
|
|
void checkColorHints();
|
|
|
|
|
|
|
|
//Folowing two are utility functions to snap rendered elements to the pixel grid
|
|
|
|
//to and from are always 0 <= val <= 1
|
|
|
|
qreal closestDistance(qreal to, qreal from);
|
|
|
|
|
|
|
|
QRectF makeUniform(const QRectF &orig, const QRectF &dst);
|
|
|
|
|
|
|
|
//Slots
|
|
|
|
void themeChanged();
|
|
|
|
void colorsChanged();
|
|
|
|
|
|
|
|
static QHash<QString, SharedSvgRenderer::Ptr> s_renderers;
|
2010-12-03 18:10:13 +01:00
|
|
|
static QWeakPointer<Theme> s_systemColorsCache;
|
2010-10-14 13:43:01 +02:00
|
|
|
|
|
|
|
Svg *q;
|
|
|
|
QWeakPointer<Theme> theme;
|
|
|
|
QHash<QString, QRectF> localRectCache;
|
2010-10-30 00:14:18 +02:00
|
|
|
QHash<QString, QSize> elementsWithSizeHints;
|
2010-10-14 13:43:01 +02:00
|
|
|
SharedSvgRenderer::Ptr renderer;
|
|
|
|
QString themePath;
|
|
|
|
QString path;
|
|
|
|
QSizeF size;
|
|
|
|
QSizeF naturalSize;
|
|
|
|
QChar styleCrc;
|
|
|
|
unsigned int lastModified;
|
|
|
|
bool multipleImages : 1;
|
|
|
|
bool themed : 1;
|
|
|
|
bool applyColors : 1;
|
|
|
|
bool usesColors : 1;
|
|
|
|
bool cacheRendering : 1;
|
|
|
|
bool themeFailed : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|