KFlowRects proposal (planned for next Monday)

Matt Newell newellm at blur.com
Mon Aug 6 19:40:11 BST 2007


On Monday 06 August 2007 09:22, Matthew Woehlke wrote:
> I would like to add (next Monday) this class to kdelibs (probably kdeui?
> where is a good place?). This class takes some information about items
> and "flows" them in a container. The container is a rectangle, with
> fixed-size items and fixed spacing between the items. The purpose it to
> determine the coordinates of the n'th item by "flowing" items in the
> container with the requested size and spacing.
>

Why such a longwinded api for something so simple.

QRect getFlowedRect( int index, const QSize & itemSize, int layoutWidth, int 
h_spacing, int v_spacing )
{
	int itemsPerRow = layoutWidth / (itemSize.width() + h_spacing);
	return QRect( QPoint( (index % itemsPerRow) * (itemSize.width() + h_spacing), 
(index / itemsPerRow) * (itemSize.height() + v_spacing) ), itemSize );
}

Seems to me that it's so simple it'd be better off put in a wiki and copy and 
pasted for people to use inline who need it. 

Matt





More information about the kde-core-devel mailing list