there is no moc file generated for this class
[kdegraphics.git] / kolourpaint / layers / tempImage / kpTempImage.cpp
blob77b4bc74a5f5154de9f2b9b42c28a6320030f802
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_TEMP_IMAGE 0
32 #include <kpTempImage.h>
34 #include <kpPixmapFX.h>
35 #include <kpViewManager.h>
38 kpTempImage::kpTempImage (bool isBrush, RenderMode renderMode,
39 const QPoint &topLeft, const kpImage &image)
40 : m_isBrush (isBrush),
41 m_renderMode (renderMode),
42 m_topLeft (topLeft),
43 m_image (image),
44 m_width (image.width ()), m_height (image.height ()),
45 m_userFunction (0),
46 m_userData (0)
48 // Use below constructor for that.
49 Q_ASSERT (renderMode != UserFunction);
52 kpTempImage::kpTempImage (bool isBrush, const QPoint &topLeft,
53 UserFunctionType userFunction, void *userData,
54 int width, int height)
55 : m_isBrush (isBrush),
56 m_renderMode (UserFunction),
57 m_topLeft (topLeft),
58 m_width (width), m_height (height),
59 m_userFunction (userFunction),
60 m_userData (userData)
62 Q_ASSERT (m_userFunction);
65 kpTempImage::kpTempImage (const kpTempImage &rhs)
66 : m_isBrush (rhs.m_isBrush),
67 m_renderMode (rhs.m_renderMode),
68 m_topLeft (rhs.m_topLeft),
69 m_image (rhs.m_image),
70 m_width (rhs.m_width), m_height (rhs.m_height),
71 m_userFunction (rhs.m_userFunction),
72 m_userData (rhs.m_userData)
76 kpTempImage &kpTempImage::operator= (const kpTempImage &rhs)
78 if (this == &rhs)
79 return *this;
81 m_isBrush = rhs.m_isBrush;
82 m_renderMode = rhs.m_renderMode;
83 m_topLeft = rhs.m_topLeft;
84 m_image = rhs.m_image;
85 m_width = rhs.m_width, m_height = rhs.m_height;
86 m_userFunction = rhs.m_userFunction;
87 m_userData = rhs.m_userData;
89 return *this;
92 kpTempImage::~kpTempImage ()
97 // public
98 bool kpTempImage::isBrush () const
100 return m_isBrush;
103 // public
104 kpTempImage::RenderMode kpTempImage::renderMode () const
106 return m_renderMode;
109 // public
110 QPoint kpTempImage::topLeft () const
112 return m_topLeft;
115 // public
116 kpImage kpTempImage::image () const
118 return m_image;
121 // public
122 kpTempImage::UserFunctionType kpTempImage::userFunction () const
124 return m_userFunction;
127 // public
128 void *kpTempImage::userData () const
130 return m_userData;
134 // public
135 bool kpTempImage::isVisible (const kpViewManager *vm) const
137 return m_isBrush ? (bool) vm->viewUnderCursor () : true;
140 // public
141 QRect kpTempImage::rect () const
143 return QRect (m_topLeft.x (), m_topLeft.y (),
144 m_width, m_height);
147 // public
148 int kpTempImage::width () const
150 return m_width;
153 // public
154 int kpTempImage::height () const
156 return m_height;
160 // public
161 bool kpTempImage::paintMayAddMask () const
163 return (m_renderMode == SetImage ||
164 m_renderMode == UserFunction);
167 // public
168 void kpTempImage::paint (kpImage *destImage, const QRect &docRect) const
170 #define REL_TOP_LEFT m_topLeft - docRect.topLeft ()
171 #define PARAMS destImage, REL_TOP_LEFT, m_image
172 switch (m_renderMode)
174 case SetImage:
175 kpPixmapFX::setPixmapAt (PARAMS);
176 break;
177 case PaintImage:
178 kpPixmapFX::paintPixmapAt (PARAMS);
179 break;
180 case UserFunction:
181 m_userFunction (destImage, REL_TOP_LEFT, m_userData);
182 break;
184 #undef PARAMS
185 #undef REL_TOP_LEFT