• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

Plasma

widgetsnapshot.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Lesser General Public
00006     License as published by the Free Software Foundation; either
00007     version 2.1 of the License, or (at your option) any later version.
00008 
00009     This library 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 GNU
00012     Lesser General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public
00015     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
00016 */
00017 
00018 #include "widgetsnapshot_p.h"
00019 
00020 #include <QPainter>
00021 #include <QImage>
00022 #include <QPixmap>
00023 #include <QStyleOptionGraphicsItem>
00024 #include <QDebug>
00025 
00026 static const int RECURSION_MAX = 20;
00027 
00028 namespace Plasma
00029 {
00030 
00031 WidgetSnapShot::WidgetSnapShot(QGraphicsItem *parent)
00032     : QGraphicsWidget(parent),
00033       m_iconBig(false),
00034       stack(0),
00035       m_target(0)
00036 {
00037 }
00038 
00039 WidgetSnapShot::~WidgetSnapShot()
00040 {
00041 }
00042 
00043 void WidgetSnapShot::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
00044 {
00045     Q_UNUSED(widget);
00046 
00047     painter->setRenderHint(QPainter::Antialiasing);
00048     painter->drawPixmap(option->exposedRect, m_snapShot, option->exposedRect);
00049 }
00050 
00051 void WidgetSnapShot::paintSubChildren(QPainter *painter,
00052                                   const QStyleOptionGraphicsItem *option,
00053                                   QGraphicsItem *target)
00054 {
00055     ++stack;
00056     QList<QGraphicsItem *> list = target->childItems();
00057     QGraphicsItem *tmp;
00058     if (list.size() > 0) {
00059         for (int i = 0; i < list.size(); ++i) {
00060             tmp = list.value(i);
00061 
00062             if ((tmp->childItems().size() > 0) && (stack < RECURSION_MAX)) {
00063                 paintSubChildren(painter, option, tmp);
00064             }
00065 
00066             if (tmp->isVisible()) {
00067                 tmp->paint(painter, option, 0);
00068             }
00069         }
00070     }
00071     --stack;
00072 }
00073 
00074 void WidgetSnapShot::setTarget(QGraphicsWidget *target)
00075 {
00076     stack = 0;
00077     m_target = target;
00078     setParentItem(target);
00079     QSize size(target->size().toSize());
00080     m_iconBig = false;
00081 
00082     if (m_target->property("iconRepresentation").isValid()) {
00083         m_iconBig = true;
00084         m_snapShot = QPixmap::fromImage(
00085             m_target->property("iconRepresentation").value<QImage>());
00086         if ((m_snapShot.height() > 0) && (m_snapShot.width() > 0)) {
00087             resize(m_snapShot.size());
00088             setTransformOriginPoint(target->geometry().center());
00089             return;
00090         }
00091     }
00092 
00093     resize(target->size());
00094 
00095     m_snapShot = QPixmap(size);
00096     m_snapShot.fill(Qt::transparent);
00097 
00098     QPainter painter(&m_snapShot);
00099     painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
00100     painter.fillRect(target->rect(), Qt::transparent);
00101 
00102     QStyleOptionGraphicsItem style;
00103     style.exposedRect = target->boundingRect();
00104     style.rect = target->rect().toRect();
00105 
00106     target->paint(&painter, &style, 0);
00107     paintSubChildren(&painter, &style, target);
00108     painter.end();
00109     setTransformOriginPoint(geometry().center());
00110 }
00111 
00112 QGraphicsWidget *WidgetSnapShot::target() const
00113 {
00114     return m_target;
00115 }
00116 
00117 
00118 bool WidgetSnapShot::isIconBigger() const
00119 {
00120     return m_iconBig;
00121 }
00122 
00123 QPixmap WidgetSnapShot::snapShot() const
00124 {
00125     return m_snapShot;
00126 }
00127 
00128 }

Plasma

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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