Bug 121082 - child view object placement seems to use stale parent geometry info
Summary: child view object placement seems to use stale parent geometry info
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: unspecified Linux
: VHI normal
Target Milestone: ---
Assignee: kst
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-31 06:41 UTC by Netterfield
Modified: 2006-02-10 00:06 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Netterfield 2006-01-31 06:41:45 UTC
Version:           1.2.0_devel (using KDE 3.4.3, Gentoo)
Compiler:          gcc version 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)
OS:                Linux (x86_64) release 2.6.12-gentoo-r6

Draw a line between two distinct data points on a plot.

Slowly resize the plot - the line moves with the data, ~as desired.

Resize quickly (faster than kst can keep up).  The final line position will no longer track the data... Move slowly again - it will jump back to where it is suppose to.

This also effects printing, even more strongly; it also effects printing font sizes...
Comment 1 George Staikos 2006-02-02 12:11:38 UTC
I had noticed this as well.  It seems to be due entirely to axis alignment.  
The axis alignment changes the plot region in the plot draw code (in paint()) 
after we've finished resizing all the children.  On a move, they finally 
catch up to the parent because axis alignment doesn't change.  updateSelf() 
should do the axis alignment.
Comment 2 Netterfield 2006-02-02 18:43:54 UTC
This needs to be fixed (at least cosmetically) for 1.2.  
Comment 3 Andrew Walker 2006-02-03 19:33:08 UTC
The following is most likely the same bug:

Start Kst
Switch to Childframe MDI mode
In the default window creates two plots
Create a rectangle contained completely by one the plots
Maximize the window

The rectangle is drawn incorrectly
Comment 4 Andrew Walker 2006-02-03 19:39:04 UTC
This seems to be related to the new paint code, as it did not happen prior to the recent changes.
Comment 5 Andrew Walker 2006-02-03 19:39:59 UTC
SVN commit 505359 by arwalker:

BUG:121082 Restrict lines and arrows to their parent - consistent with other view objects.

 M  +80 -29    ksttoplevelview.cpp  
 M  +1 -0      ksttoplevelview.h  


--- trunk/extragear/graphics/kst/kst/ksttoplevelview.cpp #505358:505359
@@ -37,6 +37,7 @@
 #include "kstaccessibility.h"
 #include "kstdoc.h"
 #include "kstgfxmousehandler.h"
+#include "kstmath.h"
 #include "kstplotgroup.h"
 #include "kstsettings.h"
 #include "ksttimers.h"
@@ -780,12 +781,80 @@
 }
 
 
