author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 5 | d3bac044e0f0 |
child 13 | c0432d11811c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
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> |
|
44 |
#include <QtGui/qdesktopwidget.h> |
|
45 |
#include <QtGui/qgraphicseffect.h> |
|
46 |
#include <QtGui/qgraphicsview.h> |
|
47 |
#include <QtGui/qgraphicsscene.h> |
|
48 |
#include <QtGui/qgraphicsitem.h> |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
49 |
#include <QtGui/qgraphicswidget.h> |
0 | 50 |
#include <QtGui/qstyleoption.h> |
51 |
||
52 |
#include "../../shared/util.h" |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
53 |
#include <private/qgraphicseffect_p.h> |
0 | 54 |
|
55 |
//TESTED_CLASS= |
|
56 |
//TESTED_FILES= |
|
57 |
||
58 |
class tst_QGraphicsEffect : public QObject |
|
59 |
{ |
|
60 |
Q_OBJECT |
|
61 |
public slots: |
|
62 |
void initTestCase(); |
|
63 |
||
64 |
private slots: |
|
65 |
void setEnabled(); |
|
66 |
void source(); |
|
67 |
void boundingRectFor(); |
|
68 |
void boundingRect(); |
|
69 |
void draw(); |
|
70 |
void opacity(); |
|
71 |
void grayscale(); |
|
72 |
void colorize(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
void drawPixmapItem(); |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
74 |
void deviceCoordinateTranslateCaching(); |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
75 |
void inheritOpacity(); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
76 |
void dropShadowClipping(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
77 |
void childrenVisibilityShouldInvalidateCache(); |
0 | 78 |
}; |
79 |
||
80 |
void tst_QGraphicsEffect::initTestCase() |
|
81 |
{} |
|
82 |
||
83 |
class CustomItem : public QGraphicsRectItem |
|
84 |
{ |
|
85 |
public: |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
86 |
CustomItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent = 0) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
87 |
: QGraphicsRectItem(x, y, width, height, parent), numRepaints(0), |
0 | 88 |
m_painter(0), m_styleOption(0) |
89 |
{} |
|
90 |
||
91 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
92 |
{ |
|
93 |
m_painter = painter; |
|
94 |
m_styleOption = option; |
|
95 |
++numRepaints; |
|
96 |
QGraphicsRectItem::paint(painter, option, widget); |
|
97 |
} |
|
98 |
||
99 |
void reset() |
|
100 |
{ |
|
101 |
numRepaints = 0; |
|
102 |
m_painter = 0; |
|
103 |
m_styleOption = 0; |
|
104 |
} |
|
105 |
||
106 |
int numRepaints; |
|
107 |
QPainter *m_painter; |
|
108 |
const QStyleOption *m_styleOption; |
|
109 |
}; |
|
110 |
||
111 |
class CustomEffect : public QGraphicsEffect |
|
112 |
{ |
|
113 |
public: |
|
114 |
CustomEffect() |
|
115 |
: QGraphicsEffect(), numRepaints(0), m_margin(10), |
|
116 |
doNothingInDraw(false), m_painter(0), m_styleOption(0), m_source(0), m_opacity(1.0) |
|
117 |
{} |
|
118 |
||
119 |
QRectF boundingRectFor(const QRectF &rect) const |
|
120 |
{ return rect.adjusted(-m_margin, -m_margin, m_margin, m_margin); } |
|
121 |
||
122 |
void reset() |
|
123 |
{ |
|
124 |
numRepaints = 0; |
|
125 |
m_sourceChangedFlags = QGraphicsEffect::ChangeFlags(); |
|
126 |
m_painter = 0; |
|
127 |
m_styleOption = 0; |
|
128 |
m_source = 0; |
|
129 |
m_opacity = 1.0; |
|
130 |
} |
|
131 |
||
132 |
void setMargin(int margin) |
|
133 |
{ |
|
134 |
m_margin = margin; |
|
135 |
updateBoundingRect(); |
|
136 |
} |
|
137 |
||
138 |
int margin() const |
|
139 |
{ return m_margin; } |
|
140 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
void draw(QPainter *painter) |
0 | 142 |
{ |
143 |
++numRepaints; |
|
144 |
if (doNothingInDraw) |
|
145 |
return; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
m_source = source(); |
0 | 147 |
m_painter = painter; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
m_styleOption = source()->styleOption(); |
0 | 149 |
m_opacity = painter->opacity(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
drawSource(painter); |
0 | 151 |
} |
152 |
||
153 |
void sourceChanged(QGraphicsEffect::ChangeFlags flags) |
|
154 |
{ m_sourceChangedFlags |= flags; } |
|
155 |
||
156 |
int numRepaints; |
|
157 |
int m_margin; |
|
158 |
QGraphicsEffect::ChangeFlags m_sourceChangedFlags; |
|
159 |
bool doNothingInDraw; |
|
160 |
QPainter *m_painter; |
|
161 |
const QStyleOption *m_styleOption; |
|
162 |
QGraphicsEffectSource *m_source; |
|
163 |
qreal m_opacity; |
|
164 |
}; |
|
165 |
||
166 |
void tst_QGraphicsEffect::setEnabled() |
|
167 |
{ |
|
168 |
CustomEffect effect; |
|
169 |
QVERIFY(effect.isEnabled()); |
|
170 |
||
171 |
effect.setEnabled(false); |
|
172 |
QVERIFY(!effect.isEnabled()); |
|
173 |
} |
|
174 |
||
175 |
void tst_QGraphicsEffect::source() |
|
176 |
{ |
|
177 |
QPointer<CustomEffect> effect = new CustomEffect; |
|
178 |
QVERIFY(!effect->source()); |
|
179 |
QVERIFY(!effect->m_sourceChangedFlags); |
|
180 |
||
181 |
// Install effect on QGraphicsItem. |
|
182 |
QGraphicsItem *item = new QGraphicsRectItem(0, 0, 10, 10); |
|
183 |
item->setGraphicsEffect(effect); |
|
184 |
QVERIFY(effect->source()); |
|
185 |
QCOMPARE(effect->source()->graphicsItem(), item); |
|
186 |
QVERIFY(effect->m_sourceChangedFlags & QGraphicsEffect::SourceAttached); |
|
187 |
effect->reset(); |
|
188 |
||
189 |
// Make sure disabling/enabling the effect doesn't change the source. |
|
190 |
effect->setEnabled(false); |
|
191 |
QVERIFY(effect->source()); |
|
192 |
QCOMPARE(effect->source()->graphicsItem(), item); |
|
193 |
QVERIFY(!effect->m_sourceChangedFlags); |
|
194 |
effect->reset(); |
|
195 |
||
196 |
effect->setEnabled(true); |
|
197 |
QVERIFY(effect->source()); |
|
198 |
QCOMPARE(effect->source()->graphicsItem(), item); |
|
199 |
QVERIFY(!effect->m_sourceChangedFlags); |
|
200 |
effect->reset(); |
|
201 |
||
202 |
// Uninstall effect on QGraphicsItem. |
|
203 |
effect->reset(); |
|
204 |
item->setGraphicsEffect(0); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
205 |
QVERIFY(!effect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
206 |
effect = new CustomEffect; |
0 | 207 |
|
208 |
// The item takes ownership and should delete the effect when destroyed. |
|
209 |
item->setGraphicsEffect(effect); |
|
210 |
QPointer<QGraphicsEffectSource> source = effect->source(); |
|
211 |
QVERIFY(source); |
|
212 |
QCOMPARE(source->graphicsItem(), item); |
|
213 |
delete item; |
|
214 |
QVERIFY(!effect); |
|
215 |
QVERIFY(!source); |
|
216 |
} |
|
217 |
||
218 |
void tst_QGraphicsEffect::boundingRectFor() |
|
219 |
{ |
|
220 |
CustomEffect effect; |
|
221 |
int margin = effect.margin(); |
|
222 |
const QRectF source(0, 0, 100, 100); |
|
223 |
QCOMPARE(effect.boundingRectFor(source), source.adjusted(-margin, -margin, margin, margin)); |
|
224 |
||
225 |
effect.setMargin(margin = 20); |
|
226 |
QCOMPARE(effect.boundingRectFor(source), source.adjusted(-margin, -margin, margin, margin)); |
|
227 |
} |
|
228 |
||
229 |
void tst_QGraphicsEffect::boundingRect() |
|
230 |
{ |
|
231 |
// No source; empty bounding rect. |
|
232 |
CustomEffect *effect = new CustomEffect; |
|
233 |
QCOMPARE(effect->boundingRect(), QRectF()); |
|
234 |
||
235 |
// Install effect on QGraphicsItem. |
|
236 |
QRectF itemRect(0, 0, 100, 100); |
|
237 |
QGraphicsRectItem *item = new QGraphicsRectItem; |
|
238 |
item->setRect(itemRect); |
|
239 |
item->setGraphicsEffect(effect); |
|
240 |
int margin = effect->margin(); |
|
241 |
QCOMPARE(effect->boundingRect(), itemRect.adjusted(-margin, -margin, margin, margin)); |
|
242 |
QCOMPARE(effect->boundingRect(), effect->boundingRectFor(itemRect)); |
|
243 |
||
244 |
// Make sure disabling/enabling the effect doesn't change the bounding rect. |
|
245 |
effect->setEnabled(false); |
|
246 |
QCOMPARE(effect->boundingRect(), itemRect.adjusted(-margin, -margin, margin, margin)); |
|
247 |
QCOMPARE(effect->boundingRect(), effect->boundingRectFor(itemRect)); |
|
248 |
effect->setEnabled(true); |
|
249 |
QCOMPARE(effect->boundingRect(), itemRect.adjusted(-margin, -margin, margin, margin)); |
|
250 |
QCOMPARE(effect->boundingRect(), effect->boundingRectFor(itemRect)); |
|
251 |
||
252 |
// Change effect margins. |
|
253 |
effect->setMargin(margin = 20); |
|
254 |
QCOMPARE(effect->boundingRect(), itemRect.adjusted(-margin, -margin, margin, margin)); |
|
255 |
QCOMPARE(effect->boundingRect(), effect->boundingRectFor(itemRect)); |
|
256 |
||
257 |
// Uninstall effect on QGraphicsItem. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
258 |
QPointer<CustomEffect> ptr = effect; |
0 | 259 |
item->setGraphicsEffect(0); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
260 |
QVERIFY(!ptr); |
0 | 261 |
|
262 |
delete item; |
|
263 |
} |
|
264 |
||
265 |
void tst_QGraphicsEffect::draw() |
|
266 |
{ |
|
267 |
QGraphicsScene scene; |
|
268 |
CustomItem *item = new CustomItem(0, 0, 100, 100); |
|
269 |
scene.addItem(item); |
|
270 |
||
271 |
QGraphicsView view(&scene); |
|
272 |
view.show(); |
|
273 |
QTest::qWaitForWindowShown(&view); |
|
274 |
QTRY_VERIFY(item->numRepaints > 0); |
|
275 |
item->reset(); |
|
276 |
||
277 |
// Make sure installing the effect triggers a repaint. |
|
278 |
CustomEffect *effect = new CustomEffect; |
|
279 |
item->setGraphicsEffect(effect); |
|
280 |
QTest::qWait(50); |
|
281 |
QCOMPARE(effect->numRepaints, 1); |
|
282 |
QCOMPARE(item->numRepaints, 1); |
|
283 |
||
284 |
// Make sure QPainter* and QStyleOptionGraphicsItem* stays persistent |
|
285 |
// during QGraphicsEffect::draw/QGraphicsItem::paint. |
|
286 |
QVERIFY(effect->m_painter); |
|
287 |
QCOMPARE(effect->m_painter, item->m_painter); |
|
288 |
QCOMPARE(effect->m_styleOption, item->m_styleOption); |
|
289 |
// Make sure QGraphicsEffect::source is persistent. |
|
290 |
QCOMPARE(effect->m_source, effect->source()); |
|
291 |
effect->reset(); |
|
292 |
item->reset(); |
|
293 |
||
294 |
// Make sure updating the source triggers a repaint. |
|
295 |
item->update(); |
|
296 |
QTest::qWait(50); |
|
297 |
QCOMPARE(effect->numRepaints, 1); |
|
298 |
QCOMPARE(item->numRepaints, 1); |
|
299 |
QVERIFY(effect->m_sourceChangedFlags & QGraphicsEffect::SourceInvalidated); |
|
300 |
effect->reset(); |
|
301 |
item->reset(); |
|
302 |
||
303 |
// Make sure changing the effect's bounding rect triggers a repaint. |
|
304 |
effect->setMargin(20); |
|
305 |
QTest::qWait(50); |
|
306 |
QCOMPARE(effect->numRepaints, 1); |
|
307 |
QCOMPARE(item->numRepaints, 1); |
|
308 |
effect->reset(); |
|
309 |
item->reset(); |
|
310 |
||
311 |
// Make sure change the item's bounding rect triggers a repaint. |
|
312 |
item->setRect(0, 0, 50, 50); |
|
313 |
QTest::qWait(50); |
|
314 |
QCOMPARE(effect->numRepaints, 1); |
|
315 |
QCOMPARE(item->numRepaints, 1); |
|
316 |
QVERIFY(effect->m_sourceChangedFlags & QGraphicsEffect::SourceBoundingRectChanged); |
|
317 |
effect->reset(); |
|
318 |
item->reset(); |
|
319 |
||
320 |
// Make sure the effect is the one to issue a repaint of the item. |
|
321 |
effect->doNothingInDraw = true; |
|
322 |
item->update(); |
|
323 |
QTest::qWait(50); |
|
324 |
QCOMPARE(effect->numRepaints, 1); |
|
325 |
QCOMPARE(item->numRepaints, 0); |
|
326 |
effect->doNothingInDraw = false; |
|
327 |
effect->reset(); |
|
328 |
item->reset(); |
|
329 |
||
330 |
// Make sure we update the source when disabling/enabling the effect. |
|
331 |
effect->setEnabled(false); |
|
332 |
QTest::qWait(50); |
|
333 |
QCOMPARE(effect->numRepaints, 0); |
|
334 |
QCOMPARE(item->numRepaints, 1); |
|
335 |
effect->reset(); |
|
336 |
item->reset(); |
|
337 |
||
338 |
effect->setEnabled(true); |
|
339 |
QTest::qWait(50); |
|
340 |
QCOMPARE(effect->numRepaints, 1); |
|
341 |
QCOMPARE(item->numRepaints, 1); |
|
342 |
effect->reset(); |
|
343 |
item->reset(); |
|
344 |
||
345 |
// Effect is already enabled; nothing should happen. |
|
346 |
effect->setEnabled(true); |
|
347 |
QTest::qWait(50); |
|
348 |
QCOMPARE(effect->numRepaints, 0); |
|
349 |
QCOMPARE(item->numRepaints, 0); |
|
350 |
||
351 |
// Make sure uninstalling an effect triggers a repaint. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
352 |
QPointer<CustomEffect> ptr = effect; |
0 | 353 |
item->setGraphicsEffect(0); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
354 |
QVERIFY(!ptr); |
0 | 355 |
QTest::qWait(50); |
356 |
QCOMPARE(item->numRepaints, 1); |
|
357 |
} |
|
358 |
||
359 |
void tst_QGraphicsEffect::opacity() |
|
360 |
{ |
|
361 |
// Make sure the painter's opacity is correct in QGraphicsEffect::draw. |
|
362 |
QGraphicsScene scene; |
|
363 |
CustomItem *item = new CustomItem(0, 0, 100, 100); |
|
364 |
item->setOpacity(0.5); |
|
365 |
CustomEffect *effect = new CustomEffect; |
|
366 |
item->setGraphicsEffect(effect); |
|
367 |
scene.addItem(item); |
|
368 |
||
369 |
QGraphicsView view(&scene); |
|
370 |
view.show(); |
|
371 |
QTest::qWaitForWindowShown(&view); |
|
372 |
QTRY_VERIFY(effect->numRepaints > 0); |
|
373 |
QCOMPARE(effect->m_opacity, qreal(0.5)); |
|
374 |
} |
|
375 |
||
376 |
void tst_QGraphicsEffect::grayscale() |
|
377 |
{ |
|
378 |
if (qApp->desktop()->depth() < 24) { |
|
379 |
QSKIP("Test only works on 32 bit displays", SkipAll); |
|
380 |
return; |
|
381 |
} |
|
382 |
||
383 |
QGraphicsScene scene(0, 0, 100, 100); |
|
384 |
||
385 |
QGraphicsRectItem *item = scene.addRect(0, 0, 50, 50); |
|
386 |
item->setPen(Qt::NoPen); |
|
387 |
item->setBrush(QColor(122, 193, 66)); // Qt light green |
|
388 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
389 |
QGraphicsColorizeEffect *effect = new QGraphicsColorizeEffect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
effect->setColor(Qt::black); |
0 | 391 |
item->setGraphicsEffect(effect); |
392 |
||
393 |
QPainter painter; |
|
394 |
QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); |
|
395 |
||
396 |
image.fill(0); |
|
397 |
painter.begin(&image); |
|
398 |
painter.setRenderHint(QPainter::Antialiasing); |
|
399 |
scene.render(&painter); |
|
400 |
painter.end(); |
|
401 |
||
402 |
QCOMPARE(image.pixel(10, 10), qRgb(148, 148, 148)); |
|
403 |
||
404 |
effect->setStrength(0.5); |
|
405 |
||
406 |
image.fill(0); |
|
407 |
painter.begin(&image); |
|
408 |
painter.setRenderHint(QPainter::Antialiasing); |
|
409 |
scene.render(&painter); |
|
410 |
painter.end(); |
|
411 |
||
412 |
QCOMPARE(image.pixel(10, 10), qRgb(135, 171, 107)); |
|
413 |
||
414 |
effect->setStrength(0.0); |
|
415 |
||
416 |
image.fill(0); |
|
417 |
painter.begin(&image); |
|
418 |
painter.setRenderHint(QPainter::Antialiasing); |
|
419 |
scene.render(&painter); |
|
420 |
painter.end(); |
|
421 |
||
422 |
QCOMPARE(image.pixel(10, 10), qRgb(122, 193, 66)); |
|
423 |
} |
|
424 |
||
425 |
void tst_QGraphicsEffect::colorize() |
|
426 |
{ |
|
427 |
if (qApp->desktop()->depth() < 24) { |
|
428 |
QSKIP("Test only works on 32 bit displays", SkipAll); |
|
429 |
return; |
|
430 |
} |
|
431 |
||
432 |
QGraphicsScene scene(0, 0, 100, 100); |
|
433 |
||
434 |
QGraphicsRectItem *item = scene.addRect(0, 0, 50, 50); |
|
435 |
item->setPen(Qt::NoPen); |
|
436 |
item->setBrush(QColor(122, 193, 66)); // Qt light green |
|
437 |
||
438 |
QGraphicsColorizeEffect *effect = new QGraphicsColorizeEffect; |
|
439 |
effect->setColor(QColor(102, 153, 51)); // Qt dark green |
|
440 |
item->setGraphicsEffect(effect); |
|
441 |
||
442 |
QPainter painter; |
|
443 |
QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); |
|
444 |
||
445 |
image.fill(0); |
|
446 |
painter.begin(&image); |
|
447 |
painter.setRenderHint(QPainter::Antialiasing); |
|
448 |
scene.render(&painter); |
|
449 |
painter.end(); |
|
450 |
||
451 |
QCOMPARE(image.pixel(10, 10), qRgb(191, 212, 169)); |
|
452 |
||
453 |
effect->setStrength(0.5); |
|
454 |
||
455 |
image.fill(0); |
|
456 |
painter.begin(&image); |
|
457 |
painter.setRenderHint(QPainter::Antialiasing); |
|
458 |
scene.render(&painter); |
|
459 |
painter.end(); |
|
460 |
||
461 |
QCOMPARE(image.pixel(10, 10), qRgb(156, 203, 117)); |
|
462 |
||
463 |
effect->setStrength(0.0); |
|
464 |
||
465 |
image.fill(0); |
|
466 |
painter.begin(&image); |
|
467 |
painter.setRenderHint(QPainter::Antialiasing); |
|
468 |
scene.render(&painter); |
|
469 |
painter.end(); |
|
470 |
||
471 |
QCOMPARE(image.pixel(10, 10), qRgb(122, 193, 66)); |
|
472 |
} |
|
473 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
474 |
class PixmapItemEffect : public QGraphicsEffect |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
475 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
476 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
477 |
PixmapItemEffect(const QPixmap &source) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
478 |
: QGraphicsEffect() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
479 |
, pixmap(source) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
480 |
, repaints(0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
481 |
{} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
482 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
483 |
QRectF boundingRectFor(const QRectF &rect) const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
484 |
{ return rect; } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
485 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
486 |
void draw(QPainter *painter) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
487 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
488 |
QVERIFY(sourcePixmap(Qt::LogicalCoordinates).pixmapData() == pixmap.pixmapData()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
489 |
QVERIFY((painter->worldTransform().type() <= QTransform::TxTranslate) == (sourcePixmap(Qt::DeviceCoordinates).pixmapData() == pixmap.pixmapData())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
490 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
491 |
++repaints; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
492 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
493 |
QPixmap pixmap; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
494 |
int repaints; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
495 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
496 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
497 |
void tst_QGraphicsEffect::drawPixmapItem() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
498 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
499 |
QImage image(32, 32, QImage::Format_RGB32); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
500 |
QPainter p(&image); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
501 |
p.fillRect(0, 0, 32, 16, Qt::blue); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
502 |
p.fillRect(0, 16, 32, 16, Qt::red); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
503 |
p.end(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
504 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
505 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
506 |
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(QPixmap::fromImage(image)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
507 |
scene.addItem(item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
508 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
509 |
PixmapItemEffect *effect = new PixmapItemEffect(item->pixmap()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
510 |
item->setGraphicsEffect(effect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
511 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
512 |
QGraphicsView view(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
513 |
view.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
514 |
QTest::qWaitForWindowShown(&view); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
515 |
QTRY_VERIFY(effect->repaints >= 1); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
516 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
517 |
item->rotate(180); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
518 |
QTest::qWait(50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
519 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
520 |
QTRY_VERIFY(effect->repaints >= 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
521 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
522 |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
523 |
class DeviceEffect : public QGraphicsEffect |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
524 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
525 |
public: |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
526 |
QRectF boundingRectFor(const QRectF &rect) const |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
527 |
{ return rect; } |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
528 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
529 |
void draw(QPainter *painter) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
530 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
531 |
QPoint offset; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
532 |
QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset, QGraphicsEffect::NoPad); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
533 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
534 |
if (pixmap.isNull()) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
535 |
return; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
536 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
537 |
painter->save(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
538 |
painter->setWorldTransform(QTransform()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
539 |
painter->drawPixmap(offset, pixmap); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
540 |
painter->restore(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
541 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
542 |
}; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
543 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
544 |
void tst_QGraphicsEffect::deviceCoordinateTranslateCaching() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
545 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
546 |
QGraphicsScene scene; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
547 |
CustomItem *item = new CustomItem(0, 0, 10, 10); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
548 |
scene.addItem(item); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
549 |
scene.setSceneRect(0, 0, 50, 0); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
550 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
551 |
item->setGraphicsEffect(new DeviceEffect); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
552 |
item->setPen(Qt::NoPen); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
553 |
item->setBrush(Qt::red); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
554 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
555 |
QGraphicsView view(&scene); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
556 |
view.show(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
557 |
QTest::qWaitForWindowShown(&view); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
558 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
559 |
QTRY_VERIFY(item->numRepaints >= 1); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
560 |
int numRepaints = item->numRepaints; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
561 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
562 |
item->translate(10, 0); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
563 |
QTest::qWait(50); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
564 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
565 |
QVERIFY(item->numRepaints == numRepaints); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
566 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
567 |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
568 |
void tst_QGraphicsEffect::inheritOpacity() |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
569 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
570 |
QGraphicsScene scene; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
571 |
QGraphicsRectItem *rectItem = new QGraphicsRectItem(0, 0, 10, 10); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
572 |
CustomItem *item = new CustomItem(0, 0, 10, 10, rectItem); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
573 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
574 |
scene.addItem(rectItem); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
575 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
576 |
item->setGraphicsEffect(new DeviceEffect); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
577 |
item->setPen(Qt::NoPen); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
578 |
item->setBrush(Qt::red); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
579 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
580 |
rectItem->setOpacity(0.5); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
581 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
582 |
QGraphicsView view(&scene); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
583 |
view.show(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
584 |
QTest::qWaitForWindowShown(&view); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
585 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
586 |
QTRY_VERIFY(item->numRepaints >= 1); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
587 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
588 |
int numRepaints = item->numRepaints; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
589 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
590 |
rectItem->setOpacity(1); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
591 |
QTest::qWait(50); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
592 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
593 |
// item should have been rerendered due to opacity changing |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
594 |
QTRY_VERIFY(item->numRepaints > numRepaints); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
595 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
596 |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
597 |
void tst_QGraphicsEffect::dropShadowClipping() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
598 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
599 |
QImage img(128, 128, QImage::Format_ARGB32_Premultiplied); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
600 |
img.fill(0xffffffff); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
601 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
602 |
QGraphicsScene scene; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
603 |
QGraphicsRectItem *item = new QGraphicsRectItem(-5, -500, 10, 1000); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
604 |
item->setGraphicsEffect(new QGraphicsDropShadowEffect); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
605 |
item->setPen(Qt::NoPen); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
606 |
item->setBrush(Qt::red); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
607 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
608 |
scene.addItem(item); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
609 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
610 |
QPainter p(&img); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
611 |
scene.render(&p, img.rect(), QRect(-64, -64, 128, 128)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
612 |
p.end(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
613 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
614 |
for (int y = 1; y < img.height(); ++y) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
615 |
for (int x = 0; x < img.width(); ++x) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
616 |
QCOMPARE(img.pixel(x, y), img.pixel(x, y-1)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
617 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
618 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
619 |
class MyGraphicsItem : public QGraphicsWidget |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
620 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
621 |
public: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
622 |
MyGraphicsItem(QGraphicsItem *parent = 0) : |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
623 |
QGraphicsWidget(parent), nbPaint(0) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
624 |
{} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
625 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
626 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
627 |
nbPaint++; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
628 |
QGraphicsWidget::paint(painter, option, widget); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
629 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
630 |
int nbPaint; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
631 |
}; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
632 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
633 |
void tst_QGraphicsEffect::childrenVisibilityShouldInvalidateCache() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
634 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
635 |
QGraphicsScene scene; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
636 |
MyGraphicsItem parent; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
637 |
parent.resize(200, 200); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
638 |
QGraphicsWidget child(&parent); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
639 |
child.resize(200, 200); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
640 |
child.setVisible(false); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
641 |
scene.addItem(&parent); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
642 |
QGraphicsView view(&scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
643 |
view.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
644 |
QApplication::setActiveWindow(&view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
645 |
QTest::qWaitForWindowShown(&view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
646 |
QTRY_COMPARE(parent.nbPaint, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
647 |
//we set an effect on the parent |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
648 |
parent.setGraphicsEffect(new QGraphicsDropShadowEffect(&parent)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
649 |
//flush the events |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
650 |
QApplication::processEvents(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
651 |
//new effect applied->repaint |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
652 |
QCOMPARE(parent.nbPaint, 2); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
653 |
child.setVisible(true); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
654 |
//flush the events |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
655 |
QApplication::processEvents(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
656 |
//a new child appears we need to redraw the effect. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
657 |
QCOMPARE(parent.nbPaint, 3); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
658 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
659 |
|
0 | 660 |
QTEST_MAIN(tst_QGraphicsEffect) |
661 |
#include "tst_qgraphicseffect.moc" |
|
662 |