File indexing completed on 2024-05-19 04:22:59
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 #include "layers/tempImage/kpTempImage.h" 0030 0031 #include "pixmapfx/kpPixmapFX.h" 0032 #include "views/manager/kpViewManager.h" 0033 0034 0035 //--------------------------------------------------------------------- 0036 0037 kpTempImage::kpTempImage (bool isBrush, RenderMode renderMode, 0038 const QPoint &topLeft, const kpImage &image) 0039 : m_isBrush (isBrush), 0040 m_renderMode (renderMode), 0041 m_topLeft (topLeft), 0042 m_image (image), 0043 m_width (image.width ()), m_height (image.height ()), 0044 m_userFunction (nullptr), 0045 m_userData (nullptr) 0046 { 0047 // Use below constructor for that. 0048 Q_ASSERT (renderMode != UserFunction); 0049 } 0050 0051 //--------------------------------------------------------------------- 0052 0053 kpTempImage::kpTempImage (bool isBrush, const QPoint &topLeft, 0054 UserFunctionType userFunction, void *userData, 0055 int width, int height) 0056 : m_isBrush (isBrush), 0057 m_renderMode (UserFunction), 0058 m_topLeft (topLeft), 0059 m_width (width), m_height (height), 0060 m_userFunction (userFunction), 0061 m_userData (userData) 0062 { 0063 Q_ASSERT (m_userFunction); 0064 } 0065 0066 //--------------------------------------------------------------------- 0067 0068 kpTempImage::kpTempImage (const kpTempImage &rhs) 0069 : m_isBrush (rhs.m_isBrush), 0070 m_renderMode (rhs.m_renderMode), 0071 m_topLeft (rhs.m_topLeft), 0072 m_image (rhs.m_image), 0073 m_width (rhs.m_width), m_height (rhs.m_height), 0074 m_userFunction (rhs.m_userFunction), 0075 m_userData (rhs.m_userData) 0076 { 0077 } 0078 0079 //--------------------------------------------------------------------- 0080 0081 kpTempImage &kpTempImage::operator= (const kpTempImage &rhs) 0082 { 0083 if (this == &rhs) { 0084 return *this; 0085 } 0086 0087 m_isBrush = rhs.m_isBrush; 0088 m_renderMode = rhs.m_renderMode; 0089 m_topLeft = rhs.m_topLeft; 0090 m_image = rhs.m_image; 0091 m_width = rhs.m_width; 0092 m_height = rhs.m_height; 0093 m_userFunction = rhs.m_userFunction; 0094 m_userData = rhs.m_userData; 0095 0096 return *this; 0097 } 0098 0099 //--------------------------------------------------------------------- 0100 0101 // public 0102 bool kpTempImage::isBrush () const 0103 { 0104 return m_isBrush; 0105 } 0106 0107 //--------------------------------------------------------------------- 0108 0109 // public 0110 kpTempImage::RenderMode kpTempImage::renderMode () const 0111 { 0112 return m_renderMode; 0113 } 0114 0115 //--------------------------------------------------------------------- 0116 0117 // public 0118 QPoint kpTempImage::topLeft () const 0119 { 0120 return m_topLeft; 0121 } 0122 0123 //--------------------------------------------------------------------- 0124 0125 // public 0126 kpImage kpTempImage::image () const 0127 { 0128 return m_image; 0129 } 0130 0131 //--------------------------------------------------------------------- 0132 0133 // public 0134 kpTempImage::UserFunctionType kpTempImage::userFunction () const 0135 { 0136 return m_userFunction; 0137 } 0138 0139 //--------------------------------------------------------------------- 0140 0141 // public 0142 void *kpTempImage::userData () const 0143 { 0144 return m_userData; 0145 } 0146 0147 //--------------------------------------------------------------------- 0148 0149 // public 0150 bool kpTempImage::isVisible (const kpViewManager *vm) const 0151 { 0152 return m_isBrush ? static_cast<bool> (vm->viewUnderCursor ()) : true; 0153 } 0154 0155 //--------------------------------------------------------------------- 0156 0157 // public 0158 QRect kpTempImage::rect () const 0159 { 0160 return {m_topLeft.x (), m_topLeft.y (), m_width, m_height}; 0161 } 0162 0163 //--------------------------------------------------------------------- 0164 0165 // public 0166 int kpTempImage::width () const 0167 { 0168 return m_width; 0169 } 0170 0171 //--------------------------------------------------------------------- 0172 0173 // public 0174 int kpTempImage::height () const 0175 { 0176 return m_height; 0177 } 0178 0179 //--------------------------------------------------------------------- 0180 0181 // public 0182 bool kpTempImage::paintMayAddMask () const 0183 { 0184 return (m_renderMode == SetImage || 0185 m_renderMode == UserFunction); 0186 } 0187 0188 //--------------------------------------------------------------------- 0189 0190 // public 0191 void kpTempImage::paint (kpImage *destImage, const QRect &docRect) const 0192 { 0193 const QPoint REL_TOP_LEFT = m_topLeft - docRect.topLeft (); 0194 0195 switch (m_renderMode) 0196 { 0197 case SetImage: 0198 { 0199 kpPixmapFX::setPixmapAt(destImage, REL_TOP_LEFT, m_image); 0200 break; 0201 } 0202 0203 case PaintImage: 0204 { 0205 kpPixmapFX::paintPixmapAt(destImage, REL_TOP_LEFT, m_image); 0206 break; 0207 } 0208 0209 case UserFunction: 0210 { 0211 m_userFunction(destImage, REL_TOP_LEFT, m_userData); 0212 break; 0213 } 0214 } 0215 } 0216 0217 //---------------------------------------------------------------------