File indexing completed on 2024-05-12 04:21:20
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 // REFACTOR: maybe make us and kpAbstractSelection share a new kpLayer base? 0029 0030 0031 #ifndef kpTempImage_H 0032 #define kpTempImage_H 0033 0034 0035 #include <QPoint> 0036 0037 #include "imagelib/kpImage.h" 0038 0039 0040 class kpViewManager; 0041 0042 0043 class kpTempImage 0044 { 0045 public: 0046 // REFACTOR: Extract into class hierarchy. 0047 enum RenderMode 0048 { 0049 SetImage, 0050 PaintImage, 0051 UserFunction 0052 }; 0053 0054 // REFACTOR: Function pointers imply a need for a proper class hierarchy. 0055 typedef void (*UserFunctionType) (kpImage * /*destImage*/, 0056 const QPoint & /*topLeft*/, 0057 void * /*userData*/); 0058 0059 /* 0060 * <isBrush> Specifies that its visibility is dependent on whether or 0061 * not the mouse cursor is inside a view. If false, the 0062 * image is always displayed. 0063 * 0064 * <userFunction> This is the only way of specifying the "UserFunction" 0065 * <renderMode>. <userFunction> must not draw outside 0066 * the claimed rectangle. 0067 */ 0068 kpTempImage (bool isBrush, RenderMode renderMode, const QPoint &topLeft, const kpImage &image); 0069 kpTempImage (bool isBrush, const QPoint &topLeft, 0070 UserFunctionType userFunction, void *userData, 0071 int width, int height); 0072 kpTempImage (const kpTempImage &rhs); 0073 kpTempImage &operator= (const kpTempImage &rhs); 0074 0075 bool isBrush () const; 0076 RenderMode renderMode () const; 0077 QPoint topLeft () const; 0078 kpImage image () const; 0079 UserFunctionType userFunction () const; 0080 void *userData () const; 0081 0082 bool isVisible (const kpViewManager *vm) const; 0083 QRect rect () const; 0084 int width () const; 0085 int height () const; 0086 0087 0088 // Returns whether a call to paint() may add a mask to <*destImage>. 0089 bool paintMayAddMask () const; 0090 0091 /* 0092 * Draws itself onto <*destImage>, given that <*destImage> represents 0093 * the unzoomed <docRect> of the kpDocument. You should check for 0094 * visibility before calling this function. 0095 */ 0096 void paint (kpImage *destImage, const QRect &docRect) const; 0097 0098 private: 0099 bool m_isBrush; 0100 RenderMode m_renderMode; 0101 QPoint m_topLeft; 0102 kpImage m_image; 0103 // == m_image.{width,height}() unless m_renderMode == UserFunction. 0104 int m_width, m_height; 0105 UserFunctionType m_userFunction; 0106 void *m_userData; 0107 }; 0108 0109 0110 #endif // kpTempImage_H