2
* Copyright 2007 by Matias Valdenegro T. <mvaldenegro@informatica.utem.cl>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library General Public License version 2 as
6
* published by the Free Software Foundation
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details
13
* You should have received a copy of the GNU Library General Public
14
* License along with this program; if not, write to the
15
* Free Software Foundation, Inc.,
16
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include "vboxlayout.h"
21
#include <QtCore/QList>
28
VBoxLayout::VBoxLayout(LayoutItem *parent)
34
VBoxLayout::~VBoxLayout()
38
Qt::Orientations VBoxLayout::expandingDirections() const
43
bool VBoxLayout::hasHeightForWidth() const
48
qreal VBoxLayout::heightForWidth(qreal w) const
54
void VBoxLayout::setGeometry(const QRectF& geometry)
56
if (!geometry.isValid() || geometry.isEmpty()) {
57
kDebug() << "Invalid Geometry " << geometry;
58
BoxLayout::setGeometry(geometry);
62
kDebug() << this << " Geometry process " << geometry << " for " << children().count() << " children";
64
QList<LayoutItem *> fixedChildren;
65
QList<LayoutItem *> expandingChildren;
67
QSizeF available = geometry.size() - QSizeF(2 * margin(), 2 * margin());
69
foreach (LayoutItem *l, children()) {
70
kDebug() << "testing layout item " << l;
71
if (l->expandingDirections() & Qt::Vertical) {
72
expandingChildren.append(l);
74
fixedChildren.append(l);
78
foreach (LayoutItem *l, fixedChildren) {
79
QSizeF hint = l->sizeHint();
80
sizes.insert(indexOf(l), QSizeF(available.width(), hint.height()));
81
available -= QSizeF(0.0, hint.height() + spacing());
84
qreal expandHeight = 0;
86
if (expandingChildren.count() > 0) {
87
expandHeight = (available.height() - ((expandingChildren.count() - 1) * spacing())) / expandingChildren.count();
90
foreach (LayoutItem *l, expandingChildren) {
91
sizes.insert(indexOf(l),QSizeF(available.width(), expandHeight));
94
QPointF start = geometry.topLeft();
95
start += QPointF(margin(), spacing());
97
for (int i = 0; i < sizes.size(); i++) {
98
LayoutItem *l = itemAt(i);
100
kDebug() << "Setting Geometry for child " << l << " to " << QRectF(start, sizes[i]);
102
l->setGeometry(QRectF(start, sizes[i]));
103
start += QPointF(0.0, sizes[i].height() + spacing());
106
BoxLayout::setGeometry(geometry);
109
QSizeF VBoxLayout::sizeHint() const
111
qreal hintHeight = 0.0;
112
qreal hintWidth = 0.0;
114
foreach(LayoutItem *l, children()) {
116
QSizeF hint = l->sizeHint();
118
hintWidth = qMax(hint.width(), hintWidth);
119
hintHeight += hint.height() + spacing();
122
return QSizeF(hintWidth, hintHeight);