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>
|
|
|
|
|
2008-05-24 17:33:35 +02:00
|
|
|
#include <plasma/theme.h>
|
|
|
|
|
2008-02-06 18:16:45 +01:00
|
|
|
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-08-27 21:59:12 +02:00
|
|
|
cachedBackground(0), cachedMask(0),
|
2008-07-25 17:08:22 +02:00
|
|
|
panelSize(-1,-1)
|
2008-02-06 19:49:14 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-05-24 07:29:42 +02:00
|
|
|
PanelData(const PanelData &other)
|
|
|
|
: enabledBorders(other.enabledBorders),
|
2008-08-27 21:59:12 +02:00
|
|
|
cachedBackground(0), cachedMask(0),
|
2008-07-25 17:08:22 +02:00
|
|
|
panelSize(other.panelSize)
|
2008-05-24 07:29:42 +02: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;
|
2008-08-27 21:59:12 +02:00
|
|
|
QBitmap *cachedMask;
|
2008-02-06 19:49:14 +01:00
|
|
|
QSizeF panelSize;
|
|
|
|
|
|
|
|
//measures
|
|
|
|
int topHeight;
|
|
|
|
int leftWidth;
|
|
|
|
int rightWidth;
|
|
|
|
int bottomHeight;
|
2008-08-23 22:36:09 +02:00
|
|
|
|
2008-07-25 17:08:22 +02:00
|
|
|
//margins, are equal to the measures by default
|
|
|
|
int topMargin;
|
|
|
|
int leftMargin;
|
|
|
|
int rightMargin;
|
|
|
|
int bottomMargin;
|
2008-02-06 19:49:14 +01:00
|
|
|
|
|
|
|
//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-07-01 20:56:43 +02:00
|
|
|
class PanelSvgPrivate
|
2008-04-21 16:01:46 +02:00
|
|
|
{
|
|
|
|
public:
|
2008-07-01 20:56:43 +02:00
|
|
|
PanelSvgPrivate(PanelSvg *psvg)
|
2008-04-21 16:01:46 +02:00
|
|
|
: q(psvg),
|
|
|
|
cacheAll(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
~PanelSvgPrivate()
|
2008-04-21 16:01:46 +02:00
|
|
|
{
|
|
|
|
qDeleteAll(panels);
|
2008-05-02 12:32:47 +02:00
|
|
|
panels.clear();
|
2008-04-21 16:01:46 +02:00
|
|
|
}
|
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
void generateBackground(PanelData *panel);
|
2008-04-21 16:01:46 +02:00
|
|
|
void updateSizes();
|
2008-05-24 17:33:35 +02:00
|
|
|
void updateNeeded();
|
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-10-11 18:19:04 +02:00
|
|
|
PanelSvg::PanelSvg(QObject *parent)
|
2008-04-23 15:07:41 +02:00
|
|
|
: Svg(parent),
|
2008-07-01 20:56:43 +02:00
|
|
|
d(new PanelSvgPrivate(this))
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-05-24 17:33:35 +02:00
|
|
|
connect(this, SIGNAL(repaintNeeded()), this, SLOT(updateNeeded()));
|
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-10-11 18:19:04 +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-24 21:49:24 +02:00
|
|
|
clearCache();
|
|
|
|
d->updateAndSignalSizes();
|
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-05-03 20:29:06 +02:00
|
|
|
QHash<QString, PanelData*>::const_iterator it = d->panels.constFind(d->prefix);
|
|
|
|
|
|
|
|
if (it != d->panels.constEnd()) {
|
|
|
|
return it.value()->enabledBorders;
|
2008-05-03 18:03:44 +02:00
|
|
|
} else {
|
|
|
|
return NoBorder;
|
|
|
|
}
|
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-05-24 07:29:42 +02:00
|
|
|
if (!d->panels.contains(d->prefix)) {
|
|
|
|
d->panels.insert(d->prefix, new PanelData(*(d->panels[oldPrefix])));
|
|
|
|
d->updateSizes();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
d->location = Floating;
|
2008-03-23 18:50:49 +01:00
|
|
|
}
|
|
|
|
|
2008-05-02 15:25:04 +02:00
|
|
|
bool PanelSvg::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
|
2008-05-08 11:12:04 +02:00
|
|
|
if (prefix.isEmpty()) {
|
|
|
|
return hasElement("center");
|
|
|
|
} else {
|
|
|
|
return hasElement(prefix + "-center");
|
|
|
|
}
|
2008-05-02 15:25:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PanelSvg::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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
QString PanelSvg::prefix()
|
2008-03-23 18:50:49 +01:00
|
|
|
{
|
|
|
|
if (d->prefix.isEmpty()) {
|
2008-04-24 21:49:24 +02:00
|
|
|
return d->prefix;
|
2008-03-23 18:50:49 +01:00
|
|
|
}
|
2008-04-24 21:49:24 +02:00
|
|
|
|
2008-03-23 18:50:49 +01:00
|
|
|
return d->prefix.left(d->prefix.size() - 1);
|
|
|
|
}
|
2008-02-15 10:04:12 +01:00
|
|
|
|
2008-10-11 18:19:04 +02:00
|
|
|
void PanelSvg::resizePanel(const QSizeF &size)
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-05-24 07:29:42 +02:00
|
|
|
if (size.isEmpty()) {
|
|
|
|
kWarning() << "Invalid size" << size;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size == d->panels[d->prefix]->panelSize) {
|
2008-02-06 18:16:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-16 22:17:36 +02:00
|
|
|
d->updateSizes();
|
2008-05-02 12:32:47 +02:00
|
|
|
d->panels[d->prefix]->panelSize = size;
|
2008-04-16 22:17:36 +02:00
|
|
|
}
|
|
|
|
|
2008-05-03 18:03:44 +02:00
|
|
|
QSizeF PanelSvg::panelSize() const
|
|
|
|
{
|
2008-05-03 20:29:06 +02:00
|
|
|
QHash<QString, PanelData*>::const_iterator it = d->panels.constFind(d->prefix);
|
|
|
|
|
|
|
|
if (it != d->panels.constEnd()) {
|
|
|
|
return it.value()->panelSize;
|
2008-05-03 18:03:44 +02:00
|
|
|
} else {
|
|
|
|
return QSize(-1, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-07-25 17:08:22 +02:00
|
|
|
return d->panels[d->prefix]->topMargin;
|
2008-02-06 18:16:45 +01:00
|
|
|
break;
|
|
|
|
|
2008-02-06 20:12:21 +01:00
|
|
|
case Plasma::LeftMargin:
|
2008-07-25 17:08:22 +02:00
|
|
|
return d->panels[d->prefix]->leftMargin;
|
2008-02-06 18:16:45 +01:00
|
|
|
break;
|
|
|
|
|
2008-02-06 20:12:21 +01:00
|
|
|
case Plasma::RightMargin:
|
2008-07-25 17:08:22 +02:00
|
|
|
return d->panels[d->prefix]->rightMargin;
|
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-07-25 17:08:22 +02:00
|
|
|
return d->panels[d->prefix]->bottomMargin;
|
2008-02-06 18:16:45 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-01 11:49:30 +02:00
|
|
|
void PanelSvg::getMargins(qreal &left, qreal &top, qreal &right, qreal &bottom) const
|
|
|
|
{
|
2008-05-24 07:29:42 +02:00
|
|
|
PanelData *panel = d->panels[d->prefix];
|
|
|
|
|
|
|
|
if (!panel || panel->noBorderPadding) {
|
|
|
|
left = top = right = bottom = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-25 17:08:22 +02:00
|
|
|
top = panel->topMargin;
|
|
|
|
left = panel->leftMargin;
|
|
|
|
right = panel->rightMargin;
|
|
|
|
bottom = panel->bottomMargin;
|
2008-05-01 11:49:30 +02:00
|
|
|
}
|
|
|
|
|
2008-08-23 22:36:09 +02:00
|
|
|
QRectF PanelSvg::contentsRect() const
|
|
|
|
{
|
|
|
|
QSizeF size(panelSize());
|
|
|
|
|
|
|
|
if (size.isValid()) {
|
|
|
|
QRectF rect(QPointF(0, 0), size);
|
|
|
|
PanelData *panel = d->panels[d->prefix];
|
|
|
|
|
2008-10-11 18:19:04 +02:00
|
|
|
return rect.adjusted(panel->leftMargin, panel->topMargin,
|
|
|
|
-panel->rightMargin, -panel->bottomMargin);
|
2008-08-23 22:36:09 +02:00
|
|
|
} else {
|
|
|
|
return QRectF();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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];
|
2008-10-11 18:19:04 +02:00
|
|
|
|
2008-08-27 21:59:12 +02:00
|
|
|
if (!panel->cachedMask) {
|
|
|
|
if (!panel->cachedBackground) {
|
|
|
|
d->generateBackground(panel);
|
|
|
|
Q_ASSERT(panel->cachedBackground);
|
|
|
|
}
|
2008-10-11 18:19:04 +02:00
|
|
|
panel->cachedMask =
|
|
|
|
new QBitmap(panel->cachedBackground->alphaChannel().createMaskFromColor(Qt::black));
|
2008-03-05 22:03:27 +01:00
|
|
|
}
|
2008-08-27 21:59:12 +02:00
|
|
|
return *(panel->cachedMask);
|
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()
|
|
|
|
{
|
2008-04-24 21:49:24 +02:00
|
|
|
PanelData *panel = d->panels[d->prefix];
|
|
|
|
|
2008-05-24 07:29:42 +02:00
|
|
|
// delete all the panels that aren't this one
|
|
|
|
QMutableHashIterator<QString, PanelData*> it(d->panels);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
PanelData *p = it.next().value();
|
|
|
|
if (panel != p) {
|
|
|
|
delete p;
|
|
|
|
it.remove();
|
|
|
|
}
|
|
|
|
}
|
2008-03-05 22:03:27 +01:00
|
|
|
}
|
|
|
|
|
2008-09-30 22:47:47 +02:00
|
|
|
QPixmap PanelSvg::panelPixmap()
|
|
|
|
{
|
|
|
|
PanelData *panel = d->panels[d->prefix];
|
|
|
|
if (!panel->cachedBackground) {
|
|
|
|
d->generateBackground(panel);
|
|
|
|
Q_ASSERT(panel->cachedBackground);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *panel->cachedBackground;
|
|
|
|
}
|
|
|
|
|
2008-10-11 18:19:04 +02:00
|
|
|
void PanelSvg::paintPanel(QPainter *painter, const QRectF &target, const QRectF &source)
|
2008-04-16 22:17:36 +02: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-04-16 22:17:36 +02:00
|
|
|
}
|
|
|
|
|
2008-09-23 01:15:57 +02:00
|
|
|
painter->drawPixmap(target, *(panel->cachedBackground), source.isValid() ? source : target);
|
2008-07-27 19:20:27 +02:00
|
|
|
}
|
|
|
|
|
2008-10-11 18:19:04 +02:00
|
|
|
void PanelSvg::paintPanel(QPainter *painter, const QPointF &pos)
|
2008-07-27 19:20:27 +02:00
|
|
|
{
|
|
|
|
PanelData *panel = d->panels[d->prefix];
|
|
|
|
if (!panel->cachedBackground) {
|
|
|
|
d->generateBackground(panel);
|
|
|
|
Q_ASSERT(panel->cachedBackground);
|
|
|
|
}
|
|
|
|
|
|
|
|
painter->drawPixmap(pos, *(panel->cachedBackground));
|
2008-04-16 22:17:36 +02:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void PanelSvgPrivate::generateBackground(PanelData *panel)
|
2008-03-05 22:03:27 +01:00
|
|
|
{
|
2008-05-24 09:33:33 +02:00
|
|
|
//kDebug() << "generating background";
|
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-07-25 17:08:22 +02:00
|
|
|
const int topOffset = 0;
|
|
|
|
const int leftOffset = 0;
|
2008-03-05 22:03:27 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
if (panel->cachedBackground) {
|
|
|
|
return;
|
|
|
|
}
|
2008-05-24 07:29:42 +02:00
|
|
|
|
2008-04-28 00:34:24 +02:00
|
|
|
if (!panel->panelSize.isValid()) {
|
|
|
|
kWarning() << "Invalid panel size" << panel->panelSize;
|
|
|
|
panel->cachedBackground = new QPixmap();
|
|
|
|
return;
|
|
|
|
}
|
2008-04-23 22:38:09 +02:00
|
|
|
|
|
|
|
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-05-01 21:51:41 +02:00
|
|
|
//if we must stretch the center or the borders we compute how much we will have to stretch
|
|
|
|
//the svg to get the desired element sizes
|
2008-10-11 18:19:04 +02:00
|
|
|
QSizeF scaledContentSize(0, 0);
|
2008-05-01 21:51:41 +02:00
|
|
|
if (q->elementSize(prefix + "center").width() > 0 &&
|
|
|
|
q->elementSize(prefix + "center").height() > 0 &&
|
|
|
|
(!panel->tileCenter || panel->stretchBorders)) {
|
|
|
|
scaledContentSize = QSizeF(contentWidth * ((qreal)q->size().width() / (qreal)q->elementSize(prefix + "center").width()),
|
|
|
|
contentHeight * ((qreal)q->size().height() / (qreal)q->elementSize(prefix + "center").height()));
|
|
|
|
}
|
2008-04-23 22:38:09 +02:00
|
|
|
|
|
|
|
//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);
|
2008-04-25 18:18:51 +02:00
|
|
|
q->paint(¢erPainter, QPoint(0, 0), prefix + "center");
|
2008-02-06 21:53:14 +01:00
|
|
|
}
|
|
|
|
|
2008-05-01 21:51:41 +02:00
|
|
|
p.drawTiledPixmap(QRect(panel->leftWidth, panel->topHeight,
|
2008-05-01 22:09:24 +02:00
|
|
|
contentWidth, contentHeight), center);
|
2008-04-23 22:38:09 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (contentHeight > 0 && contentWidth > 0) {
|
2008-05-01 21:51:41 +02:00
|
|
|
q->resize(scaledContentSize);
|
|
|
|
q->paint(&p, QRect(panel->leftWidth, panel->topHeight,
|
|
|
|
contentWidth, contentHeight),
|
|
|
|
prefix + "center");
|
2008-04-24 21:49:24 +02:00
|
|
|
q->resize();
|
2008-04-23 22:38:09 +02:00
|
|
|
}
|
|
|
|
}
|
2008-02-06 21:53:14 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
// Corners
|
2008-07-01 20:56:43 +02:00
|
|
|
if (q->hasElement(prefix + "top") && panel->enabledBorders & PanelSvg::TopBorder) {
|
2008-07-25 17:08:22 +02:00
|
|
|
contentTop = panel->topHeight;
|
|
|
|
bottomOffset += panel->topHeight;
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
if (q->hasElement(prefix + "topleft") && panel->enabledBorders & PanelSvg::LeftBorder) {
|
2008-04-25 18:18:51 +02:00
|
|
|
q->paint(&p, QRect(leftOffset, topOffset, panel->leftWidth, panel->topHeight), prefix + "topleft");
|
2008-04-23 22:38:09 +02:00
|
|
|
|
2008-07-25 17:08:22 +02:00
|
|
|
contentLeft = panel->leftWidth;
|
|
|
|
rightOffset = contentWidth + panel->leftWidth;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
if (q->hasElement(prefix + "topright") && panel->enabledBorders & PanelSvg::RightBorder) {
|
2008-04-25 18:18:51 +02:00
|
|
|
q->paint(&p, QRect(rightOffset, topOffset, panel->rightWidth, panel->topHeight), prefix + "topright");
|
2008-04-23 22:38:09 +02:00
|
|
|
}
|
|
|
|
}
|
2008-02-06 21:53:14 +01:00
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
if (q->hasElement(prefix + "bottom") && panel->enabledBorders & PanelSvg::BottomBorder) {
|
|
|
|
if (q->hasElement(prefix + "bottomleft") && panel->enabledBorders & PanelSvg::LeftBorder) {
|
2008-04-25 18:18:51 +02:00
|
|
|
q->paint(&p, QRect(leftOffset, bottomOffset, panel->leftWidth, panel->bottomHeight), prefix + "bottomleft");
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-07-25 17:08:22 +02:00
|
|
|
contentLeft = panel->leftWidth;
|
|
|
|
rightOffset = contentWidth + panel->leftWidth;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
if (q->hasElement(prefix + "bottomright") && panel->enabledBorders & PanelSvg::RightBorder) {
|
2008-04-25 18:18:51 +02:00
|
|
|
q->paint(&p, QRect(rightOffset, bottomOffset, panel->rightWidth, panel->bottomHeight), prefix + "bottomright");
|
2008-04-23 22:38:09 +02:00
|
|
|
}
|
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-04-23 22:38:09 +02:00
|
|
|
// Sides
|
|
|
|
if (panel->stretchBorders) {
|
2008-07-01 20:56:43 +02:00
|
|
|
if (panel->enabledBorders & PanelSvg::LeftBorder || panel->enabledBorders & PanelSvg::RightBorder) {
|
2008-05-01 21:51:41 +02:00
|
|
|
q->resize(q->size().width(), scaledContentSize.height());
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-10-11 18:19:04 +02:00
|
|
|
if (q->hasElement(prefix + "left") &&
|
|
|
|
panel->enabledBorders & PanelSvg::LeftBorder) {
|
2008-05-01 21:51:41 +02:00
|
|
|
q->paint(&p, QRect(leftOffset, contentTop, panel->leftWidth, contentHeight), prefix + "left");
|
|
|
|
}
|
|
|
|
|
2008-10-11 18:19:04 +02:00
|
|
|
if (q->hasElement(prefix + "right") &&
|
|
|
|
panel->enabledBorders & PanelSvg::RightBorder) {
|
2008-05-01 21:51:41 +02:00
|
|
|
q->paint(&p, QRect(rightOffset, contentTop, panel->rightWidth, contentHeight), prefix + "right");
|
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-05-01 21:51:41 +02:00
|
|
|
q->resize();
|
2008-04-23 22:38:09 +02:00
|
|
|
}
|
|
|
|
|
2008-10-11 18:19:04 +02:00
|
|
|
if (panel->enabledBorders & PanelSvg::TopBorder ||
|
|
|
|
panel->enabledBorders & PanelSvg::BottomBorder) {
|
2008-05-01 21:51:41 +02:00
|
|
|
q->resize(scaledContentSize.width(), q->size().height());
|
|
|
|
|
2008-10-11 18:19:04 +02:00
|
|
|
if (q->hasElement(prefix + "top") &&
|
|
|
|
panel->enabledBorders & PanelSvg::TopBorder) {
|
2008-05-01 21:51:41 +02:00
|
|
|
q->paint(&p, QRect(contentLeft, topOffset, contentWidth, panel->topHeight), prefix + "top");
|
|
|
|
}
|
|
|
|
|
2008-10-11 18:19:04 +02:00
|
|
|
if (q->hasElement(prefix + "bottom") &&
|
|
|
|
panel->enabledBorders & PanelSvg::BottomBorder) {
|
2008-05-01 21:51:41 +02:00
|
|
|
q->paint(&p, QRect(contentLeft, bottomOffset, contentWidth, panel->bottomHeight), prefix + "bottom");
|
|
|
|
}
|
|
|
|
|
|
|
|
q->resize();
|
2008-04-23 22:38:09 +02:00
|
|
|
}
|
|
|
|
} else {
|
2008-10-11 18:19:04 +02:00
|
|
|
if (q->hasElement(prefix + "left") &&
|
|
|
|
panel->enabledBorders & PanelSvg::LeftBorder) {
|
2008-04-23 22:38:09 +02:00
|
|
|
QPixmap left(panel->leftWidth, leftHeight);
|
|
|
|
left.fill(Qt::transparent);
|
|
|
|
|
2008-05-04 13:19:11 +02:00
|
|
|
QPainter sidePainter(&left);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
q->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-07-01 20:56:43 +02:00
|
|
|
if (q->hasElement(prefix + "right") && panel->enabledBorders & PanelSvg::RightBorder) {
|
2008-04-23 22:38:09 +02:00
|
|
|
QPixmap right(panel->rightWidth, leftHeight);
|
|
|
|
right.fill(Qt::transparent);
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-05-04 13:19:11 +02:00
|
|
|
QPainter sidePainter(&right);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
q->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-07-01 20:56:43 +02:00
|
|
|
if (q->hasElement(prefix + "top") && panel->enabledBorders & PanelSvg::TopBorder) {
|
2008-04-23 22:38:09 +02:00
|
|
|
QPixmap top(topWidth, panel->topHeight);
|
|
|
|
top.fill(Qt::transparent);
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-05-04 13:19:11 +02:00
|
|
|
QPainter sidePainter(&top);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
q->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-07-01 20:56:43 +02:00
|
|
|
if (q->hasElement(prefix + "bottom") && panel->enabledBorders & PanelSvg::BottomBorder) {
|
2008-04-23 22:38:09 +02:00
|
|
|
QPixmap bottom(topWidth, panel->bottomHeight);
|
|
|
|
bottom.fill(Qt::transparent);
|
2008-02-06 18:16:45 +01:00
|
|
|
|
2008-05-04 13:19:11 +02:00
|
|
|
QPainter sidePainter(&bottom);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
q->paint(&sidePainter, QPoint(0, 0), prefix + "bottom");
|
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
|
2008-04-24 21:49:24 +02:00
|
|
|
//q->resize(contentWidth, contentHeight);
|
2008-04-23 22:38:09 +02:00
|
|
|
//paint(&p, QRect(contentLeft, contentTop, contentWidth, contentHeight), "center");
|
2008-03-05 22:03:27 +01:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void PanelSvgPrivate::updateSizes()
|
2008-02-06 18:16:45 +01:00
|
|
|
{
|
2008-04-24 21:49:24 +02:00
|
|
|
//kDebug() << "!!!!!!!!!!!!!!!!!!!!!! updating sizes" << prefix;
|
2008-04-21 16:01:46 +02:00
|
|
|
PanelData *panel = panels[prefix];
|
2008-04-24 21:49:24 +02:00
|
|
|
Q_ASSERT(panel);
|
2008-04-21 16:01:46 +02:00
|
|
|
|
|
|
|
delete panel->cachedBackground;
|
|
|
|
panel->cachedBackground = 0;
|
2008-08-27 21:59:12 +02:00
|
|
|
delete panel->cachedMask;
|
|
|
|
panel->cachedMask = 0;
|
2008-03-23 18:50:49 +01:00
|
|
|
|
2008-04-22 22:25:28 +02:00
|
|
|
q->Svg::resize();
|
2008-07-01 20:56:43 +02:00
|
|
|
if (panel->enabledBorders & PanelSvg::TopBorder) {
|
2008-04-22 22:25:28 +02:00
|
|
|
panel->topHeight = q->elementSize(prefix + "top").height();
|
2008-10-11 18:19:04 +02:00
|
|
|
|
2008-07-25 17:08:22 +02:00
|
|
|
if (q->hasElement(prefix + "hint-top-margin")) {
|
|
|
|
panel->topMargin = q->elementSize(prefix + "hint-top-margin").height();
|
|
|
|
} else {
|
|
|
|
panel->topMargin = panel->topHeight;
|
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
} else {
|
2008-07-25 17:08:22 +02:00
|
|
|
panel->topMargin = panel->topHeight = 0;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
if (panel->enabledBorders & PanelSvg::LeftBorder) {
|
2008-04-22 22:25:28 +02:00
|
|
|
panel->leftWidth = q->elementSize(prefix + "left").width();
|
2008-10-11 18:19:04 +02:00
|
|
|
|
2008-07-25 17:08:22 +02:00
|
|
|
if (q->hasElement(prefix + "hint-left-margin")) {
|
|
|
|
panel->leftMargin = q->elementSize(prefix + "hint-left-margin").height();
|
|
|
|
} else {
|
|
|
|
panel->leftMargin = panel->leftWidth;
|
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
} else {
|
2008-07-25 17:08:22 +02:00
|
|
|
panel->leftMargin = panel->leftWidth = 0;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
if (panel->enabledBorders & PanelSvg::RightBorder) {
|
2008-04-22 22:25:28 +02:00
|
|
|
panel->rightWidth = q->elementSize(prefix + "right").width();
|
2008-10-11 18:19:04 +02:00
|
|
|
|
2008-07-25 17:08:22 +02:00
|
|
|
if (q->hasElement(prefix + "hint-right-margin")) {
|
|
|
|
panel->rightMargin = q->elementSize(prefix + "hint-right-margin").height();
|
|
|
|
} else {
|
|
|
|
panel->rightMargin = panel->rightWidth;
|
|
|
|
}
|
2008-02-06 18:16:45 +01:00
|
|
|
} else {
|
2008-07-25 17:08:22 +02:00
|
|
|
panel->rightMargin = panel->rightWidth = 0;
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
if (panel->enabledBorders & PanelSvg::BottomBorder) {
|
2008-04-22 22:25:28 +02:00
|
|
|
panel->bottomHeight = q->elementSize(prefix + "bottom").height();
|
2008-10-11 18:19:04 +02:00
|
|
|
|
2008-07-25 17:08:22 +02:00
|
|
|
if (q->hasElement(prefix + "hint-bottom-margin")) {
|
|
|
|
panel->bottomMargin = q->elementSize(prefix + "hint-bottom-margin").height();
|
|
|
|
} else {
|
|
|
|
panel->bottomMargin = panel->bottomHeight;
|
|
|
|
}
|
2008-04-22 22:25:28 +02:00
|
|
|
} else {
|
2008-07-25 17:08:22 +02:00
|
|
|
panel->bottomMargin = panel->bottomHeight = 0;
|
2008-04-22 22:25:28 +02:00
|
|
|
}
|
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");
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void PanelSvgPrivate::updateNeeded()
|
2008-05-24 17:33:35 +02:00
|
|
|
{
|
|
|
|
q->clearCache();
|
|
|
|
updateSizes();
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void PanelSvgPrivate::updateAndSignalSizes()
|
2008-04-22 22:25:28 +02:00
|
|
|
{
|
2008-05-24 17:33:35 +02:00
|
|
|
updateSizes();
|
2008-04-22 22:25:28 +02:00
|
|
|
emit q->repaintNeeded();
|
2008-02-06 18:16:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // Plasma namespace
|
|
|
|
|
2008-04-16 19:23:58 +02:00
|
|
|
#include "panelsvg.moc"
|