diff --git a/widgets/label.cpp b/widgets/label.cpp new file mode 100644 index 000000000..231769716 --- /dev/null +++ b/widgets/label.cpp @@ -0,0 +1,68 @@ +#include "label.h" + +#include +#include + +namespace Plasma { + +class Label::Private +{ + public: + Private() {} + + QString text; +}; + +Label::Label(Widget *parent) + : Widget(parent), + d(new Private) +{ +} + +Label::~Label() +{ +} + +Qt::Orientations Label::expandingDirections() const +{ + return Qt::Horizontal | Qt::Vertical; +} + +bool Label::hasHeightForWidth() const +{ + return true; +} + +qreal Label::heightForWidth(qreal w) const +{ + return 0; +} + +QSizeF Label::sizeHint() const +{ + QFontMetricsF m(QFont("Arial", 12)); + + return m.boundingRect(d->text).size(); +} + +void Label::setText(const QString& text) +{ + d->text = text; +} + +QString Label::text() const +{ + return d->text; +} + +void Label::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option); + Q_UNUSED(widget); + + /* TODO: Add config parameters, like text color, text alignment, and brush. */ + p->setPen(QPen(Qt::black, 1)); + p->drawText(localGeometry(), Qt::AlignCenter | Qt::TextWordWrap, d->text); +} + +} diff --git a/widgets/label.h b/widgets/label.h new file mode 100644 index 000000000..d8d0a2bf8 --- /dev/null +++ b/widgets/label.h @@ -0,0 +1,93 @@ + +/* + * Copyright (C) 2007 by Matias Valdenegro T. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __PLASMA_LABEL__ +#define __PLASMA_LABEL__ + +#include + +class QGraphicsTextItem; + +namespace Plasma +{ + +/** + * Simple Text Label. + * + * @author Matias Valdenegro T. + * + * This class is a simple text label, it just draws plain text. + */ +class PLASMA_EXPORT Label : public Plasma::Widget +{ + public: + + /** + * Constructor. + */ + Label(Widget *parent); + + /** + * Virtual Destructor. + */ + virtual ~Label(); + + /** + * Labels can expand in Horizontal and Vertical directions. + */ + Qt::Orientations expandingDirections() const; + + /** + * Labels can use height-for-width geometry management. + */ + bool hasHeightForWidth() const; + + /** + * Reimplemented from Plasma::Widget. + */ + qreal heightForWidth(qreal w) const; + + /** + * Reimplemented from Plasma::Widget. + */ + QSizeF sizeHint() const; + + /** + * Sets the text to be displayed. + */ + void setText(const QString& text); + + /** + * Returns the displayed text. + */ + QString text() const; + + /** + * Paint function. + */ + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + + private: + class Private; + Private *d; +}; + +} + +#endif /* __PLASMA_LABEL__ */ diff --git a/widgets/layout.h b/widgets/layout.h index 205c300b3..b71009723 100644 --- a/widgets/layout.h +++ b/widgets/layout.h @@ -30,31 +30,90 @@ namespace Plasma /** * Base class for Plasma Layout managers + * + * @author Matias Valdenegro T. + * + * All layout managers must implement this class. Normal users should use the specific layouts, + * like Plasma::VBoxLayout, Plasma::HBoxLayout and Plasma::GridLayout. */ class PLASMA_EXPORT Layout : public LayoutItem { public: + + /** + * Constructor. + */ Layout(LayoutItem *parent); + + /** + * Virtual Destructor. + */ virtual ~Layout(); + /** + * Returns the margin of this Layout. + */ qreal margin() const; + + /** + * Sets the margin of this Layout. + */ void setMargin(qreal m); + /** + * Returns the spacing between Layout elements of this Layout. + */ qreal spacing() const; + + /** + * Sets the spacing of this Layout. + */ void setSpacing(qreal s); + /** + * Returns the parent of this Layout. + */ LayoutItem *parent() const; + /** + * Returns the number of elements of this Layout. + */ virtual int count() const = 0; + + /** + * Returns true if this Layout contains no elements, false otherwise. + */ virtual bool isEmpty() const = 0; - virtual void addItem(LayoutItem *l) = 0; + /** + * Adds a Item to this Layout. + * @param l Pointer to the Item to be added. + */ + virtual void addItem(LayoutItem *l) = 0; + /** + * Removes a Item from this Layout. + * @param l Pointer to the Item to be removed. + */ virtual void removeItem(LayoutItem *l) = 0; + /** + * Returns the index of a Item in this Layout. + * @param l Pointer to an Item to be queryed. + */ virtual int indexOf(LayoutItem *l) const = 0; + + /** + * Returns a Pointer to an Item in this Layout. + * @param i Index of the desired Item. + */ virtual LayoutItem *itemAt(int i) const = 0; + + /** + * Takes the Pointer of an Item in this Layout. + * @param i Index of the desired Item. + */ virtual LayoutItem *takeAt(int i) = 0; private: diff --git a/widgets/layoutitem.h b/widgets/layoutitem.h index 6c366d654..ca4eaae41 100644 --- a/widgets/layoutitem.h +++ b/widgets/layoutitem.h @@ -31,27 +31,78 @@ class Layout; /** * Base class for Plasma layout-managed items + * + * @author Matias Valdenegro T. + * + * All layout-managed items should implement this class, but regular users just need to use + * Plasma::Widget and Plasma::Layout. */ class PLASMA_EXPORT LayoutItem { public: + + /** + * Constructor. + */ LayoutItem(); + + /** + * Virtual Destructor. + */ virtual ~LayoutItem(); + /** + * Returns a bitmask with the directions that this Item can be expanded. + */ virtual Qt::Orientations expandingDirections() const = 0; + /** + * Returns the minimum size of this Item and it's contents. + */ virtual QSizeF minimumSize() const = 0; + + /** + * Returns the maximum size of this Item. + */ virtual QSizeF maximumSize() const = 0; + /** + * Returns true whatever this Item can use height-for-width layout management, + * false otherwise. + */ virtual bool hasHeightForWidth() const; + + /** + * Returns the corresponding height for a given width. + * @param w Width + */ virtual qreal heightForWidth(qreal w) const; + /** + * Returns true whatever this Item can use width-for-height layout management, + * false otherwise. + */ virtual bool hasWidthForHeight() const; + + /** + * Returns the corresponding width for a given height. + * @param h Height + */ virtual qreal widthForHeight(qreal h) const; + /** + * Returns the geometry of this Item. + */ virtual QRectF geometry() const = 0; + + /** + * Sets the geometry of this Item. + */ virtual void setGeometry(const QRectF& geometry) = 0; + /** + * Returns the most appropiate size of this Item to hold whatever contents it has. + */ virtual QSizeF sizeHint() const = 0; /** @@ -73,7 +124,7 @@ class PLASMA_EXPORT LayoutItem void setLayout(Layout* layout); /** - * Returns the layout this item is currently associated with + * Returns the layout this item is currently associated with. */ Layout* layout(); diff --git a/widgets/pushbutton.cpp b/widgets/pushbutton.cpp index aafc71371..2884099b4 100644 --- a/widgets/pushbutton.cpp +++ b/widgets/pushbutton.cpp @@ -24,7 +24,9 @@ #include #include #include -#include +#include +#include + #include "pushbutton.moc" namespace Plasma @@ -43,37 +45,28 @@ class PushButton::Private QSize iconSize; bool hasIcon; int labelTextOpacity; - int height; - int width; - int maxWidth; - int minWidth; - int minHeight; - int maxHeight; int radius; - QTimer * updateTimer; + QTimer *updateTimer; PushButton::ButtonState state; }; -PushButton::PushButton(QGraphicsItem *parent) +PushButton::PushButton(Widget *parent) : QObject(), - QGraphicsItem(parent), - QLayoutItem (Qt::AlignHCenter), + Widget(parent), d(new Private) { setAcceptedMouseButtons(Qt::LeftButton); setAcceptsHoverEvents(true); setEnabled(true); - d->height = 40; - d->width = 100 ; - d->minWidth = d->width; - d->maxWidth = d->width; - d->minHeight = d->height; - d->maxHeight = d->height; + resize(40.0f, 100.0f); setPos(QPointF(0.0,0.0)); + + /*FIXME: Don't use hardcoded strings and colors. */ + d->state = PushButton::None; d->labelText = QString("Plasma"); - d->labelTextColor = QColor(201,201,255); + d->labelTextColor = QColor(201, 201, 255); d->hasIcon = false; d->iconSize = QSize(32,32); } @@ -88,11 +81,6 @@ void PushButton::updated(const QString&, const DataEngine::Data &data) Q_UNUSED(data) } -QRectF PushButton::boundingRect() const -{ - return QRectF(0, 0, d->width, d->height); -} - void PushButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QStyleOptionButton options; @@ -110,7 +98,7 @@ void PushButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option widget->style()->drawPrimitive(QStyle::PE_PanelButtonCommand, &options, painter, widget); widget->style()->drawPrimitive(QStyle::PE_FrameFocusRect, &options, painter, widget); - widget-> style()->drawControl(QStyle::CE_PushButton, &options, painter, widget); + widget->style()->drawControl(QStyle::CE_PushButton, &options, painter, widget); } void PushButton::setText(const QString& text) @@ -127,39 +115,11 @@ void PushButton::setText(const QString& text) } - QString PushButton::text() const { return d->labelText; } -int PushButton::height() const -{ - return d->height; -} - -int PushButton::width() const -{ - return d->width; -} - -void PushButton::setHeight(int h) -{ - prepareGeometryChange(); - d->height = h; - update(); -} - -void PushButton::setWidth(int w) -{ - if (!(w >= d->maxWidth)) - { - prepareGeometryChange (); - d->width = w; - update(); - } -} - void PushButton::setIcon(const QString& path) { if (!path.isNull()) @@ -173,25 +133,6 @@ void PushButton::setIcon(const QString& path) d->hasIcon = false; } -QSize PushButton::size() const -{ - return QSize(d->width, d->height); -} - -void PushButton::setSize(const QSize& s) -{ - prepareGeometryChange(); - if (!d->maxWidth >= s.width()) - d->width = s.width(); - d->height = s.height(); - update(); -} - -void PushButton::setMaximumWidth(int w) -{ - d->maxWidth= w; -} - bool PushButton::isDown() { if (d->state == PushButton::Pressed) @@ -199,7 +140,7 @@ bool PushButton::isDown() return false; } -void PushButton::mousePressEvent ( QGraphicsSceneMouseEvent * event ) +void PushButton::mousePressEvent(QGraphicsSceneMouseEvent *event) { event->accept(); d->state = PushButton::Pressed; @@ -207,7 +148,7 @@ void PushButton::mousePressEvent ( QGraphicsSceneMouseEvent * event ) // emit clicked(); } -void PushButton::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) +void PushButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { event->accept(); if (d->state == PushButton::Pressed) @@ -216,37 +157,28 @@ void PushButton::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) update(); } -QSize PushButton::sizeHint() const +QSizeF PushButton::sizeHint() const { - return QSize(d->width,d->height); + return minimumSize(); } -QSize PushButton::minimumSize() const +QSizeF PushButton::minimumSize() const { - return QSize(d->minWidth,d->minHeight); + QFontMetricsF m = qApp->fontMetrics(); + + return m.boundingRect(text()).size(); } -QSize PushButton::maximumSize() const +QSizeF PushButton::maximumSize() const { - return QSize(d->maxWidth,d->maxHeight); + return QSizeF(); } -Qt::Orientations PushButton::expandingDirections() const +Qt::Orientations PushButton::expandingDirections() const { return Qt::Horizontal; } -void PushButton::setGeometry(const QRect & r) -{ - setSize(r.size()); - setPos(r.x(),r.y()); -} - -QRect PushButton::geometry() const -{ - return boundingRect().toRect(); -} - bool PushButton::isEmpty() const { return false; diff --git a/widgets/pushbutton.h b/widgets/pushbutton.h index 91b8eb337..1da65f60b 100644 --- a/widgets/pushbutton.h +++ b/widgets/pushbutton.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2007 by Siraj Razick siraj@kde.org + * and Matias Valdenegro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as @@ -24,20 +25,24 @@ #include #include +#include #include -//TODO -//Please Document this class - namespace Plasma { /** - * Class that emulates a QPushButton inside plasma + * Class that emulates a QPushButton inside Plasma + * + * @author Siraj Razick and Matias Valdenegro. + * + * */ -class PLASMA_EXPORT PushButton : public QObject, public QGraphicsItem, public QLayoutItem +class PLASMA_EXPORT PushButton : public QObject, + public Plasma::Widget { Q_OBJECT + public: enum ButtonShape { @@ -55,37 +60,68 @@ class PLASMA_EXPORT PushButton : public QObject, public QGraphicsItem, public QL }; public: - PushButton(QGraphicsItem *parent = 0); + + /** + * Constructor. + */ + PushButton(Widget *parent = 0); + + /** + * Virtual Destructor. + */ virtual ~PushButton(); + /** + * Returns the text of this Button. + */ QString text() const; - void setText(const QString &name); - QSize size() const; - void setSize(const QSize& size); - - int height() const; - void setHeight(int height); - - int width() const; - void setWidth(int width); + /** + * Sets the text of this Button. + */ + void setText(const QString &text); + /** + * Sets the icon of this Button. + * @param path Path to the icon file. TODO : WTF is path? + */ void setIcon(const QString& path); - void setMaximumWidth(int maxwidth); + /** + * Paint function. + */ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); - virtual QRectF boundingRect() const; - //layout stufff - virtual QSize sizeHint() const ; - virtual QSize minimumSize() const; - virtual QSize maximumSize() const ; + /** + * Reimplemented from Plasma::Widget. + */ + virtual QSizeF sizeHint() const ; + + /** + * Reimplemented from Plasma::Widget. + */ + virtual QSizeF minimumSize() const; + + /** + * Reimplemented from Plasma::Widget. + */ + virtual QSizeF maximumSize() const ; + + /** + * Buttons prefer to expand in Horizontal direction. + */ virtual Qt::Orientations expandingDirections() const; - virtual void setGeometry(const QRect& r); - virtual QRect geometry() const ; + + /** + * TODO: What does this function do? + */ virtual bool isEmpty() const; Q_SIGNALS: + + /** + * Triggers whatever this button is clicked. + */ void clicked(); public Q_SLOTS: diff --git a/widgets/rectangle.cpp b/widgets/rectangle.cpp new file mode 100644 index 000000000..0426d7e9d --- /dev/null +++ b/widgets/rectangle.cpp @@ -0,0 +1,34 @@ +#include "rectangle.h" + +#include + +namespace Plasma { + +Rectangle::Rectangle(Widget *parent) + : Widget(parent) +{ + resize(400.0f, 400.0f); + setFlag(QGraphicsItem::ItemIsMovable); +} + +Rectangle::~Rectangle() +{ +} + +Qt::Orientations Rectangle::expandingDirections() const +{ + return Qt::Horizontal | Qt::Vertical; +} + +void Rectangle::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option); + Q_UNUSED(widget); + + p->setBrush(Qt::white); + p->setPen(Qt::black); + p->setOpacity(0.5f); + p->drawRect(localGeometry()); +} + +} diff --git a/widgets/rectangle.h b/widgets/rectangle.h new file mode 100644 index 000000000..b43e9c6a1 --- /dev/null +++ b/widgets/rectangle.h @@ -0,0 +1,20 @@ +#include + +namespace Plasma { + +class PLASMA_EXPORT Rectangle : public Plasma::Widget +{ + public: + Rectangle(Widget *parent); + virtual ~Rectangle(); + + Qt::Orientations expandingDirections() const; + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + + private: + class Private; + Private const *d; +}; + +} diff --git a/widgets/vboxlayout.cpp b/widgets/vboxlayout.cpp index c1e1e7c2a..1c646586c 100644 --- a/widgets/vboxlayout.cpp +++ b/widgets/vboxlayout.cpp @@ -84,11 +84,11 @@ QRectF VBoxLayout::geometry() const void VBoxLayout::setGeometry(const QRectF& geometry) { if (!geometry.isValid() || geometry.isEmpty()) { - kDebug() << "Invalid Geometry!" << endl; + kDebug() << "Invalid Geometry " << geometry << endl; return; } - qDebug("Geometry %p : %f, %f by %f, %f", this, geometry.x(), geometry.y(), geometry.width(), geometry.height()); + kDebug() << this << " Geometry process " << geometry << " for " << d->childList.count() << " childrens"<< endl; QList children; QList expandingChildren; @@ -118,13 +118,16 @@ void VBoxLayout::setGeometry(const QRectF& geometry) sizes.insert(indexOf(l),QSizeF(available.width(), expandHeight)); } - QPointF start = geometry.topLeft(); + //QPointF start = geometry.topLeft(); + QPointF start = QPointF(0.0f, 0.0f); start += QPointF(margin(), spacing()); for (int i = 0; i < sizes.size(); i++) { LayoutItem *l = itemAt(i); + kDebug() << "Setting Geometry for child " << l << " to " << QRectF(start, sizes[i]) << endl; + l->setGeometry(QRectF(start, sizes[i])); start += QPointF(0.0, sizes[i].height() + spacing()); } diff --git a/widgets/vboxlayout.h b/widgets/vboxlayout.h index 00ead7d65..18dcc24c8 100644 --- a/widgets/vboxlayout.h +++ b/widgets/vboxlayout.h @@ -31,11 +31,23 @@ namespace Plasma /** * Vertical Box Layout + * + * @author Matias Valdenegro T. + * + * This class implements a Vertical Box Layout, it just lays items in vertical, from up to down. */ class PLASMA_EXPORT VBoxLayout : public Layout { public: + + /** + * Constructor. + */ VBoxLayout(LayoutItem *parent = 0); + + /** + * Virtual Destructor. + */ virtual ~VBoxLayout(); Qt::Orientations expandingDirections() const; diff --git a/widgets/widget.cpp b/widgets/widget.cpp index 63f6d581e..b235a7bef 100644 --- a/widgets/widget.cpp +++ b/widgets/widget.cpp @@ -20,6 +20,8 @@ #include "widget.h" +#include + #include #include "layout.h" @@ -36,7 +38,7 @@ class Widget::Private { } ~Private() { } - QRectF geometry; + QSizeF size; Widget *parent; Layout *layout; @@ -47,11 +49,11 @@ Widget::Widget(QGraphicsItem *parent) : QGraphicsItem(parent), d(new Private) { - d->parent = dynamic_cast(parent); + d->parent = dynamic_cast(parent); if (d->parent) { d->parent->addChild(this); - d->parent->setGeometry(QRectF(QPointF(0.0, 0.0), d->parent->size())); + d->parent->invalidate(); } } @@ -101,14 +103,20 @@ qreal Widget::widthForHeight(qreal h) const QRectF Widget::geometry() const { - return d->geometry; + return QRectF(pos(), size()); +} + +QRectF Widget::localGeometry() const +{ + return QRectF(QPointF(0.0f, 0.0f), size()); } void Widget::setGeometry(const QRectF& geometry) { prepareGeometryChange(); - d->geometry = geometry; + setPos(geometry.topLeft()); + d->size = geometry.size(); updateGeometry(); update(); @@ -117,12 +125,17 @@ void Widget::setGeometry(const QRectF& geometry) void Widget::updateGeometry() { if (layout()) { - layout()->setGeometry(QRectF(QPointF(0.0, 0.0), size())); + + kDebug() << (void *) this << " updating geometry to " << size() << endl; + + layout()->setGeometry(geometry()); } } void Widget::invalidate() { + setGeometry(geometry()); + updateGeometry(); if (parent()) { @@ -137,17 +150,17 @@ QSizeF Widget::sizeHint() const QSizeF Widget::size() const { - return geometry().size(); + return d->size; } QRectF Widget::boundingRect() const { - return geometry(); + return QRectF(QPointF(0.0f, 0.0f), size()); } void Widget::resize(const QSizeF& size) { - setGeometry(QRectF(d->geometry.topLeft(), size)); + setGeometry(QRectF(pos(), size)); } void Widget::resize(qreal w, qreal h) @@ -157,7 +170,11 @@ void Widget::resize(qreal w, qreal h) void Widget::setLayout(Layout *l) { - d->layout = l; + if(!d->layout) { + d->layout = l; + } else { + kDebug() << "Widget " << this << "already has a layout!" << endl; + } } Layout *Widget::layout() const @@ -189,9 +206,10 @@ void Widget::addChild(Widget *w) void Widget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - Q_UNUSED(painter) - Q_UNUSED(option) - Q_UNUSED(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 } diff --git a/widgets/widget.h b/widgets/widget.h index 0e6dd1d97..8833ac70f 100644 --- a/widgets/widget.h +++ b/widgets/widget.h @@ -34,49 +34,152 @@ namespace Plasma class Layout; /** - * Class that emulates a QWidget inside plasma + * Base class for all Widgets in Plasma. + * + * @author Alexander Wiedenbruch and Matias Valdenegro. + * + * Widgets are the basis for User Interfaces inside Plasma. + * Widgets are rectangular, but can be in any visible shape by just using transparency to mask + * out non-rectangular areas. + * + * To implement a Widget, just subclass Plasma::Widget and implement at minimum, sizeHint() and paint() */ -class PLASMA_EXPORT Widget : public QGraphicsItem, public LayoutItem +class PLASMA_EXPORT Widget : public QGraphicsItem, + public LayoutItem { -public: - explicit Widget(QGraphicsItem *parent = 0); - virtual ~Widget(); + public: - virtual Qt::Orientations expandingDirections() const; + /** + * Constructor. + */ + explicit Widget(QGraphicsItem *parent = 0); - virtual QSizeF minimumSize() const; - virtual QSizeF maximumSize() const; + /** + * Virtual Destructor. + */ + virtual ~Widget(); - virtual bool hasHeightForWidth() const; - virtual qreal heightForWidth(qreal w) const; + /** + * Returns a bitmask with the directions that this Widget can be expanded. + */ + virtual Qt::Orientations expandingDirections() const; - virtual bool hasWidthForHeight() const; - virtual qreal widthForHeight(qreal h) const; + /** + * Returns the minimum size of this Widget and it's contents. + */ + virtual QSizeF minimumSize() const; - QRectF geometry() const; - void setGeometry(const QRectF &geometry); + /** + * Returns the maximum size of this Widget. + */ + virtual QSizeF maximumSize() const; - void updateGeometry(); + /** + * Returns true whatever this Widget can use height-for-width layout management, + * false otherwise. + */ + virtual bool hasHeightForWidth() const; - virtual void invalidate(); + /** + * Returns the corresponding height for a given width. + * @param w Width + */ + virtual qreal heightForWidth(qreal w) const; - virtual QSizeF sizeHint() const; + /** + * Returns true whatever this Widget can use width-for-height layout management, + * false otherwise. + */ + virtual bool hasWidthForHeight() const; - QSizeF size() const; + /** + * Returns the corresponding width for a given height. + * @param h Height + */ + virtual qreal widthForHeight(qreal h) const; - virtual QRectF boundingRect() const; + /** + * Returns the geometry of this Widget, in parent coordinates. + */ + QRectF geometry() const; - void resize(const QSizeF &size); - void resize(qreal w, qreal h); + /** + * Returns the geometry of this Widget, in local coordinates. + */ + QRectF localGeometry() const; - void setLayout(Layout *l); - Layout *layout() const; + /** + * Sets the geometry of this Widget. + */ + void setGeometry(const QRectF &geometry); - Widget *parent() const; - void reparent(Widget *w); + /** + * Propagates the geometry information to associated layouts and other Widgets. + */ + void updateGeometry(); - void addChild(Widget *w); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + /** + * Invalidates the geometry information. + */ + virtual void invalidate(); + + /** + * Returns the most appropiate size of this Widget to hold it's contents. + */ + virtual QSizeF sizeHint() const; + + /** + * Returns the size of this Widget. + */ + QSizeF size() const; + + /** + * Returns the bounding rectangle of this Widget. + */ + virtual QRectF boundingRect() const; + + /** + * Resizes this Widget. + * @param size New size + */ + void resize(const QSizeF &size); + + /** + * Resizes this Widget. + * @param w New width + * @param h New height + */ + void resize(qreal w, qreal h); + + /** + * Sets the Layout that will manage this Widget's childrens. + */ + void setLayout(Layout *l); + + /** + * Returns the Layout associated with this Widget. + */ + Layout *layout() const; + + /** + * Returns the parent of this Widget. + */ + Widget *parent() const; + + /** + * Changes the parent of this Widget. + */ + void reparent(Widget *w); + + /** + * Appends a child Widget to this Widget. + */ + void addChild(Widget *w); + + /** + * Paint function. Reimplement to draw on this Widget. + */ + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); private: class Private;