• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

libplasma

shadowitem.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2007 by Zack Rusin <zack@kde.org>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License as
00006  *   published by the Free Software Foundation; either version 2, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details
00013  *
00014  *   You should have received a copy of the GNU Library General Public
00015  *   License along with this program; if not, write to the
00016  *   Free Software Foundation, Inc.,
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 #include "shadowitem_p.h"
00021 
00022 #include "effects/blur.cpp"
00023 
00024 #include <QPainter>
00025 #include <QImage>
00026 #include <QDebug>
00027 
00028 namespace Plasma
00029 {
00030 
00031 ShadowItem::ShadowItem(QGraphicsItem *item)
00032 {
00033     setZValue(20);
00034     m_shadowParent = 0;
00035     m_offset = QPointF(12, 12);
00036     setShadowParent(item);
00037 }
00038 
00039 void ShadowItem::setShadowParent(QGraphicsItem *item)
00040 {
00041     m_shadowParent = item;
00042     adjustPosition();
00043     generate();
00044 }
00045 
00046 
00047 QGraphicsItem * ShadowItem::shadowParent() const
00048 {
00049     return m_shadowParent;
00050 }
00051 
00052 QSize ShadowItem::shadowedSize() const
00053 {
00054     QSize s = boundingRect().size().toSize();
00055     return s - QSize(32, 32);
00056 }
00057 
00058 void ShadowItem::generate()
00059 {
00060     if (!m_shadowParent) {
00061         return;
00062     }
00063 
00064     QPainterPath path = m_shadowParent->shape();
00065     QRectF rect = path.boundingRect();
00066     QSize s = rect.size().toSize() + QSize(30, 30);
00067     QImage img(s, QImage::Format_ARGB32_Premultiplied);
00068     img.fill(0);
00069     QPainter p(&img);
00070     p.translate(15, 15);
00071     p.setRenderHint(QPainter::Antialiasing);
00072     p.setCompositionMode(QPainter::CompositionMode_Source);
00073     p.fillPath(path, Qt::gray);
00074     p.end();
00075 #ifdef DO_GLOW
00076     QImage blurred = img;
00077     expblur<16, 7>(img, 7);
00078     p.begin(&img);
00079     p.setCompositionMode(QPainter::CompositionMode_Plus);
00080     p.drawImage(0, 0, blurred);
00081     p.end();
00082 #else
00083     expblur<16, 7>(img, 7);
00084 #endif
00085 
00086     setPixmap(QPixmap::fromImage(img));
00087 }
00088 
00089 
00090 void ShadowItem::adjustPosition()
00091 {
00092     if (!m_shadowParent) {
00093         return;
00094     }
00095 
00096     setPos(m_shadowParent->pos() - m_offset);
00097 }
00098 
00099 void ShadowItem::setOffset(const QPointF &offset)
00100 {
00101     m_offset = offset;
00102 }
00103 
00104 QPointF ShadowItem::offset() const
00105 {
00106     return m_offset;
00107 }
00108 
00109 }

libplasma

Skip menu "libplasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal