author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
** All rights reserved. |
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
44 |
#include "../../shared/util.h" |
0 | 45 |
|
46 |
#include <qpainter.h> |
|
47 |
#include <qapplication.h> |
|
48 |
#include <qwidget.h> |
|
49 |
#include <qfontmetrics.h> |
|
50 |
#include <qbitmap.h> |
|
51 |
#include <qimage.h> |
|
52 |
#include <limits.h> |
|
53 |
#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
|
54 |
#include <qprinter.h> |
|
55 |
#include <math.h> |
|
56 |
#ifdef QT3_SUPPORT |
|
57 |
#include <q3painter.h> |
|
58 |
#endif |
|
59 |
#endif |
|
60 |
#include <qpaintengine.h> |
|
61 |
#include <qdesktopwidget.h> |
|
62 |
#include <qpixmap.h> |
|
63 |
||
64 |
#include <qpainter.h> |
|
65 |
||
66 |
#include <qlabel.h> |
|
67 |
||
68 |
#include <qqueue.h> |
|
69 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
70 |
#include <qgraphicsview.h> |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
#include <qgraphicsscene.h> |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
72 |
#include <qgraphicsproxywidget.h> |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
#include <qlayout.h> |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
|
0 | 75 |
#if defined(Q_OS_SYMBIAN) |
76 |
# define SRCDIR "." |
|
77 |
#endif |
|
78 |
||
79 |
Q_DECLARE_METATYPE(QLine) |
|
80 |
Q_DECLARE_METATYPE(QRect) |
|
81 |
Q_DECLARE_METATYPE(QSize) |
|
82 |
Q_DECLARE_METATYPE(QPoint) |
|
83 |
Q_DECLARE_METATYPE(QPainterPath) |
|
84 |
||
85 |
//TESTED_CLASS= |
|
86 |
//TESTED_FILES= |
|
87 |
||
88 |
class tst_QPainter : public QObject |
|
89 |
{ |
|
90 |
Q_OBJECT |
|
91 |
||
92 |
public: |
|
93 |
tst_QPainter(); |
|
94 |
virtual ~tst_QPainter(); |
|
95 |
||
96 |
||
97 |
public slots: |
|
98 |
void init(); |
|
99 |
void cleanup(); |
|
100 |
private slots: |
|
101 |
void getSetCheck(); |
|
102 |
void qt_format_text_clip(); |
|
103 |
void qt_format_text_boundingRect(); |
|
104 |
void drawPixmap_comp_data(); |
|
105 |
void drawPixmap_comp(); |
|
106 |
void saveAndRestore_data(); |
|
107 |
void saveAndRestore(); |
|
108 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
109 |
void drawBorderPixmap(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
110 |
|
0 | 111 |
void drawLine_data(); |
112 |
void drawLine(); |
|
113 |
void drawLine_clipped(); |
|
114 |
void drawLine_task121143(); |
|
115 |
void drawLine_task216948(); |
|
116 |
||
117 |
void drawLine_task190634(); |
|
118 |
void drawLine_task229459(); |
|
119 |
void drawLine_task234891(); |
|
120 |
||
121 |
void drawRect_data() { fillData(); } |
|
122 |
void drawRect(); |
|
123 |
void drawRect2(); |
|
124 |
||
125 |
void fillRect(); |
|
126 |
void fillRect2(); |
|
127 |
void fillRect3(); |
|
128 |
void fillRect4(); |
|
129 |
||
130 |
void drawEllipse_data(); |
|
131 |
void drawEllipse(); |
|
132 |
void drawClippedEllipse_data(); |
|
133 |
void drawClippedEllipse(); |
|
134 |
||
135 |
void drawPath_data(); |
|
136 |
void drawPath(); |
|
137 |
void drawPath2(); |
|
138 |
void drawPath3(); |
|
139 |
||
140 |
void drawRoundRect_data() { fillData(); } |
|
141 |
void drawRoundRect(); |
|
142 |
||
143 |
void qimageFormats_data(); |
|
144 |
void qimageFormats(); |
|
145 |
void textOnTransparentImage(); |
|
146 |
||
147 |
void initFrom(); |
|
148 |
||
149 |
void setWindow(); |
|
150 |
||
151 |
void combinedMatrix(); |
|
152 |
void renderHints(); |
|
153 |
||
154 |
void disableEnableClipping(); |
|
155 |
void setClipRect(); |
|
156 |
void setEqualClipRegionAndPath_data(); |
|
157 |
void setEqualClipRegionAndPath(); |
|
158 |
||
159 |
void clipRectSaveRestore(); |
|
160 |
||
161 |
void clippedFillPath_data(); |
|
162 |
void clippedFillPath(); |
|
163 |
void clippedLines_data(); |
|
164 |
void clippedLines(); |
|
165 |
void clippedPolygon_data(); |
|
166 |
void clippedPolygon(); |
|
167 |
||
168 |
void clippedText(); |
|
169 |
||
170 |
void setOpacity_data(); |
|
171 |
void setOpacity(); |
|
172 |
||
173 |
void drawhelper_blend_untransformed_data(); |
|
174 |
void drawhelper_blend_untransformed(); |
|
175 |
void drawhelper_blend_tiled_untransformed_data(); |
|
176 |
void drawhelper_blend_tiled_untransformed(); |
|
177 |
||
178 |
void porterDuff_warning(); |
|
179 |
||
180 |
void drawhelper_blend_color(); |
|
181 |
||
182 |
void childWidgetViewport(); |
|
183 |
||
184 |
void fillRect_objectBoundingModeGradient(); |
|
185 |
void fillRect_stretchToDeviceMode(); |
|
186 |
void monoImages(); |
|
187 |
||
188 |
void linearGradientSymmetry(); |
|
189 |
void gradientInterpolation(); |
|
190 |
||
191 |
void fpe_pixmapTransform(); |
|
192 |
void fpe_zeroLengthLines(); |
|
193 |
void fpe_divByZero(); |
|
194 |
||
195 |
void fpe_steepSlopes_data(); |
|
196 |
void fpe_steepSlopes(); |
|
197 |
void fpe_rasterizeLine_task232012(); |
|
198 |
||
199 |
void fpe_radialGradients(); |
|
200 |
||
201 |
void rasterizer_asserts(); |
|
202 |
void rasterizer_negativeCoords(); |
|
203 |
||
204 |
void blendOverFlow_data(); |
|
205 |
void blendOverFlow(); |
|
206 |
||
207 |
void largeImagePainting_data(); |
|
208 |
void largeImagePainting(); |
|
209 |
||
210 |
void imageScaling_task206785(); |
|
211 |
||
212 |
void outlineFillConsistency(); |
|
213 |
||
214 |
void drawImage_task217400_data(); |
|
215 |
void drawImage_task217400(); |
|
216 |
void drawImage_1x1(); |
|
217 |
void drawImage_task258776(); |
|
218 |
void drawRect_task215378(); |
|
219 |
void drawRect_task247505(); |
|
220 |
||
221 |
void drawImage_data(); |
|
222 |
void drawImage(); |
|
223 |
||
224 |
void clippedImage(); |
|
225 |
||
226 |
void stateResetBetweenQPainters(); |
|
227 |
||
228 |
void imageCoordinateLimit(); |
|
229 |
void imageBlending_data(); |
|
230 |
void imageBlending(); |
|
231 |
void imageBlending_clipped(); |
|
232 |
||
233 |
void paintOnNullPixmap(); |
|
234 |
void checkCompositionMode(); |
|
235 |
||
236 |
void drawPolygon(); |
|
237 |
||
238 |
void inactivePainter(); |
|
239 |
||
240 |
void extendedBlendModes(); |
|
241 |
||
242 |
void zeroOpacity(); |
|
243 |
void clippingBug(); |
|
244 |
void emptyClip(); |
|
245 |
||
246 |
void taskQT4444_dontOverflowDashOffset(); |
|
247 |
||
248 |
void painterBegin(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
249 |
void setPenColorOnImage(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
250 |
void setPenColorOnPixmap(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
251 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
252 |
void QTBUG5939_attachPainterPrivate(); |
0 | 253 |
|
254 |
private: |
|
255 |
void fillData(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
256 |
void setPenColor(QPainter& p); |
0 | 257 |
QColor baseColor( int k, int intensity=255 ); |
258 |
QImage getResImage( const QString &dir, const QString &addition, const QString &extension ); |
|
259 |
QBitmap getBitmap( const QString &dir, const QString &filename, bool mask ); |
|
260 |
}; |
|
261 |
||
262 |
// Testing get/set functions |
|
263 |
void tst_QPainter::getSetCheck() |
|
264 |
{ |
|
265 |
QImage img(QSize(10, 10), QImage::Format_ARGB32_Premultiplied); |
|
266 |
QPainter obj1; |
|
267 |
obj1.begin(&img); |
|
268 |
// CompositionMode QPainter::compositionMode() |
|
269 |
// void QPainter::setCompositionMode(CompositionMode) |
|
270 |
obj1.setCompositionMode(QPainter::CompositionMode(QPainter::CompositionMode_SourceOver)); |
|
271 |
QCOMPARE(QPainter::CompositionMode(QPainter::CompositionMode_SourceOver), obj1.compositionMode()); |
|
272 |
obj1.setCompositionMode(QPainter::CompositionMode(QPainter::CompositionMode_DestinationOver)); |
|
273 |
QCOMPARE(QPainter::CompositionMode(QPainter::CompositionMode_DestinationOver), obj1.compositionMode()); |
|
274 |
obj1.setCompositionMode(QPainter::CompositionMode(QPainter::CompositionMode_Clear)); |
|
275 |
QCOMPARE(QPainter::CompositionMode(QPainter::CompositionMode_Clear), obj1.compositionMode()); |
|
276 |
obj1.setCompositionMode(QPainter::CompositionMode(QPainter::CompositionMode_Source)); |
|
277 |
QCOMPARE(QPainter::CompositionMode(QPainter::CompositionMode_Source), obj1.compositionMode()); |
|
278 |
obj1.setCompositionMode(QPainter::CompositionMode(QPainter::CompositionMode_Destination)); |
|
279 |
QCOMPARE(QPainter::CompositionMode(QPainter::CompositionMode_Destination), obj1.compositionMode()); |
|
280 |
obj1.setCompositionMode(QPainter::CompositionMode(QPainter::CompositionMode_SourceIn)); |
|
281 |
QCOMPARE(QPainter::CompositionMode(QPainter::CompositionMode_SourceIn), obj1.compositionMode()); |
|
282 |
obj1.setCompositionMode(QPainter::CompositionMode(QPainter::CompositionMode_DestinationIn)); |
|
283 |
QCOMPARE(QPainter::CompositionMode(QPainter::CompositionMode_DestinationIn), obj1.compositionMode()); |
|
284 |
obj1.setCompositionMode(QPainter::CompositionMode(QPainter::CompositionMode_SourceOut)); |
|
285 |
QCOMPARE(QPainter::CompositionMode(QPainter::CompositionMode_SourceOut), obj1.compositionMode()); |
|
286 |
obj1.setCompositionMode(QPainter::CompositionMode(QPainter::CompositionMode_DestinationOut)); |
|
287 |
QCOMPARE(QPainter::CompositionMode(QPainter::CompositionMode_DestinationOut), obj1.compositionMode()); |
|
288 |
obj1.setCompositionMode(QPainter::CompositionMode(QPainter::CompositionMode_SourceAtop)); |
|
289 |
QCOMPARE(QPainter::CompositionMode(QPainter::CompositionMode_SourceAtop), obj1.compositionMode()); |
|
290 |
obj1.setCompositionMode(QPainter::CompositionMode(QPainter::CompositionMode_DestinationAtop)); |
|
291 |
QCOMPARE(QPainter::CompositionMode(QPainter::CompositionMode_DestinationAtop), obj1.compositionMode()); |
|
292 |
obj1.setCompositionMode(QPainter::CompositionMode(QPainter::CompositionMode_Xor)); |
|
293 |
QCOMPARE(QPainter::CompositionMode(QPainter::CompositionMode_Xor), obj1.compositionMode()); |
|
294 |
||
295 |
// const QPen & QPainter::pen() |
|
296 |
// void QPainter::setPen(const QPen &) |
|
297 |
QPen var3(Qt::red); |
|
298 |
obj1.setPen(var3); |
|
299 |
QCOMPARE(var3, obj1.pen()); |
|
300 |
obj1.setPen(QPen()); |
|
301 |
QCOMPARE(QPen(), obj1.pen()); |
|
302 |
||
303 |
// const QBrush & QPainter::brush() |
|
304 |
// void QPainter::setBrush(const QBrush &) |
|
305 |
QBrush var4(Qt::red); |
|
306 |
obj1.setBrush(var4); |
|
307 |
QCOMPARE(var4, obj1.brush()); |
|
308 |
obj1.setBrush(QBrush()); |
|
309 |
QCOMPARE(QBrush(), obj1.brush()); |
|
310 |
||
311 |
// const QBrush & QPainter::background() |
|
312 |
// void QPainter::setBackground(const QBrush &) |
|
313 |
QBrush var5(Qt::yellow); |
|
314 |
obj1.setBackground(var5); |
|
315 |
QCOMPARE(var5, obj1.background()); |
|
316 |
obj1.setBackground(QBrush()); |
|
317 |
QCOMPARE(QBrush(), obj1.background()); |
|
318 |
||
319 |
// bool QPainter::matrixEnabled() |
|
320 |
// void QPainter::setMatrixEnabled(bool) |
|
321 |
obj1.setMatrixEnabled(false); |
|
322 |
QCOMPARE(false, obj1.matrixEnabled()); |
|
323 |
obj1.setMatrixEnabled(true); |
|
324 |
QCOMPARE(true, obj1.matrixEnabled()); |
|
325 |
||
326 |
// bool QPainter::viewTransformEnabled() |
|
327 |
// void QPainter::setViewTransformEnabled(bool) |
|
328 |
obj1.setViewTransformEnabled(false); |
|
329 |
QCOMPARE(false, obj1.viewTransformEnabled()); |
|
330 |
obj1.setViewTransformEnabled(true); |
|
331 |
QCOMPARE(true, obj1.viewTransformEnabled()); |
|
332 |
} |
|
333 |
||
334 |
Q_DECLARE_METATYPE(QPixmap) |
|
335 |
Q_DECLARE_METATYPE(QPolygon) |
|
336 |
Q_DECLARE_METATYPE(QBrush) |
|
337 |
Q_DECLARE_METATYPE(QPen) |
|
338 |
Q_DECLARE_METATYPE(QFont) |
|
339 |
Q_DECLARE_METATYPE(QColor) |
|
340 |
Q_DECLARE_METATYPE(QRegion) |
|
341 |
||
342 |
tst_QPainter::tst_QPainter() |
|
343 |
{ |
|
344 |
// QtTestCase sets this to false, but this turns off alpha pixmaps on Unix. |
|
345 |
QApplication::setDesktopSettingsAware(TRUE); |
|
346 |
} |
|
347 |
||
348 |
tst_QPainter::~tst_QPainter() |
|
349 |
{ |
|
350 |
} |
|
351 |
||
352 |
void tst_QPainter::init() |
|
353 |
{ |
|
354 |
} |
|
355 |
||
356 |
void tst_QPainter::cleanup() |
|
357 |
{ |
|
358 |
} |
|
359 |
||
360 |
/* tests the clipping operations in qt_format_text, making sure |
|
361 |
the clip rectangle after the call is the same as before |
|
362 |
*/ |
|
363 |
void tst_QPainter::qt_format_text_clip() |
|
364 |
{ |
|
365 |
QVERIFY(1); |
|
366 |
QSKIP( "Needs fixing...", SkipAll); |
|
367 |
||
368 |
QWidget *w = new QWidget( 0 ); |
|
369 |
||
370 |
int modes[] = { Qt::AlignVCenter|Qt::TextSingleLine, |
|
371 |
Qt::AlignVCenter|Qt::TextSingleLine|Qt::TextDontClip, |
|
372 |
Qt::AlignVCenter|Qt::TextWordWrap, |
|
373 |
Qt::AlignVCenter|Qt::TextWordWrap|Qt::TextDontClip, |
|
374 |
0 |
|
375 |
}; |
|
376 |
||
377 |
int *m = modes; |
|
378 |
while( *m ) { |
|
379 |
{ |
|
380 |
QPainter p( w ); |
|
381 |
QRegion clipreg = p.clipRegion(); |
|
382 |
bool hasClipping = p.hasClipping(); |
|
383 |
qreal tx = p.matrix().dx(); |
|
384 |
qreal ty = p.matrix().dy(); |
|
385 |
||
386 |
p.drawText( 10, 10, 100, 100, *m, |
|
387 |
"fooo" ); |
|
388 |
||
389 |
QVERIFY( clipreg == p.clipRegion() ); |
|
390 |
QVERIFY( hasClipping == p.hasClipping() ); |
|
391 |
QCOMPARE( tx, p.matrix().dx() ); |
|
392 |
QCOMPARE( ty, p.matrix().dy() ); |
|
393 |
||
394 |
p.setClipRect( QRect( 5, 5, 50, 50 ) ); |
|
395 |
clipreg = p.clipRegion(); |
|
396 |
hasClipping = p.hasClipping(); |
|
397 |
||
398 |
p.drawText( 10, 10, 100, 100, *m, |
|
399 |
"fooo" ); |
|
400 |
||
401 |
QVERIFY( clipreg == p.clipRegion() ); |
|
402 |
QVERIFY( hasClipping == p.hasClipping() ); |
|
403 |
QCOMPARE( tx, p.matrix().dx() ); |
|
404 |
QCOMPARE( ty, p.matrix().dy() ); |
|
405 |
} |
|
406 |
{ |
|
407 |
QPainter p( w ); |
|
408 |
p.setMatrix( QMatrix( 2, 1, 3, 4, 5, 6 ) ); |
|
409 |
QRegion clipreg = p.clipRegion(); |
|
410 |
bool hasClipping = p.hasClipping(); |
|
411 |
qreal tx = p.matrix().dx(); |
|
412 |
qreal ty = p.matrix().dy(); |
|
413 |
||
414 |
p.drawText( 10, 10, 100, 100, *m, |
|
415 |
"fooo" ); |
|
416 |
||
417 |
QVERIFY( clipreg == p.clipRegion() ); |
|
418 |
QVERIFY( hasClipping == p.hasClipping() ); |
|
419 |
QCOMPARE( tx, p.matrix().dx() ); |
|
420 |
QCOMPARE( ty, p.matrix().dy() ); |
|
421 |
||
422 |
p.setClipRect( QRect( 5, 5, 50, 50 ) ); |
|
423 |
clipreg = p.clipRegion(); |
|
424 |
hasClipping = p.hasClipping(); |
|
425 |
||
426 |
p.drawText( 10, 10, 100, 100, *m, |
|
427 |
"fooo" ); |
|
428 |
||
429 |
QVERIFY( clipreg == p.clipRegion() ); |
|
430 |
QVERIFY( hasClipping == p.hasClipping() ); |
|
431 |
QCOMPARE( tx, p.matrix().dx() ); |
|
432 |
QCOMPARE( ty, p.matrix().dy() ); |
|
433 |
} |
|
434 |
{ |
|
435 |
QPainter p( w ); |
|
436 |
QRegion clipreg = p.clipRegion(); |
|
437 |
bool hasClipping = p.hasClipping(); |
|
438 |
qreal tx = p.matrix().dx(); |
|
439 |
qreal ty = p.matrix().dy(); |
|
440 |
||
441 |
p.drawText( 10, 10, 100, 100, *m, |
|
442 |
"fooo" ); |
|
443 |
||
444 |
QVERIFY( clipreg == p.clipRegion() ); |
|
445 |
QVERIFY( hasClipping == p.hasClipping() ); |
|
446 |
QCOMPARE( tx, p.matrix().dx() ); |
|
447 |
QCOMPARE( ty, p.matrix().dy() ); |
|
448 |
||
449 |
p.setClipRect( QRect( 5, 5, 50, 50 )); |
|
450 |
clipreg = p.clipRegion(); |
|
451 |
hasClipping = p.hasClipping(); |
|
452 |
||
453 |
p.drawText( 10, 10, 100, 100, *m, |
|
454 |
"fooo" ); |
|
455 |
||
456 |
QVERIFY( clipreg == p.clipRegion() ); |
|
457 |
QVERIFY( hasClipping == p.hasClipping() ); |
|
458 |
QCOMPARE( tx, p.matrix().dx() ); |
|
459 |
QCOMPARE( ty, p.matrix().dy() ); |
|
460 |
} |
|
461 |
{ |
|
462 |
QPainter p( w ); |
|
463 |
p.setMatrix( QMatrix( 2, 1, 3, 4, 5, 6 ) ); |
|
464 |
QRegion clipreg = p.clipRegion(); |
|
465 |
bool hasClipping = p.hasClipping(); |
|
466 |
qreal tx = p.matrix().dx(); |
|
467 |
qreal ty = p.matrix().dy(); |
|
468 |
||
469 |
p.drawText( 10, 10, 100, 100, *m, |
|
470 |
"fooo" ); |
|
471 |
||
472 |
QVERIFY( clipreg == p.clipRegion() ); |
|
473 |
QVERIFY( hasClipping == p.hasClipping() ); |
|
474 |
QCOMPARE( tx, p.matrix().dx() ); |
|
475 |
QCOMPARE( ty, p.matrix().dy() ); |
|
476 |
||
477 |
p.setClipRect(QRect( 5, 5, 50, 50 )); |
|
478 |
clipreg = p.clipRegion(); |
|
479 |
hasClipping = p.hasClipping(); |
|
480 |
||
481 |
p.drawText( 10, 10, 100, 100, *m, |
|
482 |
"fooo" ); |
|
483 |
||
484 |
QVERIFY( clipreg == p.clipRegion() ); |
|
485 |
QVERIFY( hasClipping == p.hasClipping() ); |
|
486 |
QCOMPARE( tx, p.matrix().dx() ); |
|
487 |
QCOMPARE( ty, p.matrix().dy() ); |
|
488 |
} |
|
489 |
++m; |
|
490 |
} |
|
491 |
delete w; |
|
492 |
} |
|
493 |
||
494 |
/* tests the bounding rect calculations in qt_format_text, making sure |
|
495 |
the bounding rect has a reasonable value. |
|
496 |
*/ |
|
497 |
void tst_QPainter::qt_format_text_boundingRect() |
|
498 |
{ |
|
499 |
QVERIFY(1); |
|
500 |
QSKIP( "Needs fixing...", SkipAll); |
|
501 |
||
502 |
{ |
|
503 |
const char * strings[] = { |
|
504 |
"a\n\nb", |
|
505 |
"abc", |
|
506 |
"a\n \nb", |
|
507 |
"this is a longer string", |
|
508 |
"\327\222\327\223\327\233\327\223\327\222\327\233\327\222\327\223\327\233", |
|
509 |
"aa\327\222\327\233aa", |
|
510 |
"\327\222\327\223\327\233\327\223\327\222\327\233\327\222\327\223\327\233", |
|
511 |
"\327\222\327\233aa", |
|
512 |
"linebreakatend\n", |
|
513 |
"some text longer than 30 chars with a line break at the end\n", |
|
514 |
"some text\nwith line breaks\nin the middle\nand at the end\n", |
|
515 |
"foo\n\n\nfoo", |
|
516 |
0 |
|
517 |
}; |
|
518 |
||
519 |
int modes[] = { Qt::AlignVCenter|Qt::TextSingleLine, |
|
520 |
Qt::AlignVCenter|Qt::TextSingleLine|Qt::TextDontClip, |
|
521 |
Qt::AlignVCenter|Qt::TextWordWrap, |
|
522 |
Qt::AlignVCenter|Qt::TextWordWrap|Qt::TextDontClip, |
|
523 |
Qt::AlignLeft, |
|
524 |
Qt::AlignCenter, |
|
525 |
Qt::AlignRight, |
|
526 |
0 |
|
527 |
}; |
|
528 |
||
529 |
QFont f; |
|
530 |
for(int i = 5; i < 15; ++i) { |
|
531 |
f.setPointSize(i); |
|
532 |
QFontMetrics fm(f); |
|
533 |
const char **str = strings; |
|
534 |
while( *str ) { |
|
535 |
int *m = modes; |
|
536 |
while( *m ) { |
|
537 |
QRect br = fm.boundingRect( 0, 0, 2000, 100, *m, QString::fromUtf8( *str ) ); |
|
538 |
QVERIFY( br.width() < 800 ); |
|
539 |
||
540 |
QRect br2 = fm.boundingRect( br.x(), br.y(), br.width(), br.height(), *m, QString::fromUtf8( *str ) ); |
|
541 |
QCOMPARE( br, br2 ); |
|
542 |
#if 0 |
|
543 |
{ |
|
544 |
QPrinter printer; |
|
545 |
printer.setOutputToFile(TRUE); |
|
546 |
printer.setOutputFileName("tmp.prn"); |
|
547 |
QPainter p(&printer); |
|
548 |
QRect pbr = p.fontMetrics().boundingRect( 0, 0, 2000, 100, *m, QString::fromUtf8( *str ) ); |
|
549 |
QCOMPARE(pbr, br); |
|
550 |
} |
|
551 |
#endif |
|
552 |
#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
|
553 |
{ |
|
554 |
QPrinter printer(QPrinter::HighResolution); |
|
555 |
if (printer.printerName().isEmpty()) { |
|
556 |
QSKIP( "No printers installed, skipping bounding rect test", |
|
557 |
SkipSingle ); |
|
558 |
break; |
|
559 |
} |
|
560 |
||
561 |
printer.setOutputFileName("tmp.prn"); |
|
562 |
QPainter p(&printer); |
|
563 |
QRect pbr = p.fontMetrics().boundingRect( 0, 0, 12000, 600, *m, QString::fromUtf8( *str ) ); |
|
564 |
QVERIFY(pbr.width() > 2*br.width()); |
|
565 |
QVERIFY(pbr.height() > 2*br.height()); |
|
566 |
} |
|
567 |
#endif |
|
568 |
++m; |
|
569 |
} |
|
570 |
++str; |
|
571 |
} |
|
572 |
} |
|
573 |
} |
|
574 |
||
575 |
{ |
|
576 |
const char * strings[] = { |
|
577 |
"a", |
|
578 |
"a\nb", |
|
579 |
"a\n\nb", |
|
580 |
"abc", |
|
581 |
// "a\n \nb", |
|
582 |
"this is a longer string", |
|
583 |
// "\327\222\327\223\327\233\327\223\327\222\327\233\327\222\327\223\327\233", |
|
584 |
// "aa\327\222\327\233aa", |
|
585 |
// "\327\222\327\223\327\233\327\223\327\222\327\233\327\222\327\223\327\233", |
|
586 |
// "\327\222\327\233aa", |
|
587 |
// "linebreakatend\n", |
|
588 |
// "some text longer than 30 chars with a line break at the end\n", |
|
589 |
// "some text\nwith line breaks\nin the middle\nand at the end\n", |
|
590 |
"foo\n\n\nfoo", |
|
591 |
"a\n\n\n\n\nb", |
|
592 |
"a\n\n\n\n\n\nb", |
|
593 |
// "\347\231\273\351\214\262\346\203\205\345\240\261\343\201\214\350\246\213\343\201\244\343\201\213\343\202\211\343\201\252\343\201\204\343\201\213\347\204\241\345\212\271\343\201\252\343\201\237\343\202\201\343\200\201\nPhotoshop Album \343\202\222\350\265\267\345\213\225\343\201\247\343\201\215\343\201\276\343\201\233\343\202\223\343\200\202\345\206\215\343\202\244\343\203\263\343\202\271\343\203\210\343\203\274\343\203\253\343\201\227\343\201\246\343\201\217\343\201\240\343\201\225\343\201\204\343\200\202" |
|
594 |
// "\347\231\273\351\214\262\346\203\205\345\240\261\343\201\214\350\246\213\343\201\244\343\201\213\343\202\211\343\201\252\343\201\204\343\201\213\347\204\241\345\212\271\343\201\252\343\201\237\343\202\201\343\200\201\n\343\202\222\350\265\267\345\213\225\343\201\247\343\201\215\343\201\276\343\201\233\343\202\223\343\200\202\345\206\215\343\202\244\343\203\263\343\202\271\343\203\210\343\203\274\343\203\253\343\201\227\343\201\246\343\201\217\343\201\240\343\201\225\343\201\204\343\200\202", |
|
595 |
0 |
|
596 |
}; |
|
597 |
||
598 |
int modes[] = { Qt::AlignVCenter, |
|
599 |
Qt::AlignLeft, |
|
600 |
Qt::AlignCenter, |
|
601 |
Qt::AlignRight, |
|
602 |
0 |
|
603 |
}; |
|
604 |
||
605 |
||
606 |
QFont f; |
|
607 |
for(int i = 5; i < 15; ++i) { |
|
608 |
f.setPointSize(i); |
|
609 |
QFontMetrics fm(f); |
|
610 |
const char **str = strings; |
|
611 |
while( *str ) { |
|
612 |
int *m = modes; |
|
613 |
while( *m ) { |
|
614 |
QString s = QString::fromUtf8(*str); |
|
615 |
QRect br = fm.boundingRect(0, 0, 1000, 1000, *m, s ); |
|
616 |
int lines = |
|
617 |
s.count("\n"); |
|
618 |
int expectedHeight = fm.height()+lines*fm.lineSpacing(); |
|
619 |
QCOMPARE(br.height(), expectedHeight); |
|
620 |
++m; |
|
621 |
} |
|
622 |
++str; |
|
623 |
} |
|
624 |
QRect br = fm.boundingRect(0, 0, 100, 0, Qt::TextWordWrap, |
|
625 |
"A paragraph with gggggggggggggggggggggggggggggggggggg in the middle."); |
|
626 |
QVERIFY(br.height() >= fm.height()+2*fm.lineSpacing()); |
|
627 |
} |
|
628 |
} |
|
629 |
} |
|
630 |
||
631 |
||
632 |
static const char* const maskSource_data[] = { |
|
633 |
"16 13 6 1", |
|
634 |
". c None", |
|
635 |
"d c #000000", |
|
636 |
"# c #999999", |
|
637 |
"c c #cccccc", |
|
638 |
"b c #ffff00", |
|
639 |
"a c #ffffff", |
|
640 |
"...#####........", |
|
641 |
"..#aaaaa#.......", |
|
642 |
".#abcbcba######.", |
|
643 |
".#acbcbcaaaaaa#d", |
|
644 |
".#abcbcbcbcbcb#d", |
|
645 |
"#############b#d", |
|
646 |
"#aaaaaaaaaa##c#d", |
|
647 |
"#abcbcbcbcbbd##d", |
|
648 |
".#abcbcbcbcbcd#d", |
|
649 |
".#acbcbcbcbcbd#d", |
|
650 |
"..#acbcbcbcbb#dd", |
|
651 |
"..#############d", |
|
652 |
"...ddddddddddddd"}; |
|
653 |
||
654 |
static const char* const maskResult_data[] = { |
|
655 |
"16 13 6 1", |
|
656 |
". c #ff0000", |
|
657 |
"d c #000000", |
|
658 |
"# c #999999", |
|
659 |
"c c #cccccc", |
|
660 |
"b c #ffff00", |
|
661 |
"a c #ffffff", |
|
662 |
"...#####........", |
|
663 |
"..#aaaaa#.......", |
|
664 |
".#abcbcba######.", |
|
665 |
".#acbcbcaaaaaa#d", |
|
666 |
".#abcbcbcbcbcb#d", |
|
667 |
"#############b#d", |
|
668 |
"#aaaaaaaaaa##c#d", |
|
669 |
"#abcbcbcbcbbd##d", |
|
670 |
".#abcbcbcbcbcd#d", |
|
671 |
".#acbcbcbcbcbd#d", |
|
672 |
"..#acbcbcbcbb#dd", |
|
673 |
"..#############d", |
|
674 |
"...ddddddddddddd"}; |
|
675 |
||
676 |
||
677 |
void tst_QPainter::drawPixmap_comp_data() |
|
678 |
{ |
|
679 |
if (qApp->desktop()->depth() < 24) { |
|
680 |
QSKIP("Test only works on 32 bit displays", SkipAll); |
|
681 |
return; |
|
682 |
} |
|
683 |
||
684 |
QTest::addColumn<uint>("dest"); |
|
685 |
QTest::addColumn<uint>("source"); |
|
686 |
||
687 |
QTest::newRow("0% on 0%, 1") << 0x00000000u<< 0x00000000u; |
|
688 |
QTest::newRow("0% on 0%, 2") << 0x00007fffu << 0x00ff007fu; |
|
689 |
||
690 |
QTest::newRow("50% on a=0%") << 0x00000000u << 0x7fff0000u; |
|
691 |
QTest::newRow("50% on a=50%") << 0x7f000000u << 0x7fff0000u; |
|
692 |
QTest::newRow("50% on deadbeef") << 0xdeafbeefu << 0x7fff0000u; |
|
693 |
QTest::newRow("deadbeef on a=0%") << 0x00000000u << 0xdeadbeefu; |
|
694 |
QTest::newRow("deadbeef on a=50%") << 0x7f000000u << 0xdeadbeefu; |
|
695 |
QTest::newRow("50% blue on 50% red") << 0x7fff0000u << 0x7f0000ffu; |
|
696 |
QTest::newRow("50% blue on 50% green") << 0x7f00ff00u << 0x7f0000ffu; |
|
697 |
QTest::newRow("50% red on 50% green") << 0x7f00ff00u << 0x7fff0000u; |
|
698 |
QTest::newRow("0% on 50%") << 0x7fff00ffu << 0x00ffffffu; |
|
699 |
QTest::newRow("100% on deadbeef") << 0xdeafbeefu << 0xffabcdefu; |
|
700 |
QTest::newRow("100% on a=0%") << 0x00000000u << 0xffabcdefu; |
|
701 |
} |
|
702 |
||
703 |
QRgb qt_compose_alpha(QRgb source, QRgb dest) |
|
704 |
{ |
|
705 |
int r1 = qRed(dest), g1 = qGreen(dest), b1 = qBlue(dest), a1 = qAlpha(dest); |
|
706 |
int r2 = qRed(source), g2 = qGreen(source), b2 = qBlue(source), a2 = qAlpha(source); |
|
707 |
||
708 |
int alpha = qMin(a2 + ((255 - a2) * a1 + 127) / 255, 255); |
|
709 |
if (alpha == 0) |
|
710 |
return qRgba(0, 0, 0, 0); |
|
711 |
||
712 |
return qRgba( |
|
713 |
qMin((r2 * a2 + (255 - a2) * r1 * a1 / 255) / alpha, 255), |
|
714 |
qMin((g2 * a2 + (255 - a2) * g1 * a1 / 255) / alpha, 255), |
|
715 |
qMin((b2 * a2 + (255 - a2) * b1 * a1 / 255) / alpha, 255), |
|
716 |
alpha); |
|
717 |
} |
|
718 |
||
719 |
/* Tests that drawing masked pixmaps works |
|
720 |
*/ |
|
721 |
void tst_QPainter::drawPixmap_comp() |
|
722 |
{ |
|
723 |
#ifdef Q_WS_MAC |
|
724 |
QSKIP("Mac has other ideas about alpha composition", SkipAll); |
|
725 |
#endif |
|
726 |
||
727 |
QFETCH(uint, dest); |
|
728 |
QFETCH(uint, source); |
|
729 |
||
730 |
QRgb expected = qt_compose_alpha(source, dest); |
|
731 |
||
732 |
QColor c1(qRed(dest), qGreen(dest), qBlue(dest), qAlpha(dest)); |
|
733 |
QColor c2(qRed(source), qGreen(source), qBlue(source), qAlpha(source)); |
|
734 |
||
735 |
QPixmap destPm(10, 10), srcPm(10, 10); |
|
736 |
destPm.fill(c1); |
|
737 |
srcPm.fill(c2); |
|
738 |
||
739 |
#if defined(Q_WS_X11) |
|
740 |
if (!destPm.x11PictureHandle()) |
|
741 |
QSKIP("Requires XRender support", SkipAll); |
|
742 |
#endif |
|
743 |
||
744 |
QPainter p(&destPm); |
|
745 |
p.drawPixmap(0, 0, srcPm); |
|
746 |
p.end(); |
|
747 |
||
748 |
QImage result = destPm.toImage().convertToFormat(QImage::Format_ARGB32); |
|
749 |
bool different = false; |
|
750 |
for (int y=0; y<result.height(); ++y) |
|
751 |
for (int x=0; x<result.width(); ++x) { |
|
752 |
bool diff; |
|
753 |
if (qAlpha(expected) == 0) { |
|
754 |
diff = qAlpha(result.pixel(x, y)) != 0; |
|
755 |
} else { |
|
756 |
// Compensate for possible roundoff / platform fudge |
|
757 |
int off = 1; |
|
758 |
QRgb pix = result.pixel(x, y); |
|
759 |
diff = (qAbs(qRed(pix) - qRed(expected)) > off) |
|
760 |
|| (qAbs(qGreen(pix) - qGreen(expected)) > off) |
|
761 |
|| (qAbs(qBlue(pix) - qBlue(expected)) > off) |
|
762 |
|| (qAbs(qAlpha(pix) - qAlpha(expected)) > off); |
|
763 |
} |
|
764 |
if (diff && !different) |
|
765 |
qDebug( "Different at %d,%d pixel [%d,%d,%d,%d] expected [%d,%d,%d,%d]", x, y, |
|
766 |
qRed(result.pixel(x, y)), qGreen(result.pixel(x, y)), |
|
767 |
qBlue(result.pixel(x, y)), qAlpha(result.pixel(x, y)), |
|
768 |
qRed(expected), qGreen(expected), qBlue(expected), qAlpha(expected)); |
|
769 |
different |= diff; |
|
770 |
} |
|
771 |
||
772 |
QVERIFY(!different); |
|
773 |
} |
|
774 |
||
775 |
void tst_QPainter::saveAndRestore_data() |
|
776 |
{ |
|
777 |
QVERIFY(1); |
|
778 |
||
779 |
QTest::addColumn<QFont>("font"); |
|
780 |
QTest::addColumn<QPen>("pen"); |
|
781 |
QTest::addColumn<QBrush>("brush"); |
|
782 |
QTest::addColumn<QColor>("backgroundColor"); |
|
783 |
QTest::addColumn<int>("backgroundMode"); |
|
784 |
QTest::addColumn<QPoint>("brushOrigin"); |
|
785 |
QTest::addColumn<QRegion>("clipRegion"); |
|
786 |
QTest::addColumn<QRect>("window"); |
|
787 |
QTest::addColumn<QRect>("viewport"); |
|
788 |
||
789 |
QPixmap pixmap(1, 1); |
|
790 |
QPainter p(&pixmap); |
|
791 |
QFont font = p.font(); |
|
792 |
QPen pen = p.pen(); |
|
793 |
QBrush brush = p.brush(); |
|
794 |
QColor backgroundColor = p.background().color(); |
|
795 |
Qt::BGMode backgroundMode = p.backgroundMode(); |
|
796 |
QPoint brushOrigin = p.brushOrigin(); |
|
797 |
QRegion clipRegion = p.clipRegion(); |
|
798 |
QRect window = p.window(); |
|
799 |
QRect viewport = p.viewport(); |
|
800 |
||
801 |
QTest::newRow("Original") << font << pen << brush << backgroundColor << int(backgroundMode) |
|
802 |
<< brushOrigin << clipRegion << window << viewport; |
|
803 |
||
804 |
QFont font2 = font; |
|
805 |
font2.setPointSize( 24 ); |
|
806 |
QTest::newRow("Modified font.pointSize, brush, backgroundColor, backgroundMode") |
|
807 |
<< font2 << pen << QBrush(Qt::red) << QColor(Qt::blue) << int(Qt::TransparentMode) |
|
808 |
<< brushOrigin << clipRegion << window << viewport; |
|
809 |
||
810 |
font2 = font; |
|
811 |
font2.setPixelSize( 20 ); |
|
812 |
QTest::newRow("Modified font.pixelSize, brushOrigin, pos") |
|
813 |
<< font2 << pen << brush << backgroundColor << int(backgroundMode) |
|
814 |
<< QPoint( 50, 32 ) << clipRegion << window << viewport; |
|
815 |
||
816 |
QTest::newRow("Modified clipRegion, window, viewport") |
|
817 |
<< font << pen << brush << backgroundColor << int(backgroundMode) |
|
818 |
<< brushOrigin << clipRegion.subtracted(QRect(10,10,50,30)) |
|
819 |
<< QRect(-500, -500, 500, 500 ) << QRect( 0, 0, 50, 50 ); |
|
820 |
} |
|
821 |
||
822 |
void tst_QPainter::saveAndRestore() |
|
823 |
{ |
|
824 |
QFETCH( QFont, font ); |
|
825 |
QFETCH( QPen, pen ); |
|
826 |
QFETCH( QBrush, brush ); |
|
827 |
QFETCH( QColor, backgroundColor ); |
|
828 |
QFETCH( int, backgroundMode ); |
|
829 |
QFETCH( QPoint, brushOrigin ); |
|
830 |
QFETCH( QRegion, clipRegion ); |
|
831 |
QFETCH( QRect, window ); |
|
832 |
QFETCH( QRect, viewport ); |
|
833 |
||
834 |
QPixmap pixmap(1, 1); |
|
835 |
QPainter painter(&pixmap); |
|
836 |
||
837 |
QFont font_org = painter.font(); |
|
838 |
QPen pen_org = painter.pen(); |
|
839 |
QBrush brush_org = painter.brush(); |
|
840 |
QColor backgroundColor_org = painter.background().color(); |
|
841 |
Qt::BGMode backgroundMode_org = painter.backgroundMode(); |
|
842 |
QPoint brushOrigin_org = painter.brushOrigin(); |
|
843 |
QRegion clipRegion_org = painter.clipRegion(); |
|
844 |
QRect window_org = painter.window(); |
|
845 |
QRect viewport_org = painter.viewport(); |
|
846 |
||
847 |
painter.save(); |
|
848 |
painter.setFont( font ); |
|
849 |
painter.setPen( QPen(pen) ); |
|
850 |
painter.setBrush( brush ); |
|
851 |
painter.setBackground( backgroundColor ); |
|
852 |
painter.setBackgroundMode( (Qt::BGMode)backgroundMode ); |
|
853 |
painter.setBrushOrigin( brushOrigin ); |
|
854 |
painter.setClipRegion( clipRegion ); |
|
855 |
painter.setWindow( window ); |
|
856 |
painter.setViewport( viewport ); |
|
857 |
painter.restore(); |
|
858 |
||
859 |
QCOMPARE( painter.font(), font_org ); |
|
860 |
QCOMPARE( painter.font().pointSize(), font_org.pointSize() ); |
|
861 |
QCOMPARE( painter.font().pixelSize(), font_org.pixelSize() ); |
|
862 |
QCOMPARE( painter.pen(), pen_org ); |
|
863 |
QCOMPARE( painter.brush(), brush_org ); |
|
864 |
QCOMPARE( painter.background().color(), backgroundColor_org ); |
|
865 |
QCOMPARE( painter.backgroundMode(), backgroundMode_org ); |
|
866 |
QCOMPARE( painter.brushOrigin(), brushOrigin_org ); |
|
867 |
QCOMPARE( painter.clipRegion(), clipRegion_org ); |
|
868 |
QCOMPARE( painter.window(), window_org ); |
|
869 |
QCOMPARE( painter.viewport(), viewport_org ); |
|
870 |
} |
|
871 |
||
872 |
/* |
|
873 |
Helper functions |
|
874 |
*/ |
|
875 |
||
876 |
QColor tst_QPainter::baseColor( int k, int intensity ) |
|
877 |
{ |
|
878 |
int r = ( k & 1 ) * intensity; |
|
879 |
int g = ( (k>>1) & 1 ) * intensity; |
|
880 |
int b = ( (k>>2) & 1 ) * intensity; |
|
881 |
return QColor( r, g, b ); |
|
882 |
} |
|
883 |
||
884 |
QImage tst_QPainter::getResImage( const QString &dir, const QString &addition, const QString &extension ) |
|
885 |
{ |
|
886 |
QImage res; |
|
887 |
QString resFilename = dir + QString( "/res_%1." ).arg( addition ) + extension; |
|
888 |
if ( !res.load( resFilename ) ) { |
|
889 |
QWARN(QString("Could not load result data %s %1").arg(resFilename).toLatin1()); |
|
890 |
return QImage(); |
|
891 |
} |
|
892 |
return res; |
|
893 |
} |
|
894 |
||
895 |
QBitmap tst_QPainter::getBitmap( const QString &dir, const QString &filename, bool mask ) |
|
896 |
{ |
|
897 |
QBitmap bm; |
|
898 |
QString bmFilename = dir + QString( "/%1.xbm" ).arg( filename ); |
|
899 |
if ( !bm.load( bmFilename ) ) { |
|
900 |
QWARN(QString("Could not load bitmap '%1'").arg(bmFilename).toLatin1()); |
|
901 |
return QBitmap(); |
|
902 |
} |
|
903 |
if ( mask ) { |
|
904 |
QBitmap mask; |
|
905 |
QString maskFilename = dir + QString( "/%1-mask.xbm" ).arg( filename ); |
|
906 |
if ( !mask.load( maskFilename ) ) { |
|
907 |
QWARN(QString("Could not load mask '%1'").arg(maskFilename).toLatin1()); |
|
908 |
return QBitmap(); |
|
909 |
} |
|
910 |
bm.setMask( mask ); |
|
911 |
} |
|
912 |
return bm; |
|
913 |
} |
|
914 |
||
915 |
static int getPaintedPixels(const QImage &image, const QColor &background) |
|
916 |
{ |
|
917 |
uint color = background.rgba(); |
|
918 |
||
919 |
int pixels = 0; |
|
920 |
||
921 |
for (int y = 0; y < image.height(); ++y) |
|
922 |
for (int x = 0; x < image.width(); ++x) |
|
923 |
if (image.pixel(x, y) != color) |
|
924 |
++pixels; |
|
925 |
||
926 |
return pixels; |
|
927 |
} |
|
928 |
||
929 |
static QRect getPaintedSize(const QImage &image, const QColor &background) |
|
930 |
{ |
|
931 |
// not the fastest but at least it works.. |
|
932 |
int xmin = image.width() + 1; |
|
933 |
int xmax = -1; |
|
934 |
int ymin = image.height() +1; |
|
935 |
int ymax = -1; |
|
936 |
||
937 |
uint color = background.rgba(); |
|
938 |
||
939 |
for ( int y = 0; y < image.height(); ++y ) { |
|
940 |
for ( int x = 0; x < image.width(); ++x ) { |
|
941 |
QRgb pixel = image.pixel( x, y ); |
|
942 |
if ( pixel != color && x < xmin ) |
|
943 |
xmin = x; |
|
944 |
if ( pixel != color && x > xmax ) |
|
945 |
xmax = x; |
|
946 |
if ( pixel != color && y < ymin ) |
|
947 |
ymin = y; |
|
948 |
if ( pixel != color && y > ymax ) |
|
949 |
ymax = y; |
|
950 |
} |
|
951 |
} |
|
952 |
||
953 |
return QRect(xmin, ymin, xmax - xmin + 1, ymax - ymin + 1); |
|
954 |
} |
|
955 |
||
956 |
static QRect getPaintedSize(const QPixmap &pm, const QColor &background) |
|
957 |
{ |
|
958 |
return getPaintedSize(pm.toImage(), background); |
|
959 |
} |
|
960 |
||
961 |
void tst_QPainter::initFrom() |
|
962 |
{ |
|
963 |
QWidget *widget = new QWidget(); |
|
964 |
QPalette pal = widget->palette(); |
|
965 |
pal.setColor(QPalette::Foreground, QColor(255, 0, 0)); |
|
966 |
pal.setBrush(QPalette::Background, QColor(0, 255, 0)); |
|
967 |
widget->setPalette(pal); |
|
968 |
||
969 |
QFont font = widget->font(); |
|
970 |
font.setPointSize(26); |
|
971 |
font.setItalic(true); |
|
972 |
widget->setFont(font); |
|
973 |
||
974 |
QPixmap pm(100, 100); |
|
975 |
QPainter p(&pm); |
|
976 |
p.initFrom(widget); |
|
977 |
||
978 |
QCOMPARE(p.font(), font); |
|
979 |
QCOMPARE(p.pen().color(), pal.color(QPalette::Foreground)); |
|
980 |
QCOMPARE(p.background(), pal.background()); |
|
981 |
||
982 |
delete widget; |
|
983 |
} |
|
984 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
985 |
void tst_QPainter::drawBorderPixmap() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
986 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
987 |
QPixmap src(79,79); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
988 |
src.fill(Qt::transparent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
989 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
990 |
QImage pm(200,200,QImage::Format_RGB32); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
991 |
QPainter p(&pm); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
992 |
p.setTransform(QTransform(-1,0,0,-1,173.5,153.5)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
993 |
qDrawBorderPixmap(&p, QRect(0,0,75,105), QMargins(39,39,39,39), src, QRect(0,0,79,79), QMargins(39,39,39,39), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
994 |
QTileRules(Qt::StretchTile,Qt::StretchTile), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
995 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
996 |
|
0 | 997 |
void tst_QPainter::drawLine_data() |
998 |
{ |
|
999 |
QTest::addColumn<QLine>("line"); |
|
1000 |
||
1001 |
QTest::newRow("0-45") << QLine(0, 20, 100, 0); |
|
1002 |
QTest::newRow("45-90") << QLine(0, 100, 20, 0); |
|
1003 |
QTest::newRow("90-135") << QLine(20, 100, 0, 0); |
|
1004 |
QTest::newRow("135-180") << QLine(100, 20, 0, 0); |
|
1005 |
QTest::newRow("180-225") << QLine(100, 0, 0, 20); |
|
1006 |
QTest::newRow("225-270") << QLine(20, 0, 0, 100); |
|
1007 |
QTest::newRow("270-315") << QLine(0, 0, 20, 100); |
|
1008 |
QTest::newRow("315-360") << QLine(0, 0, 100, 20); |
|
1009 |
} |
|
1010 |
||
1011 |
void tst_QPainter::drawLine() |
|
1012 |
{ |
|
1013 |
const int offset = 5; |
|
1014 |
const int epsilon = 1; // allow for one pixel difference |
|
1015 |
||
1016 |
QFETCH(QLine, line); |
|
1017 |
||
1018 |
QPixmap pixmapUnclipped(qMin(line.x1(), line.x2()) |
|
1019 |
+ 2*offset + qAbs(line.dx()), |
|
1020 |
qMin(line.y1(), line.y2()) |
|
1021 |
+ 2*offset + qAbs(line.dy())); |
|
1022 |
||
1023 |
{ // unclipped |
|
1024 |
pixmapUnclipped.fill(Qt::white); |
|
1025 |
QPainter p(&pixmapUnclipped); |
|
1026 |
p.translate(offset, offset); |
|
1027 |
p.setPen(QPen(Qt::black)); |
|
1028 |
p.drawLine(line); |
|
1029 |
p.end(); |
|
1030 |
||
1031 |
const QRect painted = getPaintedSize(pixmapUnclipped, Qt::white); |
|
1032 |
||
1033 |
QLine l = line; |
|
1034 |
l.translate(offset, offset); |
|
1035 |
QVERIFY(qAbs(painted.width() - qAbs(l.dx())) <= epsilon); |
|
1036 |
QVERIFY(qAbs(painted.height() - qAbs(l.dy())) <= epsilon); |
|
1037 |
QVERIFY(qAbs(painted.top() - qMin(l.y1(), l.y2())) <= epsilon); |
|
1038 |
QVERIFY(qAbs(painted.left() - qMin(l.x1(), l.x2())) <= epsilon); |
|
1039 |
QVERIFY(qAbs(painted.bottom() - qMax(l.y1(), l.y2())) <= epsilon); |
|
1040 |
QVERIFY(qAbs(painted.right() - qMax(l.x1(), l.x2())) <= epsilon); |
|
1041 |
} |
|
1042 |
||
1043 |
QPixmap pixmapClipped(qMin(line.x1(), line.x2()) |
|
1044 |
+ 2*offset + qAbs(line.dx()), |
|
1045 |
qMin(line.y1(), line.y2()) |
|
1046 |
+ 2*offset + qAbs(line.dy())); |
|
1047 |
{ // clipped |
|
1048 |
const QRect clip = QRect(line.p1(), line.p2()).normalized(); |
|
1049 |
||
1050 |
pixmapClipped.fill(Qt::white); |
|
1051 |
QPainter p(&pixmapClipped); |
|
1052 |
p.translate(offset, offset); |
|
1053 |
p.setClipRect(clip); |
|
1054 |
p.setPen(QPen(Qt::black)); |
|
1055 |
p.drawLine(line); |
|
1056 |
p.end(); |
|
1057 |
} |
|
1058 |
||
1059 |
const QImage unclipped = pixmapUnclipped.toImage(); |
|
1060 |
const QImage clipped = pixmapClipped.toImage(); |
|
1061 |
QCOMPARE(unclipped, clipped); |
|
1062 |
} |
|
1063 |
||
1064 |
void tst_QPainter::drawLine_clipped() |
|
1065 |
{ |
|
1066 |
QImage image(16, 1, QImage::Format_ARGB32_Premultiplied); |
|
1067 |
image.fill(0x0); |
|
1068 |
||
1069 |
QPainter p(&image); |
|
1070 |
p.setPen(QPen(Qt::black, 10)); |
|
1071 |
||
1072 |
// this should fill the whole image |
|
1073 |
p.drawLine(-1, -1, 17, 1); |
|
1074 |
p.end(); |
|
1075 |
||
1076 |
for (int x = 0; x < 16; ++x) |
|
1077 |
QCOMPARE(image.pixel(x, 0), 0xff000000); |
|
1078 |
} |
|
1079 |
||
1080 |
void tst_QPainter::drawLine_task121143() |
|
1081 |
{ |
|
1082 |
QPen pen(Qt::black); |
|
1083 |
||
1084 |
QImage image(5, 5, QImage::Format_ARGB32_Premultiplied); |
|
1085 |
image.fill(0xffffffff); |
|
1086 |
QPainter p(&image); |
|
1087 |
p.setPen(pen); |
|
1088 |
p.drawLine(QLine(0, 0+4, 0+4, 0)); |
|
1089 |
p.end(); |
|
1090 |
||
1091 |
QImage expected(5, 5, QImage::Format_ARGB32_Premultiplied); |
|
1092 |
expected.fill(0xffffffff); |
|
1093 |
for (int x = 0; x < 5; ++x) |
|
1094 |
expected.setPixel(x, 5-x-1, pen.color().rgb()); |
|
1095 |
||
1096 |
QCOMPARE(image, expected); |
|
1097 |
} |
|
1098 |
||
1099 |
void tst_QPainter::drawLine_task190634() |
|
1100 |
{ |
|
1101 |
QPen pen(Qt::black, 3); |
|
1102 |
||
1103 |
QImage image(32, 32, QImage::Format_ARGB32_Premultiplied); |
|
1104 |
QPainter p(&image); |
|
1105 |
p.fillRect(0, 0, image.width(), image.height(), Qt::white); |
|
1106 |
||
1107 |
p.setPen(pen); |
|
1108 |
p.drawLine(QLineF(2, -1.6, 10, -1.6)); |
|
1109 |
p.end(); |
|
1110 |
||
1111 |
const uint *data = reinterpret_cast<uint *>(image.bits()); |
|
1112 |
||
1113 |
for (int i = 0; i < image.width() * image.height(); ++i) |
|
1114 |
QCOMPARE(data[i], 0xffffffff); |
|
1115 |
||
1116 |
p.begin(&image); |
|
1117 |
p.fillRect(0, 0, image.width(), image.height(), Qt::white); |
|
1118 |
||
1119 |
p.setPen(pen); |
|
1120 |
p.drawLine(QLineF(-1.6, 2, -1.6, 10)); |
|
1121 |
p.end(); |
|
1122 |
||
1123 |
data = reinterpret_cast<uint *>(image.bits()); |
|
1124 |
||
1125 |
for (int i = 0; i < image.width() * image.height(); ++i) |
|
1126 |
QCOMPARE(data[i], 0xffffffff); |
|
1127 |
||
1128 |
p.begin(&image); |
|
1129 |
p.fillRect(0, 0, image.width(), image.height(), Qt::white); |
|
1130 |
||
1131 |
p.setPen(pen); |
|
1132 |
p.drawLine( QPoint(2,-2), QPoint(3,-5) ); |
|
1133 |
p.end(); |
|
1134 |
||
1135 |
data = reinterpret_cast<uint *>(image.bits()); |
|
1136 |
||
1137 |
for (int i = 0; i < image.width() * image.height(); ++i) |
|
1138 |
QCOMPARE(data[i], 0xffffffff); |
|
1139 |
} |
|
1140 |
||
1141 |
void tst_QPainter::drawLine_task229459() |
|
1142 |
{ |
|
1143 |
QImage image(32, 32, QImage::Format_ARGB32_Premultiplied); |
|
1144 |
image.fill(0x0); |
|
1145 |
QPen pen(Qt::black, 64); |
|
1146 |
||
1147 |
QPainter p(&image); |
|
1148 |
p.setPen(pen); |
|
1149 |
p.drawLine(-8, -8, 10000000, 10000000); |
|
1150 |
p.end(); |
|
1151 |
||
1152 |
QImage expected = image; |
|
1153 |
expected.fill(0xff000000); |
|
1154 |
||
1155 |
QCOMPARE(image, expected); |
|
1156 |
} |
|
1157 |
||
1158 |
void tst_QPainter::drawLine_task234891() |
|
1159 |
{ |
|
1160 |
QImage img(100, 1000, QImage::Format_ARGB32_Premultiplied); |
|
1161 |
img.fill(0x0); |
|
1162 |
QImage expected = img; |
|
1163 |
||
1164 |
QPainter p(&img); |
|
1165 |
p.setPen(QPen(QBrush(QColor(255,0,0)), 6)); |
|
1166 |
p.drawLine(QPointF(25000,100),QPointF(30000,105)); |
|
1167 |
||
1168 |
p.setPen(QPen(QBrush(QColor(0,255,0)), 6)); |
|
1169 |
p.drawLine(QPointF(30000,150),QPointF(35000,155)); |
|
1170 |
||
1171 |
p.setPen(QPen(QBrush(QColor(0,0,255)), 6)); |
|
1172 |
p.drawLine(QPointF(65000,200),QPointF(66000,205)); |
|
1173 |
||
1174 |
QCOMPARE(expected, img); |
|
1175 |
} |
|
1176 |
||
1177 |
void tst_QPainter::drawLine_task216948() |
|
1178 |
{ |
|
1179 |
QImage img(1, 10, QImage::Format_ARGB32_Premultiplied); |
|
1180 |
img.fill(0x0); |
|
1181 |
||
1182 |
QPainter p(&img); |
|
1183 |
QLine line(10, 0, 10, 10); |
|
1184 |
p.translate(-10, 0); |
|
1185 |
p.drawLine(line); |
|
1186 |
p.end(); |
|
1187 |
||
1188 |
for (int i = 0; i < img.height(); ++i) |
|
1189 |
QCOMPARE(img.pixel(0, i), QColor(Qt::black).rgba()); |
|
1190 |
} |
|
1191 |
||
1192 |
void tst_QPainter::drawRect() |
|
1193 |
{ |
|
1194 |
QFETCH(QRect, rect); |
|
1195 |
QFETCH(bool, usePen); |
|
1196 |
||
1197 |
QPixmap pixmap(rect.x() + rect.width() + 10, |
|
1198 |
rect.y() + rect.height() + 10); |
|
1199 |
{ |
|
1200 |
pixmap.fill(Qt::white); |
|
1201 |
QPainter p(&pixmap); |
|
1202 |
p.setPen(usePen ? QPen(Qt::black) : QPen(Qt::NoPen)); |
|
1203 |
p.setBrush(Qt::black); |
|
1204 |
p.drawRect(rect); |
|
1205 |
p.end(); |
|
1206 |
||
1207 |
int increment = usePen ? 1 : 0; |
|
1208 |
||
1209 |
const QRect painted = getPaintedSize(pixmap, Qt::white); |
|
1210 |
QCOMPARE(painted.width(), rect.width() + increment); |
|
1211 |
QCOMPARE(painted.height(), rect.height() + increment); |
|
1212 |
} |
|
1213 |
||
1214 |
#ifdef QT3_SUPPORT |
|
1215 |
{ |
|
1216 |
if (usePen && (rect.width() < 2 || rect.height() < 2)) |
|
1217 |
return; |
|
1218 |
pixmap.fill(Qt::white); |
|
1219 |
Q3Painter p(&pixmap); |
|
1220 |
p.setPen(usePen ? QPen(Qt::black) : QPen(Qt::NoPen)); |
|
1221 |
p.setBrush(Qt::black); |
|
1222 |
p.drawRect(rect); |
|
1223 |
p.end(); |
|
1224 |
||
1225 |
const QRect painted = getPaintedSize(pixmap, Qt::white); |
|
1226 |
||
1227 |
QCOMPARE(painted.width(), rect.width()); |
|
1228 |
QCOMPARE(painted.height(), rect.height()); |
|
1229 |
} |
|
1230 |
#endif |
|
1231 |
} |
|
1232 |
||
1233 |
void tst_QPainter::drawRect2() |
|
1234 |
{ |
|
1235 |
QImage image(64, 64, QImage::Format_ARGB32_Premultiplied); |
|
1236 |
{ |
|
1237 |
image.fill(0xffffffff); |
|
1238 |
||
1239 |
QTransform transform(0.368567, 0, 0, 0, 0.368567, 0, 0.0289, 0.0289, 1); |
|
1240 |
||
1241 |
QPainter p(&image); |
|
1242 |
p.setTransform(transform); |
|
1243 |
p.setBrush(Qt::red); |
|
1244 |
p.setPen(Qt::NoPen); |
|
1245 |
p.drawRect(QRect(14, 14, 39, 39)); |
|
1246 |
p.end(); |
|
1247 |
||
1248 |
QRect fill = getPaintedSize(image, Qt::white); |
|
1249 |
image.fill(0xffffffff); |
|
1250 |
||
1251 |
p.begin(&image); |
|
1252 |
p.setTransform(transform); |
|
1253 |
p.drawRect(QRect(14, 14, 39, 39)); |
|
1254 |
p.end(); |
|
1255 |
||
1256 |
QRect stroke = getPaintedSize(image, Qt::white); |
|
1257 |
QCOMPARE(stroke.adjusted(1, 1, 0, 0), fill.adjusted(0, 0, 1, 1)); |
|
1258 |
} |
|
1259 |
} |
|
1260 |
||
1261 |
void tst_QPainter::fillRect() |
|
1262 |
{ |
|
1263 |
QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); |
|
1264 |
image.fill(QColor(0, 0, 0, 0).rgba()); |
|
1265 |
||
1266 |
QPainter p(&image); |
|
1267 |
||
1268 |
p.fillRect(0, 0, 100, 100, QColor(255, 0, 0, 127)); |
|
1269 |
||
1270 |
// pixmap.save("bla1.png", "PNG"); |
|
1271 |
QCOMPARE(getPaintedSize(image, QColor(0, 0, 0, 0)), |
|
1272 |
QRect(0, 0, 100, 100)); |
|
1273 |
QCOMPARE(getPaintedSize(image, QColor(127, 0, 0, 127)).isValid(), |
|
1274 |
QRect().isValid()); |
|
1275 |
||
1276 |
p.setCompositionMode(QPainter::CompositionMode_SourceIn); |
|
1277 |
p.fillRect(50, 0, 50, 100, QColor(0, 0, 255, 255)); |
|
1278 |
||
1279 |
QCOMPARE(getPaintedSize(image, QColor(127, 0, 0, 127)), |
|
1280 |
QRect(50, 0, 50, 100)); |
|
1281 |
QCOMPARE(getPaintedSize(image, QColor(0, 0, 127, 127)), |
|
1282 |
QRect(0, 0, 50, 100)); |
|
1283 |
} |
|
1284 |
||
1285 |
void tst_QPainter::fillRect2() |
|
1286 |
{ |
|
1287 |
QRgb background = 0x0; |
|
1288 |
||
1289 |
QImage img(1, 20, QImage::Format_ARGB32_Premultiplied); |
|
1290 |
img.fill(background); |
|
1291 |
||
1292 |
QPainter p(&img); |
|
1293 |
||
1294 |
QRectF rect(0, 1, 1.2, 18); |
|
1295 |
p.fillRect(rect, Qt::black); |
|
1296 |
||
1297 |
p.end(); |
|
1298 |
||
1299 |
QCOMPARE(img.pixel(0, 0), background); |
|
1300 |
QCOMPARE(img.pixel(0, img.height() - 1), background); |
|
1301 |
||
1302 |
QCOMPARE(img.pixel(0, 1), img.pixel(0, 2)); |
|
1303 |
QCOMPARE(img.pixel(0, img.height() - 2), img.pixel(0, img.height() - 3)); |
|
1304 |
} |
|
1305 |
||
1306 |
void tst_QPainter::fillRect3() |
|
1307 |
{ |
|
1308 |
QImage img(1, 1, QImage::Format_ARGB32_Premultiplied); |
|
1309 |
img.fill(QColor(Qt::black).rgba()); |
|
1310 |
||
1311 |
QPainter p(&img); |
|
1312 |
p.setCompositionMode(QPainter::CompositionMode_Source); |
|
1313 |
p.fillRect(img.rect(), Qt::transparent); |
|
1314 |
p.end(); |
|
1315 |
||
1316 |
QCOMPARE(img.pixel(0, 0), 0U); |
|
1317 |
} |
|
1318 |
||
1319 |
void tst_QPainter::fillRect4() |
|
1320 |
{ |
|
1321 |
QImage image(100, 1, QImage::Format_ARGB32_Premultiplied); |
|
1322 |
image.fill(0x0); |
|
1323 |
||
1324 |
QImage expected = image; |
|
1325 |
expected.fill(0xffffffff); |
|
1326 |
||
1327 |
QPainter p(&image); |
|
1328 |
p.scale(1.1, 1); |
|
1329 |
p.setPen(Qt::NoPen); |
|
1330 |
||
1331 |
for (int i = 0; i < 33; ++i) |
|
1332 |
p.fillRect(QRectF(3 * i, 0, 3, 1), Qt::white); |
|
1333 |
||
1334 |
p.end(); |
|
1335 |
||
1336 |
QCOMPARE(image, expected); |
|
1337 |
} |
|
1338 |
||
1339 |
void tst_QPainter::drawPath_data() |
|
1340 |
{ |
|
1341 |
QTest::addColumn<QPainterPath>("path"); |
|
1342 |
QTest::addColumn<QRect>("expectedBounds"); |
|
1343 |
QTest::addColumn<int>("expectedPixels"); |
|
1344 |
||
1345 |
{ |
|
1346 |
QPainterPath p; |
|
1347 |
p.addRect(2, 2, 10, 10); |
|
1348 |
QTest::newRow("int-aligned rect") << p << QRect(2, 2, 10, 10) << 10 * 10; |
|
1349 |
} |
|
1350 |
||
1351 |
{ |
|
1352 |
QPainterPath p; |
|
1353 |
p.addRect(2.25, 2.25, 10, 10); |
|
1354 |
QTest::newRow("non-aligned rect") << p << QRect(3, 3, 10, 10) << 10 * 10; |
|
1355 |
} |
|
1356 |
||
1357 |
{ |
|
1358 |
QPainterPath p; |
|
1359 |
p.addRect(2.25, 2.25, 10.5, 10.5); |
|
1360 |
QTest::newRow("non-aligned rect 2") << p << QRect(3, 3, 10, 10) << 10 * 10; |
|
1361 |
} |
|
1362 |
||
1363 |
{ |
|
1364 |
QPainterPath p; |
|
1365 |
p.addRect(2.5, 2.5, 10, 10); |
|
1366 |
QTest::newRow("non-aligned rect 3") << p << QRect(3, 3, 10, 10) << 10 * 10; |
|
1367 |
} |
|
1368 |
||
1369 |
{ |
|
1370 |
QPainterPath p; |
|
1371 |
p.addRect(2, 2, 10, 10); |
|
1372 |
p.addRect(4, 4, 6, 6); |
|
1373 |
QTest::newRow("rect-in-rect") << p << QRect(2, 2, 10, 10) << 10 * 10 - 6 * 6; |
|
1374 |
} |
|
1375 |
||
1376 |
{ |
|
1377 |
QPainterPath p; |
|
1378 |
p.addRect(2, 2, 10, 10); |
|
1379 |
p.addRect(4, 4, 6, 6); |
|
1380 |
p.addRect(6, 6, 2, 2); |
|
1381 |
QTest::newRow("rect-in-rect-in-rect") << p << QRect(2, 2, 10, 10) << 10 * 10 - 6 * 6 + 2 * 2; |
|
1382 |
} |
|
1383 |
} |
|
1384 |
||
1385 |
void tst_QPainter::drawPath() |
|
1386 |
{ |
|
1387 |
QFETCH(QPainterPath, path); |
|
1388 |
QFETCH(QRect, expectedBounds); |
|
1389 |
QFETCH(int, expectedPixels); |
|
1390 |
||
1391 |
const int offset = 2; |
|
1392 |
||
1393 |
QImage image(expectedBounds.width() + 2 * offset, expectedBounds.height() + 2 * offset, |
|
1394 |
QImage::Format_ARGB32_Premultiplied); |
|
1395 |
image.fill(QColor(Qt::white).rgb()); |
|
1396 |
||
1397 |
QPainter p(&image); |
|
1398 |
p.setPen(Qt::NoPen); |
|
1399 |
p.setBrush(Qt::black); |
|
1400 |
p.translate(offset - expectedBounds.left(), offset - expectedBounds.top()); |
|
1401 |
p.drawPath(path); |
|
1402 |
p.end(); |
|
1403 |
||
1404 |
const QRect paintedBounds = getPaintedSize(image, Qt::white); |
|
1405 |
||
1406 |
QCOMPARE(paintedBounds.x(), offset); |
|
1407 |
QCOMPARE(paintedBounds.y(), offset); |
|
1408 |
QCOMPARE(paintedBounds.width(), expectedBounds.width()); |
|
1409 |
QCOMPARE(paintedBounds.height(), expectedBounds.height()); |
|
1410 |
||
1411 |
if (expectedPixels != -1) { |
|
1412 |
int paintedPixels = getPaintedPixels(image, Qt::white); |
|
1413 |
QCOMPARE(paintedPixels, expectedPixels); |
|
1414 |
} |
|
1415 |
} |
|
1416 |
||
1417 |
void tst_QPainter::drawPath2() |
|
1418 |
{ |
|
1419 |
const int w = 50; |
|
1420 |
||
1421 |
for (int h = 5; h < 200; ++h) { |
|
1422 |
QPainterPath p1, p2; |
|
1423 |
p1.lineTo(w, 0); |
|
1424 |
p1.lineTo(w, h); |
|
1425 |
||
1426 |
p2.lineTo(w, h); |
|
1427 |
p2.lineTo(0, h); |
|
1428 |
||
1429 |
const int offset = 2; |
|
1430 |
||
1431 |
QImage image(w + 2 * offset, h + 2 * offset, |
|
1432 |
QImage::Format_ARGB32_Premultiplied); |
|
1433 |
image.fill(QColor(Qt::white).rgb()); |
|
1434 |
||
1435 |
QPainter p(&image); |
|
1436 |
p.setPen(Qt::NoPen); |
|
1437 |
p.setBrush(Qt::black); |
|
1438 |
p.translate(offset, offset); |
|
1439 |
p.drawPath(p1); |
|
1440 |
p.end(); |
|
1441 |
||
1442 |
const int p1Pixels = getPaintedPixels(image, Qt::white); |
|
1443 |
||
1444 |
image.fill(QColor(Qt::white).rgb()); |
|
1445 |
p.begin(&image); |
|
1446 |
p.setPen(Qt::NoPen); |
|
1447 |
p.setBrush(Qt::black); |
|
1448 |
p.translate(offset, offset); |
|
1449 |
p.drawPath(p2); |
|
1450 |
p.end(); |
|
1451 |
||
1452 |
const int p2Pixels = getPaintedPixels(image, Qt::white); |
|
1453 |
||
1454 |
QCOMPARE(p1Pixels + p2Pixels, w * h); |
|
1455 |
} |
|
1456 |
} |
|
1457 |
||
1458 |
void tst_QPainter::drawPath3() |
|
1459 |
{ |
|
1460 |
#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
|
1461 |
QImage imgA(400, 400, QImage::Format_RGB32); |
|
1462 |
#else |
|
1463 |
QImage imgA(100, 100, QImage::Format_RGB32); |
|
1464 |
#endif |
|
1465 |
imgA.fill(0xffffff); |
|
1466 |
QImage imgB = imgA; |
|
1467 |
||
1468 |
QPainterPath path; |
|
1469 |
for (int y = 0; y < imgA.height(); ++y) { |
|
1470 |
for (int x = 0; x < imgA.width(); ++x) { |
|
1471 |
if ((x + y) & 1) { |
|
1472 |
imgA.setPixel(x, y, 0); |
|
1473 |
path.addRect(x, y, 1, 1); |
|
1474 |
} |
|
1475 |
} |
|
1476 |
} |
|
1477 |
||
1478 |
QPainter p(&imgB); |
|
1479 |
p.setPen(Qt::NoPen); |
|
1480 |
p.setBrush(Qt::black); |
|
1481 |
||
1482 |
p.drawPath(path); |
|
1483 |
p.end(); |
|
1484 |
||
1485 |
QVERIFY(imgA == imgB); |
|
1486 |
||
1487 |
imgA.invertPixels(); |
|
1488 |
imgB.fill(0xffffff); |
|
1489 |
||
1490 |
p.begin(&imgB); |
|
1491 |
p.setPen(Qt::NoPen); |
|
1492 |
p.setBrush(Qt::black); |
|
1493 |
||
1494 |
QRectF rect(0, 0, imgA.width(), imgA.height()); |
|
1495 |
path.addRect(rect.adjusted(-10, -10, 10, 10)); |
|
1496 |
p.drawPath(path); |
|
1497 |
p.end(); |
|
1498 |
||
1499 |
QVERIFY(imgA == imgB); |
|
1500 |
||
1501 |
path.setFillRule(Qt::WindingFill); |
|
1502 |
imgB.fill(0xffffff); |
|
1503 |
||
1504 |
p.begin(&imgB); |
|
1505 |
p.setPen(Qt::NoPen); |
|
1506 |
p.setBrush(Qt::black); |
|
1507 |
QRect clip = rect.adjusted(10, 10, -10, -10).toRect(); |
|
1508 |
p.setClipRect(clip); |
|
1509 |
p.drawPath(path); |
|
1510 |
p.end(); |
|
1511 |
||
1512 |
QCOMPARE(getPaintedPixels(imgB, Qt::white), clip.width() * clip.height()); |
|
1513 |
} |
|
1514 |
||
1515 |
void tst_QPainter::drawEllipse_data() |
|
1516 |
{ |
|
1517 |
QTest::addColumn<QSize>("size"); |
|
1518 |
QTest::addColumn<bool>("usePen"); |
|
1519 |
||
1520 |
// The current drawEllipse algorithm (drawEllipse_midpoint_i in |
|
1521 |
// qpaintengine_raster.cpp) draws ellipses that are too wide if the |
|
1522 |
// ratio between width and hight is too large/small (task 114874). Those |
|
1523 |
// ratios are therefore currently avoided. |
|
1524 |
for (int w = 10; w < 128; w += 7) { |
|
1525 |
for (int h = w/2; h < qMin(2*w, 128); h += 13) { |
|
1526 |
QString s = QString("%1x%2").arg(w).arg(h); |
|
1527 |
QTest::newRow(QString("%1 with pen").arg(s).toLatin1()) << QSize(w, h) << true; |
|
1528 |
QTest::newRow(QString("%1 no pen").arg(s).toLatin1()) << QSize(w, h) << false; |
|
1529 |
} |
|
1530 |
} |
|
1531 |
} |
|
1532 |
||
1533 |
void tst_QPainter::drawEllipse() |
|
1534 |
{ |
|
1535 |
QFETCH(QSize, size); |
|
1536 |
QFETCH(bool, usePen); |
|
1537 |
||
1538 |
const int offset = 10; |
|
1539 |
QRect rect(QPoint(offset, offset), size); |
|
1540 |
||
1541 |
QImage image(size.width() + 2 * offset, size.height() + 2 * offset, |
|
1542 |
QImage::Format_ARGB32_Premultiplied); |
|
1543 |
image.fill(QColor(Qt::white).rgb()); |
|
1544 |
||
1545 |
QPainter p(&image); |
|
1546 |
p.setPen(usePen ? QPen(Qt::black) : QPen(Qt::NoPen)); |
|
1547 |
p.setBrush(Qt::black); |
|
1548 |
p.drawEllipse(rect); |
|
1549 |
p.end(); |
|
1550 |
||
1551 |
QPixmap pixmap = QPixmap::fromImage(image); |
|
1552 |
||
1553 |
const QRect painted = getPaintedSize(pixmap, Qt::white); |
|
1554 |
||
1555 |
QCOMPARE(painted.x(), rect.x()); |
|
1556 |
QCOMPARE(painted.y(), rect.y() + (usePen ? 0 : 1)); |
|
1557 |
QCOMPARE(painted.width(), size.width() + (usePen ? 1 : 0)); |
|
1558 |
QCOMPARE(painted.height(), size.height() + (usePen ? 1 : -1)); |
|
1559 |
} |
|
1560 |
||
1561 |
void tst_QPainter::drawClippedEllipse_data() |
|
1562 |
{ |
|
1563 |
QTest::addColumn<QRect>("rect"); |
|
1564 |
||
1565 |
for (int w = 20; w < 128; w += 7) { |
|
1566 |
for (int h = w/2; h < qMin(2*w, 128); h += 13) { |
|
1567 |
QString s = QString("%1x%2").arg(w).arg(h); |
|
1568 |
QTest::newRow(QString("%1 top").arg(s).toLatin1()) << QRect(0, -h/2, w, h); |
|
1569 |
QTest::newRow(QString("%1 topright").arg(s).toLatin1()) << QRect(w/2, -h/2, w, h); |
|
1570 |
QTest::newRow(QString("%1 right").arg(s).toLatin1()) << QRect(w/2, 0, w, h); |
|
1571 |
QTest::newRow(QString("%1 bottomright").arg(s).toLatin1()) << QRect(w/2, h/2, w, h); |
|
1572 |
QTest::newRow(QString("%1 bottom").arg(s).toLatin1()) << QRect(0, h/2, w, h); |
|
1573 |
QTest::newRow(QString("%1 bottomleft").arg(s).toLatin1()) << QRect(-w/2, h/2, w, h); |
|
1574 |
QTest::newRow(QString("%1 left").arg(s).toLatin1()) << QRect(-w/2, 0, w, h); |
|
1575 |
QTest::newRow(QString("%1 topleft").arg(s).toLatin1()) << QRect(-w/2, -h/2, w, h); |
|
1576 |
} |
|
1577 |
} |
|
1578 |
} |
|
1579 |
||
1580 |
void tst_QPainter::drawClippedEllipse() |
|
1581 |
{ |
|
1582 |
QFETCH(QRect, rect); |
|
1583 |
#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) |
|
1584 |
if (sizeof(qreal) != sizeof(double)) |
|
1585 |
QSKIP("Test only works for qreal==double", SkipAll); |
|
1586 |
#endif |
|
1587 |
QImage image(rect.width() + 1, rect.height() + 1, |
|
1588 |
QImage::Format_ARGB32_Premultiplied); |
|
1589 |
QRect expected = QRect(rect.x(), rect.y(), rect.width()+1, rect.height()+1) |
|
1590 |
& QRect(0, 0, image.width(), image.height()); |
|
1591 |
||
1592 |
||
1593 |
image.fill(QColor(Qt::white).rgb()); |
|
1594 |
QPainter p(&image); |
|
1595 |
p.drawEllipse(rect); |
|
1596 |
p.end(); |
|
1597 |
||
1598 |
QPixmap pixmap = QPixmap::fromImage(image); |
|
1599 |
const QRect painted = getPaintedSize(pixmap, Qt::white); |
|
1600 |
||
1601 |
QCOMPARE(painted.x(), expected.x()); |
|
1602 |
QCOMPARE(painted.y(), expected.y()); |
|
1603 |
QCOMPARE(painted.width(), expected.width()); |
|
1604 |
QCOMPARE(painted.height(), expected.height()); |
|
1605 |
||
1606 |
} |
|
1607 |
||
1608 |
void tst_QPainter::drawRoundRect() |
|
1609 |
{ |
|
1610 |
QFETCH(QRect, rect); |
|
1611 |
QFETCH(bool, usePen); |
|
1612 |
||
1613 |
#ifdef Q_WS_MAC |
|
1614 |
if (QTest::currentDataTag() == QByteArray("rect(6, 12, 3, 14) with pen") || |
|
1615 |
QTest::currentDataTag() == QByteArray("rect(6, 17, 3, 25) with pen") || |
|
1616 |
QTest::currentDataTag() == QByteArray("rect(10, 6, 10, 3) with pen") || |
|
1617 |
QTest::currentDataTag() == QByteArray("rect(10, 12, 10, 14) with pen") || |
|
1618 |
QTest::currentDataTag() == QByteArray("rect(13, 45, 17, 80) with pen") || |
|
1619 |
QTest::currentDataTag() == QByteArray("rect(13, 50, 17, 91) with pen") || |
|
1620 |
QTest::currentDataTag() == QByteArray("rect(17, 6, 24, 3) with pen") || |
|
1621 |
QTest::currentDataTag() == QByteArray("rect(24, 12, 38, 14) with pen")) |
|
1622 |
QSKIP("The Mac paint engine is off-by-one on certain rect sizes", SkipSingle); |
|
1623 |
#endif |
|
1624 |
QPixmap pixmap(rect.x() + rect.width() + 10, |
|
1625 |
rect.y() + rect.height() + 10); |
|
1626 |
{ |
|
1627 |
pixmap.fill(Qt::white); |
|
1628 |
QPainter p(&pixmap); |
|
1629 |
p.setPen(usePen ? QPen(Qt::black) : QPen(Qt::NoPen)); |
|
1630 |
p.setBrush(Qt::black); |
|
1631 |
p.drawRoundRect(rect); |
|
1632 |
p.end(); |
|
1633 |
||
1634 |
int increment = usePen ? 1 : 0; |
|
1635 |
||
1636 |
const QRect painted = getPaintedSize(pixmap, Qt::white); |
|
1637 |
QCOMPARE(painted.width(), rect.width() + increment); |
|
1638 |
QCOMPARE(painted.height(), rect.height() + increment); |
|
1639 |
} |
|
1640 |
||
1641 |
#ifdef QT3_SUPPORT |
|
1642 |
{ |
|
1643 |
pixmap.fill(Qt::white); |
|
1644 |
Q3Painter p(&pixmap); |
|
1645 |
p.setPen(usePen ? QPen(Qt::black) : QPen(Qt::NoPen)); |
|
1646 |
p.setBrush(Qt::black); |
|
1647 |
p.drawRoundRect(rect); |
|
1648 |
p.end(); |
|
1649 |
||
1650 |
const QRect painted = getPaintedSize(pixmap, Qt::white); |
|
1651 |
||
1652 |
QCOMPARE(painted.width(), rect.width()); |
|
1653 |
QCOMPARE(painted.height(), rect.height()); |
|
1654 |
} |
|
1655 |
#endif |
|
1656 |
} |
|
1657 |
||
1658 |
Q_DECLARE_METATYPE(QImage::Format) |
|
1659 |
||
1660 |
void tst_QPainter::qimageFormats_data() |
|
1661 |
{ |
|
1662 |
QTest::addColumn<QImage::Format>("format"); |
|
1663 |
QTest::newRow("QImage::Format_RGB32") << QImage::Format_RGB32; |
|
1664 |
QTest::newRow("QImage::Format_ARGB32") << QImage::Format_ARGB32; |
|
1665 |
QTest::newRow("QImage::Format_ARGB32_Premultiplied") << QImage::Format_ARGB32_Premultiplied; |
|
1666 |
QTest::newRow("QImage::Format_RGB16") << QImage::Format_RGB16; |
|
1667 |
QTest::newRow("Qimage::Format_ARGB8565_Premultiplied") << QImage::Format_ARGB8565_Premultiplied; |
|
1668 |
QTest::newRow("Qimage::Format_RGB666") << QImage::Format_RGB666; |
|
1669 |
QTest::newRow("Qimage::Format_RGB555") << QImage::Format_RGB555; |
|
1670 |
QTest::newRow("Qimage::Format_ARGB8555_Premultiplied") << QImage::Format_ARGB8555_Premultiplied; |
|
1671 |
QTest::newRow("Qimage::Format_RGB888") << QImage::Format_RGB888; |
|
1672 |
} |
|
1673 |
||
1674 |
/* |
|
1675 |
Tests that QPainter can paint on various QImage formats. |
|
1676 |
*/ |
|
1677 |
void tst_QPainter::qimageFormats() |
|
1678 |
{ |
|
1679 |
QFETCH(QImage::Format, format); |
|
1680 |
||
1681 |
const QSize size(100, 100); |
|
1682 |
QImage image(size, format); |
|
1683 |
image.fill(0); |
|
1684 |
||
1685 |
const QColor testColor(Qt::red); |
|
1686 |
QPainter p(&image); |
|
1687 |
QVERIFY(p.isActive()); |
|
1688 |
p.setBrush(QBrush(testColor)); |
|
1689 |
p.drawRect(QRect(QPoint(0,0), size)); |
|
1690 |
QCOMPARE(image.pixel(50, 50), testColor.rgb()); |
|
1691 |
} |
|
1692 |
||
1693 |
void tst_QPainter::fillData() |
|
1694 |
{ |
|
1695 |
QTest::addColumn<QRect>("rect"); |
|
1696 |
QTest::addColumn<bool>("usePen"); |
|
1697 |
||
1698 |
for (int w = 3; w < 50; w += 7) { |
|
1699 |
for (int h = 3; h < 50; h += 11) { |
|
1700 |
int x = w/2 + 5; |
|
1701 |
int y = h/2 + 5; |
|
1702 |
QTest::newRow(QString("rect(%1, %2, %3, %4) with pen").arg(x).arg(y).arg(w).arg(h).toLatin1()) |
|
1703 |
<< QRect(x, y, w, h) << true; |
|
1704 |
QTest::newRow(QString("rect(%1, %2, %3, %4) no pen").arg(x).arg(y).arg(w).arg(h).toLatin1()) |
|
1705 |
<< QRect(x, y, w, h) << false; |
|
1706 |
} |
|
1707 |
} |
|
1708 |
} |
|
1709 |
||
1710 |
/* |
|
1711 |
Test that drawline works properly after setWindow has been called. |
|
1712 |
*/ |
|
1713 |
void tst_QPainter::setWindow() |
|
1714 |
{ |
|
1715 |
QPixmap pixmap(600, 600); |
|
1716 |
pixmap.fill(QColor(Qt::white)); |
|
1717 |
||
1718 |
QPainter painter(&pixmap); |
|
1719 |
painter.setWindow(0, 0, 3, 3); |
|
1720 |
painter.drawLine(1, 1, 2, 2); |
|
1721 |
||
1722 |
const QRect painted = getPaintedSize(pixmap, Qt::white); |
|
1723 |
QVERIFY(195 < painted.y() && painted.y() < 205); // correct value is around 200 |
|
1724 |
QVERIFY(195 < painted.height() && painted.height() < 205); // correct value is around 200 |
|
1725 |
} |
|
1726 |
||
1727 |
void tst_QPainter::combinedMatrix() |
|
1728 |
{ |
|
1729 |
QPixmap pm(64, 64); |
|
1730 |
||
1731 |
QPainter p(&pm); |
|
1732 |
p.setWindow(0, 0, 1, 1); |
|
1733 |
p.setViewport(32, 0, 32, 32); |
|
1734 |
||
1735 |
p.translate(0.5, 0.5); |
|
1736 |
||
1737 |
QMatrix cm = p.combinedMatrix(); |
|
1738 |
||
1739 |
QPointF pt = QPointF(0, 0) * cm; |
|
1740 |
||
1741 |
QCOMPARE(pt.x(), 48.0); |
|
1742 |
QCOMPARE(pt.y(), 16.0); |
|
1743 |
} |
|
1744 |
||
1745 |
void tst_QPainter::textOnTransparentImage() |
|
1746 |
{ |
|
1747 |
bool foundPixel = false; |
|
1748 |
QImage image(10, 10, QImage::Format_ARGB32_Premultiplied); |
|
1749 |
image.fill(qRgba(0, 0, 0, 0)); // transparent |
|
1750 |
{ |
|
1751 |
QPainter painter(&image); |
|
1752 |
painter.setPen(QColor(255, 255, 255)); |
|
1753 |
painter.drawText(0, 10, "W"); |
|
1754 |
} |
|
1755 |
for (int x = 0; x < image.width(); ++x) |
|
1756 |
for (int y = 0; y < image.height(); ++y) |
|
1757 |
if (image.pixel(x, y) != 0) |
|
1758 |
foundPixel = true; |
|
1759 |
QVERIFY(foundPixel); |
|
1760 |
} |
|
1761 |
||
1762 |
void tst_QPainter::renderHints() |
|
1763 |
{ |
|
1764 |
QImage img(1, 1, QImage::Format_RGB32); |
|
1765 |
||
1766 |
QPainter p(&img); |
|
1767 |
||
1768 |
// Turn off all... |
|
1769 |
p.setRenderHints(QPainter::RenderHints(0xffffffff), false); |
|
1770 |
QCOMPARE(p.renderHints(), QPainter::RenderHints(0)); |
|
1771 |
||
1772 |
// Single set/get |
|
1773 |
p.setRenderHint(QPainter::Antialiasing); |
|
1774 |
QVERIFY(p.renderHints() & QPainter::Antialiasing); |
|
1775 |
||
1776 |
p.setRenderHint(QPainter::Antialiasing, false); |
|
1777 |
QVERIFY(!(p.renderHints() & QPainter::Antialiasing)); |
|
1778 |
||
1779 |
// Multi set/get |
|
1780 |
p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); |
|
1781 |
QVERIFY(p.renderHints() & (QPainter::Antialiasing | QPainter::SmoothPixmapTransform)); |
|
1782 |
||
1783 |
p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, false); |
|
1784 |
QVERIFY(!(p.renderHints() & (QPainter::Antialiasing | QPainter::SmoothPixmapTransform))); |
|
1785 |
} |
|
1786 |
||
1787 |
int countPixels(const QImage &img, const QRgb &color) |
|
1788 |
{ |
|
1789 |
int count = 0; |
|
1790 |
for (int y = 0; y < img.height(); ++y) { |
|
1791 |
for (int x = 0; x < img.width(); ++x) { |
|
1792 |
count += ((img.pixel(x, y) & 0xffffff) == color); |
|
1793 |
} |
|
1794 |
} |
|
1795 |
return count; |
|
1796 |
} |
|
1797 |
||
1798 |
template <typename T> |
|
1799 |
void testClipping(QImage &img) |
|
1800 |
{ |
|
1801 |
img.fill(0x0); |
|
1802 |
QPainterPath a, b; |
|
1803 |
a.addRect(QRect(2, 2, 4, 4)); |
|
1804 |
b.addRect(QRect(4, 4, 4, 4)); |
|
1805 |
||
1806 |
QPainter p(&img); |
|
1807 |
p.setClipPath(a); |
|
1808 |
p.setClipPath(b, Qt::UniteClip); |
|
1809 |
||
1810 |
p.setClipping(false); |
|
1811 |
p.setPen(Qt::NoPen); |
|
1812 |
p.setBrush(QColor(0xff0000)); |
|
1813 |
p.drawRect(T(0, 0, 10, 10)); |
|
1814 |
||
1815 |
p.setClipping(true); |
|
1816 |
p.setBrush(QColor(0x00ff00)); |
|
1817 |
p.drawRect(T(0, 0, 10, 10)); |
|
1818 |
||
1819 |
QCOMPARE(countPixels(img, 0xff0000), 72); |
|
1820 |
QCOMPARE(countPixels(img, 0x00ff00), 28); |
|
1821 |
||
1822 |
p.end(); |
|
1823 |
img.fill(0x0); |
|
1824 |
p.begin(&img); |
|
1825 |
p.setClipPath(a); |
|
1826 |
p.setClipPath(b, Qt::IntersectClip); |
|
1827 |
||
1828 |
p.setClipping(false); |
|
1829 |
p.setPen(Qt::NoPen); |
|
1830 |
p.setBrush(QColor(0xff0000)); |
|
1831 |
p.drawRect(T(0, 0, 10, 10)); |
|
1832 |
||
1833 |
p.setClipping(true); |
|
1834 |
p.setBrush(QColor(0x00ff00)); |
|
1835 |
p.drawRect(T(0, 0, 10, 10)); |
|
1836 |
||
1837 |
QCOMPARE(countPixels(img, 0xff0000), 96); |
|
1838 |
QCOMPARE(countPixels(img, 0x00ff00), 4); |
|
1839 |
} |
|
1840 |
||
1841 |
void tst_QPainter::disableEnableClipping() |
|
1842 |
{ |
|
1843 |
QImage img(10, 10, QImage::Format_RGB32); |
|
1844 |
||
1845 |
testClipping<QRectF>(img); |
|
1846 |
testClipping<QRect>(img); |
|
1847 |
} |
|
1848 |
||
1849 |
void tst_QPainter::setClipRect() |
|
1850 |
{ |
|
1851 |
QImage img(10, 10, QImage::Format_RGB32); |
|
1852 |
// simple test to let valgrind check for buffer overflow |
|
1853 |
{ |
|
1854 |
QPainter p(&img); |
|
1855 |
p.setClipRect(-10, -10, 100, 100); |
|
1856 |
p.fillRect(-10, -10, 100, 100, QBrush(QColor(Qt::red))); |
|
1857 |
} |
|
1858 |
||
1859 |
// rects with negative width/height |
|
1860 |
{ |
|
1861 |
QPainter p(&img); |
|
1862 |
p.setClipRect(QRect(10, 10, -10, 10)); |
|
1863 |
QVERIFY(p.clipRegion().isEmpty()); |
|
1864 |
p.setClipRect(QRect(10, 10, 10, -10)); |
|
1865 |
QVERIFY(p.clipRegion().isEmpty()); |
|
1866 |
p.setClipRect(QRectF(10.5, 10.5, -10.5, 10.5)); |
|
1867 |
QVERIFY(p.clipRegion().isEmpty()); |
|
1868 |
p.setClipRect(QRectF(10.5, 10.5, 10.5, -10.5)); |
|
1869 |
QVERIFY(p.clipRegion().isEmpty()); |
|
1870 |
} |
|
1871 |
} |
|
1872 |
||
1873 |
/* |
|
1874 |
This tests the two different clipping approaches in QRasterPaintEngine, |
|
1875 |
one when using a QRegion and one when using a QPainterPath. They should |
|
1876 |
give equal results. |
|
1877 |
*/ |
|
1878 |
void tst_QPainter::setEqualClipRegionAndPath_data() |
|
1879 |
{ |
|
1880 |
QTest::addColumn<QSize>("deviceSize"); |
|
1881 |
QTest::addColumn<QRegion>("region"); |
|
1882 |
||
1883 |
QTest::newRow("empty") << QSize(100, 100) << QRegion(); |
|
1884 |
QTest::newRow("simple rect") << QSize(100, 100) |
|
1885 |
<< QRegion(QRect(5, 5, 10, 10)); |
|
1886 |
||
1887 |
QVector<QRect> rects; |
|
1888 |
QRegion region; |
|
1889 |
||
1890 |
rects << QRect(5, 5, 10, 10) << QRect(20, 20, 10, 10); |
|
1891 |
region.setRects(rects.constData(), rects.size()); |
|
1892 |
QTest::newRow("two rects") << QSize(100, 100) << region; |
|
1893 |
||
1894 |
rects.clear(); |
|
1895 |
rects << QRect(5, 5, 10, 10) << QRect(20, 5, 10, 10); |
|
1896 |
region.setRects(rects.constData(), rects.size()); |
|
1897 |
QTest::newRow("two x-adjacent rects") << QSize(100, 100) << region; |
|
1898 |
||
1899 |
rects.clear(); |
|
1900 |
rects << QRect(0, 0, 10, 100) << QRect(12, 0, 10, 100); |
|
1901 |
region.setRects(rects.constData(), rects.size()); |
|
1902 |
QTest::newRow("two x-adjacent rects 2") << QSize(100, 100) << region; |
|
1903 |
||
1904 |
rects.clear(); |
|
1905 |
rects << QRect(0, 0, 10, 100) << QRect(12, 0, 10, 100); |
|
1906 |
region.setRects(rects.constData(), rects.size()); |
|
1907 |
QTest::newRow("two x-adjacent rects 3") << QSize(50, 50) << region; |
|
1908 |
||
1909 |
rects.clear(); |
|
1910 |
rects << QRect(0, 0, 10, 100) << QRect(12, 0, 10, 100); |
|
1911 |
region.setRects(rects.constData(), rects.size()); |
|
1912 |
QTest::newRow("two x-adjacent rects 4") << QSize(101, 101) << region; |
|
1913 |
||
1914 |
region = QRegion(QRect(0, 0, 200, 200), QRegion::Ellipse); |
|
1915 |
||
1916 |
QTest::newRow("ellipse") << QSize(190, 200) << region; |
|
1917 |
||
1918 |
region ^= QRect(50, 50, 50, 50); |
|
1919 |
QTest::newRow("ellipse 2") << QSize(200, 200) << region; |
|
1920 |
} |
|
1921 |
||
1922 |
void tst_QPainter::setEqualClipRegionAndPath() |
|
1923 |
{ |
|
1924 |
QFETCH(QSize, deviceSize); |
|
1925 |
QFETCH(QRegion, region); |
|
1926 |
||
1927 |
QPainterPath path; |
|
1928 |
path.addRegion(region); |
|
1929 |
||
1930 |
QImage img1(deviceSize.width(), deviceSize.height(), |
|
1931 |
QImage::Format_ARGB32); |
|
1932 |
QImage img2(deviceSize.width(), deviceSize.height(), |
|
1933 |
QImage::Format_ARGB32); |
|
1934 |
img1.fill(0x12345678); |
|
1935 |
img2.fill(0x12345678); |
|
1936 |
||
1937 |
{ |
|
1938 |
QPainter p(&img1); |
|
1939 |
p.setClipRegion(region); |
|
1940 |
p.fillRect(0, 0, img1.width(), img1.height(), QColor(Qt::red)); |
|
1941 |
} |
|
1942 |
{ |
|
1943 |
QPainter p(&img2); |
|
1944 |
p.setClipPath(path); |
|
1945 |
p.fillRect(0, 0, img2.width(), img2.height(), QColor(Qt::red)); |
|
1946 |
} |
|
1947 |
||
1948 |
#if 0 |
|
1949 |
if (img1 != img2) { |
|
1950 |
img1.save("setEqualClipRegionAndPath_1.xpm", "XPM"); |
|
1951 |
img2.save("setEqualClipRegionAndPath_2.xpm", "XPM"); |
|
1952 |
} |
|
1953 |
#endif |
|
1954 |
QCOMPARE(img1, img2); |
|
1955 |
||
1956 |
#if 0 |
|
1957 |
// rotated |
|
1958 |
img1.fill(0x12345678); |
|
1959 |
img2.fill(0x12345678); |
|
1960 |
||
1961 |
{ |
|
1962 |
QPainter p(&img1); |
|
1963 |
p.rotate(25); |
|
1964 |
p.setClipRegion(region); |
|
1965 |
p.fillRect(0, 0, img1.width(), img1.height(), QColor(Qt::red)); |
|
1966 |
} |
|
1967 |
{ |
|
1968 |
QPainter p(&img2); |
|
1969 |
p.rotate(25); |
|
1970 |
p.setClipPath(path); |
|
1971 |
p.fillRect(0, 0, img2.width(), img2.height(), QColor(Qt::red)); |
|
1972 |
} |
|
1973 |
||
1974 |
#if 1 |
|
1975 |
if (img1 != img2) { |
|
1976 |
img1.save("setEqualClipRegionAndPath_1.xpm", "XPM"); |
|
1977 |
img2.save("setEqualClipRegionAndPath_2.xpm", "XPM"); |
|
1978 |
} |
|
1979 |
#endif |
|
1980 |
QCOMPARE(img1, img2); |
|
1981 |
#endif |
|
1982 |
||
1983 |
// simple uniteclip |
|
1984 |
img1.fill(0x12345678); |
|
1985 |
img2.fill(0x12345678); |
|
1986 |
{ |
|
1987 |
QPainter p(&img1); |
|
1988 |
p.setClipRegion(region); |
|
1989 |
p.setClipRegion(region, Qt::UniteClip); |
|
1990 |
p.fillRect(0, 0, img1.width(), img1.height(), QColor(Qt::red)); |
|
1991 |
} |
|
1992 |
{ |
|
1993 |
QPainter p(&img2); |
|
1994 |
p.setClipPath(path); |
|
1995 |
p.setClipPath(path, Qt::UniteClip); |
|
1996 |
p.fillRect(0, 0, img2.width(), img2.height(), QColor(Qt::red)); |
|
1997 |
} |
|
1998 |
QCOMPARE(img1, img2); |
|
1999 |
img1.fill(0x12345678); |
|
2000 |
img2.fill(0x12345678); |
|
2001 |
{ |
|
2002 |
QPainter p(&img1); |
|
2003 |
p.setClipPath(path); |
|
2004 |
p.setClipRegion(region, Qt::UniteClip); |
|
2005 |
p.fillRect(0, 0, img1.width(), img1.height(), QColor(Qt::red)); |
|
2006 |
} |
|
2007 |
{ |
|
2008 |
QPainter p(&img2); |
|
2009 |
p.setClipRegion(region); |
|
2010 |
p.setClipPath(path, Qt::UniteClip); |
|
2011 |
p.fillRect(0, 0, img2.width(), img2.height(), QColor(Qt::red)); |
|
2012 |
} |
|
2013 |
#if 0 |
|
2014 |
if (img1 != img2) { |
|
2015 |
img1.save("setEqualClipRegionAndPath_1.xpm", "XPM"); |
|
2016 |
img2.save("setEqualClipRegionAndPath_2.xpm", "XPM"); |
|
2017 |
} |
|
2018 |
#endif |
|
2019 |
QCOMPARE(img1, img2); |
|
2020 |
||
2021 |
// simple intersectclip |
|
2022 |
img1.fill(0x12345678); |
|
2023 |
img2.fill(0x12345678); |
|
2024 |
{ |
|
2025 |
QPainter p(&img1); |
|
2026 |
p.setClipRegion(region); |
|
2027 |
p.setClipRegion(region, Qt::IntersectClip); |
|
2028 |
p.fillRect(0, 0, img1.width(), img1.height(), QColor(Qt::red)); |
|
2029 |
} |
|
2030 |
{ |
|
2031 |
QPainter p(&img2); |
|
2032 |
p.setClipPath(path); |
|
2033 |
p.setClipPath(path, Qt::IntersectClip); |
|
2034 |
p.fillRect(0, 0, img2.width(), img2.height(), QColor(Qt::red)); |
|
2035 |
} |
|
2036 |
#if 0 |
|
2037 |
if (img1 != img2) { |
|
2038 |
img1.save("setEqualClipRegionAndPath_1.png", "PNG"); |
|
2039 |
img2.save("setEqualClipRegionAndPath_2.png", "PNG"); |
|
2040 |
} |
|
2041 |
#endif |
|
2042 |
QCOMPARE(img1, img2); |
|
2043 |
||
2044 |
img1.fill(0x12345678); |
|
2045 |
img2.fill(0x12345678); |
|
2046 |
{ |
|
2047 |
QPainter p(&img1); |
|
2048 |
p.setClipPath(path); |
|
2049 |
p.setClipRegion(region, Qt::IntersectClip); |
|
2050 |
p.fillRect(0, 0, img1.width(), img1.height(), QColor(Qt::red)); |
|
2051 |
} |
|
2052 |
{ |
|
2053 |
QPainter p(&img2); |
|
2054 |
p.setClipRegion(region); |
|
2055 |
p.setClipPath(path, Qt::IntersectClip); |
|
2056 |
p.fillRect(0, 0, img2.width(), img2.height(), QColor(Qt::red)); |
|
2057 |
} |
|
2058 |
#if 0 |
|
2059 |
if (img1 != img2) { |
|
2060 |
img1.save("setEqualClipRegionAndPath_1.xpm", "XPM"); |
|
2061 |
img2.save("setEqualClipRegionAndPath_2.xpm", "XPM"); |
|
2062 |
} |
|
2063 |
#endif |
|
2064 |
QCOMPARE(img1, img2); |
|
2065 |
||
2066 |
} |
|
2067 |
||
2068 |
void tst_QPainter::clippedFillPath_data() |
|
2069 |
{ |
|
2070 |
QTest::addColumn<QSize>("imageSize"); |
|
2071 |
QTest::addColumn<QPainterPath>("path"); |
|
2072 |
QTest::addColumn<QRect>("clipRect"); |
|
2073 |
QTest::addColumn<QBrush>("brush"); |
|
2074 |
QTest::addColumn<QPen>("pen"); |
|
2075 |
||
2076 |
QLinearGradient gradient(QPoint(0, 0), QPoint(100, 100)); |
|
2077 |
gradient.setColorAt(0, Qt::red); |
|
2078 |
gradient.setColorAt(1, Qt::blue); |
|
2079 |
||
2080 |
||
2081 |
QPen pen2(QColor(223, 223, 0, 223)); |
|
2082 |
pen2.setWidth(2); |
|
2083 |
||
2084 |
QPainterPath path; |
|
2085 |
path.addRect(QRect(15, 15, 50, 50)); |
|
2086 |
QTest::newRow("simple rect 0") << QSize(100, 100) << path |
|
2087 |
<< QRect(15, 15, 49, 49) |
|
2088 |
<< QBrush(Qt::NoBrush) |
|
2089 |
<< QPen(Qt::black); |
|
2090 |
QTest::newRow("simple rect 1") << QSize(100, 100) << path |
|
2091 |
<< QRect(15, 15, 50, 50) |
|
2092 |
<< QBrush(Qt::NoBrush) |
|
2093 |
<< QPen(Qt::black); |
|
2094 |
QTest::newRow("simple rect 2") << QSize(100, 100) << path |
|
2095 |
<< QRect(15, 15, 51, 51) |
|
2096 |
<< QBrush(Qt::NoBrush) |
|
2097 |
<< QPen(Qt::black); |
|
2098 |
QTest::newRow("simple rect 3") << QSize(100, 100) << path |
|
2099 |
<< QRect(15, 15, 51, 51) |
|
2100 |
<< QBrush(QColor(Qt::blue)) |
|
2101 |
<< QPen(Qt::NoPen); |
|
2102 |
QTest::newRow("simple rect 4") << QSize(100, 100) << path |
|
2103 |
<< QRect(15, 15, 51, 51) |
|
2104 |
<< QBrush(gradient) |
|
2105 |
<< pen2; |
|
2106 |
||
2107 |
path = QPainterPath(); |
|
2108 |
path.addEllipse(QRect(15, 15, 50, 50)); |
|
2109 |
QTest::newRow("ellipse 0") << QSize(100, 100) << path |
|
2110 |
<< QRect(15, 15, 49, 49) |
|
2111 |
<< QBrush(Qt::NoBrush) |
|
2112 |
<< QPen(Qt::black); |
|
2113 |
QTest::newRow("ellipse 1") << QSize(100, 100) << path |
|
2114 |
<< QRect(15, 15, 50, 50) |
|
2115 |
<< QBrush(Qt::NoBrush) |
|
2116 |
<< QPen(Qt::black); |
|
2117 |
QTest::newRow("ellipse 2") << QSize(100, 100) << path |
|
2118 |
<< QRect(15, 15, 51, 51) |
|
2119 |
<< QBrush(Qt::NoBrush) |
|
2120 |
<< QPen(Qt::black); |
|
2121 |
QTest::newRow("ellipse 3") << QSize(100, 100) << path |
|
2122 |
<< QRect(15, 15, 51, 51) |
|
2123 |
<< QBrush(QColor(Qt::blue)) |
|
2124 |
<< QPen(Qt::NoPen); |
|
2125 |
QTest::newRow("ellipse 4") << QSize(100, 100) << path |
|
2126 |
<< QRect(15, 15, 51, 51) |
|
2127 |
<< QBrush(gradient) |
|
2128 |
<< pen2; |
|
2129 |
||
2130 |
path = QPainterPath(); |
|
2131 |
path.addRoundRect(QRect(15, 15, 50, 50), 20); |
|
2132 |
QTest::newRow("round rect 0") << QSize(100, 100) << path |
|
2133 |
<< QRect(15, 15, 49, 49) |
|
2134 |
<< QBrush(Qt::NoBrush) |
|
2135 |
<< QPen(Qt::black); |
|
2136 |
QTest::newRow("round rect 1") << QSize(100, 100) << path |
|
2137 |
<< QRect(15, 15, 50, 50) |
|
2138 |
<< QBrush(Qt::NoBrush) |
|
2139 |
<< QPen(Qt::black); |
|
2140 |
QTest::newRow("round rect 2") << QSize(100, 100) << path |
|
2141 |
<< QRect(15, 15, 51, 51) |
|
2142 |
<< QBrush(Qt::NoBrush) |
|
2143 |
<< QPen(Qt::black); |
|
2144 |
QTest::newRow("round rect 3") << QSize(100, 100) << path |
|
2145 |
<< QRect(15, 15, 51, 51) |
|
2146 |
<< QBrush(QColor(Qt::blue)) |
|
2147 |
<< QPen(Qt::NoPen); |
|
2148 |
QTest::newRow("round rect 4") << QSize(100, 100) << path |
|
2149 |
<< QRect(15, 15, 51, 51) |
|
2150 |
<< QBrush(gradient) |
|
2151 |
<< pen2; |
|
2152 |
||
2153 |
path = QPainterPath(); |
|
2154 |
path.moveTo(15, 50); |
|
2155 |
path.cubicTo(40, 50, 40, 15, 65, 50); |
|
2156 |
path.lineTo(15, 50); |
|
2157 |
QTest::newRow("cubic 0") << QSize(100, 100) << path |
|
2158 |
<< QRect(15, 15, 49, 49) |
|
2159 |
<< QBrush(Qt::NoBrush) |
|
2160 |
<< QPen(Qt::black); |
|
2161 |
QTest::newRow("cubic 1") << QSize(100, 100) << path |
|
2162 |
<< QRect(15, 15, 50, 50) |
|
2163 |
<< QBrush(Qt::NoBrush) |
|
2164 |
<< QPen(Qt::black); |
|
2165 |
QTest::newRow("cubic 2") << QSize(100, 100) << path |
|
2166 |
<< QRect(15, 15, 51, 51) |
|
2167 |
<< QBrush(Qt::NoBrush) |
|
2168 |
<< QPen(Qt::black); |
|
2169 |
QTest::newRow("cubic 3") << QSize(100, 100) << path |
|
2170 |
<< QRect(15, 15, 51, 51) |
|
2171 |
<< QBrush(QColor(Qt::blue)) |
|
2172 |
<< QPen(Qt::NoPen); |
|
2173 |
QTest::newRow("cubic 4") << QSize(100, 100) << path |
|
2174 |
<< QRect(15, 15, 51, 51) |
|
2175 |
<< QBrush(gradient) |
|
2176 |
<< pen2; |
|
2177 |
} |
|
2178 |
||
2179 |
void tst_QPainter::clippedFillPath() |
|
2180 |
{ |
|
2181 |
QFETCH(QSize, imageSize); |
|
2182 |
QFETCH(QPainterPath, path); |
|
2183 |
QFETCH(QRect, clipRect); |
|
2184 |
QPainterPath clipPath; |
|
2185 |
clipPath.addRect(clipRect); |
|
2186 |
QFETCH(QBrush, brush); |
|
2187 |
QFETCH(QPen, pen); |
|
2188 |
||
2189 |
const int width = imageSize.width(); |
|
2190 |
const int height = imageSize.height(); |
|
2191 |
||
2192 |
QImage clippedRect(width, height, QImage::Format_ARGB32_Premultiplied); |
|
2193 |
clippedRect.fill(0x12345678); |
|
2194 |
{ |
|
2195 |
QPainter painter(&clippedRect); |
|
2196 |
painter.setPen(pen); |
|
2197 |
painter.setBrush(brush); |
|
2198 |
painter.setClipRect(clipRect); |
|
2199 |
painter.drawPath(path); |
|
2200 |
} |
|
2201 |
||
2202 |
QImage clippedPath(width, height, QImage::Format_ARGB32_Premultiplied); |
|
2203 |
clippedPath.fill(0x12345678); |
|
2204 |
{ |
|
2205 |
QPainter painter(&clippedPath); |
|
2206 |
painter.setPen(pen); |
|
2207 |
painter.setBrush(brush); |
|
2208 |
painter.setClipPath(clipPath); |
|
2209 |
painter.drawPath(path); |
|
2210 |
} |
|
2211 |
||
2212 |
#if 0 |
|
2213 |
if (clippedRect != clippedPath) { |
|
2214 |
clippedRect.save(QString("clippedRect.png"), "PNG"); |
|
2215 |
clippedPath.save(QString("clippedPath.png"), "PNG"); |
|
2216 |
} |
|
2217 |
#endif |
|
2218 |
QCOMPARE(clippedRect, clippedPath); |
|
2219 |
||
2220 |
// repeat with antialiasing |
|
2221 |
||
2222 |
clippedRect.fill(0x12345678); |
|
2223 |
{ |
|
2224 |
QPainter painter(&clippedRect); |
|
2225 |
painter.setRenderHint(QPainter::Antialiasing); |
|
2226 |
painter.setPen(pen); |
|
2227 |
painter.setBrush(brush); |
|
2228 |
painter.setClipRect(clipRect); |
|
2229 |
painter.drawPath(path); |
|
2230 |
} |
|
2231 |
||
2232 |
clippedPath.fill(0x12345678); |
|
2233 |
{ |
|
2234 |
QPainter painter(&clippedPath); |
|
2235 |
painter.setRenderHint(QPainter::Antialiasing); |
|
2236 |
painter.setPen(pen); |
|
2237 |
painter.setBrush(brush); |
|
2238 |
painter.setClipPath(clipPath); |
|
2239 |
painter.drawPath(path); |
|
2240 |
} |
|
2241 |
||
2242 |
#if 1 |
|
2243 |
if (clippedRect != clippedPath) { |
|
2244 |
clippedRect.save(QString("clippedRect.png"), "PNG"); |
|
2245 |
clippedPath.save(QString("clippedPath.png"), "PNG"); |
|
2246 |
} |
|
2247 |
#endif |
|
2248 |
QCOMPARE(clippedRect, clippedPath); |
|
2249 |
||
2250 |
} |
|
2251 |
||
2252 |
void tst_QPainter::clippedLines_data() |
|
2253 |
{ |
|
2254 |
QTest::addColumn<QSize>("imageSize"); |
|
2255 |
QTest::addColumn<QLineF>("line"); |
|
2256 |
QTest::addColumn<QRect>("clipRect"); |
|
2257 |
QTest::addColumn<QPen>("pen"); |
|
2258 |
||
2259 |
QPen pen2(QColor(223, 223, 0, 223)); |
|
2260 |
pen2.setWidth(2); |
|
2261 |
||
2262 |
QVector<QLineF> lines; |
|
2263 |
lines << QLineF(15, 15, 65, 65) |
|
2264 |
<< QLineF(14, 14, 66, 66) |
|
2265 |
<< QLineF(16, 16, 64, 64) |
|
2266 |
<< QLineF(65, 65, 15, 15) |
|
2267 |
<< QLineF(66, 66, 14, 14) |
|
2268 |
<< QLineF(64, 64, 14, 14) |
|
2269 |
<< QLineF(15, 50, 15, 64) |
|
2270 |
<< QLineF(15, 50, 15, 65) |
|
2271 |
<< QLineF(15, 50, 15, 66) |
|
2272 |
<< QLineF(15, 50, 64, 50) |
|
2273 |
<< QLineF(15, 50, 65, 50) |
|
2274 |
<< QLineF(15, 50, 66, 50); |
|
2275 |
||
2276 |
foreach (QLineF line, lines) { |
|
2277 |
QString desc = QString("line (%1, %2, %3, %4) %5").arg(line.x1()) |
|
2278 |
.arg(line.y1()).arg(line.x2()).arg(line.y2()); |
|
2279 |
QTest::newRow(qPrintable(desc.arg(0))) << QSize(100, 100) << line |
|
2280 |
<< QRect(15, 15, 49, 49) |
|
2281 |
<< QPen(Qt::black); |
|
2282 |
QTest::newRow(qPrintable(desc.arg(1))) << QSize(100, 100) << line |
|
2283 |
<< QRect(15, 15, 50, 50) |
|
2284 |
<< QPen(Qt::black); |
|
2285 |
QTest::newRow(qPrintable(desc.arg(2))) << QSize(100, 100) << line |
|
2286 |
<< QRect(15, 15, 51, 51) |
|
2287 |
<< QPen(Qt::black); |
|
2288 |
QTest::newRow(qPrintable(desc.arg(3))) << QSize(100, 100) << line |
|
2289 |
<< QRect(15, 15, 51, 51) |
|
2290 |
<< QPen(Qt::NoPen); |
|
2291 |
QTest::newRow(qPrintable(desc.arg(4))) << QSize(100, 100) << line |
|
2292 |
<< QRect(15, 15, 51, 51) |
|
2293 |
<< pen2; |
|
2294 |
} |
|
2295 |
} |
|
2296 |
||
2297 |
void tst_QPainter::clippedLines() |
|
2298 |
{ |
|
2299 |
QFETCH(QSize, imageSize); |
|
2300 |
QFETCH(QLineF, line); |
|
2301 |
QFETCH(QRect, clipRect); |
|
2302 |
QPainterPath clipPath; |
|
2303 |
clipPath.addRect(clipRect); |
|
2304 |
QFETCH(QPen, pen); |
|
2305 |
||
2306 |
const int width = imageSize.width(); |
|
2307 |
const int height = imageSize.height(); |
|
2308 |
||
2309 |
QImage clippedRect(width, height, QImage::Format_ARGB32_Premultiplied); |
|
2310 |
clippedRect.fill(0x12345678); |
|
2311 |
{ |
|
2312 |
QPainter painter(&clippedRect); |
|
2313 |
painter.setPen(pen); |
|
2314 |
painter.setClipRect(clipRect); |
|
2315 |
painter.drawLine(line); |
|
2316 |
painter.drawLine(line.toLine()); |
|
2317 |
} |
|
2318 |
||
2319 |
QImage clippedPath(width, height, QImage::Format_ARGB32_Premultiplied); |
|
2320 |
clippedPath.fill(0x12345678); |
|
2321 |
{ |
|
2322 |
QPainter painter(&clippedPath); |
|
2323 |
painter.setPen(pen); |
|
2324 |
painter.setClipPath(clipPath); |
|
2325 |
painter.drawLine(line); |
|
2326 |
painter.drawLine(line.toLine()); |
|
2327 |
} |
|
2328 |
||
2329 |
#if 0 |
|
2330 |
if (clippedRect != clippedPath) { |
|
2331 |
clippedRect.save(QString("clippedRect.png"), "PNG"); |
|
2332 |
clippedPath.save(QString("clippedPath.png"), "PNG"); |
|
2333 |
} |
|
2334 |
#endif |
|
2335 |
QCOMPARE(clippedRect, clippedPath); |
|
2336 |
||
2337 |
// repeat with antialiasing |
|
2338 |
clippedRect.fill(0x12345678); |
|
2339 |
{ |
|
2340 |
QPainter painter(&clippedRect); |
|
2341 |
painter.setRenderHint(QPainter::Antialiasing); |
|
2342 |
painter.setPen(pen); |
|
2343 |
painter.setClipRect(clipRect); |
|
2344 |
painter.drawLine(line); |
|
2345 |
painter.drawLine(line.toLine()); |
|
2346 |
} |
|
2347 |
||
2348 |
clippedPath.fill(0x12345678); |
|
2349 |
{ |
|
2350 |
QPainter painter(&clippedPath); |
|
2351 |
painter.setRenderHint(QPainter::Antialiasing); |
|
2352 |
painter.setPen(pen); |
|
2353 |
painter.setClipPath(clipPath); |
|
2354 |
painter.drawLine(line); |
|
2355 |
painter.drawLine(line.toLine()); |
|
2356 |
} |
|
2357 |
||
2358 |
#if 0 |
|
2359 |
if (clippedRect != clippedPath) { |
|
2360 |
clippedRect.save(QString("clippedRect.png"), "PNG"); |
|
2361 |
clippedPath.save(QString("clippedPath.png"), "PNG"); |
|
2362 |
} |
|
2363 |
#endif |
|
2364 |
QCOMPARE(clippedRect, clippedPath); |
|
2365 |
} |
|
2366 |
||
2367 |
void tst_QPainter::clippedPolygon_data() |
|
2368 |
{ |
|
2369 |
clippedFillPath_data(); |
|
2370 |
}; |
|
2371 |
||
2372 |
void tst_QPainter::clippedPolygon() |
|
2373 |
{ |
|
2374 |
QFETCH(QSize, imageSize); |
|
2375 |
QFETCH(QPainterPath, path); |
|
2376 |
QPolygonF polygon = path.toFillPolygon(); |
|
2377 |
QFETCH(QRect, clipRect); |
|
2378 |
QPainterPath clipPath; |
|
2379 |
clipPath.addRect(clipRect); |
|
2380 |
QFETCH(QPen, pen); |
|
2381 |
QFETCH(QBrush, brush); |
|
2382 |
||
2383 |
const int width = imageSize.width(); |
|
2384 |
const int height = imageSize.height(); |
|
2385 |
||
2386 |
QImage clippedRect(width, height, QImage::Format_ARGB32_Premultiplied); |
|
2387 |
clippedRect.fill(0x12345678); |
|
2388 |
{ |
|
2389 |
QPainter painter(&clippedRect); |
|
2390 |
painter.setPen(pen); |
|
2391 |
painter.setBrush(brush); |
|
2392 |
painter.setClipRect(clipRect); |
|
2393 |
painter.drawPolygon(polygon); |
|
2394 |
painter.drawPolygon(polygon.toPolygon()); |
|
2395 |
} |
|
2396 |
||
2397 |
QImage clippedPath(width, height, QImage::Format_ARGB32_Premultiplied); |
|
2398 |
clippedPath.fill(0x12345678); |
|
2399 |
{ |
|
2400 |
QPainter painter(&clippedPath); |
|
2401 |
painter.setPen(pen); |
|
2402 |
painter.setBrush(brush); |
|
2403 |
painter.setClipRect(clipRect); |
|
2404 |
painter.drawPolygon(polygon); |
|
2405 |
painter.drawPolygon(polygon.toPolygon()); |
|
2406 |
} |
|
2407 |
||
2408 |
#if 0 |
|
2409 |
if (clippedRect != clippedPath) { |
|
2410 |
clippedRect.save(QString("clippedRect.png"), "PNG"); |
|
2411 |
clippedPath.save(QString("clippedPath.png"), "PNG"); |
|
2412 |
} |
|
2413 |
#endif |
|
2414 |
QCOMPARE(clippedRect, clippedPath); |
|
2415 |
||
2416 |
// repeat with antialiasing |
|
2417 |
||
2418 |
clippedRect.fill(0x12345678); |
|
2419 |
{ |
|
2420 |
QPainter painter(&clippedRect); |
|
2421 |
painter.setRenderHint(QPainter::Antialiasing); |
|
2422 |
painter.setPen(pen); |
|
2423 |
painter.setBrush(brush); |
|
2424 |
painter.setClipRect(clipRect); |
|
2425 |
painter.drawPolygon(polygon); |
|
2426 |
painter.drawPolygon(polygon.toPolygon()); |
|
2427 |
} |
|
2428 |
||
2429 |
clippedPath.fill(0x12345678); |
|
2430 |
{ |
|
2431 |
QPainter painter(&clippedPath); |
|
2432 |
painter.setRenderHint(QPainter::Antialiasing); |
|
2433 |
painter.setPen(pen); |
|
2434 |
painter.setBrush(brush); |
|
2435 |
painter.setClipRect(clipRect); |
|
2436 |
painter.drawPolygon(polygon); |
|
2437 |
painter.drawPolygon(polygon.toPolygon()); |
|
2438 |
} |
|
2439 |
||
2440 |
#if 0 |
|
2441 |
if (clippedRect != clippedPath) { |
|
2442 |
clippedRect.save(QString("clippedRect.png"), "PNG"); |
|
2443 |
clippedPath.save(QString("clippedPath.png"), "PNG"); |
|
2444 |
} |
|
2445 |
#endif |
|
2446 |
QCOMPARE(clippedRect, clippedPath); |
|
2447 |
} |
|
2448 |
||
2449 |
// this just draws some text that should be clipped in the raster |
|
2450 |
// paint engine. |
|
2451 |
void tst_QPainter::clippedText() |
|
2452 |
{ |
|
2453 |
for (char ch = 'A'; ch < 'Z'; ++ch) { |
|
2454 |
//qDebug() << ch; |
|
2455 |
QFont f; |
|
2456 |
f.setPixelSize(24); |
|
2457 |
QFontMetrics metrics(f); |
|
2458 |
QRect textRect = metrics.boundingRect(QChar(ch)); |
|
2459 |
||
2460 |
if (textRect.width() <= 8) |
|
2461 |
continue; |
|
2462 |
if (textRect.height() <= 8) |
|
2463 |
continue; |
|
2464 |
||
2465 |
QRect imageRect = textRect.adjusted(4, 4, -4, -4); |
|
2466 |
||
2467 |
QImage image(imageRect.size(), QImage::Format_ARGB32_Premultiplied); |
|
2468 |
||
2469 |
image.fill(qRgba(255, 255, 255, 255)); |
|
2470 |
{ |
|
2471 |
QPainter painter(&image); |
|
2472 |
painter.setFont(f); |
|
2473 |
painter.setPen(Qt::black); |
|
2474 |
||
2475 |
painter.drawText(0, 0, QChar(ch)); |
|
2476 |
} |
|
2477 |
||
2478 |
image.fill(qRgba(255, 255, 255, 255)); |
|
2479 |
{ |
|
2480 |
QPainter painter(&image); |
|
2481 |
painter.setFont(f); |
|
2482 |
painter.setPen(Qt::black); |
|
2483 |
||
2484 |
painter.drawText(-imageRect.topLeft(), QChar(ch)); |
|
2485 |
} |
|
2486 |
||
2487 |
bool foundPixel = false; |
|
2488 |
for (int x = 0; x < image.width(); ++x) |
|
2489 |
for (int y = 0; y < image.height(); ++y) |
|
2490 |
if (image.pixel(x, y) != 0) |
|
2491 |
foundPixel = true; |
|
2492 |
// can't QVERIFY(foundPixel) as sometimes all pixels are clipped |
|
2493 |
// away. For example for 'O' |
|
2494 |
// just call /some/ function to prevent the compiler from optimizing |
|
2495 |
// foundPixel away |
|
2496 |
QString::number(foundPixel); |
|
2497 |
||
2498 |
//image.save(QString("debug") + ch + ".xpm"); |
|
2499 |
} |
|
2500 |
||
2501 |
QVERIFY(true); // reached, don't trigger any valgrind errors |
|
2502 |
} |
|
2503 |
||
2504 |
void tst_QPainter::setOpacity_data() |
|
2505 |
{ |
|
2506 |
QTest::addColumn<QImage::Format>("destFormat"); |
|
2507 |
QTest::addColumn<QImage::Format>("srcFormat"); |
|
2508 |
||
2509 |
QTest::newRow("ARGB32P on ARGB32P") << QImage::Format_ARGB32_Premultiplied |
|
2510 |
<< QImage::Format_ARGB32_Premultiplied; |
|
2511 |
||
2512 |
QTest::newRow("ARGB32 on ARGB32") << QImage::Format_ARGB32 |
|
2513 |
<< QImage::Format_ARGB32; |
|
2514 |
||
2515 |
QTest::newRow("RGB32 on RGB32") << QImage::Format_RGB32 |
|
2516 |
<< QImage::Format_RGB32; |
|
2517 |
||
2518 |
QTest::newRow("RGB16 on RGB16") << QImage::Format_RGB16 |
|
2519 |
<< QImage::Format_RGB16; |
|
2520 |
||
2521 |
QTest::newRow("ARGB8565_Premultiplied on ARGB8565_Premultiplied") << QImage::Format_ARGB8565_Premultiplied |
|
2522 |
<< QImage::Format_ARGB8565_Premultiplied; |
|
2523 |
||
2524 |
QTest::newRow("RGB555 on RGB555") << QImage::Format_RGB555 |
|
2525 |
<< QImage::Format_RGB555; |
|
2526 |
||
2527 |
QTest::newRow("RGB666 on RGB666") << QImage::Format_RGB666 |
|
2528 |
<< QImage::Format_RGB666; |
|
2529 |
||
2530 |
QTest::newRow("ARGB8555_Premultiplied on ARGB8555_Premultiplied") << QImage::Format_ARGB8555_Premultiplied |
|
2531 |
<< QImage::Format_ARGB8555_Premultiplied; |
|
2532 |
||
2533 |
QTest::newRow("RGB888 on RGB888") << QImage::Format_RGB888 |
|
2534 |
<< QImage::Format_RGB888; |
|
2535 |
||
2536 |
QTest::newRow("RGB32 on RGB16") << QImage::Format_RGB16 |
|
2537 |
<< QImage::Format_RGB32; |
|
2538 |
||
2539 |
QTest::newRow("RGB32 on ARGB8565_Premultiplied") << QImage::Format_ARGB8565_Premultiplied |
|
2540 |
<< QImage::Format_RGB32; |
|
2541 |
||
2542 |
QTest::newRow("RGB32 on RGB666") << QImage::Format_RGB666 |
|
2543 |
<< QImage::Format_RGB32; |
|
2544 |
||
2545 |
QTest::newRow("RGB32 on RGB555") << QImage::Format_RGB555 |
|
2546 |
<< QImage::Format_RGB32; |
|
2547 |
||
2548 |
QTest::newRow("RGB32 on ARGB8555_Premultiplied") << QImage::Format_ARGB8555_Premultiplied |
|
2549 |
<< QImage::Format_RGB32; |
|
2550 |
||
2551 |
QTest::newRow("RGB32 on RGB888") << QImage::Format_RGB888 |
|
2552 |
<< QImage::Format_RGB32; |
|
2553 |
||
2554 |
QTest::newRow("RGB16 on RGB32") << QImage::Format_RGB32 |
|
2555 |
<< QImage::Format_RGB16; |
|
2556 |
||
2557 |
QTest::newRow("ARGB8565_Premultiplied on RGB32") << QImage::Format_RGB32 |
|
2558 |
<< QImage::Format_ARGB8565_Premultiplied; |
|
2559 |
||
2560 |
QTest::newRow("RGB666 on RGB32") << QImage::Format_RGB32 |
|
2561 |
<< QImage::Format_RGB666; |
|
2562 |
||
2563 |
QTest::newRow("RGB555 on RGB32") << QImage::Format_RGB32 |
|
2564 |
<< QImage::Format_RGB555; |
|
2565 |
||
2566 |
QTest::newRow("ARGB8555_Premultiplied on RGB32") << QImage::Format_RGB32 |
|
2567 |
<< QImage::Format_ARGB8555_Premultiplied; |
|
2568 |
||
2569 |
QTest::newRow("RGB888 on RGB32") << QImage::Format_RGB32 |
|
2570 |
<< QImage::Format_RGB888; |
|
2571 |
||
2572 |
QTest::newRow("RGB555 on RGB888") << QImage::Format_RGB888 |
|
2573 |
<< QImage::Format_RGB555; |
|
2574 |
||
2575 |
QTest::newRow("RGB666 on RGB888") << QImage::Format_RGB888 |
|
2576 |
<< QImage::Format_RGB666; |
|
2577 |
||
2578 |
QTest::newRow("RGB444 on RGB444") << QImage::Format_RGB444 |
|
2579 |
<< QImage::Format_RGB444; |
|
2580 |
} |
|
2581 |
||
2582 |
void tst_QPainter::setOpacity() |
|
2583 |
{ |
|
2584 |
QFETCH(QImage::Format, destFormat); |
|
2585 |
QFETCH(QImage::Format, srcFormat); |
|
2586 |
||
2587 |
const QSize imageSize(12, 12); |
|
2588 |
const QRect imageRect(QPoint(0, 0), imageSize); |
|
2589 |
QColor destColor = Qt::black; |
|
2590 |
QColor srcColor = Qt::white; |
|
2591 |
||
2592 |
QImage dest(imageSize, destFormat); |
|
2593 |
QImage src(imageSize, srcFormat); |
|
2594 |
||
2595 |
QPainter p; |
|
2596 |
p.begin(&dest); |
|
2597 |
p.fillRect(imageRect, destColor); |
|
2598 |
p.end(); |
|
2599 |
||
2600 |
p.begin(&src); |
|
2601 |
p.fillRect(imageRect, srcColor); |
|
2602 |
p.end(); |
|
2603 |
||
2604 |
p.begin(&dest); |
|
2605 |
p.setOpacity(0.5); |
|
2606 |
p.drawImage(imageRect, src, imageRect); |
|
2607 |
p.end(); |
|
2608 |
||
2609 |
QImage expected(imageSize, destFormat); |
|
2610 |
p.begin(&expected); |
|
2611 |
p.fillRect(imageRect, QColor(127, 127, 127)); |
|
2612 |
p.end(); |
|
2613 |
||
2614 |
QCOMPARE(dest, expected); |
|
2615 |
} |
|
2616 |
||
2617 |
void tst_QPainter::drawhelper_blend_untransformed_data() |
|
2618 |
{ |
|
2619 |
setOpacity_data(); |
|
2620 |
} |
|
2621 |
||
2622 |
void tst_QPainter::drawhelper_blend_untransformed() |
|
2623 |
{ |
|
2624 |
QFETCH(QImage::Format, destFormat); |
|
2625 |
QFETCH(QImage::Format, srcFormat); |
|
2626 |
||
2627 |
const int size = 128; |
|
2628 |
const QSize imageSize(size, size); |
|
2629 |
const QRect paintRect(1, 0, size - 2, size); // needs alignment and tailing |
|
2630 |
||
2631 |
QColor destColor(127, 127, 127); |
|
2632 |
QColor srcColor(Qt::white); |
|
2633 |
||
2634 |
QImage dest(imageSize, destFormat); |
|
2635 |
QImage src(imageSize, srcFormat); |
|
2636 |
||
2637 |
QPainter p; |
|
2638 |
p.begin(&src); |
|
2639 |
p.fillRect(paintRect, srcColor); |
|
2640 |
p.end(); |
|
2641 |
||
2642 |
QList<qreal> opacities = (QList<qreal>() << 0.0 << 0.1 << 0.01 << 0.4 |
|
2643 |
<< 0.5 << 0.6 << 0.9 << 1.0); |
|
2644 |
foreach (qreal opacity, opacities) { |
|
2645 |
p.begin(&dest); |
|
2646 |
p.fillRect(paintRect, destColor); |
|
2647 |
||
2648 |
p.setOpacity(opacity); |
|
2649 |
p.drawImage(paintRect, src, paintRect); |
|
2650 |
p.end(); |
|
2651 |
||
2652 |
// sanity check: make sure all pixels are equal |
|
2653 |
QImage expected(size - 2, size, destFormat); |
|
2654 |
p.begin(&expected); |
|
2655 |
p.fillRect(0, 0, expected.width(), expected.height(), |
|
2656 |
QColor(dest.pixel(1, 0))); |
|
2657 |
p.end(); |
|
2658 |
||
2659 |
const QImage subDest(dest.bits() + dest.depth() / 8, |
|
2660 |
dest.width() - 2, dest.height(), |
|
2661 |
dest.bytesPerLine(), dest.format()); |
|
2662 |
||
2663 |
if (dest.format() == QImage::Format_ARGB8565_Premultiplied || |
|
2664 |
dest.format() == QImage::Format_ARGB8555_Premultiplied) { |
|
2665 |
// Test skipped due to rounding errors... |
|
2666 |
continue; |
|
2667 |
} |
|
2668 |
#if 0 |
|
2669 |
if (subDest != expected) { |
|
2670 |
qDebug() << "size" << size << "opacity" << opacity; |
|
2671 |
for (int j = 0; j < expected.height(); ++j) { |
|
2672 |
for (int i = 0; i < expected.width(); ++i) { |
|
2673 |
if (expected.pixel(i,j) != subDest.pixel(i,j)) |
|
2674 |
qDebug() << i << j << hex << expected.pixel(i, j) |
|
2675 |
<< subDest.pixel(i, j); |
|
2676 |
} |
|
2677 |
} |
|
2678 |
} |
|
2679 |
#endif |
|
2680 |
QCOMPARE(subDest, expected); |
|
2681 |
} |
|
2682 |
} |
|
2683 |
||
2684 |
void tst_QPainter::drawhelper_blend_tiled_untransformed_data() |
|
2685 |
{ |
|
2686 |
setOpacity_data(); |
|
2687 |
} |
|
2688 |
||
2689 |
void tst_QPainter::drawhelper_blend_tiled_untransformed() |
|
2690 |
{ |
|
2691 |
QFETCH(QImage::Format, destFormat); |
|
2692 |
QFETCH(QImage::Format, srcFormat); |
|
2693 |
||
2694 |
const int size = 128; |
|
2695 |
const QSize imageSize(size, size); |
|
2696 |
const QRect paintRect(1, 0, size - 2, size); // needs alignment and tailing |
|
2697 |
||
2698 |
QColor destColor(127, 127, 127); |
|
2699 |
QColor srcColor(Qt::white); |
|
2700 |
||
2701 |
QImage dest(imageSize, destFormat); |
|
2702 |
QImage src(imageSize / 2, srcFormat); |
|
2703 |
||
2704 |
QPainter p; |
|
2705 |
p.begin(&src); |
|
2706 |
p.fillRect(QRect(QPoint(0, 0), imageSize/ 2), srcColor); |
|
2707 |
p.end(); |
|
2708 |
||
2709 |
const QBrush brush(src); |
|
2710 |
||
2711 |
QList<qreal> opacities = (QList<qreal>() << 0.0 << 0.1 << 0.01 << 0.4 |
|
2712 |
<< 0.5 << 0.6 << 0.9 << 1.0); |
|
2713 |
foreach (qreal opacity, opacities) { |
|
2714 |
p.begin(&dest); |
|
2715 |
p.fillRect(paintRect, destColor); |
|
2716 |
||
2717 |
p.setOpacity(opacity); |
|
2718 |
p.fillRect(paintRect, brush); |
|
2719 |
p.end(); |
|
2720 |
||
2721 |
// sanity check: make sure all pixels are equal |
|
2722 |
QImage expected(size - 2, size, destFormat); |
|
2723 |
p.begin(&expected); |
|
2724 |
p.fillRect(0, 0, expected.width(), expected.height(), |
|
2725 |
QColor(dest.pixel(1, 0))); |
|
2726 |
p.end(); |
|
2727 |
||
2728 |
const QImage subDest(dest.bits() + dest.depth() / 8, |
|
2729 |
dest.width() - 2, dest.height(), |
|
2730 |
dest.bytesPerLine(), dest.format()); |
|
2731 |
||
2732 |
if (dest.format() == QImage::Format_ARGB8565_Premultiplied || |
|
2733 |
dest.format() == QImage::Format_ARGB8555_Premultiplied) { |
|
2734 |
// Skipping test due to rounding errors. Test needs rewrite |
|
2735 |
continue; |
|
2736 |
} |
|
2737 |
#if 0 |
|
2738 |
if (subDest != expected) { |
|
2739 |
qDebug() << "size" << size << "opacity" << opacity; |
|
2740 |
for (int j = 0; j < expected.height(); ++j) { |
|
2741 |
for (int i = 0; i < expected.width(); ++i) { |
|
2742 |
if (expected.pixel(i,j) != subDest.pixel(i,j)) |
|
2743 |
qDebug() << i << j << hex << expected.pixel(i, j) |
|
2744 |
<< subDest.pixel(i, j); |
|
2745 |
} |
|
2746 |
} |
|
2747 |
} |
|
2748 |
#endif |
|
2749 |
QCOMPARE(subDest, expected); |
|
2750 |
} |
|
2751 |
} |
|
2752 |
||
2753 |
static QPaintEngine::PaintEngineFeatures no_porter_duff() |
|
2754 |
{ |
|
2755 |
QPaintEngine::PaintEngineFeatures features = QPaintEngine::AllFeatures; |
|
2756 |
return features & ~QPaintEngine::PorterDuff; |
|
2757 |
} |
|
2758 |
||
2759 |
class DummyPaintEngine : public QPaintEngine, public QPaintDevice |
|
2760 |
{ |
|
2761 |
public: |
|
2762 |
DummyPaintEngine() : QPaintEngine(no_porter_duff()) {} |
|
2763 |
virtual bool begin(QPaintDevice *) { return true; } |
|
2764 |
virtual bool end() { return true; } |
|
2765 |
||
2766 |
virtual void updateState(const QPaintEngineState &) {} |
|
2767 |
virtual void drawPixmap(const QRectF &, const QPixmap &, const QRectF &) {} |
|
2768 |
||
2769 |
virtual Type type() const { return User; } |
|
2770 |
||
2771 |
virtual QPaintEngine *paintEngine() const { return (QPaintEngine *)this; } |
|
2772 |
||
2773 |
virtual int metric(PaintDeviceMetric metric) const { Q_UNUSED(metric); return 0; }; |
|
2774 |
}; |
|
2775 |
||
2776 |
static bool success; |
|
2777 |
||
2778 |
void porterDuff_warningChecker(QtMsgType type, const char *msg) |
|
2779 |
{ |
|
2780 |
if (type == QtWarningMsg && msg == QLatin1String("QPainter::setCompositionMode: PorterDuff modes not supported on device")) |
|
2781 |
success = false; |
|
2782 |
} |
|
2783 |
||
2784 |
void tst_QPainter::porterDuff_warning() |
|
2785 |
{ |
|
2786 |
QtMsgHandler old = qInstallMsgHandler(porterDuff_warningChecker); |
|
2787 |
DummyPaintEngine dummy; |
|
2788 |
QPainter p(&dummy); |
|
2789 |
||
2790 |
success = true; |
|
2791 |
p.setCompositionMode(QPainter::CompositionMode_Source); |
|
2792 |
QVERIFY(success); |
|
2793 |
||
2794 |
success = true; |
|
2795 |
p.setCompositionMode(QPainter::CompositionMode_SourceOver); |
|
2796 |
QVERIFY(success); |
|
2797 |
||
2798 |
success = true; |
|
2799 |
p.setCompositionMode(QPainter::CompositionMode_DestinationOver); |
|
2800 |
QVERIFY(!success); |
|
2801 |
||
2802 |
QVERIFY(qInstallMsgHandler(old) == porterDuff_warningChecker); |
|
2803 |
} |
|
2804 |
||
2805 |
class quint24 |
|
2806 |
{ |
|
2807 |
public: |
|
2808 |
inline quint24(quint32 v) |
|
2809 |
{ |
|
2810 |
data[0] = qBlue(v); |
|
2811 |
data[1] = qGreen(v); |
|
2812 |
data[2] = qRed(v); |
|
2813 |
} |
|
2814 |
||
2815 |
inline operator quint32 () |
|
2816 |
{ |
|
2817 |
return qRgb(data[2], data[1], data[0]); |
|
2818 |
} |
|
2819 |
||
2820 |
inline bool operator==(const quint24 &v) const { |
|
2821 |
return (data[0] == v.data[0] && data[1] == v.data[1] && data[2] == v.data[2]); |
|
2822 |
} |
|
2823 |
||
2824 |
uchar data[3]; |
|
2825 |
} Q_PACKED; |
|
2826 |
||
2827 |
void tst_QPainter::drawhelper_blend_color() |
|
2828 |
{ |
|
2829 |
QImage dest(32, 32, QImage::Format_ARGB8555_Premultiplied); |
|
2830 |
dest.fill(0xff000000); |
|
2831 |
||
2832 |
{ |
|
2833 |
QPainter p(&dest); |
|
2834 |
p.fillRect(0, 0, dest.width(), dest.height(), QColor(255, 0, 0, 127)); |
|
2835 |
} |
|
2836 |
||
2837 |
QImage expected(32, 32, QImage::Format_ARGB8555_Premultiplied); |
|
2838 |
expected.fill(0xff3c007f); |
|
2839 |
||
2840 |
QCOMPARE(dest.pixel(1, 1), expected.pixel(1, 1)); |
|
2841 |
QCOMPARE(dest, expected); |
|
2842 |
} |
|
2843 |
||
2844 |
class ViewportTestWidget : public QWidget |
|
2845 |
{ |
|
2846 |
public: |
|
2847 |
ViewportTestWidget(QWidget *parent = 0) : QWidget(parent), hasPainted(false) {} |
|
2848 |
QSize sizeHint() const { |
|
2849 |
return QSize(100, 100); |
|
2850 |
} |
|
2851 |
||
2852 |
QRect viewport; |
|
2853 |
bool hasPainted; |
|
2854 |
||
2855 |
protected: |
|
2856 |
void paintEvent(QPaintEvent *) { |
|
2857 |
hasPainted = true; |
|
2858 |
QPainter p(this); |
|
2859 |
viewport = p.viewport(); |
|
2860 |
} |
|
2861 |
}; |
|
2862 |
||
2863 |
void tst_QPainter::childWidgetViewport() |
|
2864 |
{ |
|
2865 |
QWidget parent; |
|
2866 |
parent.setAutoFillBackground(true); |
|
2867 |
parent.resize(200, 200); |
|
2868 |
ViewportTestWidget child(&parent); |
|
2869 |
child.setAutoFillBackground(true); |
|
2870 |
parent.show(); |
|
2871 |
parent.update(); |
|
2872 |
qApp->processEvents(); |
|
2873 |
||
2874 |
if (child.hasPainted) { |
|
2875 |
QCOMPARE(child.viewport, QRect(QPoint(0, 0), child.sizeHint())); |
|
2876 |
} else { |
|
2877 |
qWarning("Failed to ensure that paintEvent has been run. Could not run test."); |
|
2878 |
} |
|
2879 |
} |
|
2880 |
||
2881 |
void tst_QPainter::fillRect_objectBoundingModeGradient() |
|
2882 |
{ |
|
2883 |
QImage a(10, 10, QImage::Format_ARGB32_Premultiplied); |
|
2884 |
a.fill(0x0); |
|
2885 |
QImage b = a; |
|
2886 |
||
2887 |
QLinearGradient g(QPoint(0, 0), QPoint(0, 1)); |
|
2888 |
g.setColorAt(0, Qt::red); |
|
2889 |
g.setColorAt(1, Qt::blue); |
|
2890 |
g.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
2891 |
||
2892 |
QPainter p(&a); |
|
2893 |
p.fillRect(QRect(0, 0, a.width(), a.height()), g); |
|
2894 |
p.end(); |
|
2895 |
||
2896 |
QPainterPath path; |
|
2897 |
path.addRect(0, 0, a.width(), a.height()); |
|
2898 |
||
2899 |
p.begin(&b); |
|
2900 |
p.fillPath(path, g); |
|
2901 |
p.end(); |
|
2902 |
||
2903 |
QCOMPARE(a, b); |
|
2904 |
} |
|
2905 |
||
2906 |
void tst_QPainter::fillRect_stretchToDeviceMode() |
|
2907 |
{ |
|
2908 |
QImage img(64, 64, QImage::Format_ARGB32_Premultiplied); |
|
2909 |
||
2910 |
QLinearGradient g(QPoint(0, 0), QPoint(0, 1)); |
|
2911 |
g.setCoordinateMode(QGradient::StretchToDeviceMode); |
|
2912 |
||
2913 |
QPainter p(&img); |
|
2914 |
p.fillRect(img.rect(), g); |
|
2915 |
p.end(); |
|
2916 |
||
2917 |
for (int i = 1; i < img.height(); ++i) |
|
2918 |
QVERIFY(img.pixel(0, i) != img.pixel(0, i-1)); |
|
2919 |
} |
|
2920 |
||
2921 |
void tst_QPainter::monoImages() |
|
2922 |
{ |
|
2923 |
Qt::GlobalColor colorPairs[][2] = { |
|
2924 |
{ Qt::white, Qt::black }, |
|
2925 |
{ Qt::color0, Qt::color1 }, |
|
2926 |
{ Qt::red, Qt::blue } |
|
2927 |
}; |
|
2928 |
||
2929 |
const int numColorPairs = sizeof(colorPairs) / sizeof(QRgb[2]); |
|
2930 |
||
2931 |
QImage transparent(2, 2, QImage::Format_ARGB32_Premultiplied); |
|
2932 |
transparent.fill(0x0); |
|
2933 |
||
2934 |
for (int i = 1; i < QImage::NImageFormats; ++i) { |
|
2935 |
for (int j = 0; j < numColorPairs; ++j) { |
|
2936 |
const QImage::Format format = QImage::Format(i); |
|
2937 |
if (format == QImage::Format_Indexed8) |
|
2938 |
continue; |
|
2939 |
||
2940 |
QImage img(2, 2, format); |
|
2941 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2942 |
if (img.colorCount() > 0) { |
0 | 2943 |
img.setColor(0, QColor(colorPairs[j][0]).rgba()); |
2944 |
img.setColor(1, QColor(colorPairs[j][1]).rgba()); |
|
2945 |
} |
|
2946 |
||
2947 |
img.fill(0x0); |
|
2948 |
QPainter p(&img); |
|
2949 |
p.fillRect(0, 0, 2, 2, colorPairs[j][0]); |
|
2950 |
p.fillRect(0, 0, 1, 1, colorPairs[j][1]); |
|
2951 |
p.fillRect(1, 1, 1, 1, colorPairs[j][1]); |
|
2952 |
p.end(); |
|
2953 |
||
2954 |
QImage original = img; |
|
2955 |
||
2956 |
p.begin(&img); |
|
2957 |
p.drawImage(0, 0, transparent); |
|
2958 |
p.end(); |
|
2959 |
||
2960 |
// drawing a transparent image on top of another image |
|
2961 |
// should not change the image |
|
2962 |
QCOMPARE(original, img); |
|
2963 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2964 |
if (img.colorCount() == 0) |
0 | 2965 |
continue; |
2966 |
||
2967 |
for (int k = 0; k < 2; ++k) { |
|
2968 |
QPainter p(&img); |
|
2969 |
p.fillRect(0, 0, 2, 2, colorPairs[j][k]); |
|
2970 |
p.end(); |
|
2971 |
||
2972 |
QImage argb32p(2, 2, QImage::Format_ARGB32_Premultiplied); |
|
2973 |
p.begin(&argb32p); |
|
2974 |
p.fillRect(0, 0, 2, 2, colorPairs[j][k]); |
|
2975 |
p.end(); |
|
2976 |
||
2977 |
QCOMPARE(argb32p, img.convertToFormat(argb32p.format())); |
|
2978 |
||
2979 |
// drawing argb32p image on mono image |
|
2980 |
p.begin(&img); |
|
2981 |
p.drawImage(0, 0, argb32p); |
|
2982 |
p.end(); |
|
2983 |
||
2984 |
QCOMPARE(argb32p, img.convertToFormat(argb32p.format())); |
|
2985 |
||
2986 |
// drawing mono image on argb32p image |
|
2987 |
p.begin(&argb32p); |
|
2988 |
p.drawImage(0, 0, img); |
|
2989 |
p.end(); |
|
2990 |
||
2991 |
QCOMPARE(argb32p, img.convertToFormat(argb32p.format())); |
|
2992 |
} |
|
2993 |
} |
|
2994 |
} |
|
2995 |
} |
|
2996 |
||
2997 |
#if !defined(Q_OS_IRIX) && !defined(Q_OS_AIX) && !defined(Q_CC_MSVC) && !defined(Q_OS_SOLARIS) && !defined(Q_OS_SYMBIAN) |
|
2998 |
#include <fenv.h> |
|
2999 |
||
3000 |
static const QString fpeExceptionString(int exception) |
|
3001 |
{ |
|
3002 |
#ifdef FE_INEXACT |
|
3003 |
if (exception & FE_INEXACT) |
|
3004 |
return QLatin1String("Inexact result"); |
|
3005 |
#endif |
|
3006 |
if (exception & FE_UNDERFLOW) |
|
3007 |
return QLatin1String("Underflow"); |
|
3008 |
if (exception & FE_OVERFLOW) |
|
3009 |
return QLatin1String("Overflow"); |
|
3010 |
if (exception & FE_DIVBYZERO) |
|
3011 |
return QLatin1String("Divide by zero"); |
|
3012 |
if (exception & FE_INVALID) |
|
3013 |
return QLatin1String("Invalid operation"); |
|
3014 |
return QLatin1String("No exception"); |
|
3015 |
} |
|
3016 |
||
3017 |
class FpExceptionChecker |
|
3018 |
{ |
|
3019 |
public: |
|
3020 |
FpExceptionChecker(int exceptionMask) |
|
3021 |
: m_exceptionMask(exceptionMask) |
|
3022 |
{ |
|
3023 |
feclearexcept(m_exceptionMask); |
|
3024 |
} |
|
3025 |
||
3026 |
~FpExceptionChecker() |
|
3027 |
{ |
|
3028 |
const int exceptions = fetestexcept(m_exceptionMask); |
|
3029 |
QVERIFY2(!exceptions, qPrintable(QLatin1String("Floating point exception: ") + fpeExceptionString(exceptions))); |
|
3030 |
} |
|
3031 |
||
3032 |
private: |
|
3033 |
int m_exceptionMask; |
|
3034 |
}; |
|
3035 |
||
3036 |
void fpe_rasterizeLine_task232012() |
|
3037 |
{ |
|
3038 |
FpExceptionChecker checker(FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID | FE_DIVBYZERO); |
|
3039 |
QImage img(128, 128, QImage::Format_ARGB32_Premultiplied); |
|
3040 |
img.fill(0x0); |
|
3041 |
QPainter p(&img); |
|
3042 |
||
3043 |
p.setBrush(Qt::black); |
|
3044 |
p.drawRect(QRectF(0, 0, 5, 0)); |
|
3045 |
p.drawRect(QRectF(0, 0, 0, 5)); |
|
3046 |
} |
|
3047 |
||
3048 |
void fpe_pixmapTransform() |
|
3049 |
{ |
|
3050 |
FpExceptionChecker checker(FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID | FE_DIVBYZERO); |
|
3051 |
||
3052 |
QImage img(128, 128, QImage::Format_ARGB32_Premultiplied); |
|
3053 |
||
3054 |
QPainter p(&img); |
|
3055 |
||
3056 |
const qreal scaleFactor = 0.001; |
|
3057 |
const int translateDistance = 1000000; |
|
3058 |
||
3059 |
p.setPen(Qt::red); |
|
3060 |
p.setBrush(QBrush(Qt::red,Qt::Dense6Pattern)); |
|
3061 |
||
3062 |
for (int i = 0; i < 2; ++i) { |
|
3063 |
p.setRenderHint(QPainter::SmoothPixmapTransform, i); |
|
3064 |
||
3065 |
p.resetTransform(); |
|
3066 |
p.scale(1.1, 1.1); |
|
3067 |
p.translate(translateDistance, 0); |
|
3068 |
p.drawRect(-translateDistance, 0, 100, 100); |
|
3069 |
||
3070 |
p.resetTransform(); |
|
3071 |
p.scale(scaleFactor, scaleFactor); |
|
3072 |
p.drawRect(QRectF(0, 0, 1 / scaleFactor, 1 / scaleFactor)); |
|
3073 |
} |
|
3074 |
} |
|
3075 |
||
3076 |
void fpe_zeroLengthLines() |
|
3077 |
{ |
|
3078 |
FpExceptionChecker checker(FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID | FE_DIVBYZERO); |
|
3079 |
||
3080 |
QImage img(128, 128, QImage::Format_ARGB32_Premultiplied); |
|
3081 |
||
3082 |
QPainter p(&img); |
|
3083 |
||
3084 |
p.setPen(QPen(Qt::black, 3)); |
|
3085 |
p.drawLine(64, 64, 64, 64); |
|
3086 |
} |
|
3087 |
||
3088 |
void fpe_divByZero() |
|
3089 |
{ |
|
3090 |
FpExceptionChecker checker(FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID | FE_DIVBYZERO); |
|
3091 |
||
3092 |
QImage img(128, 128, QImage::Format_ARGB32_Premultiplied); |
|
3093 |
||
3094 |
QPainter p(&img); |
|
3095 |
||
3096 |
p.setRenderHint(QPainter::Antialiasing); |
|
3097 |
||
3098 |
p.drawRect(QRectF(10, 10, 100, 0)); |
|
3099 |
p.drawRect(QRectF(10, 10, 0, 100)); |
|
3100 |
||
3101 |
p.drawRect(QRect(10, 10, 100, 0)); |
|
3102 |
p.drawRect(QRect(10, 10, 0, 100)); |
|
3103 |
||
3104 |
p.fillRect(QRectF(10, 10, 100, 0), Qt::black); |
|
3105 |
p.fillRect(QRectF(10, 10, 0, 100), Qt::black); |
|
3106 |
||
3107 |
p.fillRect(QRect(10, 10, 100, 0), Qt::black); |
|
3108 |
p.fillRect(QRect(10, 10, 0, 100), Qt::black); |
|
3109 |
} |
|
3110 |
||
3111 |
void fpe_steepSlopes() |
|
3112 |
{ |
|
3113 |
FpExceptionChecker checker(FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID | FE_DIVBYZERO); |
|
3114 |
||
3115 |
QImage img(1024, 1024, QImage::Format_ARGB32_Premultiplied); |
|
3116 |
||
3117 |
QFETCH(QTransform, transform); |
|
3118 |
QFETCH(QLineF, line); |
|
3119 |
QFETCH(bool, antialiased); |
|
3120 |
||
3121 |
QPainter p(&img); |
|
3122 |
||
3123 |
p.setPen(QPen(Qt::black, 1)); |
|
3124 |
p.setRenderHint(QPainter::Antialiasing, antialiased); |
|
3125 |
p.setTransform(transform); |
|
3126 |
||
3127 |
QEXPECT_FAIL("steep line 3 aa", "needs to be fixed", Continue); |
|
3128 |
p.drawLine(line); |
|
3129 |
} |
|
3130 |
||
3131 |
void fpe_radialGradients() |
|
3132 |
{ |
|
3133 |
FpExceptionChecker checker(FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID | FE_DIVBYZERO); |
|
3134 |
||
3135 |
QImage img(21, 21, QImage::Format_ARGB32_Premultiplied); |
|
3136 |
img.fill(0); |
|
3137 |
||
3138 |
double m = img.width() * 0.5; |
|
3139 |
||
3140 |
QPainter p(&img); |
|
3141 |
p.setRenderHints(QPainter::Antialiasing); |
|
3142 |
p.setPen(Qt::NoPen); |
|
3143 |
p.setBrush(QRadialGradient(m, m, m)); |
|
3144 |
p.drawEllipse(img.rect()); |
|
3145 |
} |
|
3146 |
||
3147 |
#define FPE_TEST(x) \ |
|
3148 |
void tst_QPainter::x() \ |
|
3149 |
{ \ |
|
3150 |
::x(); \ |
|
3151 |
} |
|
3152 |
#else |
|
3153 |
#define FPE_TEST(x) \ |
|
3154 |
void tst_QPainter::x() \ |
|
3155 |
{ \ |
|
3156 |
QSKIP("Floating point exception checking (fenv.h) not available", SkipAll); \ |
|
3157 |
} |
|
3158 |
#endif |
|
3159 |
||
3160 |
FPE_TEST(fpe_rasterizeLine_task232012) |
|
3161 |
FPE_TEST(fpe_pixmapTransform) |
|
3162 |
FPE_TEST(fpe_zeroLengthLines) |
|
3163 |
FPE_TEST(fpe_divByZero) |
|
3164 |
FPE_TEST(fpe_steepSlopes) |
|
3165 |
FPE_TEST(fpe_radialGradients) |
|
3166 |
||
3167 |
void tst_QPainter::fpe_steepSlopes_data() |
|
3168 |
{ |
|
3169 |
QTest::addColumn<QTransform>("transform"); |
|
3170 |
QTest::addColumn<QLineF>("line"); |
|
3171 |
QTest::addColumn<bool>("antialiased"); |
|
3172 |
||
3173 |
{ |
|
3174 |
const qreal dsin = 0.000014946676875461832484392500630665523431162000633776187896728515625; |
|
3175 |
const qreal dcos = 0.9999999998882984630910186751862056553363800048828125; |
|
3176 |
||
3177 |
const QTransform transform = QTransform(QMatrix(dcos, dsin, -dsin, dcos, 64, 64)); |
|
3178 |
const QLineF line(2, 2, 2, 6); |
|
3179 |
||
3180 |
QTest::newRow("task 207147 aa") << transform << line << true; |
|
3181 |
QTest::newRow("task 207147 no aa") << transform << line << false; |
|
3182 |
} |
|
3183 |
||
3184 |
{ |
|
3185 |
QTransform transform; |
|
3186 |
transform.rotate(0.0000001); |
|
3187 |
const QLineF line(5, 5, 10, 5); |
|
3188 |
||
3189 |
QTest::newRow("task 166702 aa") << transform << line << true; |
|
3190 |
QTest::newRow("task 166702 no aa") << transform << line << false; |
|
3191 |
} |
|
3192 |
||
3193 |
{ |
|
3194 |
const QTransform transform; |
|
3195 |
const QLineF line(2.5, 2.5, 2.5 + 1/256., 60000.5); |
|
3196 |
||
3197 |
QTest::newRow("steep line aa") << transform << line << true; |
|
3198 |
QTest::newRow("steep line no aa") << transform << line << false; |
|
3199 |
} |
|
3200 |
||
3201 |
{ |
|
3202 |
const QTransform transform; |
|
3203 |
const QLineF line(2.5, 2.5, 2.5 + 1/256., 1024); |
|
3204 |
||
3205 |
QTest::newRow("steep line 2 aa") << transform << line << true; |
|
3206 |
QTest::newRow("steep line 2 no aa") << transform << line << false; |
|
3207 |
} |
|
3208 |
||
3209 |
{ |
|
3210 |
const QTransform transform; |
|
3211 |
const QLineF line(2.5, 2.5, 2.5 + 1/64., 1024); |
|
3212 |
||
3213 |
QTest::newRow("steep line 3 aa") << transform << line << true; |
|
3214 |
QTest::newRow("steep line 3 no aa") << transform << line << false; |
|
3215 |
} |
|
3216 |
} |
|
3217 |
||
3218 |
qreal randf() |
|
3219 |
{ |
|
3220 |
return rand() / (RAND_MAX + 1.0); |
|
3221 |
} |
|
3222 |
||
3223 |
QPointF randInRect(const QRectF &rect) |
|
3224 |
{ |
|
3225 |
const qreal x = rect.left() + rect.width() * randf(); |
|
3226 |
const qreal y = rect.top() + rect.height() * randf(); |
|
3227 |
||
3228 |
return QPointF(x, y); |
|
3229 |
} |
|
3230 |
||
3231 |
void tst_QPainter::rasterizer_asserts() |
|
3232 |
{ |
|
3233 |
QImage img(64, 64, QImage::Format_ARGB32_Premultiplied); |
|
3234 |
||
3235 |
QRectF middle(QPointF(0, 0), img.size()); |
|
3236 |
QRectF left = middle.translated(-middle.width(), 0); |
|
3237 |
QRectF right = middle.translated(middle.width(), 0); |
|
3238 |
||
3239 |
QPainter p(&img); |
|
3240 |
img.fill(Qt::white); |
|
3241 |
p.setCompositionMode(QPainter::CompositionMode_Destination); |
|
3242 |
for (int i = 0; i < 100000; ++i) { |
|
3243 |
QPainterPath path; |
|
3244 |
path.moveTo(randInRect(middle)); |
|
3245 |
path.lineTo(randInRect(left)); |
|
3246 |
path.lineTo(randInRect(right)); |
|
3247 |
||
3248 |
p.fillPath(path, Qt::black); |
|
3249 |
} |
|
3250 |
} |
|
3251 |
||
3252 |
void tst_QPainter::rasterizer_negativeCoords() |
|
3253 |
{ |
|
3254 |
QImage img(64, 64, QImage::Format_ARGB32_Premultiplied); |
|
3255 |
img.fill(0x0); |
|
3256 |
||
3257 |
QImage original = img; |
|
3258 |
||
3259 |
QPainter p(&img); |
|
3260 |
p.rotate(90); |
|
3261 |
p.fillRect(0, 0, 70, 50, Qt::black); |
|
3262 |
||
3263 |
// image should not have changed |
|
3264 |
QCOMPARE(img.pixel(0, 0), 0x0U); |
|
3265 |
QCOMPARE(img, original); |
|
3266 |
} |
|
3267 |
||
3268 |
void tst_QPainter::blendOverFlow_data() |
|
3269 |
{ |
|
3270 |
QTest::addColumn<QImage::Format>("format"); |
|
3271 |
QTest::addColumn<int>("width"); |
|
3272 |
QTest::addColumn<int>("height"); |
|
3273 |
||
3274 |
QImage::Format format = QImage::Format_ARGB8555_Premultiplied; |
|
3275 |
QTest::newRow("555,1,1") << format << 1 << 1; |
|
3276 |
QTest::newRow("555,2,2") << format << 2 << 2; |
|
3277 |
QTest::newRow("555,10,10") << format << 10 << 10; |
|
3278 |
||
3279 |
format = QImage::Format_ARGB8565_Premultiplied; |
|
3280 |
QTest::newRow("565,1,1") << format << 1 << 1; |
|
3281 |
QTest::newRow("565,2,2") << format << 2 << 2; |
|
3282 |
QTest::newRow("565,10,10") << format << 10 << 10; |
|
3283 |
} |
|
3284 |
||
3285 |
void tst_QPainter::blendOverFlow() |
|
3286 |
{ |
|
3287 |
QFETCH(QImage::Format, format); |
|
3288 |
QFETCH(int, width); |
|
3289 |
QFETCH(int, height); |
|
3290 |
||
3291 |
QImage dest(width, height, format); |
|
3292 |
QImage src(width, height, format); |
|
3293 |
||
3294 |
{ |
|
3295 |
QPainter p(&dest); |
|
3296 |
p.fillRect(0, 0, width, height, Qt::green); |
|
3297 |
} |
|
3298 |
QImage expected = dest; |
|
3299 |
||
3300 |
{ |
|
3301 |
QPainter p(&src); |
|
3302 |
p.setCompositionMode(QPainter::CompositionMode_Source); |
|
3303 |
p.fillRect(0, 0, width, height, QColor(0, 255, 0, 6)); |
|
3304 |
} |
|
3305 |
||
3306 |
{ |
|
3307 |
QPainter p(&dest); |
|
3308 |
p.drawImage(0, 0, src); |
|
3309 |
} |
|
3310 |
||
3311 |
QCOMPARE(dest.pixel(0, 0), expected.pixel(0, 0)); |
|
3312 |
QCOMPARE(dest, expected); |
|
3313 |
} |
|
3314 |
||
3315 |
void tst_QPainter::largeImagePainting_data() |
|
3316 |
{ |
|
3317 |
QTest::addColumn<int>("width"); |
|
3318 |
QTest::addColumn<int>("height"); |
|
3319 |
QTest::addColumn<bool>("antialiased"); |
|
3320 |
||
3321 |
QTest::newRow("tall") << 1 << 32767 << false; |
|
3322 |
QTest::newRow("tall aa") << 1 << 32767 << true; |
|
3323 |
QTest::newRow("wide") << 32767 << 1 << false; |
|
3324 |
QTest::newRow("wide aa") << 32767 << 1 << true; |
|
3325 |
} |
|
3326 |
||
3327 |
void tst_QPainter::largeImagePainting() |
|
3328 |
{ |
|
3329 |
QPainterPath path; |
|
3330 |
path.addRect(0, 0, 1, 1); |
|
3331 |
path.addRect(2, 0, 1, 1); |
|
3332 |
path.addRect(0, 2, 1, 1); |
|
3333 |
||
3334 |
QFETCH(int, width); |
|
3335 |
QFETCH(int, height); |
|
3336 |
QFETCH(bool, antialiased); |
|
3337 |
||
3338 |
QImage img(width, height, QImage::Format_ARGB32_Premultiplied); |
|
3339 |
img.fill(0x0); |
|
3340 |
||
3341 |
QPainter p(&img); |
|
3342 |
p.setPen(Qt::NoPen); |
|
3343 |
p.setBrush(Qt::white); |
|
3344 |
||
3345 |
p.setRenderHint(QPainter::Antialiasing, antialiased); |
|
3346 |
||
3347 |
for (int i = 0; i < img.width(); i += 4) { |
|
3348 |
p.drawPath(path); |
|
3349 |
p.translate(4, 0); |
|
3350 |
} |
|
3351 |
||
3352 |
p.resetMatrix(); |
|
3353 |
||
3354 |
for (int i = 4; i < img.height(); i += 4) { |
|
3355 |
p.translate(0, 4); |
|
3356 |
p.drawPath(path); |
|
3357 |
} |
|
3358 |
||
3359 |
for (int i = 0; i < img.width(); ++i) { |
|
3360 |
if (i % 2) |
|
3361 |
QCOMPARE(img.pixel(i, 0), 0x0U); |
|
3362 |
else |
|
3363 |
QCOMPARE(img.pixel(i, 0), 0xffffffffU); |
|
3364 |
} |
|
3365 |
||
3366 |
for (int i = 1; i < img.height(); ++i) { |
|
3367 |
if (i % 2) |
|
3368 |
QCOMPARE(img.pixel(0, i), 0x0U); |
|
3369 |
else |
|
3370 |
QCOMPARE(img.pixel(0, i), 0xffffffffU); |
|
3371 |
} |
|
3372 |
} |
|
3373 |
||
3374 |
void tst_QPainter::imageScaling_task206785() |
|
3375 |
{ |
|
3376 |
QImage src(32, 2, QImage::Format_ARGB32_Premultiplied); |
|
3377 |
src.fill(0xffffffff); |
|
3378 |
||
3379 |
QImage dst(128, 128, QImage::Format_ARGB32_Premultiplied); |
|
3380 |
||
3381 |
QImage expected(128, 128, QImage::Format_ARGB32_Premultiplied); |
|
3382 |
expected.fill(0xffffffff); |
|
3383 |
||
3384 |
for (int i = 1; i < 5; ++i) { |
|
3385 |
qreal scale = i / qreal(5); |
|
3386 |
||
3387 |
dst.fill(0xff000000); |
|
3388 |
||
3389 |
QPainter p(&dst); |
|
3390 |
p.scale(dst.width() / qreal(src.width()), scale); |
|
3391 |
||
3392 |
for (int y = 0; y * scale < dst.height(); ++y) |
|
3393 |
p.drawImage(0, y, src); |
|
3394 |
||
3395 |
p.end(); |
|
3396 |
||
3397 |
QCOMPARE(dst, expected); |
|
3398 |
} |
|
3399 |
} |
|
3400 |
||
3401 |
#define FOR_EACH_NEIGHBOR_8 for (int dx = -1; dx <= 1; ++dx) for (int dy = -1; dy <= 1; ++dy) if (dx != 0 || dy != 0) |
|
3402 |
#define FOR_EACH_NEIGHBOR_4 for (int dx = -1; dx <= 1; ++dx) for (int dy = -1; dy <= 1; ++dy) if ((dx == 0) != (dy == 0)) |
|
3403 |
||
3404 |
uint qHash(const QPoint &point) |
|
3405 |
{ |
|
3406 |
return qHash(qMakePair(point.x(), point.y())); |
|
3407 |
} |
|
3408 |
||
3409 |
bool verifyOutlineFillConsistency(const QImage &img, QRgb outside, QRgb inside, QRgb outline) |
|
3410 |
{ |
|
3411 |
if (img.pixel(img.width() / 2, img.height() / 2) != inside) |
|
3412 |
return false; |
|
3413 |
||
3414 |
int x = img.width() / 2; |
|
3415 |
int y = img.height() / 2; |
|
3416 |
||
3417 |
while (img.pixel(++x, y) == inside) |
|
3418 |
; |
|
3419 |
||
3420 |
if (img.pixel(x, y) != outline) |
|
3421 |
return false; |
|
3422 |
||
3423 |
QQueue<QPoint> discovered; |
|
3424 |
discovered.enqueue(QPoint(x, y)); |
|
3425 |
||
3426 |
QVector<bool> visited(img.width() * img.height()); |
|
3427 |
visited.fill(false); |
|
3428 |
||
3429 |
while (!discovered.isEmpty()) { |
|
3430 |
QPoint p = discovered.dequeue(); |
|
3431 |
QRgb pixel = img.pixel(p.x(), p.y()); |
|
3432 |
||
3433 |
bool &v = visited[p.y() * img.width() + p.x()]; |
|
3434 |
if (v) |
|
3435 |
continue; |
|
3436 |
v = true; |
|
3437 |
||
3438 |
if (pixel == outline) { |
|
3439 |
FOR_EACH_NEIGHBOR_8 { |
|
3440 |
QPoint x(p.x() + dx, p.y() + dy); |
|
3441 |
discovered.enqueue(x); |
|
3442 |
} |
|
3443 |
} else { |
|
3444 |
FOR_EACH_NEIGHBOR_4 { |
|
3445 |
if ((dx == 0) == (dy == 0)) |
|
3446 |
continue; |
|
3447 |
QRgb neighbor = img.pixel(p.x() + dx, p.y() + dy); |
|
3448 |
if (pixel == inside && neighbor == outside || |
|
3449 |
pixel == outside && neighbor == inside) |
|
3450 |
return false; |
|
3451 |
} |
|
3452 |
} |
|
3453 |
} |
|
3454 |
||
3455 |
return true; |
|
3456 |
} |
|
3457 |
||
3458 |
#undef FOR_EACH_NEIGHBOR_8 |
|
3459 |
#undef FOR_EACH_NEIGHBOR_4 |
|
3460 |
||
3461 |
void tst_QPainter::outlineFillConsistency() |
|
3462 |
{ |
|
3463 |
QImage dst(256, 256, QImage::Format_ARGB32_Premultiplied); |
|
3464 |
||
3465 |
QPolygonF poly; |
|
3466 |
poly << QPointF(5, -100) << QPointF(-70, 20) << QPointF(95, 25); |
|
3467 |
||
3468 |
QPen pen(Qt::red); |
|
3469 |
QBrush brush(Qt::black); |
|
3470 |
||
3471 |
QRgb background = 0xffffffff; |
|
3472 |
for (int i = 0; i < 360; ++i) { |
|
3473 |
dst.fill(background); |
|
3474 |
||
3475 |
QPainter p(&dst); |
|
3476 |
p.translate(dst.width() / 2, dst.height() / 2); |
|
3477 |
||
3478 |
QPolygonF copy = poly; |
|
3479 |
for (int j = 0; j < copy.size(); ++j) |
|
3480 |
copy[j] = QTransform().rotate(i).map(copy[j]); |
|
3481 |
||
3482 |
p.setPen(pen); |
|
3483 |
p.setBrush(brush); |
|
3484 |
p.drawPolygon(copy); |
|
3485 |
p.end(); |
|
3486 |
||
3487 |
#if 0 |
|
3488 |
if (!verifyOutlineFillConsistency(dst, background, p.brush().color().rgba(), p.pen().color().rgba())) |
|
3489 |
dst.save(QString("outlineFillConsistency-%1.png").arg(i)); |
|
3490 |
#endif |
|
3491 |
||
3492 |
QVERIFY(verifyOutlineFillConsistency(dst, background, brush.color().rgba(), pen.color().rgba())); |
|
3493 |
} |
|
3494 |
} |
|
3495 |
||
3496 |
void tst_QPainter::drawImage_task217400_data() |
|
3497 |
{ |
|
3498 |
QTest::addColumn<QImage::Format>("format"); |
|
3499 |
||
3500 |
QTest::newRow("444") << QImage::Format_ARGB4444_Premultiplied; |
|
3501 |
QTest::newRow("555") << QImage::Format_ARGB8555_Premultiplied; |
|
3502 |
QTest::newRow("565") << QImage::Format_ARGB8565_Premultiplied; |
|
3503 |
// QTest::newRow("666") << QImage::Format_ARGB6666_Premultiplied; |
|
3504 |
QTest::newRow("888p") << QImage::Format_ARGB32_Premultiplied; |
|
3505 |
QTest::newRow("888") << QImage::Format_ARGB32; |
|
3506 |
} |
|
3507 |
||
3508 |
void tst_QPainter::drawImage_task217400() |
|
3509 |
{ |
|
3510 |
QFETCH(QImage::Format, format); |
|
3511 |
||
3512 |
const QImage src = QImage(QString(SRCDIR) + "/task217400.png") |
|
3513 |
.convertToFormat(format); |
|
3514 |
QVERIFY(!src.isNull()); |
|
3515 |
||
3516 |
QImage expected(src.size(), format); |
|
3517 |
{ |
|
3518 |
QPainter p(&expected); |
|
3519 |
p.fillRect(0, 0, expected.width(), expected.height(), Qt::white); |
|
3520 |
p.drawImage(0, 0, src); |
|
3521 |
} |
|
3522 |
||
3523 |
for (int i = 1; i <= 4; ++i) { |
|
3524 |
QImage dest(src.width() + i, src.height(), format); |
|
3525 |
{ |
|
3526 |
QPainter p(&dest); |
|
3527 |
p.fillRect(0, 0, dest.width(), dest.height(), Qt::white); |
|
3528 |
p.drawImage(i, 0, src); |
|
3529 |
} |
|
3530 |
||
3531 |
const QImage result = dest.copy(i, 0, src.width(), src.height()); |
|
3532 |
||
3533 |
#if 0 |
|
3534 |
if (result != expected) { |
|
3535 |
qDebug("i=%i", i); |
|
3536 |
result.save("result.png"); |
|
3537 |
expected.save("expected.png"); |
|
3538 |
} |
|
3539 |
#endif |
|
3540 |
QCOMPARE(result, expected); |
|
3541 |
} |
|
3542 |
} |
|
3543 |
||
3544 |
void tst_QPainter::drawImage_task258776() |
|
3545 |
{ |
|
3546 |
QImage src(16, 16, QImage::Format_RGB888); |
|
3547 |
QImage dest(33, 33, QImage::Format_RGB888); |
|
3548 |
src.fill(0x00ff00); |
|
3549 |
dest.fill(0x0000ff); |
|
3550 |
||
3551 |
QPainter painter(&dest); |
|
3552 |
painter.drawImage(QRectF(0.499, 0.499, 32, 32), src, QRectF(0, 0, 16, 16)); |
|
3553 |
painter.end(); |
|
3554 |
||
3555 |
QImage expected(33, 33, QImage::Format_RGB32); |
|
3556 |
expected.fill(0xff0000); |
|
3557 |
||
3558 |
painter.begin(&expected); |
|
3559 |
painter.drawImage(QRectF(0, 0, 32, 32), src); |
|
3560 |
painter.end(); |
|
3561 |
||
3562 |
dest = dest.convertToFormat(QImage::Format_RGB32); |
|
3563 |
||
3564 |
dest.save("dest.png"); |
|
3565 |
expected.save("expected.png"); |
|
3566 |
QCOMPARE(dest, expected); |
|
3567 |
} |
|
3568 |
||
3569 |
void tst_QPainter::clipRectSaveRestore() |
|
3570 |
{ |
|
3571 |
QImage img(64, 64, QImage::Format_ARGB32_Premultiplied); |
|
3572 |
img.fill(0x0); |
|
3573 |
||
3574 |
QPainter p(&img); |
|
3575 |
p.setClipRect(QRect(0, 0, 10, 10)); |
|
3576 |
p.save(); |
|
3577 |
p.setClipRect(QRect(5, 5, 5, 5), Qt::IntersectClip); |
|
3578 |
p.restore(); |
|
3579 |
p.fillRect(0, 0, 64, 64, Qt::black); |
|
3580 |
p.end(); |
|
3581 |
||
3582 |
QCOMPARE(img.pixel(0, 0), QColor(Qt::black).rgba()); |
|
3583 |
} |
|
3584 |
||
3585 |
void tst_QPainter::clippedImage() |
|
3586 |
{ |
|
3587 |
QImage img(16, 16, QImage::Format_ARGB32_Premultiplied); |
|
3588 |
img.fill(0x0); |
|
3589 |
||
3590 |
QImage src(16, 16, QImage::Format_RGB32); |
|
3591 |
src.fill(QColor(Qt::red).rgba()); |
|
3592 |
||
3593 |
QPainter p(&img); |
|
3594 |
p.setClipRect(QRect(1, 1, 14, 14)); |
|
3595 |
p.drawImage(0, 0, src); |
|
3596 |
p.end(); |
|
3597 |
||
3598 |
QCOMPARE(img.pixel(0, 0), 0x0U); |
|
3599 |
QCOMPARE(img.pixel(1, 1), src.pixel(1, 1)); |
|
3600 |
} |
|
3601 |
||
3602 |
void tst_QPainter::stateResetBetweenQPainters() |
|
3603 |
{ |
|
3604 |
QImage img(16, 16, QImage::Format_ARGB32); |
|
3605 |
||
3606 |
{ |
|
3607 |
QPainter p(&img); |
|
3608 |
p.setCompositionMode(QPainter::CompositionMode_Source); |
|
3609 |
p.fillRect(0, 0, 16, 16, Qt::red); |
|
3610 |
} |
|
3611 |
||
3612 |
{ |
|
3613 |
QPainter p2(&img); |
|
3614 |
p2.fillRect(0, 0, 16, 16, QColor(0, 0, 255, 63)); |
|
3615 |
} |
|
3616 |
||
3617 |
img.save("foo.png"); |
|
3618 |
||
3619 |
QVERIFY(img.pixel(0, 0) != qRgba(0, 0, 255, 63)); |
|
3620 |
QVERIFY(qRed(img.pixel(0, 0)) > 0); // We didn't erase the red channel... |
|
3621 |
QVERIFY(qBlue(img.pixel(0, 0)) < 255); // We blended the blue channel |
|
3622 |
} |
|
3623 |
||
3624 |
void tst_QPainter::drawRect_task215378() |
|
3625 |
{ |
|
3626 |
QImage img(11, 11, QImage::Format_ARGB32_Premultiplied); |
|
3627 |
img.fill(QColor(Qt::white).rgba()); |
|
3628 |
||
3629 |
QPainter p(&img); |
|
3630 |
p.setPen(QColor(127, 127, 127, 127)); |
|
3631 |
p.drawRect(0, 0, 10, 10); |
|
3632 |
p.end(); |
|
3633 |
||
3634 |
QCOMPARE(img.pixel(0, 0), img.pixel(1, 0)); |
|
3635 |
QCOMPARE(img.pixel(0, 0), img.pixel(0, 1)); |
|
3636 |
QVERIFY(img.pixel(0, 0) != img.pixel(1, 1)); |
|
3637 |
} |
|
3638 |
||
3639 |
void tst_QPainter::drawRect_task247505() |
|
3640 |
{ |
|
3641 |
QImage a(10, 10, QImage::Format_ARGB32_Premultiplied); |
|
3642 |
a.fill(0); |
|
3643 |
QImage b = a; |
|
3644 |
||
3645 |
QPainter p(&a); |
|
3646 |
p.setPen(Qt::NoPen); |
|
3647 |
p.setBrush(Qt::black); |
|
3648 |
p.drawRect(QRectF(10, 0, -10, 10)); |
|
3649 |
p.end(); |
|
3650 |
p.begin(&b); |
|
3651 |
p.setPen(Qt::NoPen); |
|
3652 |
p.setBrush(Qt::black); |
|
3653 |
p.drawRect(QRectF(0, 0, 10, 10)); |
|
3654 |
p.end(); |
|
3655 |
||
3656 |
QCOMPARE(a, b); |
|
3657 |
} |
|
3658 |
||
3659 |
void tst_QPainter::drawImage_data() |
|
3660 |
{ |
|
3661 |
QTest::addColumn<int>("x"); |
|
3662 |
QTest::addColumn<int>("y"); |
|
3663 |
QTest::addColumn<int>("w"); |
|
3664 |
QTest::addColumn<int>("h"); |
|
3665 |
QTest::addColumn<QImage::Format>("srcFormat"); |
|
3666 |
QTest::addColumn<QImage::Format>("dstFormat"); |
|
3667 |
||
3668 |
for (int srcFormat = QImage::Format_Mono; srcFormat < QImage::NImageFormats; ++srcFormat) { |
|
3669 |
for (int dstFormat = QImage::Format_Mono; dstFormat < QImage::NImageFormats; ++dstFormat) { |
|
3670 |
if (dstFormat == QImage::Format_Indexed8) |
|
3671 |
continue; |
|
3672 |
for (int odd_x = 0; odd_x <= 1; ++odd_x) { |
|
3673 |
for (int odd_width = 0; odd_width <= 1; ++odd_width) { |
|
3674 |
QString description = |
|
3675 |
QString("srcFormat %1, dstFormat %2, odd x: %3, odd width: %4") |
|
3676 |
.arg(srcFormat).arg(dstFormat).arg(odd_x).arg(odd_width); |
|
3677 |
||
3678 |
QTest::newRow(qPrintable(description)) << (10 + odd_x) << 10 << (20 + odd_width) << 20 |
|
3679 |
<< QImage::Format(srcFormat) |
|
3680 |
<< QImage::Format(dstFormat); |
|
3681 |
} |
|
3682 |
} |
|
3683 |
} |
|
3684 |
} |
|
3685 |
} |
|
3686 |
||
3687 |
bool verifyImage(const QImage &img, int x, int y, int w, int h, uint background) |
|
3688 |
{ |
|
3689 |
int imgWidth = img.width(); |
|
3690 |
int imgHeight = img.height(); |
|
3691 |
for (int i = 0; i < imgHeight; ++i) { |
|
3692 |
for (int j = 0; j < imgWidth; ++j) { |
|
3693 |
uint pixel = img.pixel(j, i); |
|
3694 |
bool outside = j < x || j >= (x + w) || i < y || i >= (y + h); |
|
3695 |
if (outside != (pixel == background)) { |
|
3696 |
//printf("%d %d, expected %x, got %x, outside: %d\n", x, y, background, pixel, outside); |
|
3697 |
return false; |
|
3698 |
} |
|
3699 |
} |
|
3700 |
} |
|
3701 |
||
3702 |
return true; |
|
3703 |
} |
|
3704 |
||
3705 |
void tst_QPainter::drawImage() |
|
3706 |
{ |
|
3707 |
QFETCH(int, x); |
|
3708 |
QFETCH(int, y); |
|
3709 |
QFETCH(int, w); |
|
3710 |
QFETCH(int, h); |
|
3711 |
QFETCH(QImage::Format, srcFormat); |
|
3712 |
QFETCH(QImage::Format, dstFormat); |
|
3713 |
||
3714 |
QImage dst(40, 40, QImage::Format_RGB32); |
|
3715 |
dst.fill(0xffffffff); |
|
3716 |
||
3717 |
dst = dst.convertToFormat(dstFormat); |
|
3718 |
uint background = dst.pixel(0, 0); |
|
3719 |
||
3720 |
QImage src(w, h, QImage::Format_RGB32); |
|
3721 |
src.fill(0xff000000); |
|
3722 |
src = src.convertToFormat(srcFormat); |
|
3723 |
||
3724 |
QPainter p(&dst); |
|
3725 |
p.drawImage(x, y, src); |
|
3726 |
p.end(); |
|
3727 |
||
3728 |
QVERIFY(verifyImage(dst, x, y, w, h, background)); |
|
3729 |
} |
|
3730 |
||
3731 |
void tst_QPainter::imageCoordinateLimit() |
|
3732 |
{ |
|
3733 |
QImage img(64, 40000, QImage::Format_MonoLSB); |
|
3734 |
QPainter p(&img); |
|
3735 |
p.drawText(10, 36000, QLatin1String("foo")); |
|
3736 |
p.setPen(QPen(Qt::black, 2)); |
|
3737 |
p.drawLine(10, 0, 60, 40000); |
|
3738 |
||
3739 |
p.setRenderHint(QPainter::Antialiasing); |
|
3740 |
p.drawLine(10, 0, 60, 40000); |
|
3741 |
} |
|
3742 |
||
3743 |
||
3744 |
void tst_QPainter::imageBlending_data() |
|
3745 |
{ |
|
3746 |
QTest::addColumn<QImage::Format>("sourceFormat"); |
|
3747 |
QTest::addColumn<QImage::Format>("destFormat"); |
|
3748 |
QTest::addColumn<int>("error"); |
|
3749 |
||
3750 |
int error_rgb565 = ((1<<3) + (1<<2) + (1<<3)); |
|
3751 |
QTest::newRow("rgb565_on_rgb565") << QImage::Format_RGB16 |
|
3752 |
<< QImage::Format_RGB16 |
|
3753 |
<< 0; |
|
3754 |
QTest::newRow("argb8565_on_rgb565") << QImage::Format_ARGB8565_Premultiplied |
|
3755 |
<< QImage::Format_RGB16 |
|
3756 |
<< error_rgb565; |
|
3757 |
||
3758 |
QTest::newRow("rgb32_on_rgb565") << QImage::Format_RGB32 |
|
3759 |
<< QImage::Format_RGB16 |
|
3760 |
<< error_rgb565; |
|
3761 |
||
3762 |
QTest::newRow("argb32pm_on_rgb565") << QImage::Format_ARGB32_Premultiplied |
|
3763 |
<< QImage::Format_RGB16 |
|
3764 |
<< error_rgb565; |
|
3765 |
} |
|
3766 |
||
3767 |
int diffColor(quint32 ap, quint32 bp) |
|
3768 |
{ |
|
3769 |
int a = qAlpha(ap) - qAlpha(bp); |
|
3770 |
int r = qRed(ap) - qRed(bp); |
|
3771 |
int b = qBlue(ap) - qBlue(bp); |
|
3772 |
int g = qBlue(ap) - qBlue(bp); |
|
3773 |
||
3774 |
return qAbs(a) + qAbs(r) + qAbs(g) + qAbs(b); |
|
3775 |
} |
|
3776 |
||
3777 |
// this test assumes premultiplied pixels... |
|
3778 |
||
3779 |
void tst_QPainter::imageBlending() |
|
3780 |
{ |
|
3781 |
QFETCH(QImage::Format, sourceFormat); |
|
3782 |
QFETCH(QImage::Format, destFormat); |
|
3783 |
QFETCH(int, error); |
|
3784 |
||
3785 |
QImage dest; |
|
3786 |
{ |
|
3787 |
QImage orig_dest(6, 6, QImage::Format_ARGB32_Premultiplied); |
|
3788 |
orig_dest.fill(0); |
|
3789 |
QPainter p(&orig_dest); |
|
3790 |
p.fillRect(0, 0, 6, 3, QColor::fromRgbF(1, 0, 0)); |
|
3791 |
p.fillRect(3, 0, 3, 6, QColor::fromRgbF(0, 0, 1, 0.5)); |
|
3792 |
p.end(); |
|
3793 |
dest = orig_dest.convertToFormat(destFormat); |
|
3794 |
||
3795 |
// An image like this: (r = red, m = magenta, b = light alpha blue, 0 = transparent) |
|
3796 |
// r r r m m m |
|
3797 |
// r r r m m m |
|
3798 |
// r r r m m m |
|
3799 |
// 0 0 0 b b b |
|
3800 |
// 0 0 0 b b b |
|
3801 |
// 0 0 0 b b b |
|
3802 |
} |
|
3803 |
||
3804 |
QImage source; |
|
3805 |
{ |
|
3806 |
QImage orig_source(6, 6, QImage::Format_ARGB32_Premultiplied); |
|
3807 |
orig_source.fill(0); |
|
3808 |
QPainter p(&orig_source); |
|
3809 |
p.fillRect(1, 1, 4, 4, QColor::fromRgbF(0, 1, 0, 0.5)); |
|
3810 |
p.fillRect(2, 2, 2, 2, QColor::fromRgbF(0, 1, 0)); |
|
3811 |
p.end(); |
|
3812 |
source = orig_source.convertToFormat(sourceFormat); |
|
3813 |
||
3814 |
// An image like this: (0 = transparent, . = green at 0.5 alpha, g = opaque green. |
|
3815 |
// 0 0 0 0 0 0 |
|
3816 |
// 0 . . . . 0 |
|
3817 |
// 0 . g g . 0 |
|
3818 |
// 0 . g g . 0 |
|
3819 |
// 0 . . . . 0 |
|
3820 |
// 0 0 0 0 0 0 |
|
3821 |
} |
|
3822 |
||
3823 |
QPainter p(&dest); |
|
3824 |
p.drawImage(0, 0, source); |
|
3825 |
p.end(); |
|
3826 |
||
3827 |
// resulting image: |
|
3828 |
// r r r m m m |
|
3829 |
// r r. r. m. m. m |
|
3830 |
// r r. g g m. m |
|
3831 |
// 0 . g g b. b |
|
3832 |
// 0 . . b. b. b |
|
3833 |
// 0 0 0 b b b |
|
3834 |
||
3835 |
// the g pixels, always green.. |
|
3836 |
QVERIFY(diffColor(dest.pixel(2, 2), 0xff00ff00) <= error); // g |
|
3837 |
||
3838 |
if (source.hasAlphaChannel()) { |
|
3839 |
QVERIFY(diffColor(dest.pixel(0, 0), 0xffff0000) <= error); // r |
|
3840 |
QVERIFY(diffColor(dest.pixel(5, 0), 0xff7f007f) <= error); // m |
|
3841 |
QVERIFY(diffColor(dest.pixel(1, 1), 0xff7f7f00) <= error); // r. |
|
3842 |
QVERIFY(diffColor(dest.pixel(4, 1), 0xff3f7f3f) <= error); // m. |
|
3843 |
if (dest.hasAlphaChannel()) { |
|
3844 |
QVERIFY(diffColor(dest.pixel(1, 3), 0x7f007f00) <= error); // . |
|
3845 |
QVERIFY(diffColor(dest.pixel(4, 3), 0x7f007f3f) <= error); // b. |
|
3846 |
QVERIFY(diffColor(dest.pixel(4, 3), 0x7f007f3f) <= error); // b. |
|
3847 |
QVERIFY(diffColor(dest.pixel(4, 4), 0x7f00007f) <= error); // b |
|
3848 |
QVERIFY(diffColor(dest.pixel(4, 0), 0) <= 0); // 0 |
|
3849 |
} |
|
3850 |
} else { |
|
3851 |
QVERIFY(diffColor(dest.pixel(0, 0), 0xff000000) <= 0); |
|
3852 |
QVERIFY(diffColor(dest.pixel(1, 1), 0xff007f00) <= error); |
|
3853 |
} |
|
3854 |
} |
|
3855 |
||
3856 |
void tst_QPainter::imageBlending_clipped() |
|
3857 |
{ |
|
3858 |
QImage src(20, 20, QImage::Format_RGB16); |
|
3859 |
QPainter p(&src); |
|
3860 |
p.fillRect(src.rect(), Qt::red); |
|
3861 |
p.end(); |
|
3862 |
||
3863 |
QImage dst(40, 20, QImage::Format_RGB16); |
|
3864 |
p.begin(&dst); |
|
3865 |
p.fillRect(dst.rect(), Qt::white); |
|
3866 |
p.end(); |
|
3867 |
||
3868 |
QImage expected = dst; |
|
3869 |
||
3870 |
p.begin(&dst); |
|
3871 |
p.setClipRect(QRect(23, 0, 20, 20)); |
|
3872 |
||
3873 |
// should be completely clipped |
|
3874 |
p.drawImage(QRectF(3, 0, 20, 20), src); |
|
3875 |
p.end(); |
|
3876 |
||
3877 |
// dst should be left unchanged |
|
3878 |
QCOMPARE(dst, expected); |
|
3879 |
} |
|
3880 |
||
3881 |
void tst_QPainter::paintOnNullPixmap() |
|
3882 |
{ |
|
3883 |
QPixmap pix(16, 16); |
|
3884 |
||
3885 |
QPixmap textPixmap; |
|
3886 |
QPainter p(&textPixmap); |
|
3887 |
p.drawPixmap(10, 10, pix); |
|
3888 |
p.end(); |
|
3889 |
||
3890 |
QPixmap textPixmap2(16,16); |
|
3891 |
p.begin(&textPixmap2); |
|
3892 |
p.end(); |
|
3893 |
} |
|
3894 |
||
3895 |
void tst_QPainter::checkCompositionMode() |
|
3896 |
{ |
|
3897 |
QImage refImage(50,50,QImage::Format_ARGB32); |
|
3898 |
QPainter painter(&refImage); |
|
3899 |
painter.fillRect(QRect(0,0,50,50),Qt::blue); |
|
3900 |
||
3901 |
QImage testImage(50,50,QImage::Format_ARGB32); |
|
3902 |
QPainter p(&testImage); |
|
3903 |
p.fillRect(QRect(0,0,50,50),Qt::red); |
|
3904 |
p.save(); |
|
3905 |
p.setCompositionMode(QPainter::CompositionMode_SourceOut); |
|
3906 |
p.restore(); |
|
3907 |
p.fillRect(QRect(0,0,50,50),Qt::blue); |
|
3908 |
||
3909 |
QCOMPARE(refImage.pixel(20,20),testImage.pixel(20,20)); |
|
3910 |
} |
|
3911 |
||
3912 |
static QLinearGradient inverseGradient(QLinearGradient g) |
|
3913 |
{ |
|
3914 |
QLinearGradient g2 = g; |
|
3915 |
||
3916 |
QGradientStops stops = g.stops(); |
|
3917 |
||
3918 |
QGradientStops inverse; |
|
3919 |
foreach (QGradientStop stop, stops) |
|
3920 |
inverse << QGradientStop(1 - stop.first, stop.second); |
|
3921 |
||
3922 |
g2.setStops(inverse); |
|
3923 |
return g2; |
|
3924 |
} |
|
3925 |
||
3926 |
void tst_QPainter::linearGradientSymmetry() |
|
3927 |
{ |
|
3928 |
QImage a(64, 8, QImage::Format_ARGB32_Premultiplied); |
|
3929 |
QImage b(64, 8, QImage::Format_ARGB32_Premultiplied); |
|
3930 |
||
3931 |
a.fill(0); |
|
3932 |
b.fill(0); |
|
3933 |
||
3934 |
QLinearGradient gradient(QRectF(b.rect()).topLeft(), QRectF(b.rect()).topRight()); |
|
3935 |
gradient.setColorAt(0.0, Qt::blue); |
|
3936 |
gradient.setColorAt(0.2, QColor(220, 220, 220, 0)); |
|
3937 |
gradient.setColorAt(0.6, Qt::red); |
|
3938 |
gradient.setColorAt(0.9, QColor(220, 220, 220, 255)); |
|
3939 |
gradient.setColorAt(1.0, Qt::black); |
|
3940 |
||
3941 |
QPainter pa(&a); |
|
3942 |
pa.fillRect(a.rect(), gradient); |
|
3943 |
pa.end(); |
|
3944 |
||
3945 |
QPainter pb(&b); |
|
3946 |
pb.fillRect(b.rect(), inverseGradient(gradient)); |
|
3947 |
pb.end(); |
|
3948 |
||
3949 |
b = b.mirrored(true); |
|
3950 |
QCOMPARE(a, b); |
|
3951 |
} |
|
3952 |
||
3953 |
void tst_QPainter::gradientInterpolation() |
|
3954 |
{ |
|
3955 |
QImage image(256, 8, QImage::Format_ARGB32_Premultiplied); |
|
3956 |
QPainter painter; |
|
3957 |
||
3958 |
QLinearGradient gradient(QRectF(image.rect()).topLeft(), QRectF(image.rect()).topRight()); |
|
3959 |
gradient.setColorAt(0.0, QColor(255, 0, 0, 0)); |
|
3960 |
gradient.setColorAt(1.0, Qt::blue); |
|
3961 |
||
3962 |
image.fill(0); |
|
3963 |
painter.begin(&image); |
|
3964 |
painter.fillRect(image.rect(), gradient); |
|
3965 |
painter.end(); |
|
3966 |
||
3967 |
const QRgb *line = reinterpret_cast<QRgb *>(image.scanLine(3)); |
|
3968 |
||
3969 |
for (int i = 0; i < 256; ++i) { |
|
3970 |
QCOMPARE(qAlpha(line[i]), qBlue(line[i])); // bright blue |
|
3971 |
QVERIFY(qAbs(qAlpha(line[i]) - i) < 3); // linear alpha |
|
3972 |
QCOMPARE(qRed(line[i]), 0); // no red component |
|
3973 |
QCOMPARE(qGreen(line[i]), 0); // no green component |
|
3974 |
} |
|
3975 |
||
3976 |
gradient.setInterpolationMode(QGradient::ComponentInterpolation); |
|
3977 |
||
3978 |
image.fill(0); |
|
3979 |
painter.begin(&image); |
|
3980 |
painter.fillRect(image.rect(), gradient); |
|
3981 |
painter.end(); |
|
3982 |
||
3983 |
for (int i = 1; i < 256; ++i) { |
|
3984 |
if (i < 128) { |
|
3985 |
QVERIFY(qRed(line[i]) >= qBlue(line[i])); // red is dominant |
|
3986 |
} else { |
|
3987 |
QVERIFY(qRed(line[i]) <= qBlue(line[i])); // blue is dominant |
|
3988 |
} |
|
3989 |
QVERIFY((qRed(line[i]) - 0.5) * (qAlpha(line[i - 1]) - 0.5) <= (qRed(line[i - 1]) + 0.5) * (qAlpha(line[i]) + 0.5)); // decreasing red |
|
3990 |
QVERIFY((qBlue(line[i]) + 0.5) * (qAlpha(line[i - 1]) + 0.5) >= (qBlue(line[i - 1]) - 0.5) * (qAlpha(line[i]) - 0.5)); // increasing blue |
|
3991 |
QVERIFY(qAbs(qAlpha(line[i]) - i) < 3); // linear alpha |
|
3992 |
QCOMPARE(qGreen(line[i]), 0); // no green component |
|
3993 |
} |
|
3994 |
} |
|
3995 |
||
3996 |
void tst_QPainter::drawPolygon() |
|
3997 |
{ |
|
3998 |
QImage img(128, 128, QImage::Format_ARGB32_Premultiplied); |
|
3999 |
||
4000 |
QPainterPathStroker stroker; |
|
4001 |
stroker.setWidth(1.5); |
|
4002 |
||
4003 |
QPainterPath path; |
|
4004 |
path.moveTo(2, 34); |
|
4005 |
path.lineTo(34, 2); |
|
4006 |
||
4007 |
QPolygonF poly = stroker.createStroke(path).toFillPolygon(); |
|
4008 |
||
4009 |
img.fill(0xffffffff); |
|
4010 |
QPainter p(&img); |
|
4011 |
p.setRenderHint(QPainter::Antialiasing); |
|
4012 |
p.setBrush(Qt::red); |
|
4013 |
p.setPen(Qt::NoPen); |
|
4014 |
p.drawPolygon(poly); |
|
4015 |
p.translate(64, 64); |
|
4016 |
p.drawPolygon(poly); |
|
4017 |
p.end(); |
|
4018 |
||
4019 |
QImage a = img.copy(); |
|
4020 |
||
4021 |
img.fill(0xffffffff); |
|
4022 |
p.begin(&img); |
|
4023 |
p.setRenderHint(QPainter::Antialiasing); |
|
4024 |
p.setBrush(Qt::red); |
|
4025 |
p.setPen(Qt::NoPen); |
|
4026 |
p.translate(64, 64); |
|
4027 |
p.drawPolygon(poly); |
|
4028 |
p.resetTransform(); |
|
4029 |
p.drawPolygon(poly); |
|
4030 |
p.end(); |
|
4031 |
||
4032 |
QCOMPARE(a, img); |
|
4033 |
} |
|
4034 |
||
4035 |
void tst_QPainter::inactivePainter() |
|
4036 |
{ |
|
4037 |
// This test succeeds if it doesn't segfault. |
|
4038 |
||
4039 |
QPainter p; |
|
4040 |
QPainterPath path; |
|
4041 |
QRegion region(QRect(20, 20, 60, 40)); |
|
4042 |
QPolygonF polygon(QVector<QPointF>() << QPointF(0, 0) << QPointF(12, 0) << QPointF(8, 6)); |
|
4043 |
path.addPolygon(polygon); |
|
4044 |
||
4045 |
p.save(); |
|
4046 |
p.restore(); |
|
4047 |
||
4048 |
p.background(); |
|
4049 |
p.setBackground(QBrush(Qt::blue)); |
|
4050 |
||
4051 |
p.brush(); |
|
4052 |
p.setBrush(Qt::red); |
|
4053 |
p.setBrush(Qt::NoBrush); |
|
4054 |
p.setBrush(QBrush(Qt::white, Qt::DiagCrossPattern)); |
|
4055 |
||
4056 |
p.backgroundMode(); |
|
4057 |
p.setBackgroundMode(Qt::OpaqueMode); |
|
4058 |
||
4059 |
p.boundingRect(QRectF(0, 0, 100, 20), Qt::AlignCenter, QLatin1String("Hello, World!")); |
|
4060 |
p.boundingRect(QRect(0, 0, 100, 20), Qt::AlignCenter, QLatin1String("Hello, World!")); |
|
4061 |
||
4062 |
p.brushOrigin(); |
|
4063 |
p.setBrushOrigin(QPointF(12, 34)); |
|
4064 |
p.setBrushOrigin(QPoint(12, 34)); |
|
4065 |
||
4066 |
p.clipPath(); |
|
4067 |
p.clipRegion(); |
|
4068 |
p.hasClipping(); |
|
4069 |
p.setClipPath(path); |
|
4070 |
p.setClipRect(QRectF(42, 42, 42, 42)); |
|
4071 |
p.setClipRect(QRect(42, 42, 42, 42)); |
|
4072 |
p.setClipRegion(region); |
|
4073 |
p.setClipping(true); |
|
4074 |
||
4075 |
p.combinedMatrix(); |
|
4076 |
p.combinedTransform(); |
|
4077 |
||
4078 |
p.compositionMode(); |
|
4079 |
p.setCompositionMode(QPainter::CompositionMode_Plus); |
|
4080 |
||
4081 |
p.device(); |
|
4082 |
p.deviceMatrix(); |
|
4083 |
p.deviceTransform(); |
|
4084 |
||
4085 |
p.font(); |
|
4086 |
p.setFont(QFont(QLatin1String("Times"), 24)); |
|
4087 |
||
4088 |
p.fontInfo(); |
|
4089 |
p.fontMetrics(); |
|
4090 |
||
4091 |
p.layoutDirection(); |
|
4092 |
p.setLayoutDirection(Qt::RightToLeft); |
|
4093 |
||
4094 |
p.opacity(); |
|
4095 |
p.setOpacity(0.75); |
|
4096 |
||
4097 |
p.pen(); |
|
4098 |
p.setPen(QPen(Qt::red)); |
|
4099 |
p.setPen(Qt::green); |
|
4100 |
p.setPen(Qt::NoPen); |
|
4101 |
||
4102 |
p.renderHints(); |
|
4103 |
p.setRenderHint(QPainter::Antialiasing, true); |
|
4104 |
p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, false); |
|
4105 |
||
4106 |
p.resetMatrix(); |
|
4107 |
p.resetTransform(); |
|
4108 |
p.rotate(1); |
|
4109 |
p.scale(2, 2); |
|
4110 |
p.shear(-1, 1); |
|
4111 |
p.translate(3, 14); |
|
4112 |
||
4113 |
p.viewTransformEnabled(); |
|
4114 |
p.setViewTransformEnabled(true); |
|
4115 |
||
4116 |
p.viewport(); |
|
4117 |
p.setViewport(QRect(10, 10, 620, 460)); |
|
4118 |
||
4119 |
p.window(); |
|
4120 |
p.setWindow(QRect(10, 10, 620, 460)); |
|
4121 |
||
4122 |
p.worldMatrix(); |
|
4123 |
p.setWorldMatrix(QMatrix().translate(43, 21), true); |
|
4124 |
p.setWorldMatrixEnabled(true); |
|
4125 |
||
4126 |
p.transform(); |
|
4127 |
p.setTransform(QTransform().translate(12, 34), true); |
|
4128 |
||
4129 |
p.worldTransform(); |
|
4130 |
p.setWorldTransform(QTransform().scale(0.5, 0.5), true); |
|
4131 |
} |
|
4132 |
||
4133 |
bool testCompositionMode(int src, int dst, int expected, QPainter::CompositionMode op) |
|
4134 |
{ |
|
4135 |
QImage actual(1, 1, QImage::Format_ARGB32_Premultiplied); |
|
4136 |
actual.fill(QColor(dst, dst, dst).rgb()); |
|
4137 |
||
4138 |
QPainter p(&actual); |
|
4139 |
p.setCompositionMode(op); |
|
4140 |
p.fillRect(0, 0, 1, 1, QColor(src, src, src)); |
|
4141 |
p.end(); |
|
4142 |
||
4143 |
if (qRed(actual.pixel(0, 0)) != expected) { |
|
4144 |
qDebug("Fail: mode %d, src[%d] dst [%d] actual [%d] expected [%d]", op, |
|
4145 |
src, dst, qRed(actual.pixel(0, 0)), expected); |
|
4146 |
return false; |
|
4147 |
} else { |
|
4148 |
return true; |
|
4149 |
} |
|
4150 |
} |
|
4151 |
||
4152 |
void tst_QPainter::extendedBlendModes() |
|
4153 |
{ |
|
4154 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_Plus)); |
|
4155 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Plus)); |
|
4156 |
QVERIFY(testCompositionMode(127, 128, 255, QPainter::CompositionMode_Plus)); |
|
4157 |
QVERIFY(testCompositionMode(127, 0, 127, QPainter::CompositionMode_Plus)); |
|
4158 |
QVERIFY(testCompositionMode( 0, 127, 127, QPainter::CompositionMode_Plus)); |
|
4159 |
QVERIFY(testCompositionMode(255, 0, 255, QPainter::CompositionMode_Plus)); |
|
4160 |
QVERIFY(testCompositionMode( 0, 255, 255, QPainter::CompositionMode_Plus)); |
|
4161 |
QVERIFY(testCompositionMode(128, 128, 255, QPainter::CompositionMode_Plus)); |
|
4162 |
||
4163 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_Multiply)); |
|
4164 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Multiply)); |
|
4165 |
QVERIFY(testCompositionMode(127, 255, 127, QPainter::CompositionMode_Multiply)); |
|
4166 |
QVERIFY(testCompositionMode(255, 127, 127, QPainter::CompositionMode_Multiply)); |
|
4167 |
QVERIFY(testCompositionMode( 63, 255, 63, QPainter::CompositionMode_Multiply)); |
|
4168 |
QVERIFY(testCompositionMode(255, 63, 63, QPainter::CompositionMode_Multiply)); |
|
4169 |
QVERIFY(testCompositionMode(127, 127, 63, QPainter::CompositionMode_Multiply)); |
|
4170 |
||
4171 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_Screen)); |
|
4172 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Screen)); |
|
4173 |
QVERIFY(testCompositionMode( 63, 255, 255, QPainter::CompositionMode_Screen)); |
|
4174 |
QVERIFY(testCompositionMode(255, 63, 255, QPainter::CompositionMode_Screen)); |
|
4175 |
QVERIFY(testCompositionMode( 63, 0, 63, QPainter::CompositionMode_Screen)); |
|
4176 |
QVERIFY(testCompositionMode( 0, 63, 63, QPainter::CompositionMode_Screen)); |
|
4177 |
QVERIFY(testCompositionMode(127, 127, 191, QPainter::CompositionMode_Screen)); |
|
4178 |
||
4179 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_Overlay)); |
|
4180 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Overlay)); |
|
4181 |
QVERIFY(testCompositionMode( 63, 63, 31, QPainter::CompositionMode_Overlay)); |
|
4182 |
QVERIFY(testCompositionMode( 63, 255, 255, QPainter::CompositionMode_Overlay)); |
|
4183 |
||
4184 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_Darken)); |
|
4185 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Darken)); |
|
4186 |
QVERIFY(testCompositionMode( 63, 63, 63, QPainter::CompositionMode_Darken)); |
|
4187 |
QVERIFY(testCompositionMode( 63, 255, 63, QPainter::CompositionMode_Darken)); |
|
4188 |
QVERIFY(testCompositionMode(255, 63, 63, QPainter::CompositionMode_Darken)); |
|
4189 |
QVERIFY(testCompositionMode( 63, 127, 63, QPainter::CompositionMode_Darken)); |
|
4190 |
QVERIFY(testCompositionMode(127, 63, 63, QPainter::CompositionMode_Darken)); |
|
4191 |
||
4192 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_Lighten)); |
|
4193 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Lighten)); |
|
4194 |
QVERIFY(testCompositionMode( 63, 63, 63, QPainter::CompositionMode_Lighten)); |
|
4195 |
QVERIFY(testCompositionMode( 63, 255, 255, QPainter::CompositionMode_Lighten)); |
|
4196 |
QVERIFY(testCompositionMode(255, 63, 255, QPainter::CompositionMode_Lighten)); |
|
4197 |
QVERIFY(testCompositionMode( 63, 127, 127, QPainter::CompositionMode_Lighten)); |
|
4198 |
QVERIFY(testCompositionMode(127, 63, 127, QPainter::CompositionMode_Lighten)); |
|
4199 |
||
4200 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_ColorDodge)); |
|
4201 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_ColorDodge)); |
|
4202 |
QVERIFY(testCompositionMode( 63, 127, 169, QPainter::CompositionMode_ColorDodge)); |
|
4203 |
QVERIFY(testCompositionMode(191, 127, 255, QPainter::CompositionMode_ColorDodge)); |
|
4204 |
QVERIFY(testCompositionMode(127, 191, 255, QPainter::CompositionMode_ColorDodge)); |
|
4205 |
||
4206 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_ColorBurn)); |
|
4207 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_ColorBurn)); |
|
4208 |
QVERIFY(testCompositionMode(127, 127, 0, QPainter::CompositionMode_ColorBurn)); |
|
4209 |
QVERIFY(testCompositionMode(128, 128, 2, QPainter::CompositionMode_ColorBurn)); |
|
4210 |
QVERIFY(testCompositionMode(191, 127, 84, QPainter::CompositionMode_ColorBurn)); |
|
4211 |
||
4212 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_HardLight)); |
|
4213 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_HardLight)); |
|
4214 |
QVERIFY(testCompositionMode(127, 127, 127, QPainter::CompositionMode_HardLight)); |
|
4215 |
QVERIFY(testCompositionMode( 63, 63, 31, QPainter::CompositionMode_HardLight)); |
|
4216 |
QVERIFY(testCompositionMode(127, 63, 63, QPainter::CompositionMode_HardLight)); |
|
4217 |
||
4218 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_SoftLight)); |
|
4219 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_SoftLight)); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4220 |
QVERIFY(testCompositionMode(127, 127, 126, QPainter::CompositionMode_SoftLight)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4221 |
QVERIFY(testCompositionMode( 63, 63, 39, QPainter::CompositionMode_SoftLight)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4222 |
QVERIFY(testCompositionMode(127, 63, 62, QPainter::CompositionMode_SoftLight)); |
0 | 4223 |
|
4224 |
QVERIFY(testCompositionMode(255, 255, 0, QPainter::CompositionMode_Difference)); |
|
4225 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Difference)); |
|
4226 |
QVERIFY(testCompositionMode(255, 0, 255, QPainter::CompositionMode_Difference)); |
|
4227 |
QVERIFY(testCompositionMode(127, 127, 0, QPainter::CompositionMode_Difference)); |
|
4228 |
QVERIFY(testCompositionMode(127, 128, 1, QPainter::CompositionMode_Difference)); |
|
4229 |
QVERIFY(testCompositionMode(127, 63, 64, QPainter::CompositionMode_Difference)); |
|
4230 |
QVERIFY(testCompositionMode( 0, 127, 127, QPainter::CompositionMode_Difference)); |
|
4231 |
||
4232 |
QVERIFY(testCompositionMode(255, 255, 0, QPainter::CompositionMode_Exclusion)); |
|
4233 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Exclusion)); |
|
4234 |
QVERIFY(testCompositionMode(255, 0, 255, QPainter::CompositionMode_Exclusion)); |
|
4235 |
QVERIFY(testCompositionMode(127, 127, 127, QPainter::CompositionMode_Exclusion)); |
|
4236 |
QVERIFY(testCompositionMode( 63, 127, 127, QPainter::CompositionMode_Exclusion)); |
|
4237 |
QVERIFY(testCompositionMode( 63, 63, 95, QPainter::CompositionMode_Exclusion)); |
|
4238 |
QVERIFY(testCompositionMode(191, 191, 96, QPainter::CompositionMode_Exclusion)); |
|
4239 |
} |
|
4240 |
||
4241 |
void tst_QPainter::zeroOpacity() |
|
4242 |
{ |
|
4243 |
QImage source(1, 1, QImage::Format_ARGB32_Premultiplied); |
|
4244 |
source.fill(0xffffffff); |
|
4245 |
||
4246 |
QImage target(1, 1, QImage::Format_RGB32); |
|
4247 |
target.fill(0xff000000); |
|
4248 |
||
4249 |
QPainter p(&target); |
|
4250 |
p.setOpacity(0.0); |
|
4251 |
p.drawImage(0, 0, source); |
|
4252 |
p.end(); |
|
4253 |
||
4254 |
QCOMPARE(target.pixel(0, 0), 0xff000000); |
|
4255 |
} |
|
4256 |
||
4257 |
void tst_QPainter::clippingBug() |
|
4258 |
{ |
|
4259 |
QImage img(32, 32, QImage::Format_ARGB32_Premultiplied); |
|
4260 |
img.fill(0); |
|
4261 |
||
4262 |
QImage expected = img; |
|
4263 |
QPainter p(&expected); |
|
4264 |
p.fillRect(1, 1, 30, 30, Qt::red); |
|
4265 |
p.end(); |
|
4266 |
||
4267 |
QPainterPath path; |
|
4268 |
path.addRect(1, 1, 30, 30); |
|
4269 |
path.addRect(1, 1, 30, 30); |
|
4270 |
path.addRect(1, 1, 30, 30); |
|
4271 |
||
4272 |
p.begin(&img); |
|
4273 |
p.setClipPath(path); |
|
4274 |
p.fillRect(0, 0, 32, 32, Qt::red); |
|
4275 |
p.end(); |
|
4276 |
||
4277 |
QCOMPARE(img, expected); |
|
4278 |
} |
|
4279 |
||
4280 |
void tst_QPainter::emptyClip() |
|
4281 |
{ |
|
4282 |
QImage img(64, 64, QImage::Format_ARGB32_Premultiplied); |
|
4283 |
QPainter p(&img); |
|
4284 |
p.setRenderHints(QPainter::Antialiasing); |
|
4285 |
p.setClipRect(0, 32, 64, 0); |
|
4286 |
p.fillRect(0, 0, 64, 64, Qt::white); |
|
4287 |
||
4288 |
QPainterPath path; |
|
4289 |
path.lineTo(64, 0); |
|
4290 |
path.lineTo(64, 64); |
|
4291 |
path.lineTo(40, 64); |
|
4292 |
path.lineTo(40, 80); |
|
4293 |
path.lineTo(0, 80); |
|
4294 |
||
4295 |
p.fillPath(path, Qt::green); |
|
4296 |
} |
|
4297 |
||
4298 |
void tst_QPainter::drawImage_1x1() |
|
4299 |
{ |
|
4300 |
QImage source(1, 1, QImage::Format_ARGB32_Premultiplied); |
|
4301 |
source.fill(0xffffffff); |
|
4302 |
||
4303 |
QImage img(32, 32, QImage::Format_ARGB32_Premultiplied); |
|
4304 |
img.fill(0xff000000); |
|
4305 |
QPainter p(&img); |
|
4306 |
p.drawImage(QRectF(0.9, 0.9, 32, 32), source); |
|
4307 |
p.end(); |
|
4308 |
||
4309 |
QImage expected = img; |
|
4310 |
expected.fill(0xff000000); |
|
4311 |
p.begin(&expected); |
|
4312 |
p.fillRect(1, 1, 31, 31, Qt::white); |
|
4313 |
p.end(); |
|
4314 |
||
4315 |
QCOMPARE(img, expected); |
|
4316 |
} |
|
4317 |
||
4318 |
void tst_QPainter::taskQT4444_dontOverflowDashOffset() |
|
4319 |
{ |
|
4320 |
QPainter p; |
|
4321 |
||
4322 |
QPen pen; |
|
4323 |
pen.setWidth(2); |
|
4324 |
pen.setStyle(Qt::DashDotLine); |
|
4325 |
||
4326 |
QPointF point[4]; |
|
4327 |
point[0] = QPointF(182.50868749707968,347.78457234212630); |
|
4328 |
point[1] = QPointF(182.50868749707968,107.22501998401277); |
|
4329 |
point[2] = QPointF(182.50868749707968,107.22501998401277); |
|
4330 |
point[3] = QPointF(520.46600762283651,107.22501998401277); |
|
4331 |
||
4332 |
QImage crashImage(QSize(1000, 120), QImage::Format_ARGB32_Premultiplied); |
|
4333 |
p.begin(&crashImage); |
|
4334 |
p.setPen(pen); |
|
4335 |
p.drawLines(point, 2); |
|
4336 |
p.end(); |
|
4337 |
||
4338 |
QVERIFY(true); // Don't crash |
|
4339 |
} |
|
4340 |
||
4341 |
void tst_QPainter::painterBegin() |
|
4342 |
{ |
|
4343 |
QImage nullImage; |
|
4344 |
QImage indexed8Image(16, 16, QImage::Format_Indexed8); |
|
4345 |
QImage rgb32Image(16, 16, QImage::Format_RGB32); |
|
4346 |
QImage argb32Image(16, 16, QImage::Format_ARGB32_Premultiplied); |
|
4347 |
||
4348 |
QPainter p; |
|
4349 |
||
4350 |
// Painting on null image should fail. |
|
4351 |
QVERIFY(!p.begin(&nullImage)); |
|
4352 |
||
4353 |
// Check that the painter is not messed up by using it on another image. |
|
4354 |
QVERIFY(p.begin(&rgb32Image)); |
|
4355 |
QVERIFY(p.end()); |
|
4356 |
||
4357 |
// If painting on indexed8 image fails, the painter state should still be OK. |
|
4358 |
if (p.begin(&indexed8Image)) |
|
4359 |
QVERIFY(p.end()); |
|
4360 |
QVERIFY(p.begin(&rgb32Image)); |
|
4361 |
QVERIFY(p.end()); |
|
4362 |
||
4363 |
// Try opening a painter on the two different images. |
|
4364 |
QVERIFY(p.begin(&rgb32Image)); |
|
4365 |
QVERIFY(!p.begin(&argb32Image)); |
|
4366 |
QVERIFY(p.end()); |
|
4367 |
||
4368 |
// Try opening two painters on the same image. |
|
4369 |
QVERIFY(p.begin(&rgb32Image)); |
|
4370 |
QPainter q; |
|
4371 |
QVERIFY(!q.begin(&rgb32Image)); |
|
4372 |
QVERIFY(!q.end()); |
|
4373 |
QVERIFY(p.end()); |
|
4374 |
||
4375 |
// Try ending an inactive painter. |
|
4376 |
QVERIFY(!p.end()); |
|
4377 |
} |
|
4378 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4379 |
void tst_QPainter::setPenColor(QPainter& p) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4380 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4381 |
p.setPen(Qt::NoPen); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4382 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4383 |
// Setting color, then style |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4384 |
// Should work even though the pen is "NoPen with color", temporarily. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4385 |
QPen newPen(p.pen()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4386 |
newPen.setColor(Qt::red); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4387 |
QCOMPARE(p.pen().style(), newPen.style()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4388 |
QCOMPARE(p.pen().style(), Qt::NoPen); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4389 |
p.setPen(newPen); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4390 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4391 |
QCOMPARE(p.pen().color().name(), QString("#ff0000")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4392 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4393 |
QPen newPen2(p.pen()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4394 |
newPen2.setStyle(Qt::SolidLine); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4395 |
p.setPen(newPen2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4396 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4397 |
QCOMPARE(p.pen().color().name(), QString("#ff0000")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4398 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4399 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4400 |
void tst_QPainter::setPenColorOnImage() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4401 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4402 |
QImage img(QSize(10, 10), QImage::Format_ARGB32_Premultiplied); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4403 |
QPainter p(&img); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4404 |
setPenColor(p); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4405 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4406 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4407 |
void tst_QPainter::setPenColorOnPixmap() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4408 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4409 |
QPixmap pix(10, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4410 |
QPainter p(&pix); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4411 |
setPenColor(p); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4412 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4413 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4414 |
class TestProxy : public QGraphicsProxyWidget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4415 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4416 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4417 |
TestProxy() : QGraphicsProxyWidget() {} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4418 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4419 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4420 |
QGraphicsProxyWidget::paint(painter, option, widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4421 |
deviceTransform = painter->deviceTransform(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4422 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4423 |
QTransform deviceTransform; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4424 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4425 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4426 |
class TestWidget : public QWidget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4427 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4428 |
Q_OBJECT |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4429 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4430 |
TestWidget() : QWidget(), painted(false) {} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4431 |
void paintEvent(QPaintEvent *) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4432 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4433 |
QPainter p(this); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4434 |
deviceTransform = p.deviceTransform(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4435 |
worldTransform = p.worldTransform(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4436 |
painted = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4437 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4438 |
QTransform deviceTransform; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4439 |
QTransform worldTransform; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4440 |
bool painted; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4441 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4442 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4443 |
void tst_QPainter::QTBUG5939_attachPainterPrivate() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4444 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4445 |
QWidget *w = new QWidget(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4446 |
QGraphicsScene *scene = new QGraphicsScene(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4447 |
QGraphicsView *view = new QGraphicsView(scene, w); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4448 |
view->move(50 ,50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4449 |
TestProxy *proxy = new TestProxy(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4450 |
TestWidget *widget = new TestWidget(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4451 |
proxy->setWidget(widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4452 |
scene->addItem(proxy); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4453 |
proxy->rotate(45); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4454 |
w->resize(scene->sceneRect().size().toSize()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4455 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4456 |
w->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4457 |
QTRY_VERIFY(widget->painted); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4458 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4459 |
QVERIFY(widget->worldTransform.isIdentity()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4460 |
QCOMPARE(widget->deviceTransform, proxy->deviceTransform); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4461 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4462 |
|
0 | 4463 |
QTEST_MAIN(tst_QPainter) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4464 |
|
0 | 4465 |
#include "tst_qpainter.moc" |