2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2008 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2008 Marco Martin <notmart@gmail.com>
|
|
|
|
*
|
|
|
|
* 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 "framesvg.h"
|
2009-01-13 22:46:07 +01:00
|
|
|
#include "private/framesvg_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
#include <QAtomicInt>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QBitmap>
|
2010-09-27 19:19:06 +02:00
|
|
|
#include <QCryptographicHash>
|
|
|
|
#include <QPainter>
|
2008-12-15 23:17:59 +01:00
|
|
|
#include <QRegion>
|
2010-09-27 19:19:06 +02:00
|
|
|
#include <QSize>
|
|
|
|
#include <QStringBuilder>
|
2008-11-29 20:24:40 +01:00
|
|
|
#include <QTimer>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kdebug.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
#include <plasma/theme.h>
|
2009-01-13 22:46:07 +01:00
|
|
|
#include <plasma/applet.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
|
|
|
|
QHash<QString, FrameData *> FrameSvgPrivate::s_sharedFrames;
|
|
|
|
|
2009-12-22 18:28:22 +01:00
|
|
|
// Any attempt to generate a frame whose width or height is larger than this
|
|
|
|
// will be rejected
|
|
|
|
static const int MAX_FRAME_SIZE = 100000;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
FrameSvg::FrameSvg(QObject *parent)
|
|
|
|
: Svg(parent),
|
|
|
|
d(new FrameSvgPrivate(this))
|
|
|
|
{
|
|
|
|
connect(this, SIGNAL(repaintNeeded()), this, SLOT(updateNeeded()));
|
2010-09-27 19:19:06 +02:00
|
|
|
d->frames.insert(QString(), new FrameData(this));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FrameSvg::~FrameSvg()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvg::setImagePath(const QString &path)
|
|
|
|
{
|
|
|
|
if (path == imagePath()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Svg::setImagePath(path);
|
|
|
|
setContainsMultipleImages(true);
|
|
|
|
|
|
|
|
clearCache();
|
|
|
|
d->updateAndSignalSizes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvg::setEnabledBorders(const EnabledBorders borders)
|
|
|
|
{
|
|
|
|
if (borders == d->frames[d->prefix]->enabledBorders) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-09 20:07:17 +02:00
|
|
|
FrameData *fd = d->frames[d->prefix];
|
|
|
|
|
|
|
|
const QString oldKey = d->cacheId(fd, d->prefix);
|
|
|
|
const EnabledBorders oldBorders = fd->enabledBorders;
|
|
|
|
fd->enabledBorders = borders;
|
|
|
|
const QString newKey = d->cacheId(fd, d->prefix);
|
|
|
|
fd->enabledBorders = oldBorders;
|
|
|
|
|
|
|
|
//kDebug() << "looking for" << newKey;
|
|
|
|
FrameData *newFd = FrameSvgPrivate::s_sharedFrames.value(newKey);
|
|
|
|
if (newFd) {
|
|
|
|
//kDebug() << "FOUND IT!" << newFd->refcount;
|
|
|
|
// we've found a math, so insert that new one and ref it ..
|
|
|
|
newFd->ref(this);
|
|
|
|
d->frames.insert(d->prefix, newFd);
|
|
|
|
|
|
|
|
//.. then deref the old one and if it's no longer used, get rid of it
|
|
|
|
if (fd->deref(this)) {
|
|
|
|
//const QString oldKey = d->cacheId(fd, d->prefix);
|
|
|
|
//kDebug() << "1. Removing it" << oldKey << fd->refcount;
|
|
|
|
FrameSvgPrivate::s_sharedFrames.remove(oldKey);
|
|
|
|
delete fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fd->refcount() == 1) {
|
|
|
|
// we're the only user of it, let's remove it from the shared keys
|
|
|
|
// we don't want to deref it, however, as we'll still be using it
|
|
|
|
FrameSvgPrivate::s_sharedFrames.remove(oldKey);
|
|
|
|
} else {
|
|
|
|
// others are using it, but we wish to change its size. so deref it,
|
|
|
|
// then create a copy of it (we're automatically ref'd via the ctor),
|
|
|
|
// then insert it into our frames.
|
|
|
|
fd->deref(this);
|
|
|
|
fd = new FrameData(*fd, this);
|
|
|
|
d->frames.insert(d->prefix, fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
fd->enabledBorders = borders;
|
2008-11-04 00:08:39 +01:00
|
|
|
d->updateAndSignalSizes();
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameSvg::EnabledBorders FrameSvg::enabledBorders() const
|
|
|
|
{
|
2010-05-13 12:08:44 +02:00
|
|
|
if (d->frames.isEmpty()) {
|
|
|
|
return NoBorder;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
QHash<QString, FrameData*>::const_iterator it = d->frames.constFind(d->prefix);
|
|
|
|
|
|
|
|
if (it != d->frames.constEnd()) {
|
|
|
|
return it.value()->enabledBorders;
|
|
|
|
} else {
|
|
|
|
return NoBorder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvg::setElementPrefix(Plasma::Location location)
|
|
|
|
{
|
|
|
|
switch (location) {
|
|
|
|
case TopEdge:
|
|
|
|
setElementPrefix("north");
|
|
|
|
break;
|
|
|
|
case BottomEdge:
|
|
|
|
setElementPrefix("south");
|
|
|
|
break;
|
|
|
|
case LeftEdge:
|
|
|
|
setElementPrefix("west");
|
|
|
|
break;
|
|
|
|
case RightEdge:
|
|
|
|
setElementPrefix("east");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
setElementPrefix(QString());
|
|
|
|
break;
|
|
|
|
}
|
2009-05-31 07:38:42 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
d->location = location;
|
|
|
|
}
|
|
|
|
|
2009-05-31 07:38:42 +02:00
|
|
|
void FrameSvg::setElementPrefix(const QString &prefix)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
const QString oldPrefix(d->prefix);
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (!hasElement(prefix % "-center")) {
|
2008-11-04 00:08:39 +01:00
|
|
|
d->prefix.clear();
|
|
|
|
} else {
|
|
|
|
d->prefix = prefix;
|
|
|
|
if (!d->prefix.isEmpty()) {
|
|
|
|
d->prefix += '-';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-31 07:38:42 +02:00
|
|
|
FrameData *oldFrameData = d->frames.value(oldPrefix);
|
|
|
|
if (oldPrefix == d->prefix && oldFrameData) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!d->frames.contains(d->prefix)) {
|
2009-05-31 07:38:42 +02:00
|
|
|
if (oldFrameData) {
|
2010-09-27 19:19:06 +02:00
|
|
|
FrameData *newFd = 0;
|
|
|
|
if (!oldFrameData->frameSize.isEmpty()) {
|
|
|
|
const QString key = d->cacheId(oldFrameData, d->prefix);
|
|
|
|
newFd = FrameSvgPrivate::s_sharedFrames.value(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// we need to put this in the cache if we didn't find it in the shared frames
|
|
|
|
// and we have a size; if we don't have a size, we'll catch it later
|
|
|
|
const bool cache = !newFd && !oldFrameData->frameSize.isEmpty();
|
|
|
|
if (newFd) {
|
|
|
|
newFd->ref(this);
|
|
|
|
} else {
|
|
|
|
newFd = new FrameData(*oldFrameData, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->frames.insert(d->prefix, newFd);
|
|
|
|
|
|
|
|
if (cache) {
|
|
|
|
// we have to cache after inserting the frame since the cacheId requires the
|
|
|
|
// frame to be in the frames collection already
|
|
|
|
const QString key = d->cacheId(oldFrameData, d->prefix);
|
|
|
|
//kDebug() << this << " 1. inserting as" << key;
|
2010-10-05 21:26:00 +02:00
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
FrameSvgPrivate::s_sharedFrames.insert(key, newFd);
|
|
|
|
}
|
2009-05-31 07:38:42 +02:00
|
|
|
} else {
|
2010-09-27 19:19:06 +02:00
|
|
|
// couldn't find anything useful, so we just create something here
|
|
|
|
// we don't have a size for it yet, so don't bother trying to share it just yet
|
|
|
|
FrameData *newFd = new FrameData(this);
|
|
|
|
d->frames.insert(d->prefix, newFd);
|
2009-05-31 07:38:42 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
d->updateSizes();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!d->cacheAll) {
|
|
|
|
d->frames.remove(oldPrefix);
|
2010-09-27 19:19:06 +02:00
|
|
|
if (oldFrameData) {
|
|
|
|
if (oldFrameData->deref(this)) {
|
|
|
|
const QString oldKey = d->cacheId(oldFrameData, oldPrefix);
|
|
|
|
FrameSvgPrivate::s_sharedFrames.remove(oldKey);
|
|
|
|
delete oldFrameData;
|
|
|
|
}
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
d->location = Floating;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FrameSvg::hasElementPrefix(const QString & prefix) const
|
|
|
|
{
|
|
|
|
//for now it simply checks if a center element exists,
|
|
|
|
//because it could make sense for certain themes to not have all the elements
|
|
|
|
if (prefix.isEmpty()) {
|
|
|
|
return hasElement("center");
|
|
|
|
} else {
|
2010-09-27 19:19:06 +02:00
|
|
|
return hasElement(prefix % "-center");
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FrameSvg::hasElementPrefix(Plasma::Location location) const
|
|
|
|
{
|
|
|
|
switch (location) {
|
|
|
|
case TopEdge:
|
|
|
|
return hasElementPrefix("north");
|
|
|
|
break;
|
|
|
|
case BottomEdge:
|
|
|
|
return hasElementPrefix("south");
|
|
|
|
break;
|
|
|
|
case LeftEdge:
|
|
|
|
return hasElementPrefix("west");
|
|
|
|
break;
|
|
|
|
case RightEdge:
|
|
|
|
return hasElementPrefix("east");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return hasElementPrefix(QString());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString FrameSvg::prefix()
|
|
|
|
{
|
|
|
|
if (d->prefix.isEmpty()) {
|
|
|
|
return d->prefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->prefix.left(d->prefix.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvg::resizeFrame(const QSizeF &size)
|
|
|
|
{
|
|
|
|
if (size.isEmpty()) {
|
|
|
|
kWarning() << "Invalid size" << size;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
FrameData *fd = d->frames[d->prefix];
|
|
|
|
if (size == fd->frameSize) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-05 21:26:00 +02:00
|
|
|
const QString oldKey = d->cacheId(fd, d->prefix);
|
2010-09-27 19:19:06 +02:00
|
|
|
const QSize currentSize = fd->frameSize;
|
|
|
|
fd->frameSize = size.toSize();
|
|
|
|
const QString newKey = d->cacheId(fd, d->prefix);
|
|
|
|
fd->frameSize = currentSize;
|
|
|
|
|
|
|
|
//kDebug() << "looking for" << newKey;
|
|
|
|
FrameData *newFd = FrameSvgPrivate::s_sharedFrames.value(newKey);
|
|
|
|
if (newFd) {
|
|
|
|
//kDebug() << "FOUND IT!" << newFd->refcount;
|
|
|
|
// we've found a math, so insert that new one and ref it ..
|
|
|
|
newFd->ref(this);
|
|
|
|
d->frames.insert(d->prefix, newFd);
|
|
|
|
|
|
|
|
//.. then deref the old one and if it's no longer used, get rid of it
|
|
|
|
if (fd->deref(this)) {
|
|
|
|
//const QString oldKey = d->cacheId(fd, d->prefix);
|
|
|
|
//kDebug() << "1. Removing it" << oldKey << fd->refcount;
|
|
|
|
FrameSvgPrivate::s_sharedFrames.remove(oldKey);
|
|
|
|
delete fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fd->refcount() == 1) {
|
|
|
|
// we're the only user of it, let's remove it from the shared keys
|
|
|
|
// we don't want to deref it, however, as we'll still be using it
|
|
|
|
FrameSvgPrivate::s_sharedFrames.remove(oldKey);
|
|
|
|
} else {
|
|
|
|
// others are using it, but we wish to change its size. so deref it,
|
|
|
|
// then create a copy of it (we're automatically ref'd via the ctor),
|
|
|
|
// then insert it into our frames.
|
|
|
|
fd->deref(this);
|
|
|
|
fd = new FrameData(*fd, this);
|
|
|
|
d->frames.insert(d->prefix, fd);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
d->updateSizes();
|
2010-09-27 19:19:06 +02:00
|
|
|
fd->frameSize = size.toSize();
|
|
|
|
// we know it isn't in s_sharedFrames do the check above, so insert it now
|
|
|
|
FrameSvgPrivate::s_sharedFrames.insert(newKey, fd);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF FrameSvg::frameSize() const
|
|
|
|
{
|
|
|
|
QHash<QString, FrameData*>::const_iterator it = d->frames.constFind(d->prefix);
|
|
|
|
|
2009-06-10 19:11:02 +02:00
|
|
|
if (it == d->frames.constEnd()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return QSize(-1, -1);
|
2009-06-10 19:11:02 +02:00
|
|
|
} else {
|
|
|
|
return d->frameSize(it.value());
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal FrameSvg::marginSize(const Plasma::MarginEdge edge) const
|
|
|
|
{
|
|
|
|
if (d->frames[d->prefix]->noBorderPadding) {
|
|
|
|
return .0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (edge) {
|
|
|
|
case Plasma::TopMargin:
|
|
|
|
return d->frames[d->prefix]->topMargin;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Plasma::LeftMargin:
|
|
|
|
return d->frames[d->prefix]->leftMargin;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Plasma::RightMargin:
|
|
|
|
return d->frames[d->prefix]->rightMargin;
|
|
|
|
break;
|
|
|
|
|
|
|
|
//Plasma::BottomMargin
|
|
|
|
default:
|
|
|
|
return d->frames[d->prefix]->bottomMargin;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvg::getMargins(qreal &left, qreal &top, qreal &right, qreal &bottom) const
|
|
|
|
{
|
|
|
|
FrameData *frame = d->frames[d->prefix];
|
|
|
|
|
2009-11-04 01:12:59 +01:00
|
|
|
if (frame->noBorderPadding) {
|
2008-11-04 00:08:39 +01:00
|
|
|
left = top = right = bottom = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
top = frame->topMargin;
|
|
|
|
left = frame->leftMargin;
|
|
|
|
right = frame->rightMargin;
|
|
|
|
bottom = frame->bottomMargin;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF FrameSvg::contentsRect() const
|
|
|
|
{
|
|
|
|
QSizeF size(frameSize());
|
|
|
|
|
|
|
|
if (size.isValid()) {
|
|
|
|
QRectF rect(QPointF(0, 0), size);
|
|
|
|
FrameData *frame = d->frames[d->prefix];
|
|
|
|
|
|
|
|
return rect.adjusted(frame->leftMargin, frame->topMargin,
|
|
|
|
-frame->rightMargin, -frame->bottomMargin);
|
|
|
|
} else {
|
|
|
|
return QRectF();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-13 22:46:07 +01:00
|
|
|
QPixmap FrameSvg::alphaMask() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2010-03-05 23:37:44 +01:00
|
|
|
//FIXME: the distinction between overlay and
|
|
|
|
return d->alphaMask();
|
2009-01-13 22:46:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QRegion FrameSvg::mask() const
|
|
|
|
{
|
|
|
|
FrameData *frame = d->frames[d->prefix];
|
2010-08-05 23:15:18 +02:00
|
|
|
QString id = d->cacheId(frame, QString());
|
|
|
|
if (!frame->cachedMasks.contains(id)) {
|
|
|
|
//TODO: Implement a better way to cap the number of cached masks
|
|
|
|
if (frame->cachedMasks.count() > frame->MAX_CACHED_MASKS) {
|
|
|
|
frame->cachedMasks.clear();
|
|
|
|
}
|
|
|
|
frame->cachedMasks.insert(id, QRegion(QBitmap(d->alphaMask().alphaChannel().createMaskFromColor(Qt::black))));
|
|
|
|
}
|
|
|
|
return frame->cachedMasks[id];
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvg::setCacheAllRenderedFrames(bool cache)
|
|
|
|
{
|
|
|
|
if (d->cacheAll && !cache) {
|
|
|
|
clearCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
d->cacheAll = cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FrameSvg::cacheAllRenderedFrames() const
|
|
|
|
{
|
|
|
|
return d->cacheAll;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvg::clearCache()
|
|
|
|
{
|
|
|
|
FrameData *frame = d->frames[d->prefix];
|
|
|
|
|
|
|
|
// delete all the frames that aren't this one
|
|
|
|
QMutableHashIterator<QString, FrameData*> it(d->frames);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
FrameData *p = it.next().value();
|
|
|
|
if (frame != p) {
|
2010-09-27 19:19:06 +02:00
|
|
|
//TODO: should we clear from the Theme pixmap cache as well?
|
|
|
|
if (p->deref(this)) {
|
|
|
|
const QString key = d->cacheId(p, it.key());
|
|
|
|
FrameSvgPrivate::s_sharedFrames.remove(key);
|
|
|
|
delete p;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
it.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap FrameSvg::framePixmap()
|
|
|
|
{
|
|
|
|
FrameData *frame = d->frames[d->prefix];
|
|
|
|
if (frame->cachedBackground.isNull()) {
|
|
|
|
d->generateBackground(frame);
|
|
|
|
if (frame->cachedBackground.isNull()) {
|
|
|
|
return QPixmap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return frame->cachedBackground;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvg::paintFrame(QPainter *painter, const QRectF &target, const QRectF &source)
|
|
|
|
{
|
|
|
|
FrameData *frame = d->frames[d->prefix];
|
|
|
|
if (frame->cachedBackground.isNull()) {
|
|
|
|
d->generateBackground(frame);
|
|
|
|
if (frame->cachedBackground.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
painter->drawPixmap(target, frame->cachedBackground, source.isValid() ? source : target);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvg::paintFrame(QPainter *painter, const QPointF &pos)
|
|
|
|
{
|
|
|
|
FrameData *frame = d->frames[d->prefix];
|
|
|
|
if (frame->cachedBackground.isNull()) {
|
|
|
|
d->generateBackground(frame);
|
|
|
|
if (frame->cachedBackground.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
painter->drawPixmap(pos, frame->cachedBackground);
|
|
|
|
}
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
//#define DEBUG_FRAMESVG_CACHE
|
|
|
|
FrameSvgPrivate::~FrameSvgPrivate()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_FRAMESVG_CACHE
|
|
|
|
kDebug() << "*************" << q << q->imagePath() << "****************";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QHashIterator<QString, FrameData *> it(frames);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
if (it.value()) {
|
|
|
|
// we remove all references from this widget to the frame, and delete it if we're the
|
|
|
|
// last user
|
|
|
|
if (it.value()->removeRefs(q)) {
|
|
|
|
const QString key = cacheId(it.value(), it.key());
|
|
|
|
#ifdef DEBUG_FRAMESVG_CACHE
|
|
|
|
kDebug() << "2. Removing it" << key << it.value() << it.value()->refcount() << s_sharedFrames.contains(key);
|
|
|
|
#endif
|
|
|
|
s_sharedFrames.remove(key);
|
|
|
|
delete it.value();
|
|
|
|
}
|
|
|
|
#ifdef DEBUG_FRAMESVG_CACHE
|
|
|
|
else {
|
|
|
|
kDebug() << "still shared:" << cacheId(it.value(), it.key()) << it.value() << it.value()->refcount() << it.value()->isUsed();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
kDebug() << "lost our value for" << it.key();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_FRAMESVG_CACHE
|
|
|
|
QHashIterator<QString, FrameData *> it2(s_sharedFrames);
|
|
|
|
int shares = 0;
|
|
|
|
while (it2.hasNext()) {
|
|
|
|
it2.next();
|
|
|
|
const int rc = it2.value()->refcount();
|
|
|
|
if (rc == 0) {
|
|
|
|
kDebug() << " LOST!" << it2.key() << rc << it2.value();// << it2.value()->references;
|
|
|
|
} else {
|
|
|
|
kDebug() << " " << it2.key() << rc << it2.value();
|
|
|
|
foreach (FrameSvg *data, it2.value()->references.keys()) {
|
|
|
|
kDebug( )<< " " << (void*)data << it2.value()->references[data];
|
|
|
|
}
|
|
|
|
shares += rc - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
kDebug() << "#####################################" << s_sharedFrames.count() << ", pixmaps saved:" << shares;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
frames.clear();
|
|
|
|
}
|
|
|
|
|
2010-03-05 23:37:44 +01:00
|
|
|
QPixmap FrameSvgPrivate::alphaMask()
|
2009-10-10 23:34:51 +02:00
|
|
|
{
|
|
|
|
FrameData *frame = frames[prefix];
|
|
|
|
QString maskPrefix;
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (q->hasElement("mask-" % prefix % "center")) {
|
2009-10-10 23:34:51 +02:00
|
|
|
maskPrefix = "mask-";
|
|
|
|
}
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (maskPrefix.isNull()) {
|
|
|
|
if (frame->cachedBackground.isNull()) {
|
|
|
|
generateBackground(frame);
|
|
|
|
if (frame->cachedBackground.isNull()) {
|
|
|
|
return QPixmap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return frame->cachedBackground;
|
|
|
|
} else {
|
2009-10-10 23:34:51 +02:00
|
|
|
QString oldPrefix = prefix;
|
|
|
|
|
|
|
|
// We are setting the prefix only temporary to generate
|
|
|
|
// the needed mask image
|
2010-09-27 19:19:06 +02:00
|
|
|
prefix = maskPrefix % oldPrefix;
|
2009-10-10 23:34:51 +02:00
|
|
|
|
|
|
|
if (!frames.contains(prefix)) {
|
2010-09-27 19:19:06 +02:00
|
|
|
const QString key = cacheId(frame, prefix);
|
|
|
|
// see if we can find a suitable candidate in the shared frames
|
|
|
|
// if successful, ref and insert, otherwise create a new one
|
|
|
|
// and insert that into both the shared frames and our frames.
|
|
|
|
FrameData *maskFrame = s_sharedFrames.value(key);
|
2010-10-05 21:26:00 +02:00
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (maskFrame) {
|
|
|
|
maskFrame->ref(q);
|
|
|
|
} else {
|
|
|
|
maskFrame = new FrameData(*frame, q);
|
|
|
|
s_sharedFrames.insert(key, maskFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
frames.insert(prefix, maskFrame);
|
2009-10-10 23:34:51 +02:00
|
|
|
updateSizes();
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameData *maskFrame = frames[prefix];
|
|
|
|
if (maskFrame->cachedBackground.isNull() || maskFrame->frameSize != frameSize(frame)) {
|
2010-10-05 21:26:00 +02:00
|
|
|
const QString oldKey = cacheId(maskFrame, prefix);
|
2009-10-10 23:34:51 +02:00
|
|
|
maskFrame->frameSize = frameSize(frame).toSize();
|
2010-10-05 21:26:00 +02:00
|
|
|
const QString newKey = cacheId(maskFrame, prefix);
|
|
|
|
if (s_sharedFrames.contains(oldKey)) {
|
|
|
|
s_sharedFrames.remove(oldKey);
|
|
|
|
s_sharedFrames.insert(newKey, maskFrame);
|
|
|
|
}
|
|
|
|
|
2009-10-10 23:34:51 +02:00
|
|
|
maskFrame->cachedBackground = QPixmap();
|
|
|
|
|
|
|
|
generateBackground(maskFrame);
|
|
|
|
if (maskFrame->cachedBackground.isNull()) {
|
|
|
|
return QPixmap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
prefix = oldPrefix;
|
|
|
|
return maskFrame->cachedBackground;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void FrameSvgPrivate::generateBackground(FrameData *frame)
|
|
|
|
{
|
|
|
|
if (!frame->cachedBackground.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-28 23:54:00 +02:00
|
|
|
const QString id = cacheId(frame, prefix);
|
2009-08-04 23:19:20 +02:00
|
|
|
|
|
|
|
Theme *theme = Theme::defaultTheme();
|
2009-09-28 23:54:00 +02:00
|
|
|
bool frameCached = !frame->cachedBackground.isNull();
|
|
|
|
bool overlayCached = false;
|
2010-09-27 19:19:06 +02:00
|
|
|
const bool overlayAvailable = !prefix.startsWith("mask-") && q->hasElement(prefix % "overlay");
|
2009-09-28 23:54:00 +02:00
|
|
|
QPixmap overlay;
|
2009-05-13 18:37:13 +02:00
|
|
|
if (q->isUsingRenderingCache()) {
|
2009-09-28 23:54:00 +02:00
|
|
|
frameCached = theme->findInCache(id, frame->cachedBackground) && !frame->cachedBackground.isNull();
|
|
|
|
|
|
|
|
if (overlayAvailable) {
|
2010-09-27 19:19:06 +02:00
|
|
|
overlayCached = theme->findInCache("overlay_" % id, overlay) && !overlay.isNull();
|
2009-05-13 18:37:13 +02:00
|
|
|
}
|
2009-05-01 18:28:10 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-09-28 23:54:00 +02:00
|
|
|
if (!frameCached) {
|
|
|
|
generateFrameBackground(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Overlays
|
|
|
|
QSize overlaySize;
|
2009-12-13 21:13:55 +01:00
|
|
|
QPoint actualOverlayPos = QPoint(0, 0);
|
2009-09-28 23:54:00 +02:00
|
|
|
if (overlayAvailable && !overlayCached) {
|
|
|
|
QPoint pos = QPoint(0, 0);
|
2010-09-27 19:19:06 +02:00
|
|
|
overlaySize = q->elementSize(prefix % "overlay");
|
2009-09-28 23:54:00 +02:00
|
|
|
|
|
|
|
//Random pos, stretched and tiled are mutually exclusive
|
2010-09-27 19:19:06 +02:00
|
|
|
if (q->hasElement(prefix % "hint-overlay-random-pos")) {
|
2009-12-13 21:13:55 +01:00
|
|
|
actualOverlayPos = overlayPos;
|
2010-09-27 19:19:06 +02:00
|
|
|
} else if (q->hasElement(prefix % "hint-overlay-pos-right")) {
|
2009-12-13 21:13:55 +01:00
|
|
|
actualOverlayPos.setX(frame->frameSize.width() - overlaySize.width());
|
2010-09-27 19:19:06 +02:00
|
|
|
} else if (q->hasElement(prefix % "hint-overlay-pos-bottom")) {
|
2009-12-13 21:13:55 +01:00
|
|
|
actualOverlayPos.setY(frame->frameSize.height() - overlaySize.height());
|
2009-09-28 23:54:00 +02:00
|
|
|
//Stretched or Tiled?
|
2010-09-27 19:19:06 +02:00
|
|
|
} else if (q->hasElement(prefix % "hint-overlay-stretch")) {
|
2009-09-28 23:54:00 +02:00
|
|
|
overlaySize = frameSize(frame).toSize();
|
|
|
|
} else {
|
2010-09-27 19:19:06 +02:00
|
|
|
if (q->hasElement(prefix % "hint-overlay-tile-horizontal")) {
|
2009-09-28 23:54:00 +02:00
|
|
|
overlaySize.setWidth(frameSize(frame).width());
|
|
|
|
}
|
2010-09-27 19:19:06 +02:00
|
|
|
if (q->hasElement(prefix % "hint-overlay-tile-vertical")) {
|
2009-09-28 23:54:00 +02:00
|
|
|
overlaySize.setHeight(frameSize(frame).height());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-05 23:37:44 +01:00
|
|
|
overlay = alphaMask();
|
2009-09-28 23:54:00 +02:00
|
|
|
QPainter overlayPainter(&overlay);
|
|
|
|
overlayPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
|
|
|
//Tiling?
|
2010-09-27 19:19:06 +02:00
|
|
|
if (q->hasElement(prefix % "hint-overlay-tile-horizontal") ||
|
|
|
|
q->hasElement(prefix % "hint-overlay-tile-vertical")) {
|
2009-09-28 23:54:00 +02:00
|
|
|
|
|
|
|
QSize s = q->size();
|
2010-09-27 19:19:06 +02:00
|
|
|
q->resize(q->elementSize(prefix % "overlay"));
|
2009-09-28 23:54:00 +02:00
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
overlayPainter.drawTiledPixmap(QRect(QPoint(0,0), overlaySize), q->pixmap(prefix % "overlay"));
|
2009-09-28 23:54:00 +02:00
|
|
|
q->resize(s);
|
|
|
|
} else {
|
2010-09-27 19:19:06 +02:00
|
|
|
q->paint(&overlayPainter, QRect(actualOverlayPos, overlaySize), prefix % "overlay");
|
2009-09-28 23:54:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
overlayPainter.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!frameCached) {
|
|
|
|
cacheFrame(prefix, frame->cachedBackground, overlayCached ? overlay : QPixmap());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!overlay.isNull()) {
|
|
|
|
QPainter p(&frame->cachedBackground);
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
2009-12-13 21:13:55 +01:00
|
|
|
p.drawPixmap(actualOverlayPos, overlay, QRect(actualOverlayPos, overlaySize));
|
2009-09-28 23:54:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvgPrivate::generateFrameBackground(FrameData *frame)
|
|
|
|
{
|
2008-11-04 00:08:39 +01:00
|
|
|
//kDebug() << "generating background";
|
2009-09-28 23:54:00 +02:00
|
|
|
const QSizeF size = frameSize(frame);
|
2010-09-27 19:19:06 +02:00
|
|
|
const int topWidth = q->elementSize(prefix % "top").width();
|
|
|
|
const int leftHeight = q->elementSize(prefix % "left").height();
|
2008-11-04 00:08:39 +01:00
|
|
|
const int topOffset = 0;
|
|
|
|
const int leftOffset = 0;
|
|
|
|
|
|
|
|
|
2009-06-10 19:11:02 +02:00
|
|
|
if (!size.isValid()) {
|
|
|
|
kWarning() << "Invalid frame size" << size;
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
2009-12-22 18:28:22 +01:00
|
|
|
if (size.width() >= MAX_FRAME_SIZE || size.height() >= MAX_FRAME_SIZE) {
|
|
|
|
kWarning() << "Not generating frame background for a size whose width or height is more than" << MAX_FRAME_SIZE << size;
|
|
|
|
return;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-06-10 19:11:02 +02:00
|
|
|
const int contentWidth = size.width() - frame->leftWidth - frame->rightWidth;
|
|
|
|
const int contentHeight = size.height() - frame->topHeight - frame->bottomHeight;
|
2008-11-04 00:08:39 +01:00
|
|
|
int contentTop = 0;
|
|
|
|
int contentLeft = 0;
|
|
|
|
int rightOffset = contentWidth;
|
|
|
|
int bottomOffset = contentHeight;
|
|
|
|
|
|
|
|
frame->cachedBackground = QPixmap(frame->leftWidth + contentWidth + frame->rightWidth,
|
|
|
|
frame->topHeight + contentHeight + frame->bottomHeight);
|
|
|
|
frame->cachedBackground.fill(Qt::transparent);
|
|
|
|
QPainter p(&frame->cachedBackground);
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
p.setRenderHint(QPainter::SmoothPixmapTransform);
|
|
|
|
|
|
|
|
//CENTER
|
|
|
|
if (frame->tileCenter) {
|
|
|
|
if (contentHeight > 0 && contentWidth > 0) {
|
2010-09-27 19:19:06 +02:00
|
|
|
const int centerTileHeight = q->elementSize(prefix % "center").height();
|
|
|
|
const int centerTileWidth = q->elementSize(prefix % "center").width();
|
2008-11-04 00:08:39 +01:00
|
|
|
QPixmap center(centerTileWidth, centerTileHeight);
|
|
|
|
center.fill(Qt::transparent);
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter centerPainter(¢er);
|
|
|
|
centerPainter.setCompositionMode(QPainter::CompositionMode_Source);
|
2010-09-27 19:19:06 +02:00
|
|
|
q->paint(¢erPainter, QRect(QPoint(0, 0), q->elementSize(prefix % "center")), prefix % "center");
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-05-06 16:16:03 +02:00
|
|
|
if (frame->composeOverBorder) {
|
|
|
|
p.drawTiledPixmap(QRect(QPoint(0, 0), size.toSize()), center);
|
|
|
|
} else {
|
|
|
|
p.drawTiledPixmap(QRect(frame->leftWidth, frame->topHeight,
|
|
|
|
contentWidth, contentHeight), center);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (contentHeight > 0 && contentWidth > 0) {
|
2010-05-06 16:16:03 +02:00
|
|
|
if (frame->composeOverBorder) {
|
|
|
|
q->paint(&p, QRect(QPoint(0, 0), size.toSize()),
|
2010-09-27 19:19:06 +02:00
|
|
|
prefix % "center");
|
2010-05-06 16:16:03 +02:00
|
|
|
} else {
|
|
|
|
q->paint(&p, QRect(frame->leftWidth, frame->topHeight,
|
|
|
|
contentWidth, contentHeight),
|
2010-09-27 19:19:06 +02:00
|
|
|
prefix % "center");
|
2010-05-06 16:16:03 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-06 16:16:03 +02:00
|
|
|
if (frame->composeOverBorder) {
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
|
|
|
p.drawPixmap(QRect(QPoint(0, 0), size.toSize()), alphaMask());
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
|
|
|
}
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (frame->enabledBorders & FrameSvg::LeftBorder && q->hasElement(prefix % "left")) {
|
2009-03-11 21:11:31 +01:00
|
|
|
rightOffset += frame->leftWidth;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
// Corners
|
2010-09-27 19:19:06 +02:00
|
|
|
if (frame->enabledBorders & FrameSvg::TopBorder && q->hasElement(prefix % "top")) {
|
2008-11-04 00:08:39 +01:00
|
|
|
contentTop = frame->topHeight;
|
|
|
|
bottomOffset += frame->topHeight;
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (q->hasElement(prefix % "topleft") && frame->enabledBorders & FrameSvg::LeftBorder) {
|
|
|
|
q->paint(&p, QRect(leftOffset, topOffset, frame->leftWidth, frame->topHeight), prefix % "topleft");
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
contentLeft = frame->leftWidth;
|
|
|
|
}
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (q->hasElement(prefix % "topright") && frame->enabledBorders & FrameSvg::RightBorder) {
|
|
|
|
q->paint(&p, QRect(rightOffset, topOffset, frame->rightWidth, frame->topHeight), prefix % "topright");
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (frame->enabledBorders & FrameSvg::BottomBorder && q->hasElement(prefix % "bottom")) {
|
|
|
|
if (q->hasElement(prefix % "bottomleft") && frame->enabledBorders & FrameSvg::LeftBorder) {
|
|
|
|
q->paint(&p, QRect(leftOffset, bottomOffset, frame->leftWidth, frame->bottomHeight), prefix % "bottomleft");
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
contentLeft = frame->leftWidth;
|
|
|
|
}
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (frame->enabledBorders & FrameSvg::RightBorder && q->hasElement(prefix % "bottomright")) {
|
|
|
|
q->paint(&p, QRect(rightOffset, bottomOffset, frame->rightWidth, frame->bottomHeight), prefix % "bottomright");
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sides
|
|
|
|
if (frame->stretchBorders) {
|
|
|
|
if (frame->enabledBorders & FrameSvg::LeftBorder || frame->enabledBorders & FrameSvg::RightBorder) {
|
2010-09-27 19:19:06 +02:00
|
|
|
if (q->hasElement(prefix % "left") &&
|
2008-11-04 00:08:39 +01:00
|
|
|
frame->enabledBorders & FrameSvg::LeftBorder) {
|
2010-09-27 19:19:06 +02:00
|
|
|
q->paint(&p, QRect(leftOffset, contentTop, frame->leftWidth, contentHeight), prefix % "left");
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (q->hasElement(prefix % "right") &&
|
2008-11-04 00:08:39 +01:00
|
|
|
frame->enabledBorders & FrameSvg::RightBorder) {
|
2010-09-27 19:19:06 +02:00
|
|
|
q->paint(&p, QRect(rightOffset, contentTop, frame->rightWidth, contentHeight), prefix % "right");
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-08 22:31:13 +01:00
|
|
|
if (frame->enabledBorders & FrameSvg::TopBorder || frame->enabledBorders & FrameSvg::BottomBorder) {
|
2010-09-27 19:19:06 +02:00
|
|
|
if (frame->enabledBorders & FrameSvg::TopBorder && q->hasElement(prefix % "top")) {
|
|
|
|
q->paint(&p, QRect(contentLeft, topOffset, contentWidth, frame->topHeight), prefix % "top");
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (frame->enabledBorders & FrameSvg::BottomBorder && q->hasElement(prefix % "bottom")) {
|
|
|
|
q->paint(&p, QRect(contentLeft, bottomOffset, contentWidth, frame->bottomHeight), prefix % "bottom");
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2010-09-27 19:19:06 +02:00
|
|
|
if (frame->enabledBorders & FrameSvg::LeftBorder && q->hasElement(prefix % "left")
|
2009-01-11 04:48:29 +01:00
|
|
|
&& leftHeight > 0 && frame->leftWidth > 0) {
|
2008-11-04 00:08:39 +01:00
|
|
|
QPixmap left(frame->leftWidth, leftHeight);
|
|
|
|
left.fill(Qt::transparent);
|
|
|
|
|
|
|
|
QPainter sidePainter(&left);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
2010-09-27 19:19:06 +02:00
|
|
|
q->paint(&sidePainter, QRect(QPoint(0, 0), left.size()), prefix % "left");
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
p.drawTiledPixmap(QRect(leftOffset, contentTop, frame->leftWidth, contentHeight), left);
|
|
|
|
}
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (frame->enabledBorders & FrameSvg::RightBorder && q->hasElement(prefix % "right") &&
|
2009-01-11 04:48:29 +01:00
|
|
|
leftHeight > 0 && frame->rightWidth > 0) {
|
2008-11-04 00:08:39 +01:00
|
|
|
QPixmap right(frame->rightWidth, leftHeight);
|
|
|
|
right.fill(Qt::transparent);
|
|
|
|
|
|
|
|
QPainter sidePainter(&right);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
2010-09-27 19:19:06 +02:00
|
|
|
q->paint(&sidePainter, QRect(QPoint(0, 0), right.size()), prefix % "right");
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
p.drawTiledPixmap(QRect(rightOffset, contentTop, frame->rightWidth, contentHeight), right);
|
|
|
|
}
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (frame->enabledBorders & FrameSvg::TopBorder && q->hasElement(prefix % "top")
|
2009-01-11 04:48:29 +01:00
|
|
|
&& topWidth > 0 && frame->topHeight > 0) {
|
2008-11-04 00:08:39 +01:00
|
|
|
QPixmap top(topWidth, frame->topHeight);
|
|
|
|
top.fill(Qt::transparent);
|
|
|
|
|
|
|
|
QPainter sidePainter(&top);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
2010-09-27 19:19:06 +02:00
|
|
|
q->paint(&sidePainter, QRect(QPoint(0, 0), top.size()), prefix % "top");
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
p.drawTiledPixmap(QRect(contentLeft, topOffset, contentWidth, frame->topHeight), top);
|
|
|
|
}
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (frame->enabledBorders & FrameSvg::BottomBorder && q->hasElement(prefix % "bottom")
|
2009-01-11 04:48:29 +01:00
|
|
|
&& topWidth > 0 && frame->bottomHeight > 0) {
|
2008-11-04 00:08:39 +01:00
|
|
|
QPixmap bottom(topWidth, frame->bottomHeight);
|
|
|
|
bottom.fill(Qt::transparent);
|
|
|
|
|
|
|
|
QPainter sidePainter(&bottom);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
2010-09-27 19:19:06 +02:00
|
|
|
q->paint(&sidePainter, QRect(QPoint(0, 0), bottom.size()), prefix % "bottom");
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
p.drawTiledPixmap(QRect(contentLeft, bottomOffset, contentWidth, frame->bottomHeight), bottom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-29 20:24:40 +01:00
|
|
|
}
|
|
|
|
|
2009-09-28 23:54:00 +02:00
|
|
|
QString FrameSvgPrivate::cacheId(FrameData *frame, const QString &prefixToSave) const
|
|
|
|
{
|
2010-09-27 19:19:06 +02:00
|
|
|
const QSize size = frameSize(frame).toSize();
|
|
|
|
const QChar s('_');
|
2010-10-09 20:07:17 +02:00
|
|
|
return QString::number(frame->enabledBorders) % s % QString::number(size.width()) % s % QString::number(size.height()) % s % prefixToSave % s % q->imagePath();
|
2009-09-28 23:54:00 +02:00
|
|
|
}
|
2009-01-13 22:46:07 +01:00
|
|
|
|
2009-09-28 23:02:24 +02:00
|
|
|
void FrameSvgPrivate::cacheFrame(const QString &prefixToSave, const QPixmap &background, const QPixmap &overlay)
|
2008-11-29 20:24:40 +01:00
|
|
|
{
|
2009-05-13 18:37:13 +02:00
|
|
|
if (!q->isUsingRenderingCache()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-31 07:38:42 +02:00
|
|
|
//insert background
|
|
|
|
FrameData *frame = frames.value(prefixToSave);
|
|
|
|
|
|
|
|
if (!frame) {
|
|
|
|
return;
|
|
|
|
}
|
2008-11-29 20:24:40 +01:00
|
|
|
|
2009-09-28 23:54:00 +02:00
|
|
|
const QString id = cacheId(frame, prefixToSave);
|
2008-11-29 20:24:40 +01:00
|
|
|
|
2009-05-31 07:38:42 +02:00
|
|
|
//kDebug()<<"Saving to cache frame"<<id;
|
2009-01-13 22:46:07 +01:00
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
Theme::defaultTheme()->insertIntoCache(id, background, QString::number((qint64)q, 16) % prefixToSave);
|
2009-01-13 22:46:07 +01:00
|
|
|
|
2009-09-28 23:02:24 +02:00
|
|
|
if (!overlay.isNull()) {
|
|
|
|
//insert overlay
|
2010-09-27 19:19:06 +02:00
|
|
|
Theme::defaultTheme()->insertIntoCache("overlay_" % id, overlay, QString::number((qint64)q, 16) % prefixToSave % "overlay");
|
2009-09-28 23:02:24 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-09-28 23:54:00 +02:00
|
|
|
void FrameSvgPrivate::updateSizes() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
//kDebug() << "!!!!!!!!!!!!!!!!!!!!!! updating sizes" << prefix;
|
|
|
|
FrameData *frame = frames[prefix];
|
|
|
|
Q_ASSERT(frame);
|
|
|
|
|
2009-01-04 20:07:46 +01:00
|
|
|
QSize s = q->size();
|
|
|
|
q->resize();
|
2008-11-04 00:08:39 +01:00
|
|
|
frame->cachedBackground = QPixmap();
|
|
|
|
|
|
|
|
if (frame->enabledBorders & FrameSvg::TopBorder) {
|
2010-09-27 19:19:06 +02:00
|
|
|
frame->topHeight = q->elementSize(prefix % "top").height();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (q->hasElement(prefix % "hint-top-margin")) {
|
|
|
|
frame->topMargin = q->elementSize(prefix % "hint-top-margin").height();
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
|
|
|
frame->topMargin = frame->topHeight;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
frame->topMargin = frame->topHeight = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame->enabledBorders & FrameSvg::LeftBorder) {
|
2010-09-27 19:19:06 +02:00
|
|
|
frame->leftWidth = q->elementSize(prefix % "left").width();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (q->hasElement(prefix % "hint-left-margin")) {
|
|
|
|
frame->leftMargin = q->elementSize(prefix % "hint-left-margin").width();
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
|
|
|
frame->leftMargin = frame->leftWidth;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
frame->leftMargin = frame->leftWidth = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame->enabledBorders & FrameSvg::RightBorder) {
|
2010-09-27 19:19:06 +02:00
|
|
|
frame->rightWidth = q->elementSize(prefix % "right").width();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (q->hasElement(prefix % "hint-right-margin")) {
|
|
|
|
frame->rightMargin = q->elementSize(prefix % "hint-right-margin").width();
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
|
|
|
frame->rightMargin = frame->rightWidth;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
frame->rightMargin = frame->rightWidth = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame->enabledBorders & FrameSvg::BottomBorder) {
|
2010-09-27 19:19:06 +02:00
|
|
|
frame->bottomHeight = q->elementSize(prefix % "bottom").height();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
if (q->hasElement(prefix % "hint-bottom-margin")) {
|
|
|
|
frame->bottomMargin = q->elementSize(prefix % "hint-bottom-margin").height();
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
|
|
|
frame->bottomMargin = frame->bottomHeight;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
frame->bottomMargin = frame->bottomHeight = 0;
|
|
|
|
}
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
frame->composeOverBorder = (q->hasElement(prefix % "hint-compose-over-border") &&
|
|
|
|
q->hasElement(prefix % "mask-center"));
|
2010-05-06 16:16:03 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
//since it's rectangular, topWidth and bottomWidth must be the same
|
2010-05-06 16:16:03 +02:00
|
|
|
//the ones that don't have a prefix is for retrocompatibility
|
2008-11-04 00:08:39 +01:00
|
|
|
frame->tileCenter = q->hasElement("hint-tile-center");
|
|
|
|
frame->noBorderPadding = q->hasElement("hint-no-border-padding");
|
|
|
|
frame->stretchBorders = q->hasElement("hint-stretch-borders");
|
2009-01-04 20:07:46 +01:00
|
|
|
q->resize(s);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvgPrivate::updateNeeded()
|
|
|
|
{
|
|
|
|
q->clearCache();
|
|
|
|
updateSizes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FrameSvgPrivate::updateAndSignalSizes()
|
|
|
|
{
|
|
|
|
updateSizes();
|
|
|
|
emit q->repaintNeeded();
|
|
|
|
}
|
|
|
|
|
2009-09-28 23:54:00 +02:00
|
|
|
QSizeF FrameSvgPrivate::frameSize(FrameData *frame) const
|
2009-06-10 19:11:02 +02:00
|
|
|
{
|
|
|
|
if (!frame->frameSize.isValid()) {
|
|
|
|
updateSizes();
|
|
|
|
frame->frameSize = q->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
return frame->frameSize;
|
|
|
|
}
|
|
|
|
|
2010-09-27 19:19:06 +02:00
|
|
|
void FrameData::ref(FrameSvg *svg)
|
|
|
|
{
|
|
|
|
references[svg] = references[svg] + 1;
|
|
|
|
//kDebug() << this << svg << references[svg];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FrameData::deref(FrameSvg *svg)
|
|
|
|
{
|
|
|
|
references[svg] = references[svg] - 1;
|
|
|
|
//kDebug() << this << svg << references[svg];
|
|
|
|
if (references[svg] < 1) {
|
|
|
|
references.remove(svg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return references.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FrameData::removeRefs(FrameSvg *svg)
|
|
|
|
{
|
|
|
|
references.remove(svg);
|
|
|
|
return references.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FrameData::isUsed() const
|
|
|
|
{
|
|
|
|
return !references.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
int FrameData::refcount() const
|
|
|
|
{
|
|
|
|
return references.count();
|
|
|
|
}
|
2009-06-10 19:11:02 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#include "framesvg.moc"
|