F:/KPlato/koffice/libs/flake/KoPathCommand.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002  * Copyright (C) 2006 Jan Hambrecht <jaham@gmx.net>
00003  * Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "KoPathCommand.h"
00022 #include "KoParameterShape.h"
00023 #include "KoShapeControllerBase.h"
00024 #include <klocale.h>
00025 #include <kdebug.h>
00026 #include <math.h>
00027 
00028 KoPathBaseCommand::KoPathBaseCommand( KoPathShape *shape )
00029 : m_shape( shape )
00030 {
00031 }
00032 
00033 void KoPathBaseCommand::repaint( const QRectF &oldControlPointRect )
00034 {
00035     QRectF repaintRect( oldControlPointRect );
00036     repaintRect.adjust( -5.0, -5.0, 5.0, 5.0 );
00037     m_shape->repaint( oldControlPointRect );
00038 
00039     // the bounding rect has changed -> normalize
00040     m_shape->normalize();
00041 
00042     // adjust the old control rect as the repainting is relative to the new shape position
00043     repaintRect = m_shape->outline().controlPointRect();
00044     // TODO use the proper adjustment if the actual point size could be retrieved
00045     repaintRect.adjust( -5.0, -5.0, 5.0, 5.0 );
00046     m_shape->repaint( repaintRect );
00047 }
00048 
00049 KoPointMoveCommand::KoPointMoveCommand( const KoPathShapePointMap &pointMap, const QPointF &offset )
00050 : m_pointMap( pointMap )
00051 , m_offset( offset )
00052 {
00053 }
00054 
00055 void KoPointMoveCommand::execute()
00056 {
00057 
00058     KoPathShapePointMap::iterator it( m_pointMap.begin() );
00059     for ( ; it != m_pointMap.end(); ++it )
00060     {
00061         QPointF offset = it.key()->documentToShape( m_offset ) - it.key()->documentToShape( QPointF( 0, 0 ) );
00062         QMatrix matrix;
00063         matrix.translate( offset.x(), offset.y() );
00064 
00065         // repaint old bounding rect
00066         it.key()->repaint();
00067         foreach( KoPathPoint *p, it.value() )
00068         {
00069             p->map( matrix, true );
00070         }
00071         it.key()->normalize();
00072         // repaint new bounding rect
00073         it.key()->repaint();
00074     }
00075 }
00076 
00077 void KoPointMoveCommand::unexecute()
00078 {
00079     m_offset *= -1.0;
00080     execute();
00081     m_offset *= -1.0;
00082 }
00083 
00084 QString KoPointMoveCommand::name() const
00085 {
00086     return i18n( "Move points" );
00087 }
00088 
00089 KoControlPointMoveCommand::KoControlPointMoveCommand( KoPathPoint *point, const QPointF &offset, KoPathPoint::KoPointType pointType )
00090 : m_point( point )
00091 , m_offset( point->parent()->documentToShape( offset ) - point->parent()->documentToShape( QPointF( 0, 0 ) ) )
00092 , m_pointType( pointType )
00093 {
00094 }
00095 
00096 void KoControlPointMoveCommand::execute()
00097 {
00098     KoPathShape * pathShape = m_point->parent();
00099     pathShape->repaint();
00100 
00101     if ( m_pointType == KoPathPoint::ControlPoint1 )
00102     {
00103         m_point->setControlPoint1( m_point->controlPoint1() + m_offset );
00104         if( m_point->properties() & KoPathPoint::IsSymmetric )
00105         {
00106             // set the other control point so that it lies on the line between the moved
00107             // control point and the point, with the same distance to the point as the moved point
00108             m_point->setControlPoint2( 2.0 * m_point->point() - m_point->controlPoint1() );
00109         }
00110         else if( m_point->properties() & KoPathPoint::IsSmooth )
00111         {
00112             // move the other control point so that it lies on the line through point and control point
00113             // keeping its distance to the point
00114             QPointF direction = m_point->point() - m_point->controlPoint1();
00115             direction /= sqrt( direction.x()*direction.x() + direction.y()*direction.y() );
00116             QPointF distance = m_point->point() - m_point->controlPoint2();
00117             qreal length = sqrt( distance.x()*distance.x() + distance.y()*distance.y() );
00118             m_point->setControlPoint2( m_point->point() + length * direction );
00119         }
00120     }
00121     else if( m_pointType == KoPathPoint::ControlPoint2 )
00122     {
00123         m_point->setControlPoint2( m_point->controlPoint2() + m_offset );
00124         if( m_point->properties() & KoPathPoint::IsSymmetric )
00125         {
00126             // set the other control point so that it lies on the line between the moved
00127             // control point and the point, with the same distance to the point as the moved point
00128             m_point->setControlPoint1( 2.0 * m_point->point() - m_point->controlPoint2() );
00129         }
00130         else if( m_point->properties() & KoPathPoint::IsSmooth )
00131         {
00132             // move the other control point so that it lies on the line through point and control point
00133             // keeping its distance to the point
00134             QPointF direction = m_point->point() - m_point->controlPoint2();
00135             direction /= sqrt( direction.x()*direction.x() + direction.y()*direction.y() );
00136             QPointF distance = m_point->point() - m_point->controlPoint1();
00137             qreal length = sqrt( distance.x()*distance.x() + distance.y()*distance.y() );
00138             m_point->setControlPoint1( m_point->point() + length * direction );
00139         }
00140     }
00141 
00142     pathShape->normalize();
00143     pathShape->repaint();
00144 }
00145 
00146 void KoControlPointMoveCommand::unexecute()
00147 {
00148     m_offset *= -1.0;
00149     execute();
00150     m_offset *= -1.0;
00151 }
00152 
00153 QString KoControlPointMoveCommand::name() const
00154 {
00155     return i18n( "Move control point" );
00156 }
00157 
00158 KoPointPropertyCommand::KoPointPropertyCommand( KoPathShape *shape, KoPathPoint *point, KoPathPoint::KoPointProperties property )
00159 : KoPathBaseCommand( shape )
00160 , m_point( point )
00161 , m_newProperties( property )
00162 {
00163     m_oldProperties = point->properties();
00164     m_controlPoint1 = point->controlPoint1();
00165     m_controlPoint2 = point->controlPoint2();
00166 }
00167 
00168 void KoPointPropertyCommand::execute()
00169 {
00170     QRectF oldControlRect = m_shape->outline().controlPointRect();
00171 
00172     if( m_newProperties & KoPathPoint::IsSymmetric )
00173     {
00174         m_newProperties &= ~KoPathPoint::IsSmooth;
00175         m_point->setProperties( m_newProperties );
00176 
00177         // First calculate the direction vector of both control points starting from the point and their
00178         // distance to the point. Then calculate the average distance and move points so that
00179         // they have the same (average) distance from the point but keeping their direction.
00180         QPointF directionC1 = m_point->controlPoint1() - m_point->point();
00181         qreal dirLengthC1 = sqrt( directionC1.x()*directionC1.x() + directionC1.y()*directionC1.y() );
00182         QPointF directionC2 = m_point->controlPoint2() - m_point->point();
00183         qreal dirLengthC2 = sqrt( directionC2.x()*directionC2.x() + directionC2.y()*directionC2.y() );
00184         qreal averageLength = 0.5 * (dirLengthC1 + dirLengthC2);
00185         m_point->setControlPoint1( m_point->point() + averageLength / dirLengthC1 * directionC1 );
00186         m_point->setControlPoint2( m_point->point() + averageLength / dirLengthC2 * directionC2 );
00187         repaint( oldControlRect );
00188     }
00189     else if( m_newProperties & KoPathPoint::IsSmooth )
00190     {
00191         m_newProperties &= ~KoPathPoint::IsSymmetric;
00192         m_point->setProperties( m_newProperties );
00193 
00194         // First calculate the direction vector of both control points starting from the point and their
00195         // distance to the point. Then calculate the normalized direction vector. Then for each control
00196         // point calculate the bisecting line between its nromalized direction vector and the negated
00197         // normalied direction vector of the other points. Then use the result as the new direction
00198         // vector for the control point and their old distance to the point.
00199         QPointF directionC1 = m_point->controlPoint1() - m_point->point();
00200         qreal dirLengthC1 = sqrt( directionC1.x()*directionC1.x() + directionC1.y()*directionC1.y() );
00201         directionC1 /= dirLengthC1;
00202         QPointF directionC2 = m_point->controlPoint2() - m_point->point();
00203         qreal dirLengthC2 = sqrt( directionC2.x()*directionC2.x() + directionC2.y()*directionC2.y() );
00204         directionC2 /= dirLengthC2;
00205         m_point->setControlPoint1( m_point->point() + 0.5 * dirLengthC1 * (directionC1 - directionC2) );
00206         m_point->setControlPoint2( m_point->point() + 0.5 * dirLengthC2 * (directionC2 - directionC1) );
00207         repaint( oldControlRect );
00208     }
00209     else
00210     {
00211         m_newProperties &= ~KoPathPoint::IsSymmetric;
00212         m_newProperties &= ~KoPathPoint::IsSmooth;
00213         m_point->setProperties( m_newProperties );
00214     }
00215 }
00216 
00217 void KoPointPropertyCommand::unexecute()
00218 {
00219     QRectF oldControlRect = m_shape->outline().controlPointRect();
00220 
00221     m_point->setProperties( m_oldProperties );
00222     m_point->setControlPoint1( m_controlPoint1 );
00223     m_point->setControlPoint2( m_controlPoint2 );
00224 
00225     repaint( oldControlRect );
00226 }
00227 
00228 QString KoPointPropertyCommand::name() const
00229 {
00230     return i18n( "Set point properties" );
00231 }
00232 
00233 KoPointRemoveCommand::KoPointRemoveCommand( const KoPathShapePointMap &pointMap )
00234 : m_pointMap( pointMap )
00235 {
00236 }
00237 
00238 void KoPointRemoveCommand::execute()
00239 {
00240     KoPathShapePointMap::iterator it( m_pointMap.begin() );
00241     m_data.clear();
00242     for ( ; it != m_pointMap.end(); ++it )
00243     {
00244         it.key()->repaint();
00245 
00246         foreach( KoPathPoint *p, it.value() )
00247         {
00248             QPair<KoSubpath*, int> pointdata = it.key()->removePoint( p );
00249             m_data.push_back( KoPointRemoveData( p, pointdata.first, pointdata.second ) );
00250         }
00251 
00252         QPointF offset = it.key()->normalize();
00253 
00254         QMatrix matrix;
00255         matrix.translate( -offset.x(), -offset.y() );
00256         foreach( KoPathPoint *p, it.value() )
00257         {
00258             p->map( matrix );
00259         }
00260         // repaint new bounding rect
00261         // TODO is this really needed
00262         it.key()->repaint();
00263     }
00264 }
00265 
00266 void KoPointRemoveCommand::unexecute()
00267 {
00268     // insert the points in inverse order
00269     KoPathShape * pathShape = 0;
00270     for( int i = m_data.size()-1; i >= 0; --i )
00271     {
00272         KoPointRemoveData &data = m_data[i];
00273         if ( pathShape && pathShape != data.m_point->parent() )
00274         {
00275             pathShape->normalize();
00276             pathShape->repaint();
00277         }
00278         pathShape = data.m_point->parent();
00279         pathShape->insertPoint( data.m_point, data.m_subpath, data.m_position );
00280     }
00281     if ( pathShape )
00282     {
00283         pathShape->normalize();
00284         pathShape->repaint();
00285     }
00286 }
00287 
00288 QString KoPointRemoveCommand::name() const
00289 {
00290     return i18n( "Remove point" );
00291 }
00292 
00293 KoSegmentSplitCommand::KoSegmentSplitCommand( KoPathShape *shape, const KoPathSegment &segment, double splitPosition )
00294 : KoPathBaseCommand( shape )
00295 , m_deletePoint( false )
00296 {
00297     if( segment.first && segment.second )
00298     {
00299         m_segments << segment;
00300         m_oldNeighbors << qMakePair( *segment.first, *segment.second );
00301         m_newNeighbors << qMakePair( *segment.first, *segment.second );
00302         m_splitPoints << 0;
00303         m_splitPointPos << qMakePair( (KoSubpath*)0, 0 );
00304         m_splitPos << splitPosition;
00305     }
00306 }
00307 
00308 KoSegmentSplitCommand::KoSegmentSplitCommand( KoPathShape *shape, const QList<KoPathSegment> &segments, const QList<double> &splitPositions )
00309 : KoPathBaseCommand( shape )
00310 , m_deletePoint( false )
00311 {
00312     Q_ASSERT(segments.size() == splitPositions.size());
00313     // check all the segments
00314     for( int i = 0; i < segments.size(); ++i )
00315     {
00316         const KoPathSegment &segment = segments[i];
00317         if( segment.first && segment.second )
00318         {
00319             m_segments << segment;
00320             m_oldNeighbors << qMakePair( *segment.first, *segment.second );
00321             m_newNeighbors << qMakePair( *segment.first, *segment.second );
00322             m_splitPoints << 0;
00323             m_splitPointPos << qMakePair( (KoSubpath*)0, 0 );
00324             m_splitPos << splitPositions[i];
00325         }
00326     }
00327 }
00328 
00329 KoSegmentSplitCommand::KoSegmentSplitCommand( KoPathShape *shape, const QList<KoPathSegment> &segments, double splitPosition )
00330 : KoPathBaseCommand( shape )
00331 , m_deletePoint( false )
00332 {
00333     // check all the segments
00334     for( int i = 0; i < segments.size(); ++i )
00335     {
00336         const KoPathSegment &segment = segments[i];
00337         if( segment.first && segment.second )
00338         {
00339             m_segments << segment;
00340             m_oldNeighbors << qMakePair( *segment.first, *segment.second );
00341             m_newNeighbors << qMakePair( *segment.first, *segment.second );
00342             m_splitPoints << 0;
00343             m_splitPointPos << qMakePair( (KoSubpath*)0, 0 );
00344             m_splitPos << splitPosition;
00345         }
00346     }
00347 }
00348 
00349 KoSegmentSplitCommand::~KoSegmentSplitCommand()
00350 {
00351     if( m_deletePoint )
00352     {
00353         foreach( KoPathPoint* p, m_splitPoints )
00354             delete p;
00355     }
00356 }
00357 
00358 void KoSegmentSplitCommand::execute()
00359 {
00360     QRectF oldControlRect = m_shape->outline().controlPointRect();
00361 
00362     m_deletePoint = false;
00363 
00364     for( int i = 0; i < m_segments.size(); ++i )
00365     {
00366         KoPathSegment &segment = m_segments[i];
00367         KoPathPoint *splitPoint = m_splitPoints[i];
00368         if( ! splitPoint )
00369         {
00370             m_splitPoints[i] = m_shape->splitAt( segment, m_splitPos[i] );
00371             m_newNeighbors[i] = qMakePair( *segment.first, *segment.second );
00372         }
00373         else
00374         {
00375             m_shape->insertPoint( splitPoint, m_splitPointPos[i].first, m_splitPointPos[i].second );
00376             *segment.first = m_newNeighbors[i].first;
00377             *segment.second = m_newNeighbors[i].second;
00378         }
00379     }
00380     repaint( oldControlRect );
00381 }
00382 
00383 void KoSegmentSplitCommand::unexecute()
00384 {
00385     QRectF oldControlRect = m_shape->outline().controlPointRect();
00386 
00387     m_deletePoint = true;
00388 
00389     for( int i = m_segments.size()-1; i >= 0; --i )
00390     {
00391         KoPathSegment &segment = m_segments[i];
00392         m_splitPointPos[i] = m_shape->removePoint( m_splitPoints[i] );
00393         *segment.first = m_oldNeighbors[i].first;
00394         *segment.second = m_oldNeighbors[i].second;
00395     }
00396     repaint( oldControlRect );
00397 }
00398 
00399 QString KoSegmentSplitCommand::name() const
00400 {
00401     return i18n( "Split segment" );
00402 }
00403 
00404 KoPointJoinCommand::KoPointJoinCommand( KoPathShape *shape, KoPathPoint *point1, KoPathPoint *point2 )
00405 : KoPathBaseCommand( shape )
00406 , m_point1( point1 )
00407 , m_point2( point2 )
00408 , m_joined( false )
00409 {
00410 }
00411 
00412 void KoPointJoinCommand::execute()
00413 {
00414     m_joined = m_shape->joinBetween( m_point1, m_point2 );
00415     m_shape->repaint();
00416 }
00417 
00418 void KoPointJoinCommand::unexecute()
00419 {
00420     if( m_joined )
00421     {
00422         m_shape->breakAt( KoPathSegment( m_point1, m_point2 ) );
00423         m_shape->repaint();
00424     }
00425 }
00426 
00427 QString KoPointJoinCommand::name() const
00428 {
00429     return i18n( "Join points" );
00430 }
00431 
00432 KoSubpathBreakCommand::KoSubpathBreakCommand( KoPathShape *shape, KoPathPoint *breakPoint )
00433 : KoPathBaseCommand( shape )
00434 , m_breakPoint( breakPoint )
00435 , m_segment( 0, 0 )
00436 , m_breakSegment( false )
00437 , m_broken( false )
00438 , m_newPoint( 0 )
00439 , m_pointData1( 0, QPointF(0,0) )
00440 , m_pointData2( 0, QPointF(0,0) )
00441 {
00442     if( breakPoint )
00443         m_pointData1 = *breakPoint;
00444     KoPathPoint *nextPoint = m_shape->nextPoint( m_breakPoint );
00445     if( nextPoint )
00446         m_pointData2 = *nextPoint;
00447 }
00448 
00449 KoSubpathBreakCommand::KoSubpathBreakCommand( KoPathShape *shape, const KoPathSegment &segment )
00450 : KoPathBaseCommand( shape )
00451 , m_breakPoint( 0 )
00452 , m_segment( segment )
00453 , m_breakSegment( true )
00454 , m_broken( false )
00455 , m_newPoint( 0 )
00456 , m_pointData1( 0, QPointF(0,0) )
00457 , m_pointData2( 0, QPointF(0,0) )
00458 {
00459     if( m_segment.first )
00460         m_pointData1 = *m_segment.first;
00461     if( m_segment.second )
00462         m_pointData2 = *m_segment.second;
00463 }
00464 
00465 KoSubpathBreakCommand::~KoSubpathBreakCommand()
00466 {
00467 }
00468 
00469 void KoSubpathBreakCommand::execute()
00470 {
00471     if( m_breakSegment )
00472     {
00473         if( m_segment.first && m_segment.second )
00474         {
00475             m_broken = m_shape->breakAt( m_segment );
00476             m_shape->repaint();
00477         }
00478     }
00479     else
00480     {
00481         if( m_breakPoint )
00482         {
00483             m_broken = m_shape->breakAt( m_breakPoint, m_newPoint );
00484             m_shape->repaint();
00485         }
00486     }
00487 }
00488 
00489 void KoSubpathBreakCommand::unexecute()
00490 {
00491     if( ! m_broken )
00492         return;
00493 
00494     if( m_breakSegment )
00495     {
00496         m_shape->joinBetween( m_segment.first, m_segment.second );
00497         *m_segment.first = m_pointData1;
00498         *m_segment.second = m_pointData2;
00499     }
00500     else
00501     {
00502         KoPathPoint *nextPoint = m_shape->nextPoint( m_newPoint );
00503         m_shape->removePoint( m_newPoint );
00504         delete m_newPoint;
00505         m_newPoint = 0;
00506         if( m_shape->joinBetween( m_breakPoint, nextPoint ) )
00507         {
00508             *m_breakPoint = m_pointData1;
00509             *nextPoint = m_pointData2;
00510         }
00511     }
00512     m_shape->repaint();
00513 }
00514 
00515 QString KoSubpathBreakCommand::name() const
00516 {
00517     return i18n( "Break subpath" );
00518 }
00519 
00520 KoSegmentTypeCommand::KoSegmentTypeCommand( KoPathShape *shape, const KoPathSegment &segment, bool changeToLine )
00521 : KoPathBaseCommand( shape )
00522 , m_changeToLine( changeToLine )
00523 {
00524     if( segment.first && segment.second )
00525         m_segments.append( segment );
00526 }
00527 
00528 KoSegmentTypeCommand::KoSegmentTypeCommand( KoPathShape *shape, const QList<KoPathSegment> &segments, bool changeToLine )
00529 : KoPathBaseCommand( shape )
00530 , m_changeToLine( changeToLine )
00531 {
00532     foreach( KoPathSegment segment, segments )
00533     {
00534         if( segment.first && segment.second )
00535             m_segments.append( segment );
00536     }
00537 }
00538 
00539 void KoSegmentTypeCommand::execute()
00540 {
00541     QRectF oldControlRect = m_shape->outline().controlPointRect();
00542 
00543     m_oldPointData.clear();
00544     foreach( KoPathSegment s, m_segments )
00545     {
00546         m_oldPointData.insert( s.first, *s.first );
00547         m_oldPointData.insert( s.second, *s.second );
00548     }
00549 
00550     foreach( KoPathSegment s, m_segments )
00551     {
00552         if( m_changeToLine )
00553         {
00554             s.first->unsetProperty( KoPathPoint::HasControlPoint2 );
00555             s.second->unsetProperty( KoPathPoint::HasControlPoint1 );
00556         }
00557         else
00558         {
00559             // check if segment is already a curve
00560             if( s.first->properties() & KoPathPoint::HasControlPoint2 || s.second->properties() & KoPathPoint::HasControlPoint1 )
00561                 continue;
00562 
00563             QPointF pointDiff = s.second->point() - s.first->point();
00564             s.first->setControlPoint2( s.first->point() + 0.3 * pointDiff );
00565             s.second->setControlPoint1( s.first->point() + 0.7 * pointDiff );
00566         }
00567     }
00568 
00569     QPointF offset = m_shape->normalize();
00570     QMatrix matrix;
00571     matrix.translate( -offset.x(), -offset.y() );
00572     QMap<KoPathPoint*, KoPathPoint>::iterator it = m_oldPointData.begin();
00573     for(; it != m_oldPointData.end(); ++it )
00574         it.value().map( matrix );
00575 
00576     repaint( oldControlRect.translated( -offset ) );
00577 }
00578 
00579 void KoSegmentTypeCommand::unexecute()
00580 {
00581     QRectF oldControlRect = m_shape->outline().controlPointRect();
00582 
00583     KoPathPoint defaultPoint( 0, QPointF(0,0) );
00584     foreach( KoPathSegment s, m_segments )
00585     {
00586         *s.first = m_oldPointData.value( s.first, defaultPoint );
00587         *s.second = m_oldPointData.value( s.second, defaultPoint );
00588     }
00589 
00590     repaint( oldControlRect );
00591 }
00592 
00593 QString KoSegmentTypeCommand::name() const
00594 {
00595     return i18n( "Change segment type" );
00596 }
00597 
00598 KoPathCombineCommand::KoPathCombineCommand( KoShapeControllerBase *controller, const QList<KoPathShape*> &paths )
00599 : m_controller( controller )
00600 , m_paths( paths )
00601 , m_combinedPath( 0 )
00602 , m_isCombined( false )
00603 {
00604 }
00605 
00606 KoPathCombineCommand::~KoPathCombineCommand()
00607 {
00608     if( m_isCombined && m_controller )
00609     {
00610         foreach( KoPathShape* path, m_paths )
00611             delete path;
00612     }
00613     else
00614         delete m_combinedPath;
00615 }
00616 
00617 void KoPathCombineCommand::execute()
00618 {
00619     if( ! m_paths.size() )
00620         return;
00621 
00622     if( ! m_combinedPath )
00623     {
00624         m_combinedPath = new KoPathShape();
00625         m_combinedPath->setBorder( m_paths.first()->border() );
00626         m_combinedPath->setShapeId( m_paths.first()->shapeId() );
00627         // combine the paths
00628         foreach( KoPathShape* path, m_paths )
00629             m_combinedPath->combine( path );
00630     }
00631 
00632     m_isCombined = true;
00633 
00634     if( m_controller )
00635     {
00636         foreach( KoPathShape* p, m_paths )
00637             m_controller->removeShape( p );
00638 
00639         m_controller->addShape( m_combinedPath );
00640     }
00641 }
00642 
00643 void KoPathCombineCommand::unexecute()
00644 {
00645     if( ! m_paths.size() )
00646         return;
00647 
00648     m_isCombined = false;
00649 
00650     if( m_controller )
00651     {
00652         m_controller->removeShape( m_combinedPath );
00653         foreach( KoPathShape* p, m_paths )
00654             m_controller->addShape( p );
00655     }
00656 }
00657 
00658 QString KoPathCombineCommand::name() const
00659 {
00660     return i18n( "Combine paths" );
00661 }
00662 
00663 KoParameterChangeCommand::KoParameterChangeCommand( KoParameterShape *shape, int handleId, const QPointF &startPoint, const QPointF &endPoint )
00664 : m_shape( shape )
00665 , m_handleId( handleId )    
00666 , m_startPoint( startPoint )    
00667 , m_endPoint( endPoint )    
00668 {
00669 }
00670 
00671 KoParameterChangeCommand::~KoParameterChangeCommand()
00672 {
00673 }
00674 
00676 void KoParameterChangeCommand::execute()
00677 {
00678     m_shape->repaint();
00679     m_shape->moveHandle( m_handleId, m_endPoint );
00680     m_shape->repaint();
00681 }
00682 
00684 void KoParameterChangeCommand::unexecute()
00685 {
00686     m_shape->repaint();
00687     m_shape->moveHandle( m_handleId, m_startPoint );
00688     m_shape->repaint();
00689 }
00690 
00692 QString KoParameterChangeCommand::name() const
00693 {
00694     return i18n( "Change parameter" );
00695 }
00696 
00697 KoParameterToPathCommand::KoParameterToPathCommand( KoParameterShape *shape )
00698 : m_shape( shape )    
00699 {
00700 }
00701 
00702 KoParameterToPathCommand::~KoParameterToPathCommand()
00703 {
00704 }
00705 
00706 void KoParameterToPathCommand::execute()
00707 {
00708     m_shape->setModified( true );
00709 }
00710 
00711 void KoParameterToPathCommand::unexecute()
00712 {
00713     m_shape->setModified( false );
00714 }
00715 
00716 QString KoParameterToPathCommand::name() const
00717 {
00718     return i18n( "Modify path" );
00719 }
00720 
00721 KoPathSeparateCommand::KoPathSeparateCommand( KoShapeControllerBase *controller, const QList<KoPathShape*> &paths )
00722 : m_controller( controller )
00723 , m_paths( paths )
00724 , m_isSeparated( false )
00725 {
00726 }
00727 
00728 KoPathSeparateCommand::~KoPathSeparateCommand()
00729 {
00730     if( m_isSeparated && m_controller )
00731     {
00732         foreach( KoPathShape* p, m_paths )
00733             delete p;
00734     }
00735     else
00736     {
00737         foreach( KoPathShape* p, m_separatedPaths )
00738             delete p;
00739     }
00740 }
00741 
00742 void KoPathSeparateCommand::execute()
00743 {
00744     if( ! m_separatedPaths.size() )
00745     {
00746         foreach( KoPathShape* p, m_paths )
00747         {
00748             QList<KoPathShape*> separatedPaths;
00749             if( p->separate( separatedPaths ) )
00750                 m_separatedPaths << separatedPaths;
00751         }
00752     }
00753 
00754     m_isSeparated = true;
00755 
00756     if( m_controller )
00757     {
00758         foreach( KoPathShape* p, m_paths )
00759             m_controller->removeShape( p );
00760         foreach( KoPathShape *p, m_separatedPaths )
00761             m_controller->addShape( p );
00762     }
00763     foreach( KoPathShape* p, m_paths )
00764         p->repaint();
00765 }
00766 
00767 void KoPathSeparateCommand::unexecute()
00768 {
00769     if( m_controller )
00770     {
00771         foreach( KoPathShape *p, m_separatedPaths )
00772             m_controller->removeShape( p );
00773         foreach( KoPathShape* p, m_paths )
00774             m_controller->addShape( p );
00775     }
00776 
00777     m_isSeparated = false;
00778 
00779     foreach( KoPathShape* p, m_paths )
00780         p->repaint();
00781 }
00782 
00783 QString KoPathSeparateCommand::name() const
00784 {
00785     return i18n( "Separate paths" );
00786 }

Généré le Wed Nov 22 23:40:59 2006 pour KPlato par  doxygen 1.5.1-p1