[Kst] extragear/graphics/kst/kst

Rick Chern rchern at interchange.ubc.ca
Fri Aug 5 00:51:36 CEST 2005


SVN commit 443110 by rchern:

Draw pictures as they are dragged, and show X on gray background if no image can be drawn.

 M  +31 -7     kstgfxpicturemousehandler.cpp  
 M  +0 -1      kstgfxrectanglemousehandler.cpp  
 M  +14 -9     ksttoplevelview.cpp  
 M  +24 -15    kstviewpicture.cpp  


--- trunk/extragear/graphics/kst/kst/kstgfxpicturemousehandler.cpp #443109:443110
@@ -15,6 +15,8 @@
  *                                                                         *
  ***************************************************************************/
 
+#include <stdlib.h>
+  
 #include "kstgfxpicturemousehandler.h"
 #include "kst.h"
 
@@ -30,17 +32,39 @@
 
 
 void KstGfxPictureMouseHandler::pressMove(const QPoint& pos, bool shift) {
-  // nothing to do for now
+  if (!_drawingPicture) {
+    _drawingPicture = new KstViewPicture();
+    // don't copy defaults - images shouldn't be sticky
+    _top->appendChild(KstViewObjectPtr(_drawingPicture));
+  }
+  
+  // set its corner point appropriately
+  QPoint newTopLeft;
+  if (_mouseOrigin.x() < pos.x()) {
+    newTopLeft.setX(_mouseOrigin.x());
+  } else {
+    newTopLeft.setX(pos.x());
+  }
+  if (_mouseOrigin.y() < pos.y()) {
+    newTopLeft.setY(_mouseOrigin.y());
+  } else {
+    newTopLeft.setY(pos.y());  
+  }
+  QSize newSize(abs(pos.x() - _mouseOrigin.x()),
+                abs(pos.y() - _mouseOrigin.y()));
+  _drawingPicture->move(newTopLeft);
+  _drawingPicture->resize(newSize);
+  _top->paint(P_PAINT);
 }
 
 
 void KstGfxPictureMouseHandler::releasePress(const QPoint& pos, bool shift) {
-    // once released, create a new picture object and popup the edit dialog
-  _drawingPicture = new KstViewPicture();
-  _top->appendChild(KstViewObjectPtr(_drawingPicture));
-  _drawingPicture->move(pos);
-  _drawingPicture->restoreSize();
-  KstApp::inst()->showEditViewObjectDialog(KstViewObjectPtr(_drawingPicture), _top);
+  // once released, popup the edit dialog
+  if (_drawingPicture) {
+    KstApp::inst()->showEditViewObjectDialog(KstViewObjectPtr(_drawingPicture), _top);
+  }
+  _drawingPicture = 0L;
+  _mouseOrigin = QPoint(-1,-1);
 }
 
 
--- trunk/extragear/graphics/kst/kst/kstgfxrectanglemousehandler.cpp #443109:443110
@@ -44,7 +44,6 @@
     _drawingRectangle = new KstViewBox();
     copyDefaults(KstViewObjectPtr(_drawingRectangle));
     _top->appendChild(KstViewObjectPtr(_drawingRectangle));
-    // TODO: set some defaults based on last used values  
   }
   
   // set its corner point appropriately
--- trunk/extragear/graphics/kst/kst/ksttoplevelview.cpp #443109:443110
@@ -214,6 +214,11 @@
 
 
 void KstTopLevelView::updateFocus(const QPoint& pos) {
+  
+  if (_activeMouseHandler) {
+    _activeMouseHandler->updateFocus(pos);
+    return;  
+  }
 
   if (_mode == DisplayMode || _mode == Unknown || tracking()) {
     return;
@@ -518,6 +523,11 @@
 // Optimize me: can store, for instance, the painter I think
 void KstTopLevelView::pressMove(const QPoint& pos, bool shift) {
   
+  if (_activeMouseHandler) {
+    _activeMouseHandler->pressMove(pos, shift);  
+    return;
+  }
+  
   // in these cases there is nothing to do         
   if (_mode == DisplayMode || _mode == Unknown) {
     _pressTarget = 0L;
@@ -534,15 +544,10 @@
   
   _mouseMoved = true;
   
-  if (_pressTarget) {
-    // handle as in layout mode
-    pressMoveLayoutMode(pos, shift);  
-    return;
-  }
-  
-  if (_activeMouseHandler) {
-    _activeMouseHandler->pressMove(pos, shift);  
-  }
+  // handle as in layout mode
+  pressMoveLayoutMode(pos, shift);  
+  return;
+
 }
 
 
--- trunk/extragear/graphics/kst/kst/kstviewpicture.cpp #443109:443110
@@ -53,26 +53,35 @@
 
 void KstViewPicture::paint(KstPaintType type, QPainter& p) {
   KstBorderedViewObject::paint(type, p);
-  QRect cr = contentsRect();
-  if (_iCache.isNull() || _iCache.size() != cr.size()) {
-    _iCache = _image.copy();
+  if (_image.isNull()) {
+    // fill with X
+    p.fillRect(geometry(), Qt::gray);
+    p.setPen(QPen(Qt::black, 0, Qt::SolidLine));
+    p.drawLine(geometry().topLeft(), geometry().bottomRight());
+    p.drawLine(geometry().topRight(), geometry().bottomLeft());
+    p.drawRect(geometry());
+  } else {
+    QRect cr = contentsRect();
+    if (_iCache.isNull() || _iCache.size() != cr.size()) {
+      _iCache = _image.copy();
+      if (!_iCache.isNull()) {
+        _iCache = _iCache.smoothScale(cr.size());
+      }
+    }
     if (!_iCache.isNull()) {
-      _iCache = _iCache.smoothScale(cr.size());
-    }
-  }
-  if (!_iCache.isNull()) {
-    if (p.rasterOp() == Qt::SetROP) { // HACK!!  we look for depth=1
+      if (p.rasterOp() == Qt::SetROP) { // HACK!!  we look for depth=1
                                       // which indicates clipping / BW mode
-      if (_iCache.hasAlphaBuffer()) {
-        p.drawImage(contentsRect().topLeft(), _iCache.createAlphaMask());
+        if (_iCache.hasAlphaBuffer()) {
+          p.drawImage(contentsRect().topLeft(), _iCache.createAlphaMask());
+        } else {
+          p.setBrush(Qt::color0);
+          p.drawRect(contentsRect());
+        }
       } else {
-        p.setBrush(Qt::color0);
-        p.drawRect(contentsRect());
+        p.drawImage(contentsRect().topLeft(), _iCache);
       }
-    } else {
-      p.drawImage(contentsRect().topLeft(), _iCache);
     }
-  }
+  }   
 }
 
 


More information about the Kst mailing list