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