File indexing completed on 2024-05-12 04:21:12
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_FLOOD_FILL 0 0030 0031 0032 #include "kpToolFloodFillCommand.h" 0033 0034 #include "imagelib/kpColor.h" 0035 #include "kpDefs.h" 0036 #include "document/kpDocument.h" 0037 #include "imagelib/kpImage.h" 0038 #include "kpLogCategories.h" 0039 0040 #include <QApplication> 0041 0042 #include <KLocalizedString> 0043 0044 //--------------------------------------------------------------------- 0045 0046 struct kpToolFloodFillCommandPrivate 0047 { 0048 kpImage oldImage; 0049 bool fillEntireImage{false}; 0050 }; 0051 0052 //--------------------------------------------------------------------- 0053 0054 kpToolFloodFillCommand::kpToolFloodFillCommand (int x, int y, 0055 const kpColor &color, int processedColorSimilarity, 0056 kpCommandEnvironment *environ) 0057 0058 : kpCommand (environ), 0059 kpFloodFill (document ()->imagePointer (), x, y, color, processedColorSimilarity), 0060 d (new kpToolFloodFillCommandPrivate ()) 0061 { 0062 d->fillEntireImage = false; 0063 } 0064 0065 //--------------------------------------------------------------------- 0066 0067 kpToolFloodFillCommand::~kpToolFloodFillCommand () 0068 { 0069 delete d; 0070 } 0071 0072 //--------------------------------------------------------------------- 0073 0074 // public virtual [base kpCommand] 0075 QString kpToolFloodFillCommand::name () const 0076 { 0077 return i18n ("Flood Fill"); 0078 } 0079 0080 //--------------------------------------------------------------------- 0081 0082 // public virtual [base kpCommand] 0083 kpCommandSize::SizeType kpToolFloodFillCommand::size () const 0084 { 0085 return kpFloodFill::size () + ImageSize (d->oldImage); 0086 } 0087 0088 //--------------------------------------------------------------------- 0089 0090 // public 0091 void kpToolFloodFillCommand::setFillEntireImage (bool yes) 0092 { 0093 d->fillEntireImage = yes; 0094 } 0095 0096 //--------------------------------------------------------------------- 0097 0098 // protected virtual [base kpCommand] 0099 void kpToolFloodFillCommand::execute () 0100 { 0101 #if DEBUG_KP_TOOL_FLOOD_FILL && 1 0102 qCDebug(kpLogCommands) << "kpToolFloodFillCommand::execute() fillEntireImage=" 0103 << d->fillEntireImage; 0104 #endif 0105 0106 kpDocument *doc = document (); 0107 Q_ASSERT (doc); 0108 0109 0110 if (d->fillEntireImage) 0111 { 0112 doc->fill (kpFloodFill::color ()); 0113 } 0114 else 0115 { 0116 QRect rect = kpFloodFill::boundingRect (); 0117 if (rect.isValid ()) 0118 { 0119 QApplication::setOverrideCursor (Qt::WaitCursor); 0120 { 0121 d->oldImage = doc->getImageAt (rect); 0122 0123 kpFloodFill::fill (); 0124 doc->slotContentsChanged (rect); 0125 } 0126 QApplication::restoreOverrideCursor (); 0127 } 0128 else 0129 { 0130 #if DEBUG_KP_TOOL_FLOOD_FILL && 1 0131 qCDebug(kpLogCommands) << "\tinvalid boundingRect - must be NOP case"; 0132 #endif 0133 } 0134 } 0135 } 0136 0137 //--------------------------------------------------------------------- 0138 0139 // protected virtual [base kpCommand] 0140 void kpToolFloodFillCommand::unexecute () 0141 { 0142 #if DEBUG_KP_TOOL_FLOOD_FILL && 1 0143 qCDebug(kpLogCommands) << "kpToolFloodFillCommand::unexecute() fillEntireImage=" 0144 << d->fillEntireImage; 0145 #endif 0146 0147 kpDocument *doc = document (); 0148 Q_ASSERT (doc); 0149 0150 0151 if (d->fillEntireImage) 0152 { 0153 doc->fill (kpFloodFill::colorToChange ()); 0154 } 0155 else 0156 { 0157 QRect rect = kpFloodFill::boundingRect (); 0158 if (rect.isValid ()) 0159 { 0160 doc->setImageAt (d->oldImage, rect.topLeft ()); 0161 0162 d->oldImage = kpImage (); 0163 0164 doc->slotContentsChanged (rect); 0165 } 0166 } 0167 } 0168 0169 //---------------------------------------------------------------------