[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/krita/core
From:       Adrian Page <adrian () pagenet ! plus ! com>
Date:       2006-01-22 19:01:17
Message-ID: 1137956477.971307.1698.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 501381 by page:

Make moving a group layer move all the layers it contains.


 M  +43 -2     kis_group_layer.cc  
 M  +7 -4      kis_group_layer.h  
 M  +11 -7     kis_strategy_move.cc  


--- trunk/koffice/krita/core/kis_group_layer.cc #501380:501381
@@ -28,12 +28,17 @@
 #include "kis_group_layer.h"
 
 KisGroupLayer::KisGroupLayer(KisImage *img, const QString &name, Q_UINT8 opacity) :
-    super(img, name, opacity)
+    super(img, name, opacity),
+    m_x(0),
+    m_y(0)
 {
     m_projection = new KisPaintDeviceImpl(img, img->colorSpace());
 }
 
-KisGroupLayer::KisGroupLayer(const KisGroupLayer &rhs) : super(rhs)
+KisGroupLayer::KisGroupLayer(const KisGroupLayer &rhs) : 
+    super(rhs),
+    m_x(rhs.m_x),
+    m_y(rhs.m_y)
 {
     for(vKisLayerSP_cit it = rhs.m_layers.begin(); it != rhs.m_layers.end(); ++it)
     {
@@ -183,4 +188,40 @@
     return groupExactBounds;
 }
 
+Q_INT32 KisGroupLayer::x() const
+{
+    return m_x;
+}
+
+void KisGroupLayer::setX(Q_INT32 x)
+{
+    Q_INT32 delta = x - m_x;
+
+    for (vKisLayerSP_cit it = m_layers.begin(); it != m_layers.end(); ++it)
+    {
+        KisLayerSP layer = *it;
+        layer->setX(layer->x() + delta);
+    }
+
+    m_x = x;
+}
+
+Q_INT32 KisGroupLayer::y() const
+{
+    return m_y;
+}
+
+void KisGroupLayer::setY(Q_INT32 y)
+{
+    Q_INT32 delta = y - m_y;
+
+    for (vKisLayerSP_cit it = m_layers.begin(); it != m_layers.end(); ++it)
+    {
+        KisLayerSP layer = *it;
+        layer->setY(layer->y() + delta);
+    }
+
+    m_y = y;
+}
+
 #include "kis_group_layer.moc"
--- trunk/koffice/krita/core/kis_group_layer.h #501380:501381
@@ -47,11 +47,11 @@
 
     virtual void deactivate() {};
 
-    virtual Q_INT32 x() const {return 0;};
-    virtual void setX(Q_INT32) {};
+    virtual Q_INT32 x() const;
+    virtual void setX(Q_INT32);
 
-    virtual Q_INT32 y() const {return 0;};
-    virtual void setY(Q_INT32) {};
+    virtual Q_INT32 y() const;
+    virtual void setY(Q_INT32);
 
     // Sets this layer and all its descendants' owner image to the given image.
     virtual void setImage(KisImage *image);
@@ -101,6 +101,9 @@
     inline int reverseIndex(int index) const { return childCount() - 1 - index; };
     vKisLayerSP m_layers; // Contains the list of all layers
     KisPaintDeviceImplSP m_projection; // The cached composition of all layers in this group
+
+    Q_INT32 m_x;
+    Q_INT32 m_y;
 };
 
 #endif // KIS_GROUP_LAYER_H_
--- trunk/koffice/krita/core/kis_strategy_move.cc #501380:501381
@@ -16,12 +16,13 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include <stdlib.h>
 #include <qpoint.h>
+#include <qcolor.h>
+
 #include <kaction.h>
 #include <kcommand.h>
 #include <klocale.h>
-#include <qcolor.h>
+#include <kdebug.h>
 
 #include "kis_canvas_controller.h"
 #include "kis_canvas_subject.h"
@@ -47,7 +48,7 @@
     private:
         KisCanvasController *m_controller;
         KisLayerSP m_device;
-        QRect m_deviceBounds;
+        QRect m_updateRect;
         QPoint m_oldPos;
         QPoint m_newPos;
         KisImageSP m_img;
@@ -61,7 +62,12 @@
         m_device = device;
         m_oldPos = oldpos;
         m_newPos = newpos;
-        m_deviceBounds = m_device->exactBounds();
+
+        QRect currentBounds = m_device->exactBounds();
+        QRect oldBounds = currentBounds;
+        oldBounds.moveBy(oldpos.x() - newpos.x(), oldpos.y() - newpos.y());
+
+        m_updateRect = currentBounds | oldBounds;
     }
 
     MoveCommand::~MoveCommand()
@@ -82,9 +88,7 @@
     {
        m_device -> setX(pos.x());
        m_device -> setY(pos.y());
-       m_deviceBounds |= QRect(pos.x(), pos.y(), m_deviceBounds.width(), m_deviceBounds.height());
-       m_img -> notify(m_deviceBounds);
-       m_deviceBounds.setRect(pos.x(), pos.y(), m_deviceBounds.width(), m_deviceBounds.height());
+       m_img -> notify(m_updateRect);
     }
 }
 
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic