2007-03-01 20:58:19 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 by Alexander Wiedenbruch <mail@wiedenbruch.de>
|
2007-05-22 18:48:34 +02:00
|
|
|
* and Matias Valdenegro <mvaldenegro@informatica.utem.cl>
|
2007-03-01 20:58:19 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2007-05-22 18:48:34 +02:00
|
|
|
|
2007-05-30 18:47:36 +02:00
|
|
|
#include "widget.h"
|
|
|
|
|
2007-05-23 19:18:43 +02:00
|
|
|
#include <QtCore/QList>
|
|
|
|
|
2007-05-22 18:48:34 +02:00
|
|
|
#include "layout.h"
|
2007-03-01 20:58:19 +01:00
|
|
|
|
2007-03-02 06:27:33 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2007-03-03 14:13:39 +01:00
|
|
|
class Widget::Private
|
|
|
|
{
|
|
|
|
public:
|
2007-05-22 18:48:34 +02:00
|
|
|
Private() : parent(0) { }
|
2007-03-20 15:21:56 +01:00
|
|
|
~Private() { }
|
2007-05-22 18:48:34 +02:00
|
|
|
|
|
|
|
QRectF geometry;
|
|
|
|
|
|
|
|
Widget *parent;
|
|
|
|
Layout *layout;
|
|
|
|
QList<Widget *> childList;
|
2007-03-03 14:13:39 +01:00
|
|
|
};
|
2007-03-01 20:58:19 +01:00
|
|
|
|
2007-03-03 14:13:39 +01:00
|
|
|
|
2007-05-22 18:48:34 +02:00
|
|
|
Widget::Widget(Widget *parent)
|
2007-05-25 04:27:33 +02:00
|
|
|
: QGraphicsItem(parent),
|
2007-03-03 14:13:39 +01:00
|
|
|
d(new Private)
|
2007-03-01 20:58:19 +01:00
|
|
|
{
|
2007-05-22 18:48:34 +02:00
|
|
|
d->parent = parent;
|
|
|
|
d->layout = 0;
|
|
|
|
|
|
|
|
if(parent) {
|
|
|
|
parent->addChild(this);
|
|
|
|
parent->setGeometry(QRectF(QPointF(0.0, 0.0), parent->size()));
|
|
|
|
}
|
2007-03-01 20:58:19 +01:00
|
|
|
}
|
|
|
|
|
2007-03-03 14:13:39 +01:00
|
|
|
Widget::~Widget()
|
2007-03-01 20:58:19 +01:00
|
|
|
{
|
2007-03-03 14:13:39 +01:00
|
|
|
delete d;
|
2007-03-01 20:58:19 +01:00
|
|
|
}
|
2007-03-02 06:27:33 +01:00
|
|
|
|
2007-05-22 18:48:34 +02:00
|
|
|
Qt::Orientations Widget::expandingDirections() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF Widget::maximumSize() const
|
|
|
|
{
|
|
|
|
return QSizeF();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF Widget::minimumSize() const
|
|
|
|
{
|
|
|
|
return QSizeF(0.0, 0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Widget::hasHeightForWidth() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal Widget::heightForWidth(qreal w) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(w);
|
|
|
|
|
|
|
|
return -1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Widget::hasWidthForHeight() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal Widget::widthForHeight(qreal h) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(h);
|
|
|
|
|
|
|
|
return -1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF Widget::geometry() const
|
|
|
|
{
|
|
|
|
return d->geometry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::setGeometry(const QRectF& geometry)
|
|
|
|
{
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
|
|
|
d->geometry = geometry;
|
|
|
|
|
|
|
|
updateGeometry();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::updateGeometry()
|
|
|
|
{
|
|
|
|
if(layout()) {
|
|
|
|
layout()->setGeometry(QRectF(QPointF(0.0, 0.0), size()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::invalidate()
|
|
|
|
{
|
|
|
|
updateGeometry();
|
|
|
|
|
|
|
|
if(parent()) {
|
|
|
|
parent()->updateGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF Widget::sizeHint() const
|
|
|
|
{
|
|
|
|
return QSizeF(0.0, 0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF Widget::size() const
|
|
|
|
{
|
|
|
|
return geometry().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF Widget::boundingRect() const
|
|
|
|
{
|
|
|
|
return geometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::resize(const QSizeF& size)
|
|
|
|
{
|
|
|
|
setGeometry(QRectF(d->geometry.topLeft(), size));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::resize(qreal w, qreal h)
|
|
|
|
{
|
|
|
|
resize(QSizeF(w, h));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::setLayout(Layout *l)
|
|
|
|
{
|
|
|
|
d->layout = l;
|
|
|
|
}
|
|
|
|
|
|
|
|
Layout *Widget::layout() const
|
|
|
|
{
|
|
|
|
return d->layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget *Widget::parent() const
|
|
|
|
{
|
|
|
|
return d->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::addChild(Widget *w)
|
|
|
|
{
|
|
|
|
if(!w) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
w->reparent(this);
|
|
|
|
d->childList.append(w);
|
|
|
|
|
2007-05-22 21:23:22 +02:00
|
|
|
qDebug("Added Child Widget : %p", (void*)w);
|
2007-05-22 18:48:34 +02:00
|
|
|
|
|
|
|
if(layout()) {
|
|
|
|
|
|
|
|
layout()->addItem(w);
|
|
|
|
|
|
|
|
updateGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::reparent(Widget *w)
|
|
|
|
{
|
|
|
|
d->parent = w;
|
2007-05-25 04:27:33 +02:00
|
|
|
setParentItem(w);
|
2007-05-22 18:48:34 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2007-03-02 06:27:33 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|