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