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

List:       kde-commits
Subject:    koffice
From:       Sven Langkamp <longamp () reallygood ! de>
Date:       2006-07-28 20:25:32
Message-ID: 1154118332.851624.28733.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 567447 by langkamp:

added boundingRect parameter to distribute command

 M  +1 -1      karbon/karbon_view.cc  
 M  +21 -26    libs/flake/KoCommand.cpp  
 M  +3 -2      libs/flake/KoCommand.h  


--- trunk/koffice/karbon/karbon_view.cc #567446:567447
@@ -783,7 +783,7 @@
 	KoSelectionSet selectedShapes = selection->selectedShapes( \
KoFlake::TopLevelSelection );  if( selectedShapes.count() < 2) return;
 
-	KoShapeDistributeCommand *cmd = new KoShapeDistributeCommand( selectedShapes, \
distribute); +	KoShapeDistributeCommand *cmd = new KoShapeDistributeCommand( \
selectedShapes, distribute, selection->boundingRect());  
 	part()->commandHistory()->addCommand( cmd, true );
 }
--- trunk/koffice/libs/flake/KoCommand.cpp #567446:567447
@@ -375,7 +375,7 @@
     return i18n( "Align shapes" );
 }
 
-KoShapeDistributeCommand::KoShapeDistributeCommand( const KoSelectionSet &shapes, \
Distribute distribute ) +KoShapeDistributeCommand::KoShapeDistributeCommand( const \
KoSelectionSet &shapes, Distribute distribute,  QRectF boundingRect )  : \
m_distribute( distribute )  {
     QMap<double,KoShape*> sortedPos;
@@ -413,7 +413,7 @@
     KoShape* last = (--sortedPos.end()).value();
 
     // determine the available space to distribute
-    double space = getAvailableSpace( first, last, extent );
+    double space = getAvailableSpace( first, last, extent, boundingRect);
     double pos = 0.0, step = space / double(shapes.count() - 1);
 
     QList<QPointF> previousPositions;
@@ -425,40 +425,37 @@
         it.next();
         position = it.value()->position();
         previousPositions  << position;
-        if( it.value() == first || it.value() == last ) {
-            newPositions << position;
-            continue;
-        }
 
-        pos += step;
         bRect = it.value()->boundingRect();
         switch( m_distribute )        {
             case DISTRIBUTE_HORIZONTAL_CENTER:
-                newPositions << QPointF( first->boundingRect().center().x() + pos - \
bRect.width()/2, position.y() ); +                newPositions << QPointF( \
boundingRect.x() + first->boundingRect().width()/2 + pos - bRect.width()/2, \
position.y() );  break;
             case DISTRIBUTE_HORIZONTAL_GAP:
-                newPositions << QPointF( first->boundingRect().right() + pos, \
position.y() ); +                newPositions << QPointF( boundingRect.left() + pos, \
position.y() );  pos += bRect.width();
                 break;
             case DISTRIBUTE_HORIZONTAL_LEFT:
-                newPositions << QPointF( first->boundingRect().left() + pos, \
position.y() ); +                newPositions << QPointF( boundingRect.left() + pos, \
position.y() );  break;
             case DISTRIBUTE_HORIZONTAL_RIGHT:
-                newPositions << QPointF( first->boundingRect().right() + pos, \
position.y() ); +                newPositions << QPointF( boundingRect.left() + \
first->boundingRect().width() + pos - bRect.width(), position.y() );  break;
             case DISTRIBUTE_VERTICAL_CENTER:
-                newPositions << QPointF( position.x(), \
first->boundingRect().center().y() + pos - bRect.height()/2 ); +                \
newPositions << QPointF( position.x(), boundingRect.y() + \
first->boundingRect().height()/2 + pos - bRect.height()/2 );  break;
             case DISTRIBUTE_VERTICAL_GAP:
-                newPositions << QPointF( position.x(), \
first->boundingRect().bottom() + pos ); +                newPositions << QPointF( \
position.x(), boundingRect.top() + pos ); +                pos += bRect.height();
                 break;
             case DISTRIBUTE_VERTICAL_BOTTOM:
-                newPositions << QPointF( position.x(), \
first->boundingRect().bottom() + pos ); +                newPositions << QPointF( \
position.x(), boundingRect.top() + first->boundingRect().height() + pos - \
bRect.height() );  break;
             case DISTRIBUTE_VERTICAL_TOP:
-                newPositions << QPointF( position.x(), first->boundingRect().top() + \
pos ); +                newPositions << QPointF( position.x(), boundingRect.top() + \
pos );  break;
         };
+        pos += step;
     }
     KoSelectionSet changedShapes = KoSelectionSet::fromList(sortedPos.values());
     m_command = new KoShapeMoveCommand(changedShapes, previousPositions, \
newPositions); @@ -483,34 +480,32 @@
     return i18n( "Distribute shapes" );
 }
 
