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

Andrew Walker arwalker at sumusltd.com
Wed May 17 23:07:10 CEST 2006


SVN commit 541977 by arwalker:

BUG:127536 Ensure moving object snaps to edges of all objects

 M  +2 -35     ksttoplevelview.cpp  
 M  +38 -0     kstviewobject.cpp  
 M  +2 -0      kstviewobject.h  


--- trunk/extragear/graphics/kst/src/libkstapp/ksttoplevelview.cpp #541976:541977
@@ -707,41 +707,8 @@
   int iXMin = STICKY_THRESHOLD;
   int iYMin = 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(&iXMin, &iYMin, _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(iXMin) < STICKY_THRESHOLD) {
     _moveOffsetSticky.setX(iXMin);
     topLeft.setX(topLeft.x() - iXMin);
@@ -751,7 +718,7 @@
     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 #541976:541977
@@ -463,6 +463,44 @@
 }
 
 
+void KstViewObject::snapToBorders(int *iXMin, int *iYMin, KstViewObjectList &selectionList, KstViewObjectPtr &pressTarget, const QRect &r) {
+  for (KstViewObjectList::Iterator i = _children.begin(); i != _children.end(); ++i) {
+    (*i)->snapToBorders(iXMin, iYMin, 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(*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();
+        }
+      }
+    }
+  }
+}
+
+
 void KstViewObject::appendChild(KstViewObjectPtr obj, bool keepAspect) {
   obj->_parent = this;
   _children.append(obj);
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewobject.h #541976:541977
@@ -118,6 +118,8 @@
     virtual bool maintainAspect() const;
     virtual void setMaintainAspect(bool maintain);
 
+    virtual void snapToBorders(int *iXMin, int *iYMin, KstViewObjectList &selectionList, KstViewObjectPtr &pressTarget, const QRect &r);
+    
     virtual void appendChild(KstViewObjectPtr obj, bool keepAspect = false);
     virtual void prependChild(KstViewObjectPtr obj, bool keepAspect = false);
     virtual bool removeChild(KstViewObjectPtr obj, bool recursive = false);


More information about the Kst mailing list