add support for fixed-size columns. default behavious remains to average item widths.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=733293
This commit is contained in:
Leo Franchi 2007-11-06 02:46:01 +00:00
parent 845139ae0a
commit d83f52e2db
2 changed files with 19 additions and 2 deletions

View File

@ -34,8 +34,10 @@ using namespace Plasma;
class FlowLayout::Private
{
public:
Private() : columnWidth( -1 ) {}
QList<LayoutItem*> items;
QRectF geometry;
qreal columnWidth;
};
FlowLayout::FlowLayout(LayoutItem* parent)
@ -128,8 +130,12 @@ void FlowLayout::setGeometry(const QRectF& geo)
// Also include the spacing either side of each item as part of the
// average width, this provides the spacing between the items and
// also allows some tolerance for small differences in item widths
const qreal averageWidth = totalWidth / d->items.count() + 2*spacing();
qreal averageWidth;
if( d->columnWidth == -1 )
averageWidth = totalWidth / d->items.count() + 2*spacing();
else
averageWidth = d->columnWidth;
const int columnCount = (int)(geometry.width() / averageWidth);
int insertColumn = 0;
@ -201,3 +207,12 @@ Qt::Orientations FlowLayout::expandingDirections() const
return Qt::Vertical | Qt::Horizontal;
}
qreal FlowLayout::columnWidth() const
{
return d->columnWidth;
}
void FlowLayout::setColumnWidth( const qreal width )
{
d->columnWidth = width;
}

View File

@ -52,6 +52,8 @@ public:
virtual QRectF geometry() const;
virtual void setGeometry(const QRectF& geometry);
virtual Qt::Orientations expandingDirections() const;
virtual void setColumnWidth( const qreal width );
virtual qreal columnWidth() const;
private:
class Private;