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_PIXMAP_FX 0
32 #include <kpPixmapFX.h>
36 #include <qapplication.h>
38 #include <qdatetime.h>
41 #include <qpainterpath.h>
51 #include <kmessagebox.h>
53 #include <kpAbstractSelection.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
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;
83 useColor
= colorHint1
;
85 useColor
= colorHint2
;
87 p
.fillRect (x
+ dx
, y
+ dy
, StippleSize
, StippleSize
,
88 useColor
.toQColor ());
95 void kpPixmapFX::drawStippledXORPolygon (QPixmap
*image
,
96 const QPolygon
&points
,
97 const kpColor
&fcolor1
, const kpColor
&fcolor2
,
98 const kpColor
&colorHint1
, const kpColor
&colorHint2
,
101 (void) fcolor1
; (void) fcolor2
;
105 kpPixmapFX::drawPolyline (image
,
107 colorHint1
, 1/*pen width*/,
112 kpPixmapFX::drawPolygon (image
,
114 colorHint1
, 1/*pen width*/,
115 kpColor::Invalid
/*no background*/,
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
,
131 colorHint1
, 1/*pen width*/,
132 kpColor::Invalid
/*no background*/,
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 ());
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);
164 // -1's compensate for Qt4's 1 pixel higher and wider
165 // QPainter::drawRect().
166 p
.drawRect (x
, y
, width
- 1, height
- 1);
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
)
177 kpPixmapFX::fillRect (image
,
179 colorHint1
, colorHint2
);
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
)
189 ::WidgetFillStippledRect (widget
,
191 colorHint1
, colorHint2
);
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
,
202 colorHint1
, 1/*pen width*/,
203 kpColor::Invalid
/*no background*/,
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
,
215 colorHint1
, colorHint2
);