1
/* This file is part of the KDE project
2
Copyright (C) 2002, 2003 The Karbon Developers
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
Boston, MA 02111-1307, USA.
22
#include "vzordercmd.h"
23
#include "vselection.h"
24
#include "vdocument.h"
27
VZOrderCmd::VZOrderCmd( VDocument *doc, VOrder state )
28
: VCommand( doc, i18n( "Order Selection" ) ), m_state( state )
30
m_selection = document()->selection()->clone();
33
VZOrderCmd::VZOrderCmd( VDocument *doc, VObject *obj, VOrder state )
34
: VCommand( doc, i18n( "Order Selection" ) ), m_state( state )
36
m_selection = new VSelection();
37
m_selection->append( obj );
40
VZOrderCmd::~VZOrderCmd()
42
delete( m_selection );
48
if( m_state == sendToBack )
50
VObjectListIterator itr( document()->selection()->objects() );
51
for ( itr.toLast() ; itr.current() ; --itr )
53
// remove from old layer
55
VLayerListIterator litr( document()->layers() );
57
for ( ; litr.current(); ++litr )
59
objects = litr.current()->objects();
60
VObjectListIterator itr2( objects );
61
for ( ; itr2.current(); ++itr2 )
62
if( itr2.current() == itr.current() )
64
litr.current()->sendToBack( *itr2.current() );
65
itr2.current()->setState( VObject::selected );
70
else if( m_state == bringToFront )
72
VObjectListIterator itr( document()->selection()->objects() );
73
for ( ; itr.current() ; ++itr )
75
// remove from old layer
77
VLayerListIterator litr( document()->layers() );
79
for ( ; litr.current(); ++litr )
81
objects = litr.current()->objects();
82
VObjectListIterator itr2( objects );
83
for ( ; itr2.current(); ++itr2 )
84
if( itr2.current() == itr.current() )
86
litr.current()->bringToFront( *itr2.current() );
87
itr2.current()->setState( VObject::selected );
92
else if( m_state == up || m_state == down )
94
VSelection selection = *m_selection;
98
// TODO : this doesn't work for objects inside groups!
99
VLayerListIterator litr( document()->layers() );
100
while( !selection.objects().isEmpty() && litr.current() )
102
for ( ; litr.current(); ++litr )
104
if( litr.current()->state() == VObject::deleted )
107
VObjectListIterator itr( selection.objects() );
108
for ( ; itr.current() ; ++itr )
110
objects = litr.current()->objects();
111
VObjectListIterator itr2( objects );
112
// find all selected VObjects that are in the current layer
113
for ( ; itr2.current(); ++itr2 )
115
if( itr2.current() == itr.current() )
117
todo.append( itr.current() );
118
// remove from selection
119
selection.take( *itr.current() );
123
kdDebug(38000) << "todo.count() : " << todo.count() << endl;
125
// we have found the affected vobjects in this vlayer
126
VObjectListIterator itr3( todo );
127
for ( ; itr3.current(); ++itr3 )
130
litr.current()->upwards( *itr3.current() );
132
litr.current()->downwards( *itr3.current() );
133
itr3.current()->setState( VObject::selected );
142
VZOrderCmd::unexecute()
144
if( m_state == sendToBack )
146
m_state = bringToFront;
148
m_state = sendToBack;
150
else if( m_state == bringToFront )
152
m_state = sendToBack;
154
m_state = bringToFront;
156
else if( m_state == up )
162
else if( m_state == down )