- make it possible to instantiate a Plasma::Widget itself (implement all pure virtuals from QGraphicsItem)

- allow parenting it to a QGraphicsItem

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=687019
This commit is contained in:
Aaron J. Seigo 2007-07-12 18:11:50 +00:00
parent ac35242c5d
commit b82624429e
2 changed files with 22 additions and 11 deletions

View File

@ -30,7 +30,10 @@ namespace Plasma
class Widget::Private class Widget::Private
{ {
public: public:
Private() : parent(0) { } Private()
: parent(0),
layout(0)
{ }
~Private() { } ~Private() { }
QRectF geometry; QRectF geometry;
@ -40,17 +43,15 @@ class Widget::Private
QList<Widget *> childList; QList<Widget *> childList;
}; };
Widget::Widget(QGraphicsItem *parent)
Widget::Widget(Widget *parent)
: QGraphicsItem(parent), : QGraphicsItem(parent),
d(new Private) d(new Private)
{ {
d->parent = parent; d->parent = dynamic_cast<Widget*>(parent);
d->layout = 0;
if (parent) { if (d->parent) {
parent->addChild(this); d->parent->addChild(this);
parent->setGeometry(QRectF(QPointF(0.0, 0.0), parent->size())); d->parent->setGeometry(QRectF(QPointF(0.0, 0.0), d->parent->size()));
} }
} }
@ -186,6 +187,15 @@ void Widget::addChild(Widget *w)
} }
} }
void Widget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(painter)
Q_UNUSED(option)
Q_UNUSED(widget)
// do nothing, but we need to reimp so we can create Widget items as this method
// is pure virtual in QGraphicsItem
}
void Widget::reparent(Widget *w) void Widget::reparent(Widget *w)
{ {
d->parent = w; d->parent = w;

View File

@ -39,7 +39,7 @@ class Layout;
class PLASMA_EXPORT Widget : public QGraphicsItem, public LayoutItem class PLASMA_EXPORT Widget : public QGraphicsItem, public LayoutItem
{ {
public: public:
Widget(Widget *parent = 0); explicit Widget(QGraphicsItem *parent = 0);
virtual ~Widget(); virtual ~Widget();
virtual Qt::Orientations expandingDirections() const; virtual Qt::Orientations expandingDirections() const;
@ -76,6 +76,7 @@ public:
void reparent(Widget *w); void reparent(Widget *w);
void addChild(Widget *w); void addChild(Widget *w);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
private: private:
class Private; class Private;