3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <kpEffectClearCommand.h>
34 #include <kpAbstractImageSelection.h>
36 #include <kpDocument.h>
37 #include <kpPixmapFX.h>
40 kpEffectClearCommand::kpEffectClearCommand (bool actOnSelection
,
41 const kpColor
&newColor
,
42 kpCommandEnvironment
*environ
)
43 : kpCommand (environ
),
44 m_actOnSelection (actOnSelection
),
45 m_newColor (newColor
),
50 kpEffectClearCommand::~kpEffectClearCommand ()
56 // public virtual [base kpCommand]
57 QString
kpEffectClearCommand::name () const
59 QString opName
= i18n ("Clear");
62 return i18n ("Selection: %1", opName
);
68 // public virtual [base kpCommand]
69 kpCommandSize::SizeType
kpEffectClearCommand::size () const
71 return ImageSize (m_oldImagePtr
);
75 // public virtual [base kpCommand]
76 void kpEffectClearCommand::execute ()
78 kpDocument
*doc
= document ();
82 m_oldImagePtr
= new kpImage ();
83 *m_oldImagePtr
= doc
->image (m_actOnSelection
);
86 // REFACTOR: Would like to derive entire class from kpEffectCommandBase but
87 // this code makes it difficult since it's not just acting on pixels
88 // (kpAbstractImageSelection::fill() takes into account the shape of a selection).
91 // OPT: could just edit pixmap directly and signal change
92 kpAbstractImageSelection
*sel
= doc
->imageSelection ();
94 sel
->fill (m_newColor
);
97 doc
->fill (m_newColor
);
100 // public virtual [base kpCommand]
101 void kpEffectClearCommand::unexecute ()
103 kpDocument
*doc
= document ();
107 doc
->setImage (m_actOnSelection
, *m_oldImagePtr
);
110 delete m_oldImagePtr
;