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

Plasma

  • sources
  • kde-4.12
  • kdelibs
  • plasma
  • animations
widgetsnapshot.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library 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 GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #include "widgetsnapshot_p.h"
19 
20 #include <QPainter>
21 #include <QImage>
22 #include <QPixmap>
23 #include <QStyleOptionGraphicsItem>
24 #include <QDebug>
25 
26 static const int RECURSION_MAX = 20;
27 
28 namespace Plasma
29 {
30 
31 WidgetSnapShot::WidgetSnapShot(QGraphicsItem *parent)
32  : QGraphicsWidget(parent),
33  m_iconBig(false),
34  stack(0),
35  m_target(0)
36 {
37 }
38 
39 WidgetSnapShot::~WidgetSnapShot()
40 {
41 }
42 
43 void WidgetSnapShot::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
44 {
45  Q_UNUSED(widget);
46 
47  painter->setRenderHint(QPainter::Antialiasing);
48  painter->drawPixmap(option->exposedRect, m_snapShot, option->exposedRect);
49 }
50 
51 void WidgetSnapShot::paintSubChildren(QPainter *painter,
52  const QStyleOptionGraphicsItem *option,
53  QGraphicsItem *target)
54 {
55  ++stack;
56  QList<QGraphicsItem *> list = target->childItems();
57  QGraphicsItem *tmp;
58  if (list.size() > 0) {
59  for (int i = 0; i < list.size(); ++i) {
60  tmp = list.value(i);
61 
62  if ((tmp->childItems().size() > 0) && (stack < RECURSION_MAX)) {
63  paintSubChildren(painter, option, tmp);
64  }
65 
66  if (tmp->isVisible()) {
67  tmp->paint(painter, option, 0);
68  }
69  }
70  }
71  --stack;
72 }
73 
74 void WidgetSnapShot::setTarget(QGraphicsWidget *target)
75 {
76  stack = 0;
77  m_target = target;
78  setParentItem(target);
79  QSize size(target->size().toSize());
80  m_iconBig = false;
81 
82  if (m_target->property("iconRepresentation").isValid()) {
83  m_iconBig = true;
84  m_snapShot = QPixmap::fromImage(
85  m_target->property("iconRepresentation").value<QImage>());
86  if ((m_snapShot.height() > 0) && (m_snapShot.width() > 0)) {
87  resize(m_snapShot.size());
88  setTransformOriginPoint(target->geometry().center());
89  return;
90  }
91  }
92 
93  resize(target->size());
94 
95  m_snapShot = QPixmap(size);
96  m_snapShot.fill(Qt::transparent);
97 
98  QPainter painter(&m_snapShot);
99  painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
100  painter.fillRect(target->rect(), Qt::transparent);
101 
102  QStyleOptionGraphicsItem style;
103  style.exposedRect = target->boundingRect();
104  style.rect = target->rect().toRect();
105 
106  target->paint(&painter, &style, 0);
107  paintSubChildren(&painter, &style, target);
108  painter.end();
109  setTransformOriginPoint(geometry().center());
110 }
111 
112 QGraphicsWidget *WidgetSnapShot::target() const
113 {
114  return m_target;
115 }
116 
117 
118 bool WidgetSnapShot::isIconBigger() const
119 {
120  return m_iconBig;
121 }
122 
123 QPixmap WidgetSnapShot::snapShot() const
124 {
125  return m_snapShot;
126 }
127 
128 }
QWidget
RECURSION_MAX
static const int RECURSION_MAX
Definition: widgetsnapshot.cpp:26
QStyleOptionGraphicsItem
QGraphicsWidget
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:34 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Plasma

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal