[Kst] [Bug 131738] Problem when moving end point of line outside of parent

Andrew Walker arwalker at sumusltd.com
Thu Aug 3 20:11:03 CEST 2006


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=131738         
arwalker sumusltd com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From arwalker sumusltd com  2006-08-03 20:11 -------
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);


More information about the Kst mailing list