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

Mike Fenton mike at staikos.net
Tue Jan 20 21:51:52 CET 2009


SVN commit 914319 by fenton:

Fix Bug - Child of PlotRenderItem loses parent on resize when renderitem's size becomes negative.


 M  +8 -0      plotitem.cpp  
 M  +14 -79    viewitem.cpp  
 M  +2 -0      viewitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #914318:914319
@@ -897,6 +897,14 @@
   plot.setBottom(plot.bottom() - xOffset - bottomPadding);
   plot.setRight(plot.right() - rightPadding);
   plot.setTop(plot.top() + topPadding);
+  if (!plot.isValid()) {
+    if (plot.width() <= 0) {
+      plot.setWidth(0.1);
+    }
+    if (plot.height() <= 0) {
+      plot.setHeight(0.1);
+    }
+  }
   return plot;
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #914318:914319
@@ -1409,18 +1409,24 @@
     _parentRelativeWidth = (width() / parentViewItem()->width());
     _parentRelativeCenter =  mapToParent(rect().center()) - parentViewItem()->rect().topLeft();
     _parentRelativeCenter =  QPointF(_parentRelativeCenter.x() / parentViewItem()->width(), _parentRelativeCenter.y() / parentViewItem()->height());
+    _parentRelativePosition =  mapToParent(rect().topLeft()) - parentViewItem()->rect().topLeft();
+    _parentRelativePosition =  QPointF(_parentRelativePosition.x() / parentViewItem()->width(), _parentRelativePosition.y() / parentViewItem()->height());
    } else if (parentView()) {
     _parentRelativeHeight = (height() / parentView()->height());
     _parentRelativeWidth = (width() / parentView()->width());
     _parentRelativeCenter =  mapToParent(rect().center()) - parentView()->rect().topLeft();
     _parentRelativeCenter =  QPointF(_parentRelativeCenter.x() / parentView()->width(), _parentRelativeCenter.y() / parentView()->height());
+    _parentRelativePosition =  mapToParent(rect().topLeft()) - parentView()->rect().topLeft();
+    _parentRelativePosition =  QPointF(_parentRelativePosition.x() / parentView()->width(), _parentRelativePosition.y() / parentView()->height());
   } else {
     _parentRelativeHeight = 0;
     _parentRelativeWidth = 0;
     _parentRelativeCenter = QPointF(0, 0);
+    _parentRelativePosition = QPointF(0, 0);
    }
 }
 
+
 QPointF ViewItem::relativeCenter() const {
   QPointF c;
   if (parentViewItem()) {
@@ -1435,8 +1441,9 @@
   return c;
 }
 
+
 void ViewItem::updateChildGeometry(const QRectF &oldParentRect, const QRectF &newParentRect) {
-//   qDebug() << "ViewItem::updateChildGeometry" << oldParentRect << newParentRect << endl;
+//   qDebug() << "ViewItem::updateChildGeometry" << this << oldParentRect << newParentRect << endl;
 
   QRectF itemRect = rect();
 
@@ -1469,86 +1476,14 @@
     QPointF centerOffset = mapToParent(r.topLeft()) - mapToParent(itemRect.topLeft());
     setPos(pos() + centerOffset);
   } else {
+    qreal newHeight = relativeHeight() * newParentRect.height();
+    qreal newWidth = relativeWidth() * newParentRect.width();
 
-    qreal dx = oldParentRect.width() ? newParentRect.width() / oldParentRect.width() : 0.0;
-    qreal dy = oldParentRect.height() ? newParentRect.height() / oldParentRect.height() : 0.0;
+    QPointF newTopLeft = newParentRect.topLeft() + QPointF(newParentRect.width() * _parentRelativePosition.x(), newParentRect.height() * _parentRelativePosition.y());
 
-    bool topChanged = oldParentRect.top() != newParentRect.top();
-    bool leftChanged = oldParentRect.left() != newParentRect.left();
-    bool bottomChanged = oldParentRect.bottom() != newParentRect.bottom();
-    bool rightChanged = oldParentRect.right() != newParentRect.right();
-
-    qreal width = itemRect.width() * dx;
-    qreal height = itemRect.height() * dy;
-
-    itemRect.setBottom(itemRect.top() + height);
-    itemRect.setRight(itemRect.left() + width);
-
-    if (topChanged) {
-      QPointF offset = oldParentRect.bottomRight() - mapToParent(rect().bottomRight());
-
-      qreal xOff = offset.x() * dx;
-      qreal yOff = offset.y() * dy;
-
-      QPointF newBottomRight = oldParentRect.bottomRight() - QPointF(xOff, yOff);
-
-      QPointF o = pos() - mapToParent(itemRect.topLeft());
-
-      QRectF r = itemRect;
-      r.moveBottom(mapFromParent(newBottomRight).y());
-
-      setPos(mapToParent(r.topLeft()) + o);
-    }
-
-    if (leftChanged) {
-      QPointF offset = oldParentRect.bottomRight() - mapToParent(rect().bottomRight());
-
-      qreal xOff = offset.x() * dx;
-      qreal yOff = offset.y() * dy;
-
-      QPointF newBottomRight = oldParentRect.bottomRight() - QPointF(xOff, yOff);
-
-      QPointF o = pos() - mapToParent(itemRect.topLeft());
-
-      QRectF r = itemRect;
-      r.moveRight(mapFromParent(newBottomRight).x());
-
-      setPos(mapToParent(r.topLeft()) + o);
-    }
-
-    if (bottomChanged) {
-
-      QPointF offset = mapToParent(rect().topLeft()) - oldParentRect.topLeft();
-
-      qreal xOff = offset.x() * dx;
-      qreal yOff = offset.y() * dy;
-
-      QPointF newTopLeft = oldParentRect.topLeft() + QPointF(xOff, yOff);
-
-      QPointF o = pos() - mapToParent(itemRect.topLeft());
-
-      QRectF r = itemRect;
-      r.moveTop(mapFromParent(newTopLeft).y());
-
-      setPos(mapToParent(r.topLeft()) + o);
-    }
-
-    if (rightChanged) {
-
-      QPointF offset = mapToParent(rect().topLeft()) - oldParentRect.topLeft();
-
-      qreal xOff = offset.x() * dx;
-      qreal yOff = offset.y() * dy;
-
-      QPointF newTopLeft = oldParentRect.topLeft() + QPointF(xOff, yOff);
-
-      QPointF o = pos() - mapToParent(itemRect.topLeft());
-
-      QRectF r = itemRect;
-      r.moveLeft(mapFromParent(newTopLeft).x());
-
-      setPos(mapToParent(r.topLeft()) + o);
-    }
+    itemRect.setWidth(newWidth);
+    itemRect.setHeight(newHeight);
+    setPos(newTopLeft);
   }
 
 //   qDebug() << "resize"
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #914318:914319
@@ -68,6 +68,7 @@
     qreal relativeHeight() const { return _parentRelativeHeight; }
     qreal relativeWidth() const { return _parentRelativeWidth; }
     QPointF relativeCenter() const;
+    QPointF relativePosition() const;
     qreal rotationAngle() const;
 
     GripMode gripMode() const;
@@ -232,6 +233,7 @@
     bool _updatingLayout;
     QPointF _originalPosition;
     QPointF _parentRelativeCenter;
+    QPointF _parentRelativePosition;
     QRectF _originalRect;
     QTransform _originalTransform;
     QLineF _normalLine;


More information about the Kst mailing list