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"
28 ShadowItem::ShadowItem(QGraphicsItem
*item
)
32 m_offset
= QPointF(12, 12);
33 setShadowParent(item
);
36 void ShadowItem::setShadowParent(QGraphicsItem
*item
)
38 m_shadowParent
= item
;
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
) {
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
);
68 p
.setRenderHint(QPainter::Antialiasing
);
69 p
.setCompositionMode(QPainter::CompositionMode_Source
);
70 p
.fillPath(path
, Qt::gray
);
74 expblur
<16, 7>(img
, 7);
76 p
.setCompositionMode(QPainter::CompositionMode_Plus
);
77 p
.drawImage(0, 0, blurred
);
80 expblur
<16, 7>(img
, 7);
83 setPixmap(QPixmap::fromImage(img
));
87 void ShadowItem::adjustPosition()
89 if (!m_shadowParent
) {
93 setPos(m_shadowParent
->pos() - m_offset
);
96 void ShadowItem::setOffset(const QPointF
&offset
)
101 QPointF
ShadowItem::offset() const