Making sure that recursion will not go beyond 20 levels.

svn path=/trunk/KDE/kdelibs/; revision=1070481
This commit is contained in:
Adenilson Cavalcanti Da Silva 2010-01-05 18:55:45 +00:00
parent 8fb2ea1980
commit 8c356fa8c1
2 changed files with 9 additions and 3 deletions

View File

@ -20,12 +20,14 @@
#include <QImage> #include <QImage>
#include <QPixmap> #include <QPixmap>
#include <QStyleOptionGraphicsItem> #include <QStyleOptionGraphicsItem>
static const int RECURSION_MAX = 20;
namespace Plasma namespace Plasma
{ {
ShadowFake::ShadowFake(QGraphicsItem *parent) ShadowFake::ShadowFake(QGraphicsItem *parent)
: QGraphicsWidget(parent), : QGraphicsWidget(parent),
stack(0),
m_target(0) m_target(0)
{ {
} }
@ -46,22 +48,25 @@ void ShadowFake::paintSubChildren(QPainter *painter,
const QStyleOptionGraphicsItem *option, const QStyleOptionGraphicsItem *option,
QGraphicsItem *target) QGraphicsItem *target)
{ {
++stack;
QList<QGraphicsItem *> list = target->childItems(); QList<QGraphicsItem *> list = target->childItems();
QGraphicsItem *tmp; QGraphicsItem *tmp;
if (list.size() > 0) { if (list.size() > 0) {
for (int i = 0; i < list.size(); ++i) { for (int i = 0; i < list.size(); ++i) {
tmp = list.value(i); tmp = list.value(i);
if (tmp->childItems().size() > 0) { if ((tmp->childItems().size() > 0) && (stack < RECURSION_MAX)) {
paintSubChildren(painter, option, tmp); paintSubChildren(painter, option, tmp);
} else {
tmp->paint(painter, option, 0);
} }
tmp->paint(painter, option, 0);
} }
} }
--stack;
} }
void ShadowFake::setTarget(QGraphicsWidget *target) void ShadowFake::setTarget(QGraphicsWidget *target)
{ {
stack = 0;
m_target = target; m_target = target;
setParentItem(target); setParentItem(target);
resize(target->size()); resize(target->size());

View File

@ -42,6 +42,7 @@ private:
void paintSubChildren(QPainter *painter, void paintSubChildren(QPainter *painter,
const QStyleOptionGraphicsItem *option, const QStyleOptionGraphicsItem *option,
QGraphicsItem *target); QGraphicsItem *target);
int stack;
QPixmap m_photo; QPixmap m_photo;
QGraphicsWidget *m_target; QGraphicsWidget *m_target;
}; };