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-21 16:01:46 +02:00
|
|
|
class PanelData
|
2008-02-06 19:49:14 +01:00
|
|
|
{
|
|
|
|
public:
|
2008-04-21 16:01:46 +02:00
|
|
|
PanelData()
|
|
|
|
: enabledBorders(PanelSvg::AllBorders),
|
2008-04-16 22:17:36 +02:00
|
|
|
cachedBackground(0),
|
2008-04-23 15:07:41 +02:00
|
|
|
panelSize(-1,-1),
|
2008-04-16 22:17:36 +02:00
|
|
|
contentAtOrigin(false)
|
2008-02-06 19:49:14 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-21 16:01:46 +02:00
|
|
|
~PanelData()
|
2008-02-06 19:49:14 +01:00
|
|
|
{
|
|
|
|
delete cachedBackground;
|
|
|
|
}
|
|
|
|
|
2008-04-21 16:01:46 +02:00
|
|
|
PanelSvg::EnabledBorders enabledBorders;
|
2008-02-06 19:49:14 +01:00
|
|
|
QPixmap *cachedBackground;
|
|
|
|
QSizeF panelSize;
|
|
|
|
|
|
|
|
//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-04-16 22:17:36 +02:00
|
|
|
bool contentAtOrigin : 1;
|
2008-02-06 19:49:14 +01:00
|
|
|
};
|
|
|
|
|
2008-04-21 16:01:46 +02:00
|
|
|
class PanelSvg::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Private(PanelSvg *psvg)
|
|
|
|
: q(psvg),
|
|
|
|
cacheAll(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~Private()
|
|
|
|
{
|
|
|
|
qDeleteAll(panels);
|
|
|
|
}
|
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
void generateBackground(PanelData *panel);
|
2008-04-21 16:01:46 +02:00
|
|
|
void updateSizes();
|
2008-04-22 22:25:28 +02:00
|
|
|
void updateAndSignalSizes();
|
2008-04-21 16:01:46 +02:00
|
|
|
|
|
|
|
Location location;
|
|
|
|
QString prefix;
|
|
|
|
|
|
|
|
PanelSvg *q;
|
|
|
|
|
|
|
|
bool cacheAll : 1;
|
|
|
|
|
|
|
|
QHash<QString, PanelData*> panels;
|
|
|
|
};
|
|
|
|
|
2008-04-23 15:07:41 +02:00
|
|
|
PanelSvg::PanelSvg(QObject* parent)
|
|
|
|
: Svg(parent),
|
2008-04-16 22:17:36 +02:00
|
|
|
d(new Private(this))
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-04-22 22:25:28 +02:00
|
|
|
connect(this, SIGNAL(repaintNeeded()), this, SLOT(updateSizes()));
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-04-21 16:01:46 +02:00
|
|
|
d->panels.insert(QString(), new PanelData());
|
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-22 22:25:28 +02:00
|
|
|
void PanelSvg::setImagePath(const QString& path)
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-04-22 22:25:28 +02:00
|
|
|
if (path == imagePath()) {
|
2008-02-06 18:16:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-23 15:07:41 +02:00
|
|
|
Svg::setImagePath(path);
|
|
|
|
|
2008-04-21 16:01:46 +02:00
|
|
|
qDeleteAll(d->panels);
|
|
|
|
|
2008-04-23 15:07:41 +02:00
|
|
|
d->panels.insert(QString(), new PanelData());
|
|
|
|
d->panels[QString()]->panelSize = size();
|
2008-04-23 22:38:09 +02:00
|
|
|
d->updateSizes();
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-16 22:17:36 +02:00
|
|
|
void PanelSvg::setEnabledBorders(const EnabledBorders borders)
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-04-21 16:01:46 +02:00
|
|
|
if (borders == d->panels[d->prefix]->enabledBorders) {
|
2008-02-06 19:49:14 +01:00
|
|
|
return;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-21 16:01:46 +02:00
|
|
|
d->panels[d->prefix]->enabledBorders = borders;
|
2008-04-23 18:18:45 +02:00
|
|
|
d->updateAndSignalSizes();
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-16 22:17:36 +02:00
|
|
|
PanelSvg::EnabledBorders PanelSvg::enabledBorders() const
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-04-21 16:01:46 +02:00
|
|
|
return d->panels[d->prefix]->enabledBorders;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-16 22:17:36 +02:00
|
|
|
void PanelSvg::setElementPrefix(Plasma::Location location)
|
2008-03-23 18:50:49 +01:00
|
|
|
{
|
|
|
|
switch (location) {
|
|
|
|
case TopEdge:
|
2008-04-16 22:17:36 +02:00
|
|
|
setElementPrefix("north");
|
2008-03-23 18:50:49 +01:00
|
|
|
break;
|
|
|
|
case BottomEdge:
|
2008-04-16 22:17:36 +02:00
|
|
|
setElementPrefix("south");
|
2008-03-23 18:50:49 +01:00
|
|
|
break;
|
|
|
|
case LeftEdge:
|
2008-04-16 22:17:36 +02:00
|
|
|
setElementPrefix("west");
|
2008-03-23 18:50:49 +01:00
|
|
|
break;
|
|
|
|
case RightEdge:
|
2008-04-16 22:17:36 +02:00
|
|
|
setElementPrefix("east");
|
2008-03-23 18:50:49 +01:00
|
|
|
break;
|
|
|
|
default:
|
2008-04-16 22:17:36 +02:00
|
|
|
setElementPrefix(QString());
|
2008-03-23 18:50:49 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
d->location = location;
|
|
|
|
}
|
|
|
|
|
2008-04-16 22:17:36 +02:00
|
|
|
void PanelSvg::setElementPrefix(const QString & prefix)
|
2008-03-23 18:50:49 +01:00
|
|
|
{
|
2008-04-21 16:01:46 +02:00
|
|
|
const QString oldPrefix(d->prefix);
|
|
|
|
|
2008-04-22 22:25:28 +02:00
|
|
|
if (!hasElement(prefix + "-center")) {
|
2008-03-23 18:50:49 +01:00
|
|
|
d->prefix.clear();
|
|
|
|
} else {
|
|
|
|
d->prefix = prefix;
|
|
|
|
if (!d->prefix.isEmpty()) {
|
|
|
|
d->prefix += '-';
|
|
|
|
}
|
2008-04-21 16:01:46 +02:00
|
|
|
|
2008-03-23 18:50:49 +01:00
|
|
|
}
|
|
|
|
|
2008-04-21 16:01:46 +02:00
|
|
|
if (oldPrefix == d->prefix && d->panels[oldPrefix]) {
|
|
|
|
return;
|
|
|
|
}
|
2008-03-23 18:50:49 +01:00
|
|
|
|
2008-04-21 16:01:46 +02:00
|
|
|
if (!d->cacheAll) {
|
|
|
|
delete d->panels[oldPrefix];
|
|
|
|
d->panels.remove(oldPrefix);
|
2008-03-23 18:50:49 +01:00
|
|
|
}
|
2008-04-21 16:01:46 +02:00
|
|
|
|
|
|
|
if (!d->panels.contains(d->prefix)) {
|
|
|
|
d->panels.insert(d->prefix, new PanelData());
|
|
|
|
}
|
|
|
|
|
|
|
|
d->location = Floating;
|
2008-03-23 18:50:49 +01:00
|
|
|
}
|
|
|
|
|
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-23 22:38:09 +02:00
|
|
|
void PanelSvg::resizePanel(const QSizeF& size)
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-04-21 16:01:46 +02:00
|
|
|
if (!size.isValid() || size.width() < 1 || size.height() < 1 || size == d->panels[d->prefix]->panelSize) {
|
2008-02-06 18:16:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-21 16:01:46 +02:00
|
|
|
d->panels[d->prefix]->panelSize = size;
|
2008-04-16 22:17:36 +02:00
|
|
|
d->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-04-21 16:01:46 +02:00
|
|
|
if (d->panels[d->prefix]->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-04-21 16:01:46 +02:00
|
|
|
return d->panels[d->prefix]->topHeight;
|
2008-02-06 18:16:45 +01:00
|
|
|
break;
|
|
|
|
|
2008-02-06 20:12:21 +01:00
|
|
|
case Plasma::LeftMargin:
|
2008-04-21 16:01:46 +02:00
|
|
|
return d->panels[d->prefix]->leftWidth;
|
2008-02-06 18:16:45 +01:00
|
|
|
break;
|
|
|
|
|
2008-02-06 20:12:21 +01:00
|
|
|
case Plasma::RightMargin:
|
2008-04-21 16:01:46 +02:00
|
|
|
return d->panels[d->prefix]->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-04-21 16:01:46 +02:00
|
|
|
return d->panels[d->prefix]->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-04-23 22:38:09 +02:00
|
|
|
PanelData *panel = d->panels[d->prefix];
|
|
|
|
if (!panel->cachedBackground) {
|
|
|
|
d->generateBackground(panel);
|
|
|
|
Q_ASSERT(panel->cachedBackground);
|
2008-03-05 22:03:27 +01:00
|
|
|
}
|
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
return panel->cachedBackground->alphaChannel().createMaskFromColor(Qt::black);
|
2008-04-21 16:01:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PanelSvg::setCacheAllRenderedPanels(bool cache)
|
|
|
|
{
|
|
|
|
if (d->cacheAll && !cache) {
|
|
|
|
clearCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
d->cacheAll = cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PanelSvg::cacheAllRenderedPanels() const
|
|
|
|
{
|
|
|
|
return d->cacheAll;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PanelSvg::clearCache()
|
|
|
|
{
|
|
|
|
qDeleteAll(d->panels);
|
2008-04-23 22:38:09 +02:00
|
|
|
d->panels.clear();
|
|
|
|
d->panels.insert(d->prefix, new PanelData());
|
2008-03-05 22:03:27 +01:00
|
|
|
}
|
|
|
|
|
2008-04-16 22:17:36 +02:00
|
|
|
void PanelSvg::paint(QPainter* painter, const QRectF& rect, const QPointF& pos)
|
|
|
|
{
|
2008-04-23 22:38:09 +02:00
|
|
|
PanelData *panel = d->panels[d->prefix];
|
|
|
|
if (!panel->cachedBackground) {
|
|
|
|
d->generateBackground(panel);
|
|
|
|
Q_ASSERT(panel->cachedBackground);
|
2008-04-16 22:17:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//FIXME: this is redundant with generatebackground for now
|
2008-04-23 22:38:09 +02:00
|
|
|
bool origined = panel->contentAtOrigin;
|
|
|
|
const int topOffset = origined ? 0 - panel->topHeight : 0;
|
|
|
|
const int leftOffset = origined ? 0 - panel->leftWidth : 0;
|
2008-04-16 22:17:36 +02:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
painter->drawPixmap(rect, *(panel->cachedBackground), rect.translated(-pos.x()-leftOffset,-pos.y()-topOffset));
|
2008-04-16 22:17:36 +02:00
|
|
|
}
|
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
void PanelSvg::Private::generateBackground(PanelData *panel)
|
2008-03-05 22:03:27 +01:00
|
|
|
{
|
2008-04-21 16:01:46 +02:00
|
|
|
bool origined = panel->contentAtOrigin;
|
2008-04-22 22:25:28 +02:00
|
|
|
const int topWidth = q->elementSize(prefix + "top").width();
|
|
|
|
const int leftHeight = q->elementSize(prefix + "left").height();
|
2008-04-21 16:01:46 +02:00
|
|
|
const int topOffset = origined ? 0 - panel->topHeight : 0;
|
|
|
|
const int leftOffset = origined ? 0 - panel->leftWidth : 0;
|
2008-03-05 22:03:27 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
if (panel->cachedBackground) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int contentWidth = panel->panelSize.width() - panel->leftWidth - panel->rightWidth;
|
|
|
|
const int contentHeight = panel->panelSize.height() - panel->topHeight - panel->bottomHeight;
|
|
|
|
int contentTop = 0;
|
|
|
|
int contentLeft = 0;
|
|
|
|
int rightOffset = contentWidth;
|
|
|
|
int bottomOffset = contentHeight;
|
|
|
|
|
|
|
|
panel->cachedBackground = new QPixmap(panel->leftWidth + contentWidth + panel->rightWidth,
|
2008-04-21 16:01:46 +02:00
|
|
|
panel->topHeight + contentHeight + panel->bottomHeight);
|
2008-04-23 22:38:09 +02:00
|
|
|
panel->cachedBackground->fill(Qt::transparent);
|
|
|
|
QPainter p(panel->cachedBackground);
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
p.setRenderHint(QPainter::SmoothPixmapTransform);
|
2008-02-06 20:46:36 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
if (origined) {
|
|
|
|
p.translate(panel->leftWidth, panel->topHeight);
|
|
|
|
}
|
2008-02-06 20:46:36 +01:00
|
|
|
|
2008-04-23 22:38:09 +02: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
|
|
|
|
if (panel->tileCenter) {
|
|
|
|
if (contentHeight > 0 && contentWidth > 0) {
|
|
|
|
int centerTileHeight;
|
|
|
|
int centerTileWidth;
|
|
|
|
centerTileHeight = q->elementSize(prefix + "center").height();
|
|
|
|
centerTileWidth = q->elementSize(prefix + "center").width();
|
|
|
|
QPixmap center(centerTileWidth, centerTileHeight);
|
|
|
|
center.fill(Qt::transparent);
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter centerPainter(¢er);
|
|
|
|
centerPainter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
q->Svg::paint(¢erPainter, QPoint(0, 0), prefix + "center");
|
2008-02-06 21:53:14 +01:00
|
|
|
}
|
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
p.drawTiledPixmap(QRect(contentLeft - panel->leftWidth, contentTop - panel->topHeight,
|
|
|
|
contentWidth + panel->leftWidth*2, contentHeight + panel->topHeight*2), center);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (contentHeight > 0 && contentWidth > 0) {
|
|
|
|
QSizeF scaledSize = QSizeF(panel->panelSize.width() -
|
|
|
|
(panel->leftWidth + panel->rightWidth) +
|
|
|
|
panel->panelSize.width()*(((qreal)(panel->leftWidth + panel->rightWidth)) / panel->panelSize.width()),
|
|
|
|
panel->panelSize.height() -
|
|
|
|
(panel->topHeight + panel->bottomHeight) +
|
|
|
|
panel->panelSize.height()*(((qreal)(panel->topHeight + panel->bottomHeight)) / panel->panelSize.height()));
|
|
|
|
|
|
|
|
q->Svg::resize(scaledSize.width(), scaledSize.height());
|
|
|
|
q->Svg::paint(&p, QRect(contentLeft - panel->leftWidth, contentTop - panel->topHeight,
|
|
|
|
contentWidth + panel->leftWidth*2, contentHeight + panel->topHeight*2),
|
|
|
|
prefix + "center");
|
|
|
|
q->Svg::resize();
|
|
|
|
}
|
|
|
|
}
|
2008-02-06 21:53:14 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
// Corners
|
|
|
|
if (panel->enabledBorders & TopBorder) {
|
|
|
|
if (!origined) {
|
|
|
|
contentTop = panel->topHeight;
|
|
|
|
bottomOffset += panel->topHeight;
|
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
if (panel->enabledBorders & LeftBorder) {
|
|
|
|
q->Svg::paint(&p, QRect(leftOffset, topOffset, panel->leftWidth, panel->topHeight), prefix + "topleft");
|
|
|
|
|
|
|
|
if (!origined) {
|
|
|
|
contentLeft = panel->leftWidth;
|
|
|
|
rightOffset = contentWidth + panel->leftWidth;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
if (panel->enabledBorders & RightBorder) {
|
|
|
|
q->Svg::paint(&p, QRect(rightOffset, topOffset, panel->rightWidth, panel->topHeight), prefix + "topright");
|
|
|
|
}
|
|
|
|
}
|
2008-02-06 21:53:14 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
if (panel->enabledBorders & BottomBorder) {
|
|
|
|
if (panel->enabledBorders & LeftBorder) {
|
|
|
|
q->Svg::paint(&p, QRect(leftOffset, bottomOffset, panel->leftWidth, panel->bottomHeight), prefix + "bottomleft");
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
if (!origined) {
|
|
|
|
contentLeft = panel->leftWidth;
|
|
|
|
rightOffset = contentWidth + panel->leftWidth;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
if (panel->enabledBorders & RightBorder) {
|
|
|
|
q->Svg::paint(&p, QRect(rightOffset, bottomOffset, panel->rightWidth, panel->bottomHeight), prefix + "bottomright");
|
|
|
|
}
|
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
// Sides
|
|
|
|
if (panel->stretchBorders) {
|
|
|
|
if (panel->enabledBorders & LeftBorder) {
|
|
|
|
q->Svg::paint(&p, QRect(leftOffset, contentTop, panel->leftWidth, contentHeight), prefix + "left");
|
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
if (panel->enabledBorders & RightBorder) {
|
|
|
|
q->Svg::paint(&p, QRect(rightOffset, contentTop, panel->rightWidth, contentHeight), prefix + "right");
|
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
if (panel->enabledBorders & TopBorder) {
|
|
|
|
q->Svg::paint(&p, QRect(contentLeft, topOffset, contentWidth, panel->topHeight), prefix + "top");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (panel->enabledBorders & BottomBorder) {
|
|
|
|
q->Svg::paint(&p, QRect(contentLeft, bottomOffset, contentWidth, panel->bottomHeight), prefix + "bottom");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (panel->enabledBorders & LeftBorder) {
|
|
|
|
QPixmap left(panel->leftWidth, leftHeight);
|
|
|
|
left.fill(Qt::transparent);
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter sidePainter(&left);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
q->Svg::paint(&sidePainter, QPoint(0, 0), prefix + "left");
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
p.drawTiledPixmap(QRect(leftOffset, contentTop, panel->leftWidth, contentHeight), left);
|
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
if (panel->enabledBorders & RightBorder) {
|
|
|
|
QPixmap right(panel->rightWidth, leftHeight);
|
|
|
|
right.fill(Qt::transparent);
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
{
|
|
|
|
QPainter sidePainter(&right);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
q->Svg::paint(&sidePainter, QPoint(0, 0), prefix + "right");
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
p.drawTiledPixmap(QRect(rightOffset, contentTop, panel->rightWidth, contentHeight), right);
|
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
if (panel->enabledBorders & TopBorder) {
|
|
|
|
QPixmap top(topWidth, panel->topHeight);
|
|
|
|
top.fill(Qt::transparent);
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
{
|
|
|
|
QPainter sidePainter(&top);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
q->Svg::paint(&sidePainter, QPoint(0, 0), prefix + "top");
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
p.drawTiledPixmap(QRect(contentLeft, topOffset, contentWidth, panel->topHeight), top);
|
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
if (panel->enabledBorders & BottomBorder) {
|
|
|
|
QPixmap bottom(topWidth, panel->bottomHeight);
|
|
|
|
bottom.fill(Qt::transparent);
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
{
|
|
|
|
QPainter sidePainter(&bottom);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
q->Svg::paint(&sidePainter, QPoint(0, 0), prefix + "bottom");
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
2008-04-23 22:38:09 +02:00
|
|
|
|
|
|
|
p.drawTiledPixmap(QRect(contentLeft, bottomOffset, contentWidth, panel->bottomHeight), bottom);
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
2008-04-23 22:38:09 +02:00
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
// re-enable this once Qt's svg rendering is un-buggered
|
|
|
|
//q->Svg::resize(contentWidth, contentHeight);
|
|
|
|
//paint(&p, QRect(contentLeft, contentTop, contentWidth, contentHeight), "center");
|
2008-03-05 22:03:27 +01:00
|
|
|
}
|
|
|
|
|
2008-04-16 22:17:36 +02:00
|
|
|
void PanelSvg::Private::updateSizes()
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-04-21 16:01:46 +02:00
|
|
|
PanelData *panel = panels[prefix];
|
|
|
|
|
|
|
|
delete panel->cachedBackground;
|
|
|
|
panel->cachedBackground = 0;
|
2008-03-23 18:50:49 +01:00
|
|
|
|
2008-04-22 22:25:28 +02:00
|
|
|
q->Svg::resize();
|
2008-04-21 16:01:46 +02:00
|
|
|
if (panel->enabledBorders & TopBorder) {
|
2008-04-22 22:25:28 +02:00
|
|
|
panel->topHeight = q->elementSize(prefix + "top").height();
|
2008-02-06 18:16:45 +01:00
|
|
|
} else {
|
2008-04-21 16:01:46 +02:00
|
|
|
panel->topHeight = 0;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-21 16:01:46 +02:00
|
|
|
if (panel->enabledBorders & LeftBorder) {
|
2008-04-22 22:25:28 +02:00
|
|
|
panel->leftWidth = q->elementSize(prefix + "left").width();
|
2008-02-06 18:16:45 +01:00
|
|
|
} else {
|
2008-04-21 16:01:46 +02:00
|
|
|
panel->leftWidth = 0;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-21 16:01:46 +02:00
|
|
|
if (panel->enabledBorders & RightBorder) {
|
2008-04-22 22:25:28 +02:00
|
|
|
panel->rightWidth = q->elementSize(prefix + "right").width();
|
2008-02-06 18:16:45 +01:00
|
|
|
} else {
|
2008-04-21 16:01:46 +02:00
|
|
|
panel->rightWidth = 0;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-22 22:25:28 +02:00
|
|
|
if (panel->enabledBorders & BottomBorder) {
|
|
|
|
panel->bottomHeight = q->elementSize(prefix + "bottom").height();
|
|
|
|
} else {
|
|
|
|
panel->bottomHeight = 0;
|
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-04-22 22:25:28 +02:00
|
|
|
//since it's rectangular, topWidth and bottomWidth must be the same
|
|
|
|
panel->tileCenter = q->hasElement("hint-tile-center");
|
|
|
|
panel->noBorderPadding = q->hasElement("hint-no-border-padding");
|
|
|
|
panel->stretchBorders = q->hasElement("hint-stretch-borders");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PanelSvg::Private::updateAndSignalSizes()
|
|
|
|
{
|
|
|
|
updateSizes();
|
|
|
|
emit q->repaintNeeded();
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // Plasma namespace
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
#include "panelsvg.moc"
|