karbon

vlayercmd.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 "vlayer.h"
22#include "vlayercmd.h"
23#include "vdocument.h"
24
25VLayerCmd::VLayerCmd( VDocument* doc, const TQString& name, VLayer* layer, VLayerCmdType order )
26 : VCommand( doc, name, "14_layers" ), m_layer( layer ), m_cmdType( order )
27{
28 if( order == addLayer )
29 {
30 layer->setState( VObject::deleted );
31 document()->insertLayer( layer );
32 }
33
34 m_oldState = layer->state();
35}
36
37void
39{
40 switch( m_cmdType )
41 {
42 case addLayer:
43 m_layer->setState( VObject::normal );
44 break;
45
46 case deleteLayer:
47 m_layer->setState( VObject::deleted );
48 break;
49
50 case raiseLayer:
51 document()->raiseLayer( m_layer );
52 break;
53
54 case lowerLayer:
55 document()->lowerLayer( m_layer );
56 break;
57 }
58
59 setSuccess( true );
60}
61
62void
64{
65 switch ( m_cmdType )
66 {
67 case addLayer:
68 m_layer->setState( VObject::deleted );
69 break;
70
71 case deleteLayer:
72 m_layer->setState( m_oldState );
73 break;
74
75 case raiseLayer:
76 document()->lowerLayer( m_layer );
77 break;
78
79 case lowerLayer:
80 document()->raiseLayer( m_layer );
81 break;
82 }
83
84 setSuccess( false );
85}
86
The base class for all karbon commands.
Definition vcommand.h:42
virtual void unexecute()
Unexecutes the command.
Definition vcommand.h:75
VDocument * document() const
Returns the document the command works on.
Definition vcommand.h:121
virtual void execute()=0
Executes the command.
All non-visual, static doc info is in here.
Definition vdocument.h:53
void lowerLayer(VLayer *layer)
Lowers the layer.
void raiseLayer(VLayer *layer)
Raises the layer.
virtual void setState(const VState state)
Sets the state to a specified new state.
Definition vgroup.cpp:148
VLayer manages a set of vobjects.
Definition vlayer.h:37
@ deleted
deleted, nearly dead
Definition vobject.h:58
@ normal
visible, not active
Definition vobject.h:54
VState state() const
Get the state the object is in.
Definition vobject.h:154
void setSuccess(bool success=true)
Set the success property.
Definition vvisitor.h:142