vfillcmd.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001, The Karbon Developers
3 Copyright (C) 2002, The Karbon Developers
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <tdelocale.h>
22
23#include "vfill.h"
24#include "vfillcmd.h"
25#include "vselection.h"
26#include "vdocument.h"
27#include "vcomposite.h"
28#include "vgroup.h"
29#include "vtext.h"
30
31VFillCmd::VFillCmd( VDocument *doc, const VFill &fill, const TQString &icon )
32 : VCommand( doc, i18n( "Fill Objects" ), icon ), m_fill( fill )
33{
34 m_selection = document()->selection()->clone();
35
36 if( m_selection->objects().count() == 1 )
37 setName( i18n( "Fill Object" ) );
38}
39
40VFillCmd::~VFillCmd()
41{
42 m_objects.clear();
43 delete m_selection;
44 m_selection = 0L;
45}
46
47void
48VFillCmd::changeFill( const VFill &fill )
49{
50 m_fill = fill;
51
52 if( !m_selection )
53 m_selection = document()->selection()->clone();
54
55 VObjectListIterator itr( m_selection->objects() );
56
57 for( ; itr.current() ; ++itr )
58 {
59 visit( *itr.current() );
60 }
61
62 setSuccess( true );
63}
64
65void
66VFillCmd::visitVGroup( VGroup& group )
67{
68 VObjectListIterator itr( group.objects() );
69
70 for( ; itr.current() ; ++itr )
71 {
72 m_oldfills.push_back( VFill( *( itr.current()->fill() ) ) );
73 itr.current()->setFill( m_fill );
74 m_objects.append(itr.current() );
75 }
76}
77
78void
79VFillCmd::visitVPath( VPath& composite )
80{
81 m_oldfills.push_back( VFill( *( composite.fill() ) ) );
82 composite.setFill( m_fill );
83 m_objects.append( &composite );
84}
85
86void
87VFillCmd::visitVText( VText& text )
88{
89 m_oldfills.push_back( VFill( *( text.fill() ) ) );
90 text.setFill( m_fill );
91 m_objects.append( &text );
92}
93
94void
95VFillCmd::execute()
96{
97 if( !m_selection )
98 m_selection = document()->selection()->clone();
99 VObjectListIterator itr( m_selection->objects() );
100
101 for( ; itr.current() ; ++itr )
102 {
103 visit( *itr.current() );
104 }
105
106 setSuccess( true );
107}
108
109void
110VFillCmd::unexecute()
111{
112 VObjectListIterator itr( m_objects );
113
114 int i = 0;
115
116 for( ; itr.current() ; ++itr )
117 {
118 itr.current()->setFill( m_oldfills[ i++ ] );
119 }
120
121 setSuccess( false );
122}
123
The base class for all karbon commands.
Definition vcommand.h:42
All non-visual, static doc info is in here.
Definition vdocument.h:53
Manages the fill of shapes.
Definition vfill.h:45
Base class for all sort of VObject conglomerats.
Definition vgroup.h:35
const VObjectList & objects() const
Read only access to the grouped objects.
Definition vgroup.h:110
virtual VFill * fill() const
Gets the object's actual fill.
Definition vobject.h:177
virtual void setFill(const VFill &fill)
Sets the fill to a given new fill.
Definition vobject.cpp:93
A composite path consists of one or many subpaths.
Definition vcomposite.h:48