~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to karbon/commands/vzordercmd.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2002, 2003 The Karbon Developers
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
18
*/
 
19
 
 
20
#include <klocale.h>
 
21
 
 
22
#include "vzordercmd.h"
 
23
#include "vselection.h"
 
24
#include "vdocument.h"
 
25
#include "vlayer.h"
 
26
 
 
27
VZOrderCmd::VZOrderCmd( VDocument *doc, VOrder state )
 
28
        : VCommand( doc, i18n( "Order Selection" ) ), m_state( state )
 
29
{
 
30
        m_selection = document()->selection()->clone();
 
31
}
 
32
 
 
33
VZOrderCmd::VZOrderCmd( VDocument *doc, VObject *obj, VOrder state )
 
34
        : VCommand( doc, i18n( "Order Selection" ) ), m_state( state )
 
35
{
 
36
        m_selection = new VSelection();
 
37
        m_selection->append( obj );
 
38
}
 
39
 
 
40
VZOrderCmd::~VZOrderCmd()
 
41
{
 
42
        delete( m_selection );
 
43
}
 
44
 
 
45
void
 
46
VZOrderCmd::execute()
 
47
{
 
48
        if( m_state == sendToBack )
 
49
        {
 
50
                VObjectListIterator itr( document()->selection()->objects() );
 
51
                for ( itr.toLast() ; itr.current() ; --itr )
 
52
                {
 
53
                        // remove from old layer
 
54
                        VObjectList objects;
 
55
                        VLayerListIterator litr( document()->layers() );
 
56
 
 
57
                        for ( ; litr.current(); ++litr )
 
58
                        {
 
59
                                objects = litr.current()->objects();
 
60
                                VObjectListIterator itr2( objects );
 
61
                                for ( ; itr2.current(); ++itr2 )
 
62
                                        if( itr2.current() == itr.current() )
 
63
                                        {
 
64
                                                litr.current()->sendToBack( *itr2.current() );
 
65
                                                itr2.current()->setState( VObject::selected );
 
66
                                        }
 
67
                        }
 
68
                }
 
69
        }
 
70
        else if( m_state == bringToFront )
 
71
        {
 
72
                VObjectListIterator itr( document()->selection()->objects() );
 
73
                for ( ; itr.current() ; ++itr )
 
74
                {
 
75
                        // remove from old layer
 
76
                        VObjectList objects;
 
77
                        VLayerListIterator litr( document()->layers() );
 
78
 
 
79
                        for ( ; litr.current(); ++litr )
 
80
                        {
 
81
                                objects = litr.current()->objects();
 
82
                                VObjectListIterator itr2( objects );
 
83
                                for ( ; itr2.current(); ++itr2 )
 
84
                                        if( itr2.current() == itr.current() )
 
85
                                        {
 
86
                                                litr.current()->bringToFront( *itr2.current() );
 
87
                                                itr2.current()->setState( VObject::selected );
 
88
                                        }
 
89
                        }
 
90
                }
 
91
        }
 
92
        else if( m_state == up || m_state == down )
 
93
        {
 
94
                VSelection selection = *m_selection;
 
95
 
 
96
                VObjectList objects;
 
97
 
 
98
                // TODO : this doesn't work for objects inside groups!
 
99
                VLayerListIterator litr( document()->layers() );
 
100
                while( !selection.objects().isEmpty() && litr.current() )
 
101
                {
 
102
                        for ( ; litr.current(); ++litr )
 
103
                        {
 
104
                                if( litr.current()->state() == VObject::deleted )
 
105
                                        continue;
 
106
                                VObjectList todo;
 
107
                                VObjectListIterator itr( selection.objects() );
 
108
                                for ( ; itr.current() ; ++itr )
 
109
                                {
 
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 )
 
114
                                        {
 
115
                                                if( itr2.current() == itr.current() )
 
116
                                                {
 
117
                                                        todo.append( itr.current() );
 
118
                                                        // remove from selection
 
119
                                                        selection.take( *itr.current() );
 
120
                                                }
 
121
                                        }
 
122
                                }
 
123
                                kdDebug(38000) << "todo.count() : " << todo.count() << endl;
 
124
 
 
125
                                // we have found the affected vobjects in this vlayer
 
126
                                VObjectListIterator itr3( todo );
 
127
                                for ( ; itr3.current(); ++itr3 )
 
128
                                {
 
129
                                        if( m_state == up )
 
130
                                                litr.current()->upwards( *itr3.current() );
 
131
                                        else
 
132
                                                litr.current()->downwards( *itr3.current() );
 
133
                                        itr3.current()->setState( VObject::selected );
 
134
                                }
 
135
                        }
 
136
                }
 
137
        }
 
138
        setSuccess( true );
 
139
}
 
140
 
 
141
void
 
142
VZOrderCmd::unexecute()
 
143
{
 
144
        if( m_state == sendToBack )
 
145
        {
 
146
                m_state = bringToFront;
 
147
                execute();
 
148
                m_state = sendToBack;
 
149
        }
 
150
        else if( m_state == bringToFront )
 
151
        {
 
152
                m_state = sendToBack;
 
153
                execute();
 
154
                m_state = bringToFront;
 
155
        }
 
156
        else if( m_state == up )
 
157
        {
 
158
                m_state = down;
 
159
                execute();
 
160
                m_state = up;
 
161
        }
 
162
        else if( m_state == down )
 
163
        {
 
164
                m_state = up;
 
165
                execute();
 
166
                m_state = down;
 
167
        }
 
168
        setSuccess( false );
 
169
}
 
170