24#include "vtransformcmd.h"
26#include "vselection.h"
30VAlignCmd::VAlignCmd(
VDocument *doc, Align align )
31 :
VCommand( doc, i18n(
"Align Objects" ) ), m_align( align )
33 m_trafoCmds.setAutoDelete(
true );
36VAlignCmd::~VAlignCmd()
43 if( document()->selection()->objects().count() == 0 )
48 if( document()->selection()->objects().count() == 1 )
49 r = document()->boundingBox();
51 r = document()->selection()->boundingBox();
52 VObjectList objs = document()->selection()->objects();
53 VObjectListIterator itr( objs );
54 VTranslateCmd *trafoCmd = 0L;
55 for( ; itr.current() ; ++itr )
57 document()->selection()->clear();
58 bbox = itr.current()->boundingBox();
61 case ALIGN_HORIZONTAL_LEFT : dx = r.topLeft().x() - bbox.topLeft().x(); dy = 0;
break;
62 case ALIGN_HORIZONTAL_CENTER: dx = r.center().x() - bbox.center().x(); dy = 0;
break;
63 case ALIGN_HORIZONTAL_RIGHT : dx = r.topRight().x() - bbox.topRight().x(); dy = 0;
break;
64 case ALIGN_VERTICAL_TOP : dx = 0; dy = r.bottomRight().y() - bbox.bottomRight().y();
break;
65 case ALIGN_VERTICAL_CENTER : dx = 0; dy = r.center().y() - bbox.center().y();
break;
66 case ALIGN_VERTICAL_BOTTOM : dx = 0; dy = r.topLeft().y() - bbox.topLeft().y();
break;
68 document()->selection()->append( itr.current() );
69 trafoCmd =
new VTranslateCmd( document(), dx, dy );
70 m_trafoCmds.append( trafoCmd );
74 for( ; itr.current() ; ++itr )
75 document()->selection()->append( itr.current() );
82 TQPtrListIterator<VTranslateCmd> itr( m_trafoCmds );
83 for( ; itr.current() ; ++itr )
84 itr.current()->unexecute();
The base class for all karbon commands.
All non-visual, static doc info is in here.