0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
#include <QtTest/QtTest>
|
|
44 |
#include <qgraphicsscene.h>
|
|
45 |
#include <qgraphicsitem.h>
|
|
46 |
|
|
47 |
class tst_QGraphicsPixmapItem : public QObject
|
|
48 |
{
|
|
49 |
Q_OBJECT
|
|
50 |
|
|
51 |
public slots:
|
|
52 |
void initTestCase();
|
|
53 |
void cleanupTestCase();
|
|
54 |
void init();
|
|
55 |
void cleanup();
|
|
56 |
|
|
57 |
private slots:
|
|
58 |
void qgraphicspixmapitem_data();
|
|
59 |
void qgraphicspixmapitem();
|
|
60 |
void boundingRect_data();
|
|
61 |
void boundingRect();
|
|
62 |
void contains_data();
|
|
63 |
void contains();
|
|
64 |
void isObscuredBy_data();
|
|
65 |
void isObscuredBy();
|
|
66 |
void offset_data();
|
|
67 |
void offset();
|
|
68 |
void opaqueArea_data();
|
|
69 |
void opaqueArea();
|
|
70 |
void pixmap_data();
|
|
71 |
void pixmap();
|
|
72 |
void setPixmap_data();
|
|
73 |
void setPixmap();
|
|
74 |
void setShapeMode_data();
|
|
75 |
void setShapeMode();
|
|
76 |
void setTransformationMode_data();
|
|
77 |
void setTransformationMode();
|
|
78 |
void shape_data();
|
|
79 |
void shape();
|
|
80 |
void extension_data();
|
|
81 |
void extension();
|
|
82 |
void setExtension_data();
|
|
83 |
void setExtension();
|
|
84 |
void supportsExtension_data();
|
|
85 |
void supportsExtension();
|
|
86 |
};
|
|
87 |
|
|
88 |
// Subclass that exposes the protected functions.
|
|
89 |
class SubQGraphicsPixmapItem : public QGraphicsPixmapItem
|
|
90 |
{
|
|
91 |
public:
|
|
92 |
enum Extension {
|
|
93 |
UserExtension = QGraphicsItem::UserExtension
|
|
94 |
};
|
|
95 |
SubQGraphicsPixmapItem(QGraphicsItem *parent = 0) : QGraphicsPixmapItem(parent)
|
|
96 |
{
|
|
97 |
}
|
|
98 |
|
|
99 |
SubQGraphicsPixmapItem(const QPixmap &pixmap, QGraphicsItem *parent = 0) : QGraphicsPixmapItem(pixmap, parent)
|
|
100 |
{
|
|
101 |
}
|
|
102 |
|
|
103 |
QVariant call_extension(QVariant const& variant) const
|
|
104 |
{ return SubQGraphicsPixmapItem::extension(variant); }
|
|
105 |
|
|
106 |
void call_setExtension(Extension extension, QVariant const& variant)
|
|
107 |
{ return SubQGraphicsPixmapItem::setExtension((QGraphicsItem::Extension)extension, variant); }
|
|
108 |
|
|
109 |
bool call_supportsExtension(Extension extension) const
|
|
110 |
{ return SubQGraphicsPixmapItem::supportsExtension((QGraphicsItem::Extension)extension); }
|
|
111 |
};
|
|
112 |
|
|
113 |
// This will be called before the first test function is executed.
|
|
114 |
// It is only called once.
|
|
115 |
void tst_QGraphicsPixmapItem::initTestCase()
|
|
116 |
{
|
|
117 |
}
|
|
118 |
|
|
119 |
// This will be called after the last test function is executed.
|
|
120 |
// It is only called once.
|
|
121 |
void tst_QGraphicsPixmapItem::cleanupTestCase()
|
|
122 |
{
|
|
123 |
}
|
|
124 |
|
|
125 |
// This will be called before each test function is executed.
|
|
126 |
void tst_QGraphicsPixmapItem::init()
|
|
127 |
{
|
|
128 |
}
|
|
129 |
|
|
130 |
// This will be called after every test function.
|
|
131 |
void tst_QGraphicsPixmapItem::cleanup()
|
|
132 |
{
|
|
133 |
}
|
|
134 |
|
|
135 |
void tst_QGraphicsPixmapItem::qgraphicspixmapitem_data()
|
|
136 |
{
|
|
137 |
}
|
|
138 |
|
|
139 |
void tst_QGraphicsPixmapItem::qgraphicspixmapitem()
|
|
140 |
{
|
|
141 |
SubQGraphicsPixmapItem item;
|
|
142 |
item.boundingRect();
|
|
143 |
item.contains(QPoint());
|
|
144 |
item.isObscuredBy(0);
|
|
145 |
item.opaqueArea();
|
|
146 |
//item.paint();
|
|
147 |
QCOMPARE(item.offset(), QPointF());
|
|
148 |
QCOMPARE(item.pixmap(), QPixmap());
|
|
149 |
QCOMPARE(item.shapeMode(), QGraphicsPixmapItem::MaskShape);
|
|
150 |
QCOMPARE(item.transformationMode(), Qt::FastTransformation);
|
|
151 |
item.setOffset(0, 0);
|
|
152 |
item.setOffset(QPointF(0, 0));
|
|
153 |
item.setPixmap(QPixmap());
|
|
154 |
item.setShapeMode(QGraphicsPixmapItem::MaskShape);
|
|
155 |
item.setTransformationMode(Qt::FastTransformation);
|
|
156 |
item.shape();
|
|
157 |
item.type();
|
|
158 |
item.call_extension(QVariant());
|
|
159 |
item.call_setExtension(SubQGraphicsPixmapItem::UserExtension, QVariant());
|
|
160 |
item.call_supportsExtension(SubQGraphicsPixmapItem::UserExtension);
|
|
161 |
}
|
|
162 |
|
|
163 |
void tst_QGraphicsPixmapItem::boundingRect_data()
|
|
164 |
{
|
|
165 |
QTest::addColumn<QPixmap>("pixmap");
|
|
166 |
QTest::addColumn<QRectF>("boundingRect");
|
|
167 |
QTest::newRow("null") << QPixmap() << QRectF();
|
|
168 |
QTest::newRow("10x10") << QPixmap(10, 10) << QRectF(-0.5, -0.5, 11, 11);
|
|
169 |
}
|
|
170 |
|
|
171 |
// public QRectF boundingRect() const
|
|
172 |
void tst_QGraphicsPixmapItem::boundingRect()
|
|
173 |
{
|
|
174 |
QFETCH(QPixmap, pixmap);
|
|
175 |
QFETCH(QRectF, boundingRect);
|
|
176 |
|
|
177 |
SubQGraphicsPixmapItem item(pixmap);
|
|
178 |
QCOMPARE(item.boundingRect(), boundingRect);
|
|
179 |
}
|
|
180 |
|
|
181 |
void tst_QGraphicsPixmapItem::contains_data()
|
|
182 |
{
|
|
183 |
QTest::addColumn<QPixmap>("pixmap");
|
|
184 |
QTest::addColumn<QPointF>("point");
|
|
185 |
QTest::addColumn<bool>("contains");
|
|
186 |
QTest::newRow("null") << QPixmap() << QPointF() << false;
|
|
187 |
QTest::newRow("10x10, 100x100") << QPixmap(10, 10) << QPointF(100, 100) << false;
|
|
188 |
QTest::newRow("10x10, 5x5") << QPixmap(10, 10) << QPointF(5, 5) << true;
|
|
189 |
QTest::newRow("border-1") << QPixmap(10, 10) << QPointF(10.5, 10.5) << false;
|
|
190 |
QTest::newRow("border-2") << QPixmap(10, 10) << QPointF(-0.5, -0.5) << false;
|
|
191 |
}
|
|
192 |
|
|
193 |
// public bool contains(QPointF const& point) const
|
|
194 |
void tst_QGraphicsPixmapItem::contains()
|
|
195 |
{
|
|
196 |
QFETCH(QPixmap, pixmap);
|
|
197 |
QFETCH(QPointF, point);
|
|
198 |
QFETCH(bool, contains);
|
|
199 |
|
|
200 |
SubQGraphicsPixmapItem item(pixmap);
|
|
201 |
QCOMPARE(item.contains(point), contains);
|
|
202 |
}
|
|
203 |
|
|
204 |
void tst_QGraphicsPixmapItem::isObscuredBy_data()
|
|
205 |
{
|
|
206 |
QTest::addColumn<QPixmap>("pixmap");
|
|
207 |
QTest::addColumn<QPixmap>("otherPixmap");
|
|
208 |
QTest::addColumn<bool>("isObscuredBy");
|
|
209 |
QTest::newRow("null") << QPixmap() << QPixmap() << false;
|
|
210 |
QTest::newRow("(10, 10) vs. (5, 5)") << QPixmap(10, 10) << QPixmap(5, 5) << false;
|
|
211 |
QTest::newRow("(5, 5) vs. (10, 10)") << QPixmap(5, 5) << QPixmap(10, 10) << true;
|
|
212 |
QTest::newRow("(10, 10) vs. (10, 10)") << QPixmap(10, 10) << QPixmap(10, 10) << false;
|
|
213 |
QTest::newRow("(9, 9) vs. (10, 10)") << QPixmap(8, 8) << QPixmap(10, 10) << true;
|
|
214 |
QTest::newRow("(10, 10) vs. (9, 9)") << QPixmap(10, 10) << QPixmap(8, 8) << false;
|
|
215 |
}
|
|
216 |
|
|
217 |
// public bool isObscuredBy(QGraphicsItem const* item) const
|
|
218 |
void tst_QGraphicsPixmapItem::isObscuredBy()
|
|
219 |
{
|
|
220 |
QFETCH(QPixmap, pixmap);
|
|
221 |
QFETCH(QPixmap, otherPixmap);
|
|
222 |
QFETCH(bool, isObscuredBy);
|
|
223 |
pixmap.fill();
|
|
224 |
otherPixmap.fill();
|
|
225 |
|
|
226 |
SubQGraphicsPixmapItem *item = new SubQGraphicsPixmapItem(pixmap);
|
|
227 |
SubQGraphicsPixmapItem *otherItem = new SubQGraphicsPixmapItem(otherPixmap);
|
|
228 |
|
|
229 |
item->setOffset(-pixmap.width() / 2.0, -pixmap.height() / 2.0);
|
|
230 |
otherItem->setOffset(-otherPixmap.width() / 2.0, -otherPixmap.height() / 2.0);
|
|
231 |
|
|
232 |
QGraphicsScene scene;
|
|
233 |
scene.addItem(item);
|
|
234 |
scene.addItem(otherItem);
|
|
235 |
otherItem->setZValue(1);
|
|
236 |
|
|
237 |
QCOMPARE(item->isObscuredBy(otherItem), isObscuredBy);
|
|
238 |
}
|
|
239 |
|
|
240 |
void tst_QGraphicsPixmapItem::offset_data()
|
|
241 |
{
|
|
242 |
QTest::addColumn<QPixmap>("pixmap");
|
|
243 |
QTest::addColumn<QPointF>("offset");
|
|
244 |
QTest::newRow("null") << QPixmap() << QPointF();
|
|
245 |
QTest::newRow("10x10, 1x1") << QPixmap(10, 10) << QPointF(1, 1);
|
|
246 |
}
|
|
247 |
|
|
248 |
// public QPointF offset() const
|
|
249 |
void tst_QGraphicsPixmapItem::offset()
|
|
250 |
{
|
|
251 |
QFETCH(QPixmap, pixmap);
|
|
252 |
QFETCH(QPointF, offset);
|
|
253 |
|
|
254 |
SubQGraphicsPixmapItem item(pixmap);
|
|
255 |
item.setOffset(offset);
|
|
256 |
QCOMPARE(item.offset(), offset);
|
|
257 |
|
|
258 |
// ### test actual painting and compare pixmap with offseted one?
|
|
259 |
}
|
|
260 |
|
|
261 |
Q_DECLARE_METATYPE(QPainterPath)
|
|
262 |
void tst_QGraphicsPixmapItem::opaqueArea_data()
|
|
263 |
{
|
|
264 |
QTest::addColumn<QPixmap>("pixmap");
|
|
265 |
QTest::addColumn<QPainterPath>("opaqueArea");
|
|
266 |
QTest::newRow("null") << QPixmap() << QPainterPath();
|
|
267 |
// Currently QGraphicsPixmapItem just calls QGraphicsItem test there
|
|
268 |
}
|
|
269 |
|
|
270 |
// public QPainterPath opaqueArea() const
|
|
271 |
void tst_QGraphicsPixmapItem::opaqueArea()
|
|
272 |
{
|
|
273 |
QFETCH(QPixmap, pixmap);
|
|
274 |
QFETCH(QPainterPath, opaqueArea);
|
|
275 |
|
|
276 |
SubQGraphicsPixmapItem item;
|
|
277 |
QCOMPARE(item.opaqueArea(), opaqueArea);
|
|
278 |
}
|
|
279 |
|
|
280 |
void tst_QGraphicsPixmapItem::pixmap_data()
|
|
281 |
{
|
|
282 |
QTest::addColumn<QPixmap>("pixmap");
|
|
283 |
QTest::newRow("null") << QPixmap();
|
|
284 |
QTest::newRow("10x10") << QPixmap(10, 10);
|
|
285 |
}
|
|
286 |
|
|
287 |
// public QPixmap pixmap() const
|
|
288 |
void tst_QGraphicsPixmapItem::pixmap()
|
|
289 |
{
|
|
290 |
QFETCH(QPixmap, pixmap);
|
|
291 |
|
|
292 |
SubQGraphicsPixmapItem item(pixmap);
|
|
293 |
QCOMPARE(item.pixmap(), pixmap);
|
|
294 |
}
|
|
295 |
|
|
296 |
void tst_QGraphicsPixmapItem::setPixmap_data()
|
|
297 |
{
|
|
298 |
QTest::addColumn<QPixmap>("pixmap");
|
|
299 |
QTest::newRow("null") << QPixmap();
|
|
300 |
QTest::newRow("10x10") << QPixmap(10, 10);
|
|
301 |
}
|
|
302 |
|
|
303 |
// public void setPixmap(QPixmap const& pixmap)
|
|
304 |
void tst_QGraphicsPixmapItem::setPixmap()
|
|
305 |
{
|
|
306 |
QFETCH(QPixmap, pixmap);
|
|
307 |
|
|
308 |
SubQGraphicsPixmapItem item;
|
|
309 |
item.setPixmap(pixmap);
|
|
310 |
QCOMPARE(item.pixmap(), pixmap);
|
|
311 |
}
|
|
312 |
|
|
313 |
Q_DECLARE_METATYPE(QGraphicsPixmapItem::ShapeMode)
|
|
314 |
void tst_QGraphicsPixmapItem::setShapeMode_data()
|
|
315 |
{
|
|
316 |
QTest::addColumn<QPixmap>("pixmap");
|
|
317 |
QTest::addColumn<QGraphicsPixmapItem::ShapeMode>("mode");
|
|
318 |
QTest::newRow("MaskShape") << QPixmap() << QGraphicsPixmapItem::MaskShape;
|
|
319 |
QTest::newRow("BoundingRectShape") << QPixmap() << QGraphicsPixmapItem::BoundingRectShape;
|
|
320 |
QTest::newRow("HeuristicMaskShape") << QPixmap() << QGraphicsPixmapItem::HeuristicMaskShape;
|
|
321 |
}
|
|
322 |
|
|
323 |
// public void setShapeMode(QGraphicsPixmapItem::ShapeMode mode)
|
|
324 |
void tst_QGraphicsPixmapItem::setShapeMode()
|
|
325 |
{
|
|
326 |
QFETCH(QPixmap, pixmap);
|
|
327 |
QFETCH(QGraphicsPixmapItem::ShapeMode, mode);
|
|
328 |
|
|
329 |
SubQGraphicsPixmapItem item(pixmap);
|
|
330 |
item.setShapeMode(mode);
|
|
331 |
QCOMPARE(item.shapeMode(), mode);
|
|
332 |
}
|
|
333 |
|
|
334 |
Q_DECLARE_METATYPE(Qt::TransformationMode)
|
|
335 |
void tst_QGraphicsPixmapItem::setTransformationMode_data()
|
|
336 |
{
|
|
337 |
QTest::addColumn<QPixmap>("pixmap");
|
|
338 |
QTest::addColumn<Qt::TransformationMode>("mode");
|
|
339 |
QTest::newRow("FastTransformation") << QPixmap() << Qt::FastTransformation;
|
|
340 |
QTest::newRow("SmoothTransformation") << QPixmap() << Qt::SmoothTransformation;
|
|
341 |
}
|
|
342 |
|
|
343 |
// public void setTransformationMode(Qt::TransformationMode mode)
|
|
344 |
void tst_QGraphicsPixmapItem::setTransformationMode()
|
|
345 |
{
|
|
346 |
QFETCH(QPixmap, pixmap);
|
|
347 |
QFETCH(Qt::TransformationMode, mode);
|
|
348 |
|
|
349 |
SubQGraphicsPixmapItem item(pixmap);
|
|
350 |
item.setTransformationMode(mode);
|
|
351 |
QCOMPARE(item.transformationMode(), mode);
|
|
352 |
}
|
|
353 |
|
|
354 |
void tst_QGraphicsPixmapItem::shape_data()
|
|
355 |
{
|
|
356 |
QTest::addColumn<QPixmap>("pixmap");
|
|
357 |
QTest::addColumn<QPainterPath>("shape");
|
|
358 |
QTest::newRow("null") << QPixmap() << QPainterPath();
|
|
359 |
// ### what does a normal shape look like?
|
|
360 |
}
|
|
361 |
|
|
362 |
// public QPainterPath shape() const
|
|
363 |
void tst_QGraphicsPixmapItem::shape()
|
|
364 |
{
|
|
365 |
QFETCH(QPixmap, pixmap);
|
|
366 |
QFETCH(QPainterPath, shape);
|
|
367 |
|
|
368 |
SubQGraphicsPixmapItem item(pixmap);
|
|
369 |
QCOMPARE(item.shape(), shape);
|
|
370 |
}
|
|
371 |
|
|
372 |
Q_DECLARE_METATYPE(SubQGraphicsPixmapItem::Extension)
|
|
373 |
Q_DECLARE_METATYPE(QVariant)
|
|
374 |
void tst_QGraphicsPixmapItem::extension_data()
|
|
375 |
{
|
|
376 |
QTest::addColumn<QVariant>("variant");
|
|
377 |
QTest::addColumn<QVariant>("extension");
|
|
378 |
QTest::newRow("null") << QVariant() << QVariant();
|
|
379 |
}
|
|
380 |
|
|
381 |
// protected QVariant extension(QVariant const& variant) const
|
|
382 |
void tst_QGraphicsPixmapItem::extension()
|
|
383 |
{
|
|
384 |
QFETCH(QVariant, variant);
|
|
385 |
QFETCH(QVariant, extension);
|
|
386 |
|
|
387 |
SubQGraphicsPixmapItem item;
|
|
388 |
QCOMPARE(item.call_extension(variant), extension);
|
|
389 |
}
|
|
390 |
|
|
391 |
void tst_QGraphicsPixmapItem::setExtension_data()
|
|
392 |
{
|
|
393 |
QTest::addColumn<SubQGraphicsPixmapItem::Extension>("extension");
|
|
394 |
QTest::addColumn<QVariant>("variant");
|
|
395 |
QTest::newRow("null") << SubQGraphicsPixmapItem::UserExtension << QVariant();
|
|
396 |
}
|
|
397 |
|
|
398 |
// protected void setExtension(QGraphicsItem::Extension extension, QVariant const& variant)
|
|
399 |
void tst_QGraphicsPixmapItem::setExtension()
|
|
400 |
{
|
|
401 |
QFETCH(SubQGraphicsPixmapItem::Extension, extension);
|
|
402 |
QFETCH(QVariant, variant);
|
|
403 |
|
|
404 |
SubQGraphicsPixmapItem item;
|
|
405 |
item.call_setExtension(extension, variant);
|
|
406 |
}
|
|
407 |
|
|
408 |
void tst_QGraphicsPixmapItem::supportsExtension_data()
|
|
409 |
{
|
|
410 |
QTest::addColumn<SubQGraphicsPixmapItem::Extension>("extension");
|
|
411 |
QTest::addColumn<bool>("supportsExtension");
|
|
412 |
QTest::newRow("null") << SubQGraphicsPixmapItem::UserExtension << false;
|
|
413 |
}
|
|
414 |
|
|
415 |
// protected bool supportsExtension(QGraphicsItem::Extension extension) const
|
|
416 |
void tst_QGraphicsPixmapItem::supportsExtension()
|
|
417 |
{
|
|
418 |
QFETCH(SubQGraphicsPixmapItem::Extension, extension);
|
|
419 |
QFETCH(bool, supportsExtension);
|
|
420 |
|
|
421 |
SubQGraphicsPixmapItem item;
|
|
422 |
QCOMPARE(item.call_supportsExtension(extension), supportsExtension);
|
|
423 |
}
|
|
424 |
|
|
425 |
QTEST_MAIN(tst_QGraphicsPixmapItem)
|
|
426 |
#include "tst_qgraphicspixmapitem.moc"
|
|
427 |
|