[Kst] extragear/graphics/kst/kst

Rick Chern rchern at interchange.ubc.ca
Mon Aug 8 23:10:19 CEST 2005


SVN commit 444118 by rchern:

Centred resize mode - allows ellipses to be resized (hotpoints for ellipses to come)

 M  +81 -2     ksttoplevelview.cpp  
 M  +2 -0      ksttoplevelview.h  
 M  +20 -0     kstviewellipse.cpp  
 M  +4 -0      kstviewellipse.h  


--- trunk/extragear/graphics/kst/kst/ksttoplevelview.cpp #444117:444118
@@ -290,6 +290,9 @@
 void KstTopLevelView::setCursorFor(const QPoint& pos, KstViewObjectPtr p) {
   char direction = p->directionFor(pos);
 
+  // cursor directions are the same for centred resize
+  direction = direction & ~CENTREDRESIZE;
+  
   switch (direction) {
     case UP:
     case DOWN:
@@ -429,7 +432,63 @@
     default:
       break;
   }
+  return resizeSnapToObjects(r, direction);
+}
+
+
+QRect KstTopLevelView::newSizeCentred(const QRect& oldSize, int direction, const QPoint& pos) {
+  QPoint centre = QPoint((oldSize.left()+oldSize.right())/2, 
+                          (oldSize.top() + oldSize.bottom())/2);
+  QRect rect = oldSize;
+  switch (_pressDirection & (UP|DOWN)) {
+    case UP:
+      if (pos.y() <= centre.y()) {
+        rect.setTop(pos.y());
+        rect.setBottom(2*centre.y() - pos.y());
+      } else {
+        rect.setTop(centre.y());
+        rect.setBottom(centre.y());  
+      }
+      break;
+    case DOWN:
+      if (pos.y() >= centre.y()) {
+        rect.setBottom(pos.y());
+        rect.setTop(2*centre.y() - pos.y());
+      } else {
+        rect.setTop(centre.y());
+        rect.setBottom(centre.y());  
+      }
+    default:
+      break;
+  }
   
+  switch (direction & (LEFT|RIGHT)) {
+    case LEFT:
+      if (pos.x() <= centre.x()) {
+        rect.setLeft(pos.x());
+        rect.setRight(2*centre.x() - pos.x());
+      } else {
+        rect.setLeft(centre.x());
+        rect.setRight(centre.x());  
+      }
+      break;
+    case RIGHT:
+      if (pos.x() >= centre.x()) {
+        rect.setRight(pos.x());
+        rect.setLeft(2*centre.x() - pos.x());
+      } else {
+        rect.setRight(centre.x());
+        rect.setLeft(centre.x());  
+      }
+      break;
+  }  
+  
+  return resizeSnapToObjects(rect, direction);
+}
+
+
+QRect KstTopLevelView::resizeSnapToObjects(const QRect& objGeometry, int direction) {
+  QRect r = objGeometry;
   {
     int iXMin = STICKY_THRESHOLD;
     int iYMin = STICKY_THRESHOLD;
@@ -496,7 +555,6 @@
   }
   
   r = r.normalize();
-  
   return r;
 }
 
@@ -722,7 +780,24 @@
 
 
 void KstTopLevelView::pressMoveLayoutModeCentredResize(const QPoint& pos, bool shift) {
+  //centred resize means that the centre of the object stays constant
+  QRect old = _prevBand;
   
+  _prevBand = newSizeCentred(_pressTarget->geometry(), _pressDirection, pos);
+  _prevBand = _prevBand.intersect(_geom);
+  if (_prevBand != old) {
+    QPainter p;
+        
+    p.begin(_w);
+    p.setRasterOp(Qt::XorROP);
+    if (old.topLeft() != QPoint(-1, -1)) {
+      p.drawWinFocusRect(old);
+    } else {     
+      p.drawWinFocusRect(_pressTarget->geometry());
+    }
+    p.drawWinFocusRect(_prevBand);
+    p.end();
+  }
 }
 
 KstViewObjectPtr KstTopLevelView::findChildOfModeType(const QPoint& pos, bool borderForTransparent) {
@@ -907,7 +982,11 @@
 
 
 void KstTopLevelView::releasePressLayoutModeCentredResize(const QPoint& pos, bool shift) {
-    
+  QRect r = newSizeCentred(_pressTarget->geometry(), _pressDirection, pos).intersect(_geom);
+        
+  _pressTarget->move(r.topLeft());
+  _pressTarget->resize(r.size());
+  _onGrid = false;
 }
 
 
--- trunk/extragear/graphics/kst/kst/ksttoplevelview.h #444117:444118
@@ -138,6 +138,8 @@
     bool popupMenu(KPopupMenu *menu, const QPoint& pos);
     void checkPosition( KstViewObjectPtr pObject, QPoint point );
     QRect newSize(const QRect& oldSize, int direction, const QPoint& pos);
+    QRect newSizeCentred(const QRect& oldSize, int direction, const QPoint& pos);
+    QRect resizeSnapToObjects(const QRect& objGeometry, int direction);
 
     // Called as a response to drag re-entering widget()
     void restartMove();
--- trunk/extragear/graphics/kst/kst/kstviewellipse.cpp #444117:444118
@@ -101,5 +101,25 @@
 }
 
 
+signed int KstViewEllipse::directionFor(const QPoint& pos) {
+  signed int direction = KstViewObject::directionFor(pos);
+  if (direction != 0) {
+    // not moving, so in any resize direction, we want it centred
+    direction |= CENTREDRESIZE;  
+  }  
+  return direction;
+}
+
+
+void KstViewEllipse::drawFocusRect(QPainter& p) {
+  KstViewObject::drawFocusRect(p);
+}
+
+
+void KstViewEllipse::drawSelectRect(QPainter& p) {
+  KstViewObject::drawFocusRect(p);
+}
+
+
 #include "kstviewellipse.moc"
 // vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/kst/kstviewellipse.h #444117:444118
@@ -51,6 +51,10 @@
     
     virtual QMap<QString, QPair<QString, QString> > dialogData() const;
     
+    virtual signed int directionFor(const QPoint& pos);
+    virtual void drawFocusRect(QPainter& p);
+    virtual void drawSelectRect(QPainter& p);
+    
   private:
     int _borderWidth;
     QColor _borderColor;


More information about the Kst mailing list