use kDebug
[kdegraphics.git] / kolourpaint / tools / kpToolFloodFill.cpp
blob73bab783a81e9f47e6b0ea7b4633ec97fdc389a3
2 /*
3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
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 #define DEBUG_KP_TOOL_FLOOD_FILL 0
32 #include <kpToolFloodFill.h>
34 #include <qapplication.h>
36 #include <kdebug.h>
37 #include <klocale.h>
39 #include <kpCommandHistory.h>
40 #include <kpDefs.h>
41 #include <kpDocument.h>
42 #include <kpToolEnvironment.h>
43 #include <kpToolFloodFillCommand.h>
46 struct kpToolFloodFillPrivate
48 kpToolFloodFillCommand *currentCommand;
51 kpToolFloodFill::kpToolFloodFill (kpToolEnvironment *environ, QObject *parent)
52 : kpTool (i18n ("Flood Fill"), i18n ("Fills regions in the image"),
53 Qt::Key_F,
54 environ, parent, "tool_flood_fill"),
55 d (new kpToolFloodFillPrivate ())
57 d->currentCommand = 0;
60 kpToolFloodFill::~kpToolFloodFill ()
62 delete d;
66 // private
67 QString kpToolFloodFill::haventBegunDrawUserMessage () const
69 return i18n ("Click to fill a region.");
73 // public virtual [base kpTool]
74 void kpToolFloodFill::begin ()
76 setUserMessage (haventBegunDrawUserMessage ());
79 // public virtual [base kpTool]
80 void kpToolFloodFill::beginDraw ()
82 #if DEBUG_KP_TOOL_FLOOD_FILL && 1
83 kDebug () << "kpToolFloodFill::beginDraw()";
84 #endif
86 QApplication::setOverrideCursor (Qt::WaitCursor);
88 environ ()->flashColorSimilarityToolBarItem ();
90 // Flood Fill is an expensive CPU operation so we only fill at a
91 // mouse click (beginDraw ()), not on mouse move (virtually draw())
92 d->currentCommand = new kpToolFloodFillCommand (
93 currentPoint ().x (), currentPoint ().y (),
94 color (mouseButton ()), processedColorSimilarity (),
95 environ ()->commandEnvironment ());
97 #if DEBUG_KP_TOOL_FLOOD_FILL && 1
98 kDebug () << "\tperforming new-doc-corner-case check";
99 #endif
101 if (document ()->url ().isEmpty () && !document ()->isModified ())
103 // Collect the colour that gets changed before we change the pixels
104 // (execute() below). Needed in unexecute().
105 d->currentCommand->prepareColorToChange ();
107 d->currentCommand->setFillEntireImage ();
110 d->currentCommand->execute ();
112 QApplication::restoreOverrideCursor ();
114 setUserMessage (cancelUserMessage ());
117 // public virtual [base kpTool]
118 void kpToolFloodFill::draw (const QPoint &thisPoint, const QPoint &, const QRect &)
120 setUserShapePoints (thisPoint);
123 // public virtual [base kpTool]
124 void kpToolFloodFill::cancelShape ()
126 d->currentCommand->unexecute ();
128 delete d->currentCommand;
129 d->currentCommand = 0;
131 setUserMessage (i18n ("Let go of all the mouse buttons."));
134 // public virtual [base kpTool]
135 void kpToolFloodFill::releasedAllButtons ()
137 setUserMessage (haventBegunDrawUserMessage ());
140 // public virtual [base kpTool]
141 void kpToolFloodFill::endDraw (const QPoint &, const QRect &)
143 environ ()->commandHistory ()->addCommand (d->currentCommand,
144 false/*no exec - we already did it up there*/);
146 // Don't delete - it just got added to the history.
147 d->currentCommand = 0;
148 setUserMessage (haventBegunDrawUserMessage ());
152 #include <kpToolFloodFill.moc>