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

List:       kde-commits
Subject:    playground/office/flake
From:       Thomas Zander <zander () kde ! org>
Date:       2006-05-14 10:24:57
Message-ID: 1147602297.907793.3142.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 540634 by zander:

Add an option to simply group shapes like found in karbon.


 M  +8 -0      lib/KoInteractionTool.h  
 M  +22 -3     lib/KoSelection.cpp  
 M  +3 -0      lib/KoShapeContainer.cpp  
 M  +6 -0      lib/KoShapeContainer.h  
 A             lib/KoShapeGroup.cpp   [License: LGPL (v2+)]
 A             lib/KoShapeGroup.h   [License: LGPL (v2+)]
 M  +0 -7      lib/TODO  
 M  +2 -2      lib/lib.pro  
 M  +21 -1     testapp/mainwindow.cpp  


--- trunk/playground/office/flake/lib/KoInteractionTool.h #540633:540634
@@ -90,6 +90,14 @@
     virtual void paint( QPainter &painter, KoViewConverter &converter );
 
     void repaintDecorations();
+    /**
+     * Returns which selection handle is at params point (or NoHandle if none).
+     * @return which selection handle is at params point (or NoHandle if none).
+     * @param point the location (in pt) where we should look for a handle
+     * @param innerHandleMeaning this boolean is altered to true if the point
+     *   is inside the selection rectangle and false if it is just outside.
+     *   The value of innerHandleMeaning is undefined if the handle location is NoHandle
+     */
     SelectionHandle handleAt(const QPointF &point, bool *innerHandleMeaning = 0);
 
 public: // Events
--- trunk/playground/office/flake/lib/KoSelection.cpp #540633:540634
@@ -21,6 +21,7 @@
 
 #include "KoSelection.h"
 #include "KoShapeContainer.h"
+#include "KoShapeGroup.h"
 #include "KoGfxEvent.h"
 
 #include <QPainter>
@@ -50,10 +51,17 @@
 void KoSelection::select(KoShape * object)
 {
     Q_ASSERT(object != this);
-    //qDebug() << "Added object " << object;
     if(m_selectedObjects.contains(object))
         return;
     m_selectedObjects << object;
+    KoShapeGroup *group = dynamic_cast<KoShapeGroup*>(object->parent());
+    if(group && !m_selectedObjects.contains(group)) {
+        m_selectedObjects << group;
+        foreach(KoShape *shape, group->iterator()) {
+            if(! m_selectedObjects.contains(shape))
+                m_selectedObjects << shape;
+        }
+    }
     requestSelectionChangedEvent();
 }
 
@@ -61,7 +69,14 @@
 {
     if(! m_selectedObjects.contains(object))
         return;
-    m_selectedObjects.remove( object );
+    KoShapeGroup *group = dynamic_cast<KoShapeGroup*>(object->parent());
+    if(group) {
+        m_selectedObjects.remove(group);
+        foreach(KoShape *shape, group->iterator())
+            m_selectedObjects.remove(shape);
+    }
+    else
+        m_selectedObjects.remove( object );
     requestSelectionChangedEvent();
 }
 
@@ -116,6 +131,8 @@
         ++it;
         for ( ; it != m_selectedObjects.end(); ++it )
         {
+            if( dynamic_cast<KoShapeGroup*>( *it ))
+                continue;
             bb = bb.unite( ( *it )->boundingBox() );
         }
     }
@@ -128,9 +145,11 @@
     bool doStripping = strip == StrippedSelection;
     foreach (KoShape *shape, m_selectedObjects) {
         KoShapeContainer *container = shape->parent();
+        if(dynamic_cast<KoShapeGroup*>(shape))
+            continue;
         bool add = true;
         while(doStripping && add && container) {
-            if(m_selectedObjects.contains(container))
+            if(dynamic_cast<KoShapeGroup*>(container) == 0 && m_selectedObjects.contains(container))
                 add = false;
             container = container->parent();
         }
--- trunk/playground/office/flake/lib/KoShapeContainer.cpp #540633:540634
@@ -186,6 +186,9 @@
         shape->repaint();
 }
 
