You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
6.1 KiB
169 lines
6.1 KiB
15 years ago
|
/*
|
||
|
* Copyright (C) 2003 by Unai Garro <ugarro@users.sourceforge.net>
|
||
|
* Copyright (C) 2004 by Enrico Ros <rosenric@dei.unipd.it>
|
||
|
* Copyright (C) 2004 by Stephan Kulow <coolo@kde.org>
|
||
|
* Copyright (C) 2004 by Oswald Buddenhagen <ossi@kde.org>
|
||
|
*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
13 years ago
|
#include "tdmlayout.h"
|
||
|
#include "tdmconfig.h"
|
||
|
#include "tdmitem.h"
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
|
|
||
14 years ago
|
#include <tqdom.h>
|
||
|
#include <tqrect.h>
|
||
15 years ago
|
|
||
14 years ago
|
KdmLayoutFixed::KdmLayoutFixed( const TQDomNode &/*node*/ )
|
||
15 years ago
|
{
|
||
|
//Parsing FIXED parameters on 'node' [NONE!]
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
KdmLayoutFixed::update( const TQRect &parentGeometry, bool force )
|
||
15 years ago
|
{
|
||
14 years ago
|
kdDebug() << timestamp() << " KdmLayoutFixed::update " << parentGeometry << endl;
|
||
15 years ago
|
|
||
14 years ago
|
// I can't layout children if the parent rectangle is not valid
|
||
15 years ago
|
if (parentGeometry.width() < 0 || parentGeometry.height() < 0) {
|
||
14 years ago
|
kdDebug() << timestamp() << " invalid\n";
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
// For each child in list I ask their hinted size and set it!
|
||
14 years ago
|
for (TQValueList<KdmItem *>::ConstIterator it = m_children.begin(); it != m_children.end(); ++it)
|
||
15 years ago
|
(*it)->setGeometry( (*it)->placementHint( parentGeometry ), force );
|
||
|
}
|
||
|
|
||
14 years ago
|
KdmLayoutBox::KdmLayoutBox( const TQDomNode &node )
|
||
15 years ago
|
{
|
||
|
//Parsing BOX parameters
|
||
14 years ago
|
TQDomNode n = node;
|
||
|
TQDomElement el = n.toElement();
|
||
15 years ago
|
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
|
||
14 years ago
|
KdmLayoutBox::update( const TQRect &parentGeometry, bool force )
|
||
15 years ago
|
{
|
||
|
kdDebug() << this << " update " << parentGeometry << endl;
|
||
|
|
||
14 years ago
|
// I can't layout children if the parent rectangle is not valid
|
||
15 years ago
|
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())
|
||
13 years ago
|
// sizeHint();
|
||
15 years ago
|
|
||
|
// kdDebug() << this << " hintedSize " << hintedSize << endl;
|
||
|
|
||
|
//XXX why was this asymmetric? it broke things big time.
|
||
14 years ago
|
TQRect childrenRect = /*box.isVertical ? TQRect( parentGeometry.topLeft(), hintedSize ) :*/ parentGeometry;
|
||
15 years ago
|
// 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;
|
||
14 years ago
|
for (TQValueList<KdmItem *>::ConstIterator it = m_children.begin(); it != m_children.end(); ++it)
|
||
15 years ago
|
if (!(*it)->isExplicitlyHidden())
|
||
|
ccnt++;
|
||
|
int height = (childrenRect.height() - (ccnt - 1) * box.spacing) / ccnt;
|
||
|
int width = (childrenRect.width() - (ccnt - 1) * box.spacing) / ccnt;
|
||
|
|
||
14 years ago
|
for (TQValueList<KdmItem *>::ConstIterator it = m_children.begin(); it != m_children.end(); ++it) {
|
||
15 years ago
|
if ((*it)->isExplicitlyHidden())
|
||
|
continue;
|
||
|
if (box.isVertical) {
|
||
14 years ago
|
TQRect temp( childrenRect.left(), childrenRect.top(), childrenRect.width(), height );
|
||
15 years ago
|
(*it)->setGeometry( temp, force );
|
||
|
childrenRect.setTop( childrenRect.top() + height + box.spacing );
|
||
|
} else {
|
||
14 years ago
|
TQRect temp( childrenRect.left(), childrenRect.top(), width, childrenRect.height() );
|
||
14 years ago
|
kdDebug() << timestamp() << " placement " << *it << " " << temp << " " << (*it)->placementHint( temp ) << endl;
|
||
15 years ago
|
temp = (*it)->placementHint( temp );
|
||
|
(*it)->setGeometry( temp, force );
|
||
|
childrenRect.setLeft( childrenRect.left() + width + box.spacing );
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
14 years ago
|
for (TQValueList<KdmItem *>::ConstIterator it = m_children.begin(); it != m_children.end(); ++it) {
|
||
15 years ago
|
if ((*it)->isExplicitlyHidden())
|
||
|
continue;
|
||
|
|
||
13 years ago
|
TQRect temp = childrenRect, itemRect;
|
||
15 years ago
|
if (box.isVertical) {
|
||
|
temp.setHeight( 0 );
|
||
13 years ago
|
itemRect = (*it)->placementHint( temp );
|
||
|
temp.setHeight( itemRect.height() );
|
||
|
childrenRect.setTop( childrenRect.top() + itemRect.size().height() + box.spacing );
|
||
15 years ago
|
} else {
|
||
|
temp.setWidth( 0 );
|
||
13 years ago
|
itemRect = (*it)->placementHint( temp );
|
||
|
kdDebug() << this << " placementHint " << *it << " " << temp << " " << itemRect << endl;
|
||
|
temp.setWidth( itemRect.width() );
|
||
|
childrenRect.setLeft( childrenRect.left() + itemRect.size().width() + box.spacing );
|
||
14 years ago
|
kdDebug() << timestamp() << " childrenRect after " << *it << " " << childrenRect << endl;
|
||
15 years ago
|
}
|
||
13 years ago
|
itemRect = (*it)->placementHint( temp );
|
||
|
kdDebug() << this << " placementHint2 " << *it << " " << temp << " " << itemRect << endl;
|
||
|
(*it)->setGeometry( itemRect, force );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
//FIXME truly experimental (is so close to greeter_geometry.c)
|
||
14 years ago
|
TQSize
|
||
13 years ago
|
KdmLayoutBox::sizeHint()
|
||
15 years ago
|
{
|
||
|
// Sum up area taken by children
|
||
|
int w = 0, h = 0;
|
||
14 years ago
|
for (TQValueList<KdmItem *>::ConstIterator it = m_children.begin(); it != m_children.end(); ++it) {
|
||
|
TQSize s = (*it)->placementHint( TQRect() ).size();
|
||
15 years ago
|
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)
|
||
14 years ago
|
return TQSize( w < box.minwidth ? box.minwidth : w,
|
||
15 years ago
|
h < box.minheight ? box.minheight : h );
|
||
|
}
|