+QPoint KstTopLevelView::handlePoint(bool shift, const QPoint& ptFixed, const QPoint& pos, double aspect) {
+  QPoint ptMoved = pos;
+  
+  if (shift) {
+    double absAspect = fabs(aspect);
+    if (absAspect < 500.0 && (double(abs((pos.y() - ptFixed.y())/(pos.x() - ptFixed.x()))) < aspect || 
+        absAspect < 0.1)) {
+      ptMoved = QPoint(pos.x(), ptFixed.y() + int(aspect*(pos.x() - ptFixed.x())));
+    } else {
+      ptMoved = QPoint(ptFixed.x() + int((pos.y() - ptFixed.y())/aspect), pos.y());
+    }
+  }
+  
+  //
+  // ensure that the point we just moved is contained by its parent...
+  //
+  QRect parentRect = _pressTarget->_parent->_geom;
+  if (parentRect.contains(ptFixed) && !parentRect.contains(ptMoved)) {
+    double gradient;
+    bool found = false;
+    int x;
+    int y;
+    
+    if (!found && ptMoved.x() < parentRect.left()) {
+      gradient = double(ptMoved.y() - ptFixed.y())/double(ptMoved.x() - ptFixed.x());
+      x = parentRect.left();
+      y = ptFixed.y() + d2i(double(x - ptFixed.x()) * gradient);
+      if (y >= parentRect.top() && y <= parentRect.bottom()) {
+        found = true;
+      }
+    }
+    if (!found && ptMoved.x() > parentRect.right()) {
+      gradient = double(ptMoved.y() - ptFixed.y())/double(ptMoved.x() - ptFixed.x());
+      x = parentRect.right();
+      y = ptFixed.y() + d2i(double(x - ptFixed.x()) * gradient);
+      if (y >= parentRect.top() && y <= parentRect.bottom()) {
+        found = true;
+      }
+    }
+    if (!found && ptMoved.y() < parentRect.top()) {
+      gradient = double(ptMoved.x() - ptFixed.x())/double(ptMoved.y() - ptFixed.y());
+      y = parentRect.top();
+      x = ptFixed.x() + d2i(double(y - ptFixed.y()) * gradient);
+      if (x >= parentRect.left() && x <= parentRect.right()) {
+        found = true;
+      }
+    }
+    if (!found && ptMoved.y() > parentRect.bottom()) {
+      gradient = double(ptMoved.x() - ptFixed.x())/double(ptMoved.y() - ptFixed.y());
+      y = parentRect.bottom();
+      x = ptFixed.x() + d2i(double(y - ptFixed.y()) * gradient);
+      if (x >= parentRect.left() && x <= parentRect.right()) {
+        found = true;
+      }
+    }
+
+    if (found) {
+      ptMoved.setX(x);
+      ptMoved.setY(y);
+    }
+  } 
+
+  return ptMoved;
+}
+
+
 void KstTopLevelView::pressMoveLayoutModeEndPoint(const QPoint& pos, bool shift) {
   // FIXME: remove this!!  Should not know about any specific type
   // for now we only know how to deal with lines 
   if (KstViewLinePtr line = kst_cast<KstViewLine>(_pressTarget)) {
     const QRect old(_prevBand);
+    QPoint ptFixed;
     double aspect;
+    
     if (line->to().x() != line->from().x()) {
       aspect = double(line->to().y() - line->from().y()) / double(line->to().x() - line->from().x());
     } else {
@@ -795,40 +864,22 @@
         aspect = 1.0E300;  
       }
     }
-    QPoint fromPoint, toPoint;
+        
     if (_pressDirection & UP) {
-      // UP means we are on the start endpoint
-      toPoint = line->to();
-      if (shift) {
-        double absAspect = fabs(aspect);
-        if (absAspect < 500 && (double(abs((pos.y() - toPoint.y())/(pos.x() - toPoint.x()))) < aspect || absAspect < 0.1)) {
-          fromPoint = QPoint(pos.x(), toPoint.y() + int(aspect*(pos.x() - toPoint.x())));
-        } else {
-          fromPoint = QPoint(toPoint.x() + int((pos.y() - toPoint.y())/aspect), pos.y());
-        }
-      } else {
-        fromPoint = pos;
-      }
+      // UP means we are on the "from" point
+      ptFixed = line->to();
+      _prevBand.setTopLeft(handlePoint(shift, ptFixed, pos, aspect));
+      _prevBand.setBottomRight(ptFixed);
     } else if (_pressDirection & DOWN) {
-      // DOWN means we are on the end endpoint
-      fromPoint = line->from();
-      if (shift) {
-        double absAspect = fabs(aspect);
-        if (absAspect < 500 && (double(abs((pos.y() - toPoint.y())/(pos.x() - toPoint.x()))) < aspect || absAspect < 0.1)) {
-          toPoint = QPoint(pos.x(), fromPoint.y() + int(aspect*(pos.x() - fromPoint.x())));
-        } else {
-          toPoint = QPoint(fromPoint.x() + int((pos.y() - fromPoint.y())/aspect), pos.y());
-        }
-      } else {
-        toPoint = pos;
-      }
+      // DOWN means we are on the "to" point
+      ptFixed = line->from();
+      _prevBand.setTopLeft(ptFixed);
+      _prevBand.setBottomRight(handlePoint(shift, ptFixed, pos, aspect));
     } else {
-      abort();
+      assert(false);
+      return;
     }
 
-    _prevBand.setTopLeft(fromPoint);
-    _prevBand.setBottomRight(toPoint);
-
     if (old != _prevBand) {
       KstPainter p;
       p.begin(_w);
--- trunk/extragear/graphics/kst/kst/ksttoplevelview.h #505358:505359
@@ -98,6 +98,7 @@
     void pressMove(const QPoint& pos, bool shift = false);
     void pressMoveLayoutMode(const QPoint& pos, bool shift = false);
     // helpers for pressMoveLayoutMode
+    QPoint handlePoint(bool shift, const QPoint& ptFixed, const QPoint& pos, double aspect);
     void pressMoveLayoutModeMove(const QPoint& pos, bool shift = false);
     void pressMoveLayoutModeResize(const QPoint& pos, bool shift = false);
     void pressMoveLayoutModeSelect(const QPoint& pos, bool shift = false);
Comment 6 Andrew Walker 2006-02-03 19:42:31 UTC
Sorry, wrong bug number.
Comment 7 Netterfield 2006-02-03 22:12:34 UTC
1.2.0 showstopper
Comment 8 George Staikos 2006-02-04 14:43:15 UTC
On Friday 03 February 2006 13:39, Andrew Walker wrote:
> This seems to be related to the new paint code, as it did not
> happen prior to the recent changes.


  No, it's not related to the new paint code.  It's due to the change that 
makes view objects adjust relative to the contentsRect instead of the 
geometry.  This is the desired behavior, but Kst2DPlot is messy and it's hard 
to get it right.
Comment 9 George Staikos 2006-02-10 00:06:40 UTC
SVN commit 507745 by staikos:

Objects are adjusted relative to the contents rect, not the parent geometry.
BUG: 121082


 M  +20 -49    kst2dplot.cpp  
 M  +0 -1      kst2dplot.h  
 M  +3 -3      kstviewlabel.cpp  
 M  +3 -2      kstviewlegend.cpp  
 M  +26 -10    kstviewobject.cpp