[Kst] extragear/graphics/kst/src/libkstapp

Andrew Walker arwalker at sumusltd.com
Thu May 25 20:37:11 CEST 2006


SVN commit 544672 by arwalker:

BUG:127536 Ensure that when mocing sticky borders apply to all objects and not just top-level objects.

 M  +10 -43    ksttoplevelview.cpp  
 M  +39 -0     kstviewobject.cpp  
 M  +2 -0      kstviewobject.h  


--- trunk/extragear/graphics/kst/src/libkstapp/ksttoplevelview.cpp #544671:544672
@@ -704,54 +704,21 @@
   r.moveTopLeft(topLeft);
   _moveOffsetSticky = QPoint(0, 0);
       
-  int iXMin = STICKY_THRESHOLD;
-  int iYMin = STICKY_THRESHOLD;
+  int xMin = STICKY_THRESHOLD;
+  int yMin = STICKY_THRESHOLD;
 
-  // check for "sticky" borders
-  for (KstViewObjectList::Iterator i = _children.begin(); i != _children.end(); ++i) {
-    if (_selectionList.find(*i) == _selectionList.end() && _pressTarget != *i) {           
-      const QRect rect((*i)->geometry());
+  snapToBorders(&xMin, &yMin, _selectionList, _pressTarget, r);
 
-      int overlapLo = r.top() > rect.top() ? r.top() : rect.top();
-      int overlapHi = r.bottom() < rect.bottom() ? r.bottom() : rect.bottom();
-      if (overlapHi - overlapLo > 0) {
-        if (labs(r.left() - rect.left()) < labs(iXMin)) {
-          iXMin = r.left() - rect.left();
-        } else if (labs(r.left() - rect.right()) < labs(iXMin)) {
-          iXMin = r.left() - rect.right();              
-        } else if (labs(r.right() - rect.left()) < labs(iXMin)) {
-          iXMin = r.right() - rect.left();
-        } else if (labs(r.right() - rect.right()) < labs(iXMin)) {
-          iXMin = r.right() - rect.right();
-        }                 
-      }
-
-      overlapLo = r.left() > rect.left() ? r.left() : rect.left();
-      overlapHi = r.right() < rect.right() ? r.right() : rect.right();
-      if (overlapHi - overlapLo > 0) {
-        if (labs(r.top() - rect.top()) < labs(iYMin)) {
-          iYMin = r.top() - rect.top();
-        } else if (labs(r.top() - rect.bottom()) < labs(iYMin)) {
-          iYMin = r.top() - rect.bottom();              
-        } else if (labs(r.bottom() - rect.top()) < labs(iYMin)) {
-          iYMin = r.bottom() - rect.top();
-        } else if (labs(r.bottom() - rect.bottom()) < labs(iYMin)) {
-          iYMin = r.bottom() - rect.bottom();
-        }
-      }
-    }
+  if (labs(xMin) < STICKY_THRESHOLD) {
+    _moveOffsetSticky.setX(xMin);
+    topLeft.setX(topLeft.x() - xMin);
   }
-
-  if (labs(iXMin) < STICKY_THRESHOLD) {
-    _moveOffsetSticky.setX(iXMin);
-    topLeft.setX(topLeft.x() - iXMin);
+  if (labs(yMin) < STICKY_THRESHOLD) {
+    _moveOffsetSticky.setY(yMin);
+    topLeft.setY(topLeft.y() - yMin);
   }
-  if (labs(iYMin) < STICKY_THRESHOLD) {
-    _moveOffsetSticky.setY(iYMin);
-    topLeft.setY(topLeft.y() - iYMin);
-  }
 
-  r.moveTopLeft(topLeft);      
+  r.moveTopLeft(topLeft);
 
   if (!_geom.contains(r, true)) {
     slideInto(_geom, r);
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewobject.cpp #544671:544672
@@ -1470,6 +1470,45 @@
 }
 
 
+void KstViewObject::snapToBorders(int *xMin, int *yMin, const KstViewObjectList &selectionList, const KstViewObjectPtr &pressTarget, const QRect &r) const {
+  for (KstViewObjectList::ConstIterator i = _children.begin(); i != _children.end(); ++i) {
+    (*i)->snapToBorders(xMin, yMin, selectionList, pressTarget, r);
+    
+    if (selectionList.find(*i) == selectionList.end() && pressTarget != *i) {
+      const QRect rect((*i)->geometry());
+        
+      int overlapLo = r.top() > rect.top() ? r.top() : rect.top();
+      int overlapHi = r.bottom() < rect.bottom() ? r.bottom() : rect.bottom();
+      if (overlapHi - overlapLo > 0) {
+        if (labs(r.left() - rect.left()) < labs(*xMin)) {
+          *xMin = r.left() - rect.left();
+        } else if (labs(r.left() - rect.right()) < labs(*xMin)) {
+          *xMin = r.left() - rect.right();
+        } else if (labs(r.right() - rect.left()) < labs(*xMin)) {
+          *xMin = r.right() - rect.left();
+        } else if (labs(r.right() - rect.right()) < labs(*xMin)) {
+          *xMin = r.right() - rect.right();
+        }
+      }
+  
+      overlapLo = r.left() > rect.left() ? r.left() : rect.left();
+      overlapHi = r.right() < rect.right() ? r.right() : rect.right();
+      if (overlapHi - overlapLo > 0) {
+        if (labs(r.top() - rect.top()) < labs(*yMin)) {
+          *yMin = r.top() - rect.top();
+        } else if (labs(r.top() - rect.bottom()) < labs(*yMin)) {
+          *yMin = r.top() - rect.bottom();
+        } else if (labs(r.bottom() - rect.top()) < labs(*yMin)) {
+          *yMin = r.bottom() - rect.top();
+        } else if (labs(r.bottom() - rect.bottom()) < labs(*yMin)) {
+          *yMin = r.bottom() - rect.bottom();
+        }
+      }
+    }
+  }
+}
+
+
 bool KstViewObject::isSelected() const {
   return _selected;
 }
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewobject.h #544671:544672
@@ -163,6 +163,8 @@
     virtual void updateSelection(const QRect& region);
     bool isContainer() const;
     
+    virtual void snapToBorders(int *xMin, int *yMin, const KstViewObjectList &selectionList, const KstViewObjectPtr &pressTarget, const QRect &r) const;
+    
     KstViewObjectPtr parent() const;
 
     void recursively(void (KstViewObject::*)(), bool self = false);


More information about the Kst mailing list