author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 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 <qgraphicswidget.h> |
|
45 |
#include <qgraphicsscene.h> |
|
46 |
#include <qgraphicssceneevent.h> |
|
47 |
#include <qgraphicsview.h> |
|
48 |
#include <qstyleoption.h> |
|
49 |
#include <qgraphicslinearlayout.h> |
|
50 |
#include <qcleanlooksstyle.h> |
|
51 |
#include <qlineedit.h> |
|
52 |
#include <qboxlayout.h> |
|
53 |
#include <qaction.h> |
|
54 |
#include <qwidgetaction.h> |
|
55 |
#include "../../shared/util.h" |
|
56 |
||
57 |
||
58 |
class EventSpy : public QObject |
|
59 |
{ |
|
60 |
Q_OBJECT |
|
61 |
public: |
|
62 |
EventSpy(QObject *watched, QEvent::Type type) |
|
63 |
: _count(0), spied(type) |
|
64 |
{ |
|
65 |
watched->installEventFilter(this); |
|
66 |
} |
|
67 |
||
68 |
int count() const { return _count; } |
|
69 |
||
70 |
protected: |
|
71 |
bool eventFilter(QObject *watched, QEvent *event) |
|
72 |
{ |
|
73 |
Q_UNUSED(watched); |
|
74 |
if (event->type() == spied) |
|
75 |
++_count; |
|
76 |
return false; |
|
77 |
} |
|
78 |
||
79 |
int _count; |
|
80 |
QEvent::Type spied; |
|
81 |
}; |
|
82 |
||
83 |
#ifndef QT_NO_STYLE_CLEANLOOKS |
|
84 |
class tst_QGraphicsWidget : public QObject { |
|
85 |
Q_OBJECT |
|
86 |
||
87 |
public slots: |
|
88 |
void initTestCase(); |
|
89 |
void cleanupTestCase(); |
|
90 |
void init(); |
|
91 |
void cleanup(); |
|
92 |
||
93 |
private slots: |
|
94 |
void qgraphicswidget(); |
|
95 |
||
96 |
void activation(); |
|
97 |
void boundingRect_data(); |
|
98 |
void boundingRect(); |
|
99 |
void dumpFocusChain_data(); |
|
100 |
void dumpFocusChain(); |
|
101 |
void focusWidget_data(); |
|
102 |
void focusWidget(); |
|
103 |
void focusWidget2(); |
|
104 |
void focusPolicy_data(); |
|
105 |
void focusPolicy(); |
|
106 |
void font_data(); |
|
107 |
void font(); |
|
108 |
void fontPropagation(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
109 |
void fontChangedEvent(); |
0 | 110 |
void fontPropagationWidgetItemWidget(); |
111 |
void fontPropagationSceneChange(); |
|
112 |
void geometry_data(); |
|
113 |
void geometry(); |
|
114 |
void getContentsMargins_data(); |
|
115 |
void getContentsMargins(); |
|
116 |
void initStyleOption_data(); |
|
117 |
void initStyleOption(); |
|
118 |
void layout_data(); |
|
119 |
void layout(); |
|
120 |
void layoutDirection_data(); |
|
121 |
void layoutDirection(); |
|
122 |
void paint_data(); |
|
123 |
void paint(); |
|
124 |
void palettePropagation(); |
|
125 |
void parentWidget_data(); |
|
126 |
void parentWidget(); |
|
127 |
void resize_data(); |
|
128 |
void resize(); |
|
129 |
void setAttribute_data(); |
|
130 |
void setAttribute(); |
|
131 |
void setStyle_data(); |
|
132 |
void setStyle(); |
|
133 |
void setTabOrder_data(); |
|
134 |
void setTabOrder(); |
|
135 |
void setTabOrderAndReparent(); |
|
136 |
void topLevelWidget_data(); |
|
137 |
void topLevelWidget(); |
|
138 |
void unsetLayoutDirection_data(); |
|
139 |
void unsetLayoutDirection(); |
|
140 |
void focusNextPrevChild_data(); |
|
141 |
void focusNextPrevChild(); |
|
142 |
void verifyFocusChain(); |
|
143 |
void updateFocusChainWhenChildDie(); |
|
144 |
void sizeHint_data(); |
|
145 |
void sizeHint(); |
|
146 |
void consistentPosSizeGeometry_data(); |
|
147 |
void consistentPosSizeGeometry(); |
|
148 |
void setSizes_data(); |
|
149 |
void setSizes(); |
|
150 |
void closePopupOnOutsideClick(); |
|
151 |
void defaultSize(); |
|
152 |
void explicitMouseGrabber(); |
|
153 |
void implicitMouseGrabber(); |
|
154 |
void doubleClickAfterExplicitMouseGrab(); |
|
155 |
void popupMouseGrabber(); |
|
156 |
void windowFlags_data(); |
|
157 |
void windowFlags(); |
|
158 |
void shortcutsDeletion(); |
|
159 |
void painterStateProtectionOnWindowFrame(); |
|
160 |
void ensureClipping(); |
|
161 |
void widgetSendsGeometryChanges(); |
|
162 |
void respectHFW(); |
|
163 |
void addChildInpolishEvent(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
void polishEvent(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
void polishEvent2(); |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
166 |
void initialShow(); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
167 |
void initialShow2(); |
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
168 |
void itemChangeEvents(); |
0 | 169 |
|
170 |
// Task fixes |
|
171 |
void task236127_bspTreeIndexFails(); |
|
172 |
void task243004_setStyleCrash(); |
|
173 |
void task250119_shortcutContext(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
174 |
void QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems(); |
0 | 175 |
}; |
176 |
||
177 |
||
178 |
static void sendMouseMove(QWidget *widget, const QPoint &point, Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons buttons = 0) |
|
179 |
{ |
|
180 |
QTest::mouseMove(widget, point); |
|
181 |
QMouseEvent event(QEvent::MouseMove, point, button, buttons, 0); |
|
182 |
QApplication::sendEvent(widget, &event); |
|
183 |
} |
|
184 |
||
185 |
// Subclass that exposes the protected functions. |
|
186 |
class SubQGraphicsWidget : public QGraphicsWidget { |
|
187 |
public: |
|
188 |
SubQGraphicsWidget(QGraphicsItem *parent = 0, Qt::WindowFlags windowFlags = 0) |
|
189 |
: QGraphicsWidget(parent, windowFlags), eventCount(0) |
|
190 |
{ } |
|
191 |
||
192 |
void initStyleOption(QStyleOption *option) |
|
193 |
{ QGraphicsWidget::initStyleOption(option); } |
|
194 |
||
195 |
void call_changeEvent(QEvent* event) |
|
196 |
{ return QGraphicsWidget::changeEvent(event); } |
|
197 |
||
198 |
bool call_event(QEvent *e) |
|
199 |
{ return event(e); } |
|
200 |
||
201 |
void call_focusInEvent(QFocusEvent* event) |
|
202 |
{ return QGraphicsWidget::focusInEvent(event); } |
|
203 |
||
204 |
bool call_focusNextPrevChild(bool next) |
|
205 |
{ return QGraphicsWidget::focusNextPrevChild(next); } |
|
206 |
||
207 |
void call_focusOutEvent(QFocusEvent* event) |
|
208 |
{ return QGraphicsWidget::focusOutEvent(event); } |
|
209 |
||
210 |
void call_hideEvent(QHideEvent* event) |
|
211 |
{ return QGraphicsWidget::hideEvent(event); } |
|
212 |
||
213 |
QVariant call_itemChange(QGraphicsItem::GraphicsItemChange change, QVariant const& value) |
|
214 |
{ return QGraphicsWidget::itemChange(change, value); } |
|
215 |
||
216 |
void call_moveEvent(QGraphicsSceneMoveEvent* event) |
|
217 |
{ return QGraphicsWidget::moveEvent(event); } |
|
218 |
||
219 |
void call_polishEvent() |
|
220 |
{ return QGraphicsWidget::polishEvent(); } |
|
221 |
||
222 |
QVariant call_propertyChange(QString const& propertyName, QVariant const& value) |
|
223 |
{ return QGraphicsWidget::propertyChange(propertyName, value); } |
|
224 |
||
225 |
void call_resizeEvent(QGraphicsSceneResizeEvent* event) |
|
226 |
{ return QGraphicsWidget::resizeEvent(event); } |
|
227 |
||
228 |
bool call_sceneEvent(QEvent* event) |
|
229 |
{ return QGraphicsWidget::sceneEvent(event); } |
|
230 |
||
231 |
void call_showEvent(QShowEvent* event) |
|
232 |
{ return QGraphicsWidget::showEvent(event); } |
|
233 |
||
234 |
QSizeF call_sizeHint(Qt::SizeHint which, QSizeF const& constraint = QSizeF()) const |
|
235 |
{ return QGraphicsWidget::sizeHint(which, constraint); } |
|
236 |
||
237 |
void call_updateGeometry() |
|
238 |
{ return QGraphicsWidget::updateGeometry(); } |
|
239 |
||
240 |
int eventCount; |
|
241 |
Qt::LayoutDirection m_painterLayoutDirection; |
|
242 |
||
243 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
244 |
{ |
|
245 |
m_painterLayoutDirection = painter->layoutDirection(); |
|
246 |
QGraphicsWidget::paint(painter, option, widget); |
|
247 |
if (hasFocus()) { |
|
248 |
painter->setPen(Qt::DotLine); |
|
249 |
painter->drawRect(rect()); |
|
250 |
} |
|
251 |
//painter->drawText(QPointF(0,15), data(0).toString()); |
|
252 |
} |
|
253 |
||
254 |
protected: |
|
255 |
bool event(QEvent *event) |
|
256 |
{ |
|
257 |
eventCount++; |
|
258 |
return QGraphicsWidget::event(event); |
|
259 |
} |
|
260 |
}; |
|
261 |
||
262 |
// This will be called before the first test function is executed. |
|
263 |
// It is only called once. |
|
264 |
void tst_QGraphicsWidget::initTestCase() |
|
265 |
{ |
|
266 |
} |
|
267 |
||
268 |
// This will be called after the last test function is executed. |
|
269 |
// It is only called once. |
|
270 |
void tst_QGraphicsWidget::cleanupTestCase() |
|
271 |
{ |
|
272 |
} |
|
273 |
||
274 |
// This will be called before each test function is executed. |
|
275 |
void tst_QGraphicsWidget::init() |
|
276 |
{ |
|
277 |
} |
|
278 |
||
279 |
// This will be called after every test function. |
|
280 |
void tst_QGraphicsWidget::cleanup() |
|
281 |
{ |
|
282 |
} |
|
283 |
||
284 |
class SizeHinter : public QGraphicsWidget |
|
285 |
{ |
|
286 |
public: |
|
287 |
SizeHinter(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0, |
|
288 |
const QSizeF &min = QSizeF(5,5), |
|
289 |
const QSizeF &pref = QSizeF(50, 50), |
|
290 |
const QSizeF &max = QSizeF(500, 500)) |
|
291 |
: QGraphicsWidget(parent, wFlags) |
|
292 |
{ |
|
293 |
m_sizes[Qt::MinimumSize] = min; |
|
294 |
m_sizes[Qt::PreferredSize] = pref; |
|
295 |
m_sizes[Qt::MaximumSize] = max; |
|
296 |
||
297 |
} |
|
298 |
void setSizeHint(Qt::SizeHint which, const QSizeF &newSizeHint) |
|
299 |
{ |
|
300 |
m_sizes[which] = newSizeHint; |
|
301 |
} |
|
302 |
||
303 |
protected: |
|
304 |
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const |
|
305 |
{ |
|
306 |
Q_UNUSED(constraint); |
|
307 |
return m_sizes[which]; |
|
308 |
} |
|
309 |
private: |
|
310 |
QSizeF m_sizes[4]; |
|
311 |
}; |
|
312 |
||
313 |
void tst_QGraphicsWidget::qgraphicswidget() |
|
314 |
{ |
|
315 |
SubQGraphicsWidget widget; |
|
316 |
QVERIFY(widget.isVisible()); |
|
317 |
||
318 |
QVERIFY(!widget.isWindow()); |
|
319 |
QCOMPARE(widget.boundingRect(), QRectF(0, 0, 0, 0)); |
|
320 |
QCOMPARE(widget.focusWidget(), (QGraphicsWidget*)0); |
|
321 |
QCOMPARE(widget.focusPolicy(), Qt::NoFocus); |
|
322 |
QCOMPARE(widget.font(), QFont()); |
|
323 |
QCOMPARE(widget.geometry(), QRectF(widget.pos(), widget.size())); |
|
324 |
QCOMPARE(widget.layout(), (QGraphicsLayout*)0); |
|
325 |
QCOMPARE(widget.layoutDirection(), Qt::LeftToRight); |
|
326 |
QCOMPARE(widget.palette(), QPalette()); |
|
327 |
QCOMPARE(widget.parentWidget(), (QGraphicsWidget*)0); |
|
328 |
QCOMPARE(widget.rect(), QRectF(QPointF(), widget.size())); |
|
329 |
QCOMPARE(widget.size(), QSizeF(0, 0)); |
|
330 |
QVERIFY(widget.style() != (QStyle*)0); |
|
331 |
QCOMPARE(widget.testAttribute(Qt::WA_AcceptDrops), false); |
|
332 |
QCOMPARE(widget.topLevelWidget(), (QGraphicsWidget*)&widget); |
|
333 |
QCOMPARE(widget.type(), (int)QGraphicsWidget::Type); |
|
334 |
QCOMPARE(widget.call_propertyChange(QString(), QVariant()), QVariant()); |
|
335 |
widget.call_sizeHint(Qt::PreferredSize, QSizeF()); |
|
336 |
||
337 |
QGraphicsScene scene; |
|
338 |
QGraphicsWidget *parent = new QGraphicsWidget; |
|
339 |
SizeHinter *child = new SizeHinter(parent); |
|
340 |
||
341 |
QCOMPARE(child->minimumSize(), QSizeF(5, 5)); |
|
342 |
} |
|
343 |
||
344 |
void tst_QGraphicsWidget::activation() |
|
345 |
{ |
|
346 |
QGraphicsWidget *widget = new QGraphicsWidget; |
|
347 |
QGraphicsWidget *window1 = new QGraphicsWidget(0, Qt::Window); |
|
348 |
QGraphicsWidget *window2 = new QGraphicsWidget(0, Qt::Window); |
|
349 |
QVERIFY(!widget->isActiveWindow()); |
|
350 |
QVERIFY(!window1->isActiveWindow()); |
|
351 |
QVERIFY(!window2->isActiveWindow()); |
|
352 |
||
353 |
QGraphicsScene scene; |
|
354 |
scene.addItem(widget); |
|
355 |
scene.addItem(window1); |
|
356 |
scene.addItem(window2); |
|
357 |
||
358 |
QVERIFY(!widget->isActiveWindow()); |
|
359 |
QVERIFY(!window1->isActiveWindow()); |
|
360 |
QVERIFY(!window2->isActiveWindow()); |
|
361 |
||
362 |
QEvent activateEvent(QEvent::WindowActivate); |
|
363 |
QApplication::sendEvent(&scene, &activateEvent); |
|
364 |
||
365 |
QVERIFY(!widget->isActiveWindow()); |
|
366 |
QVERIFY(window1->isActiveWindow()); |
|
367 |
QVERIFY(!window2->isActiveWindow()); |
|
368 |
||
369 |
scene.setActiveWindow(window1); |
|
370 |
QVERIFY(!widget->isActiveWindow()); |
|
371 |
QVERIFY(window1->isActiveWindow()); |
|
372 |
QVERIFY(!window2->isActiveWindow()); |
|
373 |
||
374 |
QEvent deactivateEvent(QEvent::WindowDeactivate); |
|
375 |
QApplication::sendEvent(&scene, &deactivateEvent); |
|
376 |
||
377 |
QVERIFY(!widget->isActiveWindow()); |
|
378 |
QVERIFY(!window1->isActiveWindow()); |
|
379 |
QVERIFY(!window2->isActiveWindow()); |
|
380 |
} |
|
381 |
||
382 |
void tst_QGraphicsWidget::boundingRect_data() |
|
383 |
{ |
|
384 |
QTest::addColumn<QSizeF>("size"); |
|
385 |
QTest::newRow("null") << QSizeF(0, 0); |
|
386 |
QTest::newRow("avg") << QSizeF(10, 10); |
|
387 |
} |
|
388 |
||
389 |
// QRectF boundingRect() const public |
|
390 |
void tst_QGraphicsWidget::boundingRect() |
|
391 |
{ |
|
392 |
QFETCH(QSizeF, size); |
|
393 |
SubQGraphicsWidget widget; |
|
394 |
widget.resize(size); |
|
395 |
QCOMPARE(widget.rect(), QRectF(QPointF(), size)); |
|
396 |
QCOMPARE(widget.boundingRect(), QRectF(QPointF(0, 0), size)); |
|
397 |
} |
|
398 |
||
399 |
void tst_QGraphicsWidget::dumpFocusChain_data() |
|
400 |
{ |
|
401 |
QTest::addColumn<bool>("scene"); |
|
402 |
QTest::addColumn<int>("children"); |
|
403 |
QTest::addColumn<bool>("setFocus"); |
|
404 |
QTest::newRow("empty world") << false << 0 << false; |
|
405 |
QTest::newRow("one world") << true << 2 << false; |
|
406 |
QTest::newRow("one world w/focus") << true << 2 << true; |
|
407 |
} |
|
408 |
||
409 |
// void dumpFocusChain(QGraphicsScene* scene) public (static) |
|
410 |
void tst_QGraphicsWidget::dumpFocusChain() |
|
411 |
{ |
|
412 |
// ### this test is very strange... |
|
413 |
QFETCH(bool, scene); |
|
414 |
SubQGraphicsWidget *parent = new SubQGraphicsWidget; |
|
415 |
QGraphicsScene *theScene = 0; |
|
416 |
if (scene) { |
|
417 |
theScene = new QGraphicsScene(this); |
|
418 |
theScene->addItem(parent); |
|
419 |
} |
|
420 |
QFETCH(int, children); |
|
421 |
QFETCH(bool, setFocus); |
|
422 |
for (int i = 0; i < children; ++i) { |
|
423 |
SubQGraphicsWidget *widget = new SubQGraphicsWidget(parent); |
|
424 |
if (setFocus) { |
|
425 |
widget->setFlag(QGraphicsItem::ItemIsFocusable, true); |
|
426 |
if (scene) |
|
427 |
theScene->setFocusItem(widget); |
|
428 |
} |
|
429 |
} |
|
430 |
||
431 |
if (!scene) |
|
432 |
delete parent; |
|
433 |
} |
|
434 |
||
435 |
void tst_QGraphicsWidget::focusWidget_data() |
|
436 |
{ |
|
437 |
QTest::addColumn<int>("childCount"); |
|
438 |
QTest::addColumn<int>("childWithFocus"); |
|
439 |
QTest::newRow("none") << 0 << 0; |
|
440 |
QTest::newRow("first") << 3 << 0; |
|
441 |
QTest::newRow("last") << 3 << 2; |
|
442 |
} |
|
443 |
||
444 |
// QGraphicsWidget* focusWidget() const public |
|
445 |
void tst_QGraphicsWidget::focusWidget() |
|
446 |
{ |
|
447 |
SubQGraphicsWidget *parent = new SubQGraphicsWidget; |
|
448 |
QCOMPARE(parent->focusWidget(), (QGraphicsWidget *)0); |
|
449 |
QGraphicsScene scene; |
|
450 |
QEvent windowActivate(QEvent::WindowActivate); |
|
451 |
qApp->sendEvent(&scene, &windowActivate); |
|
452 |
scene.addItem(parent); |
|
453 |
||
454 |
QFETCH(int, childCount); |
|
455 |
QList<SubQGraphicsWidget *> children; |
|
456 |
for (int i = 0; i < childCount; ++i) { |
|
457 |
SubQGraphicsWidget *widget = new SubQGraphicsWidget(parent); |
|
458 |
widget->setFlag(QGraphicsItem::ItemIsFocusable, true); |
|
459 |
children.append(widget); |
|
460 |
} |
|
461 |
if (childCount > 0) { |
|
462 |
QFETCH(int, childWithFocus); |
|
463 |
SubQGraphicsWidget *widget = children[childWithFocus]; |
|
464 |
widget->setFocus(); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
465 |
QTRY_VERIFY(widget->hasFocus()); |
0 | 466 |
QCOMPARE(parent->focusWidget(), static_cast<QGraphicsWidget*>(widget)); |
467 |
} |
|
468 |
} |
|
469 |
||
470 |
void tst_QGraphicsWidget::focusWidget2() |
|
471 |
{ |
|
472 |
QGraphicsScene scene; |
|
473 |
QEvent windowActivate(QEvent::WindowActivate); |
|
474 |
qApp->sendEvent(&scene, &windowActivate); |
|
475 |
||
476 |
QGraphicsWidget *widget = new QGraphicsWidget; |
|
477 |
EventSpy focusInSpy(widget, QEvent::FocusIn); |
|
478 |
EventSpy focusOutSpy(widget, QEvent::FocusOut); |
|
479 |
||
480 |
scene.addItem(widget); |
|
481 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
482 |
QTRY_VERIFY(!widget->hasFocus()); |
0 | 483 |
widget->setFocusPolicy(Qt::StrongFocus); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
484 |
QTRY_VERIFY(!widget->hasFocus()); |
0 | 485 |
|
486 |
QGraphicsWidget *subWidget = new QGraphicsWidget(widget); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
487 |
QTRY_VERIFY(!subWidget->hasFocus()); |
0 | 488 |
|
489 |
scene.setFocus(); |
|
490 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
491 |
QTRY_VERIFY(!widget->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
492 |
QTRY_VERIFY(!subWidget->hasFocus()); |
0 | 493 |
|
494 |
widget->setFocus(); |
|
495 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
496 |
QTRY_VERIFY(widget->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
497 |
QTRY_COMPARE(focusInSpy.count(), 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
498 |
QTRY_VERIFY(!subWidget->hasFocus()); |
0 | 499 |
|
500 |
QGraphicsWidget *otherSubWidget = new QGraphicsWidget; |
|
501 |
EventSpy otherFocusInSpy(otherSubWidget, QEvent::FocusIn); |
|
502 |
EventSpy otherFocusOutSpy(otherSubWidget, QEvent::FocusOut); |
|
503 |
||
504 |
otherSubWidget->setFocusPolicy(Qt::StrongFocus); |
|
505 |
otherSubWidget->setParentItem(widget); |
|
506 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
507 |
QTRY_VERIFY(widget->hasFocus()); |
0 | 508 |
QCOMPARE(scene.focusItem(), (QGraphicsItem *)widget); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
509 |
QTRY_VERIFY(!subWidget->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
510 |
QTRY_VERIFY(!otherSubWidget->hasFocus()); |
0 | 511 |
|
512 |
widget->hide(); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
513 |
QTRY_VERIFY(!widget->hasFocus()); // lose but still has subfocus |
0 | 514 |
QCOMPARE(focusInSpy.count(), 1); |
515 |
QCOMPARE(focusOutSpy.count(), 1); |
|
516 |
||
517 |
widget->show(); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
518 |
QTRY_VERIFY(!widget->hasFocus()); // no regain |
0 | 519 |
QCOMPARE(focusInSpy.count(), 1); |
520 |
QCOMPARE(focusOutSpy.count(), 1); |
|
521 |
||
522 |
widget->hide(); |
|
523 |
||
524 |
// try to setup subFocus on item that can't take focus |
|
525 |
subWidget->setFocus(); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
526 |
QTRY_VERIFY(!subWidget->hasFocus()); |
0 | 527 |
QVERIFY(!scene.focusItem()); // but isn't the scene's focus item |
528 |
||
529 |
// try to setup subFocus on item that can take focus |
|
530 |
otherSubWidget->setFocus(); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
531 |
QTRY_VERIFY(!otherSubWidget->hasFocus()); |
0 | 532 |
QCOMPARE(widget->focusWidget(), otherSubWidget); |
533 |
QVERIFY(!scene.focusItem()); // but isn't the scene's focus item |
|
534 |
||
535 |
widget->show(); |
|
536 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
537 |
QTRY_COMPARE(scene.focusItem(), (QGraphicsItem *)otherSubWidget); // but isn't the scene's focus item |
0 | 538 |
QCOMPARE(otherFocusInSpy.count(), 1); |
539 |
QCOMPARE(otherFocusOutSpy.count(), 0); |
|
540 |
||
541 |
delete otherSubWidget; |
|
542 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
543 |
QTRY_COMPARE(otherFocusOutSpy.count(), 1); |
0 | 544 |
QVERIFY(!scene.focusItem()); |
545 |
QVERIFY(!widget->focusWidget()); |
|
546 |
} |
|
547 |
||
548 |
Q_DECLARE_METATYPE(Qt::FocusPolicy) |
|
549 |
void tst_QGraphicsWidget::focusPolicy_data() |
|
550 |
{ |
|
551 |
QTest::addColumn<Qt::FocusPolicy>("focusPolicy1"); |
|
552 |
QTest::addColumn<Qt::FocusPolicy>("focusPolicy2"); |
|
553 |
||
554 |
for (int i = 0; i < 25; ++i) { |
|
555 |
QTestData &data = QTest::newRow(QString("%1").arg(i).toLatin1()); |
|
556 |
switch(i % 5) { |
|
557 |
case 0: data << Qt::TabFocus; break; |
|
558 |
case 1: data << Qt::ClickFocus; break; |
|
559 |
case 2: data << Qt::StrongFocus; break; |
|
560 |
case 3: data << Qt::WheelFocus; break; |
|
561 |
case 4: data << Qt::NoFocus; break; |
|
562 |
} |
|
563 |
switch(i / 5) { |
|
564 |
case 0: data << Qt::TabFocus; break; |
|
565 |
case 1: data << Qt::ClickFocus; break; |
|
566 |
case 2: data << Qt::StrongFocus; break; |
|
567 |
case 3: data << Qt::WheelFocus; break; |
|
568 |
case 4: data << Qt::NoFocus; break; |
|
569 |
} |
|
570 |
} |
|
571 |
} |
|
572 |
||
573 |
// Qt::FocusPolicy focusPolicy() const public |
|
574 |
void tst_QGraphicsWidget::focusPolicy() |
|
575 |
{ |
|
576 |
QGraphicsScene scene; |
|
577 |
QEvent windowActivate(QEvent::WindowActivate); |
|
578 |
qApp->sendEvent(&scene, &windowActivate); |
|
579 |
||
580 |
SubQGraphicsWidget *widget = new SubQGraphicsWidget; |
|
581 |
scene.addItem(widget); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
582 |
QTRY_COMPARE(Qt::NoFocus, widget->focusPolicy()); |
0 | 583 |
|
584 |
QFETCH(Qt::FocusPolicy, focusPolicy1); |
|
585 |
widget->setFocusPolicy(focusPolicy1); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
586 |
QTRY_COMPARE(widget->focusPolicy(), focusPolicy1); |
0 | 587 |
bool isFocusable = widget->flags() & QGraphicsItem::ItemIsFocusable; |
588 |
bool wasFocusable = isFocusable; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
589 |
QTRY_VERIFY(isFocusable == (focusPolicy1 != Qt::NoFocus)); |
0 | 590 |
widget->setFocus(); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
591 |
QTRY_COMPARE(widget->hasFocus(), isFocusable); |
0 | 592 |
|
593 |
QFETCH(Qt::FocusPolicy, focusPolicy2); |
|
594 |
widget->setFocusPolicy(focusPolicy2); |
|
595 |
QCOMPARE(widget->focusPolicy(), focusPolicy2); |
|
596 |
isFocusable = widget->flags() & QGraphicsItem::ItemIsFocusable; |
|
597 |
QVERIFY(isFocusable == (focusPolicy2 != Qt::NoFocus)); |
|
598 |
QCOMPARE(widget->hasFocus(), wasFocusable && isFocusable); |
|
599 |
} |
|
600 |
||
601 |
void tst_QGraphicsWidget::font_data() |
|
602 |
{ |
|
603 |
QTest::addColumn<QString>("fontName"); |
|
604 |
QTest::newRow("Helvetica") << "Helvetica"; |
|
605 |
} |
|
606 |
||
607 |
// QFont font() const public |
|
608 |
void tst_QGraphicsWidget::font() |
|
609 |
{ |
|
610 |
QFETCH(QString, fontName); |
|
611 |
SubQGraphicsWidget widget; |
|
612 |
QCOMPARE(widget.font(), QFont()); |
|
613 |
||
614 |
QFont font(fontName); |
|
615 |
widget.setFont(font); |
|
616 |
QCOMPARE(widget.font().family(), font.family()); |
|
617 |
} |
|
618 |
||
619 |
void tst_QGraphicsWidget::fontPropagation() |
|
620 |
{ |
|
621 |
QGraphicsWidget *root = new QGraphicsWidget; |
|
622 |
QGraphicsWidget *child0 = new QGraphicsWidget(root); |
|
623 |
QGraphicsWidget *child1 = new QGraphicsWidget(child0); |
|
624 |
QGraphicsWidget *child2 = new QGraphicsWidget(child1); |
|
625 |
QGraphicsScene scene; |
|
626 |
scene.addItem(root); |
|
627 |
||
628 |
// Check that only the application fonts apply. |
|
629 |
QFont appFont = QApplication::font(); |
|
630 |
QCOMPARE(scene.font(), appFont); |
|
631 |
QCOMPARE(root->font(), appFont); |
|
632 |
QCOMPARE(child0->font(), appFont); |
|
633 |
QCOMPARE(child1->font(), appFont); |
|
634 |
||
635 |
// Set child0's Text, and set ToolTipBase on child1. |
|
636 |
QFont boldFont; |
|
637 |
boldFont.setBold(true); |
|
638 |
child0->setFont(boldFont); |
|
639 |
QFont italicFont; |
|
640 |
italicFont.setItalic(true); |
|
641 |
child1->setFont(italicFont); |
|
642 |
||
643 |
// Check that the above settings propagate correctly. |
|
644 |
QCOMPARE(root->font(), appFont); |
|
645 |
QCOMPARE(scene.font(), appFont); |
|
646 |
QVERIFY(child0->font().bold()); |
|
647 |
QVERIFY(!child0->font().italic()); |
|
648 |
QVERIFY(child1->font().bold()); |
|
649 |
QVERIFY(child1->font().italic()); |
|
650 |
QVERIFY(child2->font().bold()); |
|
651 |
QVERIFY(child2->font().italic()); |
|
652 |
||
653 |
QGraphicsWidget *child3 = new QGraphicsWidget(child2); |
|
654 |
QVERIFY(child3->font().bold()); |
|
655 |
QVERIFY(child3->font().italic()); |
|
656 |
||
657 |
QGraphicsWidget *child4 = new QGraphicsWidget; |
|
658 |
child4->setParentItem(child3); |
|
659 |
QVERIFY(child4->font().bold()); |
|
660 |
QVERIFY(child4->font().italic()); |
|
661 |
||
662 |
// Replace the app font for child2. Button should propagate but Text |
|
663 |
// should still be ignored. The previous ToolTipBase setting is gone. |
|
664 |
QFont sizeFont; |
|
665 |
sizeFont.setPointSize(43); |
|
666 |
child1->setFont(sizeFont); |
|
667 |
||
668 |
// Check that the above settings propagate correctly. |
|
669 |
QCOMPARE(root->font(), appFont); |
|
670 |
QCOMPARE(scene.font(), appFont); |
|
671 |
QVERIFY(child0->font().bold()); |
|
672 |
QVERIFY(!child0->font().italic()); |
|
673 |
QVERIFY(child1->font().bold()); |
|
674 |
QVERIFY(!child1->font().italic()); |
|
675 |
QCOMPARE(child1->font().pointSize(), 43); |
|
676 |
QVERIFY(child2->font().bold()); |
|
677 |
QVERIFY(!child2->font().italic()); |
|
678 |
QCOMPARE(child2->font().pointSize(), 43); |
|
679 |
} |
|
680 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
681 |
void tst_QGraphicsWidget::fontChangedEvent() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
682 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
683 |
QGraphicsWidget *root = new QGraphicsWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
684 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
685 |
scene.addItem(root); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
686 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
687 |
// Check that only the application fonts apply. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
688 |
QFont appFont = QApplication::font(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
689 |
QCOMPARE(scene.font(), appFont); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
690 |
QCOMPARE(root->font(), appFont); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
691 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
692 |
EventSpy rootSpyFont(root, QEvent::FontChange); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
693 |
EventSpy rootSpyPolish(root, QEvent::Polish); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
694 |
QTRY_COMPARE(rootSpyFont.count(), 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
695 |
QTRY_COMPARE(rootSpyPolish.count(), 1); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
696 |
//The font is still the same so no fontChangeEvent |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
697 |
QTRY_COMPARE(rootSpyFont.count(), 0); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
698 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
699 |
QFont font; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
700 |
font.setPointSize(43); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
701 |
root->setFont(font); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
702 |
//The font changed |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
703 |
QTRY_COMPARE(rootSpyFont.count(), 1); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
704 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
705 |
//then roll back to the default one. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
706 |
root->setFont(appFont); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
707 |
//The font changed |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
708 |
QTRY_COMPARE(rootSpyFont.count(), 2); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
709 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
710 |
|
0 | 711 |
void tst_QGraphicsWidget::fontPropagationWidgetItemWidget() |
712 |
{ |
|
713 |
QGraphicsWidget *widget = new QGraphicsWidget; |
|
714 |
QGraphicsRectItem *rect = new QGraphicsRectItem(widget); |
|
715 |
QGraphicsWidget *widget2 = new QGraphicsWidget(rect); |
|
716 |
||
717 |
QGraphicsScene scene; |
|
718 |
scene.addItem(widget); |
|
719 |
||
720 |
QFont font; |
|
721 |
font.setPointSize(43); |
|
722 |
widget->setFont(font); |
|
723 |
||
724 |
QCOMPARE(widget2->font().pointSize(), 43); |
|
725 |
QCOMPARE(widget2->font().resolve(), QFont().resolve()); |
|
726 |
||
727 |
widget->setFont(QFont()); |
|
728 |
||
729 |
QCOMPARE(widget2->font().pointSize(), qApp->font().pointSize()); |
|
730 |
} |
|
731 |
||
732 |
void tst_QGraphicsWidget::fontPropagationSceneChange() |
|
733 |
{ |
|
734 |
QGraphicsWidget *widget = new QGraphicsWidget; |
|
735 |
QGraphicsRectItem *rect = new QGraphicsRectItem(widget); |
|
736 |
QGraphicsWidget *widget2 = new QGraphicsWidget(rect); |
|
737 |
||
738 |
QGraphicsScene scene; |
|
739 |
QGraphicsScene scene2; |
|
740 |
||
741 |
QFont font; |
|
742 |
font.setPointSize(47); |
|
743 |
scene.setFont(font); |
|
744 |
||
745 |
QFont font2; |
|
746 |
font2.setPointSize(74); |
|
747 |
scene2.setFont(font2); |
|
748 |
||
749 |
scene.addItem(widget); |
|
750 |
QCOMPARE(widget2->font().pointSize(), 47); |
|
751 |
scene2.addItem(widget); |
|
752 |
QCOMPARE(widget2->font().pointSize(), 74); |
|
753 |
} |
|
754 |
||
755 |
void tst_QGraphicsWidget::geometry_data() |
|
756 |
{ |
|
757 |
QTest::addColumn<QPointF>("pos"); |
|
758 |
QTest::addColumn<QSizeF>("size"); |
|
759 |
QTest::newRow("null, null") << QPointF() << QSizeF(0, 0); |
|
760 |
QTest::newRow("null, normal") << QPointF() << QSizeF(10, 10); |
|
761 |
QTest::newRow("neg, normal") << QPointF(-5, -5) << QSizeF(10, 10); |
|
762 |
} |
|
763 |
||
764 |
// QRectF geometry() const public |
|
765 |
void tst_QGraphicsWidget::geometry() |
|
766 |
{ |
|
767 |
SubQGraphicsWidget widget; |
|
768 |
QCOMPARE(widget.geometry(), QRectF(widget.pos(), widget.size())); |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
769 |
|
0 | 770 |
QFETCH(QPointF, pos); |
771 |
QFETCH(QSizeF, size); |
|
772 |
widget.setPos(pos); |
|
773 |
widget.resize(size); |
|
774 |
QCOMPARE(widget.geometry(), QRectF(pos, size)); |
|
775 |
} |
|
776 |
||
777 |
void tst_QGraphicsWidget::getContentsMargins_data() |
|
778 |
{ |
|
779 |
QTest::addColumn<qreal>("left"); |
|
780 |
QTest::addColumn<qreal>("top"); |
|
781 |
QTest::addColumn<qreal>("right"); |
|
782 |
QTest::addColumn<qreal>("bottom"); |
|
783 |
QTest::newRow("null") << (qreal)0 << (qreal)0 << (qreal)0 << (qreal)0; |
|
784 |
QTest::newRow("something") << (qreal)10 << (qreal)5 << (qreal)3 << (qreal)7; |
|
785 |
QTest::newRow("real") << (qreal)1.7 << (qreal)5.9 << (qreal)3.2 << (qreal)9.7; |
|
786 |
} |
|
787 |
||
788 |
// void getContentsMargins(qreal* left, qreal* top, qreal* right, qreal* bottom) const public |
|
789 |
void tst_QGraphicsWidget::getContentsMargins() |
|
790 |
{ |
|
791 |
qreal gleft; |
|
792 |
qreal gtop; |
|
793 |
qreal gright; |
|
794 |
qreal gbottom; |
|
795 |
||
796 |
SubQGraphicsWidget widget; |
|
797 |
widget.getContentsMargins(&gleft, >op, &gright, &gbottom); |
|
798 |
QCOMPARE(gleft, (qreal)0); |
|
799 |
QCOMPARE(gtop, (qreal)0); |
|
800 |
QCOMPARE(gright, (qreal)0); |
|
801 |
QCOMPARE(gbottom, (qreal)0); |
|
802 |
||
803 |
QFETCH(qreal, left); |
|
804 |
QFETCH(qreal, top); |
|
805 |
QFETCH(qreal, right); |
|
806 |
QFETCH(qreal, bottom); |
|
807 |
int oldEventCounts = widget.eventCount; |
|
808 |
widget.setContentsMargins(left, top, right, bottom); |
|
809 |
QVERIFY(left == 0 || oldEventCounts != widget.eventCount); |
|
810 |
widget.getContentsMargins(&gleft, >op, &gright, &gbottom); |
|
811 |
QCOMPARE(gleft, left); |
|
812 |
QCOMPARE(gtop, top); |
|
813 |
QCOMPARE(gright, right); |
|
814 |
QCOMPARE(gbottom, bottom); |
|
815 |
} |
|
816 |
||
817 |
Q_DECLARE_METATYPE(Qt::LayoutDirection) |
|
818 |
void tst_QGraphicsWidget::initStyleOption_data() |
|
819 |
{ |
|
820 |
QTest::addColumn<bool>("enabled"); |
|
821 |
QTest::addColumn<bool>("focus"); |
|
822 |
QTest::addColumn<bool>("underMouse"); |
|
823 |
QTest::addColumn<Qt::LayoutDirection>("layoutDirection"); |
|
824 |
QTest::addColumn<QSizeF>("size"); |
|
825 |
QTest::addColumn<QPalette>("palette"); |
|
826 |
QTest::addColumn<QString>("fontName"); |
|
827 |
QTest::newRow("none") << false << false << false << Qt::LeftToRight << QSizeF(0, 0) << QPalette() << QString(); |
|
828 |
QTest::newRow("all") << true << true << true << Qt::RightToLeft << QSizeF(300, 300) << QPalette(Qt::magenta) << "Helvetica"; |
|
829 |
QTest::newRow("rand") << true << false << false << Qt::RightToLeft << QSizeF(1, 0) << QPalette(Qt::darkCyan) << "Times"; |
|
830 |
} |
|
831 |
||
832 |
// void initStyleOption(QStyleOption* option) const public |
|
833 |
void tst_QGraphicsWidget::initStyleOption() |
|
834 |
{ |
|
835 |
QGraphicsScene scene; |
|
836 |
QGraphicsView view(&scene); |
|
837 |
view.show(); |
|
838 |
#ifdef Q_WS_X11 |
|
839 |
qt_x11_wait_for_window_manager(&view); |
|
840 |
#endif |
|
841 |
QApplication::setActiveWindow(&view); |
|
842 |
QTRY_COMPARE(QApplication::activeWindow(), &view); |
|
843 |
||
844 |
view.setAlignment(Qt::AlignTop | Qt::AlignLeft); |
|
845 |
SubQGraphicsWidget *widget = new SubQGraphicsWidget; |
|
846 |
widget->setAcceptsHoverEvents(true); |
|
847 |
QStyleOption option; |
|
848 |
scene.addItem(widget); |
|
849 |
||
850 |
QFETCH(QSizeF, size); |
|
851 |
widget->resize(size); |
|
852 |
||
853 |
QFETCH(bool, enabled); |
|
854 |
widget->setEnabled(enabled); |
|
855 |
QFETCH(bool, focus); |
|
856 |
if (focus) { |
|
857 |
widget->setFlag(QGraphicsItem::ItemIsFocusable, true); |
|
858 |
widget->setFocus(); |
|
859 |
QVERIFY(widget->hasFocus()); |
|
860 |
} |
|
861 |
QFETCH(bool, underMouse); |
|
862 |
if (underMouse) { |
|
863 |
view.resize(300, 300); |
|
864 |
view.show(); |
|
865 |
QTest::qWaitForWindowShown(&view); |
|
866 |
sendMouseMove(view.viewport(), view.mapFromScene(widget->mapToScene(widget->boundingRect().center()))); |
|
867 |
} |
|
868 |
||
869 |
QFETCH(QPalette, palette); |
|
870 |
widget->setPalette(palette); |
|
871 |
||
872 |
QFETCH(QString, fontName); |
|
873 |
widget->setFont(QFont(fontName)); |
|
874 |
||
875 |
// The test |
|
876 |
widget->initStyleOption(&option); |
|
877 |
||
878 |
bool isEnabled = option.state & QStyle::State_Enabled; |
|
879 |
QCOMPARE(isEnabled, enabled); |
|
880 |
bool hasFocus = option.state & QStyle::State_HasFocus; |
|
881 |
QCOMPARE(hasFocus, focus); |
|
882 |
bool isUnderMouse = option.state & QStyle::State_MouseOver; |
|
883 |
#ifndef Q_OS_WINCE |
|
884 |
QCOMPARE(isUnderMouse, underMouse); |
|
885 |
#endif |
|
886 |
// if (layoutDirection != Qt::LeftToRight) |
|
887 |
//QEXPECT_FAIL("", "QApplicaiton::layoutDirection doesn't propagate to QGraphicsWidget", Continue); |
|
888 |
//QCOMPARE(option.direction, layoutDirection); |
|
889 |
QCOMPARE(option.rect, QRectF(QPointF(), size).toRect()); |
|
890 |
QCOMPARE(option.palette, palette.resolve(QApplication::palette())); |
|
891 |
QCOMPARE(option.fontMetrics, QFontMetrics(widget->font())); |
|
892 |
} |
|
893 |
||
894 |
void tst_QGraphicsWidget::layout_data() |
|
895 |
{ |
|
896 |
QTest::addColumn<int>("childCount"); |
|
897 |
QTest::newRow("empty") << 0; |
|
898 |
QTest::newRow("10") << 10; |
|
899 |
} |
|
900 |
||
901 |
// QGraphicsLayout* layout() const public |
|
902 |
void tst_QGraphicsWidget::layout() |
|
903 |
{ |
|
904 |
SubQGraphicsWidget widget; |
|
905 |
widget.setContentsMargins(10, 5, 50, 100); |
|
906 |
QCOMPARE(widget.layout(), (QGraphicsLayout *)0); |
|
907 |
QFETCH(int, childCount); |
|
908 |
||
909 |
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout; |
|
910 |
QList<SubQGraphicsWidget*> children; |
|
911 |
for (int i = 0; i < childCount; ++i) { |
|
912 |
SubQGraphicsWidget *item = new SubQGraphicsWidget; |
|
913 |
layout->addItem(item); |
|
914 |
children.append(item); |
|
915 |
} |
|
916 |
widget.setLayout(layout); |
|
917 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
918 |
QTRY_COMPARE(widget.layout(), static_cast<QGraphicsLayout*>(layout)); |
0 | 919 |
for (int i = 0; i < children.count(); ++i) { |
920 |
SubQGraphicsWidget *item = children[i]; |
|
921 |
QCOMPARE(item->parentWidget(), (QGraphicsWidget *)&widget); |
|
922 |
QVERIFY(item->geometry() != QRectF(0, 0, -1, -1)); |
|
923 |
} |
|
924 |
||
925 |
// don't crash |
|
926 |
widget.setLayout(0); |
|
927 |
} |
|
928 |
||
929 |
void tst_QGraphicsWidget::layoutDirection_data() |
|
930 |
{ |
|
931 |
QTest::addColumn<Qt::LayoutDirection>("layoutDirection"); |
|
932 |
QTest::newRow("rtl") << Qt::RightToLeft; |
|
933 |
QTest::newRow("ltr") << Qt::LeftToRight; |
|
934 |
} |
|
935 |
||
936 |
// Qt::LayoutDirection layoutDirection() const public |
|
937 |
void tst_QGraphicsWidget::layoutDirection() |
|
938 |
{ |
|
939 |
QFETCH(Qt::LayoutDirection, layoutDirection); |
|
940 |
QGraphicsScene scene; |
|
941 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
942 |
SubQGraphicsWidget widget; |
|
943 |
scene.addItem(&widget); |
|
944 |
QCOMPARE(widget.layoutDirection(), Qt::LeftToRight); |
|
945 |
QCOMPARE(widget.testAttribute(Qt::WA_SetLayoutDirection), false); |
|
946 |
||
947 |
QList<SubQGraphicsWidget*> children; |
|
948 |
for (int i = 0; i < 10; ++i) { |
|
949 |
SubQGraphicsWidget *item = new SubQGraphicsWidget(&widget); |
|
950 |
children.append(item); |
|
951 |
QCOMPARE(item->testAttribute(Qt::WA_SetLayoutDirection), false); |
|
952 |
} |
|
953 |
widget.setLayoutDirection(layoutDirection); |
|
954 |
QCOMPARE(widget.testAttribute(Qt::WA_SetLayoutDirection), true); |
|
955 |
view->show(); |
|
956 |
QTest::qWaitForWindowShown(view); |
|
957 |
for (int i = 0; i < children.count(); ++i) { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
958 |
QTRY_COMPARE(children[i]->layoutDirection(), layoutDirection); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
959 |
QTRY_COMPARE(children[i]->testAttribute(Qt::WA_SetLayoutDirection), false); |
0 | 960 |
view->repaint(); |
961 |
QTRY_COMPARE(children[i]->m_painterLayoutDirection, layoutDirection); |
|
962 |
} |
|
963 |
delete view; |
|
964 |
} |
|
965 |
||
966 |
void tst_QGraphicsWidget::paint_data() |
|
967 |
{ |
|
968 |
// currently QGraphicsWidget doesn't paint or do anything ... |
|
969 |
} |
|
970 |
||
971 |
// void paint(QPainter* painter, QStyleOptionGraphicsItem const* option, QWidget* widget) public |
|
972 |
void tst_QGraphicsWidget::paint() |
|
973 |
{ |
|
974 |
SubQGraphicsWidget widget; |
|
975 |
QPainter painter; |
|
976 |
QStyleOptionGraphicsItem option; |
|
977 |
widget.paint(&painter, &option, 0); // check that widget = 0 works. |
|
978 |
} |
|
979 |
||
980 |
void tst_QGraphicsWidget::palettePropagation() |
|
981 |
{ |
|
982 |
QGraphicsWidget *root = new QGraphicsWidget; |
|
983 |
QGraphicsWidget *child0 = new QGraphicsWidget(root); |
|
984 |
QGraphicsWidget *child1 = new QGraphicsWidget(child0); |
|
985 |
QGraphicsWidget *child2 = new QGraphicsWidget(child1); |
|
986 |
QGraphicsScene scene; |
|
987 |
scene.addItem(root); |
|
988 |
||
989 |
// These colors are unlikely to be imposed on the default palette of |
|
990 |
// QWidget ;-). |
|
991 |
QColor sysPalText(21, 22, 23); |
|
992 |
QColor sysPalToolTipBase(12, 13, 14); |
|
993 |
QColor overridePalText(42, 43, 44); |
|
994 |
QColor overridePalToolTipBase(45, 46, 47); |
|
995 |
QColor sysPalButton(99, 98, 97); |
|
996 |
||
997 |
// Check that only the application fonts apply. |
|
998 |
QPalette appPal = QApplication::palette(); |
|
999 |
QCOMPARE(scene.palette(), appPal); |
|
1000 |
QCOMPARE(root->palette(), appPal); |
|
1001 |
QCOMPARE(child0->palette(), appPal); |
|
1002 |
QCOMPARE(child1->palette(), appPal); |
|
1003 |
||
1004 |
// Set child0's Text, and set ToolTipBase on child1. |
|
1005 |
QPalette textPalette; |
|
1006 |
textPalette.setColor(QPalette::Text, overridePalText); |
|
1007 |
child0->setPalette(textPalette); |
|
1008 |
QPalette toolTipPalette; |
|
1009 |
toolTipPalette.setColor(QPalette::ToolTipBase, overridePalToolTipBase); |
|
1010 |
child1->setPalette(toolTipPalette); |
|
1011 |
||
1012 |
// Check that the above settings propagate correctly. |
|
1013 |
QCOMPARE(root->palette(), appPal); |
|
1014 |
QCOMPARE(scene.palette(), appPal); |
|
1015 |
QCOMPARE(child0->palette().color(QPalette::Text), overridePalText); |
|
1016 |
QCOMPARE(child0->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); |
|
1017 |
QCOMPARE(child1->palette().color(QPalette::Text), overridePalText); |
|
1018 |
QCOMPARE(child1->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); |
|
1019 |
QCOMPARE(child2->palette().color(QPalette::Text), overridePalText); |
|
1020 |
QCOMPARE(child2->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); |
|
1021 |
||
1022 |
QGraphicsWidget *child3 = new QGraphicsWidget(child2); |
|
1023 |
QCOMPARE(child3->palette().color(QPalette::Text), overridePalText); |
|
1024 |
QCOMPARE(child3->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); |
|
1025 |
||
1026 |
QGraphicsWidget *child4 = new QGraphicsWidget; |
|
1027 |
child4->setParentItem(child3); |
|
1028 |
QCOMPARE(child4->palette().color(QPalette::Text), overridePalText); |
|
1029 |
QCOMPARE(child4->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); |
|
1030 |
||
1031 |
// Replace the app palette for child2. Button should propagate but Text |
|
1032 |
// should still be ignored. The previous ToolTipBase setting is gone. |
|
1033 |
QPalette buttonPalette; |
|
1034 |
buttonPalette.setColor(QPalette::Button, sysPalButton); |
|
1035 |
child1->setPalette(buttonPalette); |
|
1036 |
||
1037 |
QCOMPARE(root->palette(), appPal); |
|
1038 |
QCOMPARE(scene.palette(), appPal); |
|
1039 |
QCOMPARE(child0->palette().color(QPalette::Text), overridePalText); |
|
1040 |
QCOMPARE(child0->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); |
|
1041 |
QCOMPARE(child1->palette().color(QPalette::Text), overridePalText); |
|
1042 |
QCOMPARE(child1->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); |
|
1043 |
QCOMPARE(child1->palette().color(QPalette::Button), sysPalButton); |
|
1044 |
QCOMPARE(child2->palette().color(QPalette::Text), overridePalText); |
|
1045 |
QCOMPARE(child2->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); |
|
1046 |
QCOMPARE(child2->palette().color(QPalette::Button), sysPalButton); |
|
1047 |
} |
|
1048 |
||
1049 |
void tst_QGraphicsWidget::parentWidget_data() |
|
1050 |
{ |
|
1051 |
QTest::addColumn<int>("childrenCount"); |
|
1052 |
QTest::newRow("0") << 0; |
|
1053 |
QTest::newRow("1") << 1; |
|
1054 |
QTest::newRow("10") << 10; |
|
1055 |
} |
|
1056 |
||
1057 |
// QGraphicsWidget* parentWidget() const public |
|
1058 |
void tst_QGraphicsWidget::parentWidget() |
|
1059 |
{ |
|
1060 |
QFETCH(int, childrenCount); |
|
1061 |
SubQGraphicsWidget standAlongWidget; |
|
1062 |
QGraphicsLineItem standAlongItem; |
|
1063 |
||
1064 |
SubQGraphicsWidget widgetChild(&standAlongWidget); |
|
1065 |
SubQGraphicsWidget itemChild(&standAlongItem); |
|
1066 |
||
1067 |
QCOMPARE(standAlongWidget.parentWidget(), (QGraphicsWidget*)0); |
|
1068 |
QCOMPARE(widgetChild.parentWidget(), static_cast<QGraphicsWidget*>(&standAlongWidget)); |
|
1069 |
QCOMPARE(itemChild.parentWidget(), (QGraphicsWidget*)0); |
|
1070 |
||
1071 |
for (int i = 0; i < childrenCount; ++i) { |
|
1072 |
SubQGraphicsWidget *item = new SubQGraphicsWidget(&standAlongWidget); |
|
1073 |
QCOMPARE(item->parentWidget(), static_cast<QGraphicsWidget*>(&standAlongWidget)); |
|
1074 |
} |
|
1075 |
} |
|
1076 |
||
1077 |
void tst_QGraphicsWidget::resize_data() |
|
1078 |
{ |
|
1079 |
QTest::addColumn<QSizeF>("size"); |
|
1080 |
QTest::newRow("null") << QSizeF(); |
|
1081 |
QTest::newRow("10x10") << QSizeF(10, 10); |
|
1082 |
QTest::newRow("10x-1") << QSizeF(10, -1); |
|
1083 |
} |
|
1084 |
||
1085 |
// void resize(qreal w, qreal h) public |
|
1086 |
void tst_QGraphicsWidget::resize() |
|
1087 |
{ |
|
1088 |
QFETCH(QSizeF, size); |
|
1089 |
SubQGraphicsWidget widget; |
|
1090 |
||
1091 |
int oldEventCounts = widget.eventCount; |
|
1092 |
QSizeF oldSize = widget.size(); |
|
1093 |
widget.resize(size); |
|
1094 |
||
1095 |
QSizeF boundedSize = size.expandedTo(widget.minimumSize()).boundedTo(widget.maximumSize()); |
|
1096 |
QCOMPARE(widget.eventCount, oldEventCounts + ((oldSize == boundedSize) ? 0 : 1)); |
|
1097 |
QCOMPARE(widget.size(), boundedSize); |
|
1098 |
} |
|
1099 |
||
1100 |
Q_DECLARE_METATYPE(Qt::WidgetAttribute) |
|
1101 |
void tst_QGraphicsWidget::setAttribute_data() |
|
1102 |
{ |
|
1103 |
QTest::addColumn<Qt::WidgetAttribute>("attribute"); |
|
1104 |
QTest::addColumn<bool>("supported"); |
|
1105 |
QTest::newRow("WA_SetLayoutDirection") << Qt::WA_SetLayoutDirection << true; |
|
1106 |
QTest::newRow("WA_RightToLeft") << Qt::WA_RightToLeft << true; |
|
1107 |
QTest::newRow("WA_SetStyle") << Qt::WA_SetStyle << true; |
|
1108 |
QTest::newRow("WA_Resized") << Qt::WA_Resized << true; |
|
1109 |
QTest::newRow("unsupported") << Qt::WA_PaintOutsidePaintEvent << false; |
|
1110 |
} |
|
1111 |
||
1112 |
// void setAttribute(Qt::WidgetAttribute attribute, bool on = true) public |
|
1113 |
void tst_QGraphicsWidget::setAttribute() |
|
1114 |
{ |
|
1115 |
QFETCH(Qt::WidgetAttribute, attribute); |
|
1116 |
QFETCH(bool, supported); |
|
1117 |
SubQGraphicsWidget widget; |
|
1118 |
if (attribute == Qt::WA_PaintOutsidePaintEvent) |
|
1119 |
QTest::ignoreMessage(QtWarningMsg, "QGraphicsWidget::setAttribute: unsupported attribute 13"); |
|
1120 |
widget.setAttribute(attribute); |
|
1121 |
QCOMPARE(widget.testAttribute(attribute), supported); |
|
1122 |
} |
|
1123 |
||
1124 |
void tst_QGraphicsWidget::setStyle_data() |
|
1125 |
{ |
|
1126 |
QTest::addColumn<QString>("style"); |
|
1127 |
QTest::newRow("null") << ""; |
|
1128 |
QTest::newRow("cleanlooks") << "QCleanlooksStyle"; |
|
1129 |
} |
|
1130 |
||
1131 |
// void setStyle(QStyle* style) public |
|
1132 |
void tst_QGraphicsWidget::setStyle() |
|
1133 |
{ |
|
1134 |
SubQGraphicsWidget widget; |
|
1135 |
QCleanlooksStyle cleanlooksStyle; |
|
1136 |
||
1137 |
int oldEventCounts = widget.eventCount; |
|
1138 |
||
1139 |
QFETCH(QString, style); |
|
1140 |
if (style == "QCleanlooksStyle") { |
|
1141 |
widget.setStyle(&cleanlooksStyle); |
|
1142 |
QCOMPARE(widget.style(), static_cast<QStyle*>(&cleanlooksStyle)); |
|
1143 |
} else { |
|
1144 |
widget.setStyle(0); |
|
1145 |
QVERIFY(widget.style() != (QStyle *)0); |
|
1146 |
} |
|
1147 |
QCOMPARE(widget.eventCount, oldEventCounts + 1); |
|
1148 |
QCOMPARE(widget.testAttribute(Qt::WA_SetStyle), !style.isEmpty()); |
|
1149 |
||
1150 |
// cleanup |
|
1151 |
widget.setStyle(0); |
|
1152 |
} |
|
1153 |
||
1154 |
void tst_QGraphicsWidget::setTabOrder_data() |
|
1155 |
{ |
|
1156 |
QTest::addColumn<int>("childrenCount"); |
|
1157 |
QTest::newRow("0") << 0; |
|
1158 |
QTest::newRow("1") << 1; |
|
1159 |
QTest::newRow("10") << 10; |
|
1160 |
} |
|
1161 |
||
1162 |
// void setTabOrder(QGraphicsWidget* first, QGraphicsWidget* second) public |
|
1163 |
void tst_QGraphicsWidget::setTabOrder() |
|
1164 |
{ |
|
1165 |
QFETCH(int, childrenCount); |
|
1166 |
QGraphicsScene scene; |
|
1167 |
QGraphicsView view(&scene); |
|
1168 |
view.show(); |
|
1169 |
#ifdef Q_WS_X11 |
|
1170 |
qt_x11_wait_for_window_manager(&view); |
|
1171 |
#endif |
|
1172 |
QApplication::setActiveWindow(&view); |
|
1173 |
QTRY_COMPARE(QApplication::activeWindow(), &view); |
|
1174 |
||
1175 |
QGraphicsWidget *lastItem = 0; |
|
1176 |
QTest::ignoreMessage(QtWarningMsg, "QGraphicsWidget::setTabOrder(0, 0) is undefined"); |
|
1177 |
QGraphicsWidget::setTabOrder(0, 0); |
|
1178 |
||
1179 |
QList<SubQGraphicsWidget*> children; |
|
1180 |
for (int i = 0; i < childrenCount; ++i) { |
|
1181 |
SubQGraphicsWidget *item = new SubQGraphicsWidget(); |
|
1182 |
item->setFocusPolicy(Qt::TabFocus); |
|
1183 |
children.append(item); |
|
1184 |
scene.addItem(item); |
|
1185 |
if (lastItem) |
|
1186 |
QGraphicsWidget::setTabOrder(lastItem, item); |
|
1187 |
lastItem = item; |
|
1188 |
} |
|
1189 |
||
1190 |
if (!children.isEmpty()) { |
|
1191 |
QGraphicsWidget *first = children.first(); |
|
1192 |
view.viewport()->setFocus(); |
|
1193 |
QTRY_VERIFY(view.viewport()->hasFocus()); |
|
1194 |
first->setFocus(); |
|
1195 |
QVERIFY(first->hasFocus()); |
|
1196 |
QVERIFY(scene.hasFocus()); |
|
1197 |
QVERIFY(view.viewport()->hasFocus()); |
|
1198 |
||
1199 |
int currentItem = 0; |
|
1200 |
while (currentItem < children.count() - 1) { |
|
1201 |
QTest::keyPress(view.viewport(), Qt::Key_Tab); |
|
1202 |
++currentItem; |
|
1203 |
QVERIFY(children[currentItem % children.size()]->hasFocus()); |
|
1204 |
} |
|
1205 |
} |
|
1206 |
} |
|
1207 |
||
1208 |
static bool compareFocusChain(QGraphicsView *view, const QList<QGraphicsItem*> &order) |
|
1209 |
{ |
|
1210 |
QGraphicsScene *scene = view->scene(); |
|
1211 |
QStringList actual; |
|
1212 |
QGraphicsItem *oldFocusItem = scene->focusItem(); |
|
1213 |
for (int i = 0; i < order.count(); ++i) { |
|
1214 |
QGraphicsItem *focusItem = scene->focusItem(); |
|
1215 |
actual << focusItem->data(0).toString(); |
|
1216 |
//qDebug() << "i:" << i << "expected:" << QString::number(uint(order.at(i)), 16) << QString::number(uint(focusItem), 16); |
|
1217 |
if (focusItem != order.at(i)) { |
|
1218 |
qDebug() << "actual:" << actual; |
|
1219 |
scene->setFocusItem(oldFocusItem); |
|
1220 |
return false; |
|
1221 |
} |
|
1222 |
if (i < order.count() - 1) |
|
1223 |
QTest::keyPress(view, Qt::Key_Tab); |
|
1224 |
} |
|
1225 |
scene->setFocusItem(oldFocusItem); |
|
1226 |
return true; |
|
1227 |
} |
|
1228 |
||
1229 |
void tst_QGraphicsWidget::setTabOrderAndReparent() |
|
1230 |
{ |
|
1231 |
QGraphicsScene scene; |
|
1232 |
QGraphicsView view(&scene); |
|
1233 |
view.show(); |
|
1234 |
QApplication::setActiveWindow(&view); |
|
1235 |
QTest::qWaitForWindowShown(&view); |
|
1236 |
QTRY_COMPARE(QApplication::activeWindow(), &view); |
|
1237 |
||
1238 |
int i; |
|
1239 |
QGraphicsWidget *w1, *w2, *w3, *w4; |
|
1240 |
for (i = 1; i < 4; ++i) { |
|
1241 |
QGraphicsWidget *wid = new QGraphicsWidget; |
|
1242 |
wid->setFocusPolicy(Qt::StrongFocus); |
|
1243 |
wid->setData(0, QString::fromAscii("w%1").arg(i)); |
|
1244 |
scene.addItem(wid); |
|
1245 |
if (i == 1) |
|
1246 |
w1 = wid; |
|
1247 |
else if (i == 2) |
|
1248 |
w2 = wid; |
|
1249 |
else if (i == 3) |
|
1250 |
w3 = wid; |
|
1251 |
} |
|
1252 |
||
1253 |
w1->setFocus(); |
|
1254 |
QTRY_VERIFY(w1->hasFocus()); |
|
1255 |
QVERIFY(compareFocusChain(&view, QList<QGraphicsItem*>() << w1 << w2 << w3)); |
|
1256 |
||
1257 |
QGraphicsWidget *p = new QGraphicsWidget; |
|
1258 |
p->setData(0, QLatin1String("parent")); |
|
1259 |
p->setFocusPolicy(Qt::StrongFocus); |
|
1260 |
||
1261 |
w1->setFocus(); |
|
1262 |
QVERIFY(compareFocusChain(&view, QList<QGraphicsItem*>() << w1 << w2 << w3)); |
|
1263 |
||
1264 |
w1->setParentItem(p); |
|
1265 |
w2->setFocus(); |
|
1266 |
QVERIFY(compareFocusChain(&view, QList<QGraphicsItem*>() << w2 << w3)); |
|
1267 |
||
1268 |
w2->setParentItem(p); |
|
1269 |
w3->setFocus(); |
|
1270 |
QVERIFY(compareFocusChain(&view, QList<QGraphicsItem*>() << w3)); |
|
1271 |
w3->setParentItem(p); |
|
1272 |
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem*>(0)); |
|
1273 |
||
1274 |
scene.addItem(p); |
|
1275 |
p->setFocus(); |
|
1276 |
||
1277 |
QVERIFY(compareFocusChain(&view, QList<QGraphicsItem*>() << p << w1 << w2 << w3)); |
|
1278 |
delete p; |
|
1279 |
||
1280 |
for (i = 1; i < 5; ++i) { |
|
1281 |
QGraphicsWidget *wid = new QGraphicsWidget; |
|
1282 |
wid->setFocusPolicy(Qt::StrongFocus); |
|
1283 |
wid->setData(0, QString::fromAscii("w%1").arg(i)); |
|
1284 |
scene.addItem(wid); |
|
1285 |
if (i == 1) |
|
1286 |
w1 = wid; |
|
1287 |
else if (i == 2) |
|
1288 |
w2 = wid; |
|
1289 |
else if (i == 3) |
|
1290 |
w3 = wid; |
|
1291 |
else if (i == 4) |
|
1292 |
w4 = wid; |
|
1293 |
} |
|
1294 |
w4->setParentItem(w1); |
|
1295 |
QGraphicsWidget::setTabOrder(w1, w4); |
|
1296 |
w1->setFocus(); |
|
1297 |
QVERIFY(compareFocusChain(&view, QList<QGraphicsItem*>() << w1 << w4 << w2 << w3)); |
|
1298 |
||
1299 |
p = new QGraphicsWidget; |
|
1300 |
p->setData(0, QLatin1String("parent")); |
|
1301 |
p->setFocusPolicy(Qt::StrongFocus); |
|
1302 |
||
1303 |
w1->setParentItem(p); |
|
1304 |
w2->setFocus(); |
|
1305 |
QVERIFY(compareFocusChain(&view, QList<QGraphicsItem*>() << w2 << w3)); |
|
1306 |
||
1307 |
scene.addItem(p); |
|
1308 |
w2->setFocus(); |
|
1309 |
QVERIFY(compareFocusChain(&view, QList<QGraphicsItem*>() << w2 << w3 << p << w1 << w4)); |
|
1310 |
} |
|
1311 |
||
1312 |
void tst_QGraphicsWidget::topLevelWidget_data() |
|
1313 |
{ |
|
1314 |
QTest::addColumn<QString>("str"); |
|
1315 |
QTest::newRow("test one") << "foo"; |
|
1316 |
} |
|
1317 |
||
1318 |
// QGraphicsWidget* topLevelWidget() const public |
|
1319 |
void tst_QGraphicsWidget::topLevelWidget() |
|
1320 |
{ |
|
1321 |
QFETCH(QString, str); |
|
1322 |
SubQGraphicsWidget widget; |
|
1323 |
QCOMPARE(widget.topLevelWidget(), (QGraphicsWidget *)&widget); |
|
1324 |
} |
|
1325 |
||
1326 |
void tst_QGraphicsWidget::unsetLayoutDirection_data() |
|
1327 |
{ |
|
1328 |
QTest::addColumn<Qt::LayoutDirection>("layoutDirection"); |
|
1329 |
QTest::newRow("rtl") << Qt::RightToLeft; |
|
1330 |
QTest::newRow("ltr") << Qt::LeftToRight; |
|
1331 |
} |
|
1332 |
||
1333 |
// void unsetLayoutDirection() public |
|
1334 |
void tst_QGraphicsWidget::unsetLayoutDirection() |
|
1335 |
{ |
|
1336 |
QApplication::setLayoutDirection(Qt::LeftToRight); |
|
1337 |
QFETCH(Qt::LayoutDirection, layoutDirection); |
|
1338 |
SubQGraphicsWidget widget; |
|
1339 |
QCOMPARE(Qt::LeftToRight, widget.layoutDirection()); |
|
1340 |
||
1341 |
QList<SubQGraphicsWidget*> children; |
|
1342 |
for (int i = 0; i < 10; ++i) { |
|
1343 |
SubQGraphicsWidget *item = new SubQGraphicsWidget(&widget); |
|
1344 |
children.append(item); |
|
1345 |
} |
|
1346 |
widget.setLayoutDirection(layoutDirection); |
|
1347 |
widget.unsetLayoutDirection(); |
|
1348 |
QCOMPARE(widget.testAttribute(Qt::WA_SetLayoutDirection), false); |
|
1349 |
for (int i = 0; i < children.count(); ++i) { |
|
1350 |
QCOMPARE(children[i]->layoutDirection(), Qt::LeftToRight); |
|
1351 |
} |
|
1352 |
} |
|
1353 |
||
1354 |
void tst_QGraphicsWidget::focusNextPrevChild_data() |
|
1355 |
{ |
|
1356 |
QTest::addColumn<QString>("str"); |
|
1357 |
QTest::newRow("test one") << "foo"; |
|
1358 |
} |
|
1359 |
||
1360 |
// bool focusNextPrevChild(bool next) protected |
|
1361 |
void tst_QGraphicsWidget::focusNextPrevChild() |
|
1362 |
{ |
|
1363 |
QFETCH(QString, str); |
|
1364 |
SubQGraphicsWidget widget; |
|
1365 |
// ### write test after just calling it stops crashing :) |
|
1366 |
widget.call_focusNextPrevChild(true); |
|
1367 |
} |
|
1368 |
||
1369 |
void tst_QGraphicsWidget::verifyFocusChain() |
|
1370 |
{ |
|
1371 |
QGraphicsScene scene; |
|
1372 |
QGraphicsView view(&scene); |
|
1373 |
view.show(); |
|
1374 |
QApplication::setActiveWindow(&view); |
|
1375 |
QTest::qWaitForWindowShown(&view); |
|
1376 |
QTRY_COMPARE(QApplication::activeWindow(), &view); |
|
1377 |
||
1378 |
{ |
|
1379 |
// parent/child focus |
|
1380 |
SubQGraphicsWidget *w = new SubQGraphicsWidget(0, Qt::Window); |
|
1381 |
w->setFocusPolicy(Qt::StrongFocus); |
|
1382 |
SubQGraphicsWidget *w1_1 = new SubQGraphicsWidget(w); |
|
1383 |
w1_1->setFocusPolicy(Qt::StrongFocus); |
|
1384 |
scene.addItem(w); |
|
1385 |
w->setFocus(); |
|
1386 |
QVERIFY(w->hasFocus()); |
|
1387 |
w->call_focusNextPrevChild(true); |
|
1388 |
QVERIFY(w1_1->hasFocus()); |
|
1389 |
delete w; |
|
1390 |
} |
|
1391 |
||
1392 |
{ |
|
1393 |
// delete item in focus chain and verify chain |
|
1394 |
SubQGraphicsWidget *w = new SubQGraphicsWidget(0, Qt::Window); |
|
1395 |
SubQGraphicsWidget *w1_1 = new SubQGraphicsWidget(w); |
|
1396 |
SubQGraphicsWidget *w1_2 = new SubQGraphicsWidget(w); |
|
1397 |
SubQGraphicsWidget *w1_3 = new SubQGraphicsWidget(w); |
|
1398 |
w1_1->setFocusPolicy(Qt::StrongFocus); |
|
1399 |
w1_2->setFocusPolicy(Qt::StrongFocus); |
|
1400 |
w1_3->setFocusPolicy(Qt::StrongFocus); |
|
1401 |
scene.addItem(w); |
|
1402 |
w1_1->setFocus(); |
|
1403 |
QVERIFY(w1_1->hasFocus()); |
|
1404 |
QCOMPARE(w->call_focusNextPrevChild(true), true); |
|
1405 |
QVERIFY(w1_2->hasFocus()); |
|
1406 |
QCOMPARE(w->call_focusNextPrevChild(true), true); |
|
1407 |
QVERIFY(w1_3->hasFocus()); |
|
1408 |
w1_1->setFocus(); |
|
1409 |
delete w1_2; |
|
1410 |
w->call_focusNextPrevChild(true); |
|
1411 |
QVERIFY(w1_3->hasFocus()); |
|
1412 |
delete w; |
|
1413 |
} |
|
1414 |
{ |
|
1415 |
// parent/child focus |
|
1416 |
SubQGraphicsWidget *w = new SubQGraphicsWidget(0, Qt::Window); |
|
1417 |
w->setFocusPolicy(Qt::StrongFocus); |
|
1418 |
SubQGraphicsWidget *w1_1 = new SubQGraphicsWidget(w); |
|
1419 |
w1_1->setFocusPolicy(Qt::StrongFocus); |
|
1420 |
scene.addItem(w); |
|
1421 |
w->setFocus(); |
|
1422 |
QVERIFY(w->hasFocus()); |
|
1423 |
w->call_focusNextPrevChild(true); |
|
1424 |
QVERIFY(w1_1->hasFocus()); |
|
1425 |
delete w; |
|
1426 |
} |
|
1427 |
{ |
|
1428 |
// remove the tabFocusFirst widget from the scene. |
|
1429 |
QWidget *window = new QWidget; |
|
1430 |
QVBoxLayout *layout = new QVBoxLayout; |
|
1431 |
window->setLayout(layout); |
|
1432 |
QLineEdit *lineEdit = new QLineEdit; |
|
1433 |
layout->addWidget(lineEdit); |
|
1434 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
1435 |
scene.setSceneRect(-20, -20, 200, 50); |
|
1436 |
layout->addWidget(view); |
|
1437 |
view->setMinimumSize(150, 50); |
|
1438 |
SubQGraphicsWidget *w1_1 = new SubQGraphicsWidget; |
|
1439 |
w1_1->setData(0, "w1_1"); |
|
1440 |
w1_1->setGeometry(0,0,25, 25); |
|
1441 |
w1_1->setFocusPolicy(Qt::StrongFocus); |
|
1442 |
scene.addItem(w1_1); |
|
1443 |
SubQGraphicsWidget *w1_2 = new SubQGraphicsWidget; |
|
1444 |
w1_2->setData(0, "w1_2"); |
|
1445 |
w1_2->setGeometry(25,0,25, 25); |
|
1446 |
w1_2->setFocusPolicy(Qt::StrongFocus); |
|
1447 |
scene.addItem(w1_2); |
|
1448 |
window->show(); |
|
1449 |
QApplication::setActiveWindow(window); |
|
1450 |
QTest::qWaitForWindowShown(window); |
|
1451 |
||
1452 |
lineEdit->setFocus(); |
|
1453 |
QTRY_VERIFY(lineEdit->hasFocus()); |
|
1454 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
1455 |
QTRY_VERIFY(w1_1->hasFocus()); |
|
1456 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
1457 |
QTRY_VERIFY(w1_2->hasFocus()); |
|
1458 |
||
1459 |
// remove the tabFocusFirst and insert new item |
|
1460 |
delete w1_1; // calls _q_removeItemLater |
|
1461 |
SubQGraphicsWidget *w1_3 = new SubQGraphicsWidget; |
|
1462 |
w1_3->setFocusPolicy(Qt::StrongFocus); |
|
1463 |
w1_3->setData(0, "w1_3"); |
|
1464 |
w1_3->setGeometry(50,0,25, 25); |
|
1465 |
scene.addItem(w1_3); |
|
1466 |
QTRY_VERIFY(w1_2->hasFocus()); |
|
1467 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
1468 |
QTRY_VERIFY(lineEdit->hasFocus()); |
|
1469 |
// tabFocusFirst should now point to w1_2 |
|
1470 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
1471 |
QTRY_VERIFY(w1_2->hasFocus()); |
|
1472 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
1473 |
QTRY_VERIFY(w1_3->hasFocus()); |
|
1474 |
scene.removeItem(w1_2); // does not call _q_removeItemLater |
|
1475 |
delete w1_2; // calls _q_removeItemLater |
|
1476 |
||
1477 |
SubQGraphicsWidget *w1_4 = new SubQGraphicsWidget; |
|
1478 |
w1_4->setFocusPolicy(Qt::StrongFocus); |
|
1479 |
w1_4->setData(0, "w1_4"); |
|
1480 |
w1_4->setGeometry(75,0,25, 25); |
|
1481 |
scene.addItem(w1_4); |
|
1482 |
QTRY_VERIFY(w1_3->hasFocus()); |
|
1483 |
QTRY_VERIFY(compareFocusChain(view, QList<QGraphicsItem*>() << w1_3 << w1_4)); |
|
1484 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
1485 |
QTRY_VERIFY(lineEdit->hasFocus()); |
|
1486 |
// tabFocusFirst should now point to w1_3 |
|
1487 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
1488 |
QTRY_VERIFY(w1_3->hasFocus()); |
|
1489 |
QTRY_VERIFY(compareFocusChain(view, QList<QGraphicsItem*>() << w1_3 << w1_4)); |
|
1490 |
delete window; |
|
1491 |
} |
|
1492 |
} |
|
1493 |
||
1494 |
void tst_QGraphicsWidget::updateFocusChainWhenChildDie() |
|
1495 |
{ |
|
1496 |
QGraphicsScene scene; |
|
1497 |
QGraphicsView view(&scene); |
|
1498 |
view.show(); |
|
1499 |
#ifdef Q_WS_X11 |
|
1500 |
qt_x11_wait_for_window_manager(&view); |
|
1501 |
#endif |
|
1502 |
QApplication::setActiveWindow(&view); |
|
1503 |
QTRY_COMPARE(QApplication::activeWindow(), &view); |
|
1504 |
||
1505 |
// delete item in focus chain with no focus and verify chain |
|
1506 |
SubQGraphicsWidget *parent = new SubQGraphicsWidget(0, Qt::Window); |
|
1507 |
SubQGraphicsWidget *w = new SubQGraphicsWidget(0, Qt::Window); |
|
1508 |
w->resize(50,50); |
|
1509 |
w->resize(100,100); |
|
1510 |
SubQGraphicsWidget *w1_1 = new SubQGraphicsWidget(w); |
|
1511 |
w1_1->setFocusPolicy(Qt::StrongFocus); |
|
1512 |
w->setFocusPolicy(Qt::StrongFocus); |
|
1513 |
scene.addItem(w); |
|
1514 |
scene.addItem(parent); |
|
1515 |
w1_1->setFocus(); |
|
1516 |
||
1517 |
QVERIFY(w1_1->hasFocus()); |
|
1518 |
QWidget myWidget(0); |
|
1519 |
QLineEdit edit(&myWidget); |
|
1520 |
myWidget.show(); |
|
1521 |
edit.setFocus(); |
|
1522 |
QTRY_VERIFY(edit.hasFocus()); |
|
1523 |
delete w1_1; |
|
1524 |
myWidget.hide(); |
|
1525 |
w->setParentItem(parent); |
|
1526 |
//We don't crash perfect |
|
1527 |
QVERIFY(w); |
|
1528 |
QTest::mouseMove(view.viewport()); |
|
1529 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0); |
|
1530 |
QTRY_COMPARE(qApp->activeWindow(), static_cast<QWidget *>(&view)); |
|
1531 |
QTRY_COMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(w)); |
|
1532 |
} |
|
1533 |
||
1534 |
void tst_QGraphicsWidget::sizeHint_data() |
|
1535 |
{ |
|
1536 |
QTest::addColumn<bool>("layout"); |
|
1537 |
QTest::newRow("no layout") << false; |
|
1538 |
QTest::newRow("layout") << true; |
|
1539 |
} |
|
1540 |
||
1541 |
// QSizeF sizeHint(Qt::SizeHint which, QSizeF const& constraint = QSizeF()) const protected |
|
1542 |
void tst_QGraphicsWidget::sizeHint() |
|
1543 |
{ |
|
1544 |
QFETCH(bool, layout); |
|
1545 |
SubQGraphicsWidget widget; |
|
1546 |
||
1547 |
if (layout) { |
|
1548 |
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout; |
|
1549 |
widget.setLayout(layout); |
|
1550 |
} |
|
1551 |
widget.call_sizeHint(Qt::MinimumSize, QSizeF()); |
|
1552 |
} |
|
1553 |
||
1554 |
void tst_QGraphicsWidget::consistentPosSizeGeometry_data() |
|
1555 |
{ |
|
1556 |
QTest::addColumn<QSizeF>("minSize"); |
|
1557 |
QTest::addColumn<QSizeF>("maxSize"); |
|
1558 |
QTest::addColumn<QRectF>("geometry"); |
|
1559 |
QTest::addColumn<QRectF>("expectedGeometry"); |
|
1560 |
||
1561 |
QTest::newRow("size is valid") << QSizeF(0, 0) << QSizeF(200, 200) << QRectF(0, 0, 100, 100) << QRectF(0, 0, 100, 100); |
|
1562 |
QTest::newRow("size is larger than max") << QSizeF(0, 0) << QSizeF(50, 50) << QRectF(0, 0, 100, 100) << QRectF(0, 0, 50, 50); |
|
1563 |
QTest::newRow("size is smaller than min") << QSizeF(50, 50) << QSizeF(150, 150) << QRectF(0, 0, 10, 10) << QRectF(0, 0, 50, 50); |
|
1564 |
} |
|
1565 |
||
1566 |
void tst_QGraphicsWidget::consistentPosSizeGeometry() |
|
1567 |
{ |
|
1568 |
QFETCH(QSizeF, minSize); |
|
1569 |
QFETCH(QSizeF, maxSize); |
|
1570 |
QFETCH(QRectF, geometry); |
|
1571 |
QFETCH(QRectF, expectedGeometry); |
|
1572 |
||
1573 |
QGraphicsScene scene; |
|
1574 |
QGraphicsView view(&scene); |
|
1575 |
QGraphicsWidget *w = new QGraphicsWidget; |
|
1576 |
scene.addItem(w); |
|
1577 |
w->setMinimumSize(minSize); |
|
1578 |
w->setMaximumSize(maxSize); |
|
1579 |
w->setGeometry(geometry); |
|
1580 |
QCOMPARE(w->geometry(), expectedGeometry); |
|
1581 |
QCOMPARE(w->pos(), expectedGeometry.topLeft()); |
|
1582 |
QCOMPARE(w->size(), expectedGeometry.size()); |
|
1583 |
||
1584 |
QRectF otherGeom = QRectF(QPointF(12.34,12.34), minSize); |
|
1585 |
w->setGeometry(otherGeom); |
|
1586 |
QCOMPARE(w->geometry(), otherGeom); |
|
1587 |
QCOMPARE(w->pos(), otherGeom.topLeft()); |
|
1588 |
QCOMPARE(w->size(), otherGeom.size()); |
|
1589 |
||
1590 |
w->setPos(geometry.topLeft()); |
|
1591 |
QCOMPARE(w->geometry().topLeft(), expectedGeometry.topLeft()); |
|
1592 |
QCOMPARE(w->pos(), expectedGeometry.topLeft()); |
|
1593 |
||
1594 |
w->resize(geometry.size()); |
|
1595 |
QCOMPARE(w->geometry().size(), expectedGeometry.size()); |
|
1596 |
QCOMPARE(w->geometry(), expectedGeometry); |
|
1597 |
||
1598 |
view.show(); |
|
1599 |
||
1600 |
} |
|
1601 |
||
1602 |
||
1603 |
enum WhichSize { |
|
1604 |
MinimumWidth, |
|
1605 |
PreferredWidth, |
|
1606 |
MaximumWidth, |
|
1607 |
MinimumHeight, |
|
1608 |
PreferredHeight, |
|
1609 |
MaximumHeight, |
|
1610 |
MinimumSize, |
|
1611 |
PreferredSize, |
|
1612 |
MaximumSize, |
|
1613 |
MinimumSizeHint, |
|
1614 |
PreferredSizeHint, |
|
1615 |
MaximumSizeHint, |
|
1616 |
Size, |
|
1617 |
None, |
|
1618 |
}; |
|
1619 |
||
1620 |
typedef QPair<int, QVariant> Inst; |
|
1621 |
||
1622 |
Q_DECLARE_METATYPE(Inst) |
|
1623 |
Q_DECLARE_METATYPE(QVector<Inst>) |
|
1624 |
||
1625 |
void tst_QGraphicsWidget::setSizes_data() |
|
1626 |
{ |
|
1627 |
||
1628 |
QTest::addColumn<QVector<Inst> >("inputInstructions"); |
|
1629 |
QTest::addColumn<QVector<Inst> >("compareInstructions"); |
|
1630 |
||
1631 |
QTest::newRow("minSize1") << (QVector<Inst>() << Inst(Size, QSize(25, 25)) << Inst(MinimumSize, QSize(10, 10))) |
|
1632 |
<< (QVector<Inst>() << Inst(Size, QSize(25,25))); |
|
1633 |
QTest::newRow("minSize2") << (QVector<Inst>() << Inst(Size, QSizeF(20, 20)) << Inst(MinimumSize, QSizeF(25, 25))) |
|
1634 |
<< (QVector<Inst>() << Inst(Size, QSizeF(25, 25))); |
|
1635 |
QTest::newRow("minWidth1") << (QVector<Inst>() << Inst(Size, QSizeF(20, 20)) << Inst(MinimumWidth, 5.0)) |
|
1636 |
<< (QVector<Inst>() << Inst(Size, QSizeF(20, 20))); |
|
1637 |
QTest::newRow("minWidth2") << (QVector<Inst>() << Inst(Size, QSizeF(20, 20)) << Inst(MinimumWidth, 25.0)) |
|
1638 |
<< (QVector<Inst>() << Inst(Size, QSizeF(25, 20))); |
|
1639 |
QTest::newRow("minHeight1") << (QVector<Inst>() << Inst(Size, QSizeF(20, 20)) << Inst(MinimumHeight, 5.0)) |
|
1640 |
<< (QVector<Inst>() << Inst(Size, QSizeF(20, 20))); |
|
1641 |
QTest::newRow("minHeight2") << (QVector<Inst>() << Inst(Size, QSizeF(20, 20)) << Inst(MinimumHeight, 25.0)) |
|
1642 |
<< (QVector<Inst>() << Inst(Size, QSizeF(20, 25))); |
|
1643 |
QTest::newRow("maxSize1") << (QVector<Inst>() << Inst(Size, QSizeF(40, 40)) << Inst(MaximumSize, QSizeF(30, 30))) |
|
1644 |
<< (QVector<Inst>() << Inst(Size, QSizeF(30, 30))); |
|
1645 |
QTest::newRow("maxSize2") << (QVector<Inst>() << Inst(Size, QSizeF(40, 40)) << Inst(MaximumSize, QSizeF(30, -1))) |
|
1646 |
<< (QVector<Inst>() << Inst(Size, QSizeF(30, 40))); |
|
1647 |
QTest::newRow("maxSize3") << (QVector<Inst>() << Inst(Size, QSizeF(40, 40)) << Inst(MaximumSize, QSizeF(-1, 30))) |
|
1648 |
<< (QVector<Inst>() << Inst(Size, QSizeF(40, 30))); |
|
1649 |
QTest::newRow("maxWidth1")<< (QVector<Inst>() << Inst(Size, QSizeF(40, 40)) << Inst(MaximumWidth, 30)) |
|
1650 |
<< (QVector<Inst>() << Inst(Size, QSizeF(30, 40))); |
|
1651 |
QTest::newRow("maxHeight")<< (QVector<Inst>() << Inst(Size, QSizeF(40, 40)) << Inst(MaximumHeight, 20)) |
|
1652 |
<< (QVector<Inst>() << Inst(Size, QSizeF(40, 20))); |
|
1653 |
QTest::newRow("unsetMinSize")<< (QVector<Inst>() << Inst(Size, QSizeF(40, 40)) << Inst(MinimumSize, QSizeF(-1, -1))) |
|
1654 |
<< (QVector<Inst>() << Inst(MinimumSize, QSizeF(5, 5))); |
|
1655 |
QTest::newRow("unsetMaxSize")<< (QVector<Inst>() << Inst(Size, QSizeF(40, 40)) << Inst(MaximumSize, QSizeF(-1, -1))) |
|
1656 |
<< (QVector<Inst>() << Inst(MaximumSize, QSizeF(500, 500))); |
|
1657 |
QTest::newRow("unsetMinSize, expand size to minimumSizeHint") << (QVector<Inst>() |
|
1658 |
<< Inst(MinimumSize, QSize(0, 0)) |
|
1659 |
<< Inst(Size, QSize(1,1)) |
|
1660 |
<< Inst(MinimumSize, QSize(-1.0, -1.0)) |
|
1661 |
) |
|
1662 |
<< (QVector<Inst>() |
|
1663 |
<< Inst(Size, QSize(5,5)) |
|
1664 |
<< Inst(MinimumSize, QSize(5,5)) |
|
1665 |
); |
|
1666 |
||
1667 |
} |
|
1668 |
||
1669 |
void tst_QGraphicsWidget::setSizes() |
|
1670 |
{ |
|
1671 |
QFETCH(QVector<Inst>, inputInstructions); |
|
1672 |
QFETCH(QVector<Inst>, compareInstructions); |
|
1673 |
||
1674 |
QGraphicsScene scene; |
|
1675 |
QGraphicsView view(&scene); |
|
1676 |
SizeHinter *widget = new SizeHinter(0, Qt::Window); |
|
1677 |
QSizeF min = QSizeF(10, 10); |
|
1678 |
QSizeF pref = QSizeF(25, 25); |
|
1679 |
QSizeF max = QSizeF(50, 50); |
|
1680 |
||
1681 |
int i; |
|
1682 |
for (i = 0; i < inputInstructions.count(); ++i) { |
|
1683 |
Inst input = inputInstructions.at(i); |
|
1684 |
||
1685 |
// defaults |
|
1686 |
switch (input.first) { |
|
1687 |
case MinimumSize: |
|
1688 |
min = input.second.toSizeF(); |
|
1689 |
break; |
|
1690 |
case PreferredSize: |
|
1691 |
pref = input.second.toSizeF(); |
|
1692 |
break; |
|
1693 |
case MaximumSize: |
|
1694 |
max = input.second.toSizeF(); |
|
1695 |
break; |
|
1696 |
case Size: |
|
1697 |
widget->resize(input.second.toSizeF()); |
|
1698 |
break; |
|
1699 |
case MinimumWidth: |
|
1700 |
widget->setMinimumWidth(qreal(input.second.toDouble())); |
|
1701 |
break; |
|
1702 |
case PreferredWidth: |
|
1703 |
widget->setPreferredWidth(qreal(input.second.toDouble())); |
|
1704 |
break; |
|
1705 |
case MaximumWidth: |
|
1706 |
widget->setMaximumWidth(qreal(input.second.toDouble())); |
|
1707 |
break; |
|
1708 |
case MinimumHeight: |
|
1709 |
widget->setMinimumHeight(qreal(input.second.toDouble())); |
|
1710 |
break; |
|
1711 |
case PreferredHeight: |
|
1712 |
widget->setPreferredHeight(qreal(input.second.toDouble())); |
|
1713 |
break; |
|
1714 |
case MaximumHeight: |
|
1715 |
widget->setMaximumHeight(qreal(input.second.toDouble())); |
|
1716 |
break; |
|
1717 |
case MinimumSizeHint: |
|
1718 |
widget->setSizeHint(Qt::MinimumSize, input.second.toSizeF()); |
|
1719 |
break; |
|
1720 |
case PreferredSizeHint: |
|
1721 |
widget->setSizeHint(Qt::PreferredSize, input.second.toSizeF()); |
|
1722 |
break; |
|
1723 |
case MaximumSizeHint: |
|
1724 |
widget->setSizeHint(Qt::MaximumSize, input.second.toSizeF()); |
|
1725 |
break; |
|
1726 |
default: |
|
1727 |
qWarning("instruction not implemented"); |
|
1728 |
break; |
|
1729 |
} |
|
1730 |
} |
|
1731 |
||
1732 |
widget->setMinimumSize(min); |
|
1733 |
widget->setPreferredSize(pref); |
|
1734 |
widget->setMaximumSize(max); |
|
1735 |
||
1736 |
for (i = 0; i < compareInstructions.count(); ++i) { |
|
1737 |
Inst input = compareInstructions.at(i); |
|
1738 |
switch (input.first) { |
|
1739 |
case MinimumSize: |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1740 |
QTRY_COMPARE(widget->minimumSize(), input.second.toSizeF()); |
0 | 1741 |
break; |
1742 |
case PreferredSize: |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1743 |
QTRY_COMPARE(widget->preferredSize(), input.second.toSizeF()); |
0 | 1744 |
break; |
1745 |
case MaximumSize: |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1746 |
QTRY_COMPARE(widget->maximumSize(), input.second.toSizeF()); |
0 | 1747 |
break; |
1748 |
case Size: |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1749 |
QTRY_COMPARE(widget->size(), input.second.toSizeF()); |
0 | 1750 |
break; |
1751 |
case MinimumWidth: |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1752 |
QTRY_COMPARE(widget->minimumWidth(), qreal(input.second.toDouble())); |
0 | 1753 |
break; |
1754 |
case PreferredWidth: |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1755 |
QTRY_COMPARE(widget->preferredWidth(), qreal(input.second.toDouble())); |
0 | 1756 |
break; |
1757 |
case MaximumWidth: |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1758 |
QTRY_COMPARE(widget->maximumWidth(), qreal(input.second.toDouble())); |
0 | 1759 |
break; |
1760 |
default: |
|
1761 |
qWarning("instruction not implemented"); |
|
1762 |
break; |
|
1763 |
} |
|
1764 |
} |
|
1765 |
delete widget; |
|
1766 |
} |
|
1767 |
||
1768 |
void tst_QGraphicsWidget::closePopupOnOutsideClick() |
|
1769 |
{ |
|
1770 |
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Popup); |
|
1771 |
widget->resize(100, 100); |
|
1772 |
||
1773 |
QGraphicsScene scene; |
|
1774 |
scene.addItem(widget); |
|
1775 |
||
1776 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
1777 |
event.ignore(); |
|
1778 |
event.setScenePos(QPointF(50, 50)); |
|
1779 |
qApp->sendEvent(&scene, &event); |
|
1780 |
||
1781 |
QVERIFY(widget->isVisible()); |
|
1782 |
QVERIFY(event.isAccepted()); |
|
1783 |
||
1784 |
event.ignore(); |
|
1785 |
event.setScenePos(QPointF(150, 150)); |
|
1786 |
qApp->sendEvent(&scene, &event); |
|
1787 |
||
1788 |
QVERIFY(!widget->isVisible()); |
|
1789 |
QVERIFY(event.isAccepted()); |
|
1790 |
} |
|
1791 |
||
1792 |
void tst_QGraphicsWidget::task236127_bspTreeIndexFails() |
|
1793 |
{ |
|
1794 |
QGraphicsWidget *widget = new QGraphicsWidget; |
|
1795 |
QGraphicsWidget *widget2 = new QGraphicsWidget; |
|
1796 |
widget->resize(10, 10); |
|
1797 |
widget2->resize(10, 10); |
|
1798 |
widget2->setZValue(1); |
|
1799 |
QCOMPARE(widget2->zValue(), qreal(1)); |
|
1800 |
QCOMPARE(widget->zValue(), qreal(0)); |
|
1801 |
widget->setData(0, "widget"); |
|
1802 |
widget2->setData(0, "widget2"); |
|
1803 |
||
1804 |
QGraphicsScene scene; |
|
1805 |
scene.addItem(widget); |
|
1806 |
scene.addItem(widget2); |
|
1807 |
||
1808 |
QGraphicsView view(&scene); |
|
1809 |
view.show(); |
|
1810 |
#ifdef Q_WS_X11 |
|
1811 |
qt_x11_wait_for_window_manager(&view); |
|
1812 |
#endif |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1813 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1814 |
QTRY_VERIFY(!scene.itemAt(25, 25)); |
0 | 1815 |
widget->setGeometry(0, 112, 360, 528); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1816 |
QTRY_COMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget); |
0 | 1817 |
widget2->setGeometry(0, 573, 360, 67); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1818 |
QTRY_COMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1819 |
QTRY_COMPARE(scene.itemAt(50, 585), (QGraphicsItem *)widget2); |
0 | 1820 |
} |
1821 |
||
1822 |
void tst_QGraphicsWidget::defaultSize() |
|
1823 |
{ |
|
1824 |
SubQGraphicsWidget *widget = new SubQGraphicsWidget; |
|
1825 |
widget->setMinimumSize(40, 40); |
|
1826 |
QGraphicsScene scene; |
|
1827 |
scene.addItem(widget); |
|
1828 |
||
1829 |
QGraphicsView view(&scene); |
|
1830 |
view.show(); |
|
1831 |
#ifdef Q_WS_X11 |
|
1832 |
qt_x11_wait_for_window_manager(&view); |
|
1833 |
#endif |
|
1834 |
QSizeF initialSize = widget->size(); |
|
1835 |
||
1836 |
widget->resize(initialSize); |
|
1837 |
QCOMPARE(widget->geometry().size(), initialSize); |
|
1838 |
widget->setVisible(false); |
|
1839 |
widget->setMinimumSize(10, 10); |
|
1840 |
widget->setPreferredSize(60, 60); |
|
1841 |
widget->setMaximumSize(110, 110); |
|
1842 |
widget->setVisible(true); |
|
1843 |
// should still have its size set to initialsize |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1844 |
QTRY_COMPARE(widget->geometry().size(), initialSize); |
0 | 1845 |
|
1846 |
} |
|
1847 |
||
1848 |
void tst_QGraphicsWidget::explicitMouseGrabber() |
|
1849 |
{ |
|
1850 |
QGraphicsWidget *widget = new QGraphicsWidget; |
|
1851 |
EventSpy widgetGrabEventSpy(widget, QEvent::GrabMouse); |
|
1852 |
EventSpy widgetUngrabEventSpy(widget, QEvent::UngrabMouse); |
|
1853 |
||
1854 |
// Grab without scene |
|
1855 |
QTest::ignoreMessage(QtWarningMsg, "QGraphicsItem::grabMouse: cannot grab mouse without scene"); |
|
1856 |
widget->grabMouse(); |
|
1857 |
QCOMPARE(widgetGrabEventSpy.count(), 0); |
|
1858 |
QTest::ignoreMessage(QtWarningMsg, "QGraphicsItem::ungrabMouse: cannot ungrab mouse without scene"); |
|
1859 |
widget->ungrabMouse(); |
|
1860 |
QCOMPARE(widgetUngrabEventSpy.count(), 0); |
|
1861 |
||
1862 |
// Add to scene |
|
1863 |
QGraphicsScene scene; |
|
1864 |
scene.addItem(widget); |
|
1865 |
||
1866 |
// Ungrab while not grabber |
|
1867 |
QTest::ignoreMessage(QtWarningMsg, "QGraphicsItem::ungrabMouse: not a mouse grabber"); |
|
1868 |
widget->ungrabMouse(); |
|
1869 |
||
1870 |
// Simple grab with scene |
|
1871 |
QVERIFY(!scene.mouseGrabberItem()); |
|
1872 |
widget->grabMouse(); |
|
1873 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget); |
|
1874 |
QCOMPARE(widgetGrabEventSpy.count(), 1); |
|
1875 |
widget->ungrabMouse(); |
|
1876 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
1877 |
QCOMPARE(widgetUngrabEventSpy.count(), 1); |
|
1878 |
||
1879 |
// Grab while grabbing |
|
1880 |
widget->grabMouse(); |
|
1881 |
QCOMPARE(widgetGrabEventSpy.count(), 2); |
|
1882 |
QTest::ignoreMessage(QtWarningMsg, "QGraphicsItem::grabMouse: already a mouse grabber"); |
|
1883 |
widget->grabMouse(); |
|
1884 |
QCOMPARE(widgetGrabEventSpy.count(), 2); |
|
1885 |
QCOMPARE(widgetUngrabEventSpy.count(), 1); |
|
1886 |
widget->ungrabMouse(); |
|
1887 |
QCOMPARE(widgetUngrabEventSpy.count(), 2); |
|
1888 |
||
1889 |
// Add two more widgets to the scene |
|
1890 |
QGraphicsWidget *widget2 = new QGraphicsWidget; |
|
1891 |
scene.addItem(widget2); |
|
1892 |
EventSpy widget2GrabEventSpy(widget2, QEvent::GrabMouse); |
|
1893 |
EventSpy widget2UngrabEventSpy(widget2, QEvent::UngrabMouse); |
|
1894 |
QGraphicsWidget *widget3 = new QGraphicsWidget; |
|
1895 |
scene.addItem(widget3); |
|
1896 |
EventSpy widget3GrabEventSpy(widget3, QEvent::GrabMouse); |
|
1897 |
EventSpy widget3UngrabEventSpy(widget3, QEvent::UngrabMouse); |
|
1898 |
||
1899 |
widget->setData(0, "widget"); |
|
1900 |
widget2->setData(0, "widget2"); |
|
1901 |
widget3->setData(0, "widget3"); |
|
1902 |
||
1903 |
// Simple nested grabbing |
|
1904 |
widget->grabMouse(); |
|
1905 |
QCOMPARE(widgetGrabEventSpy.count(), 3); |
|
1906 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget); |
|
1907 |
widget2->grabMouse(); |
|
1908 |
QCOMPARE(widgetUngrabEventSpy.count(), 3); |
|
1909 |
QCOMPARE(widget2GrabEventSpy.count(), 1); |
|
1910 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget2); |
|
1911 |
widget3->grabMouse(); |
|
1912 |
QCOMPARE(widget2UngrabEventSpy.count(), 1); |
|
1913 |
QCOMPARE(widget3GrabEventSpy.count(), 1); |
|
1914 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget3); |
|
1915 |
widget3->ungrabMouse(); |
|
1916 |
QCOMPARE(widget3UngrabEventSpy.count(), 1); |
|
1917 |
QCOMPARE(widget2GrabEventSpy.count(), 2); |
|
1918 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget2); |
|
1919 |
widget2->ungrabMouse(); |
|
1920 |
QCOMPARE(widget2UngrabEventSpy.count(), 2); |
|
1921 |
QCOMPARE(widgetGrabEventSpy.count(), 4); |
|
1922 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget); |
|
1923 |
widget->ungrabMouse(); |
|
1924 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
1925 |
||
1926 |
// Out of order ungrab |
|
1927 |
widget->grabMouse(); |
|
1928 |
QCOMPARE(widgetGrabEventSpy.count(), 5); |
|
1929 |
widget2->grabMouse(); |
|
1930 |
QCOMPARE(widget2GrabEventSpy.count(), 3); |
|
1931 |
widget3->grabMouse(); |
|
1932 |
QCOMPARE(widget3GrabEventSpy.count(), 2); |
|
1933 |
widget2->ungrabMouse(); |
|
1934 |
QCOMPARE(widget3UngrabEventSpy.count(), 2); |
|
1935 |
QCOMPARE(widget2UngrabEventSpy.count(), 4); |
|
1936 |
QCOMPARE(widgetGrabEventSpy.count(), 6); |
|
1937 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget); |
|
1938 |
} |
|
1939 |
||
1940 |
void tst_QGraphicsWidget::implicitMouseGrabber() |
|
1941 |
{ |
|
1942 |
QGraphicsScene scene; |
|
1943 |
QGraphicsWidget *widget = new QGraphicsWidget; |
|
1944 |
widget->setFlag(QGraphicsItem::ItemIsMovable); // can grab mouse |
|
1945 |
widget->resize(200, 200); |
|
1946 |
EventSpy widgetGrabEventSpy(widget, QEvent::GrabMouse); |
|
1947 |
EventSpy widgetUngrabEventSpy(widget, QEvent::UngrabMouse); |
|
1948 |
scene.addItem(widget); |
|
1949 |
||
1950 |
QVERIFY(!scene.mouseGrabberItem()); |
|
1951 |
||
1952 |
// Click on an item, see if gain and lose implicit mouse grab. |
|
1953 |
{ |
|
1954 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
1955 |
event.ignore(); |
|
1956 |
event.setButton(Qt::LeftButton); |
|
1957 |
event.setScenePos(QPointF(50, 50)); |
|
1958 |
qApp->sendEvent(&scene, &event); |
|
1959 |
} |
|
1960 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget); |
|
1961 |
QCOMPARE(widgetGrabEventSpy.count(), 1); |
|
1962 |
{ |
|
1963 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); |
|
1964 |
event.ignore(); |
|
1965 |
event.setButton(Qt::LeftButton); |
|
1966 |
event.setScenePos(QPointF(50, 50)); |
|
1967 |
qApp->sendEvent(&scene, &event); |
|
1968 |
} |
|
1969 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
1970 |
QCOMPARE(widgetGrabEventSpy.count(), 1); |
|
1971 |
QCOMPARE(widgetUngrabEventSpy.count(), 1); |
|
1972 |
||
1973 |
// Click on an item that already grabs the mouse. Shouldn't have any effect. |
|
1974 |
widget->grabMouse(); |
|
1975 |
QCOMPARE(widgetGrabEventSpy.count(), 2); |
|
1976 |
{ |
|
1977 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
1978 |
event.ignore(); |
|
1979 |
event.setButton(Qt::LeftButton); |
|
1980 |
event.setScenePos(QPointF(50, 50)); |
|
1981 |
qApp->sendEvent(&scene, &event); |
|
1982 |
} |
|
1983 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget); |
|
1984 |
QCOMPARE(widgetGrabEventSpy.count(), 2); |
|
1985 |
{ |
|
1986 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); |
|
1987 |
event.ignore(); |
|
1988 |
event.setButton(Qt::LeftButton); |
|
1989 |
event.setScenePos(QPointF(50, 50)); |
|
1990 |
qApp->sendEvent(&scene, &event); |
|
1991 |
} |
|
1992 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget); |
|
1993 |
QCOMPARE(widgetGrabEventSpy.count(), 2); |
|
1994 |
QCOMPARE(widgetUngrabEventSpy.count(), 1); |
|
1995 |
widget->ungrabMouse(); |
|
1996 |
QCOMPARE(widgetUngrabEventSpy.count(), 2); |
|
1997 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
1998 |
||
1999 |
// Implicit mouse grabber tries to explicitly grab the mouse |
|
2000 |
{ |
|
2001 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
2002 |
event.ignore(); |
|
2003 |
event.setButton(Qt::LeftButton); |
|
2004 |
event.setScenePos(QPointF(50, 50)); |
|
2005 |
qApp->sendEvent(&scene, &event); |
|
2006 |
} |
|
2007 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget); |
|
2008 |
QCOMPARE(widgetGrabEventSpy.count(), 3); |
|
2009 |
widget->grabMouse(); |
|
2010 |
QCOMPARE(widgetUngrabEventSpy.count(), 2); |
|
2011 |
{ |
|
2012 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); |
|
2013 |
event.ignore(); |
|
2014 |
event.setButton(Qt::LeftButton); |
|
2015 |
event.setScenePos(QPointF(50, 50)); |
|
2016 |
qApp->sendEvent(&scene, &event); |
|
2017 |
} |
|
2018 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget); |
|
2019 |
QCOMPARE(widgetGrabEventSpy.count(), 3); |
|
2020 |
QCOMPARE(widgetUngrabEventSpy.count(), 2); |
|
2021 |
widget->ungrabMouse(); |
|
2022 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
2023 |
QCOMPARE(widgetGrabEventSpy.count(), 3); |
|
2024 |
QCOMPARE(widgetUngrabEventSpy.count(), 3); |
|
2025 |
||
2026 |
// Arrival of a new widget |
|
2027 |
QGraphicsWidget *widget2 = new QGraphicsWidget; |
|
2028 |
widget2->setFlag(QGraphicsItem::ItemIsMovable); // can grab mouse |
|
2029 |
widget2->resize(200, 200); |
|
2030 |
widget2->setPos(205, 0); |
|
2031 |
EventSpy widget2GrabEventSpy(widget2, QEvent::GrabMouse); |
|
2032 |
EventSpy widget2UngrabEventSpy(widget2, QEvent::UngrabMouse); |
|
2033 |
scene.addItem(widget2); |
|
2034 |
||
2035 |
// Implicit grab while there's an explicit grab is not possible. |
|
2036 |
widget->grabMouse(); |
|
2037 |
QCOMPARE(widgetGrabEventSpy.count(), 4); |
|
2038 |
{ |
|
2039 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
2040 |
event.ignore(); |
|
2041 |
event.setButton(Qt::LeftButton); |
|
2042 |
event.setScenePos(QPointF(250, 50)); |
|
2043 |
qApp->sendEvent(&scene, &event); |
|
2044 |
} |
|
2045 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget); |
|
2046 |
QCOMPARE(widgetGrabEventSpy.count(), 4); |
|
2047 |
QCOMPARE(widget2GrabEventSpy.count(), 0); |
|
2048 |
QCOMPARE(widget2UngrabEventSpy.count(), 0); |
|
2049 |
||
2050 |
scene.removeItem(widget); |
|
2051 |
QCOMPARE(widgetUngrabEventSpy.count(), 4); |
|
2052 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
2053 |
} |
|
2054 |
||
2055 |
class GrabOnPressItem : public QGraphicsRectItem |
|
2056 |
{ |
|
2057 |
public: |
|
2058 |
GrabOnPressItem(const QRectF &rect) |
|
2059 |
: QGraphicsRectItem(rect), |
|
2060 |
npress(0), nrelease(0), ndoubleClick(0), |
|
2061 |
ngrab(0), nungrab(0) |
|
2062 |
{ |
|
2063 |
} |
|
2064 |
int npress; |
|
2065 |
int nrelease; |
|
2066 |
int ndoubleClick; |
|
2067 |
int ngrab; |
|
2068 |
int nungrab; |
|
2069 |
protected: |
|
2070 |
bool sceneEvent(QEvent *event) |
|
2071 |
{ |
|
2072 |
switch (event->type()) { |
|
2073 |
case QEvent::GrabMouse: |
|
2074 |
++ngrab; |
|
2075 |
break; |
|
2076 |
case QEvent::UngrabMouse: |
|
2077 |
++nungrab; |
|
2078 |
break; |
|
2079 |
default: |
|
2080 |
break; |
|
2081 |
} |
|
2082 |
return QGraphicsRectItem::sceneEvent(event); |
|
2083 |
} |
|
2084 |
||
2085 |
void mousePressEvent(QGraphicsSceneMouseEvent *) |
|
2086 |
{ |
|
2087 |
grabMouse(); |
|
2088 |
++npress; |
|
2089 |
} |
|
2090 |
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) |
|
2091 |
{ |
|
2092 |
ungrabMouse(); |
|
2093 |
++nrelease; |
|
2094 |
} |
|
2095 |
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) |
|
2096 |
{ |
|
2097 |
++ndoubleClick; |
|
2098 |
} |
|
2099 |
}; |
|
2100 |
||
2101 |
void tst_QGraphicsWidget::doubleClickAfterExplicitMouseGrab() |
|
2102 |
{ |
|
2103 |
QGraphicsScene scene; |
|
2104 |
GrabOnPressItem *item = new GrabOnPressItem(QRectF(0, 0, 100, 100)); |
|
2105 |
scene.addItem(item); |
|
2106 |
||
2107 |
{ |
|
2108 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
2109 |
event.setButton(Qt::LeftButton); |
|
2110 |
event.setButtons(Qt::LeftButton); |
|
2111 |
event.ignore(); |
|
2112 |
event.setScenePos(QPointF(50, 50)); |
|
2113 |
qApp->sendEvent(&scene, &event); |
|
2114 |
} |
|
2115 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item); |
|
2116 |
QCOMPARE(item->npress, 1); |
|
2117 |
QCOMPARE(item->ngrab, 1); |
|
2118 |
{ |
|
2119 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); |
|
2120 |
event.setButton(Qt::LeftButton); |
|
2121 |
event.setButtons(0); |
|
2122 |
event.ignore(); |
|
2123 |
event.setScenePos(QPointF(50, 50)); |
|
2124 |
qApp->sendEvent(&scene, &event); |
|
2125 |
} |
|
2126 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
2127 |
QCOMPARE(item->nrelease, 1); |
|
2128 |
QCOMPARE(item->nungrab, 1); |
|
2129 |
{ |
|
2130 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseDoubleClick); |
|
2131 |
event.setButton(Qt::LeftButton); |
|
2132 |
event.setButtons(Qt::LeftButton); |
|
2133 |
event.ignore(); |
|
2134 |
event.setScenePos(QPointF(50, 50)); |
|
2135 |
qApp->sendEvent(&scene, &event); |
|
2136 |
} |
|
2137 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item); |
|
2138 |
QCOMPARE(item->ndoubleClick, 1); |
|
2139 |
QCOMPARE(item->ngrab, 2); |
|
2140 |
{ |
|
2141 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); |
|
2142 |
event.setButton(Qt::LeftButton); |
|
2143 |
event.setButtons(0); |
|
2144 |
event.ignore(); |
|
2145 |
event.setScenePos(QPointF(50, 50)); |
|
2146 |
qApp->sendEvent(&scene, &event); |
|
2147 |
} |
|
2148 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
2149 |
QCOMPARE(item->nrelease, 2); |
|
2150 |
QCOMPARE(item->nungrab, 2); |
|
2151 |
} |
|
2152 |
||
2153 |
void tst_QGraphicsWidget::popupMouseGrabber() |
|
2154 |
{ |
|
2155 |
QGraphicsScene scene; |
|
2156 |
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Popup); |
|
2157 |
widget->setFlag(QGraphicsItem::ItemIsMovable); // can grab mouse |
|
2158 |
widget->resize(200, 200); |
|
2159 |
EventSpy widgetGrabEventSpy(widget, QEvent::GrabMouse); |
|
2160 |
EventSpy widgetUngrabEventSpy(widget, QEvent::UngrabMouse); |
|
2161 |
||
2162 |
// Simply adding a visible popup to the scene immediately grabs the mouse. |
|
2163 |
scene.addItem(widget); |
|
2164 |
QCOMPARE(widgetGrabEventSpy.count(), 1); |
|
2165 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget); |
|
2166 |
||
2167 |
// Hiding it loses the grab again. |
|
2168 |
widget->hide(); |
|
2169 |
QCOMPARE(widgetUngrabEventSpy.count(), 1); |
|
2170 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0); |
|
2171 |
||
2172 |
// Showing it grabs the mosue again |
|
2173 |
widget->show(); |
|
2174 |
QCOMPARE(widgetGrabEventSpy.count(), 2); |
|
2175 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget); |
|
2176 |
||
2177 |
// Add two popups |
|
2178 |
QGraphicsWidget *widget2 = new QGraphicsWidget(0, Qt::Popup); |
|
2179 |
widget2->setFlag(QGraphicsItem::ItemIsMovable); // can grab mouse |
|
2180 |
widget2->resize(200, 200); |
|
2181 |
EventSpy widget2GrabEventSpy(widget2, QEvent::GrabMouse); |
|
2182 |
EventSpy widget2UngrabEventSpy(widget2, QEvent::UngrabMouse); |
|
2183 |
QGraphicsWidget *widget3 = new QGraphicsWidget(0, Qt::Popup); |
|
2184 |
widget3->setFlag(QGraphicsItem::ItemIsMovable); // can grab mouse |
|
2185 |
widget3->resize(200, 200); |
|
2186 |
EventSpy widget3GrabEventSpy(widget3, QEvent::GrabMouse); |
|
2187 |
EventSpy widget3UngrabEventSpy(widget3, QEvent::UngrabMouse); |
|
2188 |
||
2189 |
// Adding to the scene grabs |
|
2190 |
scene.addItem(widget2); |
|
2191 |
QCOMPARE(widgetUngrabEventSpy.count(), 2); |
|
2192 |
QCOMPARE(widget2GrabEventSpy.count(), 1); |
|
2193 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget2); |
|
2194 |
||
2195 |
// Adding to the scene grabs again |
|
2196 |
scene.addItem(widget3); |
|
2197 |
QCOMPARE(widget2UngrabEventSpy.count(), 1); |
|
2198 |
QCOMPARE(widget3GrabEventSpy.count(), 1); |
|
2199 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget3); |
|
2200 |
||
2201 |
// Hiding the topmost widget causes widget 2 to regain grab. |
|
2202 |
widget3->hide(); |
|
2203 |
QCOMPARE(widget2GrabEventSpy.count(), 2); |
|
2204 |
QCOMPARE(widget3UngrabEventSpy.count(), 1); |
|
2205 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget2); |
|
2206 |
widget3->show(); |
|
2207 |
QCOMPARE(widget2UngrabEventSpy.count(), 2); |
|
2208 |
QCOMPARE(widget3GrabEventSpy.count(), 2); |
|
2209 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget3); |
|
2210 |
||
2211 |
// Clicking outside the popup still causes it to close (despite that it's |
|
2212 |
// an explicit mouse grabber). |
|
2213 |
{ |
|
2214 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
|
2215 |
event.ignore(); |
|
2216 |
event.setButton(Qt::LeftButton); |
|
2217 |
event.setScenePos(QPointF(500, 500)); // outside |
|
2218 |
qApp->sendEvent(&scene, &event); |
|
2219 |
} |
|
2220 |
QVERIFY(!widget3->isVisible()); |
|
2221 |
QCOMPARE(widget3UngrabEventSpy.count(), 2); |
|
2222 |
QCOMPARE(widget2GrabEventSpy.count(), 3); |
|
2223 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget2); |
|
2224 |
QVERIFY(widget2->isVisible()); |
|
2225 |
QVERIFY(widget->isVisible()); |
|
2226 |
widget3->show(); |
|
2227 |
QCOMPARE(widget3GrabEventSpy.count(), 3); |
|
2228 |
QCOMPARE(widget2UngrabEventSpy.count(), 3); |
|
2229 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget3); |
|
2230 |
||
2231 |
// This is something of a curiosity. What happens if you call |
|
2232 |
// ungrabMouse() on a popup? The answer is - it loses the grab. If you |
|
2233 |
// hide and show the popup again, it will regain the grab. |
|
2234 |
widget3->ungrabMouse(); |
|
2235 |
QCOMPARE(widget3UngrabEventSpy.count(), 3); |
|
2236 |
QCOMPARE(widget2GrabEventSpy.count(), 4); |
|
2237 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget2); |
|
2238 |
widget3->hide(); |
|
2239 |
widget3->show(); |
|
2240 |
QCOMPARE(widget3GrabEventSpy.count(), 4); |
|
2241 |
QCOMPARE(widget2UngrabEventSpy.count(), 4); |
|
2242 |
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)widget3); |
|
2243 |
} |
|
2244 |
||
2245 |
void tst_QGraphicsWidget::windowFlags_data() |
|
2246 |
{ |
|
2247 |
QTest::addColumn<int>("inputFlags"); |
|
2248 |
QTest::addColumn<int>("outputFlags"); |
|
2249 |
||
2250 |
QTest::newRow("nil") << 0 << 0; |
|
2251 |
||
2252 |
// Window types |
|
2253 |
QTest::newRow("Qt::Window") << int(Qt::Window) |
|
2254 |
<< int(Qt::Window | Qt::WindowTitleHint | Qt::WindowSystemMenuHint |
|
2255 |
| Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint); |
|
2256 |
QTest::newRow("Qt::SubWindow") << int(Qt::SubWindow) |
|
2257 |
<< int(Qt::SubWindow | Qt::WindowTitleHint | Qt::WindowSystemMenuHint |
|
2258 |
| Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint); |
|
2259 |
QTest::newRow("Qt::Dialog") << int(Qt::Dialog) |
|
2260 |
<< int(Qt::Dialog | Qt::WindowTitleHint | Qt::WindowSystemMenuHint |
|
2261 |
| Qt::WindowContextHelpButtonHint); |
|
2262 |
QTest::newRow("Qt::Sheet") << int(Qt::Sheet) |
|
2263 |
<< int(Qt::Sheet | Qt::WindowTitleHint | Qt::WindowSystemMenuHint |
|
2264 |
| Qt::WindowContextHelpButtonHint); |
|
2265 |
QTest::newRow("Qt::Tool") << int(Qt::Tool) |
|
2266 |
<< int(Qt::Tool | Qt::WindowTitleHint | Qt::WindowSystemMenuHint); |
|
2267 |
||
2268 |
// Custom window flags |
|
2269 |
QTest::newRow("Qt::FramelessWindowHint") << int(Qt::FramelessWindowHint) |
|
2270 |
<< int(Qt::FramelessWindowHint); |
|
2271 |
QTest::newRow("Qt::CustomizeWindowHint") << int(Qt::CustomizeWindowHint) |
|
2272 |
<< int(Qt::CustomizeWindowHint); |
|
2273 |
} |
|
2274 |
||
2275 |
void tst_QGraphicsWidget::windowFlags() |
|
2276 |
{ |
|
2277 |
QFETCH(int, inputFlags); |
|
2278 |
QFETCH(int, outputFlags); |
|
2279 |
||
2280 |
// Construct with flags set already |
|
2281 |
QGraphicsWidget widget(0, Qt::WindowFlags(inputFlags)); |
|
2282 |
QCOMPARE(widget.windowFlags(), Qt::WindowFlags(outputFlags)); |
|
2283 |
||
2284 |
// Set flags after construction |
|
2285 |
QGraphicsWidget widget2; |
|
2286 |
widget2.setWindowFlags(Qt::WindowFlags(inputFlags)); |
|
2287 |
QCOMPARE(widget2.windowFlags(), Qt::WindowFlags(outputFlags)); |
|
2288 |
||
2289 |
// Reset flags |
|
2290 |
widget2.setWindowFlags(0); |
|
2291 |
QVERIFY(!widget2.windowFlags()); |
|
2292 |
||
2293 |
// Set flags back again |
|
2294 |
widget2.setWindowFlags(Qt::WindowFlags(inputFlags)); |
|
2295 |
QCOMPARE(widget2.windowFlags(), Qt::WindowFlags(outputFlags)); |
|
2296 |
||
2297 |
// Construct with custom flags set already |
|
2298 |
QGraphicsWidget widget3(0, Qt::WindowFlags(inputFlags | Qt::FramelessWindowHint)); |
|
2299 |
QCOMPARE(widget3.windowFlags(), Qt::WindowFlags(inputFlags | Qt::FramelessWindowHint)); |
|
2300 |
||
2301 |
// Set custom flags after construction |
|
2302 |
QGraphicsWidget widget4; |
|
2303 |
widget4.setWindowFlags(Qt::WindowFlags(inputFlags | Qt::FramelessWindowHint)); |
|
2304 |
QCOMPARE(widget4.windowFlags(), Qt::WindowFlags(inputFlags | Qt::FramelessWindowHint)); |
|
2305 |
||
2306 |
// Reset flags |
|
2307 |
widget4.setWindowFlags(0); |
|
2308 |
QVERIFY(!widget4.windowFlags()); |
|
2309 |
||
2310 |
// Set custom flags back again |
|
2311 |
widget4.setWindowFlags(Qt::WindowFlags(inputFlags | Qt::FramelessWindowHint)); |
|
2312 |
QCOMPARE(widget4.windowFlags(), Qt::WindowFlags(inputFlags | Qt::FramelessWindowHint)); |
|
2313 |
||
2314 |
QGraphicsWidget *widget5 = new QGraphicsWidget; |
|
2315 |
widget5->setWindowFlags(Qt::WindowFlags(inputFlags)); |
|
2316 |
QCOMPARE(widget5->windowFlags(), Qt::WindowFlags(outputFlags)); |
|
2317 |
QGraphicsWidget window(0, Qt::Window); |
|
2318 |
widget5->setParentItem(&window); |
|
2319 |
QCOMPARE(widget5->windowFlags(), Qt::WindowFlags(outputFlags)); |
|
2320 |
} |
|
2321 |
||
2322 |
void tst_QGraphicsWidget::shortcutsDeletion() |
|
2323 |
{ |
|
2324 |
QGraphicsWidget *widget = new QGraphicsWidget; |
|
2325 |
QGraphicsWidget *widget2 = new QGraphicsWidget; |
|
2326 |
widget->setMinimumSize(40, 40); |
|
2327 |
QWidgetAction *del = new QWidgetAction(widget); |
|
2328 |
del->setIcon(QIcon("edit-delete")); |
|
2329 |
del->setShortcut(Qt::Key_Delete); |
|
2330 |
del->setShortcutContext(Qt::WidgetShortcut); |
|
2331 |
widget2->addAction(del); |
|
2332 |
widget2->addAction(del); |
|
2333 |
delete widget; |
|
2334 |
} |
|
2335 |
||
2336 |
class MessUpPainterWidget : public QGraphicsWidget |
|
2337 |
{ |
|
2338 |
public: |
|
2339 |
MessUpPainterWidget(QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0) |
|
2340 |
: QGraphicsWidget(parent, wFlags) |
|
2341 |
{} |
|
2342 |
||
2343 |
void paintWindowFrame(QPainter * painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
2344 |
{ |
|
2345 |
QCOMPARE(painter->opacity(), 1.0); |
|
2346 |
painter->setOpacity(0.0); |
|
2347 |
QGraphicsWidget::paintWindowFrame(painter, option, widget); |
|
2348 |
} |
|
2349 |
void paint(QPainter * painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
2350 |
{ |
|
2351 |
QCOMPARE(painter->opacity(), 1.0); |
|
2352 |
painter->drawRect(0, 0, 100, 100); |
|
2353 |
QGraphicsWidget::paint(painter, option, widget); |
|
2354 |
} |
|
2355 |
||
2356 |
}; |
|
2357 |
||
2358 |
void tst_QGraphicsWidget::painterStateProtectionOnWindowFrame() |
|
2359 |
{ |
|
2360 |
MessUpPainterWidget *widget = new MessUpPainterWidget(0, Qt::Window); |
|
2361 |
QGraphicsScene scene(0, 0, 300, 300); |
|
2362 |
QGraphicsView view(&scene); |
|
2363 |
scene.addItem(widget); |
|
2364 |
view.show(); |
|
2365 |
QTest::qWaitForWindowShown(&view); |
|
2366 |
} |
|
2367 |
||
2368 |
class ProxyStyle : public QCommonStyle |
|
2369 |
{ |
|
2370 |
public: |
|
2371 |
ProxyStyle(QStyle *proxyStyle) : QCommonStyle() |
|
2372 |
{ |
|
2373 |
m_proxyStyle = proxyStyle; |
|
2374 |
} |
|
2375 |
||
2376 |
int pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const |
|
2377 |
{ |
|
2378 |
return m_proxyStyle->pixelMetric(metric, option, widget); |
|
2379 |
} |
|
2380 |
||
2381 |
private: |
|
2382 |
QStyle *m_proxyStyle; |
|
2383 |
}; |
|
2384 |
||
2385 |
class StyledGraphicsWidget : public QGraphicsWidget |
|
2386 |
{ |
|
2387 |
public: |
|
2388 |
StyledGraphicsWidget(bool useOwnStyle) : QGraphicsWidget(), m_style(0) { |
|
2389 |
if (useOwnStyle) { |
|
2390 |
QStyle *oldStyle = style(); |
|
2391 |
m_style = new ProxyStyle(oldStyle); |
|
2392 |
setStyle(m_style); |
|
2393 |
} |
|
2394 |
||
2395 |
style()->pixelMetric(QStyle::PM_SmallIconSize); // crash when style() is still in widgetStyles |
|
2396 |
} |
|
2397 |
||
2398 |
~StyledGraphicsWidget() { |
|
2399 |
delete m_style; |
|
2400 |
} |
|
2401 |
||
2402 |
private: |
|
2403 |
QStyle *m_style; |
|
2404 |
}; |
|
2405 |
||
2406 |
void tst_QGraphicsWidget::task243004_setStyleCrash() |
|
2407 |
{ |
|
2408 |
QGraphicsItem *item1 = new StyledGraphicsWidget(true); |
|
2409 |
delete item1; // item1 not removed from widgetStyles |
|
2410 |
||
2411 |
QGraphicsItem *item2 = new StyledGraphicsWidget(false); |
|
2412 |
delete item2; |
|
2413 |
} |
|
2414 |
||
2415 |
class GraphicsWidget_task250119 : public QGraphicsWidget |
|
2416 |
{ |
|
2417 |
public: |
|
2418 |
GraphicsWidget_task250119() |
|
2419 |
: shortcutEvents(0) |
|
2420 |
{ |
|
2421 |
setFocusPolicy(Qt::StrongFocus); |
|
2422 |
resize(100, 100); |
|
2423 |
} |
|
2424 |
||
2425 |
int shortcutEvents; |
|
2426 |
||
2427 |
private: |
|
2428 |
bool event(QEvent *event) |
|
2429 |
{ |
|
2430 |
if (event->type() == QEvent::Shortcut) |
|
2431 |
shortcutEvents++; |
|
2432 |
return QGraphicsWidget::event(event); |
|
2433 |
} |
|
2434 |
||
2435 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
|
2436 |
{ |
|
2437 |
if (hasFocus()) { |
|
2438 |
painter->setPen(QPen(Qt::black, 0, Qt::DashLine)); |
|
2439 |
painter->drawRect(rect()); |
|
2440 |
} |
|
2441 |
painter->setPen(QPen(Qt::black, 0, Qt::SolidLine)); |
|
2442 |
painter->fillRect(rect().adjusted(2, 2, -2, -2), Qt::yellow); |
|
2443 |
painter->drawRect(rect().adjusted(2, 2, -2, -2)); |
|
2444 |
} |
|
2445 |
}; |
|
2446 |
||
2447 |
void tst_QGraphicsWidget::task250119_shortcutContext() |
|
2448 |
{ |
|
2449 |
QGraphicsScene scene; |
|
2450 |
QGraphicsView view; |
|
2451 |
view.setScene(&scene); |
|
2452 |
view.show(); |
|
2453 |
QApplication::setActiveWindow(&view); |
|
2454 |
QTRY_COMPARE(QApplication::activeWindow(), &view); |
|
2455 |
||
2456 |
||
2457 |
// *** Event: *** |
|
2458 |
||
2459 |
GraphicsWidget_task250119 w_event; |
|
2460 |
scene.addItem(&w_event); |
|
2461 |
||
2462 |
const int id = w_event.grabShortcut(Qt::Key_A, Qt::WidgetWithChildrenShortcut); |
|
2463 |
w_event.setShortcutEnabled(id, true); |
|
2464 |
||
2465 |
w_event.setFocus(); |
|
2466 |
QTest::keyPress(&view, Qt::Key_A); |
|
2467 |
QCOMPARE(w_event.shortcutEvents, 1); |
|
2468 |
||
2469 |
w_event.clearFocus(); |
|
2470 |
QTest::keyPress(&view, Qt::Key_A); |
|
2471 |
QCOMPARE(w_event.shortcutEvents, 1); |
|
2472 |
||
2473 |
scene.removeItem(&w_event); |
|
2474 |
||
2475 |
||
2476 |
// *** Signal: *** |
|
2477 |
||
2478 |
GraphicsWidget_task250119 w_signal; |
|
2479 |
scene.addItem(&w_signal); |
|
2480 |
||
2481 |
QAction action(0); |
|
2482 |
action.setShortcut(Qt::Key_B); |
|
2483 |
action.setShortcutContext(Qt::WidgetWithChildrenShortcut); |
|
2484 |
QSignalSpy spy(&action, SIGNAL(triggered())); |
|
2485 |
||
2486 |
w_signal.addAction(&action); |
|
2487 |
||
2488 |
w_signal.setFocus(); |
|
2489 |
QTest::keyPress(&view, Qt::Key_B); |
|
2490 |
QCOMPARE(spy.count(), 1); |
|
2491 |
||
2492 |
w_signal.clearFocus(); |
|
2493 |
QTest::keyPress(&view, Qt::Key_B); |
|
2494 |
QCOMPARE(spy.count(), 1); |
|
2495 |
||
2496 |
scene.removeItem(&w_signal); |
|
2497 |
} |
|
2498 |
||
2499 |
class ClippingAndTransformsScene : public QGraphicsScene |
|
2500 |
{ |
|
2501 |
public: |
|
2502 |
QList<QGraphicsItem *> drawnItems; |
|
2503 |
protected: |
|
2504 |
void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], |
|
2505 |
const QStyleOptionGraphicsItem options[], QWidget *widget = 0) |
|
2506 |
{ |
|
2507 |
drawnItems.clear(); |
|
2508 |
for (int i = 0; i < numItems; ++i) |
|
2509 |
drawnItems << items[i]; |
|
2510 |
QGraphicsScene::drawItems(painter, numItems, items, options, widget); |
|
2511 |
} |
|
2512 |
}; |
|
2513 |
||
2514 |
class RectWidget : public QGraphicsWidget |
|
2515 |
{ |
|
2516 |
public: |
|
2517 |
||
2518 |
RectWidget(Qt::GlobalColor color, QGraphicsItem *parent=0) : QGraphicsWidget(parent), mColor(color) {} |
|
2519 |
||
2520 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
|
2521 |
{ |
|
2522 |
painter->setBrush(QBrush(mColor)); |
|
2523 |
painter->drawRect(boundingRect()); |
|
2524 |
} |
|
2525 |
||
2526 |
Qt::GlobalColor mColor; |
|
2527 |
}; |
|
2528 |
||
2529 |
class RectItem : public QGraphicsItem |
|
2530 |
{ |
|
2531 |
public: |
|
2532 |
||
2533 |
RectItem(Qt::GlobalColor color, QGraphicsItem *parent=0) : QGraphicsItem(parent), mColor(color) {} |
|
2534 |
||
2535 |
QRectF boundingRect() const |
|
2536 |
{return QRectF(10,10,50,50);} |
|
2537 |
||
2538 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
|
2539 |
{ |
|
2540 |
painter->setBrush(QBrush(mColor)); |
|
2541 |
painter->drawRect(boundingRect()); |
|
2542 |
} |
|
2543 |
||
2544 |
Qt::GlobalColor mColor; |
|
2545 |
}; |
|
2546 |
||
2547 |
void tst_QGraphicsWidget::ensureClipping() |
|
2548 |
{ |
|
2549 |
ClippingAndTransformsScene scene; |
|
2550 |
scene.setSceneRect(-50, -50, 200, 200); |
|
2551 |
||
2552 |
//A root that clip children |
|
2553 |
RectWidget *clipWidget = new RectWidget(Qt::black); |
|
2554 |
scene.addItem(clipWidget); |
|
2555 |
||
2556 |
clipWidget->setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
2557 |
||
2558 |
//a child |
|
2559 |
RectWidget *childWidget = new RectWidget(Qt::red, clipWidget); |
|
2560 |
clipWidget->setGeometry(QRectF(10, 10, 100, 100)); |
|
2561 |
childWidget->setGeometry(QRectF(25, 25, 50, 50)); |
|
2562 |
||
2563 |
//We put a QGraphicsItem to be sure this one is also paint |
|
2564 |
RectItem *childitem = new RectItem(Qt::blue, clipWidget); |
|
2565 |
||
2566 |
QGraphicsView view(&scene); |
|
2567 |
view.setOptimizationFlag(QGraphicsView::IndirectPainting); |
|
2568 |
view.show(); |
|
2569 |
QTest::qWaitForWindowShown(&view); |
|
2570 |
||
2571 |
QList<QGraphicsItem *> expected; |
|
2572 |
expected << clipWidget << childWidget << childitem; |
|
2573 |
QTRY_VERIFY(scene.drawnItems.contains(clipWidget)); |
|
2574 |
QVERIFY(scene.drawnItems.contains(childWidget)); |
|
2575 |
QVERIFY(scene.drawnItems.contains(childitem)); |
|
2576 |
} |
|
2577 |
||
2578 |
class ItemChangeTester : public QGraphicsWidget |
|
2579 |
{ |
|
2580 |
public: |
|
2581 |
ItemChangeTester() |
|
2582 |
{ setFlag(ItemSendsGeometryChanges); clear(); } |
|
2583 |
ItemChangeTester(QGraphicsItem *parent) : QGraphicsWidget(parent) |
|
2584 |
{ setFlag(ItemSendsGeometryChanges); clear(); } |
|
2585 |
||
2586 |
void clear() |
|
2587 |
{ |
|
2588 |
changes.clear(); |
|
2589 |
values.clear(); |
|
2590 |
oldValues.clear(); |
|
2591 |
} |
|
2592 |
QList<GraphicsItemChange> changes; |
|
2593 |
QList<QVariant> values; |
|
2594 |
QList<QVariant> oldValues; |
|
2595 |
protected: |
|
2596 |
QVariant itemChange(GraphicsItemChange change, const QVariant &value) |
|
2597 |
{ |
|
2598 |
changes << change; |
|
2599 |
values << value; |
|
2600 |
switch (change) { |
|
2601 |
case QGraphicsItem::ItemPositionChange: |
|
2602 |
oldValues << pos(); |
|
2603 |
break; |
|
2604 |
case QGraphicsItem::ItemPositionHasChanged: |
|
2605 |
break; |
|
2606 |
default: |
|
2607 |
break; |
|
2608 |
} |
|
2609 |
return value; |
|
2610 |
} |
|
2611 |
}; |
|
2612 |
||
2613 |
void tst_QGraphicsWidget::widgetSendsGeometryChanges() |
|
2614 |
{ |
|
2615 |
ItemChangeTester widget; |
|
2616 |
widget.setFlags(0); |
|
2617 |
widget.clear(); |
|
2618 |
||
2619 |
QPointF pos(10, 10); |
|
2620 |
widget.setPos(pos); |
|
2621 |
||
2622 |
QCOMPARE(widget.pos(), pos); |
|
2623 |
QCOMPARE(widget.changes.size(), 0); |
|
2624 |
||
2625 |
widget.setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); |
|
2626 |
QCOMPARE(widget.changes.size(), 2); |
|
2627 |
||
2628 |
widget.setPos(QPointF()); |
|
2629 |
QCOMPARE(widget.changes.size(), 4); |
|
2630 |
||
2631 |
QCOMPARE(widget.pos(), QPointF()); |
|
2632 |
||
2633 |
QRectF geometry(20, 20, 50, 50); |
|
2634 |
widget.setGeometry(geometry); |
|
2635 |
QCOMPARE(widget.changes.size(), 6); |
|
2636 |
||
2637 |
QCOMPARE(widget.geometry(), geometry); |
|
2638 |
||
2639 |
QCOMPARE(widget.changes, QList<QGraphicsItem::GraphicsItemChange>() |
|
2640 |
<< QGraphicsItem::ItemFlagsChange |
|
2641 |
<< QGraphicsItem::ItemFlagsHaveChanged |
|
2642 |
<< QGraphicsItem::ItemPositionChange |
|
2643 |
<< QGraphicsItem::ItemPositionHasChanged |
|
2644 |
<< QGraphicsItem::ItemPositionChange |
|
2645 |
<< QGraphicsItem::ItemPositionHasChanged); |
|
2646 |
} |
|
2647 |
||
2648 |
class HFWWidget : public QGraphicsWidget |
|
2649 |
{ |
|
2650 |
public: |
|
2651 |
HFWWidget() : QGraphicsWidget(0, Qt::Window) |
|
2652 |
{ |
|
2653 |
QSizePolicy sp; |
|
2654 |
sp.setHeightForWidth(true); |
|
2655 |
setSizePolicy(sp); |
|
2656 |
} |
|
2657 |
||
2658 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
2659 |
{ |
|
2660 |
Q_UNUSED(option); |
|
2661 |
Q_UNUSED(widget); |
|
2662 |
qreal w = rect().width(); |
|
2663 |
QRectF box(0, 0, w, 2400/w); |
|
2664 |
painter->drawRoundRect(box); |
|
2665 |
painter->drawLine(box.topLeft(), box.bottomRight()); |
|
2666 |
painter->drawLine(box.bottomLeft(), box.topRight()); |
|
2667 |
} |
|
2668 |
||
2669 |
protected: |
|
2670 |
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const |
|
2671 |
{ |
|
2672 |
qreal w = constraint.width(); |
|
2673 |
switch (which) { |
|
2674 |
case Qt::MinimumSize: |
|
2675 |
if (w >= 0 && constraint.height() < 0) { |
|
2676 |
// keep the same area of 60x40 = 2400 |
|
2677 |
return QSizeF(w, 2400.0/w); |
|
2678 |
} else { |
|
2679 |
return QSizeF(10, 10); |
|
2680 |
} |
|
2681 |
break; |
|
2682 |
case Qt::PreferredSize: |
|
2683 |
return QSizeF(48.989794, 48.989794); |
|
2684 |
default: |
|
2685 |
break; |
|
2686 |
} |
|
2687 |
return QGraphicsWidget::sizeHint(which, constraint); |
|
2688 |
} |
|
2689 |
}; |
|
2690 |
||
2691 |
void tst_QGraphicsWidget::respectHFW() |
|
2692 |
{ |
|
2693 |
#if defined(Q_OS_WINCE) || defined(Q_OS_MAC) || defined(Q_WS_QWS) |
|
2694 |
qDebug("This test is platform dependent, it fails on wince, mac and qws. Please fix."); |
|
2695 |
#else |
|
2696 |
QGraphicsScene scene; |
|
2697 |
HFWWidget *window = new HFWWidget; |
|
2698 |
scene.addItem(window); |
|
2699 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
2700 |
view->resize(400, 400); |
|
2701 |
view->setSceneRect(-100, -100, 300,300); |
|
2702 |
||
2703 |
view->show(); |
|
2704 |
window->setGeometry(0, 0, 70, 70); |
|
2705 |
QTest::qWaitForWindowShown(view); |
|
2706 |
||
2707 |
{ // here we go - simulate a interactive resize of the window |
|
2708 |
QTest::mouseMove(view, view->mapFromScene(71, 71)); // bottom right corner |
|
2709 |
||
2710 |
QTest::mousePress(view->viewport(), Qt::LeftButton, 0, view->mapFromScene(71, 71), 200); |
|
2711 |
view->grabMouse(); |
|
2712 |
// move both mouse cursor and set correct event in order to emulate resize |
|
2713 |
QTest::mouseMove(view->viewport(), view->mapFromScene(60, 30), 200); |
|
2714 |
QMouseEvent e = QMouseEvent(QEvent::MouseMove, |
|
2715 |
view->mapFromScene(60, 20), |
|
2716 |
Qt::NoButton, |
|
2717 |
Qt::LeftButton, |
|
2718 |
Qt::NoModifier); |
|
2719 |
QApplication::sendEvent(view->viewport(), &e); |
|
2720 |
view->releaseMouse(); |
|
2721 |
} |
|
2722 |
const QSizeF winSize = window->size(); |
|
2723 |
qreal minHFW = window->effectiveSizeHint(Qt::MinimumSize, QSizeF(winSize.width(), -1)).height(); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2724 |
QTRY_VERIFY(qAbs(minHFW - winSize.height()) < 1); |
0 | 2725 |
#endif |
2726 |
} |
|
2727 |
||
2728 |
class PolishWidget : public QGraphicsWidget |
|
2729 |
{ |
|
2730 |
public: |
|
2731 |
||
2732 |
PolishWidget(Qt::GlobalColor color, QGraphicsItem *parent=0) : |
|
2733 |
QGraphicsWidget(parent), mColor(color) |
|
2734 |
{ |
|
2735 |
} |
|
2736 |
||
2737 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
|
2738 |
{ |
|
2739 |
painter->setBrush(QBrush(mColor)); |
|
2740 |
painter->drawRect(boundingRect()); |
|
2741 |
} |
|
2742 |
||
2743 |
void polishEvent() |
|
2744 |
{ |
|
2745 |
if (!parentWidget()) { |
|
2746 |
//We add a child in the polish event for the parent |
|
2747 |
PolishWidget *childWidget = new PolishWidget(Qt::black, this); |
|
2748 |
childWidget->setGeometry(QRectF(10,10,30,30)); |
|
2749 |
} |
|
2750 |
||
2751 |
QGraphicsWidget::polishEvent(); |
|
2752 |
mColor = Qt::red; |
|
2753 |
update(); |
|
2754 |
numberOfPolish++; |
|
2755 |
} |
|
2756 |
||
2757 |
static int numberOfPolish; |
|
2758 |
||
2759 |
private: |
|
2760 |
Qt::GlobalColor mColor; |
|
2761 |
}; |
|
2762 |
||
2763 |
int PolishWidget::numberOfPolish = 0; |
|
2764 |
||
2765 |
void tst_QGraphicsWidget::addChildInpolishEvent() |
|
2766 |
{ |
|
2767 |
QGraphicsScene scene; |
|
2768 |
||
2769 |
PolishWidget *parentWidget = new PolishWidget(Qt::white); |
|
2770 |
scene.addItem(parentWidget); |
|
2771 |
||
2772 |
QGraphicsView view(&scene); |
|
2773 |
view.resize(200, 200); |
|
2774 |
view.show(); |
|
2775 |
QTest::qWaitForWindowShown(&view); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2776 |
QTRY_COMPARE(PolishWidget::numberOfPolish, 2); |
0 | 2777 |
} |
2778 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2779 |
void tst_QGraphicsWidget::polishEvent() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2780 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2781 |
class MyGraphicsWidget : public QGraphicsWidget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2782 |
{ public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2783 |
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2784 |
{ events << QEvent::Paint; } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2785 |
void polishEvent() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2786 |
{ events << QEvent::Polish; } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2787 |
QList<QEvent::Type> events; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2788 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2789 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2790 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2791 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2792 |
MyGraphicsWidget *widget = new MyGraphicsWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2793 |
scene.addItem(widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2794 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2795 |
QGraphicsView view(&scene); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2796 |
view.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2797 |
QTest::qWaitForWindowShown(&view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2798 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2799 |
// Make sure the item is painted. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2800 |
QTRY_VERIFY(widget->events.contains(QEvent::Paint)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2801 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2802 |
// Make sure the item got polish before paint. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2803 |
QCOMPARE(widget->events.at(0), QEvent::Polish); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2804 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2805 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2806 |
void tst_QGraphicsWidget::polishEvent2() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2807 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2808 |
class MyGraphicsWidget : public QGraphicsWidget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2809 |
{ public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2810 |
void polishEvent() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2811 |
{ events << QEvent::Polish; } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2812 |
QList<QEvent::Type> events; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2813 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2814 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2815 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2816 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2817 |
MyGraphicsWidget *widget = new MyGraphicsWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2818 |
widget->hide(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2819 |
scene.addItem(widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2820 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2821 |
widget->events.clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2822 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2823 |
// Make sure the item got polish event. |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2824 |
QTRY_VERIFY(widget->events.contains(QEvent::Polish)); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2825 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2826 |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2827 |
void tst_QGraphicsWidget::initialShow() |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2828 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2829 |
class MyGraphicsWidget : public QGraphicsWidget |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2830 |
{ public: |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2831 |
MyGraphicsWidget() : repaints(0) {} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2832 |
int repaints; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2833 |
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget*) { ++repaints; } |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2834 |
void polishEvent() { update(); } |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2835 |
}; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2836 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2837 |
QGraphicsScene scene; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2838 |
MyGraphicsWidget *widget = new MyGraphicsWidget; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2839 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2840 |
QGraphicsView view(&scene); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2841 |
view.show(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2842 |
QTest::qWaitForWindowShown(&view); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2843 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2844 |
scene.addItem(widget); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2845 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2846 |
QTRY_COMPARE(widget->repaints, 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2847 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2848 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2849 |
void tst_QGraphicsWidget::initialShow2() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2850 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2851 |
class MyGraphicsWidget : public QGraphicsWidget |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2852 |
{ public: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2853 |
MyGraphicsWidget() : repaints(0) {} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2854 |
int repaints; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2855 |
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget*) { ++repaints; } |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2856 |
void polishEvent() { update(); } |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2857 |
}; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2858 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2859 |
// Don't let paint events triggered by the windowing system |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2860 |
// influence our test case. We're only interested in knowing |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2861 |
// whether a QGraphicsWidget generates an additional repaint |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2862 |
// on the inital show. Hence create a dummy scenario to find out |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2863 |
// how many repaints we should expect. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2864 |
QGraphicsScene dummyScene(0, 0, 200, 200); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2865 |
dummyScene.addItem(new QGraphicsRectItem(0, 0, 100, 100)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2866 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2867 |
QGraphicsView *dummyView = new QGraphicsView(&dummyScene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2868 |
dummyView->setWindowFlags(Qt::X11BypassWindowManagerHint); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2869 |
EventSpy paintSpy(dummyView->viewport(), QEvent::Paint); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2870 |
dummyView->show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2871 |
QTest::qWaitForWindowShown(dummyView); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2872 |
const int expectedRepaintCount = paintSpy.count(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2873 |
delete dummyView; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2874 |
dummyView = 0; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2875 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2876 |
MyGraphicsWidget *widget = new MyGraphicsWidget; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2877 |
widget->resize(100, 100); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2878 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2879 |
QGraphicsScene scene(0, 0, 200, 200); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2880 |
scene.addItem(widget); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2881 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2882 |
QGraphicsView view(&scene); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2883 |
view.setWindowFlags(Qt::X11BypassWindowManagerHint); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2884 |
view.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2885 |
QTest::qWaitForWindowShown(&view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2886 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
2887 |
QTRY_COMPARE(widget->repaints, expectedRepaintCount); |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2888 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2889 |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2890 |
void tst_QGraphicsWidget::itemChangeEvents() |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2891 |
{ |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2892 |
class TestGraphicsWidget : public QGraphicsWidget |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2893 |
{ public: |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2894 |
TestGraphicsWidget() : QGraphicsWidget() {} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2895 |
QHash<QEvent::Type, QVariant> valueDuringEvents; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2896 |
bool event(QEvent *event) { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2897 |
Q_UNUSED(event); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2898 |
switch (event->type()) { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2899 |
case QEvent::EnabledChange: { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2900 |
valueDuringEvents.insert(QEvent::EnabledChange, isEnabled()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2901 |
break; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2902 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2903 |
case QEvent::ParentAboutToChange: { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2904 |
valueDuringEvents.insert(QEvent::ParentAboutToChange, qVariantFromValue(parentItem())); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2905 |
break; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2906 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2907 |
case QEvent::ParentChange: { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2908 |
valueDuringEvents.insert(QEvent::ParentChange, qVariantFromValue(parentItem())); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2909 |
break; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2910 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2911 |
case QEvent::CursorChange: { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2912 |
valueDuringEvents.insert(QEvent::CursorChange, int(cursor().shape())); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2913 |
break; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2914 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2915 |
case QEvent::ToolTipChange: { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2916 |
valueDuringEvents.insert(QEvent::ToolTipChange, toolTip()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2917 |
break; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2918 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2919 |
default: { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2920 |
break; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2921 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2922 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2923 |
return true; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2924 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2925 |
void showEvent(QShowEvent *event) { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2926 |
Q_UNUSED(event); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2927 |
valueDuringEvents.insert(QEvent::Show, isVisible()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2928 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2929 |
void hideEvent(QHideEvent *event) { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2930 |
Q_UNUSED(event); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2931 |
valueDuringEvents.insert(QEvent::Hide, isVisible()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2932 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2933 |
}; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2934 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2935 |
QGraphicsScene scene; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2936 |
QGraphicsView view(&scene); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2937 |
QGraphicsWidget *parent = new QGraphicsWidget; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2938 |
scene.addItem(parent); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2939 |
view.show(); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2940 |
QTest::qWaitForWindowShown(&view); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2941 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2942 |
TestGraphicsWidget *item = new TestGraphicsWidget; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2943 |
item->setParentItem(parent); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2944 |
// ParentAboutToChange should be triggered before the parent has changed |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2945 |
QTRY_COMPARE(qVariantValue<QGraphicsItem *>(item->valueDuringEvents.value(QEvent::ParentAboutToChange)), |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2946 |
static_cast<QGraphicsItem *>(0)); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2947 |
// ParentChange should be triggered after the parent has changed |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2948 |
QTRY_COMPARE(qVariantValue<QGraphicsItem *>(item->valueDuringEvents.value(QEvent::ParentChange)), |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2949 |
static_cast<QGraphicsItem *>(parent)); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2950 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2951 |
// ShowEvent should be triggered before the item is shown |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2952 |
QTRY_VERIFY(!item->valueDuringEvents.value(QEvent::Show).toBool()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2953 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2954 |
// HideEvent should be triggered after the item is hidden |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2955 |
QVERIFY(item->isVisible()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2956 |
item->setVisible(false); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2957 |
QVERIFY(!item->isVisible()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2958 |
QTRY_VERIFY(!item->valueDuringEvents.value(QEvent::Hide).toBool()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2959 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2960 |
// CursorChange should be triggered after the cursor has changed |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2961 |
item->setCursor(Qt::PointingHandCursor); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2962 |
QTRY_COMPARE(item->valueDuringEvents.value(QEvent::CursorChange).toInt(), int(item->cursor().shape())); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2963 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2964 |
// ToolTipChange should be triggered after the tooltip has changed |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2965 |
item->setToolTip("tooltipText"); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2966 |
QTRY_COMPARE(item->valueDuringEvents.value(QEvent::ToolTipChange).toString(), item->toolTip()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2967 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2968 |
// EnabledChange should be triggered after the enabled state has changed |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2969 |
QVERIFY(item->isEnabled()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2970 |
item->setEnabled(false); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2971 |
QVERIFY(!item->isEnabled()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2972 |
QTRY_VERIFY(!item->valueDuringEvents.value(QEvent::EnabledChange).toBool()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2973 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
7
diff
changeset
|
2974 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2975 |
void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2976 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2977 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2978 |
QGraphicsWidget* parent1 = new QGraphicsWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2979 |
QGraphicsWidget* child1_0 = new QGraphicsWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2980 |
QGraphicsWidget* child1_1 = new QGraphicsWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2981 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2982 |
QGraphicsWidget* parent2 = new QGraphicsWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2983 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2984 |
// Add the parent and child to the scene. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2985 |
scene.addItem(parent1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2986 |
child1_0->setParentItem(parent1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2987 |
child1_1->setParentItem(parent1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2988 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2989 |
// Hide and show the child. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2990 |
child1_0->setParentItem(NULL); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2991 |
scene.removeItem(child1_0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2992 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2993 |
// Remove parent from the scene. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2994 |
scene.removeItem(parent1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2995 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2996 |
delete child1_0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2997 |
delete child1_1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2998 |
delete parent1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2999 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3000 |
// Add an item into the scene. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3001 |
scene.addItem(parent2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3002 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3003 |
//This should not crash |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3004 |
} |
0 | 3005 |
|
3006 |
QTEST_MAIN(tst_QGraphicsWidget) |
|
3007 |
#include "tst_qgraphicswidget.moc" |
|
3008 |
||
3009 |
#else // QT_NO_STYLE_CLEANLOOKS |
|
3010 |
QTEST_NOOP_MAIN |
|
3011 |
#endif |
|
3012 |