vshapecmd.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
22#include "vcomposite.h"
23#include "vdocument.h"
24#include "vselection.h"
25#include "vshapecmd.h"
26
27
28VShapeCmd::VShapeCmd( VDocument* doc, const TQString& name, VPath* shape, const TQString& icon )
29 : VCommand( doc, name, icon ), m_shape( shape )
30{
31}
32
33void
34VShapeCmd::execute()
35{
36 if( !m_shape )
37 return;
38
39 if( m_shape->state() == VObject::deleted )
40 {
41 document()->selection()->clear();
42 m_shape->setState( VObject::normal );
43 document()->selection()->append( m_shape );
44 }
45 else
46 {
47 m_shape->setState( VObject::normal );
48 m_shape->setFill( *( document()->selection()->fill() ) );
49 m_shape->setStroke( *( document()->selection()->stroke() ) );
50
51 // Add path:
52 document()->append( m_shape );
53 document()->selection()->clear();
54 document()->selection()->append( m_shape );
55 }
56
57 setSuccess( true );
58}
59
60void
61VShapeCmd::unexecute()
62{
63 if( !m_shape )
64 return;
65
66 document()->selection()->take( *m_shape );
67 m_shape->setState( VObject::deleted );
68
69 setSuccess( false );
70}
71
The base class for all karbon commands.
Definition vcommand.h:42
All non-visual, static doc info is in here.
Definition vdocument.h:53
@ deleted
deleted, nearly dead
Definition vobject.h:58
@ normal
visible, not active
Definition vobject.h:54
A composite path consists of one or many subpaths.
Definition vcomposite.h:48