+QList<KoShape*> KoShapeContainer::iterator() const {
+    return m_children->iterator();
+}
 
 // ## inner class KoGraphicsContainerModel::Relation
 KoShapeContainer::ChildrenData::Relation::Relation(KoShape *child)
--- trunk/playground/office/flake/lib/KoShapeContainer.h #540633:540634
@@ -182,6 +182,12 @@
 
     void repaint() const;
 
+    /**
+     * Create and return an iterator over all child objects.
+     * @return an interator over all child objects.
+     */
+    QList<KoShape*> iterator() const;
+
 private:
     /**
      */
--- trunk/playground/office/flake/lib/TODO #540633:540634
@@ -10,10 +10,3 @@
     Also here a bool for the destructor -> del KoShape
 * discuss possibility to move KoShapp::m_connectors to a specialized class
   (since its only for Kivio)
-* add a boolean to the Container to make it 'virtual' where a virtual container has
-  the following changes;
-    - it will never be drawn (naturally its children will be)
-    - all its children are non-inline
-    - clicking on a child will select all children (but not the parent)
-    - you can not select the parent.
-
--- trunk/playground/office/flake/lib/lib.pro #540633:540634
@@ -10,9 +10,9 @@
            KoTool.h KoInteractionTool.h KoCommand.h \
            KoInteractionStrategy.h KoShapeMoveStrategy.h \
            KoShapeRubberSelectStrategy.h KoViewConverter.h \
-           KoShapeRotateStrategy.h
+           KoShapeRotateStrategy.h KoShapeGroup.h
 SOURCES += KoShape.cpp KoPathShape.cpp KoSelection.cpp KoGfxStyle.cpp \
            KoShapeManager.cpp KoShapeContainer.cpp KoRepaintManager.cpp \
            KoInteractionTool.cpp KoShapeMoveStrategy.cpp KoShapeRubberSelectStrategy.cpp \
            KoRectangleShape.cpp KoCommand.cpp KoInteractionStrategy.cpp KoTool.cpp \
-           KoShapeRotateStrategy.cpp
+           KoShapeRotateStrategy.cpp KoShapeGroup.cpp
--- trunk/playground/office/flake/testapp/mainwindow.cpp #540633:540634
@@ -34,6 +34,7 @@
 
 #include <KoShape.h>
 #include <KoShapeManager.h>
+#include <KoShapeGroup.h>
 #include <KoRectangleShape.h>
 #include <KoPathShape.h>
 #include <KoGfxEvent.h>
@@ -119,8 +120,27 @@
     container2->addChild(kgb5);
     container2->setClipping(kgb5, true);
 
+    KoShapeGroup *group = new KoShapeGroup();
+    KoShape *red = new KoRectangleShape();
+    red->style().setFill( Qt::red );
+    red->resize(QSizeF(40,10));
+    red->setPosition(QPointF(120,10));
+    KoShape *white = new KoRectangleShape();
+    white->style().setFill( Qt::white );
+    white->resize(QSizeF(40,10));
+    white->setPosition(QPointF(120,20));
+    KoShape *blue = new KoRectangleShape();
+    blue->style().setFill( Qt::blue );
+    blue->resize(QSizeF(40,10));
+    blue->setPosition(QPointF(120,30));
+    group->addChild(red);
+    group->addChild(white);
+    group->addChild(blue);
+    group->setZIndex(4);
+
     QList<KoShape *> objects;
-    objects << kgb << kgb2 << kgb3 << container << kgb4 << container2 << image << kgb5;
+    objects << kgb << kgb2 << kgb3 << container << kgb4 << container2 << image << kgb5 <<
+            red << white << blue << group;
     return objects;
 }
 
[prev in list] [next in list] [prev in thread] [next in thread] 

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