2007-09-13 07:40:37 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2007 by Robert Knight <robertknight@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-09-14 22:17:11 +02:00
|
|
|
* it under the terms of the GNU Library General Public License as
|
2007-09-14 21:06:18 +02:00
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
2007-09-13 07:40:37 +02:00
|
|
|
*
|
|
|
|
* 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-09-10 22:38:59 +02:00
|
|
|
#include "freelayout.h"
|
|
|
|
|
2007-11-11 00:13:42 +01:00
|
|
|
#include <KDebug>
|
|
|
|
|
|
|
|
#include <plasma/widgets/layout.h>
|
|
|
|
|
2007-09-13 07:40:37 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
2007-09-10 22:38:59 +02:00
|
|
|
|
|
|
|
class FreeLayout::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QList<LayoutItem*> children;
|
|
|
|
};
|
|
|
|
|
|
|
|
FreeLayout::FreeLayout(LayoutItem *parent)
|
2007-09-13 07:40:37 +02:00
|
|
|
: Layout(parent),
|
|
|
|
d(new Private)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FreeLayout::~FreeLayout()
|
2007-09-10 22:38:59 +02:00
|
|
|
{
|
2007-09-13 07:40:37 +02:00
|
|
|
delete d;
|
2007-09-10 22:38:59 +02:00
|
|
|
}
|
2007-09-13 07:40:37 +02:00
|
|
|
|
2007-09-10 22:38:59 +02:00
|
|
|
Qt::Orientations FreeLayout::expandingDirections() const
|
|
|
|
{
|
|
|
|
return Qt::Horizontal | Qt::Vertical;
|
|
|
|
}
|
2007-09-13 07:40:37 +02:00
|
|
|
|
2007-09-10 22:38:59 +02:00
|
|
|
void FreeLayout::addItem(LayoutItem *item)
|
|
|
|
{
|
2007-11-19 23:04:30 +01:00
|
|
|
if (d->children.contains(item)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-09-10 22:38:59 +02:00
|
|
|
d->children << item;
|
|
|
|
item->setManagingLayout(this);
|
|
|
|
}
|
2007-09-13 07:40:37 +02:00
|
|
|
|
2007-09-10 22:38:59 +02:00
|
|
|
void FreeLayout::removeItem(LayoutItem *item)
|
|
|
|
{
|
|
|
|
d->children.removeAll(item);
|
2007-11-19 23:04:30 +01:00
|
|
|
item->unsetManagingLayout(this);
|
2007-09-10 22:38:59 +02:00
|
|
|
}
|
2007-09-13 07:40:37 +02:00
|
|
|
|
2007-09-10 22:38:59 +02:00
|
|
|
int FreeLayout::indexOf(LayoutItem *item) const
|
|
|
|
{
|
|
|
|
return d->children.indexOf(item);
|
|
|
|
}
|
2007-09-13 07:40:37 +02:00
|
|
|
|
2007-09-10 22:38:59 +02:00
|
|
|
LayoutItem * FreeLayout::itemAt(int i) const
|
|
|
|
{
|
|
|
|
return d->children[i];
|
|
|
|
}
|
2007-09-13 07:40:37 +02:00
|
|
|
|
2007-09-10 22:38:59 +02:00
|
|
|
int FreeLayout::count() const
|
|
|
|
{
|
|
|
|
return d->children.count();
|
|
|
|
}
|
2007-09-13 07:40:37 +02:00
|
|
|
|
|
|
|
LayoutItem * FreeLayout::takeAt(int i)
|
2007-09-10 22:38:59 +02:00
|
|
|
{
|
|
|
|
return d->children.takeAt(i);
|
|
|
|
}
|
2007-09-13 07:40:37 +02:00
|
|
|
|
2007-11-17 19:53:16 +01:00
|
|
|
void FreeLayout::setGeometry(const QRectF &)
|
2007-09-10 22:38:59 +02:00
|
|
|
{
|
2007-09-13 07:40:37 +02:00
|
|
|
foreach (LayoutItem *child , d->children) {
|
2007-09-15 06:16:11 +02:00
|
|
|
if (child->geometry().size() != child->sizeHint()) {
|
2007-11-17 19:53:16 +01:00
|
|
|
child->setGeometry(QRectF(child->geometry().topLeft(), child->sizeHint()));
|
2007-09-15 06:16:11 +02:00
|
|
|
}
|
2007-09-10 22:38:59 +02:00
|
|
|
}
|
|
|
|
}
|
2007-09-13 07:40:37 +02:00
|
|
|
|
2007-09-10 22:38:59 +02:00
|
|
|
QRectF FreeLayout::geometry() const
|
|
|
|
{
|
2007-11-17 19:53:16 +01:00
|
|
|
if (parent()) {
|
|
|
|
return parent()->geometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QRectF(QPointF(0, 0), maximumSize());
|
2007-09-10 22:38:59 +02:00
|
|
|
}
|
2007-09-13 07:40:37 +02:00
|
|
|
|
2007-09-10 22:38:59 +02:00
|
|
|
QSizeF FreeLayout::sizeHint() const
|
|
|
|
{
|
2007-11-11 00:13:42 +01:00
|
|
|
if (parent()) {
|
2007-11-17 19:53:16 +01:00
|
|
|
//kDebug() << "returning size hint from freelayout of" << parent()->geometry().size();
|
2007-11-11 00:13:42 +01:00
|
|
|
return parent()->geometry().size();
|
|
|
|
}
|
|
|
|
|
2007-11-17 19:53:16 +01:00
|
|
|
//kDebug() << "returning size hint from freelayout of" << maximumSize();
|
2007-09-10 22:38:59 +02:00
|
|
|
return maximumSize();
|
|
|
|
}
|
|
|
|
|
2007-09-13 07:40:37 +02:00
|
|
|
}
|
|
|
|
|