1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
/*
* Copyright (C) 2003 by Unai Garro <[email protected]>
* Copyright (C) 2004 by Enrico Ros <[email protected]>
* Copyright (C) 2004 by Stephan Kulow <[email protected]>
* Copyright (C) 2004 by Oswald Buddenhagen <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 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 "kdmlayout.h"
#include "kdmitem.h"
#include <kdebug.h>
#include <tqdom.h>
#include <tqrect.h>
KdmLayoutFixed::KdmLayoutFixed( const TQDomNode &/*node*/ )
{
//Parsing FIXED parameters on 'node' [NONE!]
}
void
KdmLayoutFixed::update( const TQRect &parentGeometry, bool force )
{
kdDebug() << "KdmLayoutFixed::update " << parentGeometry << endl;
// I can't layout children if the parent rectangle is not valid
if (parentGeometry.width() < 0 || parentGeometry.height() < 0) {
kdDebug() << "invalid\n";
return;
}
// For each child in list I ask their hinted size and set it!
for (TQValueList<KdmItem *>::ConstIterator it = m_children.begin(); it != m_children.end(); ++it)
(*it)->setGeometry( (*it)->placementHint( parentGeometry ), force );
}
KdmLayoutBox::KdmLayoutBox( const TQDomNode &node )
{
//Parsing BOX parameters
TQDomNode n = node;
TQDomElement el = n.toElement();
box.isVertical = el.attribute( "orientation", "vertical" ) != "horizontal";
box.xpadding = el.attribute( "xpadding", "0" ).toInt();
box.ypadding = el.attribute( "ypadding", "0" ).toInt();
box.spacing = el.attribute( "spacing", "0" ).toInt();
box.minwidth = el.attribute( "min-width", "0" ).toInt();
box.minheight = el.attribute( "min-height", "0" ).toInt();
box.homogeneous = el.attribute( "homogeneous", "false" ) == "true";
}
void
KdmLayoutBox::update( const TQRect &parentGeometry, bool force )
{
kdDebug() << this << " update " << parentGeometry << endl;
// I can't layout children if the parent rectangle is not valid
if (!parentGeometry.isValid() || parentGeometry.isEmpty())
return;
// Check if box size was computed. If not compute it
// TODO check if this prevents updating changing items
// if (!hintedSize.isValid())
// sizeHint();
// kdDebug() << this << " hintedSize " << hintedSize << endl;
//XXX why was this asymmetric? it broke things big time.
TQRect childrenRect = /*box.isVertical ? TQRect( parentGeometry.topLeft(), hintedSize ) :*/ parentGeometry;
// Begin cutting the parent rectangle to attach children on the right place
childrenRect.addCoords( box.xpadding, box.ypadding, -box.xpadding, -box.ypadding );
kdDebug() << this << " childrenRect " << childrenRect << endl;
// For each child in list ...
if (box.homogeneous) {
int ccnt = 0;
for (TQValueList<KdmItem *>::ConstIterator it = m_children.begin(); it != m_children.end(); ++it)
if (!(*it)->isExplicitlyHidden())
ccnt++;
int height = (childrenRect.height() - (ccnt - 1) * box.spacing) / ccnt;
int width = (childrenRect.width() - (ccnt - 1) * box.spacing) / ccnt;
for (TQValueList<KdmItem *>::ConstIterator it = m_children.begin(); it != m_children.end(); ++it) {
if ((*it)->isExplicitlyHidden())
continue;
if (box.isVertical) {
TQRect temp( childrenRect.left(), childrenRect.top(), childrenRect.width(), height );
(*it)->setGeometry( temp, force );
childrenRect.setTop( childrenRect.top() + height + box.spacing );
} else {
TQRect temp( childrenRect.left(), childrenRect.top(), width, childrenRect.height() );
kdDebug() << "placement " << *it << " " << temp << " " << (*it)->placementHint( temp ) << endl;
temp = (*it)->placementHint( temp );
(*it)->setGeometry( temp, force );
childrenRect.setLeft( childrenRect.left() + width + box.spacing );
}
}
} else {
for (TQValueList<KdmItem *>::ConstIterator it = m_children.begin(); it != m_children.end(); ++it) {
if ((*it)->isExplicitlyHidden())
continue;
TQRect temp = childrenRect, itemRect;
if (box.isVertical) {
temp.setHeight( 0 );
itemRect = (*it)->placementHint( temp );
temp.setHeight( itemRect.height() );
childrenRect.setTop( childrenRect.top() + itemRect.size().height() + box.spacing );
} else {
temp.setWidth( 0 );
itemRect = (*it)->placementHint( temp );
kdDebug() << this << " placementHint " << *it << " " << temp << " " << itemRect << endl;
temp.setWidth( itemRect.width() );
childrenRect.setLeft( childrenRect.left() + itemRect.size().width() + box.spacing );
kdDebug() << "childrenRect after " << *it << " " << childrenRect << endl;
}
itemRect = (*it)->placementHint( temp );
kdDebug() << this << " placementHint2 " << *it << " " << temp << " " << itemRect << endl;
(*it)->setGeometry( itemRect, force );
}
}
}
//FIXME truly experimental (is so close to greeter_geometry.c)
QSize
KdmLayoutBox::sizeHint()
{
// Sum up area taken by children
int w = 0, h = 0;
for (TQValueList<KdmItem *>::ConstIterator it = m_children.begin(); it != m_children.end(); ++it) {
TQSize s = (*it)->placementHint( TQRect() ).size();
if (box.isVertical) {
if (s.width() > w)
w = s.width();
h += s.height();
} else {
if (s.height() > h)
h = s.height();
w += s.width();
}
}
// Add padding and items spacing
w += 2 * box.xpadding;
h += 2 * box.ypadding;
if (box.isVertical)
h += box.spacing * (m_children.count() - 1);
else
w += box.spacing * (m_children.count() - 1);
// Make hint at least equal to minimum size (if set)
return TQSize( w < box.minwidth ? box.minwidth : w,
h < box.minheight ? box.minheight : h );
}
|