- if(blocks.length() > 0) {
- // first, search for blocks that are at (0,0)
- int xMaxZero = 0;
- int yMaxZero = 0;
- int xMax = 0;
- int yMax = 0;
- bool isZeroBlocks = false;
- bool isOtherBlocks = false;
- foreach(BoxItem* item, blocks) {
- QPointF p = item->pos() + item->getOriginPoint();
- if ((p.x()==0.0) && (p.y()==0.0)) {
- isZeroBlocks = true;
- if (item->getTotalWidth() > xMaxZero) {
- xMaxZero = item->getTotalWidth();
+ 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) {
+
+ if (item->getSpan() == BoxItem::VSpan) {
+ if (item->getMinimumBoxHeight() > topHighest) {
+ topHighest = item->getMinimumBoxHeight();