+ QList<BoxItem *> blocks = getScene()->getBoxItems();
+ if(blocks.length() == 0) return; // no blocks within, keep the miniumum computed before.
+
+ QRectF boxFree; // the bounding box of free blocks.
+ foreach(BoxItem* item, blocks) {
+ QRectF boxItem = item->boundingRect();
+ if (item->getPosition() == BoxItem::Free) {
+ boxItem.translate(item->pos());
+ if (item->getSpan() == BoxItem::NoSpan) {
+ boxFree = boxFree.united(boxItem);
+ }
+ else if (item->getSpan() == BoxItem::HSpan) {
+ QRectF r(boxFree.left()+boxFree.width()/2.0,boxItem.top(),1,boxItem.height());
+ boxFree = boxFree.united(r);
+ }
+ else if (item->getSpan() == BoxItem::VSpan) {
+ QRectF r(boxItem.left(),boxFree.top()+boxFree.height()/2.0,boxItem.width(),1);
+ boxFree = boxFree.united(r);
+ }
+ }
+ }
+ // find the move to apply to freely located items
+ double gapXLeft = 0.0;
+ double gapYTop = 0.0;
+ if (boxFree.left() < marginConn) {
+ gapXLeft = boxFree.left() - marginConn;
+ }
+ if (boxFree.top() < marginConn) {
+ gapYTop = boxFree.top() - marginConn;
+ }
+ // translate the box
+ boxFree.translate(-gapXLeft,-gapYTop);
+ minimumBoxWidth = boxFree.right() + marginConn;
+ minimumBoxHeight = boxFree.bottom() + marginConn;
+
+ // find the highest/largest item stick on top/bottom/left/right
+
+ qreal topHighest = 0.0;
+ qreal bottomHighest = 0.0;
+ qreal leftLargest = 0.0;
+ qreal rightLargest = 0.0;
+
+ foreach(BoxItem* item, blocks) {
+ QRectF boxItem = item->boundingRect();
+
+ if (item->getPosition() == BoxItem::Top) {