Warning, file /graphics/kolourpaint/commands/tools/rectangular/kpToolRectangularCommand.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 
0002 /*
0003    Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
0004    All rights reserved.
0005 
0006    Redistribution and use in source and binary forms, with or without
0007    modification, are permitted provided that the following conditions
0008    are met:
0009 
0010    1. Redistributions of source code must retain the above copyright
0011       notice, this list of conditions and the following disclaimer.
0012    2. Redistributions in binary form must reproduce the above copyright
0013       notice, this list of conditions and the following disclaimer in the
0014       documentation and/or other materials provided with the distribution.
0015 
0016    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0017    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0018    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0019    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0020    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0021    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0022    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0023    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0024    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0025    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0026 */
0027 
0028 
0029 #define DEBUG_KP_TOOL_RECTANGULAR_COMMAND 0
0030 
0031 
0032 #include "kpToolRectangularCommand.h"
0033 
0034 #include "imagelib/kpColor.h"
0035 #include "kpDefs.h"
0036 #include "document/kpDocument.h"
0037 #include "imagelib/kpPainter.h"
0038 #include "pixmapfx/kpPixmapFX.h"
0039 #include "layers/tempImage/kpTempImage.h"
0040 #include "widgets/toolbars/kpToolToolBar.h"
0041 #include "widgets/toolbars/options/kpToolWidgetFillStyle.h"
0042 #include "widgets/toolbars/options/kpToolWidgetLineWidth.h"
0043 #include "views/kpView.h"
0044 #include "views/manager/kpViewManager.h"
0045 #include "kpLogCategories.h"
0046 
0047 
0048 struct kpToolRectangularCommandPrivate
0049 {
0050     kpToolRectangularBase::DrawShapeFunc drawShapeFunc{};
0051 
0052     QRect rect;
0053 
0054     kpColor fcolor;
0055     int penWidth{};
0056     kpColor bcolor;
0057 
0058     kpImage oldImage;
0059 };
0060 
0061 kpToolRectangularCommand::kpToolRectangularCommand (const QString &name,
0062         kpToolRectangularBase::DrawShapeFunc drawShapeFunc,
0063         const QRect &rect,
0064         const kpColor &fcolor, int penWidth,
0065         const kpColor &bcolor,
0066         kpCommandEnvironment *environ)
0067 
0068     : kpNamedCommand (name, environ),
0069       d (new kpToolRectangularCommandPrivate ())
0070 {
0071     d->drawShapeFunc = drawShapeFunc;
0072 
0073     d->rect = rect;
0074 
0075     d->fcolor = fcolor;
0076     d->penWidth = penWidth;
0077     d->bcolor = bcolor;
0078 }
0079 
0080 kpToolRectangularCommand::~kpToolRectangularCommand ()
0081 {
0082     delete d;
0083 }
0084 
0085 
0086 // public virtual [base kpCommand]
0087 kpCommandSize::SizeType kpToolRectangularCommand::size () const
0088 {
0089     return ImageSize (d->oldImage);
0090 }
0091 
0092 
0093 // public virtual [base kpCommand]
0094 void kpToolRectangularCommand::execute ()
0095 {
0096     kpDocument *doc = document ();
0097     Q_ASSERT (doc);
0098 
0099     // Store Undo info.
0100     // OPT: For a pure rectangle, can do better if there is no bcolor, by only
0101     //      saving 4 pixmaps corresponding to the pixels dirtied by the 4 edges.
0102     Q_ASSERT (d->oldImage.isNull ());
0103     d->oldImage = doc->getImageAt (d->rect);
0104 
0105     // Invoke shape drawing function passed in ctor.
0106     kpImage image = d->oldImage;
0107     (*d->drawShapeFunc) (&image,
0108         0, 0, d->rect.width (), d->rect.height (),
0109         d->fcolor, d->penWidth,
0110         d->bcolor);
0111 
0112     doc->setImageAt (image, d->rect.topLeft ());
0113 }
0114 
0115 // public virtual [base kpCommand]
0116 void kpToolRectangularCommand::unexecute ()
0117 {
0118     kpDocument *doc = document ();
0119     Q_ASSERT (doc);
0120 
0121     Q_ASSERT (!d->oldImage.isNull ());
0122     doc->setImageAt (d->oldImage, d->rect.topLeft ());
0123 
0124     d->oldImage = kpImage ();
0125 }
0126