[Kst] extragear/graphics/kst/kst

George Staikos staikos at kde.org
Wed Nov 23 00:08:57 CET 2005


SVN commit 482443 by staikos:

getting sick of this


 M  +78 -76    kstviewobject.cpp  


--- trunk/extragear/graphics/kst/kst/kstviewobject.cpp #482442:482443
@@ -618,85 +618,87 @@
   }
   
   int cnt = childrenCopy.count();
-  if (cnt > 0) {
-    // FIXME: don't allow regrid to a number of columns that will result in
-    //        >= height() plots in a column
-    if (!_onGrid) {
-      if (cols <= 0) {
-        cols = int(sqrt(cnt));
+  if (cnt < 1) {
+    return;
+  }
+
+  // FIXME: don't allow regrid to a number of columns that will result in
+  //        >= height() plots in a column
+  if (!_onGrid) {
+    if (cols <= 0) {
+      cols = int(sqrt(cnt));
+    }
+    _onGrid = true;
+    _columns = QMAX(1, cols);
+  } else {
+    if (cols > 0) {
+      _columns = cols;
+    } else if (cols <= 0){
+      _columns = QMAX(1, int(sqrt(cnt)));
+    }
+  }
+  int rows = ( cnt + _columns - 1 ) / _columns;
+
+  //
+  // the following is an attempt to arrange objects on a grid.
+  //  This should behave as both a snap-to-grid when the objects
+  //  are already roughly aligned to the desired grid, but should
+  //  also act to retain the inherent order when this is not the
+  //  case. The inherent order is defined by identifying objects
+  //  from left-to-right and top-to-bottom based on the position
+  //  of their top-left corner.
+  //
+  double minDistance = 0.0;
+  double distance;
+  int pos = 0;
+  int x = 0;
+  int y = 0;
+  int w = _geom.width() / _columns;
+  int h = _geom.height() / rows;
+
+  //kstdDebug() << "cleanup with w=" << w << " and h=" << h << endl;
+  //kstdDebug() << "columns=" << _columns  << endl;
+  for (int i = 0; i < cnt; ++i) {
+    KstViewObjectList::Iterator nearest = childrenCopy.end();
+    QPoint pt(x, y);
+    QSize sz(w, h);
+
+    // adjust the last column to be sure that we don't spill over
+    if (pos % _columns == _columns - 1) {
+      sz.setWidth(_geom.width() - x);
+    }
+
+    // adjust the last row to be sure that we don't spill over
+    if (pos / _columns == rows - 1) {
+      sz.setHeight(_geom.height() - y);
+    }
+
+    for (KstViewObjectList::Iterator it = childrenCopy.begin(); it != childrenCopy.end(); ++it) {
+      distance  = ceil( (double)rows * 2.0 * (*it)->aspectRatio().y );
+      distance  = rows * d2i( distance );
+      distance += (*it)->aspectRatio().x * rows;
+      distance += (*it)->aspectRatio().y;
+
+      if (it == childrenCopy.begin() || distance < minDistance) {
+        minDistance = distance;
+        nearest = it;
       }
-      _onGrid = true;
-      _columns = QMAX(1, cols);
+    }
+
+    if (nearest != childrenCopy.end()) {
+      KstViewObjectPtr vop = *nearest;
+      vop->move(pt);
+      vop->resize(sz);
+      vop->lowerToBottom();
+      childrenCopy.remove(vop);
+    }
+
+    if (++pos % _columns == 0) {
+      x = 0;
+      y += h;
     } else {
-      if (cols > 0) {
-        _columns = cols;
-      } else if (cols <= 0){
-        _columns = QMAX(1, int(sqrt(cnt)));
-      }
+      x += w;
     }
-    int rows = ( cnt + _columns - 1 ) / _columns;
-    
-    //
-    // the following is an attempt to arrange objects on a grid.
-    //  This should behave as both a snap-to-grid when the objects
-    //  are already roughly aligned to the desired grid, but should
-    //  also act to retain the inherent order when this is not the
-    //  case. The inherent order is defined by identifying objects
-    //  from left-to-right and top-to-bottom based on the position
-    //  of their top-left corner.
-    //
-    double minDistance = 0.0;
-    double distance;
-    int pos = 0;
-    int x = 0;
-    int y = 0;
-    int w = _geom.width() / _columns;
-    int h = _geom.height() / rows;
-      
-    //kstdDebug() << "cleanup with w=" << w << " and h=" << h << endl;
-    //kstdDebug() << "columns=" << _columns  << endl;
-    for (int i = 0; i < cnt; ++i) {
-      KstViewObjectList::Iterator nearest = childrenCopy.end();
-      QPoint pt(x, y);
-      QSize sz(w, h);
-  
-      // adjust the last column to be sure that we don't spill over
-      if (pos % _columns == _columns - 1) {
-        sz.setWidth(_geom.width() - x);
-      }
-  
-      // adjust the last row to be sure that we don't spill over
-      if (pos / _columns == rows - 1) {
-        sz.setHeight(_geom.height() - y);
-      }
-  
-      for (KstViewObjectList::Iterator it = childrenCopy.begin(); it != childrenCopy.end(); ++it) {
-        distance  = ceil( (double)rows * 2.0 * (*it)->aspectRatio().y );
-        distance  = rows * d2i( distance );
-        distance += (*it)->aspectRatio().x * rows;
-        distance += (*it)->aspectRatio().y;
-        
-        if (it == childrenCopy.begin() || distance < minDistance) {
-          minDistance = distance;
-          nearest = it;
-        }
-      }
-  
-      if (nearest != childrenCopy.end()) {
-        KstViewObjectPtr vop = *nearest;
-        vop->move(pt);
-        vop->resize(sz);
-        vop->lowerToBottom();
-        childrenCopy.remove(vop);
-      }
-  
-      if (++pos % _columns == 0) {
-        x = 0;
-        y += h;
-      } else {
-        x += w;
-      }
-    }
   }
 }
 


More information about the Kst mailing list