summaryrefslogtreecommitdiffstats
path: root/karbon/commands/vzordercmd.cc
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
commit8362bf63dea22bbf6736609b0f49c152f975eb63 (patch)
tree0eea3928e39e50fae91d4e68b21b1e6cbae25604 /karbon/commands/vzordercmd.cc
downloadkoffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz
koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'karbon/commands/vzordercmd.cc')
-rw-r--r--karbon/commands/vzordercmd.cc172
1 files changed, 172 insertions, 0 deletions
diff --git a/karbon/commands/vzordercmd.cc b/karbon/commands/vzordercmd.cc
new file mode 100644
index 00000000..2839120f
--- /dev/null
+++ b/karbon/commands/vzordercmd.cc
@@ -0,0 +1,172 @@
+/* This file is part of the KDE project
+ Copyright (C) 2002, 2003 The Karbon Developers
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+*/
+
+#include <klocale.h>
+
+#include "vzordercmd.h"
+#include "vselection.h"
+#include "vdocument.h"
+#include "vlayer.h"
+
+VZOrderCmd::VZOrderCmd( VDocument *doc, VOrder state )
+ : VCommand( doc, i18n( "Order Selection" ) ), m_state( state )
+{
+ m_selection = document()->selection()->clone();
+}
+
+VZOrderCmd::VZOrderCmd( VDocument *doc, VObject *obj, VOrder state )
+ : VCommand( doc, i18n( "Order Selection" ) ), m_state( state )
+{
+ m_selection = new VSelection();
+ m_selection->append( obj );
+}
+
+VZOrderCmd::~VZOrderCmd()
+{
+ delete( m_selection );
+}
+
+void
+VZOrderCmd::execute()
+{
+ if( m_state == sendToBack )
+ {
+ VObjectListIterator itr( document()->selection()->objects() );
+ for ( itr.toLast() ; itr.current() ; --itr )
+ {
+ // remove from old layer
+ VObjectList objects;
+ VLayerListIterator litr( document()->layers() );
+
+ for ( ; litr.current(); ++litr )
+ {
+ objects = litr.current()->objects();
+ VObjectListIterator itr2( objects );
+ for ( ; itr2.current(); ++itr2 )
+ if( itr2.current() == itr.current() )
+ {
+ litr.current()->sendToBack( *itr2.current() );
+ itr2.current()->setState( VObject::selected );
+ }
+ }
+ }
+ }
+ else if( m_state == bringToFront )
+ {
+ VObjectListIterator itr( document()->selection()->objects() );
+ for ( ; itr.current() ; ++itr )
+ {
+ // remove from old layer
+ VObjectList objects;
+ VLayerListIterator litr( document()->layers() );
+
+ for ( ; litr.current(); ++litr )
+ {
+ objects = litr.current()->objects();
+ VObjectListIterator itr2( objects );
+ for ( ; itr2.current(); ++itr2 )
+ if( itr2.current() == itr.current() )
+ {
+ litr.current()->bringToFront( *itr2.current() );
+ itr2.current()->setState( VObject::selected );
+ }
+ }
+ }
+ }
+ else if( m_state == up || m_state == down )
+ {
+ VSelection selection = *m_selection;
+ // TODO : this doesn't work for objects inside groups!
+ VLayerListIterator litr( document()->layers() );
+ while( !selection.objects().isEmpty() && litr.current() )
+ {
+ for ( ; litr.current(); ++litr )
+ {
+ if( litr.current()->state() == VObject::deleted )
+ continue;
+ VObjectList objects = litr.current()->objects();
+ VObjectList todo;
+ VObjectListIterator objectItr( objects );
+ // find all selected VObjects that are in the current layer
+ for ( ; objectItr.current(); ++objectItr )
+ {
+ VObjectListIterator selectionItr( selection.objects() );
+ for ( ; selectionItr.current() ; ++selectionItr )
+ {
+ if( objectItr.current() == selectionItr.current() )
+ {
+ if( m_state == up )
+ todo.prepend( objectItr.current() );
+ else
+ todo.append( objectItr.current() );
+ }
+ }
+ }
+
+ kdDebug(38000) << "todo.count() : " << todo.count() << endl;
+
+ // we have found the affected vobjects in this vlayer
+ VObjectListIterator todoItr( todo );
+ for ( ; todoItr.current(); ++todoItr )
+ {
+ if( m_state == up )
+ litr.current()->upwards( *todoItr.current() );
+ else
+ litr.current()->downwards( *todoItr.current() );
+ // remove from selection
+ selection.take( *todoItr.current() );
+ // make sure object stays selected
+ todoItr.current()->setState( VObject::selected );
+ }
+ }
+ }
+ }
+ setSuccess( true );
+}
+
+void
+VZOrderCmd::unexecute()
+{
+ if( m_state == sendToBack )
+ {
+ m_state = bringToFront;
+ execute();
+ m_state = sendToBack;
+ }
+ else if( m_state == bringToFront )
+ {
+ m_state = sendToBack;
+ execute();
+ m_state = bringToFront;
+ }
+ else if( m_state == up )
+ {
+ m_state = down;
+ execute();
+ m_state = up;
+ }
+ else if( m_state == down )
+ {
+ m_state = up;
+ execute();
+ m_state = down;
+ }
+ setSuccess( false );
+}
+