diff --git a/widgets/widget.cpp b/widgets/widget.cpp index 1b8c6cba3..14303eaa8 100644 --- a/widgets/widget.cpp +++ b/widgets/widget.cpp @@ -288,12 +288,13 @@ Widget *Widget::parent() const void Widget::addChild(Widget *w) { - if (!w) { + if (!w || w->parent() == this) { return; } - w->reparent(this); d->childList.append(w); + w->d->parent = this; + w->setParentItem(this); //kDebug() << "Added Child Widget" << w; @@ -301,6 +302,7 @@ void Widget::addChild(Widget *w) layout()->addItem(w); updateGeometry(); } + w->update(); } void Widget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) @@ -437,11 +439,17 @@ void Widget::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *opti // Replaced by widget's own function } -void Widget::reparent(Widget *w) +QVariant Widget::itemChange(GraphicsItemChange change, const QVariant &value) { - d->parent = w; - setParentItem(w); - update(); + if (change == QGraphicsItem::ItemChildRemovedChange) { + Widget *child = dynamic_cast(value.value()); + if (child) { + d->childList.removeAll(child); + updateGeometry(); + } + } + + return QGraphicsItem::itemChange(change, value); } void Widget::managingLayoutChanged() diff --git a/widgets/widget.h b/widgets/widget.h index cf66f94d7..e8beeeca7 100644 --- a/widgets/widget.h +++ b/widgets/widget.h @@ -211,12 +211,6 @@ TODO: implement once we decide how to handle the font system */ Q_INVOKABLE Widget *parent() const; - /** - * Sets the parent of this Plasma::Widget; - * @param widget the widget to reparent to. - */ - Q_INVOKABLE void reparent(Widget *widget); - /** * Add another Plasma::Widget as a child of this one. * @param widget the widget to reparent to this Plasma::Widget. @@ -256,6 +250,7 @@ protected: * @param widget the parent QWidget (most likely the Corona) */ virtual void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + QVariant itemChange(GraphicsItemChange change, const QVariant &value); void setSize(const QSizeF& size); void managingLayoutChanged();