[Kst] branches/work/kst/portto4/kst/src/libkstapp
Adam Treat
treat at kde.org
Wed Sep 19 01:44:05 CEST 2007
SVN commit 714233 by treat:
* Works much better for arbitrary number of nested
items. Could probably be simplified a good bit.
M +49 -13 viewitem.cpp
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #714232:714233
@@ -1091,7 +1091,7 @@
void ViewItem::updateChildGeometry(ViewItem *child, const QRectF &oldParentRect,
const QRectF &newParentRect) {
-// qDebug() << "ViewItem::updateChildGeometry" << oldParentRect << newParentRect << endl;
+// qDebug() << "ViewItem::updateChildGeometry" << oldParentRect << newParentRect << endl;
qreal dx = oldParentRect.width() ? newParentRect.width() / oldParentRect.width() : 0.0;
qreal dy = oldParentRect.height() ? newParentRect.height() / oldParentRect.height() : 0.0;
@@ -1112,19 +1112,26 @@
qreal width = rect.width() * dx;
qreal height = rect.height() * dy;
+ rect.setBottom(rect.top() + height);
+ rect.setRight(rect.left() + width);
+
if (topChanged) {
- rect.setTop(rect.top() + rect.height() - height);
- } else if (bottomChanged) {
- rect.setBottom(rect.top() + height);
+ QPointF offset = oldParentRect.bottomRight() - child->mapToParent(child->rect().bottomRight());
+
+ qreal xOff = offset.x() * dx;
+ qreal yOff = offset.y() * dy;
+
+ QPointF newBottomRight = oldParentRect.bottomRight() - QPointF(xOff, yOff);
+
+ QPointF o = child->pos() - child->mapToParent(rect.topLeft());
+
+ QRectF r = rect;
+ r.moveBottom(child->mapFromParent(newBottomRight).y());
+
+ child->setPos(child->mapToParent(r.topLeft()) + o);
}
if (leftChanged) {
- rect.setLeft(rect.left() + rect.width() - width);
- } else if (rightChanged) {
- rect.setRight(rect.left() + width);
- }
-
- if (topChanged || leftChanged) {
QPointF offset = oldParentRect.bottomRight() - child->mapToParent(child->rect().bottomRight());
qreal xOff = offset.x() * dx;
@@ -1132,9 +1139,16 @@
QPointF newBottomRight = oldParentRect.bottomRight() - QPointF(xOff, yOff);
- rect.moveBottomRight(child->mapFromParent(newBottomRight));
- } else {
+ QPointF o = child->pos() - child->mapToParent(rect.topLeft());
+ QRectF r = rect;
+ r.moveRight(child->mapFromParent(newBottomRight).x());
+
+ child->setPos(child->mapToParent(r.topLeft()) + o);
+ }
+
+ if (bottomChanged) {
+
QPointF offset = child->mapToParent(child->rect().topLeft()) - oldParentRect.topLeft();
qreal xOff = offset.x() * dx;
@@ -1142,9 +1156,31 @@
QPointF newTopLeft = oldParentRect.topLeft() + QPointF(xOff, yOff);
- rect.moveTopLeft(child->mapFromParent(newTopLeft));
+ QPointF o = child->pos() - child->mapToParent(rect.topLeft());
+
+ QRectF r = rect;
+ r.moveTop(child->mapFromParent(newTopLeft).y());
+
+ child->setPos(child->mapToParent(r.topLeft()) + o);
}
+ if (rightChanged) {
+
+ QPointF offset = child->mapToParent(child->rect().topLeft()) - oldParentRect.topLeft();
+
+ qreal xOff = offset.x() * dx;
+ qreal yOff = offset.y() * dy;
+
+ QPointF newTopLeft = oldParentRect.topLeft() + QPointF(xOff, yOff);
+
+ QPointF o = child->pos() - child->mapToParent(rect.topLeft());
+
+ QRectF r = rect;
+ r.moveLeft(child->mapFromParent(newTopLeft).x());
+
+ child->setPos(child->mapToParent(r.topLeft()) + o);
+ }
+
// qDebug() << "resize"
// << "\nbefore:" << child->rect()
// << "\nafter:" << rect
More information about the Kst
mailing list