author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 14 May 2010 16:40:13 +0300 | |
changeset 22 | 79de32ba3296 |
parent 18 | 2f34d5167611 |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 (sizeof(qreal) != sizeof(double)) |
|
1584 |
QSKIP("Test only works for qreal==double", SkipAll); |
|
1585 |
QImage image(rect.width() + 1, rect.height() + 1, |
|
1586 |
QImage::Format_ARGB32_Premultiplied); |
|
1587 |
QRect expected = QRect(rect.x(), rect.y(), rect.width()+1, rect.height()+1) |
|
1588 |
& QRect(0, 0, image.width(), image.height()); |
|
1589 |
||
1590 |
||
1591 |
image.fill(QColor(Qt::white).rgb()); |
|
1592 |
QPainter p(&image); |
|
1593 |
p.drawEllipse(rect); |
|
1594 |
p.end(); |
|
1595 |
||
1596 |
QPixmap pixmap = QPixmap::fromImage(image); |
|
1597 |
const QRect painted = getPaintedSize(pixmap, Qt::white); |
|
1598 |
||
1599 |
QCOMPARE(painted.x(), expected.x()); |
|
1600 |
QCOMPARE(painted.y(), expected.y()); |
|
1601 |
QCOMPARE(painted.width(), expected.width()); |
|
1602 |
QCOMPARE(painted.height(), expected.height()); |
|
1603 |
||
1604 |
} |
|
1605 |
||
1606 |
void tst_QPainter::drawRoundRect() |
|
1607 |
{ |
|
1608 |
QFETCH(QRect, rect); |
|
1609 |
QFETCH(bool, usePen); |
|
1610 |
||
1611 |
#ifdef Q_WS_MAC |
|
1612 |
if (QTest::currentDataTag() == QByteArray("rect(6, 12, 3, 14) with pen") || |
|
1613 |
QTest::currentDataTag() == QByteArray("rect(6, 17, 3, 25) with pen") || |
|
1614 |
QTest::currentDataTag() == QByteArray("rect(10, 6, 10, 3) with pen") || |
|
1615 |
QTest::currentDataTag() == QByteArray("rect(10, 12, 10, 14) with pen") || |
|
1616 |
QTest::currentDataTag() == QByteArray("rect(13, 45, 17, 80) with pen") || |
|
1617 |
QTest::currentDataTag() == QByteArray("rect(13, 50, 17, 91) with pen") || |
|
1618 |
QTest::currentDataTag() == QByteArray("rect(17, 6, 24, 3) with pen") || |
|
1619 |
QTest::currentDataTag() == QByteArray("rect(24, 12, 38, 14) with pen")) |
|
1620 |
QSKIP("The Mac paint engine is off-by-one on certain rect sizes", SkipSingle); |
|
1621 |
#endif |
|
1622 |
QPixmap pixmap(rect.x() + rect.width() + 10, |
|
1623 |
rect.y() + rect.height() + 10); |
|
1624 |
{ |
|
1625 |
pixmap.fill(Qt::white); |
|
1626 |
QPainter p(&pixmap); |
|
1627 |
p.setPen(usePen ? QPen(Qt::black) : QPen(Qt::NoPen)); |
|
1628 |
p.setBrush(Qt::black); |
|
1629 |
p.drawRoundRect(rect); |
|
1630 |
p.end(); |
|
1631 |
||
1632 |
int increment = usePen ? 1 : 0; |
|
1633 |
||
1634 |
const QRect painted = getPaintedSize(pixmap, Qt::white); |
|
1635 |
QCOMPARE(painted.width(), rect.width() + increment); |
|
1636 |
QCOMPARE(painted.height(), rect.height() + increment); |
|
1637 |
} |
|
1638 |
||
1639 |
#ifdef QT3_SUPPORT |
|
1640 |
{ |
|
1641 |
pixmap.fill(Qt::white); |
|
1642 |
Q3Painter p(&pixmap); |
|
1643 |
p.setPen(usePen ? QPen(Qt::black) : QPen(Qt::NoPen)); |
|
1644 |
p.setBrush(Qt::black); |
|
1645 |
p.drawRoundRect(rect); |
|
1646 |
p.end(); |
|
1647 |
||
1648 |
const QRect painted = getPaintedSize(pixmap, Qt::white); |
|
1649 |
||
1650 |
QCOMPARE(painted.width(), rect.width()); |
|
1651 |
QCOMPARE(painted.height(), rect.height()); |
|
1652 |
} |
|
1653 |
#endif |
|
1654 |
} |
|
1655 |
||
1656 |
Q_DECLARE_METATYPE(QImage::Format) |
|
1657 |
||
1658 |
void tst_QPainter::qimageFormats_data() |
|
1659 |
{ |
|
1660 |
QTest::addColumn<QImage::Format>("format"); |
|
1661 |
QTest::newRow("QImage::Format_RGB32") << QImage::Format_RGB32; |
|
1662 |
QTest::newRow("QImage::Format_ARGB32") << QImage::Format_ARGB32; |
|
1663 |
QTest::newRow("QImage::Format_ARGB32_Premultiplied") << QImage::Format_ARGB32_Premultiplied; |
|
1664 |
QTest::newRow("QImage::Format_RGB16") << QImage::Format_RGB16; |
|
1665 |
QTest::newRow("Qimage::Format_ARGB8565_Premultiplied") << QImage::Format_ARGB8565_Premultiplied; |
|
1666 |
QTest::newRow("Qimage::Format_RGB666") << QImage::Format_RGB666; |
|
1667 |
QTest::newRow("Qimage::Format_RGB555") << QImage::Format_RGB555; |
|
1668 |
QTest::newRow("Qimage::Format_ARGB8555_Premultiplied") << QImage::Format_ARGB8555_Premultiplied; |
|
1669 |
QTest::newRow("Qimage::Format_RGB888") << QImage::Format_RGB888; |
|
1670 |
} |
|
1671 |
||
1672 |
/* |
|
1673 |
Tests that QPainter can paint on various QImage formats. |
|
1674 |
*/ |
|
1675 |
void tst_QPainter::qimageFormats() |
|
1676 |
{ |
|
1677 |
QFETCH(QImage::Format, format); |
|
1678 |
||
1679 |
const QSize size(100, 100); |
|
1680 |
QImage image(size, format); |
|
1681 |
image.fill(0); |
|
1682 |
||
1683 |
const QColor testColor(Qt::red); |
|
1684 |
QPainter p(&image); |
|
1685 |
QVERIFY(p.isActive()); |
|
1686 |
p.setBrush(QBrush(testColor)); |
|
1687 |
p.drawRect(QRect(QPoint(0,0), size)); |
|
1688 |
QCOMPARE(image.pixel(50, 50), testColor.rgb()); |
|
1689 |
} |
|
1690 |
||
1691 |
void tst_QPainter::fillData() |
|
1692 |
{ |
|
1693 |
QTest::addColumn<QRect>("rect"); |
|
1694 |
QTest::addColumn<bool>("usePen"); |
|
1695 |
||
1696 |
for (int w = 3; w < 50; w += 7) { |
|
1697 |
for (int h = 3; h < 50; h += 11) { |
|
1698 |
int x = w/2 + 5; |
|
1699 |
int y = h/2 + 5; |
|
1700 |
QTest::newRow(QString("rect(%1, %2, %3, %4) with pen").arg(x).arg(y).arg(w).arg(h).toLatin1()) |
|
1701 |
<< QRect(x, y, w, h) << true; |
|
1702 |
QTest::newRow(QString("rect(%1, %2, %3, %4) no pen").arg(x).arg(y).arg(w).arg(h).toLatin1()) |
|
1703 |
<< QRect(x, y, w, h) << false; |
|
1704 |
} |
|
1705 |
} |
|
1706 |
} |
|
1707 |
||
1708 |
/* |
|
1709 |
Test that drawline works properly after setWindow has been called. |
|
1710 |
*/ |
|
1711 |
void tst_QPainter::setWindow() |
|
1712 |
{ |
|
1713 |
QPixmap pixmap(600, 600); |
|
1714 |
pixmap.fill(QColor(Qt::white)); |
|
1715 |
||
1716 |
QPainter painter(&pixmap); |
|
1717 |
painter.setWindow(0, 0, 3, 3); |
|
1718 |
painter.drawLine(1, 1, 2, 2); |
|
1719 |
||
1720 |
const QRect painted = getPaintedSize(pixmap, Qt::white); |
|
1721 |
QVERIFY(195 < painted.y() && painted.y() < 205); // correct value is around 200 |
|
1722 |
QVERIFY(195 < painted.height() && painted.height() < 205); // correct value is around 200 |
|
1723 |
} |
|
1724 |
||
1725 |
void tst_QPainter::combinedMatrix() |
|
1726 |
{ |
|
1727 |
QPixmap pm(64, 64); |
|
1728 |
||
1729 |
QPainter p(&pm); |
|
1730 |
p.setWindow(0, 0, 1, 1); |
|
1731 |
p.setViewport(32, 0, 32, 32); |
|
1732 |
||
1733 |
p.translate(0.5, 0.5); |
|
1734 |
||
1735 |
QMatrix cm = p.combinedMatrix(); |
|
1736 |
||
1737 |
QPointF pt = QPointF(0, 0) * cm; |
|
1738 |
||
1739 |
QCOMPARE(pt.x(), 48.0); |
|
1740 |
QCOMPARE(pt.y(), 16.0); |
|
1741 |
} |
|
1742 |
||
1743 |
void tst_QPainter::textOnTransparentImage() |
|
1744 |
{ |
|
1745 |
bool foundPixel = false; |
|
1746 |
QImage image(10, 10, QImage::Format_ARGB32_Premultiplied); |
|
1747 |
image.fill(qRgba(0, 0, 0, 0)); // transparent |
|
1748 |
{ |
|
1749 |
QPainter painter(&image); |
|
1750 |
painter.setPen(QColor(255, 255, 255)); |
|
1751 |
painter.drawText(0, 10, "W"); |
|
1752 |
} |
|
1753 |
for (int x = 0; x < image.width(); ++x) |
|
1754 |
for (int y = 0; y < image.height(); ++y) |
|
1755 |
if (image.pixel(x, y) != 0) |
|
1756 |
foundPixel = true; |
|
1757 |
QVERIFY(foundPixel); |
|
1758 |
} |
|
1759 |
||
1760 |
void tst_QPainter::renderHints() |
|
1761 |
{ |
|
1762 |
QImage img(1, 1, QImage::Format_RGB32); |
|
1763 |
||
1764 |
QPainter p(&img); |
|
1765 |
||
1766 |
// Turn off all... |
|
1767 |
p.setRenderHints(QPainter::RenderHints(0xffffffff), false); |
|
1768 |
QCOMPARE(p.renderHints(), QPainter::RenderHints(0)); |
|
1769 |
||
1770 |
// Single set/get |
|
1771 |
p.setRenderHint(QPainter::Antialiasing); |
|
1772 |
QVERIFY(p.renderHints() & QPainter::Antialiasing); |
|
1773 |
||
1774 |
p.setRenderHint(QPainter::Antialiasing, false); |
|
1775 |
QVERIFY(!(p.renderHints() & QPainter::Antialiasing)); |
|
1776 |
||
1777 |
// Multi set/get |
|
1778 |
p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); |
|
1779 |
QVERIFY(p.renderHints() & (QPainter::Antialiasing | QPainter::SmoothPixmapTransform)); |
|
1780 |
||
1781 |
p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, false); |
|
1782 |
QVERIFY(!(p.renderHints() & (QPainter::Antialiasing | QPainter::SmoothPixmapTransform))); |
|
1783 |
} |
|
1784 |
||
1785 |
int countPixels(const QImage &img, const QRgb &color) |
|
1786 |
{ |
|
1787 |
int count = 0; |
|
1788 |
for (int y = 0; y < img.height(); ++y) { |
|
1789 |
for (int x = 0; x < img.width(); ++x) { |
|
1790 |
count += ((img.pixel(x, y) & 0xffffff) == color); |
|
1791 |
} |
|
1792 |
} |
|
1793 |
return count; |
|
1794 |
} |
|
1795 |
||
1796 |
template <typename T> |
|
1797 |
void testClipping(QImage &img) |
|
1798 |
{ |
|
1799 |
img.fill(0x0); |
|
1800 |
QPainterPath a, b; |
|
1801 |
a.addRect(QRect(2, 2, 4, 4)); |
|
1802 |
b.addRect(QRect(4, 4, 4, 4)); |
|
1803 |
||
1804 |
QPainter p(&img); |
|
1805 |
p.setClipPath(a); |
|
1806 |
p.setClipPath(b, Qt::UniteClip); |
|
1807 |
||
1808 |
p.setClipping(false); |
|
1809 |
p.setPen(Qt::NoPen); |
|
1810 |
p.setBrush(QColor(0xff0000)); |
|
1811 |
p.drawRect(T(0, 0, 10, 10)); |
|
1812 |
||
1813 |
p.setClipping(true); |
|
1814 |
p.setBrush(QColor(0x00ff00)); |
|
1815 |
p.drawRect(T(0, 0, 10, 10)); |
|
1816 |
||
1817 |
QCOMPARE(countPixels(img, 0xff0000), 72); |
|
1818 |
QCOMPARE(countPixels(img, 0x00ff00), 28); |
|
1819 |
||
1820 |
p.end(); |
|
1821 |
img.fill(0x0); |
|
1822 |
p.begin(&img); |
|
1823 |
p.setClipPath(a); |
|
1824 |
p.setClipPath(b, Qt::IntersectClip); |
|
1825 |
||
1826 |
p.setClipping(false); |
|
1827 |
p.setPen(Qt::NoPen); |
|
1828 |
p.setBrush(QColor(0xff0000)); |
|
1829 |
p.drawRect(T(0, 0, 10, 10)); |
|
1830 |
||
1831 |
p.setClipping(true); |
|
1832 |
p.setBrush(QColor(0x00ff00)); |
|
1833 |
p.drawRect(T(0, 0, 10, 10)); |
|
1834 |
||
1835 |
QCOMPARE(countPixels(img, 0xff0000), 96); |
|
1836 |
QCOMPARE(countPixels(img, 0x00ff00), 4); |
|
1837 |
} |
|
1838 |
||
1839 |
void tst_QPainter::disableEnableClipping() |
|
1840 |
{ |
|
1841 |
QImage img(10, 10, QImage::Format_RGB32); |
|
1842 |
||
1843 |
testClipping<QRectF>(img); |
|
1844 |
testClipping<QRect>(img); |
|
1845 |
} |
|
1846 |
||
1847 |
void tst_QPainter::setClipRect() |
|
1848 |
{ |
|
1849 |
QImage img(10, 10, QImage::Format_RGB32); |
|
1850 |
// simple test to let valgrind check for buffer overflow |
|
1851 |
{ |
|
1852 |
QPainter p(&img); |
|
1853 |
p.setClipRect(-10, -10, 100, 100); |
|
1854 |
p.fillRect(-10, -10, 100, 100, QBrush(QColor(Qt::red))); |
|
1855 |
} |
|
1856 |
||
1857 |
// rects with negative width/height |
|
1858 |
{ |
|
1859 |
QPainter p(&img); |
|
1860 |
p.setClipRect(QRect(10, 10, -10, 10)); |
|
1861 |
QVERIFY(p.clipRegion().isEmpty()); |
|
1862 |
p.setClipRect(QRect(10, 10, 10, -10)); |
|
1863 |
QVERIFY(p.clipRegion().isEmpty()); |
|
1864 |
p.setClipRect(QRectF(10.5, 10.5, -10.5, 10.5)); |
|
1865 |
QVERIFY(p.clipRegion().isEmpty()); |
|
1866 |
p.setClipRect(QRectF(10.5, 10.5, 10.5, -10.5)); |
|
1867 |
QVERIFY(p.clipRegion().isEmpty()); |
|
1868 |
} |
|
1869 |
} |
|
1870 |
||
1871 |
/* |
|
1872 |
This tests the two different clipping approaches in QRasterPaintEngine, |
|
1873 |
one when using a QRegion and one when using a QPainterPath. They should |
|
1874 |
give equal results. |
|
1875 |
*/ |
|
1876 |
void tst_QPainter::setEqualClipRegionAndPath_data() |
|
1877 |
{ |
|
1878 |
QTest::addColumn<QSize>("deviceSize"); |
|
1879 |
QTest::addColumn<QRegion>("region"); |
|
1880 |
||
1881 |
QTest::newRow("empty") << QSize(100, 100) << QRegion(); |
|
1882 |
QTest::newRow("simple rect") << QSize(100, 100) |
|
1883 |
<< QRegion(QRect(5, 5, 10, 10)); |
|
1884 |
||
1885 |
QVector<QRect> rects; |
|
1886 |
QRegion region; |
|
1887 |
||
1888 |
rects << QRect(5, 5, 10, 10) << QRect(20, 20, 10, 10); |
|
1889 |
region.setRects(rects.constData(), rects.size()); |
|
1890 |
QTest::newRow("two rects") << QSize(100, 100) << region; |
|
1891 |
||
1892 |
rects.clear(); |
|
1893 |
rects << QRect(5, 5, 10, 10) << QRect(20, 5, 10, 10); |
|
1894 |
region.setRects(rects.constData(), rects.size()); |
|
1895 |
QTest::newRow("two x-adjacent rects") << QSize(100, 100) << region; |
|
1896 |
||
1897 |
rects.clear(); |
|
1898 |
rects << QRect(0, 0, 10, 100) << QRect(12, 0, 10, 100); |
|
1899 |
region.setRects(rects.constData(), rects.size()); |
|
1900 |
QTest::newRow("two x-adjacent rects 2") << QSize(100, 100) << region; |
|
1901 |
||
1902 |
rects.clear(); |
|
1903 |
rects << QRect(0, 0, 10, 100) << QRect(12, 0, 10, 100); |
|
1904 |
region.setRects(rects.constData(), rects.size()); |
|
1905 |
QTest::newRow("two x-adjacent rects 3") << QSize(50, 50) << region; |
|
1906 |
||
1907 |
rects.clear(); |
|
1908 |
rects << QRect(0, 0, 10, 100) << QRect(12, 0, 10, 100); |
|
1909 |
region.setRects(rects.constData(), rects.size()); |
|
1910 |
QTest::newRow("two x-adjacent rects 4") << QSize(101, 101) << region; |
|
1911 |
||
1912 |
region = QRegion(QRect(0, 0, 200, 200), QRegion::Ellipse); |
|
1913 |
||
1914 |
QTest::newRow("ellipse") << QSize(190, 200) << region; |
|
1915 |
||
1916 |
region ^= QRect(50, 50, 50, 50); |
|
1917 |
QTest::newRow("ellipse 2") << QSize(200, 200) << region; |
|
1918 |
} |
|
1919 |
||
1920 |
void tst_QPainter::setEqualClipRegionAndPath() |
|
1921 |
{ |
|
1922 |
QFETCH(QSize, deviceSize); |
|
1923 |
QFETCH(QRegion, region); |
|
1924 |
||
1925 |
QPainterPath path; |
|
1926 |
path.addRegion(region); |
|
1927 |
||
1928 |
QImage img1(deviceSize.width(), deviceSize.height(), |
|
1929 |
QImage::Format_ARGB32); |
|
1930 |
QImage img2(deviceSize.width(), deviceSize.height(), |
|
1931 |
QImage::Format_ARGB32); |
|
1932 |
img1.fill(0x12345678); |
|
1933 |
img2.fill(0x12345678); |
|
1934 |
||
1935 |
{ |
|
1936 |
QPainter p(&img1); |
|
1937 |
p.setClipRegion(region); |
|
1938 |
p.fillRect(0, 0, img1.width(), img1.height(), QColor(Qt::red)); |
|
1939 |
} |
|
1940 |
{ |
|
1941 |
QPainter p(&img2); |
|
1942 |
p.setClipPath(path); |
|
1943 |
p.fillRect(0, 0, img2.width(), img2.height(), QColor(Qt::red)); |
|
1944 |
} |
|
1945 |
||
1946 |
#if 0 |
|
1947 |
if (img1 != img2) { |
|
1948 |
img1.save("setEqualClipRegionAndPath_1.xpm", "XPM"); |
|
1949 |
img2.save("setEqualClipRegionAndPath_2.xpm", "XPM"); |
|
1950 |
} |
|
1951 |
#endif |
|
1952 |
QCOMPARE(img1, img2); |
|
1953 |
||
1954 |
#if 0 |
|
1955 |
// rotated |
|
1956 |
img1.fill(0x12345678); |
|
1957 |
img2.fill(0x12345678); |
|
1958 |
||
1959 |
{ |
|
1960 |
QPainter p(&img1); |
|
1961 |
p.rotate(25); |
|
1962 |
p.setClipRegion(region); |
|
1963 |
p.fillRect(0, 0, img1.width(), img1.height(), QColor(Qt::red)); |
|
1964 |
} |
|
1965 |
{ |
|
1966 |
QPainter p(&img2); |
|
1967 |
p.rotate(25); |
|
1968 |
p.setClipPath(path); |
|
1969 |
p.fillRect(0, 0, img2.width(), img2.height(), QColor(Qt::red)); |
|
1970 |
} |
|
1971 |
||
1972 |
#if 1 |
|
1973 |
if (img1 != img2) { |
|
1974 |
img1.save("setEqualClipRegionAndPath_1.xpm", "XPM"); |
|
1975 |
img2.save("setEqualClipRegionAndPath_2.xpm", "XPM"); |
|
1976 |
} |
|
1977 |
#endif |
|
1978 |
QCOMPARE(img1, img2); |
|
1979 |
#endif |
|
1980 |
||
1981 |
// simple uniteclip |
|
1982 |
img1.fill(0x12345678); |
|
1983 |
img2.fill(0x12345678); |
|
1984 |
{ |
|
1985 |
QPainter p(&img1); |
|
1986 |
p.setClipRegion(region); |
|
1987 |
p.setClipRegion(region, Qt::UniteClip); |
|
1988 |
p.fillRect(0, 0, img1.width(), img1.height(), QColor(Qt::red)); |
|
1989 |
} |
|
1990 |
{ |
|
1991 |
QPainter p(&img2); |
|
1992 |
p.setClipPath(path); |
|
1993 |
p.setClipPath(path, Qt::UniteClip); |
|
1994 |
p.fillRect(0, 0, img2.width(), img2.height(), QColor(Qt::red)); |
|
1995 |
} |
|
1996 |
QCOMPARE(img1, img2); |
|
1997 |
img1.fill(0x12345678); |
|
1998 |
img2.fill(0x12345678); |
|
1999 |
{ |
|
2000 |
QPainter p(&img1); |
|
2001 |
p.setClipPath(path); |
|
2002 |
p.setClipRegion(region, Qt::UniteClip); |
|
2003 |
p.fillRect(0, 0, img1.width(), img1.height(), QColor(Qt::red)); |
|
2004 |
} |
|
2005 |
{ |
|
2006 |
QPainter p(&img2); |
|
2007 |
p.setClipRegion(region); |
|
2008 |
p.setClipPath(path, Qt::UniteClip); |
|
2009 |
p.fillRect(0, 0, img2.width(), img2.height(), QColor(Qt::red)); |
|
2010 |
} |
|
2011 |
#if 0 |
|
2012 |
if (img1 != img2) { |
|
2013 |
img1.save("setEqualClipRegionAndPath_1.xpm", "XPM"); |
|
2014 |
img2.save("setEqualClipRegionAndPath_2.xpm", "XPM"); |
|
2015 |
} |
|
2016 |
#endif |
|
2017 |
QCOMPARE(img1, img2); |
|
2018 |
||
2019 |
// simple intersectclip |
|
2020 |
img1.fill(0x12345678); |
|
2021 |
img2.fill(0x12345678); |
|
2022 |
{ |
|
2023 |
QPainter p(&img1); |
|
2024 |
p.setClipRegion(region); |
|
2025 |
p.setClipRegion(region, Qt::IntersectClip); |
|
2026 |
p.fillRect(0, 0, img1.width(), img1.height(), QColor(Qt::red)); |
|
2027 |
} |
|
2028 |
{ |
|
2029 |
QPainter p(&img2); |
|
2030 |
p.setClipPath(path); |
|
2031 |
p.setClipPath(path, Qt::IntersectClip); |
|
2032 |
p.fillRect(0, 0, img2.width(), img2.height(), QColor(Qt::red)); |
|
2033 |
} |
|
2034 |
#if 0 |
|
2035 |
if (img1 != img2) { |
|
2036 |
img1.save("setEqualClipRegionAndPath_1.png", "PNG"); |
|
2037 |
img2.save("setEqualClipRegionAndPath_2.png", "PNG"); |
|
2038 |
} |
|
2039 |
#endif |
|
2040 |
QCOMPARE(img1, img2); |
|
2041 |
||
2042 |
img1.fill(0x12345678); |
|
2043 |
img2.fill(0x12345678); |
|
2044 |
{ |
|
2045 |
QPainter p(&img1); |
|
2046 |
p.setClipPath(path); |
|
2047 |
p.setClipRegion(region, Qt::IntersectClip); |
|
2048 |
p.fillRect(0, 0, img1.width(), img1.height(), QColor(Qt::red)); |
|
2049 |
} |
|
2050 |
{ |
|
2051 |
QPainter p(&img2); |
|
2052 |
p.setClipRegion(region); |
|
2053 |
p.setClipPath(path, Qt::IntersectClip); |
|
2054 |
p.fillRect(0, 0, img2.width(), img2.height(), QColor(Qt::red)); |
|
2055 |
} |
|
2056 |
#if 0 |
|
2057 |
if (img1 != img2) { |
|
2058 |
img1.save("setEqualClipRegionAndPath_1.xpm", "XPM"); |
|
2059 |
img2.save("setEqualClipRegionAndPath_2.xpm", "XPM"); |
|
2060 |
} |
|
2061 |
#endif |
|
2062 |
QCOMPARE(img1, img2); |
|
2063 |
||
2064 |
} |
|
2065 |
||
2066 |
void tst_QPainter::clippedFillPath_data() |
|
2067 |
{ |
|
2068 |
QTest::addColumn<QSize>("imageSize"); |
|
2069 |
QTest::addColumn<QPainterPath>("path"); |
|
2070 |
QTest::addColumn<QRect>("clipRect"); |
|
2071 |
QTest::addColumn<QBrush>("brush"); |
|
2072 |
QTest::addColumn<QPen>("pen"); |
|
2073 |
||
2074 |
QLinearGradient gradient(QPoint(0, 0), QPoint(100, 100)); |
|
2075 |
gradient.setColorAt(0, Qt::red); |
|
2076 |
gradient.setColorAt(1, Qt::blue); |
|
2077 |
||
2078 |
||
2079 |
QPen pen2(QColor(223, 223, 0, 223)); |
|
2080 |
pen2.setWidth(2); |
|
2081 |
||
2082 |
QPainterPath path; |
|
2083 |
path.addRect(QRect(15, 15, 50, 50)); |
|
2084 |
QTest::newRow("simple rect 0") << QSize(100, 100) << path |
|
2085 |
<< QRect(15, 15, 49, 49) |
|
2086 |
<< QBrush(Qt::NoBrush) |
|
2087 |
<< QPen(Qt::black); |
|
2088 |
QTest::newRow("simple rect 1") << QSize(100, 100) << path |
|
2089 |
<< QRect(15, 15, 50, 50) |
|
2090 |
<< QBrush(Qt::NoBrush) |
|
2091 |
<< QPen(Qt::black); |
|
2092 |
QTest::newRow("simple rect 2") << QSize(100, 100) << path |
|
2093 |
<< QRect(15, 15, 51, 51) |
|
2094 |
<< QBrush(Qt::NoBrush) |
|
2095 |
<< QPen(Qt::black); |
|
2096 |
QTest::newRow("simple rect 3") << QSize(100, 100) << path |
|
2097 |
<< QRect(15, 15, 51, 51) |
|
2098 |
<< QBrush(QColor(Qt::blue)) |
|
2099 |
<< QPen(Qt::NoPen); |
|
2100 |
QTest::newRow("simple rect 4") << QSize(100, 100) << path |
|
2101 |
<< QRect(15, 15, 51, 51) |
|
2102 |
<< QBrush(gradient) |
|
2103 |
<< pen2; |
|
2104 |
||
2105 |
path = QPainterPath(); |
|
2106 |
path.addEllipse(QRect(15, 15, 50, 50)); |
|
2107 |
QTest::newRow("ellipse 0") << QSize(100, 100) << path |
|
2108 |
<< QRect(15, 15, 49, 49) |
|
2109 |
<< QBrush(Qt::NoBrush) |
|
2110 |
<< QPen(Qt::black); |
|
2111 |
QTest::newRow("ellipse 1") << QSize(100, 100) << path |
|
2112 |
<< QRect(15, 15, 50, 50) |
|
2113 |
<< QBrush(Qt::NoBrush) |
|
2114 |
<< QPen(Qt::black); |
|
2115 |
QTest::newRow("ellipse 2") << QSize(100, 100) << path |
|
2116 |
<< QRect(15, 15, 51, 51) |
|
2117 |
<< QBrush(Qt::NoBrush) |
|
2118 |
<< QPen(Qt::black); |
|
2119 |
QTest::newRow("ellipse 3") << QSize(100, 100) << path |
|
2120 |
<< QRect(15, 15, 51, 51) |
|
2121 |
<< QBrush(QColor(Qt::blue)) |
|
2122 |
<< QPen(Qt::NoPen); |
|
2123 |
QTest::newRow("ellipse 4") << QSize(100, 100) << path |
|
2124 |
<< QRect(15, 15, 51, 51) |
|
2125 |
<< QBrush(gradient) |
|
2126 |
<< pen2; |
|
2127 |
||
2128 |
path = QPainterPath(); |
|
2129 |
path.addRoundRect(QRect(15, 15, 50, 50), 20); |
|
2130 |
QTest::newRow("round rect 0") << QSize(100, 100) << path |
|
2131 |
<< QRect(15, 15, 49, 49) |
|
2132 |
<< QBrush(Qt::NoBrush) |
|
2133 |
<< QPen(Qt::black); |
|
2134 |
QTest::newRow("round rect 1") << QSize(100, 100) << path |
|
2135 |
<< QRect(15, 15, 50, 50) |
|
2136 |
<< QBrush(Qt::NoBrush) |
|
2137 |
<< QPen(Qt::black); |
|
2138 |
QTest::newRow("round rect 2") << QSize(100, 100) << path |
|
2139 |
<< QRect(15, 15, 51, 51) |
|
2140 |
<< QBrush(Qt::NoBrush) |
|
2141 |
<< QPen(Qt::black); |
|
2142 |
QTest::newRow("round rect 3") << QSize(100, 100) << path |
|
2143 |
<< QRect(15, 15, 51, 51) |
|
2144 |
<< QBrush(QColor(Qt::blue)) |
|
2145 |
<< QPen(Qt::NoPen); |
|
2146 |
QTest::newRow("round rect 4") << QSize(100, 100) << path |
|
2147 |
<< QRect(15, 15, 51, 51) |
|
2148 |
<< QBrush(gradient) |
|
2149 |
<< pen2; |
|
2150 |
||
2151 |
path = QPainterPath(); |
|
2152 |
path.moveTo(15, 50); |
|
2153 |
path.cubicTo(40, 50, 40, 15, 65, 50); |
|
2154 |
path.lineTo(15, 50); |
|
2155 |
QTest::newRow("cubic 0") << QSize(100, 100) << path |
|
2156 |
<< QRect(15, 15, 49, 49) |
|
2157 |
<< QBrush(Qt::NoBrush) |
|
2158 |
<< QPen(Qt::black); |
|
2159 |
QTest::newRow("cubic 1") << QSize(100, 100) << path |
|
2160 |
<< QRect(15, 15, 50, 50) |
|
2161 |
<< QBrush(Qt::NoBrush) |
|
2162 |
<< QPen(Qt::black); |
|
2163 |
QTest::newRow("cubic 2") << QSize(100, 100) << path |
|
2164 |
<< QRect(15, 15, 51, 51) |
|
2165 |
<< QBrush(Qt::NoBrush) |
|
2166 |
<< QPen(Qt::black); |
|
2167 |
QTest::newRow("cubic 3") << QSize(100, 100) << path |
|
2168 |
<< QRect(15, 15, 51, 51) |
|
2169 |
<< QBrush(QColor(Qt::blue)) |
|
2170 |
<< QPen(Qt::NoPen); |
|
2171 |
QTest::newRow("cubic 4") << QSize(100, 100) << path |
|
2172 |
<< QRect(15, 15, 51, 51) |
|
2173 |
<< QBrush(gradient) |
|
2174 |
<< pen2; |
|
2175 |
} |
|
2176 |
||
2177 |
void tst_QPainter::clippedFillPath() |
|
2178 |
{ |
|
2179 |
QFETCH(QSize, imageSize); |
|
2180 |
QFETCH(QPainterPath, path); |
|
2181 |
QFETCH(QRect, clipRect); |
|
2182 |
QPainterPath clipPath; |
|
2183 |
clipPath.addRect(clipRect); |
|
2184 |
QFETCH(QBrush, brush); |
|
2185 |
QFETCH(QPen, pen); |
|
2186 |
||
2187 |
const int width = imageSize.width(); |
|
2188 |
const int height = imageSize.height(); |
|
2189 |
||
2190 |
QImage clippedRect(width, height, QImage::Format_ARGB32_Premultiplied); |
|
2191 |
clippedRect.fill(0x12345678); |
|
2192 |
{ |
|
2193 |
QPainter painter(&clippedRect); |
|
2194 |
painter.setPen(pen); |
|
2195 |
painter.setBrush(brush); |
|
2196 |
painter.setClipRect(clipRect); |
|
2197 |
painter.drawPath(path); |
|
2198 |
} |
|
2199 |
||
2200 |
QImage clippedPath(width, height, QImage::Format_ARGB32_Premultiplied); |
|
2201 |
clippedPath.fill(0x12345678); |
|
2202 |
{ |
|
2203 |
QPainter painter(&clippedPath); |
|
2204 |
painter.setPen(pen); |
|
2205 |
painter.setBrush(brush); |
|
2206 |
painter.setClipPath(clipPath); |
|
2207 |
painter.drawPath(path); |
|
2208 |
} |
|
2209 |
||
2210 |
#if 0 |
|
2211 |
if (clippedRect != clippedPath) { |
|
2212 |
clippedRect.save(QString("clippedRect.png"), "PNG"); |
|
2213 |
clippedPath.save(QString("clippedPath.png"), "PNG"); |
|
2214 |
} |
|
2215 |
#endif |
|
2216 |
QCOMPARE(clippedRect, clippedPath); |
|
2217 |
||
2218 |
// repeat with antialiasing |
|
2219 |
||
2220 |
clippedRect.fill(0x12345678); |
|
2221 |
{ |
|
2222 |
QPainter painter(&clippedRect); |
|
2223 |
painter.setRenderHint(QPainter::Antialiasing); |
|
2224 |
painter.setPen(pen); |
|
2225 |
painter.setBrush(brush); |
|
2226 |
painter.setClipRect(clipRect); |
|
2227 |
painter.drawPath(path); |
|
2228 |
} |
|
2229 |
||
2230 |
clippedPath.fill(0x12345678); |
|
2231 |
{ |
|
2232 |
QPainter painter(&clippedPath); |
|
2233 |
painter.setRenderHint(QPainter::Antialiasing); |
|
2234 |
painter.setPen(pen); |
|
2235 |
painter.setBrush(brush); |
|
2236 |
painter.setClipPath(clipPath); |
|
2237 |
painter.drawPath(path); |
|
2238 |
} |
|
2239 |
||
2240 |
#if 1 |
|
2241 |
if (clippedRect != clippedPath) { |
|
2242 |
clippedRect.save(QString("clippedRect.png"), "PNG"); |
|
2243 |
clippedPath.save(QString("clippedPath.png"), "PNG"); |
|
2244 |
} |
|
2245 |
#endif |
|
2246 |
QCOMPARE(clippedRect, clippedPath); |
|
2247 |
||
2248 |
} |
|
2249 |
||
2250 |
void tst_QPainter::clippedLines_data() |
|
2251 |
{ |
|
2252 |
QTest::addColumn<QSize>("imageSize"); |
|
2253 |
QTest::addColumn<QLineF>("line"); |
|
2254 |
QTest::addColumn<QRect>("clipRect"); |
|
2255 |
QTest::addColumn<QPen>("pen"); |
|
2256 |
||
2257 |
QPen pen2(QColor(223, 223, 0, 223)); |
|
2258 |
pen2.setWidth(2); |
|
2259 |
||
2260 |
QVector<QLineF> lines; |
|
2261 |
lines << QLineF(15, 15, 65, 65) |
|
2262 |
<< QLineF(14, 14, 66, 66) |
|
2263 |
<< QLineF(16, 16, 64, 64) |
|
2264 |
<< QLineF(65, 65, 15, 15) |
|
2265 |
<< QLineF(66, 66, 14, 14) |
|
2266 |
<< QLineF(64, 64, 14, 14) |
|
2267 |
<< QLineF(15, 50, 15, 64) |
|
2268 |
<< QLineF(15, 50, 15, 65) |
|
2269 |
<< QLineF(15, 50, 15, 66) |
|
2270 |
<< QLineF(15, 50, 64, 50) |
|
2271 |
<< QLineF(15, 50, 65, 50) |
|
2272 |
<< QLineF(15, 50, 66, 50); |
|
2273 |
||
2274 |
foreach (QLineF line, lines) { |
|
2275 |
QString desc = QString("line (%1, %2, %3, %4) %5").arg(line.x1()) |
|
2276 |
.arg(line.y1()).arg(line.x2()).arg(line.y2()); |
|
2277 |
QTest::newRow(qPrintable(desc.arg(0))) << QSize(100, 100) << line |
|
2278 |
<< QRect(15, 15, 49, 49) |
|
2279 |
<< QPen(Qt::black); |
|
2280 |
QTest::newRow(qPrintable(desc.arg(1))) << QSize(100, 100) << line |
|
2281 |
<< QRect(15, 15, 50, 50) |
|
2282 |
<< QPen(Qt::black); |
|
2283 |
QTest::newRow(qPrintable(desc.arg(2))) << QSize(100, 100) << line |
|
2284 |
<< QRect(15, 15, 51, 51) |
|
2285 |
<< QPen(Qt::black); |
|
2286 |
QTest::newRow(qPrintable(desc.arg(3))) << QSize(100, 100) << line |
|
2287 |
<< QRect(15, 15, 51, 51) |
|
2288 |
<< QPen(Qt::NoPen); |
|
2289 |
QTest::newRow(qPrintable(desc.arg(4))) << QSize(100, 100) << line |
|
2290 |
<< QRect(15, 15, 51, 51) |
|
2291 |
<< pen2; |
|
2292 |
} |
|
2293 |
} |
|
2294 |
||
2295 |
void tst_QPainter::clippedLines() |
|
2296 |
{ |
|
2297 |
QFETCH(QSize, imageSize); |
|
2298 |
QFETCH(QLineF, line); |
|
2299 |
QFETCH(QRect, clipRect); |
|
2300 |
QPainterPath clipPath; |
|
2301 |
clipPath.addRect(clipRect); |
|
2302 |
QFETCH(QPen, pen); |
|
2303 |
||
2304 |
const int width = imageSize.width(); |
|
2305 |
const int height = imageSize.height(); |
|
2306 |
||
2307 |
QImage clippedRect(width, height, QImage::Format_ARGB32_Premultiplied); |
|
2308 |
clippedRect.fill(0x12345678); |
|
2309 |
{ |
|
2310 |
QPainter painter(&clippedRect); |
|
2311 |
painter.setPen(pen); |
|
2312 |
painter.setClipRect(clipRect); |
|
2313 |
painter.drawLine(line); |
|
2314 |
painter.drawLine(line.toLine()); |
|
2315 |
} |
|
2316 |
||
2317 |
QImage clippedPath(width, height, QImage::Format_ARGB32_Premultiplied); |
|
2318 |
clippedPath.fill(0x12345678); |
|
2319 |
{ |
|
2320 |
QPainter painter(&clippedPath); |
|
2321 |
painter.setPen(pen); |
|
2322 |
painter.setClipPath(clipPath); |
|
2323 |
painter.drawLine(line); |
|
2324 |
painter.drawLine(line.toLine()); |
|
2325 |
} |
|
2326 |
||
2327 |
#if 0 |
|
2328 |
if (clippedRect != clippedPath) { |
|
2329 |
clippedRect.save(QString("clippedRect.png"), "PNG"); |
|
2330 |
clippedPath.save(QString("clippedPath.png"), "PNG"); |
|
2331 |
} |
|
2332 |
#endif |
|
2333 |
QCOMPARE(clippedRect, clippedPath); |
|
2334 |
||
2335 |
// repeat with antialiasing |
|
2336 |
clippedRect.fill(0x12345678); |
|
2337 |
{ |
|
2338 |
QPainter painter(&clippedRect); |
|
2339 |
painter.setRenderHint(QPainter::Antialiasing); |
|
2340 |
painter.setPen(pen); |
|
2341 |
painter.setClipRect(clipRect); |
|
2342 |
painter.drawLine(line); |
|
2343 |
painter.drawLine(line.toLine()); |
|
2344 |
} |
|
2345 |
||
2346 |
clippedPath.fill(0x12345678); |
|
2347 |
{ |
|
2348 |
QPainter painter(&clippedPath); |
|
2349 |
painter.setRenderHint(QPainter::Antialiasing); |
|
2350 |
painter.setPen(pen); |
|
2351 |
painter.setClipPath(clipPath); |
|
2352 |
painter.drawLine(line); |
|
2353 |
painter.drawLine(line.toLine()); |
|
2354 |
} |
|
2355 |
||
2356 |
#if 0 |
|
2357 |
if (clippedRect != clippedPath) { |
|
2358 |
clippedRect.save(QString("clippedRect.png"), "PNG"); |
|
2359 |
clippedPath.save(QString("clippedPath.png"), "PNG"); |
|
2360 |
} |
|
2361 |
#endif |
|
2362 |
QCOMPARE(clippedRect, clippedPath); |
|
2363 |
} |
|
2364 |
||
2365 |
void tst_QPainter::clippedPolygon_data() |
|
2366 |
{ |
|
2367 |
clippedFillPath_data(); |
|
2368 |
}; |
|
2369 |
||
2370 |
void tst_QPainter::clippedPolygon() |
|
2371 |
{ |
|
2372 |
QFETCH(QSize, imageSize); |
|
2373 |
QFETCH(QPainterPath, path); |
|
2374 |
QPolygonF polygon = path.toFillPolygon(); |
|
2375 |
QFETCH(QRect, clipRect); |
|
2376 |
QPainterPath clipPath; |
|
2377 |
clipPath.addRect(clipRect); |
|
2378 |
QFETCH(QPen, pen); |
|
2379 |
QFETCH(QBrush, brush); |
|
2380 |
||
2381 |
const int width = imageSize.width(); |
|
2382 |
const int height = imageSize.height(); |
|
2383 |
||
2384 |
QImage clippedRect(width, height, QImage::Format_ARGB32_Premultiplied); |
|
2385 |
clippedRect.fill(0x12345678); |
|
2386 |
{ |
|
2387 |
QPainter painter(&clippedRect); |
|
2388 |
painter.setPen(pen); |
|
2389 |
painter.setBrush(brush); |
|
2390 |
painter.setClipRect(clipRect); |
|
2391 |
painter.drawPolygon(polygon); |
|
2392 |
painter.drawPolygon(polygon.toPolygon()); |
|
2393 |
} |
|
2394 |
||
2395 |
QImage clippedPath(width, height, QImage::Format_ARGB32_Premultiplied); |
|
2396 |
clippedPath.fill(0x12345678); |
|
2397 |
{ |
|
2398 |
QPainter painter(&clippedPath); |
|
2399 |
painter.setPen(pen); |
|
2400 |
painter.setBrush(brush); |
|
2401 |
painter.setClipRect(clipRect); |
|
2402 |
painter.drawPolygon(polygon); |
|
2403 |
painter.drawPolygon(polygon.toPolygon()); |
|
2404 |
} |
|
2405 |
||
2406 |
#if 0 |
|
2407 |
if (clippedRect != clippedPath) { |
|
2408 |
clippedRect.save(QString("clippedRect.png"), "PNG"); |
|
2409 |
clippedPath.save(QString("clippedPath.png"), "PNG"); |
|
2410 |
} |
|
2411 |
#endif |
|
2412 |
QCOMPARE(clippedRect, clippedPath); |
|
2413 |
||
2414 |
// repeat with antialiasing |
|
2415 |
||
2416 |
clippedRect.fill(0x12345678); |
|
2417 |
{ |
|
2418 |
QPainter painter(&clippedRect); |
|
2419 |
painter.setRenderHint(QPainter::Antialiasing); |
|
2420 |
painter.setPen(pen); |
|
2421 |
painter.setBrush(brush); |
|
2422 |
painter.setClipRect(clipRect); |
|
2423 |
painter.drawPolygon(polygon); |
|
2424 |
painter.drawPolygon(polygon.toPolygon()); |
|
2425 |
} |
|
2426 |
||
2427 |
clippedPath.fill(0x12345678); |
|
2428 |
{ |
|
2429 |
QPainter painter(&clippedPath); |
|
2430 |
painter.setRenderHint(QPainter::Antialiasing); |
|
2431 |
painter.setPen(pen); |
|
2432 |
painter.setBrush(brush); |
|
2433 |
painter.setClipRect(clipRect); |
|
2434 |
painter.drawPolygon(polygon); |
|
2435 |
painter.drawPolygon(polygon.toPolygon()); |
|
2436 |
} |
|
2437 |
||
2438 |
#if 0 |
|
2439 |
if (clippedRect != clippedPath) { |
|
2440 |
clippedRect.save(QString("clippedRect.png"), "PNG"); |
|
2441 |
clippedPath.save(QString("clippedPath.png"), "PNG"); |
|
2442 |
} |
|
2443 |
#endif |
|
2444 |
QCOMPARE(clippedRect, clippedPath); |
|
2445 |
} |
|
2446 |
||
2447 |
// this just draws some text that should be clipped in the raster |
|
2448 |
// paint engine. |
|
2449 |
void tst_QPainter::clippedText() |
|
2450 |
{ |
|
2451 |
for (char ch = 'A'; ch < 'Z'; ++ch) { |
|
2452 |
//qDebug() << ch; |
|
2453 |
QFont f; |
|
2454 |
f.setPixelSize(24); |
|
2455 |
QFontMetrics metrics(f); |
|
2456 |
QRect textRect = metrics.boundingRect(QChar(ch)); |
|
2457 |
||
2458 |
if (textRect.width() <= 8) |
|
2459 |
continue; |
|
2460 |
if (textRect.height() <= 8) |
|
2461 |
continue; |
|
2462 |
||
2463 |
QRect imageRect = textRect.adjusted(4, 4, -4, -4); |
|
2464 |
||
2465 |
QImage image(imageRect.size(), QImage::Format_ARGB32_Premultiplied); |
|
2466 |
||
2467 |
image.fill(qRgba(255, 255, 255, 255)); |
|
2468 |
{ |
|
2469 |
QPainter painter(&image); |
|
2470 |
painter.setFont(f); |
|
2471 |
painter.setPen(Qt::black); |
|
2472 |
||
2473 |
painter.drawText(0, 0, QChar(ch)); |
|
2474 |
} |
|
2475 |
||
2476 |
image.fill(qRgba(255, 255, 255, 255)); |
|
2477 |
{ |
|
2478 |
QPainter painter(&image); |
|
2479 |
painter.setFont(f); |
|
2480 |
painter.setPen(Qt::black); |
|
2481 |
||
2482 |
painter.drawText(-imageRect.topLeft(), QChar(ch)); |
|
2483 |
} |
|
2484 |
||
2485 |
bool foundPixel = false; |
|
2486 |
for (int x = 0; x < image.width(); ++x) |
|
2487 |
for (int y = 0; y < image.height(); ++y) |
|
2488 |
if (image.pixel(x, y) != 0) |
|
2489 |
foundPixel = true; |
|
2490 |
// can't QVERIFY(foundPixel) as sometimes all pixels are clipped |
|
2491 |
// away. For example for 'O' |
|
2492 |
// just call /some/ function to prevent the compiler from optimizing |
|
2493 |
// foundPixel away |
|
2494 |
QString::number(foundPixel); |
|
2495 |
||
2496 |
//image.save(QString("debug") + ch + ".xpm"); |
|
2497 |
} |
|
2498 |
||
2499 |
QVERIFY(true); // reached, don't trigger any valgrind errors |
|
2500 |
} |
|
2501 |
||
2502 |
void tst_QPainter::setOpacity_data() |
|
2503 |
{ |
|
2504 |
QTest::addColumn<QImage::Format>("destFormat"); |
|
2505 |
QTest::addColumn<QImage::Format>("srcFormat"); |
|
2506 |
||
2507 |
QTest::newRow("ARGB32P on ARGB32P") << QImage::Format_ARGB32_Premultiplied |
|
2508 |
<< QImage::Format_ARGB32_Premultiplied; |
|
2509 |
||
2510 |
QTest::newRow("ARGB32 on ARGB32") << QImage::Format_ARGB32 |
|
2511 |
<< QImage::Format_ARGB32; |
|
2512 |
||
2513 |
QTest::newRow("RGB32 on RGB32") << QImage::Format_RGB32 |
|
2514 |
<< QImage::Format_RGB32; |
|
2515 |
||
2516 |
QTest::newRow("RGB16 on RGB16") << QImage::Format_RGB16 |
|
2517 |
<< QImage::Format_RGB16; |
|
2518 |
||
2519 |
QTest::newRow("ARGB8565_Premultiplied on ARGB8565_Premultiplied") << QImage::Format_ARGB8565_Premultiplied |
|
2520 |
<< QImage::Format_ARGB8565_Premultiplied; |
|
2521 |
||
2522 |
QTest::newRow("RGB555 on RGB555") << QImage::Format_RGB555 |
|
2523 |
<< QImage::Format_RGB555; |
|
2524 |
||
2525 |
QTest::newRow("RGB666 on RGB666") << QImage::Format_RGB666 |
|
2526 |
<< QImage::Format_RGB666; |
|
2527 |
||
2528 |
QTest::newRow("ARGB8555_Premultiplied on ARGB8555_Premultiplied") << QImage::Format_ARGB8555_Premultiplied |
|
2529 |
<< QImage::Format_ARGB8555_Premultiplied; |
|
2530 |
||
2531 |
QTest::newRow("RGB888 on RGB888") << QImage::Format_RGB888 |
|
2532 |
<< QImage::Format_RGB888; |
|
2533 |
||
2534 |
QTest::newRow("RGB32 on RGB16") << QImage::Format_RGB16 |
|
2535 |
<< QImage::Format_RGB32; |
|
2536 |
||
2537 |
QTest::newRow("RGB32 on ARGB8565_Premultiplied") << QImage::Format_ARGB8565_Premultiplied |
|
2538 |
<< QImage::Format_RGB32; |
|
2539 |
||
2540 |
QTest::newRow("RGB32 on RGB666") << QImage::Format_RGB666 |
|
2541 |
<< QImage::Format_RGB32; |
|
2542 |
||
2543 |
QTest::newRow("RGB32 on RGB555") << QImage::Format_RGB555 |
|
2544 |
<< QImage::Format_RGB32; |
|
2545 |
||
2546 |
QTest::newRow("RGB32 on ARGB8555_Premultiplied") << QImage::Format_ARGB8555_Premultiplied |
|
2547 |
<< QImage::Format_RGB32; |
|
2548 |
||
2549 |
QTest::newRow("RGB32 on RGB888") << QImage::Format_RGB888 |
|
2550 |
<< QImage::Format_RGB32; |
|
2551 |
||
2552 |
QTest::newRow("RGB16 on RGB32") << QImage::Format_RGB32 |
|
2553 |
<< QImage::Format_RGB16; |
|
2554 |
||
2555 |
QTest::newRow("ARGB8565_Premultiplied on RGB32") << QImage::Format_RGB32 |
|
2556 |
<< QImage::Format_ARGB8565_Premultiplied; |
|
2557 |
||
2558 |
QTest::newRow("RGB666 on RGB32") << QImage::Format_RGB32 |
|
2559 |
<< QImage::Format_RGB666; |
|
2560 |
||
2561 |
QTest::newRow("RGB555 on RGB32") << QImage::Format_RGB32 |
|
2562 |
<< QImage::Format_RGB555; |
|
2563 |
||
2564 |
QTest::newRow("ARGB8555_Premultiplied on RGB32") << QImage::Format_RGB32 |
|
2565 |
<< QImage::Format_ARGB8555_Premultiplied; |
|
2566 |
||
2567 |
QTest::newRow("RGB888 on RGB32") << QImage::Format_RGB32 |
|
2568 |
<< QImage::Format_RGB888; |
|
2569 |
||
2570 |
QTest::newRow("RGB555 on RGB888") << QImage::Format_RGB888 |
|
2571 |
<< QImage::Format_RGB555; |
|
2572 |
||
2573 |
QTest::newRow("RGB666 on RGB888") << QImage::Format_RGB888 |
|
2574 |
<< QImage::Format_RGB666; |
|
2575 |
||
2576 |
QTest::newRow("RGB444 on RGB444") << QImage::Format_RGB444 |
|
2577 |
<< QImage::Format_RGB444; |
|
2578 |
} |
|
2579 |
||
2580 |
void tst_QPainter::setOpacity() |
|
2581 |
{ |
|
2582 |
QFETCH(QImage::Format, destFormat); |
|
2583 |
QFETCH(QImage::Format, srcFormat); |
|
2584 |
||
2585 |
const QSize imageSize(12, 12); |
|
2586 |
const QRect imageRect(QPoint(0, 0), imageSize); |
|
2587 |
QColor destColor = Qt::black; |
|
2588 |
QColor srcColor = Qt::white; |
|
2589 |
||
2590 |
QImage dest(imageSize, destFormat); |
|
2591 |
QImage src(imageSize, srcFormat); |
|
2592 |
||
2593 |
QPainter p; |
|
2594 |
p.begin(&dest); |
|
2595 |
p.fillRect(imageRect, destColor); |
|
2596 |
p.end(); |
|
2597 |
||
2598 |
p.begin(&src); |
|
2599 |
p.fillRect(imageRect, srcColor); |
|
2600 |
p.end(); |
|
2601 |
||
2602 |
p.begin(&dest); |
|
2603 |
p.setOpacity(0.5); |
|
2604 |
p.drawImage(imageRect, src, imageRect); |
|
2605 |
p.end(); |
|
2606 |
||
2607 |
QImage expected(imageSize, destFormat); |
|
2608 |
p.begin(&expected); |
|
2609 |
p.fillRect(imageRect, QColor(127, 127, 127)); |
|
2610 |
p.end(); |
|
2611 |
||
2612 |
QCOMPARE(dest, expected); |
|
2613 |
} |
|
2614 |
||
2615 |
void tst_QPainter::drawhelper_blend_untransformed_data() |
|
2616 |
{ |
|
2617 |
setOpacity_data(); |
|
2618 |
} |
|
2619 |
||
2620 |
void tst_QPainter::drawhelper_blend_untransformed() |
|
2621 |
{ |
|
2622 |
QFETCH(QImage::Format, destFormat); |
|
2623 |
QFETCH(QImage::Format, srcFormat); |
|
2624 |
||
2625 |
const int size = 128; |
|
2626 |
const QSize imageSize(size, size); |
|
2627 |
const QRect paintRect(1, 0, size - 2, size); // needs alignment and tailing |
|
2628 |
||
2629 |
QColor destColor(127, 127, 127); |
|
2630 |
QColor srcColor(Qt::white); |
|
2631 |
||
2632 |
QImage dest(imageSize, destFormat); |
|
2633 |
QImage src(imageSize, srcFormat); |
|
2634 |
||
2635 |
QPainter p; |
|
2636 |
p.begin(&src); |
|
2637 |
p.fillRect(paintRect, srcColor); |
|
2638 |
p.end(); |
|
2639 |
||
2640 |
QList<qreal> opacities = (QList<qreal>() << 0.0 << 0.1 << 0.01 << 0.4 |
|
2641 |
<< 0.5 << 0.6 << 0.9 << 1.0); |
|
2642 |
foreach (qreal opacity, opacities) { |
|
2643 |
p.begin(&dest); |
|
2644 |
p.fillRect(paintRect, destColor); |
|
2645 |
||
2646 |
p.setOpacity(opacity); |
|
2647 |
p.drawImage(paintRect, src, paintRect); |
|
2648 |
p.end(); |
|
2649 |
||
2650 |
// sanity check: make sure all pixels are equal |
|
2651 |
QImage expected(size - 2, size, destFormat); |
|
2652 |
p.begin(&expected); |
|
2653 |
p.fillRect(0, 0, expected.width(), expected.height(), |
|
2654 |
QColor(dest.pixel(1, 0))); |
|
2655 |
p.end(); |
|
2656 |
||
2657 |
const QImage subDest(dest.bits() + dest.depth() / 8, |
|
2658 |
dest.width() - 2, dest.height(), |
|
2659 |
dest.bytesPerLine(), dest.format()); |
|
2660 |
||
2661 |
if (dest.format() == QImage::Format_ARGB8565_Premultiplied || |
|
2662 |
dest.format() == QImage::Format_ARGB8555_Premultiplied) { |
|
2663 |
// Test skipped due to rounding errors... |
|
2664 |
continue; |
|
2665 |
} |
|
2666 |
#if 0 |
|
2667 |
if (subDest != expected) { |
|
2668 |
qDebug() << "size" << size << "opacity" << opacity; |
|
2669 |
for (int j = 0; j < expected.height(); ++j) { |
|
2670 |
for (int i = 0; i < expected.width(); ++i) { |
|
2671 |
if (expected.pixel(i,j) != subDest.pixel(i,j)) |
|
2672 |
qDebug() << i << j << hex << expected.pixel(i, j) |
|
2673 |
<< subDest.pixel(i, j); |
|
2674 |
} |
|
2675 |
} |
|
2676 |
} |
|
2677 |
#endif |
|
2678 |
QCOMPARE(subDest, expected); |
|
2679 |
} |
|
2680 |
} |
|
2681 |
||
2682 |
void tst_QPainter::drawhelper_blend_tiled_untransformed_data() |
|
2683 |
{ |
|
2684 |
setOpacity_data(); |
|
2685 |
} |
|
2686 |
||
2687 |
void tst_QPainter::drawhelper_blend_tiled_untransformed() |
|
2688 |
{ |
|
2689 |
QFETCH(QImage::Format, destFormat); |
|
2690 |
QFETCH(QImage::Format, srcFormat); |
|
2691 |
||
2692 |
const int size = 128; |
|
2693 |
const QSize imageSize(size, size); |
|
2694 |
const QRect paintRect(1, 0, size - 2, size); // needs alignment and tailing |
|
2695 |
||
2696 |
QColor destColor(127, 127, 127); |
|
2697 |
QColor srcColor(Qt::white); |
|
2698 |
||
2699 |
QImage dest(imageSize, destFormat); |
|
2700 |
QImage src(imageSize / 2, srcFormat); |
|
2701 |
||
2702 |
QPainter p; |
|
2703 |
p.begin(&src); |
|
2704 |
p.fillRect(QRect(QPoint(0, 0), imageSize/ 2), srcColor); |
|
2705 |
p.end(); |
|
2706 |
||
2707 |
const QBrush brush(src); |
|
2708 |
||
2709 |
QList<qreal> opacities = (QList<qreal>() << 0.0 << 0.1 << 0.01 << 0.4 |
|
2710 |
<< 0.5 << 0.6 << 0.9 << 1.0); |
|
2711 |
foreach (qreal opacity, opacities) { |
|
2712 |
p.begin(&dest); |
|
2713 |
p.fillRect(paintRect, destColor); |
|
2714 |
||
2715 |
p.setOpacity(opacity); |
|
2716 |
p.fillRect(paintRect, brush); |
|
2717 |
p.end(); |
|
2718 |
||
2719 |
// sanity check: make sure all pixels are equal |
|
2720 |
QImage expected(size - 2, size, destFormat); |
|
2721 |
p.begin(&expected); |
|
2722 |
p.fillRect(0, 0, expected.width(), expected.height(), |
|
2723 |
QColor(dest.pixel(1, 0))); |
|
2724 |
p.end(); |
|
2725 |
||
2726 |
const QImage subDest(dest.bits() + dest.depth() / 8, |
|
2727 |
dest.width() - 2, dest.height(), |
|
2728 |
dest.bytesPerLine(), dest.format()); |
|
2729 |
||
2730 |
if (dest.format() == QImage::Format_ARGB8565_Premultiplied || |
|
2731 |
dest.format() == QImage::Format_ARGB8555_Premultiplied) { |
|
2732 |
// Skipping test due to rounding errors. Test needs rewrite |
|
2733 |
continue; |
|
2734 |
} |
|
2735 |
#if 0 |
|
2736 |
if (subDest != expected) { |
|
2737 |
qDebug() << "size" << size << "opacity" << opacity; |
|
2738 |
for (int j = 0; j < expected.height(); ++j) { |
|
2739 |
for (int i = 0; i < expected.width(); ++i) { |
|
2740 |
if (expected.pixel(i,j) != subDest.pixel(i,j)) |
|
2741 |
qDebug() << i << j << hex << expected.pixel(i, j) |
|
2742 |
<< subDest.pixel(i, j); |
|
2743 |
} |
|
2744 |
} |
|
2745 |
} |
|
2746 |
#endif |
|
2747 |
QCOMPARE(subDest, expected); |
|
2748 |
} |
|
2749 |
} |
|
2750 |
||
2751 |
static QPaintEngine::PaintEngineFeatures no_porter_duff() |
|
2752 |
{ |
|
2753 |
QPaintEngine::PaintEngineFeatures features = QPaintEngine::AllFeatures; |
|
2754 |
return features & ~QPaintEngine::PorterDuff; |
|
2755 |
} |
|
2756 |
||
2757 |
class DummyPaintEngine : public QPaintEngine, public QPaintDevice |
|
2758 |
{ |
|
2759 |
public: |
|
2760 |
DummyPaintEngine() : QPaintEngine(no_porter_duff()) {} |
|
2761 |
virtual bool begin(QPaintDevice *) { return true; } |
|
2762 |
virtual bool end() { return true; } |
|
2763 |
||
2764 |
virtual void updateState(const QPaintEngineState &) {} |
|
2765 |
virtual void drawPixmap(const QRectF &, const QPixmap &, const QRectF &) {} |
|
2766 |
||
2767 |
virtual Type type() const { return User; } |
|
2768 |
||
2769 |
virtual QPaintEngine *paintEngine() const { return (QPaintEngine *)this; } |
|
2770 |
||
2771 |
virtual int metric(PaintDeviceMetric metric) const { Q_UNUSED(metric); return 0; }; |
|
2772 |
}; |
|
2773 |
||
2774 |
static bool success; |
|
2775 |
||
2776 |
void porterDuff_warningChecker(QtMsgType type, const char *msg) |
|
2777 |
{ |
|
2778 |
if (type == QtWarningMsg && msg == QLatin1String("QPainter::setCompositionMode: PorterDuff modes not supported on device")) |
|
2779 |
success = false; |
|
2780 |
} |
|
2781 |
||
2782 |
void tst_QPainter::porterDuff_warning() |
|
2783 |
{ |
|
2784 |
QtMsgHandler old = qInstallMsgHandler(porterDuff_warningChecker); |
|
2785 |
DummyPaintEngine dummy; |
|
2786 |
QPainter p(&dummy); |
|
2787 |
||
2788 |
success = true; |
|
2789 |
p.setCompositionMode(QPainter::CompositionMode_Source); |
|
2790 |
QVERIFY(success); |
|
2791 |
||
2792 |
success = true; |
|
2793 |
p.setCompositionMode(QPainter::CompositionMode_SourceOver); |
|
2794 |
QVERIFY(success); |
|
2795 |
||
2796 |
success = true; |
|
2797 |
p.setCompositionMode(QPainter::CompositionMode_DestinationOver); |
|
2798 |
QVERIFY(!success); |
|
2799 |
||
2800 |
QVERIFY(qInstallMsgHandler(old) == porterDuff_warningChecker); |
|
2801 |
} |
|
2802 |
||
2803 |
class quint24 |
|
2804 |
{ |
|
2805 |
public: |
|
2806 |
inline quint24(quint32 v) |
|
2807 |
{ |
|
2808 |
data[0] = qBlue(v); |
|
2809 |
data[1] = qGreen(v); |
|
2810 |
data[2] = qRed(v); |
|
2811 |
} |
|
2812 |
||
2813 |
inline operator quint32 () |
|
2814 |
{ |
|
2815 |
return qRgb(data[2], data[1], data[0]); |
|
2816 |
} |
|
2817 |
||
2818 |
inline bool operator==(const quint24 &v) const { |
|
2819 |
return (data[0] == v.data[0] && data[1] == v.data[1] && data[2] == v.data[2]); |
|
2820 |
} |
|
2821 |
||
2822 |
uchar data[3]; |
|
2823 |
} Q_PACKED; |
|
2824 |
||
2825 |
void tst_QPainter::drawhelper_blend_color() |
|
2826 |
{ |
|
2827 |
QImage dest(32, 32, QImage::Format_ARGB8555_Premultiplied); |
|
2828 |
dest.fill(0xff000000); |
|
2829 |
||
2830 |
{ |
|
2831 |
QPainter p(&dest); |
|
2832 |
p.fillRect(0, 0, dest.width(), dest.height(), QColor(255, 0, 0, 127)); |
|
2833 |
} |
|
2834 |
||
2835 |
QImage expected(32, 32, QImage::Format_ARGB8555_Premultiplied); |
|
2836 |
expected.fill(0xff3c007f); |
|
2837 |
||
2838 |
QCOMPARE(dest.pixel(1, 1), expected.pixel(1, 1)); |
|
2839 |
QCOMPARE(dest, expected); |
|
2840 |
} |
|
2841 |
||
2842 |
class ViewportTestWidget : public QWidget |
|
2843 |
{ |
|
2844 |
public: |
|
2845 |
ViewportTestWidget(QWidget *parent = 0) : QWidget(parent), hasPainted(false) {} |
|
2846 |
QSize sizeHint() const { |
|
2847 |
return QSize(100, 100); |
|
2848 |
} |
|
2849 |
||
2850 |
QRect viewport; |
|
2851 |
bool hasPainted; |
|
2852 |
||
2853 |
protected: |
|
2854 |
void paintEvent(QPaintEvent *) { |
|
2855 |
hasPainted = true; |
|
2856 |
QPainter p(this); |
|
2857 |
viewport = p.viewport(); |
|
2858 |
} |
|
2859 |
}; |
|
2860 |
||
2861 |
void tst_QPainter::childWidgetViewport() |
|
2862 |
{ |
|
2863 |
QWidget parent; |
|
2864 |
parent.setAutoFillBackground(true); |
|
2865 |
parent.resize(200, 200); |
|
2866 |
ViewportTestWidget child(&parent); |
|
2867 |
child.setAutoFillBackground(true); |
|
2868 |
parent.show(); |
|
2869 |
parent.update(); |
|
2870 |
qApp->processEvents(); |
|
2871 |
||
2872 |
if (child.hasPainted) { |
|
2873 |
QCOMPARE(child.viewport, QRect(QPoint(0, 0), child.sizeHint())); |
|
2874 |
} else { |
|
2875 |
qWarning("Failed to ensure that paintEvent has been run. Could not run test."); |
|
2876 |
} |
|
2877 |
} |
|
2878 |
||
2879 |
void tst_QPainter::fillRect_objectBoundingModeGradient() |
|
2880 |
{ |
|
2881 |
QImage a(10, 10, QImage::Format_ARGB32_Premultiplied); |
|
2882 |
a.fill(0x0); |
|
2883 |
QImage b = a; |
|
2884 |
||
2885 |
QLinearGradient g(QPoint(0, 0), QPoint(0, 1)); |
|
2886 |
g.setColorAt(0, Qt::red); |
|
2887 |
g.setColorAt(1, Qt::blue); |
|
2888 |
g.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
2889 |
||
2890 |
QPainter p(&a); |
|
2891 |
p.fillRect(QRect(0, 0, a.width(), a.height()), g); |
|
2892 |
p.end(); |
|
2893 |
||
2894 |
QPainterPath path; |
|
2895 |
path.addRect(0, 0, a.width(), a.height()); |
|
2896 |
||
2897 |
p.begin(&b); |
|
2898 |
p.fillPath(path, g); |
|
2899 |
p.end(); |
|
2900 |
||
2901 |
QCOMPARE(a, b); |
|
2902 |
} |
|
2903 |
||
2904 |
void tst_QPainter::fillRect_stretchToDeviceMode() |
|
2905 |
{ |
|
2906 |
QImage img(64, 64, QImage::Format_ARGB32_Premultiplied); |
|
2907 |
||
2908 |
QLinearGradient g(QPoint(0, 0), QPoint(0, 1)); |
|
2909 |
g.setCoordinateMode(QGradient::StretchToDeviceMode); |
|
2910 |
||
2911 |
QPainter p(&img); |
|
2912 |
p.fillRect(img.rect(), g); |
|
2913 |
p.end(); |
|
2914 |
||
2915 |
for (int i = 1; i < img.height(); ++i) |
|
2916 |
QVERIFY(img.pixel(0, i) != img.pixel(0, i-1)); |
|
2917 |
} |
|
2918 |
||
2919 |
void tst_QPainter::monoImages() |
|
2920 |
{ |
|
2921 |
Qt::GlobalColor colorPairs[][2] = { |
|
2922 |
{ Qt::white, Qt::black }, |
|
2923 |
{ Qt::color0, Qt::color1 }, |
|
2924 |
{ Qt::red, Qt::blue } |
|
2925 |
}; |
|
2926 |
||
2927 |
const int numColorPairs = sizeof(colorPairs) / sizeof(QRgb[2]); |
|
2928 |
||
2929 |
QImage transparent(2, 2, QImage::Format_ARGB32_Premultiplied); |
|
2930 |
transparent.fill(0x0); |
|
2931 |
||
2932 |
for (int i = 1; i < QImage::NImageFormats; ++i) { |
|
2933 |
for (int j = 0; j < numColorPairs; ++j) { |
|
2934 |
const QImage::Format format = QImage::Format(i); |
|
2935 |
if (format == QImage::Format_Indexed8) |
|
2936 |
continue; |
|
2937 |
||
2938 |
QImage img(2, 2, format); |
|
2939 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2940 |
if (img.colorCount() > 0) { |
0 | 2941 |
img.setColor(0, QColor(colorPairs[j][0]).rgba()); |
2942 |
img.setColor(1, QColor(colorPairs[j][1]).rgba()); |
|
2943 |
} |
|
2944 |
||
2945 |
img.fill(0x0); |
|
2946 |
QPainter p(&img); |
|
2947 |
p.fillRect(0, 0, 2, 2, colorPairs[j][0]); |
|
2948 |
p.fillRect(0, 0, 1, 1, colorPairs[j][1]); |
|
2949 |
p.fillRect(1, 1, 1, 1, colorPairs[j][1]); |
|
2950 |
p.end(); |
|
2951 |
||
2952 |
QImage original = img; |
|
2953 |
||
2954 |
p.begin(&img); |
|
2955 |
p.drawImage(0, 0, transparent); |
|
2956 |
p.end(); |
|
2957 |
||
2958 |
// drawing a transparent image on top of another image |
|
2959 |
// should not change the image |
|
2960 |
QCOMPARE(original, img); |
|
2961 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2962 |
if (img.colorCount() == 0) |
0 | 2963 |
continue; |
2964 |
||
2965 |
for (int k = 0; k < 2; ++k) { |
|
2966 |
QPainter p(&img); |
|
2967 |
p.fillRect(0, 0, 2, 2, colorPairs[j][k]); |
|
2968 |
p.end(); |
|
2969 |
||
2970 |
QImage argb32p(2, 2, QImage::Format_ARGB32_Premultiplied); |
|
2971 |
p.begin(&argb32p); |
|
2972 |
p.fillRect(0, 0, 2, 2, colorPairs[j][k]); |
|
2973 |
p.end(); |
|
2974 |
||
2975 |
QCOMPARE(argb32p, img.convertToFormat(argb32p.format())); |
|
2976 |
||
2977 |
// drawing argb32p image on mono image |
|
2978 |
p.begin(&img); |
|
2979 |
p.drawImage(0, 0, argb32p); |
|
2980 |
p.end(); |
|
2981 |
||
2982 |
QCOMPARE(argb32p, img.convertToFormat(argb32p.format())); |
|
2983 |
||
2984 |
// drawing mono image on argb32p image |
|
2985 |
p.begin(&argb32p); |
|
2986 |
p.drawImage(0, 0, img); |
|
2987 |
p.end(); |
|
2988 |
||
2989 |
QCOMPARE(argb32p, img.convertToFormat(argb32p.format())); |
|
2990 |
} |
|
2991 |
} |
|
2992 |
} |
|
2993 |
} |
|
2994 |
||
2995 |
#if !defined(Q_OS_IRIX) && !defined(Q_OS_AIX) && !defined(Q_CC_MSVC) && !defined(Q_OS_SOLARIS) && !defined(Q_OS_SYMBIAN) |
|
2996 |
#include <fenv.h> |
|
2997 |
||
2998 |
static const QString fpeExceptionString(int exception) |
|
2999 |
{ |
|
3000 |
#ifdef FE_INEXACT |
|
3001 |
if (exception & FE_INEXACT) |
|
3002 |
return QLatin1String("Inexact result"); |
|
3003 |
#endif |
|
3004 |
if (exception & FE_UNDERFLOW) |
|
3005 |
return QLatin1String("Underflow"); |
|
3006 |
if (exception & FE_OVERFLOW) |
|
3007 |
return QLatin1String("Overflow"); |
|
3008 |
if (exception & FE_DIVBYZERO) |
|
3009 |
return QLatin1String("Divide by zero"); |
|
3010 |
if (exception & FE_INVALID) |
|
3011 |
return QLatin1String("Invalid operation"); |
|
3012 |
return QLatin1String("No exception"); |
|
3013 |
} |
|
3014 |
||
3015 |
class FpExceptionChecker |
|
3016 |
{ |
|
3017 |
public: |
|
3018 |
FpExceptionChecker(int exceptionMask) |
|
3019 |
: m_exceptionMask(exceptionMask) |
|
3020 |
{ |
|
3021 |
feclearexcept(m_exceptionMask); |
|
3022 |
} |
|
3023 |
||
3024 |
~FpExceptionChecker() |
|
3025 |
{ |
|
3026 |
const int exceptions = fetestexcept(m_exceptionMask); |
|
3027 |
QVERIFY2(!exceptions, qPrintable(QLatin1String("Floating point exception: ") + fpeExceptionString(exceptions))); |
|
3028 |
} |
|
3029 |
||
3030 |
private: |
|
3031 |
int m_exceptionMask; |
|
3032 |
}; |
|
3033 |
||
3034 |
void fpe_rasterizeLine_task232012() |
|
3035 |
{ |
|
3036 |
FpExceptionChecker checker(FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID | FE_DIVBYZERO); |
|
3037 |
QImage img(128, 128, QImage::Format_ARGB32_Premultiplied); |
|
3038 |
img.fill(0x0); |
|
3039 |
QPainter p(&img); |
|
3040 |
||
3041 |
p.setBrush(Qt::black); |
|
3042 |
p.drawRect(QRectF(0, 0, 5, 0)); |
|
3043 |
p.drawRect(QRectF(0, 0, 0, 5)); |
|
3044 |
} |
|
3045 |
||
3046 |
void fpe_pixmapTransform() |
|
3047 |
{ |
|
3048 |
FpExceptionChecker checker(FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID | FE_DIVBYZERO); |
|
3049 |
||
3050 |
QImage img(128, 128, QImage::Format_ARGB32_Premultiplied); |
|
3051 |
||
3052 |
QPainter p(&img); |
|
3053 |
||
3054 |
const qreal scaleFactor = 0.001; |
|
3055 |
const int translateDistance = 1000000; |
|
3056 |
||
3057 |
p.setPen(Qt::red); |
|
3058 |
p.setBrush(QBrush(Qt::red,Qt::Dense6Pattern)); |
|
3059 |
||
3060 |
for (int i = 0; i < 2; ++i) { |
|
3061 |
p.setRenderHint(QPainter::SmoothPixmapTransform, i); |
|
3062 |
||
3063 |
p.resetTransform(); |
|
3064 |
p.scale(1.1, 1.1); |
|
3065 |
p.translate(translateDistance, 0); |
|
3066 |
p.drawRect(-translateDistance, 0, 100, 100); |
|
3067 |
||
3068 |
p.resetTransform(); |
|
3069 |
p.scale(scaleFactor, scaleFactor); |
|
3070 |
p.drawRect(QRectF(0, 0, 1 / scaleFactor, 1 / scaleFactor)); |
|
3071 |
} |
|
3072 |
} |
|
3073 |
||
3074 |
void fpe_zeroLengthLines() |
|
3075 |
{ |
|
3076 |
FpExceptionChecker checker(FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID | FE_DIVBYZERO); |
|
3077 |
||
3078 |
QImage img(128, 128, QImage::Format_ARGB32_Premultiplied); |
|
3079 |
||
3080 |
QPainter p(&img); |
|
3081 |
||
3082 |
p.setPen(QPen(Qt::black, 3)); |
|
3083 |
p.drawLine(64, 64, 64, 64); |
|
3084 |
} |
|
3085 |
||
3086 |
void fpe_divByZero() |
|
3087 |
{ |
|
3088 |
FpExceptionChecker checker(FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID | FE_DIVBYZERO); |
|
3089 |
||
3090 |
QImage img(128, 128, QImage::Format_ARGB32_Premultiplied); |
|
3091 |
||
3092 |
QPainter p(&img); |
|
3093 |
||
3094 |
p.setRenderHint(QPainter::Antialiasing); |
|
3095 |
||
3096 |
p.drawRect(QRectF(10, 10, 100, 0)); |
|
3097 |
p.drawRect(QRectF(10, 10, 0, 100)); |
|
3098 |
||
3099 |
p.drawRect(QRect(10, 10, 100, 0)); |
|
3100 |
p.drawRect(QRect(10, 10, 0, 100)); |
|
3101 |
||
3102 |
p.fillRect(QRectF(10, 10, 100, 0), Qt::black); |
|
3103 |
p.fillRect(QRectF(10, 10, 0, 100), Qt::black); |
|
3104 |
||
3105 |
p.fillRect(QRect(10, 10, 100, 0), Qt::black); |
|
3106 |
p.fillRect(QRect(10, 10, 0, 100), Qt::black); |
|
3107 |
} |
|
3108 |
||
3109 |
void fpe_steepSlopes() |
|
3110 |
{ |
|
3111 |
FpExceptionChecker checker(FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID | FE_DIVBYZERO); |
|
3112 |
||
3113 |
QImage img(1024, 1024, QImage::Format_ARGB32_Premultiplied); |
|
3114 |
||
3115 |
QFETCH(QTransform, transform); |
|
3116 |
QFETCH(QLineF, line); |
|
3117 |
QFETCH(bool, antialiased); |
|
3118 |
||
3119 |
QPainter p(&img); |
|
3120 |
||
3121 |
p.setPen(QPen(Qt::black, 1)); |
|
3122 |
p.setRenderHint(QPainter::Antialiasing, antialiased); |
|
3123 |
p.setTransform(transform); |
|
3124 |
||
3125 |
QEXPECT_FAIL("steep line 3 aa", "needs to be fixed", Continue); |
|
3126 |
p.drawLine(line); |
|
3127 |
} |
|
3128 |
||
3129 |
void fpe_radialGradients() |
|
3130 |
{ |
|
3131 |
FpExceptionChecker checker(FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID | FE_DIVBYZERO); |
|
3132 |
||
3133 |
QImage img(21, 21, QImage::Format_ARGB32_Premultiplied); |
|
3134 |
img.fill(0); |
|
3135 |
||
3136 |
double m = img.width() * 0.5; |
|
3137 |
||
3138 |
QPainter p(&img); |
|
3139 |
p.setRenderHints(QPainter::Antialiasing); |
|
3140 |
p.setPen(Qt::NoPen); |
|
3141 |
p.setBrush(QRadialGradient(m, m, m)); |
|
3142 |
p.drawEllipse(img.rect()); |
|
3143 |
} |
|
3144 |
||
3145 |
#define FPE_TEST(x) \ |
|
3146 |
void tst_QPainter::x() \ |
|
3147 |
{ \ |
|
3148 |
::x(); \ |
|
3149 |
} |
|
3150 |
#else |
|
3151 |
#define FPE_TEST(x) \ |
|
3152 |
void tst_QPainter::x() \ |
|
3153 |
{ \ |
|
3154 |
QSKIP("Floating point exception checking (fenv.h) not available", SkipAll); \ |
|
3155 |
} |
|
3156 |
#endif |
|
3157 |
||
3158 |
FPE_TEST(fpe_rasterizeLine_task232012) |
|
3159 |
FPE_TEST(fpe_pixmapTransform) |
|
3160 |
FPE_TEST(fpe_zeroLengthLines) |
|
3161 |
FPE_TEST(fpe_divByZero) |
|
3162 |
FPE_TEST(fpe_steepSlopes) |
|
3163 |
FPE_TEST(fpe_radialGradients) |
|
3164 |
||
3165 |
void tst_QPainter::fpe_steepSlopes_data() |
|
3166 |
{ |
|
3167 |
QTest::addColumn<QTransform>("transform"); |
|
3168 |
QTest::addColumn<QLineF>("line"); |
|
3169 |
QTest::addColumn<bool>("antialiased"); |
|
3170 |
||
3171 |
{ |
|
3172 |
const qreal dsin = 0.000014946676875461832484392500630665523431162000633776187896728515625; |
|
3173 |
const qreal dcos = 0.9999999998882984630910186751862056553363800048828125; |
|
3174 |
||
3175 |
const QTransform transform = QTransform(QMatrix(dcos, dsin, -dsin, dcos, 64, 64)); |
|
3176 |
const QLineF line(2, 2, 2, 6); |
|
3177 |
||
3178 |
QTest::newRow("task 207147 aa") << transform << line << true; |
|
3179 |
QTest::newRow("task 207147 no aa") << transform << line << false; |
|
3180 |
} |
|
3181 |
||
3182 |
{ |
|
3183 |
QTransform transform; |
|
3184 |
transform.rotate(0.0000001); |
|
3185 |
const QLineF line(5, 5, 10, 5); |
|
3186 |
||
3187 |
QTest::newRow("task 166702 aa") << transform << line << true; |
|
3188 |
QTest::newRow("task 166702 no aa") << transform << line << false; |
|
3189 |
} |
|
3190 |
||
3191 |
{ |
|
3192 |
const QTransform transform; |
|
3193 |
const QLineF line(2.5, 2.5, 2.5 + 1/256., 60000.5); |
|
3194 |
||
3195 |
QTest::newRow("steep line aa") << transform << line << true; |
|
3196 |
QTest::newRow("steep line no aa") << transform << line << false; |
|
3197 |
} |
|
3198 |
||
3199 |
{ |
|
3200 |
const QTransform transform; |
|
3201 |
const QLineF line(2.5, 2.5, 2.5 + 1/256., 1024); |
|
3202 |
||
3203 |
QTest::newRow("steep line 2 aa") << transform << line << true; |
|
3204 |
QTest::newRow("steep line 2 no aa") << transform << line << false; |
|
3205 |
} |
|
3206 |
||
3207 |
{ |
|
3208 |
const QTransform transform; |
|
3209 |
const QLineF line(2.5, 2.5, 2.5 + 1/64., 1024); |
|
3210 |
||
3211 |
QTest::newRow("steep line 3 aa") << transform << line << true; |
|
3212 |
QTest::newRow("steep line 3 no aa") << transform << line << false; |
|
3213 |
} |
|
3214 |
} |
|
3215 |
||
3216 |
qreal randf() |
|
3217 |
{ |
|
3218 |
return rand() / (RAND_MAX + 1.0); |
|
3219 |
} |
|
3220 |
||
3221 |
QPointF randInRect(const QRectF &rect) |
|
3222 |
{ |
|
3223 |
const qreal x = rect.left() + rect.width() * randf(); |
|
3224 |
const qreal y = rect.top() + rect.height() * randf(); |
|
3225 |
||
3226 |
return QPointF(x, y); |
|
3227 |
} |
|
3228 |
||
3229 |
void tst_QPainter::rasterizer_asserts() |
|
3230 |
{ |
|
3231 |
QImage img(64, 64, QImage::Format_ARGB32_Premultiplied); |
|
3232 |
||
3233 |
QRectF middle(QPointF(0, 0), img.size()); |
|
3234 |
QRectF left = middle.translated(-middle.width(), 0); |
|
3235 |
QRectF right = middle.translated(middle.width(), 0); |
|
3236 |
||
3237 |
QPainter p(&img); |
|
3238 |
img.fill(Qt::white); |
|
3239 |
p.setCompositionMode(QPainter::CompositionMode_Destination); |
|
3240 |
for (int i = 0; i < 100000; ++i) { |
|
3241 |
QPainterPath path; |
|
3242 |
path.moveTo(randInRect(middle)); |
|
3243 |
path.lineTo(randInRect(left)); |
|
3244 |
path.lineTo(randInRect(right)); |
|
3245 |
||
3246 |
p.fillPath(path, Qt::black); |
|
3247 |
} |
|
3248 |
} |
|
3249 |
||
3250 |
void tst_QPainter::rasterizer_negativeCoords() |
|
3251 |
{ |
|
3252 |
QImage img(64, 64, QImage::Format_ARGB32_Premultiplied); |
|
3253 |
img.fill(0x0); |
|
3254 |
||
3255 |
QImage original = img; |
|
3256 |
||
3257 |
QPainter p(&img); |
|
3258 |
p.rotate(90); |
|
3259 |
p.fillRect(0, 0, 70, 50, Qt::black); |
|
3260 |
||
3261 |
// image should not have changed |
|
3262 |
QCOMPARE(img.pixel(0, 0), 0x0U); |
|
3263 |
QCOMPARE(img, original); |
|
3264 |
} |
|
3265 |
||
3266 |
void tst_QPainter::blendOverFlow_data() |
|
3267 |
{ |
|
3268 |
QTest::addColumn<QImage::Format>("format"); |
|
3269 |
QTest::addColumn<int>("width"); |
|
3270 |
QTest::addColumn<int>("height"); |
|
3271 |
||
3272 |
QImage::Format format = QImage::Format_ARGB8555_Premultiplied; |
|
3273 |
QTest::newRow("555,1,1") << format << 1 << 1; |
|
3274 |
QTest::newRow("555,2,2") << format << 2 << 2; |
|
3275 |
QTest::newRow("555,10,10") << format << 10 << 10; |
|
3276 |
||
3277 |
format = QImage::Format_ARGB8565_Premultiplied; |
|
3278 |
QTest::newRow("565,1,1") << format << 1 << 1; |
|
3279 |
QTest::newRow("565,2,2") << format << 2 << 2; |
|
3280 |
QTest::newRow("565,10,10") << format << 10 << 10; |
|
3281 |
} |
|
3282 |
||
3283 |
void tst_QPainter::blendOverFlow() |
|
3284 |
{ |
|
3285 |
QFETCH(QImage::Format, format); |
|
3286 |
QFETCH(int, width); |
|
3287 |
QFETCH(int, height); |
|
3288 |
||
3289 |
QImage dest(width, height, format); |
|
3290 |
QImage src(width, height, format); |
|
3291 |
||
3292 |
{ |
|
3293 |
QPainter p(&dest); |
|
3294 |
p.fillRect(0, 0, width, height, Qt::green); |
|
3295 |
} |
|
3296 |
QImage expected = dest; |
|
3297 |
||
3298 |
{ |
|
3299 |
QPainter p(&src); |
|
3300 |
p.setCompositionMode(QPainter::CompositionMode_Source); |
|
3301 |
p.fillRect(0, 0, width, height, QColor(0, 255, 0, 6)); |
|
3302 |
} |
|
3303 |
||
3304 |
{ |
|
3305 |
QPainter p(&dest); |
|
3306 |
p.drawImage(0, 0, src); |
|
3307 |
} |
|
3308 |
||
3309 |
QCOMPARE(dest.pixel(0, 0), expected.pixel(0, 0)); |
|
3310 |
QCOMPARE(dest, expected); |
|
3311 |
} |
|
3312 |
||
3313 |
void tst_QPainter::largeImagePainting_data() |
|
3314 |
{ |
|
3315 |
QTest::addColumn<int>("width"); |
|
3316 |
QTest::addColumn<int>("height"); |
|
3317 |
QTest::addColumn<bool>("antialiased"); |
|
3318 |
||
3319 |
QTest::newRow("tall") << 1 << 32767 << false; |
|
3320 |
QTest::newRow("tall aa") << 1 << 32767 << true; |
|
3321 |
QTest::newRow("wide") << 32767 << 1 << false; |
|
3322 |
QTest::newRow("wide aa") << 32767 << 1 << true; |
|
3323 |
} |
|
3324 |
||
3325 |
void tst_QPainter::largeImagePainting() |
|
3326 |
{ |
|
3327 |
QPainterPath path; |
|
3328 |
path.addRect(0, 0, 1, 1); |
|
3329 |
path.addRect(2, 0, 1, 1); |
|
3330 |
path.addRect(0, 2, 1, 1); |
|
3331 |
||
3332 |
QFETCH(int, width); |
|
3333 |
QFETCH(int, height); |
|
3334 |
QFETCH(bool, antialiased); |
|
3335 |
||
3336 |
QImage img(width, height, QImage::Format_ARGB32_Premultiplied); |
|
3337 |
img.fill(0x0); |
|
3338 |
||
3339 |
QPainter p(&img); |
|
3340 |
p.setPen(Qt::NoPen); |
|
3341 |
p.setBrush(Qt::white); |
|
3342 |
||
3343 |
p.setRenderHint(QPainter::Antialiasing, antialiased); |
|
3344 |
||
3345 |
for (int i = 0; i < img.width(); i += 4) { |
|
3346 |
p.drawPath(path); |
|
3347 |
p.translate(4, 0); |
|
3348 |
} |
|
3349 |
||
3350 |
p.resetMatrix(); |
|
3351 |
||
3352 |
for (int i = 4; i < img.height(); i += 4) { |
|
3353 |
p.translate(0, 4); |
|
3354 |
p.drawPath(path); |
|
3355 |
} |
|
3356 |
||
3357 |
for (int i = 0; i < img.width(); ++i) { |
|
3358 |
if (i % 2) |
|
3359 |
QCOMPARE(img.pixel(i, 0), 0x0U); |
|
3360 |
else |
|
3361 |
QCOMPARE(img.pixel(i, 0), 0xffffffffU); |
|
3362 |
} |
|
3363 |
||
3364 |
for (int i = 1; i < img.height(); ++i) { |
|
3365 |
if (i % 2) |
|
3366 |
QCOMPARE(img.pixel(0, i), 0x0U); |
|
3367 |
else |
|
3368 |
QCOMPARE(img.pixel(0, i), 0xffffffffU); |
|
3369 |
} |
|
3370 |
} |
|
3371 |
||
3372 |
void tst_QPainter::imageScaling_task206785() |
|
3373 |
{ |
|
3374 |
QImage src(32, 2, QImage::Format_ARGB32_Premultiplied); |
|
3375 |
src.fill(0xffffffff); |
|
3376 |
||
3377 |
QImage dst(128, 128, QImage::Format_ARGB32_Premultiplied); |
|
3378 |
||
3379 |
QImage expected(128, 128, QImage::Format_ARGB32_Premultiplied); |
|
3380 |
expected.fill(0xffffffff); |
|
3381 |
||
3382 |
for (int i = 1; i < 5; ++i) { |
|
3383 |
qreal scale = i / qreal(5); |
|
3384 |
||
3385 |
dst.fill(0xff000000); |
|
3386 |
||
3387 |
QPainter p(&dst); |
|
3388 |
p.scale(dst.width() / qreal(src.width()), scale); |
|
3389 |
||
3390 |
for (int y = 0; y * scale < dst.height(); ++y) |
|
3391 |
p.drawImage(0, y, src); |
|
3392 |
||
3393 |
p.end(); |
|
3394 |
||
3395 |
QCOMPARE(dst, expected); |
|
3396 |
} |
|
3397 |
} |
|
3398 |
||
3399 |
#define FOR_EACH_NEIGHBOR_8 for (int dx = -1; dx <= 1; ++dx) for (int dy = -1; dy <= 1; ++dy) if (dx != 0 || dy != 0) |
|
3400 |
#define FOR_EACH_NEIGHBOR_4 for (int dx = -1; dx <= 1; ++dx) for (int dy = -1; dy <= 1; ++dy) if ((dx == 0) != (dy == 0)) |
|
3401 |
||
3402 |
uint qHash(const QPoint &point) |
|
3403 |
{ |
|
3404 |
return qHash(qMakePair(point.x(), point.y())); |
|
3405 |
} |
|
3406 |
||
3407 |
bool verifyOutlineFillConsistency(const QImage &img, QRgb outside, QRgb inside, QRgb outline) |
|
3408 |
{ |
|
3409 |
if (img.pixel(img.width() / 2, img.height() / 2) != inside) |
|
3410 |
return false; |
|
3411 |
||
3412 |
int x = img.width() / 2; |
|
3413 |
int y = img.height() / 2; |
|
3414 |
||
3415 |
while (img.pixel(++x, y) == inside) |
|
3416 |
; |
|
3417 |
||
3418 |
if (img.pixel(x, y) != outline) |
|
3419 |
return false; |
|
3420 |
||
3421 |
QQueue<QPoint> discovered; |
|
3422 |
discovered.enqueue(QPoint(x, y)); |
|
3423 |
||
3424 |
QVector<bool> visited(img.width() * img.height()); |
|
3425 |
visited.fill(false); |
|
3426 |
||
3427 |
while (!discovered.isEmpty()) { |
|
3428 |
QPoint p = discovered.dequeue(); |
|
3429 |
QRgb pixel = img.pixel(p.x(), p.y()); |
|
3430 |
||
3431 |
bool &v = visited[p.y() * img.width() + p.x()]; |
|
3432 |
if (v) |
|
3433 |
continue; |
|
3434 |
v = true; |
|
3435 |
||
3436 |
if (pixel == outline) { |
|
3437 |
FOR_EACH_NEIGHBOR_8 { |
|
3438 |
QPoint x(p.x() + dx, p.y() + dy); |
|
3439 |
discovered.enqueue(x); |
|
3440 |
} |
|
3441 |
} else { |
|
3442 |
FOR_EACH_NEIGHBOR_4 { |
|
3443 |
if ((dx == 0) == (dy == 0)) |
|
3444 |
continue; |
|
3445 |
QRgb neighbor = img.pixel(p.x() + dx, p.y() + dy); |
|
3446 |
if (pixel == inside && neighbor == outside || |
|
3447 |
pixel == outside && neighbor == inside) |
|
3448 |
return false; |
|
3449 |
} |
|
3450 |
} |
|
3451 |
} |
|
3452 |
||
3453 |
return true; |
|
3454 |
} |
|
3455 |
||
3456 |
#undef FOR_EACH_NEIGHBOR_8 |
|
3457 |
#undef FOR_EACH_NEIGHBOR_4 |
|
3458 |
||
3459 |
void tst_QPainter::outlineFillConsistency() |
|
3460 |
{ |
|
3461 |
QImage dst(256, 256, QImage::Format_ARGB32_Premultiplied); |
|
3462 |
||
3463 |
QPolygonF poly; |
|
3464 |
poly << QPointF(5, -100) << QPointF(-70, 20) << QPointF(95, 25); |
|
3465 |
||
3466 |
QPen pen(Qt::red); |
|
3467 |
QBrush brush(Qt::black); |
|
3468 |
||
3469 |
QRgb background = 0xffffffff; |
|
3470 |
for (int i = 0; i < 360; ++i) { |
|
3471 |
dst.fill(background); |
|
3472 |
||
3473 |
QPainter p(&dst); |
|
3474 |
p.translate(dst.width() / 2, dst.height() / 2); |
|
3475 |
||
3476 |
QPolygonF copy = poly; |
|
3477 |
for (int j = 0; j < copy.size(); ++j) |
|
3478 |
copy[j] = QTransform().rotate(i).map(copy[j]); |
|
3479 |
||
3480 |
p.setPen(pen); |
|
3481 |
p.setBrush(brush); |
|
3482 |
p.drawPolygon(copy); |
|
3483 |
p.end(); |
|
3484 |
||
3485 |
#if 0 |
|
3486 |
if (!verifyOutlineFillConsistency(dst, background, p.brush().color().rgba(), p.pen().color().rgba())) |
|
3487 |
dst.save(QString("outlineFillConsistency-%1.png").arg(i)); |
|
3488 |
#endif |
|
3489 |
||
3490 |
QVERIFY(verifyOutlineFillConsistency(dst, background, brush.color().rgba(), pen.color().rgba())); |
|
3491 |
} |
|
3492 |
} |
|
3493 |
||
3494 |
void tst_QPainter::drawImage_task217400_data() |
|
3495 |
{ |
|
3496 |
QTest::addColumn<QImage::Format>("format"); |
|
3497 |
||
3498 |
QTest::newRow("444") << QImage::Format_ARGB4444_Premultiplied; |
|
3499 |
QTest::newRow("555") << QImage::Format_ARGB8555_Premultiplied; |
|
3500 |
QTest::newRow("565") << QImage::Format_ARGB8565_Premultiplied; |
|
3501 |
// QTest::newRow("666") << QImage::Format_ARGB6666_Premultiplied; |
|
3502 |
QTest::newRow("888p") << QImage::Format_ARGB32_Premultiplied; |
|
3503 |
QTest::newRow("888") << QImage::Format_ARGB32; |
|
3504 |
} |
|
3505 |
||
3506 |
void tst_QPainter::drawImage_task217400() |
|
3507 |
{ |
|
3508 |
QFETCH(QImage::Format, format); |
|
3509 |
||
3510 |
const QImage src = QImage(QString(SRCDIR) + "/task217400.png") |
|
3511 |
.convertToFormat(format); |
|
3512 |
QVERIFY(!src.isNull()); |
|
3513 |
||
3514 |
QImage expected(src.size(), format); |
|
3515 |
{ |
|
3516 |
QPainter p(&expected); |
|
3517 |
p.fillRect(0, 0, expected.width(), expected.height(), Qt::white); |
|
3518 |
p.drawImage(0, 0, src); |
|
3519 |
} |
|
3520 |
||
3521 |
for (int i = 1; i <= 4; ++i) { |
|
3522 |
QImage dest(src.width() + i, src.height(), format); |
|
3523 |
{ |
|
3524 |
QPainter p(&dest); |
|
3525 |
p.fillRect(0, 0, dest.width(), dest.height(), Qt::white); |
|
3526 |
p.drawImage(i, 0, src); |
|
3527 |
} |
|
3528 |
||
3529 |
const QImage result = dest.copy(i, 0, src.width(), src.height()); |
|
3530 |
||
3531 |
#if 0 |
|
3532 |
if (result != expected) { |
|
3533 |
qDebug("i=%i", i); |
|
3534 |
result.save("result.png"); |
|
3535 |
expected.save("expected.png"); |
|
3536 |
} |
|
3537 |
#endif |
|
3538 |
QCOMPARE(result, expected); |
|
3539 |
} |
|
3540 |
} |
|
3541 |
||
3542 |
void tst_QPainter::drawImage_task258776() |
|
3543 |
{ |
|
3544 |
QImage src(16, 16, QImage::Format_RGB888); |
|
3545 |
QImage dest(33, 33, QImage::Format_RGB888); |
|
3546 |
src.fill(0x00ff00); |
|
3547 |
dest.fill(0x0000ff); |
|
3548 |
||
3549 |
QPainter painter(&dest); |
|
3550 |
painter.drawImage(QRectF(0.499, 0.499, 32, 32), src, QRectF(0, 0, 16, 16)); |
|
3551 |
painter.end(); |
|
3552 |
||
3553 |
QImage expected(33, 33, QImage::Format_RGB32); |
|
3554 |
expected.fill(0xff0000); |
|
3555 |
||
3556 |
painter.begin(&expected); |
|
3557 |
painter.drawImage(QRectF(0, 0, 32, 32), src); |
|
3558 |
painter.end(); |
|
3559 |
||
3560 |
dest = dest.convertToFormat(QImage::Format_RGB32); |
|
3561 |
||
3562 |
dest.save("dest.png"); |
|
3563 |
expected.save("expected.png"); |
|
3564 |
QCOMPARE(dest, expected); |
|
3565 |
} |
|
3566 |
||
3567 |
void tst_QPainter::clipRectSaveRestore() |
|
3568 |
{ |
|
3569 |
QImage img(64, 64, QImage::Format_ARGB32_Premultiplied); |
|
3570 |
img.fill(0x0); |
|
3571 |
||
3572 |
QPainter p(&img); |
|
3573 |
p.setClipRect(QRect(0, 0, 10, 10)); |
|
3574 |
p.save(); |
|
3575 |
p.setClipRect(QRect(5, 5, 5, 5), Qt::IntersectClip); |
|
3576 |
p.restore(); |
|
3577 |
p.fillRect(0, 0, 64, 64, Qt::black); |
|
3578 |
p.end(); |
|
3579 |
||
3580 |
QCOMPARE(img.pixel(0, 0), QColor(Qt::black).rgba()); |
|
3581 |
} |
|
3582 |
||
3583 |
void tst_QPainter::clippedImage() |
|
3584 |
{ |
|
3585 |
QImage img(16, 16, QImage::Format_ARGB32_Premultiplied); |
|
3586 |
img.fill(0x0); |
|
3587 |
||
3588 |
QImage src(16, 16, QImage::Format_RGB32); |
|
3589 |
src.fill(QColor(Qt::red).rgba()); |
|
3590 |
||
3591 |
QPainter p(&img); |
|
3592 |
p.setClipRect(QRect(1, 1, 14, 14)); |
|
3593 |
p.drawImage(0, 0, src); |
|
3594 |
p.end(); |
|
3595 |
||
3596 |
QCOMPARE(img.pixel(0, 0), 0x0U); |
|
3597 |
QCOMPARE(img.pixel(1, 1), src.pixel(1, 1)); |
|
3598 |
} |
|
3599 |
||
3600 |
void tst_QPainter::stateResetBetweenQPainters() |
|
3601 |
{ |
|
3602 |
QImage img(16, 16, QImage::Format_ARGB32); |
|
3603 |
||
3604 |
{ |
|
3605 |
QPainter p(&img); |
|
3606 |
p.setCompositionMode(QPainter::CompositionMode_Source); |
|
3607 |
p.fillRect(0, 0, 16, 16, Qt::red); |
|
3608 |
} |
|
3609 |
||
3610 |
{ |
|
3611 |
QPainter p2(&img); |
|
3612 |
p2.fillRect(0, 0, 16, 16, QColor(0, 0, 255, 63)); |
|
3613 |
} |
|
3614 |
||
3615 |
img.save("foo.png"); |
|
3616 |
||
3617 |
QVERIFY(img.pixel(0, 0) != qRgba(0, 0, 255, 63)); |
|
3618 |
QVERIFY(qRed(img.pixel(0, 0)) > 0); // We didn't erase the red channel... |
|
3619 |
QVERIFY(qBlue(img.pixel(0, 0)) < 255); // We blended the blue channel |
|
3620 |
} |
|
3621 |
||
3622 |
void tst_QPainter::drawRect_task215378() |
|
3623 |
{ |
|
3624 |
QImage img(11, 11, QImage::Format_ARGB32_Premultiplied); |
|
3625 |
img.fill(QColor(Qt::white).rgba()); |
|
3626 |
||
3627 |
QPainter p(&img); |
|
3628 |
p.setPen(QColor(127, 127, 127, 127)); |
|
3629 |
p.drawRect(0, 0, 10, 10); |
|
3630 |
p.end(); |
|
3631 |
||
3632 |
QCOMPARE(img.pixel(0, 0), img.pixel(1, 0)); |
|
3633 |
QCOMPARE(img.pixel(0, 0), img.pixel(0, 1)); |
|
3634 |
QVERIFY(img.pixel(0, 0) != img.pixel(1, 1)); |
|
3635 |
} |
|
3636 |
||
3637 |
void tst_QPainter::drawRect_task247505() |
|
3638 |
{ |
|
3639 |
QImage a(10, 10, QImage::Format_ARGB32_Premultiplied); |
|
3640 |
a.fill(0); |
|
3641 |
QImage b = a; |
|
3642 |
||
3643 |
QPainter p(&a); |
|
3644 |
p.setPen(Qt::NoPen); |
|
3645 |
p.setBrush(Qt::black); |
|
3646 |
p.drawRect(QRectF(10, 0, -10, 10)); |
|
3647 |
p.end(); |
|
3648 |
p.begin(&b); |
|
3649 |
p.setPen(Qt::NoPen); |
|
3650 |
p.setBrush(Qt::black); |
|
3651 |
p.drawRect(QRectF(0, 0, 10, 10)); |
|
3652 |
p.end(); |
|
3653 |
||
3654 |
QCOMPARE(a, b); |
|
3655 |
} |
|
3656 |
||
3657 |
void tst_QPainter::drawImage_data() |
|
3658 |
{ |
|
3659 |
QTest::addColumn<int>("x"); |
|
3660 |
QTest::addColumn<int>("y"); |
|
3661 |
QTest::addColumn<int>("w"); |
|
3662 |
QTest::addColumn<int>("h"); |
|
3663 |
QTest::addColumn<QImage::Format>("srcFormat"); |
|
3664 |
QTest::addColumn<QImage::Format>("dstFormat"); |
|
3665 |
||
3666 |
for (int srcFormat = QImage::Format_Mono; srcFormat < QImage::NImageFormats; ++srcFormat) { |
|
3667 |
for (int dstFormat = QImage::Format_Mono; dstFormat < QImage::NImageFormats; ++dstFormat) { |
|
3668 |
if (dstFormat == QImage::Format_Indexed8) |
|
3669 |
continue; |
|
3670 |
for (int odd_x = 0; odd_x <= 1; ++odd_x) { |
|
3671 |
for (int odd_width = 0; odd_width <= 1; ++odd_width) { |
|
3672 |
QString description = |
|
3673 |
QString("srcFormat %1, dstFormat %2, odd x: %3, odd width: %4") |
|
3674 |
.arg(srcFormat).arg(dstFormat).arg(odd_x).arg(odd_width); |
|
3675 |
||
3676 |
QTest::newRow(qPrintable(description)) << (10 + odd_x) << 10 << (20 + odd_width) << 20 |
|
3677 |
<< QImage::Format(srcFormat) |
|
3678 |
<< QImage::Format(dstFormat); |
|
3679 |
} |
|
3680 |
} |
|
3681 |
} |
|
3682 |
} |
|
3683 |
} |
|
3684 |
||
3685 |
bool verifyImage(const QImage &img, int x, int y, int w, int h, uint background) |
|
3686 |
{ |
|
3687 |
int imgWidth = img.width(); |
|
3688 |
int imgHeight = img.height(); |
|
3689 |
for (int i = 0; i < imgHeight; ++i) { |
|
3690 |
for (int j = 0; j < imgWidth; ++j) { |
|
3691 |
uint pixel = img.pixel(j, i); |
|
3692 |
bool outside = j < x || j >= (x + w) || i < y || i >= (y + h); |
|
3693 |
if (outside != (pixel == background)) { |
|
3694 |
//printf("%d %d, expected %x, got %x, outside: %d\n", x, y, background, pixel, outside); |
|
3695 |
return false; |
|
3696 |
} |
|
3697 |
} |
|
3698 |
} |
|
3699 |
||
3700 |
return true; |
|
3701 |
} |
|
3702 |
||
3703 |
void tst_QPainter::drawImage() |
|
3704 |
{ |
|
3705 |
QFETCH(int, x); |
|
3706 |
QFETCH(int, y); |
|
3707 |
QFETCH(int, w); |
|
3708 |
QFETCH(int, h); |
|
3709 |
QFETCH(QImage::Format, srcFormat); |
|
3710 |
QFETCH(QImage::Format, dstFormat); |
|
3711 |
||
3712 |
QImage dst(40, 40, QImage::Format_RGB32); |
|
3713 |
dst.fill(0xffffffff); |
|
3714 |
||
3715 |
dst = dst.convertToFormat(dstFormat); |
|
3716 |
uint background = dst.pixel(0, 0); |
|
3717 |
||
3718 |
QImage src(w, h, QImage::Format_RGB32); |
|
3719 |
src.fill(0xff000000); |
|
3720 |
src = src.convertToFormat(srcFormat); |
|
3721 |
||
3722 |
QPainter p(&dst); |
|
3723 |
p.drawImage(x, y, src); |
|
3724 |
p.end(); |
|
3725 |
||
3726 |
QVERIFY(verifyImage(dst, x, y, w, h, background)); |
|
3727 |
} |
|
3728 |
||
3729 |
void tst_QPainter::imageCoordinateLimit() |
|
3730 |
{ |
|
3731 |
QImage img(64, 40000, QImage::Format_MonoLSB); |
|
3732 |
QPainter p(&img); |
|
3733 |
p.drawText(10, 36000, QLatin1String("foo")); |
|
3734 |
p.setPen(QPen(Qt::black, 2)); |
|
3735 |
p.drawLine(10, 0, 60, 40000); |
|
3736 |
||
3737 |
p.setRenderHint(QPainter::Antialiasing); |
|
3738 |
p.drawLine(10, 0, 60, 40000); |
|
3739 |
} |
|
3740 |
||
3741 |
||
3742 |
void tst_QPainter::imageBlending_data() |
|
3743 |
{ |
|
3744 |
QTest::addColumn<QImage::Format>("sourceFormat"); |
|
3745 |
QTest::addColumn<QImage::Format>("destFormat"); |
|
3746 |
QTest::addColumn<int>("error"); |
|
3747 |
||
3748 |
int error_rgb565 = ((1<<3) + (1<<2) + (1<<3)); |
|
3749 |
QTest::newRow("rgb565_on_rgb565") << QImage::Format_RGB16 |
|
3750 |
<< QImage::Format_RGB16 |
|
3751 |
<< 0; |
|
3752 |
QTest::newRow("argb8565_on_rgb565") << QImage::Format_ARGB8565_Premultiplied |
|
3753 |
<< QImage::Format_RGB16 |
|
3754 |
<< error_rgb565; |
|
3755 |
||
3756 |
QTest::newRow("rgb32_on_rgb565") << QImage::Format_RGB32 |
|
3757 |
<< QImage::Format_RGB16 |
|
3758 |
<< error_rgb565; |
|
3759 |
||
3760 |
QTest::newRow("argb32pm_on_rgb565") << QImage::Format_ARGB32_Premultiplied |
|
3761 |
<< QImage::Format_RGB16 |
|
3762 |
<< error_rgb565; |
|
3763 |
} |
|
3764 |
||
3765 |
int diffColor(quint32 ap, quint32 bp) |
|
3766 |
{ |
|
3767 |
int a = qAlpha(ap) - qAlpha(bp); |
|
3768 |
int r = qRed(ap) - qRed(bp); |
|
3769 |
int b = qBlue(ap) - qBlue(bp); |
|
3770 |
int g = qBlue(ap) - qBlue(bp); |
|
3771 |
||
3772 |
return qAbs(a) + qAbs(r) + qAbs(g) + qAbs(b); |
|
3773 |
} |
|
3774 |
||
3775 |
// this test assumes premultiplied pixels... |
|
3776 |
||
3777 |
void tst_QPainter::imageBlending() |
|
3778 |
{ |
|
3779 |
QFETCH(QImage::Format, sourceFormat); |
|
3780 |
QFETCH(QImage::Format, destFormat); |
|
3781 |
QFETCH(int, error); |
|
3782 |
||
3783 |
QImage dest; |
|
3784 |
{ |
|
3785 |
QImage orig_dest(6, 6, QImage::Format_ARGB32_Premultiplied); |
|
3786 |
orig_dest.fill(0); |
|
3787 |
QPainter p(&orig_dest); |
|
3788 |
p.fillRect(0, 0, 6, 3, QColor::fromRgbF(1, 0, 0)); |
|
3789 |
p.fillRect(3, 0, 3, 6, QColor::fromRgbF(0, 0, 1, 0.5)); |
|
3790 |
p.end(); |
|
3791 |
dest = orig_dest.convertToFormat(destFormat); |
|
3792 |
||
3793 |
// An image like this: (r = red, m = magenta, b = light alpha blue, 0 = transparent) |
|
3794 |
// r r r m m m |
|
3795 |
// r r r m m m |
|
3796 |
// r r r m m m |
|
3797 |
// 0 0 0 b b b |
|
3798 |
// 0 0 0 b b b |
|
3799 |
// 0 0 0 b b b |
|
3800 |
} |
|
3801 |
||
3802 |
QImage source; |
|
3803 |
{ |
|
3804 |
QImage orig_source(6, 6, QImage::Format_ARGB32_Premultiplied); |
|
3805 |
orig_source.fill(0); |
|
3806 |
QPainter p(&orig_source); |
|
3807 |
p.fillRect(1, 1, 4, 4, QColor::fromRgbF(0, 1, 0, 0.5)); |
|
3808 |
p.fillRect(2, 2, 2, 2, QColor::fromRgbF(0, 1, 0)); |
|
3809 |
p.end(); |
|
3810 |
source = orig_source.convertToFormat(sourceFormat); |
|
3811 |
||
3812 |
// An image like this: (0 = transparent, . = green at 0.5 alpha, g = opaque green. |
|
3813 |
// 0 0 0 0 0 0 |
|
3814 |
// 0 . . . . 0 |
|
3815 |
// 0 . g g . 0 |
|
3816 |
// 0 . g g . 0 |
|
3817 |
// 0 . . . . 0 |
|
3818 |
// 0 0 0 0 0 0 |
|
3819 |
} |
|
3820 |
||
3821 |
QPainter p(&dest); |
|
3822 |
p.drawImage(0, 0, source); |
|
3823 |
p.end(); |
|
3824 |
||
3825 |
// resulting image: |
|
3826 |
// r r r m m m |
|
3827 |
// r r. r. m. m. m |
|
3828 |
// r r. g g m. m |
|
3829 |
// 0 . g g b. b |
|
3830 |
// 0 . . b. b. b |
|
3831 |
// 0 0 0 b b b |
|
3832 |
||
3833 |
// the g pixels, always green.. |
|
3834 |
QVERIFY(diffColor(dest.pixel(2, 2), 0xff00ff00) <= error); // g |
|
3835 |
||
3836 |
if (source.hasAlphaChannel()) { |
|
3837 |
QVERIFY(diffColor(dest.pixel(0, 0), 0xffff0000) <= error); // r |
|
3838 |
QVERIFY(diffColor(dest.pixel(5, 0), 0xff7f007f) <= error); // m |
|
3839 |
QVERIFY(diffColor(dest.pixel(1, 1), 0xff7f7f00) <= error); // r. |
|
3840 |
QVERIFY(diffColor(dest.pixel(4, 1), 0xff3f7f3f) <= error); // m. |
|
3841 |
if (dest.hasAlphaChannel()) { |
|
3842 |
QVERIFY(diffColor(dest.pixel(1, 3), 0x7f007f00) <= error); // . |
|
3843 |
QVERIFY(diffColor(dest.pixel(4, 3), 0x7f007f3f) <= error); // b. |
|
3844 |
QVERIFY(diffColor(dest.pixel(4, 3), 0x7f007f3f) <= error); // b. |
|
3845 |
QVERIFY(diffColor(dest.pixel(4, 4), 0x7f00007f) <= error); // b |
|
3846 |
QVERIFY(diffColor(dest.pixel(4, 0), 0) <= 0); // 0 |
|
3847 |
} |
|
3848 |
} else { |
|
3849 |
QVERIFY(diffColor(dest.pixel(0, 0), 0xff000000) <= 0); |
|
3850 |
QVERIFY(diffColor(dest.pixel(1, 1), 0xff007f00) <= error); |
|
3851 |
} |
|
3852 |
} |
|
3853 |
||
3854 |
void tst_QPainter::imageBlending_clipped() |
|
3855 |
{ |
|
3856 |
QImage src(20, 20, QImage::Format_RGB16); |
|
3857 |
QPainter p(&src); |
|
3858 |
p.fillRect(src.rect(), Qt::red); |
|
3859 |
p.end(); |
|
3860 |
||
3861 |
QImage dst(40, 20, QImage::Format_RGB16); |
|
3862 |
p.begin(&dst); |
|
3863 |
p.fillRect(dst.rect(), Qt::white); |
|
3864 |
p.end(); |
|
3865 |
||
3866 |
QImage expected = dst; |
|
3867 |
||
3868 |
p.begin(&dst); |
|
3869 |
p.setClipRect(QRect(23, 0, 20, 20)); |
|
3870 |
||
3871 |
// should be completely clipped |
|
3872 |
p.drawImage(QRectF(3, 0, 20, 20), src); |
|
3873 |
p.end(); |
|
3874 |
||
3875 |
// dst should be left unchanged |
|
3876 |
QCOMPARE(dst, expected); |
|
3877 |
} |
|
3878 |
||
3879 |
void tst_QPainter::paintOnNullPixmap() |
|
3880 |
{ |
|
3881 |
QPixmap pix(16, 16); |
|
3882 |
||
3883 |
QPixmap textPixmap; |
|
3884 |
QPainter p(&textPixmap); |
|
3885 |
p.drawPixmap(10, 10, pix); |
|
3886 |
p.end(); |
|
3887 |
||
3888 |
QPixmap textPixmap2(16,16); |
|
3889 |
p.begin(&textPixmap2); |
|
3890 |
p.end(); |
|
3891 |
} |
|
3892 |
||
3893 |
void tst_QPainter::checkCompositionMode() |
|
3894 |
{ |
|
3895 |
QImage refImage(50,50,QImage::Format_ARGB32); |
|
3896 |
QPainter painter(&refImage); |
|
3897 |
painter.fillRect(QRect(0,0,50,50),Qt::blue); |
|
3898 |
||
3899 |
QImage testImage(50,50,QImage::Format_ARGB32); |
|
3900 |
QPainter p(&testImage); |
|
3901 |
p.fillRect(QRect(0,0,50,50),Qt::red); |
|
3902 |
p.save(); |
|
3903 |
p.setCompositionMode(QPainter::CompositionMode_SourceOut); |
|
3904 |
p.restore(); |
|
3905 |
p.fillRect(QRect(0,0,50,50),Qt::blue); |
|
3906 |
||
3907 |
QCOMPARE(refImage.pixel(20,20),testImage.pixel(20,20)); |
|
3908 |
} |
|
3909 |
||
3910 |
static QLinearGradient inverseGradient(QLinearGradient g) |
|
3911 |
{ |
|
3912 |
QLinearGradient g2 = g; |
|
3913 |
||
3914 |
QGradientStops stops = g.stops(); |
|
3915 |
||
3916 |
QGradientStops inverse; |
|
3917 |
foreach (QGradientStop stop, stops) |
|
3918 |
inverse << QGradientStop(1 - stop.first, stop.second); |
|
3919 |
||
3920 |
g2.setStops(inverse); |
|
3921 |
return g2; |
|
3922 |
} |
|
3923 |
||
3924 |
void tst_QPainter::linearGradientSymmetry() |
|
3925 |
{ |
|
3926 |
QImage a(64, 8, QImage::Format_ARGB32_Premultiplied); |
|
3927 |
QImage b(64, 8, QImage::Format_ARGB32_Premultiplied); |
|
3928 |
||
3929 |
a.fill(0); |
|
3930 |
b.fill(0); |
|
3931 |
||
3932 |
QLinearGradient gradient(QRectF(b.rect()).topLeft(), QRectF(b.rect()).topRight()); |
|
3933 |
gradient.setColorAt(0.0, Qt::blue); |
|
3934 |
gradient.setColorAt(0.2, QColor(220, 220, 220, 0)); |
|
3935 |
gradient.setColorAt(0.6, Qt::red); |
|
3936 |
gradient.setColorAt(0.9, QColor(220, 220, 220, 255)); |
|
3937 |
gradient.setColorAt(1.0, Qt::black); |
|
3938 |
||
3939 |
QPainter pa(&a); |
|
3940 |
pa.fillRect(a.rect(), gradient); |
|
3941 |
pa.end(); |
|
3942 |
||
3943 |
QPainter pb(&b); |
|
3944 |
pb.fillRect(b.rect(), inverseGradient(gradient)); |
|
3945 |
pb.end(); |
|
3946 |
||
3947 |
b = b.mirrored(true); |
|
3948 |
QCOMPARE(a, b); |
|
3949 |
} |
|
3950 |
||
3951 |
void tst_QPainter::gradientInterpolation() |
|
3952 |
{ |
|
3953 |
QImage image(256, 8, QImage::Format_ARGB32_Premultiplied); |
|
3954 |
QPainter painter; |
|
3955 |
||
3956 |
QLinearGradient gradient(QRectF(image.rect()).topLeft(), QRectF(image.rect()).topRight()); |
|
3957 |
gradient.setColorAt(0.0, QColor(255, 0, 0, 0)); |
|
3958 |
gradient.setColorAt(1.0, Qt::blue); |
|
3959 |
||
3960 |
image.fill(0); |
|
3961 |
painter.begin(&image); |
|
3962 |
painter.fillRect(image.rect(), gradient); |
|
3963 |
painter.end(); |
|
3964 |
||
3965 |
const QRgb *line = reinterpret_cast<QRgb *>(image.scanLine(3)); |
|
3966 |
||
3967 |
for (int i = 0; i < 256; ++i) { |
|
3968 |
QCOMPARE(qAlpha(line[i]), qBlue(line[i])); // bright blue |
|
3969 |
QVERIFY(qAbs(qAlpha(line[i]) - i) < 3); // linear alpha |
|
3970 |
QCOMPARE(qRed(line[i]), 0); // no red component |
|
3971 |
QCOMPARE(qGreen(line[i]), 0); // no green component |
|
3972 |
} |
|
3973 |
||
3974 |
gradient.setInterpolationMode(QGradient::ComponentInterpolation); |
|
3975 |
||
3976 |
image.fill(0); |
|
3977 |
painter.begin(&image); |
|
3978 |
painter.fillRect(image.rect(), gradient); |
|
3979 |
painter.end(); |
|
3980 |
||
3981 |
for (int i = 1; i < 256; ++i) { |
|
3982 |
if (i < 128) { |
|
3983 |
QVERIFY(qRed(line[i]) >= qBlue(line[i])); // red is dominant |
|
3984 |
} else { |
|
3985 |
QVERIFY(qRed(line[i]) <= qBlue(line[i])); // blue is dominant |
|
3986 |
} |
|
3987 |
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 |
|
3988 |
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 |
|
3989 |
QVERIFY(qAbs(qAlpha(line[i]) - i) < 3); // linear alpha |
|
3990 |
QCOMPARE(qGreen(line[i]), 0); // no green component |
|
3991 |
} |
|
3992 |
} |
|
3993 |
||
3994 |
void tst_QPainter::drawPolygon() |
|
3995 |
{ |
|
3996 |
QImage img(128, 128, QImage::Format_ARGB32_Premultiplied); |
|
3997 |
||
3998 |
QPainterPathStroker stroker; |
|
3999 |
stroker.setWidth(1.5); |
|
4000 |
||
4001 |
QPainterPath path; |
|
4002 |
path.moveTo(2, 34); |
|
4003 |
path.lineTo(34, 2); |
|
4004 |
||
4005 |
QPolygonF poly = stroker.createStroke(path).toFillPolygon(); |
|
4006 |
||
4007 |
img.fill(0xffffffff); |
|
4008 |
QPainter p(&img); |
|
4009 |
p.setRenderHint(QPainter::Antialiasing); |
|
4010 |
p.setBrush(Qt::red); |
|
4011 |
p.setPen(Qt::NoPen); |
|
4012 |
p.drawPolygon(poly); |
|
4013 |
p.translate(64, 64); |
|
4014 |
p.drawPolygon(poly); |
|
4015 |
p.end(); |
|
4016 |
||
4017 |
QImage a = img.copy(); |
|
4018 |
||
4019 |
img.fill(0xffffffff); |
|
4020 |
p.begin(&img); |
|
4021 |
p.setRenderHint(QPainter::Antialiasing); |
|
4022 |
p.setBrush(Qt::red); |
|
4023 |
p.setPen(Qt::NoPen); |
|
4024 |
p.translate(64, 64); |
|
4025 |
p.drawPolygon(poly); |
|
4026 |
p.resetTransform(); |
|
4027 |
p.drawPolygon(poly); |
|
4028 |
p.end(); |
|
4029 |
||
4030 |
QCOMPARE(a, img); |
|
4031 |
} |
|
4032 |
||
4033 |
void tst_QPainter::inactivePainter() |
|
4034 |
{ |
|
4035 |
// This test succeeds if it doesn't segfault. |
|
4036 |
||
4037 |
QPainter p; |
|
4038 |
QPainterPath path; |
|
4039 |
QRegion region(QRect(20, 20, 60, 40)); |
|
4040 |
QPolygonF polygon(QVector<QPointF>() << QPointF(0, 0) << QPointF(12, 0) << QPointF(8, 6)); |
|
4041 |
path.addPolygon(polygon); |
|
4042 |
||
4043 |
p.save(); |
|
4044 |
p.restore(); |
|
4045 |
||
4046 |
p.background(); |
|
4047 |
p.setBackground(QBrush(Qt::blue)); |
|
4048 |
||
4049 |
p.brush(); |
|
4050 |
p.setBrush(Qt::red); |
|
4051 |
p.setBrush(Qt::NoBrush); |
|
4052 |
p.setBrush(QBrush(Qt::white, Qt::DiagCrossPattern)); |
|
4053 |
||
4054 |
p.backgroundMode(); |
|
4055 |
p.setBackgroundMode(Qt::OpaqueMode); |
|
4056 |
||
4057 |
p.boundingRect(QRectF(0, 0, 100, 20), Qt::AlignCenter, QLatin1String("Hello, World!")); |
|
4058 |
p.boundingRect(QRect(0, 0, 100, 20), Qt::AlignCenter, QLatin1String("Hello, World!")); |
|
4059 |
||
4060 |
p.brushOrigin(); |
|
4061 |
p.setBrushOrigin(QPointF(12, 34)); |
|
4062 |
p.setBrushOrigin(QPoint(12, 34)); |
|
4063 |
||
4064 |
p.clipPath(); |
|
4065 |
p.clipRegion(); |
|
4066 |
p.hasClipping(); |
|
4067 |
p.setClipPath(path); |
|
4068 |
p.setClipRect(QRectF(42, 42, 42, 42)); |
|
4069 |
p.setClipRect(QRect(42, 42, 42, 42)); |
|
4070 |
p.setClipRegion(region); |
|
4071 |
p.setClipping(true); |
|
4072 |
||
4073 |
p.combinedMatrix(); |
|
4074 |
p.combinedTransform(); |
|
4075 |
||
4076 |
p.compositionMode(); |
|
4077 |
p.setCompositionMode(QPainter::CompositionMode_Plus); |
|
4078 |
||
4079 |
p.device(); |
|
4080 |
p.deviceMatrix(); |
|
4081 |
p.deviceTransform(); |
|
4082 |
||
4083 |
p.font(); |
|
4084 |
p.setFont(QFont(QLatin1String("Times"), 24)); |
|
4085 |
||
4086 |
p.fontInfo(); |
|
4087 |
p.fontMetrics(); |
|
4088 |
||
4089 |
p.layoutDirection(); |
|
4090 |
p.setLayoutDirection(Qt::RightToLeft); |
|
4091 |
||
4092 |
p.opacity(); |
|
4093 |
p.setOpacity(0.75); |
|
4094 |
||
4095 |
p.pen(); |
|
4096 |
p.setPen(QPen(Qt::red)); |
|
4097 |
p.setPen(Qt::green); |
|
4098 |
p.setPen(Qt::NoPen); |
|
4099 |
||
4100 |
p.renderHints(); |
|
4101 |
p.setRenderHint(QPainter::Antialiasing, true); |
|
4102 |
p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, false); |
|
4103 |
||
4104 |
p.resetMatrix(); |
|
4105 |
p.resetTransform(); |
|
4106 |
p.rotate(1); |
|
4107 |
p.scale(2, 2); |
|
4108 |
p.shear(-1, 1); |
|
4109 |
p.translate(3, 14); |
|
4110 |
||
4111 |
p.viewTransformEnabled(); |
|
4112 |
p.setViewTransformEnabled(true); |
|
4113 |
||
4114 |
p.viewport(); |
|
4115 |
p.setViewport(QRect(10, 10, 620, 460)); |
|
4116 |
||
4117 |
p.window(); |
|
4118 |
p.setWindow(QRect(10, 10, 620, 460)); |
|
4119 |
||
4120 |
p.worldMatrix(); |
|
4121 |
p.setWorldMatrix(QMatrix().translate(43, 21), true); |
|
4122 |
p.setWorldMatrixEnabled(true); |
|
4123 |
||
4124 |
p.transform(); |
|
4125 |
p.setTransform(QTransform().translate(12, 34), true); |
|
4126 |
||
4127 |
p.worldTransform(); |
|
4128 |
p.setWorldTransform(QTransform().scale(0.5, 0.5), true); |
|
4129 |
} |
|
4130 |
||
4131 |
bool testCompositionMode(int src, int dst, int expected, QPainter::CompositionMode op) |
|
4132 |
{ |
|
4133 |
QImage actual(1, 1, QImage::Format_ARGB32_Premultiplied); |
|
4134 |
actual.fill(QColor(dst, dst, dst).rgb()); |
|
4135 |
||
4136 |
QPainter p(&actual); |
|
4137 |
p.setCompositionMode(op); |
|
4138 |
p.fillRect(0, 0, 1, 1, QColor(src, src, src)); |
|
4139 |
p.end(); |
|
4140 |
||
4141 |
if (qRed(actual.pixel(0, 0)) != expected) { |
|
4142 |
qDebug("Fail: mode %d, src[%d] dst [%d] actual [%d] expected [%d]", op, |
|
4143 |
src, dst, qRed(actual.pixel(0, 0)), expected); |
|
4144 |
return false; |
|
4145 |
} else { |
|
4146 |
return true; |
|
4147 |
} |
|
4148 |
} |
|
4149 |
||
4150 |
void tst_QPainter::extendedBlendModes() |
|
4151 |
{ |
|
4152 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_Plus)); |
|
4153 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Plus)); |
|
4154 |
QVERIFY(testCompositionMode(127, 128, 255, QPainter::CompositionMode_Plus)); |
|
4155 |
QVERIFY(testCompositionMode(127, 0, 127, QPainter::CompositionMode_Plus)); |
|
4156 |
QVERIFY(testCompositionMode( 0, 127, 127, QPainter::CompositionMode_Plus)); |
|
4157 |
QVERIFY(testCompositionMode(255, 0, 255, QPainter::CompositionMode_Plus)); |
|
4158 |
QVERIFY(testCompositionMode( 0, 255, 255, QPainter::CompositionMode_Plus)); |
|
4159 |
QVERIFY(testCompositionMode(128, 128, 255, QPainter::CompositionMode_Plus)); |
|
4160 |
||
4161 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_Multiply)); |
|
4162 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Multiply)); |
|
4163 |
QVERIFY(testCompositionMode(127, 255, 127, QPainter::CompositionMode_Multiply)); |
|
4164 |
QVERIFY(testCompositionMode(255, 127, 127, QPainter::CompositionMode_Multiply)); |
|
4165 |
QVERIFY(testCompositionMode( 63, 255, 63, QPainter::CompositionMode_Multiply)); |
|
4166 |
QVERIFY(testCompositionMode(255, 63, 63, QPainter::CompositionMode_Multiply)); |
|
4167 |
QVERIFY(testCompositionMode(127, 127, 63, QPainter::CompositionMode_Multiply)); |
|
4168 |
||
4169 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_Screen)); |
|
4170 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Screen)); |
|
4171 |
QVERIFY(testCompositionMode( 63, 255, 255, QPainter::CompositionMode_Screen)); |
|
4172 |
QVERIFY(testCompositionMode(255, 63, 255, QPainter::CompositionMode_Screen)); |
|
4173 |
QVERIFY(testCompositionMode( 63, 0, 63, QPainter::CompositionMode_Screen)); |
|
4174 |
QVERIFY(testCompositionMode( 0, 63, 63, QPainter::CompositionMode_Screen)); |
|
4175 |
QVERIFY(testCompositionMode(127, 127, 191, QPainter::CompositionMode_Screen)); |
|
4176 |
||
4177 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_Overlay)); |
|
4178 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Overlay)); |
|
4179 |
QVERIFY(testCompositionMode( 63, 63, 31, QPainter::CompositionMode_Overlay)); |
|
4180 |
QVERIFY(testCompositionMode( 63, 255, 255, QPainter::CompositionMode_Overlay)); |
|
4181 |
||
4182 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_Darken)); |
|
4183 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Darken)); |
|
4184 |
QVERIFY(testCompositionMode( 63, 63, 63, QPainter::CompositionMode_Darken)); |
|
4185 |
QVERIFY(testCompositionMode( 63, 255, 63, QPainter::CompositionMode_Darken)); |
|
4186 |
QVERIFY(testCompositionMode(255, 63, 63, QPainter::CompositionMode_Darken)); |
|
4187 |
QVERIFY(testCompositionMode( 63, 127, 63, QPainter::CompositionMode_Darken)); |
|
4188 |
QVERIFY(testCompositionMode(127, 63, 63, QPainter::CompositionMode_Darken)); |
|
4189 |
||
4190 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_Lighten)); |
|
4191 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Lighten)); |
|
4192 |
QVERIFY(testCompositionMode( 63, 63, 63, QPainter::CompositionMode_Lighten)); |
|
4193 |
QVERIFY(testCompositionMode( 63, 255, 255, QPainter::CompositionMode_Lighten)); |
|
4194 |
QVERIFY(testCompositionMode(255, 63, 255, QPainter::CompositionMode_Lighten)); |
|
4195 |
QVERIFY(testCompositionMode( 63, 127, 127, QPainter::CompositionMode_Lighten)); |
|
4196 |
QVERIFY(testCompositionMode(127, 63, 127, QPainter::CompositionMode_Lighten)); |
|
4197 |
||
4198 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_ColorDodge)); |
|
4199 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_ColorDodge)); |
|
4200 |
QVERIFY(testCompositionMode( 63, 127, 169, QPainter::CompositionMode_ColorDodge)); |
|
4201 |
QVERIFY(testCompositionMode(191, 127, 255, QPainter::CompositionMode_ColorDodge)); |
|
4202 |
QVERIFY(testCompositionMode(127, 191, 255, QPainter::CompositionMode_ColorDodge)); |
|
4203 |
||
4204 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_ColorBurn)); |
|
4205 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_ColorBurn)); |
|
4206 |
QVERIFY(testCompositionMode(127, 127, 0, QPainter::CompositionMode_ColorBurn)); |
|
4207 |
QVERIFY(testCompositionMode(128, 128, 2, QPainter::CompositionMode_ColorBurn)); |
|
4208 |
QVERIFY(testCompositionMode(191, 127, 84, QPainter::CompositionMode_ColorBurn)); |
|
4209 |
||
4210 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_HardLight)); |
|
4211 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_HardLight)); |
|
4212 |
QVERIFY(testCompositionMode(127, 127, 127, QPainter::CompositionMode_HardLight)); |
|
4213 |
QVERIFY(testCompositionMode( 63, 63, 31, QPainter::CompositionMode_HardLight)); |
|
4214 |
QVERIFY(testCompositionMode(127, 63, 63, QPainter::CompositionMode_HardLight)); |
|
4215 |
||
4216 |
QVERIFY(testCompositionMode(255, 255, 255, QPainter::CompositionMode_SoftLight)); |
|
4217 |
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
|
4218 |
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
|
4219 |
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
|
4220 |
QVERIFY(testCompositionMode(127, 63, 62, QPainter::CompositionMode_SoftLight)); |
0 | 4221 |
|
4222 |
QVERIFY(testCompositionMode(255, 255, 0, QPainter::CompositionMode_Difference)); |
|
4223 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Difference)); |
|
4224 |
QVERIFY(testCompositionMode(255, 0, 255, QPainter::CompositionMode_Difference)); |
|
4225 |
QVERIFY(testCompositionMode(127, 127, 0, QPainter::CompositionMode_Difference)); |
|
4226 |
QVERIFY(testCompositionMode(127, 128, 1, QPainter::CompositionMode_Difference)); |
|
4227 |
QVERIFY(testCompositionMode(127, 63, 64, QPainter::CompositionMode_Difference)); |
|
4228 |
QVERIFY(testCompositionMode( 0, 127, 127, QPainter::CompositionMode_Difference)); |
|
4229 |
||
4230 |
QVERIFY(testCompositionMode(255, 255, 0, QPainter::CompositionMode_Exclusion)); |
|
4231 |
QVERIFY(testCompositionMode( 0, 0, 0, QPainter::CompositionMode_Exclusion)); |
|
4232 |
QVERIFY(testCompositionMode(255, 0, 255, QPainter::CompositionMode_Exclusion)); |
|
4233 |
QVERIFY(testCompositionMode(127, 127, 127, QPainter::CompositionMode_Exclusion)); |
|
4234 |
QVERIFY(testCompositionMode( 63, 127, 127, QPainter::CompositionMode_Exclusion)); |
|
4235 |
QVERIFY(testCompositionMode( 63, 63, 95, QPainter::CompositionMode_Exclusion)); |
|
4236 |
QVERIFY(testCompositionMode(191, 191, 96, QPainter::CompositionMode_Exclusion)); |
|
4237 |
} |
|
4238 |
||
4239 |
void tst_QPainter::zeroOpacity() |
|
4240 |
{ |
|
4241 |
QImage source(1, 1, QImage::Format_ARGB32_Premultiplied); |
|
4242 |
source.fill(0xffffffff); |
|
4243 |
||
4244 |
QImage target(1, 1, QImage::Format_RGB32); |
|
4245 |
target.fill(0xff000000); |
|
4246 |
||
4247 |
QPainter p(&target); |
|
4248 |
p.setOpacity(0.0); |
|
4249 |
p.drawImage(0, 0, source); |
|
4250 |
p.end(); |
|
4251 |
||
4252 |
QCOMPARE(target.pixel(0, 0), 0xff000000); |
|
4253 |
} |
|
4254 |
||
4255 |
void tst_QPainter::clippingBug() |
|
4256 |
{ |
|
4257 |
QImage img(32, 32, QImage::Format_ARGB32_Premultiplied); |
|
4258 |
img.fill(0); |
|
4259 |
||
4260 |
QImage expected = img; |
|
4261 |
QPainter p(&expected); |
|
4262 |
p.fillRect(1, 1, 30, 30, Qt::red); |
|
4263 |
p.end(); |
|
4264 |
||
4265 |
QPainterPath path; |
|
4266 |
path.addRect(1, 1, 30, 30); |
|
4267 |
path.addRect(1, 1, 30, 30); |
|
4268 |
path.addRect(1, 1, 30, 30); |
|
4269 |
||
4270 |
p.begin(&img); |
|
4271 |
p.setClipPath(path); |
|
4272 |
p.fillRect(0, 0, 32, 32, Qt::red); |
|
4273 |
p.end(); |
|
4274 |
||
4275 |
QCOMPARE(img, expected); |
|
4276 |
} |
|
4277 |
||
4278 |
void tst_QPainter::emptyClip() |
|
4279 |
{ |
|
4280 |
QImage img(64, 64, QImage::Format_ARGB32_Premultiplied); |
|
4281 |
QPainter p(&img); |
|
4282 |
p.setRenderHints(QPainter::Antialiasing); |
|
4283 |
p.setClipRect(0, 32, 64, 0); |
|
4284 |
p.fillRect(0, 0, 64, 64, Qt::white); |
|
4285 |
||
4286 |
QPainterPath path; |
|
4287 |
path.lineTo(64, 0); |
|
4288 |
path.lineTo(64, 64); |
|
4289 |
path.lineTo(40, 64); |
|
4290 |
path.lineTo(40, 80); |
|
4291 |
path.lineTo(0, 80); |
|
4292 |
||
4293 |
p.fillPath(path, Qt::green); |
|
4294 |
} |
|
4295 |
||
4296 |
void tst_QPainter::drawImage_1x1() |
|
4297 |
{ |
|
4298 |
QImage source(1, 1, QImage::Format_ARGB32_Premultiplied); |
|
4299 |
source.fill(0xffffffff); |
|
4300 |
||
4301 |
QImage img(32, 32, QImage::Format_ARGB32_Premultiplied); |
|
4302 |
img.fill(0xff000000); |
|
4303 |
QPainter p(&img); |
|
4304 |
p.drawImage(QRectF(0.9, 0.9, 32, 32), source); |
|
4305 |
p.end(); |
|
4306 |
||
4307 |
QImage expected = img; |
|
4308 |
expected.fill(0xff000000); |
|
4309 |
p.begin(&expected); |
|
4310 |
p.fillRect(1, 1, 31, 31, Qt::white); |
|
4311 |
p.end(); |
|
4312 |
||
4313 |
QCOMPARE(img, expected); |
|
4314 |
} |
|
4315 |
||
4316 |
void tst_QPainter::taskQT4444_dontOverflowDashOffset() |
|
4317 |
{ |
|
4318 |
QPainter p; |
|
4319 |
||
4320 |
QPen pen; |
|
4321 |
pen.setWidth(2); |
|
4322 |
pen.setStyle(Qt::DashDotLine); |
|
4323 |
||
4324 |
QPointF point[4]; |
|
4325 |
point[0] = QPointF(182.50868749707968,347.78457234212630); |
|
4326 |
point[1] = QPointF(182.50868749707968,107.22501998401277); |
|
4327 |
point[2] = QPointF(182.50868749707968,107.22501998401277); |
|
4328 |
point[3] = QPointF(520.46600762283651,107.22501998401277); |
|
4329 |
||
4330 |
QImage crashImage(QSize(1000, 120), QImage::Format_ARGB32_Premultiplied); |
|
4331 |
p.begin(&crashImage); |
|
4332 |
p.setPen(pen); |
|
4333 |
p.drawLines(point, 2); |
|
4334 |
p.end(); |
|
4335 |
||
4336 |
QVERIFY(true); // Don't crash |
|
4337 |
} |
|
4338 |
||
4339 |
void tst_QPainter::painterBegin() |
|
4340 |
{ |
|
4341 |
QImage nullImage; |
|
4342 |
QImage indexed8Image(16, 16, QImage::Format_Indexed8); |
|
4343 |
QImage rgb32Image(16, 16, QImage::Format_RGB32); |
|
4344 |
QImage argb32Image(16, 16, QImage::Format_ARGB32_Premultiplied); |
|
4345 |
||
4346 |
QPainter p; |
|
4347 |
||
4348 |
// Painting on null image should fail. |
|
4349 |
QVERIFY(!p.begin(&nullImage)); |
|
4350 |
||
4351 |
// Check that the painter is not messed up by using it on another image. |
|
4352 |
QVERIFY(p.begin(&rgb32Image)); |
|
4353 |
QVERIFY(p.end()); |
|
4354 |
||
4355 |
// If painting on indexed8 image fails, the painter state should still be OK. |
|
4356 |
if (p.begin(&indexed8Image)) |
|
4357 |
QVERIFY(p.end()); |
|
4358 |
QVERIFY(p.begin(&rgb32Image)); |
|
4359 |
QVERIFY(p.end()); |
|
4360 |
||
4361 |
// Try opening a painter on the two different images. |
|
4362 |
QVERIFY(p.begin(&rgb32Image)); |
|
4363 |
QVERIFY(!p.begin(&argb32Image)); |
|
4364 |
QVERIFY(p.end()); |
|
4365 |
||
4366 |
// Try opening two painters on the same image. |
|
4367 |
QVERIFY(p.begin(&rgb32Image)); |
|
4368 |
QPainter q; |
|
4369 |
QVERIFY(!q.begin(&rgb32Image)); |
|
4370 |
QVERIFY(!q.end()); |
|
4371 |
QVERIFY(p.end()); |
|
4372 |
||
4373 |
// Try ending an inactive painter. |
|
4374 |
QVERIFY(!p.end()); |
|
4375 |
} |
|
4376 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4377 |
void tst_QPainter::setPenColor(QPainter& p) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4378 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4379 |
p.setPen(Qt::NoPen); |
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 |
// Setting color, then style |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4382 |
// 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
|
4383 |
QPen newPen(p.pen()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4384 |
newPen.setColor(Qt::red); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4385 |
QCOMPARE(p.pen().style(), newPen.style()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4386 |
QCOMPARE(p.pen().style(), Qt::NoPen); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4387 |
p.setPen(newPen); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4388 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4389 |
QCOMPARE(p.pen().color().name(), QString("#ff0000")); |
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 |
QPen newPen2(p.pen()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4392 |
newPen2.setStyle(Qt::SolidLine); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4393 |
p.setPen(newPen2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4394 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4395 |
QCOMPARE(p.pen().color().name(), QString("#ff0000")); |
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 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4398 |
void tst_QPainter::setPenColorOnImage() |
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 |
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
|
4401 |
QPainter p(&img); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4402 |
setPenColor(p); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4403 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4404 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4405 |
void tst_QPainter::setPenColorOnPixmap() |
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 |
QPixmap pix(10, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4408 |
QPainter p(&pix); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4409 |
setPenColor(p); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4410 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4411 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4412 |
class TestProxy : public QGraphicsProxyWidget |
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 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4415 |
TestProxy() : QGraphicsProxyWidget() {} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4416 |
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
|
4417 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4418 |
QGraphicsProxyWidget::paint(painter, option, widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4419 |
deviceTransform = painter->deviceTransform(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4420 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4421 |
QTransform 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 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4424 |
class TestWidget : public QWidget |
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 |
Q_OBJECT |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4427 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4428 |
TestWidget() : QWidget(), painted(false) {} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4429 |
void paintEvent(QPaintEvent *) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4430 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4431 |
QPainter p(this); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4432 |
deviceTransform = p.deviceTransform(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4433 |
worldTransform = p.worldTransform(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4434 |
painted = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4435 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4436 |
QTransform deviceTransform; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4437 |
QTransform worldTransform; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4438 |
bool painted; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4439 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4440 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4441 |
void tst_QPainter::QTBUG5939_attachPainterPrivate() |
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 |
QWidget *w = new QWidget(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4444 |
QGraphicsScene *scene = new QGraphicsScene(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4445 |
QGraphicsView *view = new QGraphicsView(scene, w); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4446 |
view->move(50 ,50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4447 |
TestProxy *proxy = new TestProxy(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4448 |
TestWidget *widget = new TestWidget(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4449 |
proxy->setWidget(widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4450 |
scene->addItem(proxy); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4451 |
proxy->rotate(45); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4452 |
w->resize(scene->sceneRect().size().toSize()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4453 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4454 |
w->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4455 |
QTRY_VERIFY(widget->painted); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4456 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4457 |
QVERIFY(widget->worldTransform.isIdentity()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4458 |
QCOMPARE(widget->deviceTransform, proxy->deviceTransform); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4459 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4460 |
|
0 | 4461 |
QTEST_MAIN(tst_QPainter) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4462 |
|
0 | 4463 |
#include "tst_qpainter.moc" |