get rid of reparent() as that is completely superceded by addChild, and catch when children items no longer belong to us.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=730877
This commit is contained in:
Aaron J. Seigo 2007-10-29 23:10:45 +00:00
parent f846464288
commit 5b10495cf4
2 changed files with 15 additions and 12 deletions

View File

@ -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<Plasma::Widget*>(value.value<QGraphicsItem*>());
if (child) {
d->childList.removeAll(child);
updateGeometry();
}
}
return QGraphicsItem::itemChange(change, value);
}
void Widget::managingLayoutChanged()

View File

@ -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();