[Kst] branches/work/kst/portto4/kst/src/libkstapp

Mike Fenton mike at staikos.net
Tue Mar 25 20:41:15 CET 2008


SVN commit 790054 by fenton:

Remove Line based items from the grid layout maintaining the aspect ratio of the item independently.
Prevent grid layout items from calculating to a negative width/height.


 M  +7 -0      gridlayouthelper.cpp  
 M  +2 -1      lineitem.cpp  
 M  +7 -6      viewitem.cpp  
 M  +5 -1      viewitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/gridlayouthelper.cpp #790053:790054
@@ -129,6 +129,13 @@
                 c.setBottom(ch);
         }
 
+        // Make sure the sizes are all positive.
+        if (c.width() < 0)
+          c.setRight(c.left());
+
+        if (c.height() < 0)
+          c.setBottom(c.top());
+
         grid->setCells(c, v); // Mark cellblock
     }
 
--- branches/work/kst/portto4/kst/src/libkstapp/lineitem.cpp #790053:790054
@@ -28,6 +28,7 @@
   setZValue(LINE_ZVALUE);
   setAllowedGrips(RightMidGrip | LeftMidGrip);
   setAllowedGripModes(Resize);
+  setAllowsLayout(false);
   QPen p = pen();
   p.setWidthF(1);
   setPen(p);
@@ -143,7 +144,7 @@
 
 void LineItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
 
-  if (parentView()->viewMode() == View::Data || itemInLayout()) {
+  if (parentView()->viewMode() == View::Data) {
     event->ignore();
     return;
   }
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #790053:790054
@@ -46,6 +46,7 @@
     _lockAspectRatio(false),
     _lockAspectRatioFixed(false),
     _hasStaticGeometry(false),
+    _allowsLayout(true),
     _hovering(false),
     _acceptsChildItems(true),
     _acceptsContextMenuEvents(true),
@@ -277,7 +278,7 @@
 
 
 bool ViewItem::itemInLayout() const {
-  return parentViewItem() && parentViewItem()->layout();
+  return parentViewItem() && parentViewItem()->layout() && allowsLayout();
 }
 
 
@@ -349,9 +350,6 @@
     updateRelativeSize();
   }
 
-  if (layout())
-    return;
-
   foreach (QGraphicsItem *item, QGraphicsItem::children()) {
     if (item->parentItem() != this)
       continue;
@@ -364,7 +362,10 @@
     if (viewItem->hasStaticGeometry())
       continue;
 
-    viewItem->updateChildGeometry(oldViewRect, viewRect);
+
+    if (!layout() || !viewItem->allowsLayout()) {
+      viewItem->updateChildGeometry(oldViewRect, viewRect);
+    }
   }
 }
 
@@ -1837,7 +1838,7 @@
 
   foreach (QGraphicsItem *item, list) {
     ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(item);
-    if (!viewItem || viewItem->hasStaticGeometry() || viewItem->parentItem() != _item)
+    if (!viewItem || viewItem->hasStaticGeometry() || !viewItem->allowsLayout() || viewItem->parentItem() != _item)
       continue;
     viewItems.append(viewItem);
   }
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #790053:790054
@@ -81,9 +81,12 @@
     bool lockAspectRatioFixed() const { return _lockAspectRatioFixed; }
     void setLockAspectRatioFixed(bool enable) { _lockAspectRatioFixed = enable; }
 
-    bool hasStaticGeometry() { return _hasStaticGeometry; }
+    bool hasStaticGeometry() const { return _hasStaticGeometry; }
     void setHasStaticGeometry(bool hasStaticGeometry ) { _hasStaticGeometry = hasStaticGeometry; }
 
+    bool allowsLayout() const { return _allowsLayout; }
+    void setAllowsLayout(bool allowsLayout ) { _allowsLayout = allowsLayout; }
+
     //NOTE We can change this to a generic abstract class once we have
     //more layouts besides grid layout...
     ViewGridLayout *layout() const;
@@ -207,6 +210,7 @@
     bool _lockAspectRatio;
     bool _lockAspectRatioFixed;
     bool _hasStaticGeometry;
+    bool _allowsLayout;
     bool _hovering;
     bool _acceptsChildItems;
     bool _acceptsContextMenuEvents;


More information about the Kst mailing list