2009-12-27 23:16:11 +01:00
|
|
|
/*
|
|
|
|
Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library 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
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2009-11-13 02:20:51 +01:00
|
|
|
|
|
|
|
#include "pulsershadow_p.h"
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QPixmap>
|
2009-12-03 20:30:02 +01:00
|
|
|
#include <QStyleOptionGraphicsItem>
|
2010-01-05 19:55:45 +01:00
|
|
|
static const int RECURSION_MAX = 20;
|
2009-11-13 02:20:51 +01:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2010-01-04 10:17:49 +01:00
|
|
|
ShadowFake::ShadowFake(QGraphicsItem *parent)
|
|
|
|
: QGraphicsWidget(parent),
|
2010-01-05 19:55:45 +01:00
|
|
|
stack(0),
|
2010-01-04 10:17:49 +01:00
|
|
|
m_target(0)
|
|
|
|
{
|
|
|
|
}
|
2009-11-13 02:20:51 +01:00
|
|
|
|
|
|
|
ShadowFake::~ShadowFake()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-01-04 10:17:49 +01:00
|
|
|
void ShadowFake::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
|
|
|
Q_UNUSED(widget);
|
|
|
|
|
|
|
|
painter->setRenderHint(QPainter::Antialiasing);
|
|
|
|
painter->drawPixmap(option->exposedRect, m_photo, option->exposedRect);
|
|
|
|
}
|
|
|
|
|
2010-01-05 19:23:59 +01:00
|
|
|
void ShadowFake::paintSubChildren(QPainter *painter,
|
|
|
|
const QStyleOptionGraphicsItem *option,
|
|
|
|
QGraphicsItem *target)
|
|
|
|
{
|
2010-01-05 19:55:45 +01:00
|
|
|
++stack;
|
2010-01-05 19:23:59 +01:00
|
|
|
QList<QGraphicsItem *> list = target->childItems();
|
|
|
|
QGraphicsItem *tmp;
|
|
|
|
if (list.size() > 0) {
|
|
|
|
for (int i = 0; i < list.size(); ++i) {
|
|
|
|
tmp = list.value(i);
|
2010-01-05 19:55:45 +01:00
|
|
|
if ((tmp->childItems().size() > 0) && (stack < RECURSION_MAX)) {
|
2010-01-05 19:23:59 +01:00
|
|
|
paintSubChildren(painter, option, tmp);
|
|
|
|
}
|
2010-01-05 19:55:45 +01:00
|
|
|
|
|
|
|
tmp->paint(painter, option, 0);
|
2010-01-05 19:23:59 +01:00
|
|
|
}
|
|
|
|
}
|
2010-01-05 19:55:45 +01:00
|
|
|
--stack;
|
2010-01-05 19:23:59 +01:00
|
|
|
}
|
|
|
|
|
2010-01-04 10:17:49 +01:00
|
|
|
void ShadowFake::setTarget(QGraphicsWidget *target)
|
2009-11-13 02:20:51 +01:00
|
|
|
{
|
2010-01-05 19:55:45 +01:00
|
|
|
stack = 0;
|
2010-01-04 10:17:49 +01:00
|
|
|
m_target = target;
|
2009-11-13 02:20:51 +01:00
|
|
|
setParentItem(target);
|
2009-11-18 22:33:24 +01:00
|
|
|
resize(target->size());
|
|
|
|
setTransformOriginPoint(geometry().center());
|
2009-11-13 02:20:51 +01:00
|
|
|
QSize size(target->size().toSize());
|
|
|
|
|
2010-01-04 10:17:49 +01:00
|
|
|
m_photo = QPixmap(size);
|
|
|
|
m_photo.fill(Qt::transparent);
|
2009-11-13 02:20:51 +01:00
|
|
|
|
2010-01-04 10:17:49 +01:00
|
|
|
QPainter painter(&m_photo);
|
2009-11-13 02:20:51 +01:00
|
|
|
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
|
|
|
painter.fillRect(target->rect(), Qt::transparent);
|
2009-12-03 20:30:02 +01:00
|
|
|
QStyleOptionGraphicsItem style;
|
2010-01-04 10:17:49 +01:00
|
|
|
//FIXME: some widgets follow exposedRect viewport (e.g. QGraphicsWebView)
|
2009-12-18 20:30:02 +01:00
|
|
|
style.exposedRect = target->boundingRect();
|
2009-12-03 20:30:02 +01:00
|
|
|
target->paint(&painter, &style, 0);
|
2010-01-05 19:23:59 +01:00
|
|
|
paintSubChildren(&painter, &style, target);
|
2009-11-13 02:20:51 +01:00
|
|
|
painter.end();
|
|
|
|
}
|
|
|
|
|
2010-01-04 10:17:49 +01:00
|
|
|
QGraphicsWidget *ShadowFake::target() const
|
2009-11-13 02:20:51 +01:00
|
|
|
{
|
2010-01-04 10:17:49 +01:00
|
|
|
return m_target;
|
2009-11-13 02:20:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-01-04 10:17:49 +01:00
|
|
|
|