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 #define DEBUG_KP_TOOL_COLOR_PICKER 0
32 #include <kpToolColorPicker.h>
37 #include <kpColorToolBar.h>
38 #include <kpCommandHistory.h>
40 #include <kpDocument.h>
41 #include <kpPixmapFX.h>
42 #include <kpToolColorPickerCommand.h>
43 #include <kpToolEnvironment.h>
46 kpToolColorPicker::kpToolColorPicker (kpToolEnvironment
*environ
, QObject
*parent
)
47 : kpTool (i18n ("Color Picker"), i18n ("Lets you select a color from the image"),
49 environ
, parent
, "tool_color_picker")
53 kpToolColorPicker::~kpToolColorPicker ()
59 kpColor
kpToolColorPicker::colorAtPixel (const QPoint
&p
)
61 #if DEBUG_KP_TOOL_COLOR_PICKER && 0
62 kDebug () << "kpToolColorPicker::colorAtPixel" << p
;
65 return kpPixmapFX::getColorAtPixel (document ()->image (), p
);
70 QString
kpToolColorPicker::haventBegunDrawUserMessage () const
72 return i18n ("Click to select a color.");
76 // public virtual [base kpTool]
77 void kpToolColorPicker::begin ()
79 setUserMessage (haventBegunDrawUserMessage ());
82 // public virtual [base kpTool]
83 void kpToolColorPicker::beginDraw ()
85 m_oldColor
= color (mouseButton ());
87 setUserMessage (cancelUserMessage ());
90 // public virtual [base kpTool]
91 void kpToolColorPicker::draw (const QPoint
&thisPoint
, const QPoint
&, const QRect
&)
93 const kpColor color
= colorAtPixel (thisPoint
);
97 environ ()->setColor (mouseButton (), color
);
98 setUserShapePoints (thisPoint
);
102 environ ()->setColor (mouseButton (), m_oldColor
);
103 setUserShapePoints ();
107 // public virtual [base kpTool]
108 void kpToolColorPicker::cancelShape ()
110 environ ()->setColor (mouseButton (), m_oldColor
);
112 setUserMessage (i18n ("Let go of all the mouse buttons."));
115 // public virtual [base kpTool]
116 void kpToolColorPicker::releasedAllButtons ()
118 setUserMessage (haventBegunDrawUserMessage ());
122 // public virtual [base kpTool]
123 void kpToolColorPicker::endDraw (const QPoint
&thisPoint
, const QRect
&)
125 const kpColor color
= colorAtPixel (thisPoint
);
127 if (color
.isValid ())
129 kpToolColorPickerCommand
*cmd
=
130 new kpToolColorPickerCommand (
133 environ ()->commandEnvironment ());
135 environ ()->commandHistory ()->addCommand (cmd
, false/*no exec*/);
136 setUserMessage (haventBegunDrawUserMessage ());
145 #include <kpToolColorPicker.moc>