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_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
),
44 m_width (image
.width ()), m_height (image
.height ()),
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
),
58 m_width (width
), m_height (height
),
59 m_userFunction (userFunction
),
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
)
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
;
92 kpTempImage::~kpTempImage ()
98 bool kpTempImage::isBrush () const
104 kpTempImage::RenderMode
kpTempImage::renderMode () const
110 QPoint
kpTempImage::topLeft () const
116 kpImage
kpTempImage::image () const
122 kpTempImage::UserFunctionType
kpTempImage::userFunction () const
124 return m_userFunction
;
128 void *kpTempImage::userData () const
135 bool kpTempImage::isVisible (const kpViewManager
*vm
) const
137 return m_isBrush
? (bool) vm
->viewUnderCursor () : true;
141 QRect
kpTempImage::rect () const
143 return QRect (m_topLeft
.x (), m_topLeft
.y (),
148 int kpTempImage::width () const
154 int kpTempImage::height () const
161 bool kpTempImage::paintMayAddMask () const
163 return (m_renderMode
== SetImage
||
164 m_renderMode
== UserFunction
);
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
)
175 kpPixmapFX::setPixmapAt (PARAMS
);
178 kpPixmapFX::paintPixmapAt (PARAMS
);
181 m_userFunction (destImage
, REL_TOP_LEFT
, m_userData
);