2007-07-26 08:58:33 +02:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2007 by Matias Valdenegro T. <mvaldenegro@informatica.utem.cl>
|
2007-07-26 08:58:33 +02: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hboxlayout.h"
|
|
|
|
|
|
|
|
#include <QtCore/QList>
|
|
|
|
|
|
|
|
#include <KDebug>
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
HBoxLayout::HBoxLayout(LayoutItem *parent)
|
2007-07-26 09:25:30 +02:00
|
|
|
: BoxLayout(parent),
|
|
|
|
d(0)
|
2007-07-26 08:58:33 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
HBoxLayout::~HBoxLayout()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::Orientations HBoxLayout::expandingDirections() const
|
|
|
|
{
|
2007-07-26 09:25:30 +02:00
|
|
|
return Qt::Horizontal;
|
2007-07-26 08:58:33 +02:00
|
|
|
}
|
|
|
|
|
2007-07-26 09:12:05 +02:00
|
|
|
bool HBoxLayout::hasWidthForHeight() const
|
2007-07-26 08:58:33 +02:00
|
|
|
{
|
2007-07-26 09:25:30 +02:00
|
|
|
return true;
|
2007-07-26 08:58:33 +02:00
|
|
|
}
|
|
|
|
|
2007-07-26 09:12:05 +02:00
|
|
|
qreal HBoxLayout::widthForHeight(qreal w) const
|
2007-07-26 08:58:33 +02:00
|
|
|
{
|
2007-07-26 09:23:30 +02:00
|
|
|
Q_UNUSED(w);
|
2007-07-26 09:25:30 +02:00
|
|
|
return qreal();
|
2007-07-26 08:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void HBoxLayout::setGeometry(const QRectF& geometry)
|
|
|
|
{
|
|
|
|
if (!geometry.isValid() || geometry.isEmpty()) {
|
2007-08-02 15:12:59 +02:00
|
|
|
kDebug() << "Invalid Geometry " << geometry;
|
2007-07-26 08:58:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-08-16 22:37:29 +02:00
|
|
|
kDebug() << this << " Geometry process " << geometry << " for " << children().count() << " childrens";
|
2007-07-26 08:58:33 +02:00
|
|
|
|
2007-07-26 09:23:30 +02:00
|
|
|
QList<LayoutItem *> fixedChildren;
|
2007-07-26 08:58:33 +02:00
|
|
|
QList<LayoutItem *> expandingChildren;
|
|
|
|
QList<QSizeF> sizes;
|
|
|
|
QSizeF available = geometry.size() - QSizeF(2 * margin(), 2 * margin());
|
|
|
|
|
2007-07-26 09:23:30 +02:00
|
|
|
foreach (LayoutItem *l, children()) {
|
2007-07-26 08:58:33 +02:00
|
|
|
if (l->expandingDirections() & Qt::Horizontal) {
|
2007-07-27 22:00:07 +02:00
|
|
|
expandingChildren.append(l);
|
2007-07-26 08:58:33 +02:00
|
|
|
} else {
|
2007-07-27 22:00:07 +02:00
|
|
|
fixedChildren.append(l);
|
2007-07-26 08:58:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-26 09:23:30 +02:00
|
|
|
foreach (LayoutItem *l, fixedChildren) {
|
2007-07-26 08:58:33 +02:00
|
|
|
QSizeF hint = l->sizeHint();
|
|
|
|
sizes.insert(indexOf(l), QSizeF(available.width(), hint.height()));
|
|
|
|
available -= QSizeF(hint.width() + spacing(), 0.0f);
|
|
|
|
}
|
|
|
|
|
2007-07-27 22:00:07 +02:00
|
|
|
qreal expandWidth = 0;
|
|
|
|
if (expandingChildren.count() > 0) {
|
2007-08-16 22:37:29 +02:00
|
|
|
expandWidth = (available.width() - ((expandingChildren.count() - 1) * spacing())) / expandingChildren.count();
|
2007-07-27 22:00:07 +02:00
|
|
|
}
|
2007-07-26 08:58:33 +02:00
|
|
|
|
|
|
|
foreach (LayoutItem *l, expandingChildren) {
|
|
|
|
sizes.insert(indexOf(l), QSizeF(expandWidth, available.height()));
|
|
|
|
}
|
|
|
|
|
2007-08-10 18:04:26 +02:00
|
|
|
QPointF start = geometry.topLeft();
|
2007-07-26 08:58:33 +02:00
|
|
|
start += QPointF(margin(), spacing());
|
|
|
|
|
|
|
|
for (int i = 0; i < sizes.size(); i++) {
|
|
|
|
LayoutItem *l = itemAt(i);
|
2007-08-02 15:12:59 +02:00
|
|
|
kDebug() << "Setting Geometry for child " << l << " to " << QRectF(start, sizes[i]);
|
2007-07-26 08:58:33 +02:00
|
|
|
l->setGeometry(QRectF(start, sizes[i]));
|
|
|
|
start += QPointF(sizes[i].width() + spacing(), 0.0);
|
|
|
|
}
|
|
|
|
|
2007-07-26 09:23:30 +02:00
|
|
|
BoxLayout::setGeometry(geometry);
|
2007-07-26 08:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF HBoxLayout::sizeHint() const
|
|
|
|
{
|
2007-07-26 09:25:30 +02:00
|
|
|
qreal hintHeight = 0.0;
|
|
|
|
qreal hintWidth = 0.0;
|
2007-07-26 08:58:33 +02:00
|
|
|
|
2007-07-26 09:25:30 +02:00
|
|
|
foreach(LayoutItem *l, children()) {
|
2007-07-26 08:58:33 +02:00
|
|
|
|
2007-07-26 09:25:30 +02:00
|
|
|
QSizeF hint = l->sizeHint();
|
2007-07-26 08:58:33 +02:00
|
|
|
|
|
|
|
hintHeight = qMax(hint.height(), hintHeight);
|
|
|
|
hintWidth += hint.width() + spacing();
|
2007-07-26 09:25:30 +02:00
|
|
|
}
|
2007-07-26 08:58:33 +02:00
|
|
|
|
2007-07-26 09:25:30 +02:00
|
|
|
return QSizeF(hintWidth, hintHeight);
|
2007-07-26 08:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|