Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / libs / plasma / shadowitem.cpp
blob4c7d64215c10dbb560ed5d2448c8dd3ff582e1d9
1 /*
2 * Copyright 2007 by Zack Rusin <zack@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "shadowitem_p.h"
22 #include "effects/blur.cpp"
24 #include <QPainter>
25 #include <QImage>
26 #include <QDebug>
28 ShadowItem::ShadowItem(QGraphicsItem *item)
30 setZValue(20);
31 m_shadowParent = 0;
32 m_offset = QPointF(12, 12);
33 setShadowParent(item);
36 void ShadowItem::setShadowParent(QGraphicsItem *item)
38 m_shadowParent = item;
39 adjustPosition();
40 generate();
44 QGraphicsItem * ShadowItem::shadowParent() const
46 return m_shadowParent;
49 QSize ShadowItem::shadowedSize() const
51 QSize s = boundingRect().size().toSize();
52 return s - QSize(32, 32);
55 void ShadowItem::generate()
57 if (!m_shadowParent) {
58 return;
61 QPainterPath path = m_shadowParent->shape();
62 QRectF rect = path.boundingRect();
63 QSize s = rect.size().toSize() + QSize(30, 30);
64 QImage img(s, QImage::Format_ARGB32_Premultiplied);
65 img.fill(0);
66 QPainter p(&img);
67 p.translate(15, 15);
68 p.setRenderHint(QPainter::Antialiasing);
69 p.setCompositionMode(QPainter::CompositionMode_Source);
70 p.fillPath(path, Qt::gray);
71 p.end();
72 #ifdef DO_GLOW
73 QImage blurred = img;
74 expblur<16, 7>(img, 7);
75 p.begin(&img);
76 p.setCompositionMode(QPainter::CompositionMode_Plus);
77 p.drawImage(0, 0, blurred);
78 p.end();
79 #else
80 expblur<16, 7>(img, 7);
81 #endif
83 setPixmap(QPixmap::fromImage(img));
87 void ShadowItem::adjustPosition()
89 if (!m_shadowParent) {
90 return;
93 setPos(m_shadowParent->pos() - m_offset);
96 void ShadowItem::setOffset(const QPointF &offset)
98 m_offset = offset;
101 QPointF ShadowItem::offset() const
103 return m_offset;