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>
|
|
|
|
|
2007-11-20 00:40:03 +01:00
|
|
|
#include <plasma/layouts/layout.h>
|
2007-11-11 00:13:42 +01:00
|
|
|
|
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)
|
|
|
|
{
|
2007-12-03 17:11:27 +01:00
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-09-10 22:38:59 +02:00
|
|
|
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-20 00:45:56 +01:00
|
|
|
void FreeLayout::relayout()
|
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-28 00:18:00 +01:00
|
|
|
QSizeF newSize = child->sizeHint().expandedTo(minimumSize()).boundedTo(maximumSize());
|
|
|
|
child->setGeometry(QRectF(child->geometry().topLeft(), newSize));
|
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()) {
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "returning size hint from freelayout of" << parent()->geometry().size();
|
2007-11-11 00:13:42 +01:00
|
|
|
return parent()->geometry().size();
|
|
|
|
}
|
|
|
|
|
2008-01-08 02:25:09 +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
|
|
|
}
|
|
|
|
|