2008-02-06 18:16:45 +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.
|
|
|
|
*/
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
#include "panelsvg.h"
|
2008-02-06 18:16:45 +01:00
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QSize>
|
2008-03-05 22:03:27 +01:00
|
|
|
#include <QBitmap>
|
2008-02-06 18:16:45 +01:00
|
|
|
|
|
|
|
#include <KDebug>
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
class PanelSvg::Private
|
2008-02-06 19:49:14 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Private()
|
2008-02-06 20:24:48 +01:00
|
|
|
: bFlags(DrawAllBorders|ContentAtOrigin),
|
2008-02-15 10:04:12 +01:00
|
|
|
cachedBackground(0), pos(0,0)
|
2008-02-06 19:49:14 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~Private()
|
|
|
|
{
|
|
|
|
delete cachedBackground;
|
|
|
|
}
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
void generateBackground();
|
|
|
|
|
2008-02-06 19:49:14 +01:00
|
|
|
BorderFlags bFlags;
|
|
|
|
QPixmap *cachedBackground;
|
|
|
|
Svg *background;
|
|
|
|
QSizeF panelSize;
|
2008-02-15 10:04:12 +01:00
|
|
|
QPointF pos;
|
2008-02-06 19:49:14 +01:00
|
|
|
|
2008-03-23 18:50:49 +01:00
|
|
|
Location location;
|
|
|
|
QString prefix;
|
|
|
|
|
2008-02-06 19:49:14 +01:00
|
|
|
//measures
|
|
|
|
int topHeight;
|
|
|
|
int leftWidth;
|
|
|
|
int rightWidth;
|
|
|
|
int bottomHeight;
|
|
|
|
|
|
|
|
//size of the svg where the size of the "center"
|
|
|
|
//element is contentWidth x contentHeight
|
|
|
|
bool noBorderPadding : 1;
|
|
|
|
bool stretchBorders : 1;
|
2008-03-09 01:15:32 +01:00
|
|
|
bool tileCenter : 1;
|
2008-02-06 19:49:14 +01:00
|
|
|
};
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
PanelSvg::PanelSvg(const QString& imagePath, QObject* parent)
|
2008-02-06 18:16:45 +01:00
|
|
|
: QObject(parent),
|
2008-02-06 19:49:14 +01:00
|
|
|
d(new Private)
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-02-06 19:49:14 +01:00
|
|
|
d->background = new Svg(imagePath, this);
|
|
|
|
connect(d->background, SIGNAL(repaintNeeded()), this, SLOT(updateSizes()));
|
2008-02-06 18:16:45 +01:00
|
|
|
|
|
|
|
updateSizes();
|
2008-02-06 19:49:14 +01:00
|
|
|
d->panelSize = d->background->size();
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
PanelSvg::~PanelSvg()
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-02-06 19:49:14 +01:00
|
|
|
delete d;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
void PanelSvg::setFile(const QString& imagePath)
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-02-06 19:49:14 +01:00
|
|
|
if (imagePath == d->background->file()) {
|
2008-02-06 18:16:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-06 19:49:14 +01:00
|
|
|
d->background->setFile(imagePath);
|
2008-03-23 18:50:49 +01:00
|
|
|
setPrefix(prefix());
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
QString PanelSvg::file() const
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-02-06 19:49:14 +01:00
|
|
|
return d->background->file();
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
void PanelSvg::setBorderFlags(const BorderFlags flags)
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-02-06 19:49:14 +01:00
|
|
|
if (flags == d->bFlags) {
|
|
|
|
return;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-02-06 19:49:14 +01:00
|
|
|
d->bFlags = flags;
|
2008-02-06 18:16:45 +01:00
|
|
|
updateSizes();
|
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
PanelSvg::BorderFlags PanelSvg::borderFlags() const
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-02-06 19:49:14 +01:00
|
|
|
return d->bFlags;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
void PanelSvg::setPos(const QPointF& pos)
|
2008-02-15 10:04:12 +01:00
|
|
|
{
|
|
|
|
d->pos = pos;
|
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
QPointF PanelSvg::pos() const
|
2008-02-15 10:04:12 +01:00
|
|
|
{
|
|
|
|
return d->pos;
|
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
void PanelSvg::setLocation(Plasma::Location location)
|
2008-03-23 18:50:49 +01:00
|
|
|
{
|
|
|
|
switch (location) {
|
|
|
|
case TopEdge:
|
|
|
|
setPrefix("north");
|
|
|
|
break;
|
|
|
|
case BottomEdge:
|
|
|
|
setPrefix("south");
|
|
|
|
break;
|
|
|
|
case LeftEdge:
|
|
|
|
setPrefix("west");
|
|
|
|
break;
|
|
|
|
case RightEdge:
|
|
|
|
setPrefix("east");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
setPrefix(QString());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
d->location = location;
|
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
Plasma::Location PanelSvg::location() const
|
2008-03-23 18:50:49 +01:00
|
|
|
{
|
|
|
|
return d->location;
|
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
void PanelSvg::setPrefix(const QString & prefix)
|
2008-03-23 18:50:49 +01:00
|
|
|
{
|
2008-04-16 16:31:43 +02:00
|
|
|
if (!d->background->hasElement(prefix + "-center")) {
|
2008-03-23 18:50:49 +01:00
|
|
|
d->prefix.clear();
|
|
|
|
} else {
|
|
|
|
d->prefix = prefix;
|
|
|
|
if (!d->prefix.isEmpty()) {
|
|
|
|
d->prefix += '-';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
d->location = Floating;
|
|
|
|
|
|
|
|
if (d->cachedBackground) {
|
|
|
|
updateSizes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
QString PanelSvg::prefix()
|
2008-03-23 18:50:49 +01:00
|
|
|
{
|
|
|
|
if (d->prefix.isEmpty()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
return d->prefix.left(d->prefix.size() - 1);
|
|
|
|
}
|
2008-02-15 10:04:12 +01:00
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
void PanelSvg::resize(const QSizeF& size)
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-02-06 19:49:14 +01:00
|
|
|
if (!size.isValid() || size.width() < 1 || size.height() < 1 || size == d->panelSize) {
|
2008-02-06 18:16:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-06 19:49:14 +01:00
|
|
|
d->panelSize = size;
|
2008-02-06 18:16:45 +01:00
|
|
|
updateSizes();
|
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
qreal PanelSvg::marginSize(const Plasma::MarginEdge edge) const
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-02-06 19:49:14 +01:00
|
|
|
if (d->noBorderPadding) {
|
2008-02-06 18:16:45 +01:00
|
|
|
return .0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (edge) {
|
2008-02-06 20:12:21 +01:00
|
|
|
case Plasma::TopMargin:
|
2008-02-06 19:49:14 +01:00
|
|
|
return d->topHeight;
|
2008-02-06 18:16:45 +01:00
|
|
|
break;
|
|
|
|
|
2008-02-06 20:12:21 +01:00
|
|
|
case Plasma::LeftMargin:
|
2008-02-06 19:49:14 +01:00
|
|
|
return d->leftWidth;
|
2008-02-06 18:16:45 +01:00
|
|
|
break;
|
|
|
|
|
2008-02-06 20:12:21 +01:00
|
|
|
case Plasma::RightMargin:
|
2008-02-06 19:49:14 +01:00
|
|
|
return d->rightWidth;
|
2008-02-06 18:16:45 +01:00
|
|
|
break;
|
|
|
|
|
2008-02-06 20:12:21 +01:00
|
|
|
//Plasma::BottomMargin
|
2008-02-06 18:16:45 +01:00
|
|
|
default:
|
2008-02-06 19:49:14 +01:00
|
|
|
return d->bottomHeight;
|
2008-02-06 18:16:45 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
QBitmap PanelSvg::mask() const
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-02-06 19:49:14 +01:00
|
|
|
if (!d->cachedBackground) {
|
2008-03-05 22:03:27 +01:00
|
|
|
d->generateBackground();
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->cachedBackground->alphaChannel().createMaskFromColor(Qt::black);
|
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
void PanelSvg::Private::generateBackground()
|
2008-03-05 22:03:27 +01:00
|
|
|
{
|
|
|
|
bool origined = bFlags & ContentAtOrigin;
|
2008-03-23 18:50:49 +01:00
|
|
|
const int topWidth = background->elementSize(prefix + "top").width();
|
|
|
|
const int leftHeight = background->elementSize(prefix + "left").height();
|
2008-03-05 22:03:27 +01:00
|
|
|
const int topOffset = origined ? 0 - topHeight : 0;
|
|
|
|
const int leftOffset = origined ? 0 - leftWidth : 0;
|
|
|
|
|
|
|
|
if (!cachedBackground) {
|
|
|
|
const int contentWidth = panelSize.width() - leftWidth - rightWidth;
|
|
|
|
const int contentHeight = panelSize.height() - topHeight - bottomHeight;
|
2008-02-06 21:53:14 +01:00
|
|
|
int contentTop = 0;
|
|
|
|
int contentLeft = 0;
|
|
|
|
int rightOffset = contentWidth;
|
|
|
|
int bottomOffset = contentHeight;
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
delete cachedBackground;
|
|
|
|
cachedBackground = new QPixmap(leftWidth + contentWidth + rightWidth,
|
|
|
|
topHeight + contentHeight + bottomHeight);
|
|
|
|
cachedBackground->fill(Qt::transparent);
|
|
|
|
QPainter p(cachedBackground);
|
2008-02-06 21:53:14 +01:00
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
p.setRenderHint(QPainter::SmoothPixmapTransform);
|
2008-02-06 20:46:36 +01:00
|
|
|
|
2008-02-06 21:53:14 +01:00
|
|
|
if (origined) {
|
2008-03-05 22:03:27 +01:00
|
|
|
p.translate(leftWidth, topHeight);
|
2008-02-06 20:46:36 +01:00
|
|
|
}
|
|
|
|
|
2008-02-06 18:16:45 +01:00
|
|
|
//FIXME: This is a hack to fix a drawing problems with svg files where a thin transparent border is drawn around the svg image.
|
|
|
|
// the transparent border around the svg seems to vary in size depending on the size of the svg and as a result increasing the
|
|
|
|
// svg image by 2 all around didn't resolve the issue. For now it resizes based on the border size.
|
|
|
|
|
|
|
|
|
|
|
|
//CENTER
|
2008-03-23 18:50:49 +01:00
|
|
|
if (tileCenter) {
|
2008-03-09 01:15:32 +01:00
|
|
|
if (contentHeight > 0 && contentWidth > 0) {
|
|
|
|
int centerTileHeight;
|
|
|
|
int centerTileWidth;
|
2008-03-23 18:50:49 +01:00
|
|
|
centerTileHeight = background->elementSize(prefix + "center").height();
|
|
|
|
centerTileWidth = background->elementSize(prefix + "center").width();
|
2008-03-09 01:15:32 +01:00
|
|
|
QPixmap center(centerTileWidth, centerTileHeight);
|
|
|
|
center.fill(Qt::transparent);
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter centerPainter(¢er);
|
|
|
|
centerPainter.setCompositionMode(QPainter::CompositionMode_Source);
|
2008-03-23 18:50:49 +01:00
|
|
|
background->paint(¢erPainter, QPoint(0, 0), prefix + "center");
|
2008-03-09 01:15:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
p.drawTiledPixmap(QRect(contentLeft - leftWidth, contentTop - topHeight,
|
|
|
|
contentWidth + leftWidth*2, contentHeight + topHeight*2), center);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (contentHeight > 0 && contentWidth > 0) {
|
|
|
|
QSizeF scaledSize = QSizeF(panelSize.width() -
|
|
|
|
(leftWidth + rightWidth) +
|
|
|
|
panelSize.width()*(((qreal)(leftWidth + rightWidth)) / panelSize.width()),
|
|
|
|
panelSize.height() -
|
|
|
|
(topHeight + bottomHeight) +
|
|
|
|
panelSize.height()*(((qreal)(topHeight + bottomHeight)) / panelSize.height()));
|
2008-03-23 18:50:49 +01:00
|
|
|
|
2008-03-09 01:15:32 +01:00
|
|
|
background->resize(scaledSize.width(), scaledSize.height());
|
|
|
|
background->paint(&p, QRect(contentLeft - leftWidth, contentTop - topHeight,
|
|
|
|
contentWidth + leftWidth*2, contentHeight + topHeight*2),
|
2008-03-23 18:50:49 +01:00
|
|
|
prefix + "center");
|
2008-03-09 01:15:32 +01:00
|
|
|
background->resize();
|
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-03-09 01:15:32 +01:00
|
|
|
|
2008-02-06 21:53:14 +01:00
|
|
|
// Corners
|
2008-03-05 22:03:27 +01:00
|
|
|
if (bFlags & DrawTopBorder) {
|
2008-02-06 21:53:14 +01:00
|
|
|
if (!origined) {
|
2008-03-05 22:03:27 +01:00
|
|
|
contentTop = topHeight;
|
|
|
|
bottomOffset += topHeight;
|
2008-02-06 21:53:14 +01:00
|
|
|
}
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
if (bFlags & DrawLeftBorder) {
|
2008-03-23 18:50:49 +01:00
|
|
|
background->paint(&p, QRect(leftOffset, topOffset, leftWidth, topHeight), prefix + "topleft");
|
2008-02-06 21:53:14 +01:00
|
|
|
|
|
|
|
if (!origined) {
|
2008-03-05 22:03:27 +01:00
|
|
|
contentLeft = leftWidth;
|
|
|
|
rightOffset = contentWidth + leftWidth;
|
2008-02-06 21:53:14 +01:00
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
if (bFlags & DrawRightBorder) {
|
2008-03-23 18:50:49 +01:00
|
|
|
background->paint(&p, QRect(rightOffset, topOffset, rightWidth, topHeight), prefix + "topright");
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
if (bFlags & DrawBottomBorder) {
|
|
|
|
if (bFlags & DrawLeftBorder) {
|
2008-03-23 18:50:49 +01:00
|
|
|
background->paint(&p, QRect(leftOffset, bottomOffset, leftWidth, bottomHeight), prefix + "bottomleft");
|
2008-02-06 21:53:14 +01:00
|
|
|
|
|
|
|
if (!origined) {
|
2008-03-05 22:03:27 +01:00
|
|
|
contentLeft = leftWidth;
|
|
|
|
rightOffset = contentWidth + leftWidth;
|
2008-02-06 21:53:14 +01:00
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
if (bFlags & DrawRightBorder) {
|
2008-03-23 18:50:49 +01:00
|
|
|
background->paint(&p, QRect(rightOffset, bottomOffset, rightWidth, bottomHeight), prefix + "bottomright");
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-06 21:53:14 +01:00
|
|
|
// Sides
|
2008-03-05 22:03:27 +01:00
|
|
|
if (stretchBorders) {
|
|
|
|
if (bFlags & DrawLeftBorder) {
|
2008-03-23 18:50:49 +01:00
|
|
|
background->paint(&p, QRect(leftOffset, contentTop, leftWidth, contentHeight), prefix + "left");
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
if (bFlags & DrawRightBorder) {
|
2008-03-23 18:50:49 +01:00
|
|
|
background->paint(&p, QRect(rightOffset, contentTop, rightWidth, contentHeight), prefix + "right");
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
if (bFlags & DrawTopBorder) {
|
2008-03-23 18:50:49 +01:00
|
|
|
background->paint(&p, QRect(contentLeft, topOffset, contentWidth, topHeight), prefix + "top");
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
if (bFlags & DrawBottomBorder) {
|
2008-03-23 18:50:49 +01:00
|
|
|
background->paint(&p, QRect(contentLeft, bottomOffset, contentWidth, bottomHeight), prefix + "bottom");
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
} else {
|
2008-03-05 22:03:27 +01:00
|
|
|
if (bFlags & DrawLeftBorder) {
|
|
|
|
QPixmap left(leftWidth, leftHeight);
|
2008-02-06 18:16:45 +01:00
|
|
|
left.fill(Qt::transparent);
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter sidePainter(&left);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
2008-03-23 18:50:49 +01:00
|
|
|
background->paint(&sidePainter, QPoint(0, 0), prefix + "left");
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
p.drawTiledPixmap(QRect(leftOffset, contentTop, leftWidth, contentHeight), left);
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
if (bFlags & DrawRightBorder) {
|
|
|
|
QPixmap right(rightWidth, leftHeight);
|
2008-02-06 18:16:45 +01:00
|
|
|
right.fill(Qt::transparent);
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter sidePainter(&right);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
2008-03-23 18:50:49 +01:00
|
|
|
background->paint(&sidePainter, QPoint(0, 0), prefix + "right");
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
p.drawTiledPixmap(QRect(rightOffset, contentTop, rightWidth, contentHeight), right);
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
if (bFlags & DrawTopBorder) {
|
|
|
|
QPixmap top(topWidth, topHeight);
|
2008-02-06 18:16:45 +01:00
|
|
|
top.fill(Qt::transparent);
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter sidePainter(&top);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
2008-03-23 18:50:49 +01:00
|
|
|
background->paint(&sidePainter, QPoint(0, 0), prefix + "top");
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
p.drawTiledPixmap(QRect(contentLeft, topOffset, contentWidth, topHeight), top);
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
if (bFlags & DrawBottomBorder) {
|
|
|
|
QPixmap bottom(topWidth, bottomHeight);
|
2008-02-06 18:16:45 +01:00
|
|
|
bottom.fill(Qt::transparent);
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter sidePainter(&bottom);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
2008-03-23 18:50:49 +01:00
|
|
|
background->paint(&sidePainter, QPoint(0, 0), prefix + "bottom");
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
p.drawTiledPixmap(QRect(contentLeft, bottomOffset, contentWidth, bottomHeight), bottom);
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// re-enable this once Qt's svg rendering is un-buggered
|
|
|
|
//resize(contentWidth, contentHeight);
|
|
|
|
//paint(&p, QRect(contentLeft, contentTop, contentWidth, contentHeight), "center");
|
|
|
|
}
|
2008-03-05 22:03:27 +01:00
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
void PanelSvg::paint(QPainter* painter, const QRectF& rect)
|
2008-03-05 22:03:27 +01:00
|
|
|
{
|
|
|
|
if (!d->cachedBackground) {
|
|
|
|
d->generateBackground();
|
|
|
|
}
|
|
|
|
|
|
|
|
//FIXME: this is redundant with generatebackground for now
|
|
|
|
bool origined = d->bFlags & ContentAtOrigin;
|
2008-03-23 18:50:49 +01:00
|
|
|
const int topWidth = d->background->elementSize(d->prefix + "top").width();
|
|
|
|
const int leftHeight = d->background->elementSize(d->prefix + "left").height();
|
2008-03-05 22:03:27 +01:00
|
|
|
const int topOffset = origined ? 0 - d->topHeight : 0;
|
|
|
|
const int leftOffset = origined ? 0 - d->leftWidth : 0;
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-03-05 22:03:27 +01:00
|
|
|
painter->drawPixmap(rect, *d->cachedBackground, rect.translated(-d->pos.x()-leftOffset,-d->pos.y()-topOffset));
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
void PanelSvg::updateSizes()
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-02-07 05:33:02 +01:00
|
|
|
delete d->cachedBackground;
|
|
|
|
d->cachedBackground = 0;
|
2008-03-23 18:50:49 +01:00
|
|
|
|
2008-02-06 19:49:14 +01:00
|
|
|
d->background->resize();
|
2008-02-06 20:24:48 +01:00
|
|
|
if (d->bFlags & DrawTopBorder) {
|
2008-03-23 18:50:49 +01:00
|
|
|
d->topHeight = d->background->elementSize(d->prefix + "top").height();
|
2008-02-06 18:16:45 +01:00
|
|
|
} else {
|
2008-02-06 19:49:14 +01:00
|
|
|
d->topHeight = 0;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-02-06 20:24:48 +01:00
|
|
|
if (d->bFlags & DrawLeftBorder) {
|
2008-03-23 18:50:49 +01:00
|
|
|
d->leftWidth = d->background->elementSize(d->prefix + "left").width();
|
2008-02-06 18:16:45 +01:00
|
|
|
} else {
|
2008-02-06 19:49:14 +01:00
|
|
|
d->leftWidth = 0;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-02-06 20:24:48 +01:00
|
|
|
if (d->bFlags & DrawRightBorder) {
|
2008-03-23 18:50:49 +01:00
|
|
|
d->rightWidth = d->background->elementSize(d->prefix + "right").width();
|
2008-02-06 18:16:45 +01:00
|
|
|
} else {
|
2008-02-06 19:49:14 +01:00
|
|
|
d->rightWidth = 0;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-02-06 20:24:48 +01:00
|
|
|
if (d->bFlags & DrawBottomBorder) {
|
2008-03-23 18:50:49 +01:00
|
|
|
d->bottomHeight = d->background->elementSize(d->prefix + "bottom").height();
|
2008-02-06 18:16:45 +01:00
|
|
|
} else {
|
2008-02-06 19:49:14 +01:00
|
|
|
d->bottomHeight = 0;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//since it's rectangular, topWidth and bottomWidth must be the same
|
2008-04-16 16:31:43 +02:00
|
|
|
d->tileCenter = d->background->hasElement("hint-tile-center");
|
|
|
|
d->noBorderPadding = d->background->hasElement("hint-no-border-padding");
|
|
|
|
d->stretchBorders = d->background->hasElement("hint-stretch-borders");
|
2008-02-06 21:53:14 +01:00
|
|
|
emit repaintNeeded();
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // Plasma namespace
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
#include "panelsvg.moc"
|