Add a method to change the parent of a layout. Make isEmpty() non-virtual, and instead always equal to (count()==0). Add invalidate() method which is used like the method of the same name in QLayout to invalidate cached information in the layout.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=706937
This commit is contained in:
Robert Knight 2007-08-31 15:27:32 +00:00
parent af8659fa22
commit f7861353ba
2 changed files with 50 additions and 4 deletions

View File

@ -21,6 +21,9 @@
#include <math.h> #include <math.h>
#include <QtCore/QList> #include <QtCore/QList>
#include <QtDebug>
#include "widget.h"
namespace Plasma namespace Plasma
{ {
@ -52,6 +55,10 @@ Layout::Layout(LayoutItem *parent)
{ {
} }
void Layout::setParent(LayoutItem *parent) {
d->parent = parent;
}
Layout::~Layout() Layout::~Layout()
{ {
if (parent()) { if (parent()) {
@ -60,11 +67,41 @@ Layout::~Layout()
delete d; delete d;
} }
bool Layout::isEmpty() const
{
return count() == 0;
}
void Layout::update() void Layout::update()
{ {
// this will force an update
setGeometry( parent()->geometry() ); setGeometry(geometry());
} }
void Layout::invalidate()
{
//qDebug() << "Layout update";
LayoutItem *item = parent();
while ( item ) {
//qDebug() << "Looking at item " << item;
Widget *widget = dynamic_cast<Widget*>(item);
if ( widget ) {
//qDebug() << "Parent widget found and invalidated";
widget->updateGeometry();
break;
}
else {
Layout *layout = dynamic_cast<Layout*>(item);
if ( layout ) {
item = layout->parent();
// qDebug() << "Item is a layout";
}
else
item = 0;
}
}
}
LayoutAnimator* Layout::animator() const LayoutAnimator* Layout::animator() const
{ {

View File

@ -78,6 +78,11 @@ class PLASMA_EXPORT Layout : public LayoutItem
*/ */
LayoutItem *parent() const; LayoutItem *parent() const;
/**
* Sets the parent of this layout.
*/
void setParent(LayoutItem *parent);
/** /**
* Returns the number of elements of this Layout. * Returns the number of elements of this Layout.
*/ */
@ -86,7 +91,7 @@ class PLASMA_EXPORT Layout : public LayoutItem
/** /**
* Returns true if this Layout contains no elements, false otherwise. * Returns true if this Layout contains no elements, false otherwise.
*/ */
virtual bool isEmpty() const = 0; bool isEmpty() const;
/** /**
* Adds a Item to this Layout. * Adds a Item to this Layout.
@ -143,6 +148,10 @@ class PLASMA_EXPORT Layout : public LayoutItem
* implementation allows unlimited resizing. * implementation allows unlimited resizing.
*/ */
virtual QSizeF maximumSize() const; virtual QSizeF maximumSize() const;
/** TODO Document me */
void invalidate();
private: private:
class Private; class Private;
Private *const d; Private *const d;