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-03-19 20:47:52 +01:00
|
|
|
#include <QDebug>
|
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-02-22 22:58:21 +01:00
|
|
|
m_iconBig(false),
|
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-03-19 20:47:52 +01:00
|
|
|
|
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
|
|
|
|
2010-03-19 20:47:52 +01:00
|
|
|
if (tmp->isVisible()) {
|
|
|
|
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);
|
|
|
|
QSize size(target->size().toSize());
|
2010-02-22 22:58:21 +01:00
|
|
|
m_iconBig = false;
|
|
|
|
|
|
|
|
if (m_target->property("iconRepresentation").isValid()) {
|
|
|
|
m_iconBig = true;
|
|
|
|
m_photo = QPixmap::fromImage(
|
|
|
|
m_target->property("iconRepresentation").value<QImage>());
|
2010-02-23 00:18:30 +01:00
|
|
|
if ((m_photo.height() > 0) && (m_photo.width() > 0)) {
|
|
|
|
resize(m_photo.size());
|
|
|
|
setTransformOriginPoint(target->geometry().center());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-02-22 22:58:21 +01:00
|
|
|
|
2010-02-23 00:18:30 +01:00
|
|
|
resize(target->size());
|
2009-11-13 02:20:51 +01:00
|
|
|
|
2010-02-23 00:18:30 +01:00
|
|
|
m_photo = QPixmap(size);
|
|
|
|
m_photo.fill(Qt::transparent);
|
2009-11-13 02:20:51 +01:00
|
|
|
|
2010-02-23 00:18:30 +01:00
|
|
|
QPainter painter(&m_photo);
|
|
|
|
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
|
|
|
painter.fillRect(target->rect(), Qt::transparent);
|
2010-02-22 22:38:22 +01:00
|
|
|
|
2010-02-23 00:18:30 +01:00
|
|
|
QStyleOptionGraphicsItem style;
|
|
|
|
style.exposedRect = target->boundingRect();
|
|
|
|
style.rect = target->rect().toRect();
|
2010-02-22 22:58:21 +01:00
|
|
|
|
2010-02-23 00:18:30 +01:00
|
|
|
target->paint(&painter, &style, 0);
|
|
|
|
paintSubChildren(&painter, &style, target);
|
|
|
|
painter.end();
|
|
|
|
setTransformOriginPoint(geometry().center());
|
2009-11-13 02:20:51 +01:00
|
|
|
}
|
|
|
|
|
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-02-22 22:58:21 +01:00
|
|
|
|
|
|
|
bool ShadowFake::isIconBigger()
|
|
|
|
{
|
|
|
|
return m_iconBig;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-13 02:20:51 +01:00
|
|
|
}
|
2010-01-04 10:17:49 +01:00
|
|
|
|