-double KoShapeDistributeCommand::getAvailableSpace( KoShape *first, KoShape *last, \
double extent ) +double KoShapeDistributeCommand::getAvailableSpace( KoShape *first, \
KoShape *last, double extent, QRectF boundingRect  )  {
     switch( m_distribute ) {
         case DISTRIBUTE_HORIZONTAL_CENTER:
-            return last->boundingRect().center().x() - \
first->boundingRect().center().x(); +            return boundingRect.width() - \
last->boundingRect().width()/2 - first->boundingRect().width()/2;  break;
         case DISTRIBUTE_HORIZONTAL_GAP:
-            extent -= first->boundingRect().width() + last->boundingRect().width();
-            return last->boundingRect().left() - first->boundingRect().right() - \
extent; +            return boundingRect.width() - extent;
             break;
         case DISTRIBUTE_HORIZONTAL_LEFT:
-            return last->boundingRect().left() - first->boundingRect().left();
+            return boundingRect.width() - last->boundingRect().width();
             break;
         case DISTRIBUTE_HORIZONTAL_RIGHT:
-            return last->boundingRect().right() - first->boundingRect().right();
+            return boundingRect.width() - first->boundingRect().width();
             break;
         case DISTRIBUTE_VERTICAL_CENTER:
-            return last->boundingRect().center().y() - \
first->boundingRect().center().y(); +            return boundingRect.height() - \
last->boundingRect().height()/2 - first->boundingRect().height()/2;  break;
         case DISTRIBUTE_VERTICAL_GAP:
-            extent -= first->boundingRect().height() + \
                last->boundingRect().height();
-            return last->boundingRect().top() - first->boundingRect().bottom() - \
extent; +            return boundingRect.height() - extent;
             break;
         case DISTRIBUTE_VERTICAL_BOTTOM:
-            return last->boundingRect().bottom() - first->boundingRect().bottom();
+            return boundingRect.height() - first->boundingRect().height();
             break;
         case DISTRIBUTE_VERTICAL_TOP:
-            return last->boundingRect().top() - first->boundingRect().top();
+            return boundingRect.height() - last->boundingRect().height();
             break;
     }
     return 0.0;
--- trunk/koffice/libs/flake/KoCommand.h #567446:567447
@@ -299,8 +299,9 @@
      * Command to align a set of shapes in a rect
      * @param shapes a set of all the shapes that should be distributed
      * @param distribute the distribution type
+     * @param boundingRect the rect the shapes will be distributed in
      */
-    KoShapeDistributeCommand( const KoSelectionSet &shapes, Distribute distribute );
+    KoShapeDistributeCommand( const KoSelectionSet &shapes, Distribute distribute, \
QRectF boundingRect );  virtual ~KoShapeDistributeCommand();
     /// execute the command
     virtual void execute();
@@ -309,7 +310,7 @@
     /// return the name of this command
     virtual QString name () const;
 private:
-    double getAvailableSpace( KoShape *first, KoShape *last, double extent );
+    double getAvailableSpace( KoShape *first, KoShape *last, double extent, QRectF \
boundingRect );  Distribute m_distribute;
     KoShapeMoveCommand *m_command;
 };


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

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