compile
[kdegraphics.git] / kolourpaint / pixmapfx / kpPixmapFX_DrawRasterOps.cpp
blob114f9ae6b6c7a4a8395d7636440c3600f0f5e7a0
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_PIXMAP_FX 0
32 #include <kpPixmapFX.h>
34 #include <math.h>
36 #include <qapplication.h>
37 #include <qbitmap.h>
38 #include <qdatetime.h>
39 #include <qimage.h>
40 #include <qpainter.h>
41 #include <qpainterpath.h>
42 #include <qpixmap.h>
43 #include <qpoint.h>
44 #include <qpolygon.h>
45 #include <qrect.h>
47 #include <kconfig.h>
48 #include <kdebug.h>
49 #include <kglobal.h>
50 #include <klocale.h>
51 #include <kmessagebox.h>
53 #include <kpAbstractSelection.h>
54 #include <kpColor.h>
55 #include <kpDefs.h>
56 #include <kpTool.h>
57 #include <kconfiggroup.h>
60 static void WidgetFillStippledRect (QWidget *widget,
61 int x, int y, int width, int height,
62 const kpColor &colorHint1, const kpColor &colorHint2)
64 // (transparent color handling not yet implemented)
65 Q_ASSERT (colorHint1.isOpaque () && colorHint2.isOpaque ());
68 // LOREFACTOR: code dup with FillRectHelper() but hard to not dup
70 QPainter p (widget);
71 p.setClipRect (x, y, width, height);
73 const int StippleSize = 4;
75 for (int dy = 0; dy < height; dy += StippleSize)
77 for (int dx = 0; dx < width; dx += StippleSize)
79 const bool parity = ((dy + dx) / StippleSize) % 2;
81 kpColor useColor;
82 if (!parity)
83 useColor = colorHint1;
84 else
85 useColor = colorHint2;
87 p.fillRect (x + dx, y + dy, StippleSize, StippleSize,
88 useColor.toQColor ());
94 // public static
95 void kpPixmapFX::drawStippledXORPolygon (QPixmap *image,
96 const QPolygon &points,
97 const kpColor &fcolor1, const kpColor &fcolor2,
98 const kpColor &colorHint1, const kpColor &colorHint2,
99 bool isFinal)
101 (void) fcolor1; (void) fcolor2;
103 if (!isFinal)
105 kpPixmapFX::drawPolyline (image,
106 points,
107 colorHint1, 1/*pen width*/,
108 colorHint2);
110 else
112 kpPixmapFX::drawPolygon (image,
113 points,
114 colorHint1, 1/*pen width*/,
115 kpColor::Invalid/*no background*/,
116 true/*is final*/,
117 colorHint2);
122 // public static
123 void kpPixmapFX::drawStippledXORRect (QPixmap *image,
124 int x, int y, int width, int height,
125 const kpColor &fcolor1, const kpColor &fcolor2,
126 const kpColor &colorHint1, const kpColor &colorHint2)
128 (void) fcolor1; (void) fcolor2;
129 kpPixmapFX::drawRect (image,
130 x, y, width, height,
131 colorHint1, 1/*pen width*/,
132 kpColor::Invalid/*no background*/,
133 colorHint2);
136 // public static
137 void kpPixmapFX::widgetDrawStippledXORRect (QWidget *widget,
138 int x, int y, int width, int height,
139 const kpColor &fcolor1, const kpColor &fcolor2,
140 const kpColor &colorHint1, const kpColor &colorHint2,
141 const QRect &clipRect)
143 (void) fcolor1; (void) fcolor2;
145 // (transparent color handling not yet implemented)
146 Q_ASSERT (colorHint1.isOpaque () && colorHint2.isOpaque ());
148 QPainter p (widget);
150 if (!clipRect.isEmpty ())
151 p.setClipRect (clipRect);
153 p.setPen (QPen (colorHint1.toQColor (), 1/*width*/, Qt::DotLine));
154 p.setBackground (colorHint2.toQColor ());
155 p.setBackgroundMode (Qt::OpaqueMode);
157 // LOREFACTOR: code dup with DrawGenericRect() but hard to not dup
158 if (width == 1 || height == 1)
160 p.drawLine (x, y, x + width - 1, y + height - 1);
161 return;
164 // -1's compensate for Qt4's 1 pixel higher and wider
165 // QPainter::drawRect().
166 p.drawRect (x, y, width - 1, height - 1);
170 // public static
171 void kpPixmapFX::fillXORRect (QPixmap *image,
172 int x, int y, int width, int height,
173 const kpColor &fcolor,
174 const kpColor &colorHint1, const kpColor &colorHint2)
176 (void) fcolor;
177 kpPixmapFX::fillRect (image,
178 x, y, width, height,
179 colorHint1, colorHint2);
182 // public static
183 void kpPixmapFX::widgetFillXORRect (QWidget *widget,
184 int x, int y, int width, int height,
185 const kpColor &fcolor,
186 const kpColor &colorHint1, const kpColor &colorHint2)
188 (void) fcolor;
189 ::WidgetFillStippledRect (widget,
190 x, y, width, height,
191 colorHint1, colorHint2);
195 // public static
196 void kpPixmapFX::drawNOTRect (QPixmap *image,
197 int x, int y, int width, int height,
198 const kpColor &colorHint1, const kpColor &colorHint2)
200 kpPixmapFX::drawRect (image,
201 x, y, width, height,
202 colorHint1, 1/*pen width*/,
203 kpColor::Invalid/*no background*/,
204 colorHint2);
208 // public static
209 void kpPixmapFX::widgetFillNOTRect (QWidget *widget,
210 int x, int y, int width, int height,
211 const kpColor &colorHint1, const kpColor &colorHint2)
213 ::WidgetFillStippledRect (widget,
214 x, y, width, height,
215 colorHint1, colorHint2);