Bug 131738

Summary: Problem when moving end point of line outside of parent
Product: [Applications] kst Reporter: Andrew Walker <arwalker>
Component: generalAssignee: kst
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: 1.x   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Andrew Walker 2006-08-02 19:34:28 UTC
Version:           HEAD (using KDE KDE 3.5.0)
Installed from:    Compiled From Sources
OS:                Linux

PROBLEM:
The "clipping" behaviour when an end point of a line is moved outside of its parent is inconsistent with the behaviour during line creation and is overly simplistic

STEPS TO REPRODUCE:
Start Kst
Create a line in the default window (this works best in childframe mode)
Switch to layout mode
Select the line
Click on an endpoint of the line
Drag the endpoint outside of the window and move it around

RESULTS:
The line is "clipped" to the window by a simplistic algortihm such that the line does not lie between the fixed end-point and the cursor.

EXPECTED RESULTS:
The line is "clipped" such that it does lie between the fixed end-point and the cursor, as is the case during creation of a new line.
Comment 1 Duncan Hanson 2006-08-02 19:55:18 UTC
The fix for this is the 2 line change which I mentioned in CCBUG:131679

On Wed, 2006-08-02 at 17:34 +0000, Andrew Walker wrote:
[bugs.kde.org quoted mail]
Comment 2 Andrew Walker 2006-08-03 20:11:00 UTC
SVN commit 569391 by arwalker:

BUG:131738 Better restrict a line being resized to its parent - also more consistent with behaviour during line creation

 M  +12 -8     kstgfxmousehandlerutils.cpp  
 M  +8 -11     ksttoplevelview.cpp  


--- trunk/extragear/graphics/kst/src/libkstapp/kstgfxmousehandlerutils.cpp #569390:569391
@@ -29,10 +29,14 @@
 QPoint KstGfxMouseHandlerUtils::findNearestPtOnLine(const QPoint& fromPoint, const QPoint& toPoint, const QPoint& pos, const QRect &bounds) {
   QPoint npos = pos;
   
-  if (fromPoint.y() == toPoint.y() ) {
+  if (fromPoint.y() == toPoint.y()) {
     npos.setY(fromPoint.y());
+    npos.setX(kMax(npos.x(), bounds.left()));
+    npos.setX(kMin(npos.x(), bounds.right()));
   } else if (fromPoint.x() == toPoint.x()) {
     npos.setX(fromPoint.x());
+    npos.setY(kMax(npos.y(), bounds.top()));
+    npos.setY(kMin(npos.y(), bounds.bottom()));
   } else {
     double newxpos, newypos;
     double slope = double(toPoint.y() - fromPoint.y()) / double(toPoint.x() - fromPoint.x());
@@ -61,14 +65,14 @@
 
   if (maintainAspect) {
     QPoint fakeMovePoint = anchorPoint + QPoint(quadrantSign(pos,anchorPoint)*abs((movePoint - anchorPoint).x()),abs((movePoint - anchorPoint).y())); // allow the rectangle to flip.
-
     npos = findNearestPtOnLine(anchorPoint, fakeMovePoint, pos, bounds);
   }
-
+  
   newSize.setTopLeft(anchorPoint);
   newSize.setBottomRight(npos);
   newSize = newSize.normalize();
-
+  newSize = bounds.intersect(newSize);
+  
   return newSize;
 }
 
@@ -183,9 +187,9 @@
     QPoint mouseDisplacement(pos - mouseOrigin); // for picking type of line..
 
     if (mouseDisplacement.x() == 0) { // vertical line.
-      npos = findNearestPtOnLine(mouseOrigin,mouseOrigin + QPoint(0,1), pos, bounds);
+      npos = findNearestPtOnLine(mouseOrigin, mouseOrigin + QPoint(0,1), pos, bounds);
     } else if (mouseDisplacement.y() == 0) { // horizontal line.
-      npos = findNearestPtOnLine(mouseOrigin,mouseOrigin + QPoint(1,0), pos, bounds);
+      npos = findNearestPtOnLine(mouseOrigin, mouseOrigin + QPoint(1,0), pos, bounds);
     } else { // 45deg or vertical or horizontal.
       int dx = int(round(2.0*mouseDisplacement.x()/abs(mouseDisplacement.y())));
       int dy = int(round(2.0*mouseDisplacement.y()/abs(mouseDisplacement.x())));
@@ -197,9 +201,9 @@
         dy /= abs(dy);
       }
   
-      npos = findNearestPtOnLine(mouseOrigin,mouseOrigin + QPoint(dx,dy), pos, bounds);
+      npos = findNearestPtOnLine(mouseOrigin, mouseOrigin + QPoint(dx,dy), pos, bounds);
     }
-    return QRect(mouseOrigin,npos);
+    return QRect(mouseOrigin, npos);
   }
 }
 
--- trunk/extragear/graphics/kst/src/libkstapp/ksttoplevelview.cpp #569390:569391
@@ -782,14 +782,7 @@
   // for now we only know how to deal with lines 
 
   const QRect bounds(_pressTarget->_parent->geometry());
-  QPoint npos(pos);
 
-  //pos must be inside the parent
-  npos.setX(kMax(npos.x(), bounds.left()));
-  npos.setX(kMin(npos.x(), bounds.right()));
-  npos.setY(kMin(npos.y(), bounds.bottom()));
-  npos.setY(kMax(npos.y(), bounds.top()));
-
   if (KstViewLinePtr line = kst_cast<KstViewLine>(_pressTarget)) {
     QPoint movePoint, anchorPoint;
     QPoint *fromPoint, *toPoint;
@@ -806,13 +799,17 @@
       fromPoint = &anchorPoint;
       toPoint = &movePoint;
     } else {
-      abort();
+      return;
     }
-
+    
     if (maintainAspect) {
-      movePoint = KstGfxMouseHandlerUtils::findNearestPtOnLine(anchorPoint, movePoint, npos, bounds);
+      movePoint = KstGfxMouseHandlerUtils::findNearestPtOnLine(anchorPoint, movePoint, pos, bounds);
     } else {
-      movePoint = npos; // already enforced pos inside parent.
+      if (bounds.contains(pos)) {
+        movePoint = pos;
+      } else {
+        movePoint = KstGfxMouseHandlerUtils::findNearestPtOnLine(anchorPoint, pos, pos, bounds);
+      }
     }
 
     const QRect old(_prevBand);