File indexing completed on 2024-05-12 04:21:25
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 #ifndef KP_TOOL_FLOW_BASE_H 0030 #define KP_TOOL_FLOW_BASE_H 0031 0032 0033 #include <QRect> 0034 0035 #include "layers/tempImage/kpTempImage.h" 0036 #include "tools/kpTool.h" 0037 0038 0039 class QPoint; 0040 class QString; 0041 0042 class kpColor; 0043 class kpToolFlowCommand; 0044 0045 0046 class kpToolFlowBase : public kpTool 0047 { 0048 Q_OBJECT 0049 0050 public: 0051 kpToolFlowBase(const QString &text, const QString &description, 0052 int key, 0053 kpToolEnvironment *environ, QObject *parent, const QString &name); 0054 0055 ~kpToolFlowBase() override; 0056 0057 // Returns the dirty rectangle for drawing a brush(of size 0058 // <brushWidth>x<brushHeight>) at <mousePoint>. <mousePoint> will end 0059 // up being the midpoint of the returned rectangle(subject to integer 0060 // precision). 0061 static QRect hotRectForMousePointAndBrushWidthHeight( 0062 const QPoint &mousePoint, 0063 int brushWidth, int brushHeight); 0064 0065 void begin() override; 0066 void end() override; 0067 0068 void beginDraw() override; 0069 void hover(const QPoint &point) override; 0070 0071 // drawPoint() normally calls drawLine(point,point). Override drawPoint() 0072 // if you think you can be more efficient. 0073 virtual QRect drawPoint(const QPoint &point); 0074 virtual QRect drawLine(const QPoint &thisPoint, const QPoint &lastPoint) = 0; 0075 0076 virtual bool drawShouldProceed(const QPoint & /*thisPoint*/, const QPoint & /*lastPoint*/, const QRect & /*normalizedRect*/) { return true; } 0077 void draw(const QPoint &thisPoint, const QPoint &lastPoint, const QRect &normalizedRect) override; 0078 void cancelShape() override; 0079 void releasedAllButtons() override; 0080 void endDraw(const QPoint &, const QRect &) override; 0081 0082 protected: 0083 virtual QString haventBegunDrawUserMessage() const = 0; 0084 0085 virtual bool haveSquareBrushes() const { return false; } 0086 virtual bool haveDiverseBrushes() const { return false; } 0087 bool haveAnyBrushes() const 0088 { 0089 return(haveSquareBrushes() || haveDiverseBrushes()); 0090 } 0091 0092 virtual bool colorsAreSwapped() const { return false; } 0093 0094 kpTempImage::UserFunctionType brushDrawFunction() const; 0095 void *brushDrawFunctionData() const; 0096 0097 int brushWidth() const; 0098 int brushHeight() const; 0099 0100 bool brushIsDiagonalLine() const; 0101 0102 kpToolFlowCommand *currentCommand() const; 0103 virtual kpColor color(int which); 0104 QRect hotRect() const; 0105 0106 protected Q_SLOTS: 0107 void updateBrushAndCursor(); 0108 0109 void slotForegroundColorChanged(const kpColor &col) override; 0110 void slotBackgroundColorChanged(const kpColor &col) override; 0111 0112 private: 0113 void clearBrushCursorData(); 0114 0115 private: 0116 struct kpToolFlowBasePrivate *d; 0117 }; 0118 0119 0120 #endif // KP_TOOL_FLOW_BASE_H