~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy

« back to all changes in this revision

Viewing changes to libs/plasma/widgets/vboxlayout.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2007 by Matias Valdenegro T. <mvaldenegro@informatica.utem.cl>
 
3
 *
 
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
 
7
 *
 
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
 
12
 *
 
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.
 
17
 */
 
18
 
 
19
#include "vboxlayout.h"
 
20
 
 
21
#include <QtCore/QList>
 
22
 
 
23
#include <KDebug>
 
24
 
 
25
namespace Plasma
 
26
{
 
27
 
 
28
VBoxLayout::VBoxLayout(LayoutItem *parent)
 
29
    : BoxLayout(parent),
 
30
      d(0)
 
31
{
 
32
}
 
33
 
 
34
VBoxLayout::~VBoxLayout()
 
35
{
 
36
}
 
37
 
 
38
Qt::Orientations VBoxLayout::expandingDirections() const
 
39
{
 
40
    return Qt::Vertical;
 
41
}
 
42
 
 
43
bool VBoxLayout::hasHeightForWidth() const
 
44
{
 
45
    return true;
 
46
}
 
47
 
 
48
qreal VBoxLayout::heightForWidth(qreal w) const
 
49
{
 
50
    Q_UNUSED(w);
 
51
    return qreal();
 
52
}
 
53
 
 
54
void VBoxLayout::setGeometry(const QRectF& geometry)
 
55
{
 
56
    if (!geometry.isValid() || geometry.isEmpty()) {
 
57
        kDebug() << "Invalid Geometry " << geometry;
 
58
        BoxLayout::setGeometry(geometry);
 
59
        return;
 
60
    }
 
61
 
 
62
    kDebug() << this << " Geometry process " << geometry << " for " << children().count() << " children";
 
63
 
 
64
    QList<LayoutItem *> fixedChildren;
 
65
    QList<LayoutItem *> expandingChildren;
 
66
    QList<QSizeF> sizes;
 
67
    QSizeF available = geometry.size() - QSizeF(2 * margin(), 2 * margin());
 
68
 
 
69
    foreach (LayoutItem *l, children()) {
 
70
        kDebug() << "testing layout item " << l;
 
71
        if (l->expandingDirections() & Qt::Vertical) {
 
72
            expandingChildren.append(l);
 
73
        } else {
 
74
            fixedChildren.append(l);
 
75
        }
 
76
    }
 
77
 
 
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());
 
82
    }
 
83
 
 
84
    qreal expandHeight = 0;
 
85
 
 
86
    if (expandingChildren.count() > 0) {
 
87
        expandHeight = (available.height() - ((expandingChildren.count() - 1) * spacing())) / expandingChildren.count();
 
88
    }
 
89
 
 
90
    foreach (LayoutItem *l, expandingChildren) {
 
91
        sizes.insert(indexOf(l),QSizeF(available.width(), expandHeight));
 
92
    }
 
93
 
 
94
    QPointF start = geometry.topLeft();
 
95
    start += QPointF(margin(), spacing());
 
96
 
 
97
    for (int i = 0; i < sizes.size(); i++) {
 
98
        LayoutItem *l = itemAt(i);
 
99
 
 
100
        kDebug() << "Setting Geometry for child " << l << " to " << QRectF(start, sizes[i]);
 
101
 
 
102
        l->setGeometry(QRectF(start, sizes[i]));
 
103
        start += QPointF(0.0, sizes[i].height() + spacing());
 
104
    }
 
105
 
 
106
    BoxLayout::setGeometry(geometry);
 
107
}
 
108
 
 
109
QSizeF VBoxLayout::sizeHint() const
 
110
{
 
111
    qreal hintHeight = 0.0;
 
112
    qreal hintWidth = 0.0;
 
113
 
 
114
    foreach(LayoutItem *l, children()) {
 
115
 
 
116
        QSizeF hint = l->sizeHint();
 
117
 
 
118
        hintWidth = qMax(hint.width(), hintWidth);
 
119
        hintHeight += hint.height() + spacing();
 
120
    }
 
121
 
 
122
    return QSizeF(hintWidth, hintHeight);
 
123
}
 
124
 
 
125
}