author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 4 | 3b1da2848fc7 |
child 13 | c0432d11811c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <QtGui> |
|
45 |
#include "../../shared/util.h" |
|
46 |
#include <private/qlayoutengine_p.h> // qSmartMin functions... |
|
47 |
#if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) |
|
48 |
#include <QMacStyle> |
|
49 |
#endif |
|
50 |
#ifdef Q_WS_X11 |
|
51 |
#include <private/qt_x11_p.h> |
|
52 |
#endif |
|
53 |
||
54 |
static void sendMouseMove(QWidget *widget, const QPoint &point, Qt::MouseButton button = Qt::NoButton) |
|
55 |
{ |
|
56 |
QMouseEvent event(QEvent::MouseMove, point, widget->mapToGlobal(point), button, button, 0); |
|
57 |
QApplication::sendEvent(widget, &event); |
|
58 |
} |
|
59 |
||
60 |
||
61 |
#ifndef QT_NO_STYLE_CLEANLOOKS |
|
62 |
/* |
|
63 |
Notes: |
|
64 |
||
65 |
1) The proxy and the widget geometries are linked. |
|
66 |
proxy resize => widget resize => stop (no livelock) |
|
67 |
widget resize => proxy resize => stop (no livelock) |
|
68 |
||
69 |
2) As far as possible, the properties are linked. |
|
70 |
proxy enable => widget enable => stop |
|
71 |
widget disabled => proxy disabled => stop |
|
72 |
||
73 |
3) Windowed state is linked |
|
74 |
Windowed proxy state => windowed widget state => stop |
|
75 |
Windowed widget state => windowed proxy state => stop |
|
76 |
*/ |
|
77 |
||
78 |
class EventSpy : public QObject |
|
79 |
{ |
|
80 |
public: |
|
81 |
EventSpy(QObject *receiver) |
|
82 |
{ |
|
83 |
receiver->installEventFilter(this); |
|
84 |
} |
|
85 |
||
86 |
QMap<QEvent::Type, int> counts; |
|
87 |
||
88 |
protected: |
|
89 |
bool eventFilter(QObject *, QEvent *event) |
|
90 |
{ |
|
91 |
++counts[event->type()]; |
|
92 |
return false; |
|
93 |
} |
|
94 |
}; |
|
95 |
||
96 |
class tst_QGraphicsProxyWidget : public QObject |
|
97 |
{ |
|
98 |
Q_OBJECT |
|
99 |
||
100 |
public slots: |
|
101 |
void initTestCase(); |
|
102 |
void cleanupTestCase(); |
|
103 |
void init(); |
|
104 |
void cleanup(); |
|
105 |
||
106 |
private slots: |
|
107 |
void qgraphicsproxywidget_data(); |
|
108 |
void qgraphicsproxywidget(); |
|
109 |
void paint(); |
|
110 |
void paint_2(); |
|
111 |
void setWidget_data(); |
|
112 |
void setWidget(); |
|
113 |
void eventFilter_data(); |
|
114 |
void eventFilter(); |
|
115 |
void focusInEvent_data(); |
|
116 |
void focusInEvent(); |
|
117 |
void focusInEventNoWidget(); |
|
118 |
void focusNextPrevChild_data(); |
|
119 |
void focusNextPrevChild(); |
|
120 |
void focusOutEvent_data(); |
|
121 |
void focusOutEvent(); |
|
122 |
void hoverEnterLeaveEvent_data(); |
|
123 |
void hoverEnterLeaveEvent(); |
|
124 |
void hoverMoveEvent_data(); |
|
125 |
void hoverMoveEvent(); |
|
126 |
void keyPressEvent_data(); |
|
127 |
void keyPressEvent(); |
|
128 |
void keyReleaseEvent_data(); |
|
129 |
void keyReleaseEvent(); |
|
130 |
void mouseDoubleClickEvent_data(); |
|
131 |
void mouseDoubleClickEvent(); |
|
132 |
void mousePressReleaseEvent_data(); |
|
133 |
void mousePressReleaseEvent(); |
|
134 |
void resizeEvent_data(); |
|
135 |
void resizeEvent(); |
|
136 |
void paintEvent(); |
|
137 |
void wheelEvent(); |
|
138 |
void sizeHint_data(); |
|
139 |
void sizeHint(); |
|
140 |
void sizePolicy(); |
|
141 |
void minimumSize(); |
|
142 |
void maximumSize(); |
|
143 |
void scrollUpdate(); |
|
144 |
void setWidget_simple(); |
|
145 |
void setWidget_ownership(); |
|
146 |
void resize_simple_data(); |
|
147 |
void resize_simple(); |
|
148 |
void symmetricMove(); |
|
149 |
void symmetricResize(); |
|
150 |
void symmetricEnabled(); |
|
151 |
void symmetricVisible(); |
|
152 |
void tabFocus_simpleWidget(); |
|
153 |
void tabFocus_simpleTwoWidgets(); |
|
154 |
void tabFocus_complexWidget(); |
|
155 |
void tabFocus_complexTwoWidgets(); |
|
156 |
void setFocus_simpleWidget(); |
|
157 |
void setFocus_simpleTwoWidgets(); |
|
158 |
void setFocus_complexTwoWidgets(); |
|
159 |
void popup_basic(); |
|
160 |
void popup_subwidget(); |
|
161 |
void changingCursor_basic(); |
|
162 |
void tooltip_basic(); |
|
163 |
void childPos_data(); |
|
164 |
void childPos(); |
|
165 |
void autoShow(); |
|
166 |
void windowOpacity(); |
|
167 |
void stylePropagation(); |
|
168 |
void palettePropagation(); |
|
169 |
void fontPropagation(); |
|
170 |
void dontCrashWhenDie(); |
|
171 |
void createProxyForChildWidget(); |
|
172 |
void actionsContextMenu(); |
|
173 |
void actionsContextMenu_data(); |
|
174 |
void deleteProxyForChildWidget(); |
|
175 |
void bypassGraphicsProxyWidget_data(); |
|
176 |
void bypassGraphicsProxyWidget(); |
|
177 |
void dragDrop(); |
|
178 |
void windowFlags_data(); |
|
179 |
void windowFlags(); |
|
180 |
void comboboxWindowFlags(); |
|
181 |
void updateAndDelete(); |
|
182 |
void inputMethod(); |
|
183 |
void clickFocus(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
184 |
void windowFrameMargins(); |
0 | 185 |
}; |
186 |
||
187 |
// Subclass that exposes the protected functions. |
|
188 |
class SubQGraphicsProxyWidget : public QGraphicsProxyWidget |
|
189 |
{ |
|
190 |
||
191 |
public: |
|
192 |
SubQGraphicsProxyWidget(QGraphicsItem *parent = 0) : QGraphicsProxyWidget(parent), |
|
193 |
paintCount(0), keyPress(0), focusOut(0) |
|
194 |
{} |
|
195 |
||
196 |
bool call_eventFilter(QObject* object, QEvent* event) |
|
197 |
{ return SubQGraphicsProxyWidget::eventFilter(object, event); } |
|
198 |
||
199 |
void call_focusInEvent(QFocusEvent* event) |
|
200 |
{ return SubQGraphicsProxyWidget::focusInEvent(event); } |
|
201 |
||
202 |
bool call_focusNextPrevChild(bool next) |
|
203 |
{ return SubQGraphicsProxyWidget::focusNextPrevChild(next); } |
|
204 |
||
205 |
void call_focusOutEvent(QFocusEvent* event) |
|
206 |
{ return SubQGraphicsProxyWidget::focusOutEvent(event); } |
|
207 |
||
208 |
void call_hideEvent(QHideEvent* event) |
|
209 |
{ return SubQGraphicsProxyWidget::hideEvent(event); } |
|
210 |
||
211 |
void call_hoverEnterEvent(QGraphicsSceneHoverEvent* event) |
|
212 |
{ return SubQGraphicsProxyWidget::hoverEnterEvent(event); } |
|
213 |
||
214 |
void call_hoverLeaveEvent(QGraphicsSceneHoverEvent* event) |
|
215 |
{ return SubQGraphicsProxyWidget::hoverLeaveEvent(event); } |
|
216 |
||
217 |
void call_hoverMoveEvent(QGraphicsSceneHoverEvent* event) |
|
218 |
{ return SubQGraphicsProxyWidget::hoverMoveEvent(event); } |
|
219 |
||
220 |
void call_keyPressEvent(QKeyEvent* event) |
|
221 |
{ return SubQGraphicsProxyWidget::keyPressEvent(event); } |
|
222 |
||
223 |
void call_keyReleaseEvent(QKeyEvent* event) |
|
224 |
{ return SubQGraphicsProxyWidget::keyReleaseEvent(event); } |
|
225 |
||
226 |
void call_mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) |
|
227 |
{ return SubQGraphicsProxyWidget::mouseDoubleClickEvent(event); } |
|
228 |
||
229 |
void call_mouseMoveEvent(QGraphicsSceneMouseEvent* event) |
|
230 |
{ return SubQGraphicsProxyWidget::mouseMoveEvent(event); } |
|
231 |
||
232 |
void call_mousePressEvent(QGraphicsSceneMouseEvent* event) |
|
233 |
{ return SubQGraphicsProxyWidget::mousePressEvent(event); } |
|
234 |
||
235 |
void call_mouseReleaseEvent(QGraphicsSceneMouseEvent* event) |
|
236 |
{ return SubQGraphicsProxyWidget::mouseReleaseEvent(event); } |
|
237 |
||
238 |
void call_resizeEvent(QGraphicsSceneResizeEvent* event) |
|
239 |
{ return SubQGraphicsProxyWidget::resizeEvent(event); } |
|
240 |
||
241 |
QSizeF call_sizeHint(Qt::SizeHint which, QSizeF const& constraint = QSizeF()) const |
|
242 |
{ return SubQGraphicsProxyWidget::sizeHint(which, constraint); } |
|
243 |
||
244 |
void call_showEvent(QShowEvent* event) |
|
245 |
{ return SubQGraphicsProxyWidget::showEvent(event); } |
|
246 |
||
247 |
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) { |
|
248 |
paintCount++; |
|
249 |
QGraphicsProxyWidget::paint(painter, option, widget); |
|
250 |
} |
|
251 |
||
252 |
void focusOutEvent(QFocusEvent *event) |
|
253 |
{ |
|
254 |
focusOut++; |
|
255 |
QGraphicsProxyWidget::focusOutEvent(event); |
|
256 |
} |
|
257 |
||
258 |
bool eventFilter(QObject *object, QEvent *event) { |
|
259 |
if (event->type() == QEvent::KeyPress && object == widget()) |
|
260 |
keyPress++; |
|
261 |
return QGraphicsProxyWidget::eventFilter(object, event); |
|
262 |
} |
|
263 |
int paintCount; |
|
264 |
int keyPress; |
|
265 |
int focusOut; |
|
266 |
}; |
|
267 |
||
268 |
class WheelWidget : public QWidget |
|
269 |
{ |
|
270 |
public: |
|
271 |
WheelWidget() : wheelEventCalled(false) { setFocusPolicy(Qt::WheelFocus); } |
|
272 |
||
273 |
virtual void wheelEvent(QWheelEvent *event) { event->accept(); wheelEventCalled = true; } |
|
274 |
||
275 |
bool wheelEventCalled; |
|
276 |
}; |
|
277 |
||
278 |
// This will be called before the first test function is executed. |
|
279 |
// It is only called once. |
|
280 |
void tst_QGraphicsProxyWidget::initTestCase() |
|
281 |
{ |
|
282 |
#ifdef Q_OS_WINCE //disable magic for WindowsCE |
|
283 |
qApp->setAutoMaximizeThreshold(-1); |
|
284 |
#endif |
|
285 |
} |
|
286 |
||
287 |
// This will be called after the last test function is executed. |
|
288 |
// It is only called once. |
|
289 |
void tst_QGraphicsProxyWidget::cleanupTestCase() |
|
290 |
{ |
|
291 |
} |
|
292 |
||
293 |
// This will be called before each test function is executed. |
|
294 |
void tst_QGraphicsProxyWidget::init() |
|
295 |
{ |
|
296 |
} |
|
297 |
||
298 |
// This will be called after every test function. |
|
299 |
void tst_QGraphicsProxyWidget::cleanup() |
|
300 |
{ |
|
301 |
} |
|
302 |
||
303 |
void tst_QGraphicsProxyWidget::qgraphicsproxywidget_data() |
|
304 |
{ |
|
305 |
} |
|
306 |
||
307 |
void tst_QGraphicsProxyWidget::qgraphicsproxywidget() |
|
308 |
{ |
|
309 |
SubQGraphicsProxyWidget proxy; |
|
310 |
proxy.paint(0, 0, 0); |
|
311 |
proxy.setWidget(0); |
|
312 |
QVERIFY(proxy.type() == QGraphicsProxyWidget::Type); |
|
313 |
QVERIFY(!proxy.widget()); |
|
314 |
QEvent event(QEvent::None); |
|
315 |
proxy.call_eventFilter(0, &event); |
|
316 |
QFocusEvent focusEvent(QEvent::FocusIn); |
|
317 |
focusEvent.ignore(); |
|
318 |
proxy.call_focusInEvent(&focusEvent); |
|
319 |
QCOMPARE(focusEvent.isAccepted(), false); |
|
320 |
QCOMPARE(proxy.call_focusNextPrevChild(false), false); |
|
321 |
QCOMPARE(proxy.call_focusNextPrevChild(true), false); |
|
322 |
proxy.call_focusOutEvent(&focusEvent); |
|
323 |
QHideEvent hideEvent; |
|
324 |
proxy.call_hideEvent(&hideEvent); |
|
325 |
QGraphicsSceneHoverEvent hoverEvent; |
|
326 |
proxy.call_hoverEnterEvent(&hoverEvent); |
|
327 |
proxy.call_hoverLeaveEvent(&hoverEvent); |
|
328 |
proxy.call_hoverMoveEvent(&hoverEvent); |
|
329 |
QKeyEvent keyEvent(QEvent::KeyPress, 0, Qt::NoModifier); |
|
330 |
proxy.call_keyPressEvent(&keyEvent); |
|
331 |
proxy.call_keyReleaseEvent(&keyEvent); |
|
332 |
QGraphicsSceneMouseEvent mouseEvent; |
|
333 |
proxy.call_mouseDoubleClickEvent(&mouseEvent); |
|
334 |
proxy.call_mouseMoveEvent(&mouseEvent); |
|
335 |
proxy.call_mousePressEvent(&mouseEvent); |
|
336 |
proxy.call_mouseReleaseEvent(&mouseEvent); |
|
337 |
QGraphicsSceneResizeEvent resizeEvent; |
|
338 |
proxy.call_resizeEvent(&resizeEvent); |
|
339 |
QShowEvent showEvent; |
|
340 |
proxy.call_showEvent(&showEvent); |
|
341 |
proxy.call_sizeHint(Qt::PreferredSize, QSizeF()); |
|
342 |
} |
|
343 |
||
344 |
// public void paint(QPainter* painter, QStyleOptionGraphicsItem const* option, QWidget* widget) |
|
345 |
void tst_QGraphicsProxyWidget::paint() |
|
346 |
{ |
|
347 |
SubQGraphicsProxyWidget proxy; |
|
348 |
proxy.paint(0, 0, 0); |
|
349 |
} |
|
350 |
||
351 |
class MyProxyWidget : public QGraphicsProxyWidget |
|
352 |
{ |
|
353 |
public: |
|
354 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
355 |
{ |
|
356 |
// Make sure QGraphicsProxyWidget::paint does not modify the render hints set on the painter. |
|
357 |
painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform |
|
358 |
| QPainter::NonCosmeticDefaultPen | QPainter::TextAntialiasing); |
|
359 |
const QPainter::RenderHints oldRenderHints = painter->renderHints(); |
|
360 |
QGraphicsProxyWidget::paint(painter, option, widget); |
|
361 |
QCOMPARE(painter->renderHints(), oldRenderHints); |
|
362 |
} |
|
363 |
}; |
|
364 |
||
365 |
void tst_QGraphicsProxyWidget::paint_2() |
|
366 |
{ |
|
367 |
MyProxyWidget *proxyWidget = new MyProxyWidget; |
|
368 |
proxyWidget->setWidget(new QLineEdit); |
|
369 |
||
370 |
QGraphicsScene scene; |
|
371 |
scene.addItem(proxyWidget); |
|
372 |
scene.setSceneRect(scene.itemsBoundingRect()); |
|
373 |
||
374 |
// Trigger repaint. |
|
375 |
QPixmap pixmap(scene.sceneRect().toRect().size()); |
|
376 |
QPainter painter(&pixmap); |
|
377 |
scene.render(&painter); |
|
378 |
} |
|
379 |
||
380 |
void tst_QGraphicsProxyWidget::setWidget_data() |
|
381 |
{ |
|
382 |
QTest::addColumn<bool>("widgetExists"); |
|
383 |
QTest::addColumn<bool>("insertWidget"); |
|
384 |
QTest::addColumn<bool>("hasParent"); |
|
385 |
QTest::addColumn<bool>("proxyHasParent"); |
|
386 |
||
387 |
QTest::newRow("setWidget(0)") << false << false << false << false; |
|
388 |
QTest::newRow("setWidget(widget)") << false << true << false << false; |
|
389 |
QTest::newRow("setWidget(widgetWParent)") << false << true << true << false; |
|
390 |
QTest::newRow("setWidget(1), setWidget(0)") << true << false << false << false; |
|
391 |
QTest::newRow("setWidget(1), setWidget(widget)") << true << true << false << false; |
|
392 |
QTest::newRow("setWidget(1), setWidget(widgetWParent)") << true << true << true << false; |
|
393 |
QTest::newRow("p setWidget(0)") << false << false << false << true; |
|
394 |
QTest::newRow("p setWidget(widget)") << false << true << false << true; |
|
395 |
QTest::newRow("p setWidget(widgetWParent)") << false << true << true << true; |
|
396 |
QTest::newRow("p setWidget(1), setWidget(0)") << true << false << false << true; |
|
397 |
QTest::newRow("p setWidget(1), setWidget(widget)") << true << true << false << true; |
|
398 |
QTest::newRow("p setWidget(1), setWidget(widgetWParent)") << true << true << true << true; |
|
399 |
} |
|
400 |
||
401 |
// public void setWidget(QWidget* widget) |
|
402 |
void tst_QGraphicsProxyWidget::setWidget() |
|
403 |
{ |
|
404 |
QFETCH(bool, widgetExists); |
|
405 |
QFETCH(bool, insertWidget); |
|
406 |
QFETCH(bool, hasParent); |
|
407 |
QFETCH(bool, proxyHasParent); |
|
408 |
||
409 |
QGraphicsScene scene; |
|
410 |
QGraphicsView view(&scene); |
|
411 |
view.show(); |
|
412 |
#ifdef Q_WS_X11 |
|
413 |
qt_x11_wait_for_window_manager(&view); |
|
414 |
#endif |
|
415 |
QPointer<SubQGraphicsProxyWidget> proxy = new SubQGraphicsProxyWidget; |
|
416 |
SubQGraphicsProxyWidget parentProxy; |
|
417 |
scene.addItem(proxy); |
|
418 |
scene.addItem(&parentProxy); |
|
419 |
if (proxyHasParent) |
|
420 |
proxy->setParent(&parentProxy); |
|
421 |
QPointer<QWidget> existingSubWidget = new QWidget; |
|
422 |
proxy->setVisible(false); |
|
423 |
proxy->setEnabled(false); |
|
424 |
||
425 |
if (widgetExists) { |
|
426 |
existingSubWidget->setAttribute(Qt::WA_QuitOnClose, true); |
|
427 |
proxy->setWidget(existingSubWidget); |
|
428 |
} |
|
429 |
||
430 |
QWidget *widget = new QWidget; |
|
431 |
#ifndef QT_NO_CURSOR |
|
432 |
widget->setCursor(Qt::IBeamCursor); |
|
433 |
#endif |
|
434 |
widget->setPalette(QPalette(Qt::magenta)); |
|
435 |
widget->setLayoutDirection(Qt::RightToLeft); |
|
436 |
QCleanlooksStyle cleanlooksStyle; |
|
437 |
widget->setStyle(&cleanlooksStyle); |
|
438 |
widget->setFont(QFont("Times")); |
|
439 |
widget->setVisible(true); |
|
440 |
QApplication::setActiveWindow(widget); |
|
441 |
widget->activateWindow(); |
|
442 |
widget->setEnabled(true); |
|
443 |
widget->resize(325, 241); |
|
444 |
widget->setMinimumSize(100, 200); |
|
445 |
widget->setMaximumSize(1000, 2000); |
|
446 |
widget->setFocusPolicy(Qt::TabFocus); |
|
447 |
widget->setContentsMargins(10, 29, 19, 81); |
|
448 |
widget->setFocus(Qt::TabFocusReason); |
|
449 |
widget->setAcceptDrops(true); |
|
450 |
QTRY_VERIFY(widget->hasFocus()); |
|
451 |
QVERIFY(widget->isActiveWindow()); |
|
452 |
||
453 |
QWidget parentWidget; |
|
454 |
if (hasParent) |
|
455 |
widget->setParent(&parentWidget); |
|
456 |
||
457 |
QWidget *subWidget = insertWidget ? widget : 0; |
|
458 |
bool shouldBeInsertable = !hasParent && subWidget; |
|
459 |
if (shouldBeInsertable) |
|
460 |
subWidget->setAttribute(Qt::WA_QuitOnClose, true); |
|
461 |
||
462 |
proxy->setWidget(subWidget); |
|
463 |
||
464 |
if (shouldBeInsertable) { |
|
465 |
QCOMPARE(proxy->widget(), subWidget); |
|
466 |
QVERIFY(subWidget->testAttribute(Qt::WA_DontShowOnScreen)); |
|
467 |
QVERIFY(!subWidget->testAttribute(Qt::WA_QuitOnClose)); |
|
468 |
QCOMPARE(proxy->acceptHoverEvents(), true); |
|
469 |
#ifndef QT_NO_CURSOR |
|
470 |
QVERIFY(proxy->hasCursor()); |
|
471 |
||
472 |
// These should match |
|
473 |
QCOMPARE(proxy->cursor().shape(), widget->cursor().shape()); |
|
474 |
#endif |
|
475 |
//###QCOMPARE(proxy->palette(), widget->palette()); |
|
476 |
QCOMPARE(proxy->layoutDirection(), widget->layoutDirection()); |
|
477 |
QCOMPARE(proxy->style(), widget->style()); |
|
478 |
QCOMPARE(proxy->isVisible(), widget->isVisible()); |
|
479 |
QCOMPARE(proxy->isEnabled(), widget->isEnabled()); |
|
480 |
QVERIFY(proxy->flags() & QGraphicsItem::ItemIsFocusable); |
|
481 |
QCOMPARE(proxy->effectiveSizeHint(Qt::MinimumSize).toSize(), |
|
482 |
qSmartMinSize(widget)); |
|
483 |
QCOMPARE(proxy->minimumSize().toSize(), |
|
484 |
qSmartMinSize(widget) ); |
|
485 |
QCOMPARE(proxy->maximumSize().toSize(), QSize(1000, 2000)); |
|
486 |
QCOMPARE(proxy->effectiveSizeHint(Qt::PreferredSize).toSize(), |
|
487 |
qSmartMinSize(widget)); |
|
488 |
QCOMPARE(proxy->size().toSize(), widget->size()); |
|
489 |
QCOMPARE(proxy->rect().toRect(), widget->rect()); |
|
490 |
QCOMPARE(proxy->focusPolicy(), Qt::WheelFocus); |
|
491 |
QVERIFY(proxy->acceptDrops()); |
|
492 |
QCOMPARE(proxy->acceptsHoverEvents(), true); // to get widget enter events |
|
493 |
int left, top, right, bottom; |
|
494 |
widget->getContentsMargins(&left, &top, &right, &bottom); |
|
495 |
qreal rleft, rtop, rright, rbottom; |
|
496 |
proxy->getContentsMargins(&rleft, &rtop, &rright, &rbottom); |
|
497 |
QCOMPARE((qreal)left, rleft); |
|
498 |
QCOMPARE((qreal)top, rtop); |
|
499 |
QCOMPARE((qreal)right, rright); |
|
500 |
QCOMPARE((qreal)bottom, rbottom); |
|
501 |
} else { |
|
502 |
// proxy shouldn't mess with the widget if it can't insert it. |
|
503 |
QCOMPARE(proxy->widget(), (QWidget*)0); |
|
504 |
QCOMPARE(proxy->acceptHoverEvents(), false); |
|
505 |
if (subWidget) { |
|
506 |
QVERIFY(!subWidget->testAttribute(Qt::WA_DontShowOnScreen)); |
|
507 |
QVERIFY(subWidget->testAttribute(Qt::WA_QuitOnClose)); |
|
508 |
// reset |
|
509 |
subWidget->setAttribute(Qt::WA_QuitOnClose, false); |
|
510 |
} |
|
511 |
} |
|
512 |
||
513 |
if (widgetExists) { |
|
514 |
QCOMPARE(existingSubWidget->parent(), static_cast<QObject*>(0)); |
|
515 |
QVERIFY(!existingSubWidget->testAttribute(Qt::WA_DontShowOnScreen)); |
|
516 |
QVERIFY(!existingSubWidget->testAttribute(Qt::WA_QuitOnClose)); |
|
517 |
} |
|
518 |
||
519 |
if (hasParent) |
|
520 |
widget->setParent(0); |
|
521 |
||
522 |
delete widget; |
|
523 |
if (shouldBeInsertable) |
|
524 |
QVERIFY(!proxy); |
|
525 |
delete existingSubWidget; |
|
526 |
if (!shouldBeInsertable) { |
|
527 |
QVERIFY(proxy); |
|
528 |
delete proxy; |
|
529 |
} |
|
530 |
QVERIFY(!proxy); |
|
531 |
} |
|
532 |
||
533 |
Q_DECLARE_METATYPE(QEvent::Type) |
|
534 |
void tst_QGraphicsProxyWidget::eventFilter_data() |
|
535 |
{ |
|
536 |
QTest::addColumn<QEvent::Type>("eventType"); |
|
537 |
QTest::addColumn<bool>("fromObject"); // big grin evil |
|
538 |
QTest::newRow("none") << QEvent::None << false; |
|
539 |
for (int i = 0; i < 2; ++i) { |
|
540 |
bool fromObject = (i == 0); |
|
541 |
QTest::newRow(QString("resize %1").arg(fromObject).toLatin1()) << QEvent::Resize << fromObject; |
|
542 |
QTest::newRow(QString("move %1").arg(fromObject).toLatin1()) << QEvent::Move << fromObject; |
|
543 |
QTest::newRow(QString("hide %1").arg(fromObject).toLatin1()) << QEvent::Hide << fromObject; |
|
544 |
QTest::newRow(QString("show %1").arg(fromObject).toLatin1()) << QEvent::Show << fromObject; |
|
545 |
QTest::newRow(QString("enabled %1").arg(fromObject).toLatin1()) << QEvent::EnabledChange << fromObject; |
|
546 |
QTest::newRow(QString("focusIn %1").arg(fromObject).toLatin1()) << QEvent::FocusIn << fromObject; |
|
547 |
QTest::newRow(QString("focusOut %1").arg(fromObject).toLatin1()) << QEvent::FocusOut << fromObject; |
|
548 |
QTest::newRow(QString("keyPress %1").arg(fromObject).toLatin1()) << QEvent::KeyPress << fromObject; |
|
549 |
} |
|
550 |
} |
|
551 |
||
552 |
// protected bool eventFilter(QObject* object, QEvent* event) |
|
553 |
void tst_QGraphicsProxyWidget::eventFilter() |
|
554 |
{ |
|
555 |
QFETCH(QEvent::Type, eventType); |
|
556 |
QFETCH(bool, fromObject); |
|
557 |
||
558 |
QGraphicsScene scene; |
|
559 |
QEvent windowActivate(QEvent::WindowActivate); |
|
560 |
qApp->sendEvent(&scene, &windowActivate); |
|
561 |
||
562 |
SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; |
|
563 |
scene.addItem(proxy); |
|
564 |
||
565 |
QWidget *widget = new QWidget(0, Qt::FramelessWindowHint); |
|
566 |
widget->setFocusPolicy(Qt::TabFocus); |
|
567 |
widget->resize(10, 10); |
|
568 |
widget->show(); |
|
569 |
proxy->setWidget(widget); |
|
570 |
proxy->show(); |
|
571 |
||
572 |
// mirror whatever is happening to the widget |
|
573 |
// don't get in a loop |
|
574 |
switch (eventType) { |
|
575 |
case QEvent::None: { |
|
576 |
QEvent event(QEvent::None); |
|
577 |
proxy->call_eventFilter(widget, &event); |
|
578 |
break; |
|
579 |
} |
|
580 |
case QEvent::Resize: { |
|
581 |
QSize oldSize = widget->size(); |
|
582 |
QSize newSize = QSize(100, 100); |
|
583 |
if (fromObject) { |
|
584 |
widget->resize(newSize); |
|
585 |
} else { |
|
586 |
proxy->resize(newSize); |
|
587 |
} |
|
588 |
QCOMPARE(proxy->size().toSize(), newSize); |
|
589 |
QCOMPARE(widget->size(), newSize); |
|
590 |
break; |
|
591 |
} |
|
592 |
case QEvent::Move: { |
|
593 |
QPoint oldPoint = widget->pos(); |
|
594 |
QPoint newPoint = QPoint(100, 100); |
|
595 |
if (fromObject) { |
|
596 |
widget->move(newPoint); |
|
597 |
} else { |
|
598 |
proxy->setPos(newPoint); |
|
599 |
} |
|
600 |
QCOMPARE(proxy->pos().toPoint(), newPoint); |
|
601 |
QCOMPARE(widget->pos(), newPoint); |
|
602 |
break; |
|
603 |
} |
|
604 |
case QEvent::Hide: { |
|
605 |
// A hide event can only come from a widget |
|
606 |
if (fromObject) { |
|
607 |
widget->setFocus(Qt::TabFocusReason); |
|
608 |
widget->hide(); |
|
609 |
} else { |
|
610 |
QHideEvent event; |
|
611 |
proxy->call_eventFilter(widget, &event); |
|
612 |
} |
|
613 |
QCOMPARE(proxy->isVisible(), false); |
|
614 |
break; |
|
615 |
} |
|
616 |
case QEvent::Show: { |
|
617 |
// A show event can either come from a widget or somewhere else |
|
618 |
widget->hide(); |
|
619 |
if (fromObject) { |
|
620 |
widget->show(); |
|
621 |
} else { |
|
622 |
QShowEvent event; |
|
623 |
proxy->call_eventFilter(widget, &event); |
|
624 |
} |
|
625 |
QCOMPARE(proxy->isVisible(), true); |
|
626 |
break; |
|
627 |
} |
|
628 |
case QEvent::EnabledChange: { |
|
629 |
widget->setEnabled(false); |
|
630 |
proxy->setEnabled(false); |
|
631 |
if (fromObject) { |
|
632 |
widget->setEnabled(true); |
|
633 |
QCOMPARE(proxy->isEnabled(), true); |
|
634 |
widget->setEnabled(false); |
|
635 |
QCOMPARE(proxy->isEnabled(), false); |
|
636 |
} else { |
|
637 |
QEvent event(QEvent::EnabledChange); |
|
638 |
proxy->call_eventFilter(widget, &event); |
|
639 |
// match the widget not the event |
|
640 |
QCOMPARE(proxy->isEnabled(), false); |
|
641 |
} |
|
642 |
break; |
|
643 |
} |
|
644 |
case QEvent::FocusIn: { |
|
645 |
if (fromObject) { |
|
646 |
widget->setFocus(Qt::TabFocusReason); |
|
647 |
QVERIFY(proxy->hasFocus()); |
|
648 |
} |
|
649 |
break; |
|
650 |
} |
|
651 |
case QEvent::FocusOut: { |
|
652 |
widget->setFocus(Qt::TabFocusReason); |
|
653 |
QVERIFY(proxy->hasFocus()); |
|
654 |
QVERIFY(widget->hasFocus()); |
|
655 |
if (fromObject) { |
|
656 |
widget->clearFocus(); |
|
657 |
QVERIFY(!proxy->hasFocus()); |
|
658 |
} |
|
659 |
break; |
|
660 |
} |
|
661 |
case QEvent::KeyPress: { |
|
662 |
if (fromObject) { |
|
663 |
QTest::keyPress(widget, Qt::Key_A, Qt::NoModifier); |
|
664 |
} else { |
|
665 |
QKeyEvent event(QEvent::KeyPress, Qt::Key_A, Qt::NoModifier); |
|
666 |
proxy->call_eventFilter(widget, &event); |
|
667 |
} |
|
668 |
QCOMPARE(proxy->keyPress, 1); |
|
669 |
break; |
|
670 |
} |
|
671 |
default: |
|
672 |
break; |
|
673 |
} |
|
674 |
} |
|
675 |
||
676 |
void tst_QGraphicsProxyWidget::focusInEvent_data() |
|
677 |
{ |
|
678 |
QTest::addColumn<bool>("widgetHasFocus"); |
|
679 |
QTest::addColumn<bool>("widgetCanHaveFocus"); |
|
680 |
QTest::newRow("no focus, can't get") << false << false; |
|
681 |
QTest::newRow("no focus, can get") << false << true; |
|
682 |
QTest::newRow("has focus, can't get") << true << false; |
|
683 |
QTest::newRow("has focus, can get") << true << true; |
|
684 |
// ### add test for widget having a focusNextPrevChild |
|
685 |
} |
|
686 |
||
687 |
// protected void focusInEvent(QFocusEvent* event) |
|
688 |
void tst_QGraphicsProxyWidget::focusInEvent() |
|
689 |
{ |
|
690 |
// ### This test is just plain old broken |
|
691 |
QFETCH(bool, widgetHasFocus); |
|
692 |
QFETCH(bool, widgetCanHaveFocus); |
|
693 |
||
694 |
QGraphicsScene scene; |
|
695 |
QEvent windowActivate(QEvent::WindowActivate); |
|
696 |
qApp->sendEvent(&scene, &windowActivate); |
|
697 |
||
698 |
SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; |
|
699 |
proxy->setEnabled(true); |
|
700 |
scene.addItem(proxy); |
|
701 |
proxy->setVisible(true); |
|
702 |
||
703 |
QWidget *widget = new QWidget; |
|
704 |
widget->resize(100, 100); |
|
705 |
if (widgetCanHaveFocus) |
|
706 |
widget->setFocusPolicy(Qt::WheelFocus); |
|
707 |
widget->show(); |
|
708 |
||
709 |
if (widgetHasFocus) |
|
710 |
widget->setFocus(Qt::TabFocusReason); |
|
711 |
||
712 |
proxy->setWidget(widget); |
|
713 |
proxy->setFlag(QGraphicsItem::ItemIsFocusable, true); // <- shouldn't need to do this |
|
714 |
||
715 |
// ### This test is just plain old broken - sending a focus in event |
|
716 |
// does not cause items to gain input focus. The widget has focus |
|
717 |
// because the proxy has focus, not because it got this event. |
|
718 |
||
719 |
QFocusEvent event(QEvent::FocusIn, Qt::TabFocusReason); |
|
720 |
event.ignore(); |
|
721 |
proxy->call_focusInEvent(&event); |
|
722 |
QTRY_COMPARE(widget->hasFocus(), widgetCanHaveFocus); |
|
723 |
} |
|
724 |
||
725 |
void tst_QGraphicsProxyWidget::focusInEventNoWidget() |
|
726 |
{ |
|
727 |
QGraphicsView view; |
|
728 |
QGraphicsScene scene(&view); |
|
729 |
SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; |
|
730 |
proxy->setEnabled(true); |
|
731 |
scene.addItem(proxy); |
|
732 |
proxy->setVisible(true); |
|
733 |
view.show(); |
|
734 |
||
735 |
proxy->setFlag(QGraphicsItem::ItemIsFocusable, true); // <- shouldn't need to do this |
|
736 |
QFocusEvent event(QEvent::FocusIn, Qt::TabFocusReason); |
|
737 |
event.ignore(); |
|
738 |
//should not crash |
|
739 |
proxy->call_focusInEvent(&event); |
|
740 |
} |
|
741 |
||
742 |
void tst_QGraphicsProxyWidget::focusNextPrevChild_data() |
|
743 |
{ |
|
744 |
QTest::addColumn<bool>("hasWidget"); |
|
745 |
QTest::addColumn<bool>("hasScene"); |
|
746 |
QTest::addColumn<bool>("next"); |
|
747 |
QTest::addColumn<bool>("focusNextPrevChild"); |
|
748 |
||
749 |
for (int i = 0; i < 2; ++i) { |
|
750 |
for (int j = 0; j < 2; ++j) { |
|
751 |
for (int k = 0; k < 2; ++k) { |
|
752 |
bool next = (i == 0); |
|
753 |
bool hasWidget = (j == 0); |
|
754 |
bool hasScene = (k == 0); |
|
755 |
bool result = hasScene && hasWidget; |
|
756 |
QString name = QString("Forward: %1, hasWidget: %2, hasScene: %3, result: %4").arg(next).arg(hasWidget).arg(hasScene).arg(result); |
|
757 |
QTest::newRow(name.toLatin1()) << hasWidget << hasScene << next << result; |
|
758 |
} |
|
759 |
} |
|
760 |
} |
|
761 |
} |
|
762 |
||
763 |
// protected bool focusNextPrevChild(bool next) |
|
764 |
void tst_QGraphicsProxyWidget::focusNextPrevChild() |
|
765 |
{ |
|
766 |
QFETCH(bool, next); |
|
767 |
QFETCH(bool, focusNextPrevChild); |
|
768 |
QFETCH(bool, hasWidget); |
|
769 |
QFETCH(bool, hasScene); |
|
770 |
||
771 |
// If a widget has its own focusNextPrevChild we need to respect it |
|
772 |
// otherwise respect the scene |
|
773 |
// Respect the widget over the scene! |
|
774 |
||
775 |
SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; |
|
776 |
||
777 |
QLabel *widget = new QLabel; |
|
778 |
// I can't believe designer adds this much junk! |
|
779 |
widget->setText("<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head><body style=\" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;\"> <p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><a href=\"http://www.slashdot.org\"><span style=\" text-decoration: underline; color:#0000ff;\">old</span></a> foo <a href=\"http://www.reddit.org\"><span style=\" text-decoration: underline; color:#0000ff;\">new</span></a></p></body></html>"); |
|
780 |
widget->setTextInteractionFlags(Qt::TextBrowserInteraction); |
|
781 |
||
782 |
if (hasWidget) |
|
783 |
proxy->setWidget(widget); |
|
784 |
||
785 |
QGraphicsScene scene; |
|
786 |
QGraphicsView view(&scene); |
|
787 |
view.show(); |
|
788 |
QApplication::setActiveWindow(&view); |
|
789 |
QTest::qWaitForWindowShown(&view); |
|
790 |
QApplication::processEvents(); |
|
791 |
QTRY_COMPARE(QApplication::activeWindow(), &view); |
|
792 |
if (hasScene) { |
|
793 |
scene.addItem(proxy); |
|
794 |
proxy->show(); |
|
795 |
||
796 |
// widget should take precedence over scene so make scene.focusNextPrevChild return false |
|
797 |
// so we know that a true can only come from the widget |
|
798 |
if (!(hasWidget && hasScene)) { |
|
799 |
QGraphicsTextItem *item = new QGraphicsTextItem("Foo"); |
|
800 |
item->setTextInteractionFlags(Qt::TextBrowserInteraction); |
|
801 |
scene.addItem(item); |
|
802 |
item->setPos(50, 40); |
|
803 |
} |
|
804 |
scene.setFocusItem(proxy); |
|
805 |
QVERIFY(proxy->hasFocus()); |
|
806 |
} |
|
807 |
||
808 |
QCOMPARE(proxy->call_focusNextPrevChild(next), focusNextPrevChild); |
|
809 |
||
810 |
if (!hasScene) |
|
811 |
delete proxy; |
|
812 |
} |
|
813 |
||
814 |
void tst_QGraphicsProxyWidget::focusOutEvent_data() |
|
815 |
{ |
|
816 |
QTest::addColumn<bool>("hasWidget"); |
|
817 |
QTest::addColumn<bool>("call"); |
|
818 |
QTest::newRow("no widget, focus to other widget") << false << false; |
|
819 |
QTest::newRow("no widget, focusOutCalled") << false << true; |
|
820 |
QTest::newRow("widget, focus to other widget") << true << false; |
|
821 |
QTest::newRow("widget, focusOutCalled") << true << true; |
|
822 |
} |
|
823 |
||
824 |
// protected void focusOutEvent(QFocusEvent* event) |
|
825 |
void tst_QGraphicsProxyWidget::focusOutEvent() |
|
826 |
{ |
|
827 |
QFETCH(bool, hasWidget); |
|
828 |
QFETCH(bool, call); |
|
829 |
||
830 |
QGraphicsScene scene; |
|
831 |
QGraphicsView view(&scene); |
|
832 |
SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; |
|
833 |
scene.addItem(proxy); |
|
834 |
view.show(); |
|
835 |
QApplication::setActiveWindow(&view); |
|
836 |
view.activateWindow(); |
|
837 |
view.setFocus(); |
|
838 |
QTest::qWaitForWindowShown(&view); |
|
839 |
QApplication::processEvents(); |
|
840 |
QTRY_VERIFY(view.isVisible()); |
|
841 |
QTRY_COMPARE(QApplication::activeWindow(), &view); |
|
842 |
||
843 |
QWidget *widget = new QWidget; |
|
844 |
widget->setFocusPolicy(Qt::WheelFocus); |
|
845 |
if (hasWidget) |
|
846 |
proxy->setWidget(widget); |
|
847 |
proxy->show(); |
|
848 |
proxy->setFocus(); |
|
849 |
QVERIFY(proxy->hasFocus()); |
|
850 |
QEXPECT_FAIL("widget, focus to other widget", "Widget should have focus but doesn't", Continue); |
|
851 |
QEXPECT_FAIL("widget, focusOutCalled", "Widget should have focus but doesn't", Continue); |
|
852 |
QCOMPARE(widget->hasFocus(), hasWidget); |
|
853 |
||
854 |
if (!call) { |
|
855 |
QWidget *other = new QLineEdit(&view); |
|
856 |
other->show(); |
|
857 |
QApplication::processEvents(); |
|
858 |
QTRY_VERIFY(other->isVisible()); |
|
859 |
other->setFocus(); |
|
860 |
QTRY_VERIFY(other->hasFocus()); |
|
861 |
qApp->processEvents(); |
|
862 |
QTRY_COMPARE(proxy->hasFocus(), false); |
|
863 |
QVERIFY(proxy->focusOut); |
|
864 |
QCOMPARE(widget->hasFocus(), false); |
|
865 |
} else { |
|
866 |
{ |
|
867 |
/* |
|
868 |
### Test doesn't make sense |
|
869 |
QFocusEvent focusEvent(QEvent::FocusOut); |
|
870 |
proxy->call_focusOutEvent(&focusEvent); |
|
871 |
QCOMPARE(focusEvent.isAccepted(), hasWidget); |
|
872 |
qApp->processEvents(); |
|
873 |
QCOMPARE(proxy->paintCount, hasWidget ? 1 : 0); |
|
874 |
*/ |
|
875 |
} |
|
876 |
{ |
|
877 |
/* |
|
878 |
### Test doesn't make sense |
|
879 |
proxy->setFlag(QGraphicsItem::ItemIsFocusable, false); |
|
880 |
QFocusEvent focusEvent(QEvent::FocusOut); |
|
881 |
proxy->call_focusOutEvent(&focusEvent); |
|
882 |
QCOMPARE(focusEvent.isAccepted(), hasWidget); |
|
883 |
qApp->processEvents(); |
|
884 |
QCOMPARE(proxy->paintCount, 0); |
|
885 |
*/ |
|
886 |
} |
|
887 |
} |
|
888 |
} |
|
889 |
||
890 |
class EventLogger : public QWidget |
|
891 |
{ |
|
892 |
public: |
|
893 |
EventLogger() : QWidget(), enterCount(0), leaveCount(0), moveCount(0), |
|
894 |
hoverEnter(0), hoverLeave(0), hoverMove(0) |
|
895 |
{ |
|
896 |
installEventFilter(this); |
|
897 |
} |
|
898 |
||
899 |
void enterEvent(QEvent *event) |
|
900 |
{ |
|
901 |
enterCount++; |
|
902 |
QWidget::enterEvent(event); |
|
903 |
} |
|
904 |
||
905 |
void leaveEvent(QEvent *event ) |
|
906 |
{ |
|
907 |
leaveCount++; |
|
908 |
QWidget::leaveEvent(event); |
|
909 |
} |
|
910 |
||
911 |
void mouseMoveEvent(QMouseEvent *event) |
|
912 |
{ |
|
913 |
event->setAccepted(true); |
|
914 |
moveCount++; |
|
915 |
QWidget::mouseMoveEvent(event); |
|
916 |
} |
|
917 |
||
918 |
int enterCount; |
|
919 |
int leaveCount; |
|
920 |
int moveCount; |
|
921 |
||
922 |
int hoverEnter; |
|
923 |
int hoverLeave; |
|
924 |
int hoverMove; |
|
925 |
protected: |
|
926 |
bool eventFilter(QObject *object, QEvent *event) |
|
927 |
{ |
|
928 |
switch (event->type()) { |
|
929 |
case QEvent::HoverEnter: |
|
930 |
hoverEnter++; |
|
931 |
break; |
|
932 |
case QEvent::HoverLeave: |
|
933 |
hoverLeave++; |
|
934 |
break; |
|
935 |
case QEvent::HoverMove: |
|
936 |
hoverMove++; |
|
937 |
break; |
|
938 |
default: |
|
939 |
break; |
|
940 |
} |
|
941 |
return QWidget::eventFilter(object, event); |
|
942 |
} |
|
943 |
}; |
|
944 |
||
945 |
void tst_QGraphicsProxyWidget::hoverEnterLeaveEvent_data() |
|
946 |
{ |
|
947 |
QTest::addColumn<bool>("hasWidget"); |
|
948 |
QTest::addColumn<bool>("hoverEnabled"); |
|
949 |
QTest::newRow("widget, no hover") << true << false; |
|
950 |
QTest::newRow("no widget, no hover") << false << false; |
|
951 |
QTest::newRow("widget, hover") << true << true; |
|
952 |
QTest::newRow("no widget, hover") << false << true; |
|
953 |
} |
|
954 |
||
955 |
// protected void hoverEnterEvent(QGraphicsSceneHoverEvent* event) |
|
956 |
void tst_QGraphicsProxyWidget::hoverEnterLeaveEvent() |
|
957 |
{ |
|
958 |
QFETCH(bool, hasWidget); |
|
959 |
QFETCH(bool, hoverEnabled); |
|
960 |
||
961 |
#if defined(Q_OS_WINCE) && (!defined(GWES_ICONCURS) || defined(QT_NO_CURSOR)) |
|
962 |
QSKIP("hover events not supported on this platform", SkipAll); |
|
963 |
#endif |
|
964 |
||
965 |
// proxy should translate this into events that the widget would expect |
|
966 |
||
967 |
QGraphicsScene scene; |
|
968 |
QGraphicsView view(&scene); |
|
969 |
//do not let the window manager move the window while we are moving the mouse on it |
|
970 |
view.setWindowFlags(Qt::X11BypassWindowManagerHint); |
|
971 |
view.show(); |
|
972 |
#ifdef Q_WS_X11 |
|
973 |
qt_x11_wait_for_window_manager(&view); |
|
974 |
#endif |
|
975 |
||
976 |
SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; |
|
977 |
EventLogger *widget = new EventLogger; |
|
978 |
widget->resize(50, 50); |
|
979 |
widget->setAttribute(Qt::WA_Hover, hoverEnabled); |
|
980 |
widget->setMouseTracking(true); |
|
981 |
view.resize(100, 100); |
|
982 |
if (hasWidget) |
|
983 |
proxy->setWidget(widget); |
|
984 |
proxy->setPos(50, 0); |
|
985 |
scene.addItem(proxy); |
|
986 |
QTest::qWait(30); |
|
987 |
QTest::mouseMove(&view, QPoint(10, 10)); |
|
988 |
QTest::qWait(30); |
|
989 |
||
990 |
// in |
|
991 |
QTest::mouseMove(&view, QPoint(50, 50)); |
|
992 |
QTest::qWait(25); |
|
993 |
QTRY_COMPARE(widget->testAttribute(Qt::WA_UnderMouse), hasWidget ? true : false); |
|
994 |
// ### this attribute isn't supported |
|
995 |
QCOMPARE(widget->enterCount, hasWidget ? 1 : 0); |
|
996 |
QCOMPARE(widget->hoverEnter, (hasWidget && hoverEnabled) ? 1 : 0); |
|
997 |
// does not work on all platforms |
|
998 |
//QCOMPARE(widget->moveCount, 0); |
|
999 |
||
1000 |
// out |
|
1001 |
QTest::mouseMove(&view, QPoint(10, 10)); |
|
1002 |
QTest::qWait(25); |
|
1003 |
// QTRY_COMPARE(widget->testAttribute(Qt::WA_UnderMouse), false); |
|
1004 |
// ### this attribute isn't supported |
|
1005 |
QCOMPARE(widget->leaveCount, hasWidget ? 1 : 0); |
|
1006 |
QCOMPARE(widget->hoverLeave, (hasWidget && hoverEnabled) ? 1 : 0); |
|
1007 |
// does not work on all platforms |
|
1008 |
//QCOMPARE(widget->moveCount, 0); |
|
1009 |
||
1010 |
if (!hasWidget) |
|
1011 |
delete widget; |
|
1012 |
} |
|
1013 |
||
1014 |
void tst_QGraphicsProxyWidget::hoverMoveEvent_data() |
|
1015 |
{ |
|
1016 |
QTest::addColumn<bool>("hasWidget"); |
|
1017 |
QTest::addColumn<bool>("hoverEnabled"); |
|
1018 |
QTest::addColumn<bool>("mouseTracking"); |
|
1019 |
QTest::addColumn<bool>("mouseDown"); |
|
1020 |
for (int i = 0; i < 2; ++i) { |
|
1021 |
for (int j = 0; j < 2; ++j) { |
|
1022 |
for (int k = 0; k < 2; ++k) { |
|
1023 |
for (int l = 0; l < 2; ++l) { |
|
1024 |
bool hasWidget = (i == 0); |
|
1025 |
bool hoverEnabled = (j == 0); |
|
1026 |
bool mouseTracking = (k == 0); |
|
1027 |
bool mouseDown = (l == 0); |
|
1028 |
QString name = QString("hasWidget:%1, hover:%2, mouseTracking:%3, mouseDown: %4").arg(hasWidget).arg(hoverEnabled).arg(mouseTracking).arg(mouseDown); |
|
1029 |
QTest::newRow(name.toLatin1()) << hasWidget << hoverEnabled << mouseTracking << mouseDown; |
|
1030 |
} |
|
1031 |
} |
|
1032 |
} |
|
1033 |
} |
|
1034 |
} |
|
1035 |
||
1036 |
// protected void hoverMoveEvent(QGraphicsSceneHoverEvent* event) |
|
1037 |
void tst_QGraphicsProxyWidget::hoverMoveEvent() |
|
1038 |
{ |
|
1039 |
QFETCH(bool, hasWidget); |
|
1040 |
QFETCH(bool, hoverEnabled); |
|
1041 |
QFETCH(bool, mouseTracking); |
|
1042 |
QFETCH(bool, mouseDown); |
|
1043 |
||
1044 |
QSKIP("Ambiguous test...", SkipAll); |
|
1045 |
||
1046 |
// proxy should translate the move events to what the widget would expect |
|
1047 |
||
1048 |
QGraphicsScene scene; |
|
1049 |
QGraphicsView view(&scene); |
|
1050 |
view.show(); |
|
1051 |
||
1052 |
SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; |
|
1053 |
proxy->setFlag(QGraphicsItem::ItemIsFocusable, true); // ### remove me!!! |
|
1054 |
EventLogger *widget = new EventLogger; |
|
1055 |
widget->resize(50, 50); |
|
1056 |
widget->setAttribute(Qt::WA_Hover, hoverEnabled); |
|
1057 |
if (mouseTracking) |
|
1058 |
widget->setMouseTracking(true); |
|
1059 |
view.resize(100, 100); |
|
1060 |
if (hasWidget) |
|
1061 |
proxy->setWidget(widget); |
|
1062 |
proxy->setPos(50, 0); |
|
1063 |
scene.addItem(proxy); |
|
1064 |
||
1065 |
// in |
|
1066 |
QTest::mouseMove(&view, QPoint(50, 50)); |
|
1067 |
QTest::qWait(12); |
|
1068 |
||
1069 |
if (mouseDown) |
|
1070 |
QTest::mousePress(view.viewport(), Qt::LeftButton); |
|
1071 |
||
1072 |
// move a little bit |
|
1073 |
QTest::mouseMove(&view, QPoint(60, 60)); |
|
1074 |
QTest::qWait(12); |
|
1075 |
QTRY_COMPARE(widget->hoverEnter, (hasWidget && hoverEnabled) ? 1 : 0); |
|
1076 |
QCOMPARE(widget->moveCount, (hasWidget && mouseTracking) || (hasWidget && mouseDown) ? 1 : 0); |
|
1077 |
||
1078 |
if (!hasWidget) |
|
1079 |
delete widget; |
|
1080 |
} |
|
1081 |
||
1082 |
void tst_QGraphicsProxyWidget::keyPressEvent_data() |
|
1083 |
{ |
|
1084 |
QTest::addColumn<bool>("hasWidget"); |
|
1085 |
QTest::newRow("widget") << true; |
|
1086 |
QTest::newRow("no widget") << false; |
|
1087 |
} |
|
1088 |
||
1089 |
// protected void keyPressEvent(QKeyEvent* event) |
|
1090 |
void tst_QGraphicsProxyWidget::keyPressEvent() |
|
1091 |
{ |
|
1092 |
QFETCH(bool, hasWidget); |
|
1093 |
||
1094 |
QGraphicsScene scene; |
|
1095 |
QGraphicsView view(&scene); |
|
1096 |
view.show(); |
|
1097 |
view.viewport()->setFocus(); |
|
1098 |
QApplication::setActiveWindow(&view); |
|
1099 |
QTest::qWaitForWindowShown(&view); |
|
1100 |
QApplication::processEvents(); |
|
1101 |
QTRY_COMPARE(QApplication::activeWindow(), &view); |
|
1102 |
||
1103 |
SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; |
|
1104 |
proxy->setFlag(QGraphicsItem::ItemIsFocusable, true); // ### remove me!!! |
|
1105 |
||
1106 |
QLineEdit *widget = new QLineEdit; |
|
1107 |
widget->resize(50, 50); |
|
1108 |
view.resize(100, 100); |
|
1109 |
if (hasWidget) { |
|
1110 |
proxy->setWidget(widget); |
|
1111 |
proxy->show(); |
|
1112 |
} |
|
1113 |
proxy->setPos(50, 0); |
|
1114 |
scene.addItem(proxy); |
|
1115 |
proxy->setFocus(); |
|
1116 |
||
1117 |
QTest::keyPress(view.viewport(), 'x'); |
|
1118 |
||
1119 |
QTRY_COMPARE(widget->text(), hasWidget ? QString("x") : QString()); |
|
1120 |
||
1121 |
if (!hasWidget) |
|
1122 |
delete widget; |
|
1123 |
} |
|
1124 |
||
1125 |
void tst_QGraphicsProxyWidget::keyReleaseEvent_data() |
|
1126 |
{ |
|
1127 |
QTest::addColumn<bool>("hasWidget"); |
|
1128 |
QTest::newRow("widget") << true; |
|
1129 |
QTest::newRow("no widget") << false; |
|
1130 |
} |
|
1131 |
||
1132 |
// protected void keyReleaseEvent(QKeyEvent* event) |
|
1133 |
void tst_QGraphicsProxyWidget::keyReleaseEvent() |
|
1134 |
{ |
|
1135 |
QFETCH(bool, hasWidget); |
|
1136 |
||
1137 |
QGraphicsScene scene; |
|
1138 |
QGraphicsView view(&scene); |
|
1139 |
view.show(); |
|
1140 |
QApplication::setActiveWindow(&view); |
|
1141 |
QTest::qWaitForWindowShown(&view); |
|
1142 |
QTRY_COMPARE(QApplication::activeWindow(), &view); |
|
1143 |
||
1144 |
||
1145 |
SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; |
|
1146 |
proxy->setFlag(QGraphicsItem::ItemIsFocusable, true); // ### remove me!!! |
|
1147 |
QPushButton *widget = new QPushButton; |
|
1148 |
QSignalSpy spy(widget, SIGNAL(clicked())); |
|
1149 |
widget->resize(50, 50); |
|
1150 |
view.resize(100, 100); |
|
1151 |
if (hasWidget) { |
|
1152 |
proxy->setWidget(widget); |
|
1153 |
proxy->show(); |
|
1154 |
} |
|
1155 |
proxy->setPos(50, 0); |
|
1156 |
scene.addItem(proxy); |
|
1157 |
proxy->setFocus(); |
|
1158 |
||
1159 |
QTest::keyPress(view.viewport(), Qt::Key_Space); |
|
1160 |
QTRY_COMPARE(spy.count(), 0); |
|
1161 |
QTest::keyRelease(view.viewport(), Qt::Key_Space); |
|
1162 |
QTRY_COMPARE(spy.count(), (hasWidget) ? 1 : 0); |
|
1163 |
||
1164 |
if (!hasWidget) |
|
1165 |
delete widget; |
|
1166 |
} |
|
1167 |
||
1168 |
void tst_QGraphicsProxyWidget::mouseDoubleClickEvent_data() |
|
1169 |
{ |
|
1170 |
QTest::addColumn<bool>("hasWidget"); |
|
1171 |
QTest::newRow("widget") << true; |
|
1172 |
QTest::newRow("no widget") << false; |
|
1173 |
} |
|
1174 |
||
1175 |
// protected void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) |
|
1176 |
void tst_QGraphicsProxyWidget::mouseDoubleClickEvent() |
|
1177 |
{ |
|
1178 |
QFETCH(bool, hasWidget); |
|
1179 |
||
1180 |
QGraphicsScene scene; |
|
1181 |
QGraphicsView view(&scene); |
|
1182 |
view.show(); |
|
1183 |
||
1184 |
QApplication::setActiveWindow(&view); |
|
1185 |
QTest::qWaitForWindowShown(&view); |
|
1186 |
QTRY_COMPARE(QApplication::activeWindow(), &view); |
|
1187 |
||
1188 |
SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; |
|
1189 |
proxy->setFlag(QGraphicsItem::ItemIsFocusable, true); // ### remove me!!! |
|
1190 |
QLineEdit *widget = new QLineEdit; |
|
1191 |
widget->setText("foo"); |
|
1192 |
widget->resize(50, 50); |
|
1193 |
view.resize(100, 100); |
|
1194 |
if (hasWidget) { |
|
1195 |
proxy->setWidget(widget); |
|
1196 |
proxy->show(); |
|
1197 |
} |
|
1198 |
proxy->setPos(50, 0); |
|
1199 |
scene.addItem(proxy); |
|
1200 |
proxy->setFocus(); |
|
1201 |
||
1202 |
QTest::mouseMove(view.viewport(), view.mapFromScene(proxy->mapToScene(15, proxy->boundingRect().center().y()))); |
|
1203 |
QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(proxy->mapToScene(15, proxy->boundingRect().center().y()))); |
|
1204 |
QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(proxy->mapToScene(15, proxy->boundingRect().center().y()))); |
|
1205 |
QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(proxy->mapToScene(15, proxy->boundingRect().center().y()))); |
|
1206 |
QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(proxy->mapToScene(15, proxy->boundingRect().center().y()))); |
|
1207 |
||
1208 |
QTRY_COMPARE(widget->selectedText(), hasWidget ? QString("foo") : QString()); |
|
1209 |
||
1210 |
if (!hasWidget) |
|
1211 |
delete widget; |
|
1212 |
} |
|
1213 |
||
1214 |
void tst_QGraphicsProxyWidget::mousePressReleaseEvent_data() |
|
1215 |
{ |
|
1216 |
QTest::addColumn<bool>("hasWidget"); |
|
1217 |
QTest::newRow("widget") << true; |
|
1218 |
QTest::newRow("no widget") << false; |
|
1219 |
} |
|
1220 |
||
1221 |
// protected void mousePressEvent(QGraphicsSceneMouseEvent* event) |
|
1222 |
void tst_QGraphicsProxyWidget::mousePressReleaseEvent() |
|
1223 |
{ |
|
1224 |
QFETCH(bool, hasWidget); |
|
1225 |
||
1226 |
QGraphicsScene scene; |
|
1227 |
QGraphicsView view(&scene); |
|
1228 |
view.show(); |
|
1229 |
QTest::qWaitForWindowShown(&view); |
|
1230 |
||
1231 |
SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; |
|
1232 |
proxy->setFlag(QGraphicsItem::ItemIsFocusable, true); // ### remove me!!! |
|
1233 |
QPushButton *widget = new QPushButton; |
|
1234 |
QSignalSpy spy(widget, SIGNAL(clicked())); |
|
1235 |
widget->resize(50, 50); |
|
1236 |
view.resize(100, 100); |
|
1237 |
if (hasWidget) { |
|
1238 |
proxy->setWidget(widget); |
|
1239 |
proxy->show(); |
|
1240 |
} |
|
1241 |
proxy->setPos(50, 0); |
|
1242 |
scene.addItem(proxy); |
|
1243 |
proxy->setFocus(); |
|
1244 |
||
1245 |
QTest::mousePress(view.viewport(), Qt::LeftButton, 0, |
|
1246 |
view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center()))); |
|
1247 |
QTRY_COMPARE(spy.count(), 0); |
|
1248 |
QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, |
|
1249 |
view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center()))); |
|
1250 |
QTRY_COMPARE(spy.count(), (hasWidget) ? 1 : 0); |
|
1251 |
||
1252 |
if (!hasWidget) |
|
1253 |
delete widget; |
|
1254 |
} |
|
1255 |
||
1256 |
void tst_QGraphicsProxyWidget::resizeEvent_data() |
|
1257 |
{ |
|
1258 |
QTest::addColumn<bool>("hasWidget"); |
|
1259 |
QTest::newRow("widget") << true; |
|
1260 |
QTest::newRow("no widget") << false; |
|
1261 |
} |
|
1262 |
||
1263 |
// protected void resizeEvent(QGraphicsSceneResizeEvent* event) |
|
1264 |
void tst_QGraphicsProxyWidget::resizeEvent() |
|
1265 |
{ |
|
1266 |
QFETCH(bool, hasWidget); |
|
1267 |
||
1268 |
SubQGraphicsProxyWidget proxy; |
|
1269 |
QWidget *widget = new QWidget; |
|
1270 |
if (hasWidget) |
|
1271 |
proxy.setWidget(widget); |
|
1272 |
||
1273 |
QSize newSize(100, 100); |
|
1274 |
QGraphicsSceneResizeEvent event; |
|
1275 |
event.setOldSize(QSize(10, 10)); |
|
1276 |
event.setNewSize(newSize); |
|
1277 |
proxy.call_resizeEvent(&event); |
|
1278 |
if (hasWidget) |
|
1279 |
QCOMPARE(widget->size(), newSize); |
|
1280 |
if (!hasWidget) |
|
1281 |
delete widget; |
|
1282 |
} |
|
1283 |
||
1284 |
void tst_QGraphicsProxyWidget::paintEvent() |
|
1285 |
{ |
|
1286 |
//we test that calling update on a widget inside a QGraphicsView is triggering a repaint |
|
1287 |
QGraphicsScene scene; |
|
1288 |
QGraphicsView view(&scene); |
|
1289 |
view.show(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1290 |
QApplication::setActiveWindow(&view); |
0 | 1291 |
QTest::qWaitForWindowShown(&view); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1292 |
QTRY_VERIFY(view.isActiveWindow()); |
0 | 1293 |
|
1294 |
SubQGraphicsProxyWidget proxy; |
|
1295 |
||
1296 |
QWidget *w = new QWidget; |
|
1297 |
//showing the widget here seems to create a bug in Graphics View |
|
1298 |
//this bug prevents the widget from being updated |
|
1299 |
||
1300 |
w->show(); |
|
1301 |
QTest::qWaitForWindowShown(w); |
|
1302 |
QApplication::processEvents(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1303 |
QTest::qWait(30); |
0 | 1304 |
proxy.setWidget(w); |
1305 |
scene.addItem(&proxy); |
|
1306 |
||
1307 |
//make sure we flush all the paint events |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1308 |
QTest::qWait(30); |
0 | 1309 |
QTRY_VERIFY(proxy.paintCount > 1); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1310 |
QTest::qWait(30); |
0 | 1311 |
proxy.paintCount = 0; |
1312 |
||
1313 |
w->update(); |
|
1314 |
QTest::qWait(30); |
|
1315 |
QTRY_COMPARE(proxy.paintCount, 1); //the widget should have been painted now |
|
1316 |
} |
|
1317 |
||
1318 |
||
1319 |
void tst_QGraphicsProxyWidget::wheelEvent() |
|
1320 |
{ |
|
1321 |
QGraphicsScene scene; |
|
1322 |
QGraphicsView view(&scene); |
|
1323 |
view.show(); |
|
1324 |
#ifdef Q_WS_X11 |
|
1325 |
qt_x11_wait_for_window_manager(&view); |
|
1326 |
#endif |
|
1327 |
||
1328 |
WheelWidget *wheelWidget = new WheelWidget(); |
|
1329 |
wheelWidget->setFixedSize(400, 400); |
|
1330 |
||
1331 |
QGraphicsProxyWidget *proxy = scene.addWidget(wheelWidget); |
|
1332 |
proxy->setVisible(true); |
|
1333 |
||
1334 |
QGraphicsSceneWheelEvent event(QEvent::GraphicsSceneWheel); |
|
1335 |
event.setScenePos(QPoint(50, 50)); |
|
1336 |
event.setAccepted(false); |
|
1337 |
wheelWidget->wheelEventCalled = false; |
|
1338 |
||
1339 |
QApplication::sendEvent(&scene, &event); |
|
1340 |
||
1341 |
QVERIFY(event.isAccepted()); |
|
1342 |
QVERIFY(wheelWidget->wheelEventCalled); |
|
1343 |
} |
|
1344 |
||
1345 |
Q_DECLARE_METATYPE(Qt::SizeHint) |
|
1346 |
void tst_QGraphicsProxyWidget::sizeHint_data() |
|
1347 |
{ |
|
1348 |
QTest::addColumn<Qt::SizeHint>("which"); |
|
1349 |
QTest::addColumn<QSizeF>("constraint"); |
|
1350 |
QTest::addColumn<QSizeF>("sizeHint"); |
|
1351 |
QTest::addColumn<bool>("hasWidget"); |
|
1352 |
||
1353 |
for (int i = 0; i < 2; ++i) { |
|
1354 |
bool hasWidget = (i == 0); |
|
1355 |
// ### What should these do? |
|
1356 |
QTest::newRow("min") << Qt::MinimumSize << QSizeF() << QSizeF() << hasWidget; |
|
1357 |
QTest::newRow("pre") << Qt::PreferredSize << QSizeF() << QSizeF() << hasWidget; |
|
1358 |
QTest::newRow("max") << Qt::MaximumSize << QSizeF() << QSizeF() << hasWidget; |
|
1359 |
QTest::newRow("mindes") << Qt::MinimumDescent << QSizeF() << QSizeF() << hasWidget; |
|
1360 |
QTest::newRow("nsize") << Qt::NSizeHints << QSizeF() << QSizeF() << hasWidget; |
|
1361 |
} |
|
1362 |
} |
|
1363 |
||
1364 |
// protected QSizeF sizeHint(Qt::SizeHint which, QSizeF const& constraint = QSizeF()) const |
|
1365 |
void tst_QGraphicsProxyWidget::sizeHint() |
|
1366 |
{ |
|
1367 |
QFETCH(Qt::SizeHint, which); |
|
1368 |
QFETCH(QSizeF, constraint); |
|
1369 |
QFETCH(QSizeF, sizeHint); |
|
1370 |
QFETCH(bool, hasWidget); |
|
1371 |
QSKIP("Broken test", SkipAll); |
|
1372 |
SubQGraphicsProxyWidget proxy; |
|
1373 |
QWidget *widget = new QWidget; |
|
1374 |
if (hasWidget) |
|
1375 |
proxy.setWidget(widget); |
|
1376 |
QCOMPARE(proxy.call_sizeHint(which, constraint), sizeHint); |
|
1377 |
if (!hasWidget) |
|
1378 |
delete widget; |
|
1379 |
} |
|
1380 |
||
1381 |
void tst_QGraphicsProxyWidget::sizePolicy() |
|
1382 |
{ |
|
1383 |
for (int p = 0; p < 2; ++p) { |
|
1384 |
bool hasWidget = (p == 0 ? true : false); |
|
1385 |
SubQGraphicsProxyWidget proxy; |
|
1386 |
QWidget *widget = new QWidget; |
|
1387 |
QSizePolicy proxyPol(QSizePolicy::Maximum, QSizePolicy::Expanding); |
|
1388 |
proxy.setSizePolicy(proxyPol); |
|
1389 |
QSizePolicy widgetPol(QSizePolicy::Fixed, QSizePolicy::Minimum); |
|
1390 |
widget->setSizePolicy(widgetPol); |
|
1391 |
||
1392 |
QCOMPARE(proxy.sizePolicy(), proxyPol); |
|
1393 |
QCOMPARE(widget->sizePolicy(), widgetPol); |
|
1394 |
if (hasWidget) { |
|
1395 |
proxy.setWidget(widget); |
|
1396 |
QCOMPARE(proxy.sizePolicy(), widgetPol); |
|
1397 |
} else { |
|
1398 |
QCOMPARE(proxy.sizePolicy(), proxyPol); |
|
1399 |
} |
|
1400 |
QCOMPARE(widget->sizePolicy(), widgetPol); |
|
1401 |
||
1402 |
proxy.setSizePolicy(widgetPol); |
|
1403 |
widget->setSizePolicy(proxyPol); |
|
1404 |
if (hasWidget) |
|
1405 |
QCOMPARE(proxy.sizePolicy(), proxyPol); |
|
1406 |
else |
|
1407 |
QCOMPARE(proxy.sizePolicy(), widgetPol); |
|
1408 |
} |
|
1409 |
} |
|
1410 |
||
1411 |
void tst_QGraphicsProxyWidget::minimumSize() |
|
1412 |
{ |
|
1413 |
SubQGraphicsProxyWidget proxy; |
|
1414 |
QWidget *widget = new QWidget; |
|
1415 |
QSize minSize(50, 50); |
|
1416 |
widget->setMinimumSize(minSize); |
|
1417 |
proxy.resize(30, 30); |
|
1418 |
widget->resize(30,30); |
|
1419 |
QCOMPARE(proxy.size(), QSizeF(30, 30)); |
|
1420 |
proxy.setWidget(widget); |
|
1421 |
QCOMPARE(proxy.size().toSize(), minSize); |
|
1422 |
QCOMPARE(proxy.minimumSize().toSize(), minSize); |
|
1423 |
widget->setMinimumSize(70, 70); |
|
1424 |
QCOMPARE(proxy.minimumSize(), QSizeF(70, 70)); |
|
1425 |
QCOMPARE(proxy.size(), QSizeF(70, 70)); |
|
1426 |
} |
|
1427 |
||
1428 |
void tst_QGraphicsProxyWidget::maximumSize() |
|
1429 |
{ |
|
1430 |
SubQGraphicsProxyWidget proxy; |
|
1431 |
QWidget *widget = new QWidget; |
|
1432 |
QSize maxSize(150, 150); |
|
1433 |
widget->setMaximumSize(maxSize); |
|
1434 |
proxy.resize(200, 200); |
|
1435 |
widget->resize(200,200); |
|
1436 |
QCOMPARE(proxy.size(), QSizeF(200, 200)); |
|
1437 |
proxy.setWidget(widget); |
|
1438 |
QCOMPARE(proxy.size().toSize(), maxSize); |
|
1439 |
QCOMPARE(proxy.maximumSize().toSize(), maxSize); |
|
1440 |
widget->setMaximumSize(70, 70); |
|
1441 |
QCOMPARE(proxy.maximumSize(), QSizeF(70, 70)); |
|
1442 |
QCOMPARE(proxy.size(), QSizeF(70, 70)); |
|
1443 |
} |
|
1444 |
||
1445 |
class View : public QGraphicsView |
|
1446 |
{ |
|
1447 |
public: |
|
1448 |
View(QGraphicsScene *scene, QWidget *parent = 0) |
|
1449 |
: QGraphicsView(scene, parent), npaints(0) |
|
1450 |
{ } |
|
1451 |
QRegion paintEventRegion; |
|
1452 |
int npaints; |
|
1453 |
protected: |
|
1454 |
void paintEvent(QPaintEvent *event) |
|
1455 |
{ |
|
1456 |
++npaints; |
|
1457 |
paintEventRegion += event->region(); |
|
1458 |
QGraphicsView::paintEvent(event); |
|
1459 |
} |
|
1460 |
}; |
|
1461 |
||
1462 |
class ScrollWidget : public QWidget |
|
1463 |
{ |
|
1464 |
Q_OBJECT |
|
1465 |
public: |
|
1466 |
ScrollWidget() : npaints(0) |
|
1467 |
{ |
|
1468 |
resize(200, 200); |
|
1469 |
} |
|
1470 |
QRegion paintEventRegion; |
|
1471 |
int npaints; |
|
1472 |
||
1473 |
public slots: |
|
1474 |
void updateScroll() |
|
1475 |
{ |
|
1476 |
update(0, 0, 200, 10); |
|
1477 |
scroll(0, 10, QRect(0, 0, 100, 20)); |
|
1478 |
} |
|
1479 |
||
1480 |
protected: |
|
1481 |
void paintEvent(QPaintEvent *event) |
|
1482 |
{ |
|
1483 |
++npaints; |
|
1484 |
paintEventRegion += event->region(); |
|
1485 |
QPainter painter(this); |
|
1486 |
painter.fillRect(event->rect(), Qt::blue); |
|
1487 |
} |
|
1488 |
}; |
|
1489 |
||
1490 |
void tst_QGraphicsProxyWidget::scrollUpdate() |
|
1491 |
{ |
|
1492 |
ScrollWidget *widget = new ScrollWidget; |
|
1493 |
||
1494 |
QGraphicsScene scene; |
|
1495 |
scene.addWidget(widget); |
|
1496 |
||
1497 |
View view(&scene); |
|
1498 |
view.show(); |
|
1499 |
QTest::qWaitForWindowShown(&view); |
|
1500 |
QTRY_VERIFY(view.npaints >= 1); |
|
1501 |
QTest::qWait(20); |
|
1502 |
widget->paintEventRegion = QRegion(); |
|
1503 |
widget->npaints = 0; |
|
1504 |
view.paintEventRegion = QRegion(); |
|
1505 |
view.npaints = 0; |
|
1506 |
QTimer::singleShot(0, widget, SLOT(updateScroll())); |
|
1507 |
QTest::qWait(50); |
|
1508 |
QTRY_COMPARE(view.npaints, 2); |
|
1509 |
// QRect(0, 0, 200, 12) is the first update, expanded (-2, -2, 2, 2) |
|
1510 |
// QRect(0, 12, 102, 10) is the scroll update, expanded (-2, -2, 2, 2), |
|
1511 |
// intersected with the above update. |
|
1512 |
QCOMPARE(view.paintEventRegion.rects(), |
|
1513 |
QVector<QRect>() << QRect(0, 0, 200, 12) << QRect(0, 12, 102, 10)); |
|
1514 |
QCOMPARE(widget->npaints, 2); |
|
1515 |
QCOMPARE(widget->paintEventRegion.rects(), |
|
1516 |
QVector<QRect>() << QRect(0, 0, 200, 12) << QRect(0, 12, 102, 10)); |
|
1517 |
} |
|
1518 |
||
1519 |
void tst_QGraphicsProxyWidget::setWidget_simple() |
|
1520 |
{ |
|
1521 |
QGraphicsProxyWidget proxy; |
|
1522 |
QLineEdit *lineEdit = new QLineEdit; |
|
1523 |
proxy.setWidget(lineEdit); |
|
1524 |
||
1525 |
QVERIFY(lineEdit->testAttribute(Qt::WA_DontShowOnScreen)); |
|
1526 |
// Size hints |
|
1527 |
// ### size hints are tested in a different test |
|
1528 |
// QCOMPARE(proxy.effectiveSizeHint(Qt::MinimumSize).toSize(), lineEdit->minimumSizeHint()); |
|
1529 |
// QCOMPARE(proxy.effectiveSizeHint(Qt::MaximumSize).toSize(), lineEdit->maximumSize()); |
|
1530 |
// QCOMPARE(proxy.effectiveSizeHint(Qt::PreferredSize).toSize(), lineEdit->sizeHint()); |
|
1531 |
QCOMPARE(proxy.size().toSize(), lineEdit->minimumSizeHint().expandedTo(lineEdit->size())); |
|
1532 |
QRect rect = lineEdit->rect(); |
|
1533 |
rect.setSize(rect.size().expandedTo(lineEdit->minimumSizeHint())); |
|
1534 |
QCOMPARE(proxy.rect().toRect(), rect); |
|
1535 |
||
1536 |
// Properties |
|
1537 |
// QCOMPARE(proxy.focusPolicy(), lineEdit->focusPolicy()); |
|
1538 |
// QCOMPARE(proxy.palette(), lineEdit->palette()); |
|
1539 |
#ifndef QT_NO_CURSOR |
|
1540 |
QCOMPARE(proxy.cursor().shape(), lineEdit->cursor().shape()); |
|
1541 |
#endif |
|
1542 |
QCOMPARE(proxy.layoutDirection(), lineEdit->layoutDirection()); |
|
1543 |
QCOMPARE(proxy.style(), lineEdit->style()); |
|
1544 |
QCOMPARE(proxy.font(), lineEdit->font()); |
|
1545 |
QCOMPARE(proxy.isEnabled(), lineEdit->isEnabled()); |
|
1546 |
QCOMPARE(proxy.isVisible(), lineEdit->isVisible()); |
|
1547 |
} |
|
1548 |
||
1549 |
void tst_QGraphicsProxyWidget::setWidget_ownership() |
|
1550 |
{ |
|
1551 |
QPointer<QLineEdit> lineEdit = new QLineEdit; |
|
1552 |
QPointer<QLineEdit> lineEdit2 = new QLineEdit; |
|
1553 |
QVERIFY(lineEdit); |
|
1554 |
{ |
|
1555 |
// Create a proxy and transfer ownership to it |
|
1556 |
QGraphicsProxyWidget proxy; |
|
1557 |
proxy.setWidget(lineEdit); |
|
1558 |
QCOMPARE(proxy.widget(), (QWidget *)lineEdit); |
|
1559 |
||
1560 |
// Remove the widget without destroying it. |
|
1561 |
proxy.setWidget(0); |
|
1562 |
QVERIFY(!proxy.widget()); |
|
1563 |
QVERIFY(lineEdit); |
|
1564 |
||
1565 |
// Assign the widget again and switch to another widget. |
|
1566 |
proxy.setWidget(lineEdit); |
|
1567 |
proxy.setWidget(lineEdit2); |
|
1568 |
QCOMPARE(proxy.widget(), (QWidget *)lineEdit2); |
|
1569 |
||
1570 |
// Assign the first widget, and destroy the proxy. |
|
1571 |
proxy.setWidget(lineEdit); |
|
1572 |
} |
|
1573 |
QVERIFY(!lineEdit); |
|
1574 |
QVERIFY(lineEdit2); |
|
1575 |
||
1576 |
QGraphicsScene scene; |
|
1577 |
QPointer<QGraphicsProxyWidget> proxy = scene.addWidget(lineEdit2); |
|
1578 |
||
1579 |
delete lineEdit2; |
|
1580 |
QVERIFY(!proxy); |
|
1581 |
} |
|
1582 |
||
1583 |
void tst_QGraphicsProxyWidget::resize_simple_data() |
|
1584 |
{ |
|
1585 |
QTest::addColumn<QSizeF>("size"); |
|
1586 |
||
1587 |
QTest::newRow("200, 200") << QSizeF(200, 200); |
|
1588 |
#if !defined(QT_ARCH_ARM) && !defined(Q_OS_WINCE) |
|
1589 |
QTest::newRow("1000, 1000") << QSizeF(1000, 1000); |
|
1590 |
// Since 4.5, 10000x10000 runs out of memory. |
|
1591 |
// QTest::newRow("10000, 10000") << QSizeF(10000, 10000); |
|
1592 |
#endif |
|
1593 |
} |
|
1594 |
||
1595 |
void tst_QGraphicsProxyWidget::resize_simple() |
|
1596 |
{ |
|
1597 |
QFETCH(QSizeF, size); |
|
1598 |
||
1599 |
QGraphicsProxyWidget proxy; |
|
1600 |
QWidget *widget = new QWidget; |
|
1601 |
widget->setGeometry(0, 0, (int)size.width(), (int)size.height()); |
|
1602 |
proxy.setWidget(widget); |
|
1603 |
widget->show(); |
|
1604 |
QCOMPARE(widget->pos(), QPoint()); |
|
1605 |
||
1606 |
// The proxy resizes itself, the line edit follows |
|
1607 |
proxy.resize(size); |
|
1608 |
QCOMPARE(proxy.size(), size); |
|
1609 |
QCOMPARE(proxy.size().toSize(), widget->size()); |
|
1610 |
||
1611 |
// The line edit resizes itself, the proxy follows (no loopback/live lock) |
|
1612 |
QSize doubleSize = size.toSize() * 2; |
|
1613 |
widget->resize(doubleSize); |
|
1614 |
QCOMPARE(widget->size(), doubleSize); |
|
1615 |
QCOMPARE(widget->size(), proxy.size().toSize()); |
|
1616 |
} |
|
1617 |
||
1618 |
void tst_QGraphicsProxyWidget::symmetricMove() |
|
1619 |
{ |
|
1620 |
QGraphicsProxyWidget proxy; |
|
1621 |
QLineEdit *lineEdit = new QLineEdit; |
|
1622 |
proxy.setWidget(lineEdit); |
|
1623 |
lineEdit->show(); |
|
1624 |
||
1625 |
proxy.setPos(10, 10); |
|
1626 |
QCOMPARE(proxy.pos(), QPointF(10, 10)); |
|
1627 |
QCOMPARE(lineEdit->pos(), QPoint(10, 10)); |
|
1628 |
||
1629 |
lineEdit->move(5, 5); |
|
1630 |
QCOMPARE(proxy.pos(), QPointF(5, 5)); |
|
1631 |
QCOMPARE(lineEdit->pos(), QPoint(5, 5)); |
|
1632 |
} |
|
1633 |
||
1634 |
void tst_QGraphicsProxyWidget::symmetricResize() |
|
1635 |
{ |
|
1636 |
QGraphicsProxyWidget proxy; |
|
1637 |
QLineEdit *lineEdit = new QLineEdit; |
|
1638 |
proxy.setWidget(lineEdit); |
|
1639 |
lineEdit->show(); |
|
1640 |
||
1641 |
proxy.resize(256, 256); |
|
1642 |
QCOMPARE(proxy.size(), QSizeF(256, 256)); |
|
1643 |
QCOMPARE(lineEdit->size(), QSize(256, 256)); |
|
1644 |
||
1645 |
lineEdit->resize(512, 512); |
|
1646 |
QCOMPARE(proxy.size(), QSizeF(512, 512)); |
|
1647 |
QCOMPARE(lineEdit->size(), QSize(512, 512)); |
|
1648 |
} |
|
1649 |
||
1650 |
void tst_QGraphicsProxyWidget::symmetricVisible() |
|
1651 |
{ |
|
1652 |
QGraphicsProxyWidget proxy; |
|
1653 |
QLineEdit *lineEdit = new QLineEdit; |
|
1654 |
proxy.setWidget(lineEdit); |
|
1655 |
lineEdit->show(); |
|
1656 |
||
1657 |
QCOMPARE(proxy.isVisible(), lineEdit->isVisible()); |
|
1658 |
||
1659 |
proxy.hide(); |
|
1660 |
QCOMPARE(proxy.isVisible(), lineEdit->isVisible()); |
|
1661 |
proxy.show(); |
|
1662 |
QCOMPARE(proxy.isVisible(), lineEdit->isVisible()); |
|
1663 |
lineEdit->hide(); |
|
1664 |
QCOMPARE(proxy.isVisible(), lineEdit->isVisible()); |
|
1665 |
lineEdit->show(); |
|
1666 |
QCOMPARE(proxy.isVisible(), lineEdit->isVisible()); |
|
1667 |
} |
|
1668 |
||
1669 |
void tst_QGraphicsProxyWidget::symmetricEnabled() |
|
1670 |
{ |
|
1671 |
QGraphicsProxyWidget proxy; |
|
1672 |
QLineEdit *lineEdit = new QLineEdit; |
|
1673 |
proxy.setWidget(lineEdit); |
|
1674 |
lineEdit->show(); |
|
1675 |
||
1676 |
QCOMPARE(proxy.isEnabled(), lineEdit->isEnabled()); |
|
1677 |
proxy.setEnabled(false); |
|
1678 |
QCOMPARE(proxy.isEnabled(), lineEdit->isEnabled()); |
|
1679 |
proxy.setEnabled(true); |
|
1680 |
QCOMPARE(proxy.isEnabled(), lineEdit->isEnabled()); |
|
1681 |
lineEdit->setEnabled(false); |
|
1682 |
QCOMPARE(proxy.isEnabled(), lineEdit->isEnabled()); |
|
1683 |
lineEdit->setEnabled(true); |
|
1684 |
QCOMPARE(proxy.isEnabled(), lineEdit->isEnabled()); |
|
1685 |
} |
|
1686 |
||
1687 |
void tst_QGraphicsProxyWidget::tabFocus_simpleWidget() |
|
1688 |
{ |
|
1689 |
QGraphicsScene scene; |
|
1690 |
QLineEdit *edit = new QLineEdit; |
|
1691 |
QGraphicsProxyWidget *editProxy = scene.addWidget(edit); |
|
1692 |
editProxy->show(); |
|
1693 |
||
1694 |
QDial *leftDial = new QDial; |
|
1695 |
QDial *rightDial = new QDial; |
|
1696 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
1697 |
||
1698 |
QWidget window; |
|
1699 |
QHBoxLayout *layout = new QHBoxLayout; |
|
1700 |
layout->addWidget(leftDial); |
|
1701 |
layout->addWidget(view); |
|
1702 |
layout->addWidget(rightDial); |
|
1703 |
window.setLayout(layout); |
|
1704 |
||
1705 |
window.show(); |
|
1706 |
QApplication::setActiveWindow(&window); |
|
1707 |
window.activateWindow(); |
|
1708 |
QTest::qWaitForWindowShown(&window); |
|
1709 |
||
1710 |
leftDial->setFocus(); |
|
1711 |
QApplication::processEvents(); |
|
1712 |
QTRY_VERIFY(leftDial->hasFocus()); |
|
1713 |
||
1714 |
EventSpy eventSpy(edit); |
|
1715 |
||
1716 |
// Tab into line edit |
|
1717 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
1718 |
QApplication::processEvents(); |
|
1719 |
QTRY_VERIFY(!leftDial->hasFocus()); |
|
1720 |
QTRY_VERIFY(view->hasFocus()); |
|
1721 |
QVERIFY(view->viewport()->hasFocus()); |
|
1722 |
QVERIFY(scene.hasFocus()); |
|
1723 |
QVERIFY(editProxy->hasFocus()); |
|
1724 |
QVERIFY(edit->hasFocus()); |
|
1725 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 1); |
|
1726 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 0); |
|
1727 |
||
1728 |
// Tab into right dial |
|
1729 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
1730 |
QApplication::processEvents(); |
|
1731 |
QTRY_VERIFY(!view->hasFocus()); |
|
1732 |
QVERIFY(!view->viewport()->hasFocus()); |
|
1733 |
QVERIFY(!scene.hasFocus()); |
|
1734 |
QVERIFY(!editProxy->hasFocus()); |
|
1735 |
QVERIFY(!edit->hasFocus()); |
|
1736 |
QTRY_VERIFY(rightDial->hasFocus()); |
|
1737 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 1); |
|
1738 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 1); |
|
1739 |
||
1740 |
// Backtab into line edit |
|
1741 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
1742 |
QApplication::processEvents(); |
|
1743 |
QTRY_VERIFY(view->hasFocus()); |
|
1744 |
QVERIFY(view->viewport()->hasFocus()); |
|
1745 |
QTRY_VERIFY(scene.hasFocus()); |
|
1746 |
QVERIFY(editProxy->hasFocus()); |
|
1747 |
QVERIFY(edit->hasFocus()); |
|
1748 |
QVERIFY(!rightDial->hasFocus()); |
|
1749 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 2); |
|
1750 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 1); |
|
1751 |
||
1752 |
// Backtab into left dial |
|
1753 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
1754 |
QApplication::processEvents(); |
|
1755 |
QTRY_VERIFY(!view->hasFocus()); |
|
1756 |
QVERIFY(!view->viewport()->hasFocus()); |
|
1757 |
QVERIFY(!scene.hasFocus()); |
|
1758 |
QVERIFY(!editProxy->hasFocus()); |
|
1759 |
QVERIFY(!edit->hasFocus()); |
|
1760 |
QTRY_VERIFY(leftDial->hasFocus()); |
|
1761 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 2); |
|
1762 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 2); |
|
1763 |
||
1764 |
delete view; |
|
1765 |
} |
|
1766 |
||
1767 |
void tst_QGraphicsProxyWidget::tabFocus_simpleTwoWidgets() |
|
1768 |
{ |
|
1769 |
QGraphicsScene scene; |
|
1770 |
QLineEdit *edit = new QLineEdit; |
|
1771 |
QLineEdit *edit2 = new QLineEdit; |
|
1772 |
QGraphicsProxyWidget *editProxy = scene.addWidget(edit); |
|
1773 |
editProxy->show(); |
|
1774 |
QGraphicsProxyWidget *editProxy2 = scene.addWidget(edit2); |
|
1775 |
editProxy2->show(); |
|
1776 |
editProxy2->setPos(0, editProxy->rect().height() * 1.1); |
|
1777 |
||
1778 |
QDial *leftDial = new QDial; |
|
1779 |
QDial *rightDial = new QDial; |
|
1780 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
1781 |
||
1782 |
QWidget window; |
|
1783 |
QHBoxLayout *layout = new QHBoxLayout; |
|
1784 |
layout->addWidget(leftDial); |
|
1785 |
layout->addWidget(view); |
|
1786 |
layout->addWidget(rightDial); |
|
1787 |
window.setLayout(layout); |
|
1788 |
||
1789 |
window.show(); |
|
1790 |
QApplication::setActiveWindow(&window); |
|
1791 |
window.activateWindow(); |
|
1792 |
QTest::qWaitForWindowShown(&window); |
|
1793 |
||
1794 |
leftDial->setFocus(); |
|
1795 |
QApplication::processEvents(); |
|
1796 |
QTRY_VERIFY(leftDial->hasFocus()); |
|
1797 |
||
1798 |
EventSpy eventSpy(edit); |
|
1799 |
EventSpy eventSpy2(edit2); |
|
1800 |
||
1801 |
// Tab into line edit |
|
1802 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
1803 |
QApplication::processEvents(); |
|
1804 |
QVERIFY(!leftDial->hasFocus()); |
|
1805 |
QVERIFY(view->hasFocus()); |
|
1806 |
QVERIFY(view->viewport()->hasFocus()); |
|
1807 |
QVERIFY(scene.hasFocus()); |
|
1808 |
QVERIFY(editProxy->hasFocus()); |
|
1809 |
QVERIFY(edit->hasFocus()); |
|
1810 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 1); |
|
1811 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 0); |
|
1812 |
||
1813 |
// Tab into second line edit |
|
1814 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
1815 |
QApplication::processEvents(); |
|
1816 |
QVERIFY(view->hasFocus()); |
|
1817 |
QVERIFY(view->viewport()->hasFocus()); |
|
1818 |
QVERIFY(scene.hasFocus()); |
|
1819 |
QVERIFY(!editProxy->hasFocus()); |
|
1820 |
QVERIFY(!edit->hasFocus()); |
|
1821 |
QVERIFY(editProxy2->hasFocus()); |
|
1822 |
QVERIFY(edit2->hasFocus()); |
|
1823 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 1); |
|
1824 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 1); |
|
1825 |
QCOMPARE(eventSpy2.counts[QEvent::FocusIn], 1); |
|
1826 |
QCOMPARE(eventSpy2.counts[QEvent::FocusOut], 0); |
|
1827 |
||
1828 |
// Tab into right dial |
|
1829 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
1830 |
QApplication::processEvents(); |
|
1831 |
QVERIFY(!view->hasFocus()); |
|
1832 |
QVERIFY(!view->viewport()->hasFocus()); |
|
1833 |
QVERIFY(!scene.hasFocus()); |
|
1834 |
QVERIFY(!editProxy->hasFocus()); |
|
1835 |
QVERIFY(!edit->hasFocus()); |
|
1836 |
QVERIFY(!editProxy2->hasFocus()); |
|
1837 |
QVERIFY(!edit2->hasFocus()); |
|
1838 |
QVERIFY(rightDial->hasFocus()); |
|
1839 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 1); |
|
1840 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 1); |
|
1841 |
QCOMPARE(eventSpy2.counts[QEvent::FocusIn], 1); |
|
1842 |
QCOMPARE(eventSpy2.counts[QEvent::FocusOut], 1); |
|
1843 |
||
1844 |
// Backtab into line edit 2 |
|
1845 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
1846 |
QApplication::processEvents(); |
|
1847 |
QVERIFY(view->hasFocus()); |
|
1848 |
QVERIFY(view->viewport()->hasFocus()); |
|
1849 |
QVERIFY(scene.hasFocus()); |
|
1850 |
QVERIFY(!editProxy->hasFocus()); |
|
1851 |
QVERIFY(!edit->hasFocus()); |
|
1852 |
QVERIFY(editProxy2->hasFocus()); |
|
1853 |
QVERIFY(edit2->hasFocus()); |
|
1854 |
QVERIFY(!rightDial->hasFocus()); |
|
1855 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 1); |
|
1856 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 1); |
|
1857 |
QCOMPARE(eventSpy2.counts[QEvent::FocusIn], 2); |
|
1858 |
QCOMPARE(eventSpy2.counts[QEvent::FocusOut], 1); |
|
1859 |
||
1860 |
// Backtab into line edit 1 |
|
1861 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
1862 |
QApplication::processEvents(); |
|
1863 |
QVERIFY(view->hasFocus()); |
|
1864 |
QVERIFY(view->viewport()->hasFocus()); |
|
1865 |
QVERIFY(scene.hasFocus()); |
|
1866 |
QVERIFY(editProxy->hasFocus()); |
|
1867 |
QVERIFY(edit->hasFocus()); |
|
1868 |
QVERIFY(!editProxy2->hasFocus()); |
|
1869 |
QVERIFY(!edit2->hasFocus()); |
|
1870 |
QVERIFY(!rightDial->hasFocus()); |
|
1871 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 2); |
|
1872 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 1); |
|
1873 |
QCOMPARE(eventSpy2.counts[QEvent::FocusIn], 2); |
|
1874 |
QCOMPARE(eventSpy2.counts[QEvent::FocusOut], 2); |
|
1875 |
||
1876 |
// Backtab into left dial |
|
1877 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
1878 |
QApplication::processEvents(); |
|
1879 |
QVERIFY(!view->hasFocus()); |
|
1880 |
QVERIFY(!view->viewport()->hasFocus()); |
|
1881 |
QVERIFY(!scene.hasFocus()); |
|
1882 |
QVERIFY(!editProxy->hasFocus()); |
|
1883 |
QVERIFY(!edit->hasFocus()); |
|
1884 |
QVERIFY(leftDial->hasFocus()); |
|
1885 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 2); |
|
1886 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 2); |
|
1887 |
||
1888 |
delete view; |
|
1889 |
} |
|
1890 |
||
1891 |
void tst_QGraphicsProxyWidget::tabFocus_complexWidget() |
|
1892 |
{ |
|
1893 |
QGraphicsScene scene; |
|
1894 |
||
1895 |
QLineEdit *edit1 = new QLineEdit; |
|
1896 |
edit1->setText("QLineEdit 1"); |
|
1897 |
QLineEdit *edit2 = new QLineEdit; |
|
1898 |
edit2->setText("QLineEdit 2"); |
|
1899 |
QVBoxLayout *vlayout = new QVBoxLayout; |
|
1900 |
vlayout->addWidget(edit1); |
|
1901 |
vlayout->addWidget(edit2); |
|
1902 |
||
1903 |
QGroupBox *box = new QGroupBox("QGroupBox"); |
|
1904 |
box->setCheckable(true); |
|
1905 |
box->setChecked(true); |
|
1906 |
box->setLayout(vlayout); |
|
1907 |
||
1908 |
QGraphicsProxyWidget *proxy = scene.addWidget(box); |
|
1909 |
proxy->show(); |
|
1910 |
||
1911 |
QDial *leftDial = new QDial; |
|
1912 |
QDial *rightDial = new QDial; |
|
1913 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
1914 |
||
1915 |
QWidget window; |
|
1916 |
QHBoxLayout *layout = new QHBoxLayout; |
|
1917 |
layout->addWidget(leftDial); |
|
1918 |
layout->addWidget(view); |
|
1919 |
layout->addWidget(rightDial); |
|
1920 |
window.setLayout(layout); |
|
1921 |
||
1922 |
window.show(); |
|
1923 |
QApplication::setActiveWindow(&window); |
|
1924 |
window.activateWindow(); |
|
1925 |
QTest::qWaitForWindowShown(&window); |
|
1926 |
||
1927 |
leftDial->setFocus(); |
|
1928 |
QApplication::processEvents(); |
|
1929 |
QTRY_VERIFY(leftDial->hasFocus()); |
|
1930 |
||
1931 |
EventSpy eventSpy(edit1); |
|
1932 |
EventSpy eventSpy2(edit2); |
|
1933 |
EventSpy eventSpyBox(box); |
|
1934 |
||
1935 |
// Tab into group box |
|
1936 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
1937 |
QApplication::processEvents(); |
|
1938 |
QVERIFY(!leftDial->hasFocus()); |
|
1939 |
QVERIFY(view->hasFocus()); |
|
1940 |
QVERIFY(view->viewport()->hasFocus()); |
|
1941 |
QVERIFY(scene.hasFocus()); |
|
1942 |
QVERIFY(proxy->hasFocus()); |
|
1943 |
QVERIFY(box->hasFocus()); |
|
1944 |
||
1945 |
// Tab into line edit |
|
1946 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
1947 |
QApplication::processEvents(); |
|
1948 |
edit1->hasFocus(); |
|
1949 |
QVERIFY(!box->hasFocus()); |
|
1950 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 1); |
|
1951 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 0); |
|
1952 |
||
1953 |
// Tab into line edit 2 |
|
1954 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
1955 |
QApplication::processEvents(); |
|
1956 |
edit2->hasFocus(); |
|
1957 |
QVERIFY(!edit1->hasFocus()); |
|
1958 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 1); |
|
1959 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 1); |
|
1960 |
QCOMPARE(eventSpy2.counts[QEvent::FocusIn], 1); |
|
1961 |
QCOMPARE(eventSpy2.counts[QEvent::FocusOut], 0); |
|
1962 |
||
1963 |
// Tab into right dial |
|
1964 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
1965 |
QApplication::processEvents(); |
|
1966 |
QVERIFY(!edit2->hasFocus()); |
|
1967 |
rightDial->hasFocus(); |
|
1968 |
QCOMPARE(eventSpy2.counts[QEvent::FocusIn], 1); |
|
1969 |
QCOMPARE(eventSpy2.counts[QEvent::FocusOut], 1); |
|
1970 |
||
1971 |
// Backtab into line edit 2 |
|
1972 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
1973 |
QApplication::processEvents(); |
|
1974 |
QVERIFY(!rightDial->hasFocus()); |
|
1975 |
edit2->hasFocus(); |
|
1976 |
QCOMPARE(eventSpy2.counts[QEvent::FocusIn], 2); |
|
1977 |
QCOMPARE(eventSpy2.counts[QEvent::FocusOut], 1); |
|
1978 |
||
1979 |
// Backtab into line edit 1 |
|
1980 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
1981 |
QApplication::processEvents(); |
|
1982 |
QVERIFY(!edit2->hasFocus()); |
|
1983 |
edit1->hasFocus(); |
|
1984 |
QCOMPARE(eventSpy2.counts[QEvent::FocusOut], 2); |
|
1985 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 2); |
|
1986 |
||
1987 |
// Backtab into line box |
|
1988 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
1989 |
QApplication::processEvents(); |
|
1990 |
QVERIFY(!edit1->hasFocus()); |
|
1991 |
box->hasFocus(); |
|
1992 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 2); |
|
1993 |
||
1994 |
// Backtab into left dial |
|
1995 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
1996 |
QApplication::processEvents(); |
|
1997 |
QVERIFY(!box->hasFocus()); |
|
1998 |
leftDial->hasFocus(); |
|
1999 |
||
2000 |
delete view; |
|
2001 |
} |
|
2002 |
||
2003 |
void tst_QGraphicsProxyWidget::tabFocus_complexTwoWidgets() |
|
2004 |
{ |
|
2005 |
// ### add event spies to this test. |
|
2006 |
QGraphicsScene scene; |
|
2007 |
||
2008 |
QLineEdit *edit1 = new QLineEdit; |
|
2009 |
edit1->setText("QLineEdit 1"); |
|
2010 |
QLineEdit *edit2 = new QLineEdit; |
|
2011 |
edit2->setText("QLineEdit 2"); |
|
2012 |
QFontComboBox *fontComboBox = new QFontComboBox; |
|
2013 |
QVBoxLayout *vlayout = new QVBoxLayout; |
|
2014 |
vlayout->addWidget(edit1); |
|
2015 |
vlayout->addWidget(fontComboBox); |
|
2016 |
vlayout->addWidget(edit2); |
|
2017 |
||
2018 |
QGroupBox *box = new QGroupBox("QGroupBox"); |
|
2019 |
box->setCheckable(true); |
|
2020 |
box->setChecked(true); |
|
2021 |
box->setLayout(vlayout); |
|
2022 |
||
2023 |
QLineEdit *edit1_2 = new QLineEdit; |
|
2024 |
edit1_2->setText("QLineEdit 1_2"); |
|
2025 |
QLineEdit *edit2_2 = new QLineEdit; |
|
2026 |
edit2_2->setText("QLineEdit 2_2"); |
|
2027 |
QFontComboBox *fontComboBox2 = new QFontComboBox; |
|
2028 |
vlayout = new QVBoxLayout; |
|
2029 |
vlayout->addWidget(edit1_2); |
|
2030 |
vlayout->addWidget(fontComboBox2); |
|
2031 |
vlayout->addWidget(edit2_2); |
|
2032 |
||
2033 |
QGroupBox *box_2 = new QGroupBox("QGroupBox 2"); |
|
2034 |
box_2->setCheckable(true); |
|
2035 |
box_2->setChecked(true); |
|
2036 |
box_2->setLayout(vlayout); |
|
2037 |
||
2038 |
QGraphicsProxyWidget *proxy = scene.addWidget(box); |
|
2039 |
proxy->show(); |
|
2040 |
||
2041 |
QGraphicsProxyWidget *proxy_2 = scene.addWidget(box_2); |
|
2042 |
proxy_2->setPos(proxy->boundingRect().width() * 1.2, 0); |
|
2043 |
proxy_2->show(); |
|
2044 |
||
2045 |
QDial *leftDial = new QDial; |
|
2046 |
QDial *rightDial = new QDial; |
|
2047 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
2048 |
view->setRenderHint(QPainter::Antialiasing); |
|
2049 |
view->rotate(45); |
|
2050 |
view->scale(0.5, 0.5); |
|
2051 |
||
2052 |
QWidget window; |
|
2053 |
QHBoxLayout *layout = new QHBoxLayout; |
|
2054 |
layout->addWidget(leftDial); |
|
2055 |
layout->addWidget(view); |
|
2056 |
layout->addWidget(rightDial); |
|
2057 |
window.setLayout(layout); |
|
2058 |
||
2059 |
window.show(); |
|
2060 |
QApplication::setActiveWindow(&window); |
|
2061 |
window.activateWindow(); |
|
2062 |
QTest::qWaitForWindowShown(&window); |
|
2063 |
QTRY_COMPARE(QApplication::activeWindow(), &window); |
|
2064 |
||
2065 |
leftDial->setFocus(); |
|
2066 |
QApplication::processEvents(); |
|
2067 |
QTRY_VERIFY(leftDial->hasFocus()); |
|
2068 |
||
2069 |
EventSpy eventSpy(edit1); |
|
2070 |
EventSpy eventSpy2(edit2); |
|
2071 |
EventSpy eventSpy3(fontComboBox); |
|
2072 |
EventSpy eventSpy1_2(edit1_2); |
|
2073 |
EventSpy eventSpy2_2(edit2_2); |
|
2074 |
EventSpy eventSpy2_3(fontComboBox2); |
|
2075 |
EventSpy eventSpyBox(box); |
|
2076 |
||
2077 |
// Tab into group box |
|
2078 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
2079 |
QApplication::processEvents(); |
|
2080 |
QVERIFY(!leftDial->hasFocus()); |
|
2081 |
QVERIFY(view->hasFocus()); |
|
2082 |
QVERIFY(view->viewport()->hasFocus()); |
|
2083 |
QVERIFY(scene.hasFocus()); |
|
2084 |
QVERIFY(proxy->hasFocus()); |
|
2085 |
QVERIFY(box->hasFocus()); |
|
2086 |
||
2087 |
// Tab into line edit |
|
2088 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
2089 |
QApplication::processEvents(); |
|
2090 |
edit1->hasFocus(); |
|
2091 |
QVERIFY(!box->hasFocus()); |
|
2092 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 1); |
|
2093 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 0); |
|
2094 |
||
2095 |
// Tab to the font combobox |
|
2096 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
2097 |
QApplication::processEvents(); |
|
2098 |
fontComboBox->hasFocus(); |
|
2099 |
QVERIFY(!edit2->hasFocus()); |
|
2100 |
QCOMPARE(eventSpy3.counts[QEvent::FocusIn], 1); |
|
2101 |
QCOMPARE(eventSpy3.counts[QEvent::FocusOut], 0); |
|
2102 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 1); |
|
2103 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 1); |
|
2104 |
||
2105 |
// Tab into line edit 2 |
|
2106 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
2107 |
QApplication::processEvents(); |
|
2108 |
edit2->hasFocus(); |
|
2109 |
QVERIFY(!edit1->hasFocus()); |
|
2110 |
QCOMPARE(eventSpy2.counts[QEvent::FocusIn], 1); |
|
2111 |
QCOMPARE(eventSpy2.counts[QEvent::FocusOut], 0); |
|
2112 |
QCOMPARE(eventSpy3.counts[QEvent::FocusOut], 1); |
|
2113 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 1); |
|
2114 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 1); |
|
2115 |
||
2116 |
// Tab into right box |
|
2117 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
2118 |
QApplication::processEvents(); |
|
2119 |
QVERIFY(!edit2->hasFocus()); |
|
2120 |
box_2->hasFocus(); |
|
2121 |
||
2122 |
// Tab into right top line edit |
|
2123 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
2124 |
QApplication::processEvents(); |
|
2125 |
QVERIFY(!box_2->hasFocus()); |
|
2126 |
edit1_2->hasFocus(); |
|
2127 |
QCOMPARE(eventSpy1_2.counts[QEvent::FocusIn], 1); |
|
2128 |
QCOMPARE(eventSpy1_2.counts[QEvent::FocusOut], 0); |
|
2129 |
||
2130 |
// Tab into right font combobox |
|
2131 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
2132 |
QApplication::processEvents(); |
|
2133 |
QVERIFY(!edit1_2->hasFocus()); |
|
2134 |
fontComboBox2->hasFocus(); |
|
2135 |
QCOMPARE(eventSpy1_2.counts[QEvent::FocusIn], 1); |
|
2136 |
QCOMPARE(eventSpy1_2.counts[QEvent::FocusOut], 1); |
|
2137 |
QCOMPARE(eventSpy2_3.counts[QEvent::FocusIn], 1); |
|
2138 |
QCOMPARE(eventSpy2_3.counts[QEvent::FocusOut], 0); |
|
2139 |
||
2140 |
// Tab into right bottom line edit |
|
2141 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
2142 |
QApplication::processEvents(); |
|
2143 |
QVERIFY(!edit1_2->hasFocus()); |
|
2144 |
edit2_2->hasFocus(); |
|
2145 |
QCOMPARE(eventSpy1_2.counts[QEvent::FocusIn], 1); |
|
2146 |
QCOMPARE(eventSpy1_2.counts[QEvent::FocusOut], 1); |
|
2147 |
QCOMPARE(eventSpy2_3.counts[QEvent::FocusIn], 1); |
|
2148 |
QCOMPARE(eventSpy2_3.counts[QEvent::FocusOut], 1); |
|
2149 |
QCOMPARE(eventSpy2_2.counts[QEvent::FocusIn], 1); |
|
2150 |
QCOMPARE(eventSpy2_2.counts[QEvent::FocusOut], 0); |
|
2151 |
||
2152 |
// Tab into right dial |
|
2153 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); |
|
2154 |
QApplication::processEvents(); |
|
2155 |
QVERIFY(!edit2->hasFocus()); |
|
2156 |
rightDial->hasFocus(); |
|
2157 |
QCOMPARE(eventSpy2_2.counts[QEvent::FocusOut], 1); |
|
2158 |
||
2159 |
// Backtab into line edit 2 |
|
2160 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
2161 |
QApplication::processEvents(); |
|
2162 |
QVERIFY(!rightDial->hasFocus()); |
|
2163 |
edit2_2->hasFocus(); |
|
2164 |
||
2165 |
// Backtab into the right font combobox |
|
2166 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
2167 |
QApplication::processEvents(); |
|
2168 |
QVERIFY(!edit2_2->hasFocus()); |
|
2169 |
fontComboBox2->hasFocus(); |
|
2170 |
||
2171 |
// Backtab into line edit 1 |
|
2172 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
2173 |
QApplication::processEvents(); |
|
2174 |
QVERIFY(!edit2_2->hasFocus()); |
|
2175 |
edit1_2->hasFocus(); |
|
2176 |
||
2177 |
// Backtab into line box |
|
2178 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
2179 |
QApplication::processEvents(); |
|
2180 |
QVERIFY(!edit1_2->hasFocus()); |
|
2181 |
box_2->hasFocus(); |
|
2182 |
||
2183 |
// Backtab into line edit 2 |
|
2184 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
2185 |
QApplication::processEvents(); |
|
2186 |
QVERIFY(!rightDial->hasFocus()); |
|
2187 |
edit2->hasFocus(); |
|
2188 |
||
2189 |
// Backtab into the font combobox |
|
2190 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
2191 |
QApplication::processEvents(); |
|
2192 |
QVERIFY(!edit2->hasFocus()); |
|
2193 |
fontComboBox->hasFocus(); |
|
2194 |
||
2195 |
// Backtab into line edit 1 |
|
2196 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
2197 |
QApplication::processEvents(); |
|
2198 |
QVERIFY(!fontComboBox->hasFocus()); |
|
2199 |
edit1->hasFocus(); |
|
2200 |
||
2201 |
// Backtab into line box |
|
2202 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
2203 |
QApplication::processEvents(); |
|
2204 |
QVERIFY(!edit1->hasFocus()); |
|
2205 |
box->hasFocus(); |
|
2206 |
||
2207 |
// Backtab into left dial |
|
2208 |
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); |
|
2209 |
QApplication::processEvents(); |
|
2210 |
QVERIFY(!box->hasFocus()); |
|
2211 |
leftDial->hasFocus(); |
|
2212 |
||
2213 |
delete view; |
|
2214 |
} |
|
2215 |
||
2216 |
void tst_QGraphicsProxyWidget::setFocus_simpleWidget() |
|
2217 |
{ |
|
2218 |
QGraphicsScene scene; |
|
2219 |
QLineEdit *edit = new QLineEdit; |
|
2220 |
QGraphicsProxyWidget *editProxy = scene.addWidget(edit); |
|
2221 |
editProxy->show(); |
|
2222 |
||
2223 |
QDial *leftDial = new QDial; |
|
2224 |
QDial *rightDial = new QDial; |
|
2225 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
2226 |
||
2227 |
QWidget window; |
|
2228 |
QHBoxLayout *layout = new QHBoxLayout; |
|
2229 |
layout->addWidget(leftDial); |
|
2230 |
layout->addWidget(view); |
|
2231 |
layout->addWidget(rightDial); |
|
2232 |
window.setLayout(layout); |
|
2233 |
||
2234 |
window.show(); |
|
2235 |
QApplication::setActiveWindow(&window); |
|
2236 |
window.activateWindow(); |
|
2237 |
QTest::qWaitForWindowShown(&window); |
|
2238 |
QTRY_COMPARE(QApplication::activeWindow(), &window); |
|
2239 |
||
2240 |
leftDial->setFocus(); |
|
2241 |
QApplication::processEvents(); |
|
2242 |
QTRY_VERIFY(leftDial->hasFocus()); |
|
2243 |
||
2244 |
EventSpy eventSpy(edit); |
|
2245 |
||
2246 |
// Calling setFocus for the line edit when the view doesn't have input |
|
2247 |
// focus does not steal focus from the dial. The edit, proxy and scene |
|
2248 |
// have focus but only in their own little space. |
|
2249 |
edit->setFocus(); |
|
2250 |
QVERIFY(scene.hasFocus()); |
|
2251 |
QVERIFY(edit->hasFocus()); |
|
2252 |
QVERIFY(!view->hasFocus()); |
|
2253 |
QVERIFY(!view->viewport()->hasFocus()); |
|
2254 |
QVERIFY(leftDial->hasFocus()); |
|
2255 |
||
2256 |
// Clearing focus is a local operation. |
|
2257 |
edit->clearFocus(); |
|
2258 |
QVERIFY(scene.hasFocus()); |
|
2259 |
QVERIFY(!edit->hasFocus()); |
|
2260 |
QVERIFY(!view->hasFocus()); |
|
2261 |
QVERIFY(leftDial->hasFocus()); |
|
2262 |
||
2263 |
view->setFocus(); |
|
2264 |
QVERIFY(scene.hasFocus()); |
|
2265 |
QVERIFY(view->hasFocus()); |
|
2266 |
QVERIFY(!leftDial->hasFocus()); |
|
2267 |
QVERIFY(!edit->hasFocus()); |
|
2268 |
||
2269 |
scene.clearFocus(); |
|
2270 |
QVERIFY(!scene.hasFocus()); |
|
2271 |
||
2272 |
edit->setFocus(); |
|
2273 |
QVERIFY(scene.hasFocus()); |
|
2274 |
QVERIFY(edit->hasFocus()); |
|
2275 |
QVERIFY(editProxy->hasFocus()); |
|
2276 |
||
2277 |
// Symmetry |
|
2278 |
editProxy->clearFocus(); |
|
2279 |
QVERIFY(!edit->hasFocus()); |
|
2280 |
||
2281 |
delete view; |
|
2282 |
} |
|
2283 |
||
2284 |
void tst_QGraphicsProxyWidget::setFocus_simpleTwoWidgets() |
|
2285 |
{ |
|
2286 |
QGraphicsScene scene; |
|
2287 |
QLineEdit *edit = new QLineEdit; |
|
2288 |
QGraphicsProxyWidget *editProxy = scene.addWidget(edit); |
|
2289 |
editProxy->show(); |
|
2290 |
QLineEdit *edit2 = new QLineEdit; |
|
2291 |
QGraphicsProxyWidget *edit2Proxy = scene.addWidget(edit2); |
|
2292 |
edit2Proxy->show(); |
|
2293 |
edit2Proxy->setPos(editProxy->boundingRect().width() * 1.01, 0); |
|
2294 |
||
2295 |
QDial *leftDial = new QDial; |
|
2296 |
QDial *rightDial = new QDial; |
|
2297 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
2298 |
||
2299 |
QWidget window; |
|
2300 |
QHBoxLayout *layout = new QHBoxLayout; |
|
2301 |
layout->addWidget(leftDial); |
|
2302 |
layout->addWidget(view); |
|
2303 |
layout->addWidget(rightDial); |
|
2304 |
window.setLayout(layout); |
|
2305 |
||
2306 |
window.show(); |
|
2307 |
QApplication::setActiveWindow(&window); |
|
2308 |
window.activateWindow(); |
|
2309 |
QTest::qWaitForWindowShown(&window); |
|
2310 |
QTRY_COMPARE(QApplication::activeWindow(), &window); |
|
2311 |
||
2312 |
leftDial->setFocus(); |
|
2313 |
QApplication::processEvents(); |
|
2314 |
QTRY_VERIFY(leftDial->hasFocus()); |
|
2315 |
||
2316 |
EventSpy eventSpy(edit); |
|
2317 |
||
2318 |
view->setFocus(); |
|
2319 |
QVERIFY(!edit->hasFocus()); |
|
2320 |
||
2321 |
edit->setFocus(); |
|
2322 |
QVERIFY(scene.hasFocus()); |
|
2323 |
QVERIFY(edit->hasFocus()); |
|
2324 |
QVERIFY(editProxy->hasFocus()); |
|
2325 |
||
2326 |
edit2->setFocus(); |
|
2327 |
QVERIFY(scene.hasFocus()); |
|
2328 |
QVERIFY(!edit->hasFocus()); |
|
2329 |
QVERIFY(!editProxy->hasFocus()); |
|
2330 |
QVERIFY(edit2->hasFocus()); |
|
2331 |
QVERIFY(edit2Proxy->hasFocus()); |
|
2332 |
||
2333 |
delete view; |
|
2334 |
} |
|
2335 |
||
2336 |
void tst_QGraphicsProxyWidget::setFocus_complexTwoWidgets() |
|
2337 |
{ |
|
2338 |
// ### add event spies to this test. |
|
2339 |
QGraphicsScene scene; |
|
2340 |
||
2341 |
QLineEdit *edit1 = new QLineEdit; |
|
2342 |
edit1->setText("QLineEdit 1"); |
|
2343 |
QLineEdit *edit2 = new QLineEdit; |
|
2344 |
edit2->setText("QLineEdit 2"); |
|
2345 |
QVBoxLayout *vlayout = new QVBoxLayout; |
|
2346 |
vlayout->addWidget(edit1); |
|
2347 |
vlayout->addWidget(edit2); |
|
2348 |
||
2349 |
QGroupBox *box = new QGroupBox("QGroupBox"); |
|
2350 |
box->setCheckable(true); |
|
2351 |
box->setChecked(true); |
|
2352 |
box->setLayout(vlayout); |
|
2353 |
||
2354 |
QLineEdit *edit1_2 = new QLineEdit; |
|
2355 |
edit1_2->setText("QLineEdit 1_2"); |
|
2356 |
QLineEdit *edit2_2 = new QLineEdit; |
|
2357 |
edit2_2->setText("QLineEdit 2_2"); |
|
2358 |
vlayout = new QVBoxLayout; |
|
2359 |
vlayout->addWidget(edit1_2); |
|
2360 |
vlayout->addWidget(edit2_2); |
|
2361 |
||
2362 |
QGroupBox *box_2 = new QGroupBox("QGroupBox 2"); |
|
2363 |
box_2->setCheckable(true); |
|
2364 |
box_2->setChecked(true); |
|
2365 |
box_2->setLayout(vlayout); |
|
2366 |
||
2367 |
QGraphicsProxyWidget *proxy = scene.addWidget(box); |
|
2368 |
proxy->show(); |
|
2369 |
||
2370 |
QGraphicsProxyWidget *proxy_2 = scene.addWidget(box_2); |
|
2371 |
proxy_2->setPos(proxy->boundingRect().width() * 1.2, 0); |
|
2372 |
proxy_2->show(); |
|
2373 |
||
2374 |
QDial *leftDial = new QDial; |
|
2375 |
QDial *rightDial = new QDial; |
|
2376 |
QGraphicsView *view = new QGraphicsView(&scene); |
|
2377 |
||
2378 |
QWidget window; |
|
2379 |
QHBoxLayout *layout = new QHBoxLayout; |
|
2380 |
layout->addWidget(leftDial); |
|
2381 |
layout->addWidget(view); |
|
2382 |
layout->addWidget(rightDial); |
|
2383 |
window.setLayout(layout); |
|
2384 |
||
2385 |
window.show(); |
|
2386 |
QApplication::setActiveWindow(&window); |
|
2387 |
window.activateWindow(); |
|
2388 |
QTest::qWaitForWindowShown(&window); |
|
2389 |
QTRY_COMPARE(QApplication::activeWindow(), &window); |
|
2390 |
||
2391 |
leftDial->setFocus(); |
|
2392 |
QApplication::processEvents(); |
|
2393 |
QTRY_VERIFY(leftDial->hasFocus()); |
|
2394 |
||
2395 |
EventSpy eventSpy(edit1); |
|
2396 |
EventSpy eventSpy2(edit2); |
|
2397 |
EventSpy eventSpyBox(box); |
|
2398 |
EventSpy eventSpy_2(edit1_2); |
|
2399 |
EventSpy eventSpy2_2(edit2_2); |
|
2400 |
EventSpy eventSpyBox_2(box_2); |
|
2401 |
||
2402 |
view->setFocus(); |
|
2403 |
||
2404 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 0); |
|
2405 |
||
2406 |
edit1->setFocus(); |
|
2407 |
QApplication::processEvents(); |
|
2408 |
QVERIFY(scene.hasFocus()); |
|
2409 |
QVERIFY(edit1->hasFocus()); |
|
2410 |
QVERIFY(!box->hasFocus()); |
|
2411 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 1); |
|
2412 |
QCOMPARE(eventSpyBox.counts[QEvent::FocusIn], 0); |
|
2413 |
||
2414 |
edit2_2->setFocus(); |
|
2415 |
QApplication::processEvents(); |
|
2416 |
QVERIFY(!edit1->hasFocus()); |
|
2417 |
QVERIFY(!box_2->hasFocus()); |
|
2418 |
QVERIFY(edit2_2->hasFocus()); |
|
2419 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 1); |
|
2420 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 1); |
|
2421 |
QCOMPARE(eventSpy2_2.counts[QEvent::FocusIn], 1); |
|
2422 |
QCOMPARE(eventSpyBox.counts[QEvent::FocusIn], 0); |
|
2423 |
QCOMPARE(eventSpyBox_2.counts[QEvent::FocusIn], 0); |
|
2424 |
||
2425 |
box->setFocus(); |
|
2426 |
QApplication::processEvents(); |
|
2427 |
QVERIFY(!edit2_2->hasFocus()); |
|
2428 |
QVERIFY(!edit1->hasFocus()); |
|
2429 |
QVERIFY(box->hasFocus()); |
|
2430 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 1); |
|
2431 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 1); |
|
2432 |
QCOMPARE(eventSpy2_2.counts[QEvent::FocusIn], 1); |
|
2433 |
QCOMPARE(eventSpy2_2.counts[QEvent::FocusOut], 1); |
|
2434 |
QCOMPARE(eventSpyBox.counts[QEvent::FocusIn], 1); |
|
2435 |
QCOMPARE(eventSpyBox.counts[QEvent::FocusOut], 0); |
|
2436 |
QCOMPARE(eventSpyBox_2.counts[QEvent::FocusIn], 0); |
|
2437 |
QCOMPARE(eventSpyBox_2.counts[QEvent::FocusOut], 0); |
|
2438 |
||
2439 |
edit2_2->setFocus(); |
|
2440 |
QApplication::processEvents(); |
|
2441 |
QVERIFY(edit2_2->hasFocus()); |
|
2442 |
QVERIFY(!edit1->hasFocus()); |
|
2443 |
QVERIFY(!box->hasFocus()); |
|
2444 |
QVERIFY(!box_2->hasFocus()); |
|
2445 |
QCOMPARE(eventSpy.counts[QEvent::FocusIn], 1); |
|
2446 |
QCOMPARE(eventSpy.counts[QEvent::FocusOut], 1); |
|
2447 |
QCOMPARE(eventSpy2_2.counts[QEvent::FocusIn], 2); |
|
2448 |
QCOMPARE(eventSpy2_2.counts[QEvent::FocusOut], 1); |
|
2449 |
QCOMPARE(eventSpyBox.counts[QEvent::FocusIn], 1); |
|
2450 |
QCOMPARE(eventSpyBox.counts[QEvent::FocusOut], 1); |
|
2451 |
QCOMPARE(eventSpyBox_2.counts[QEvent::FocusIn], 0); |
|
2452 |
QCOMPARE(eventSpyBox_2.counts[QEvent::FocusOut], 0); |
|
2453 |
||
2454 |
delete view; |
|
2455 |
} |
|
2456 |
||
2457 |
void tst_QGraphicsProxyWidget::popup_basic() |
|
2458 |
{ |
|
2459 |
// ProxyWidget should automatically create proxy's when the widget creates a child |
|
2460 |
QGraphicsScene *scene = new QGraphicsScene; |
|
2461 |
QGraphicsView view(scene); |
|
2462 |
view.setAlignment(Qt::AlignLeft | Qt::AlignTop); |
|
2463 |
view.setGeometry(0, 100, 480, 500); |
|
2464 |
view.show(); |
|
2465 |
||
2466 |
SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; |
|
2467 |
QComboBox *box = new QComboBox; |
|
2468 |
box->setGeometry(0, 0, 320, 40); |
|
2469 |
box->addItems(QStringList() << "monday" << "tuesday" << "wednesday" |
|
2470 |
<< "thursday" << "saturday" << "sunday"); |
|
2471 |
QCOMPARE(proxy->childItems().count(), 0); |
|
2472 |
proxy->setWidget(box); |
|
2473 |
proxy->show(); |
|
2474 |
scene->addItem(proxy); |
|
2475 |
||
2476 |
QCOMPARE(box->pos(), QPoint()); |
|
2477 |
QCOMPARE(proxy->pos(), QPointF()); |
|
2478 |
||
2479 |
QTest::qWaitForWindowShown(&view); |
|
2480 |
QTest::qWait(125); |
|
2481 |
QApplication::processEvents(); |
|
2482 |
||
2483 |
QTest::mousePress(view.viewport(), Qt::LeftButton, 0, |
|
2484 |
view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center()))); |
|
2485 |
||
2486 |
QTest::qWait(12); |
|
2487 |
||
2488 |
QCOMPARE(box->pos(), QPoint()); |
|
2489 |
||
2490 |
QCOMPARE(proxy->childItems().count(), 1); |
|
2491 |
QGraphicsProxyWidget *child = (QGraphicsProxyWidget*)(proxy->childItems())[0]; |
|
2492 |
QVERIFY(child->isWidget()); |
|
2493 |
QVERIFY(child->widget()); |
|
2494 |
QStyleOptionComboBox opt; |
|
2495 |
opt.initFrom(box); |
|
2496 |
opt.editable = box->isEditable(); |
|
2497 |
if (box->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt)) |
|
2498 |
QSKIP("Does not work due to SH_Combobox_Popup", SkipAll); |
|
2499 |
QCOMPARE(child->widget()->parent(), static_cast<QObject*>(box)); |
|
2500 |
||
2501 |
QTest::qWait(12); |
|
2502 |
QTRY_COMPARE(proxy->pos(), QPointF(box->pos())); |
|
2503 |
QCOMPARE(child->x(), qreal(box->x())); |
|
2504 |
QCOMPARE(child->y(), qreal(box->rect().bottom())); |
|
2505 |
#ifndef Q_OS_WIN |
|
2506 |
// The popup's coordinates on Windows are in global space, |
|
2507 |
// regardless. |
|
2508 |
QCOMPARE(child->widget()->x(), box->x()); |
|
2509 |
QCOMPARE(child->widget()->y(), box->rect().bottom()); |
|
2510 |
QCOMPARE(child->geometry().toRect(), child->widget()->geometry()); |
|
2511 |
#endif |
|
2512 |
QTest::qWait(12); |
|
2513 |
} |
|
2514 |
||
2515 |
void tst_QGraphicsProxyWidget::popup_subwidget() |
|
2516 |
{ |
|
2517 |
QGroupBox *groupBox = new QGroupBox; |
|
2518 |
groupBox->setTitle("GroupBox"); |
|
2519 |
groupBox->setCheckable(true); |
|
2520 |
||
2521 |
QComboBox *box = new QComboBox; |
|
2522 |
box->addItems(QStringList() << "monday" << "tuesday" << "wednesday" |
|
2523 |
<< "thursday" << "saturday" << "sunday"); |
|
2524 |
||
2525 |
QVBoxLayout *layout = new QVBoxLayout; |
|
2526 |
layout->addWidget(new QLineEdit("QLineEdit")); |
|
2527 |
layout->addWidget(box); |
|
2528 |
layout->addWidget(new QLineEdit("QLineEdit")); |
|
2529 |
groupBox->setLayout(layout); |
|
2530 |
||
2531 |
QGraphicsScene scene; |
|
2532 |
QGraphicsProxyWidget *groupBoxProxy = scene.addWidget(groupBox); |
|
2533 |
groupBox->show(); |
|
2534 |
groupBox->move(10000, 10000); |
|
2535 |
QCOMPARE(groupBox->pos(), QPoint(10000, 10000)); |
|
2536 |
QCOMPARE(groupBoxProxy->pos(), QPointF(10000, 10000)); |
|
2537 |
||
2538 |
QGraphicsView view(&scene); |
|
2539 |
view.show(); |
|
2540 |
#ifdef Q_WS_X11 |
|
2541 |
qt_x11_wait_for_window_manager(&view); |
|
2542 |
#endif |
|
2543 |
||
2544 |
box->showPopup(); |
|
2545 |
||
2546 |
QVERIFY(!groupBoxProxy->childItems().isEmpty()); |
|
2547 |
||
2548 |
QStyleOptionComboBox opt; |
|
2549 |
opt.initFrom(box); |
|
2550 |
opt.editable = box->isEditable(); |
|
2551 |
if (box->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt)) |
|
2552 |
QSKIP("Does not work due to SH_Combobox_Popup", SkipAll); |
|
2553 |
QGraphicsProxyWidget *child = (QGraphicsProxyWidget*)(groupBoxProxy->childItems())[0]; |
|
2554 |
QWidget *popup = child->widget(); |
|
2555 |
QCOMPARE(popup->parent(), static_cast<QObject*>(box)); |
|
2556 |
QCOMPARE(popup->x(), box->mapToGlobal(QPoint()).x()); |
|
2557 |
QCOMPARE(popup->y(), QRect(box->mapToGlobal(QPoint()), box->size()).bottom()); |
|
2558 |
QCOMPARE(popup->size(), child->size().toSize()); |
|
2559 |
} |
|
2560 |
||
2561 |
void tst_QGraphicsProxyWidget::changingCursor_basic() |
|
2562 |
{ |
|
2563 |
#if defined(Q_OS_WINCE) && (!defined(GWES_ICONCURS) || defined(QT_NO_CURSOR)) |
|
2564 |
QSKIP("hover events not supported on this platform", SkipAll); |
|
2565 |
#endif |
|
2566 |
#ifndef QT_NO_CURSOR |
|
2567 |
// Confirm that mouse events are working properly by checking that |
|
2568 |
// when moving the mouse over a line edit it will change the cursor into the I |
|
2569 |
QGraphicsScene scene; |
|
2570 |
QGraphicsView view(&scene); |
|
2571 |
view.show(); |
|
2572 |
||
2573 |
SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; |
|
2574 |
QLineEdit *widget = new QLineEdit; |
|
2575 |
proxy->setWidget(widget); |
|
2576 |
proxy->show(); |
|
2577 |
scene.addItem(proxy); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2578 |
QApplication::setActiveWindow(&view); |
0 | 2579 |
QTest::qWaitForWindowShown(&view); |
2580 |
QApplication::processEvents(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2581 |
QTRY_VERIFY(view.isActiveWindow()); |
0 | 2582 |
|
2583 |
// in |
|
2584 |
QTest::mouseMove(view.viewport(), view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center()))); |
|
2585 |
sendMouseMove(view.viewport(), view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center()))); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2586 |
QTest::qWait(12); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2587 |
QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); |
0 | 2588 |
|
2589 |
// out |
|
2590 |
QTest::mouseMove(view.viewport(), QPoint(1, 1)); |
|
2591 |
sendMouseMove(view.viewport(), QPoint(1, 1)); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2592 |
QTest::qWait(12); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2593 |
QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::ArrowCursor); |
0 | 2594 |
#endif |
2595 |
} |
|
2596 |
||
2597 |
void tst_QGraphicsProxyWidget::tooltip_basic() |
|
2598 |
{ |
|
2599 |
// Confirm that mouse events are working properly by checking that |
|
2600 |
// when moving the mouse over a label with a tooptip the tooltip appears |
|
2601 |
QGraphicsScene scene; |
|
2602 |
QGraphicsView view(&scene); |
|
2603 |
view.show(); |
|
2604 |
||
2605 |
QSKIP("Tooltips don't work yet", SkipAll); |
|
2606 |
||
2607 |
SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; |
|
2608 |
QLabel *widget = new QLabel; |
|
2609 |
widget->setText("If it ain't tested it's broken"); |
|
2610 |
widget->setToolTip("When in doubt, test"); |
|
2611 |
proxy->setWidget(widget); |
|
2612 |
widget->show(); |
|
2613 |
scene.addItem(proxy); |
|
2614 |
QTest::qWait(125); |
|
2615 |
||
2616 |
// in |
|
2617 |
QTest::mouseMove(view.viewport(), view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center()))); |
|
2618 |
QTest::qWait(3000); |
|
2619 |
||
2620 |
QCOMPARE(proxy->childItems().count(), 1); |
|
2621 |
QGraphicsProxyWidget *child = (QGraphicsProxyWidget*)(proxy->childItems())[0]; |
|
2622 |
QVERIFY(child->isWidget()); |
|
2623 |
QVERIFY(child->widget()); |
|
2624 |
QCOMPARE(child->widget()->parent(), static_cast<QObject*>(widget)); |
|
2625 |
QCOMPARE(child->widget()->x(), widget->x()); // ### ??? |
|
2626 |
QCOMPARE(child->widget()->y(), widget->y() + widget->height()); // ### ??? |
|
2627 |
} |
|
2628 |
||
2629 |
void tst_QGraphicsProxyWidget::childPos_data() |
|
2630 |
{ |
|
2631 |
QTest::addColumn<bool>("moveCombo"); |
|
2632 |
QTest::addColumn<QPoint>("comboPos"); |
|
2633 |
QTest::addColumn<QPointF>("proxyPos"); |
|
2634 |
QTest::addColumn<QPointF>("menuPos"); |
|
2635 |
||
2636 |
QTest::newRow("0") << true << QPoint() << QPointF() << QPointF(); |
|
2637 |
QTest::newRow("1") << true << QPoint(10, 0) << QPointF(10, 0) << QPointF(); |
|
2638 |
QTest::newRow("2") << true << QPoint(100, 0) << QPointF(100, 0) << QPointF(); |
|
2639 |
QTest::newRow("3") << true << QPoint(1000, 0) << QPointF(1000, 0) << QPointF(); |
|
2640 |
QTest::newRow("4") << true << QPoint(10000, 0) << QPointF(10000, 0) << QPointF(); |
|
2641 |
QTest::newRow("5") << true << QPoint(-10000, 0) << QPointF(-10000, 0) << QPointF(); |
|
2642 |
QTest::newRow("6") << true << QPoint(-1000, 0) << QPointF(-1000, 0) << QPointF(); |
|
2643 |
QTest::newRow("7") << true << QPoint(-100, 0) << QPointF(-100, 0) << QPointF(); |
|
2644 |
QTest::newRow("8") << true << QPoint(-10, 0) << QPointF(-10, 0) << QPointF(); |
|
2645 |
QTest::newRow("0-") << false << QPoint() << QPointF() << QPointF(); |
|
2646 |
QTest::newRow("1-") << false << QPoint(10, 0) << QPointF(10, 0) << QPointF(); |
|
2647 |
QTest::newRow("2-") << false << QPoint(100, 0) << QPointF(100, 0) << QPointF(); |
|
2648 |
QTest::newRow("3-") << false << QPoint(1000, 0) << QPointF(1000, 0) << QPointF(); |
|
2649 |
QTest::newRow("4-") << false << QPoint(10000, 0) << QPointF(10000, 0) << QPointF(); |
|
2650 |
QTest::newRow("5-") << false << QPoint(-10000, 0) << QPointF(-10000, 0) << QPointF(); |
|
2651 |
QTest::newRow("6-") << false << QPoint(-1000, 0) << QPointF(-1000, 0) << QPointF(); |
|
2652 |
QTest::newRow("7-") << false << QPoint(-100, 0) << QPointF(-100, 0) << QPointF(); |
|
2653 |
QTest::newRow("8-") << false << QPoint(-10, 0) << QPointF(-10, 0) << QPointF(); |
|
2654 |
} |
|
2655 |
||
2656 |
void tst_QGraphicsProxyWidget::childPos() |
|
2657 |
{ |
|
2658 |
#ifdef Q_OS_IRIX |
|
2659 |
QSKIP("This test is not reliable on IRIX.", SkipAll); |
|
2660 |
#endif |
|
2661 |
QFETCH(bool, moveCombo); |
|
2662 |
QFETCH(QPoint, comboPos); |
|
2663 |
QFETCH(QPointF, proxyPos); |
|
2664 |
QFETCH(QPointF, menuPos); |
|
2665 |
||
2666 |
QGraphicsScene scene; |
|
2667 |
||
2668 |
QComboBox *box = new QComboBox; |
|
2669 |
box->addItem("Item 1"); |
|
2670 |
box->addItem("Item 2"); |
|
2671 |
box->addItem("Item 3"); |
|
2672 |
box->addItem("Item 4"); |
|
2673 |
||
2674 |
if (moveCombo) |
|
2675 |
box->move(comboPos); |
|
2676 |
||
2677 |
QGraphicsProxyWidget *proxy = scene.addWidget(box); |
|
2678 |
proxy->show(); |
|
2679 |
QVERIFY(proxy->isVisible()); |
|
2680 |
QVERIFY(box->isVisible()); |
|
2681 |
||
2682 |
if (!moveCombo) |
|
2683 |
proxy->setPos(proxyPos); |
|
2684 |
||
2685 |
QCOMPARE(proxy->pos(), proxyPos); |
|
2686 |
QCOMPARE(box->pos(), comboPos); |
|
2687 |
||
2688 |
for (int i = 0; i < 2; ++i) { |
|
2689 |
box->showPopup(); |
|
2690 |
QApplication::processEvents(); |
|
2691 |
QApplication::processEvents(); |
|
2692 |
||
2693 |
QWidget *menu = 0; |
|
2694 |
foreach (QObject *child, box->children()) { |
|
2695 |
if ((menu = qobject_cast<QWidget *>(child))) |
|
2696 |
break; |
|
2697 |
} |
|
2698 |
QVERIFY(menu); |
|
2699 |
QVERIFY(menu->isVisible()); |
|
2700 |
QVERIFY(menu->testAttribute(Qt::WA_DontShowOnScreen)); |
|
2701 |
||
2702 |
QCOMPARE(proxy->childItems().size(), 1); |
|
2703 |
QGraphicsProxyWidget *proxyChild = 0; |
|
2704 |
foreach (QGraphicsItem *child, proxy->childItems()) { |
|
2705 |
if (child->isWidget() && (proxyChild = qobject_cast<QGraphicsProxyWidget *>(static_cast<QGraphicsWidget *>(child)))) |
|
2706 |
break; |
|
2707 |
} |
|
2708 |
QVERIFY(proxyChild); |
|
2709 |
QVERIFY(proxyChild->isVisible()); |
|
2710 |
qreal expectedXPosition = 0.0; |
|
2711 |
#if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) |
|
2712 |
// The Mac style wants the popup to show up at QPoint(4 - 11, 1). |
|
2713 |
// See QMacStyle::subControlRect SC_ComboBoxListBoxPopup. |
|
2714 |
if (qobject_cast<QMacStyle *>(QApplication::style())) |
|
2715 |
expectedXPosition = qreal(4 - 11); |
|
2716 |
#endif |
|
2717 |
QCOMPARE(proxyChild->pos().x(), expectedXPosition); |
|
2718 |
menu->hide(); |
|
2719 |
} |
|
2720 |
} |
|
2721 |
||
2722 |
void tst_QGraphicsProxyWidget::autoShow() |
|
2723 |
{ |
|
2724 |
QGraphicsScene scene; |
|
2725 |
QGraphicsView view(&scene); |
|
2726 |
||
2727 |
QGraphicsProxyWidget *proxy1 = scene.addWidget(new QPushButton("Button1")); |
|
2728 |
||
2729 |
QPushButton *button2 = new QPushButton("Button2"); |
|
2730 |
button2->hide(); |
|
2731 |
QGraphicsProxyWidget *proxy2 = new QGraphicsProxyWidget(); |
|
2732 |
proxy2->setWidget(button2); |
|
2733 |
scene.addItem(proxy2); |
|
2734 |
||
2735 |
view.show(); |
|
2736 |
QApplication::processEvents(); |
|
2737 |
||
2738 |
QCOMPARE(proxy1->isVisible(), true); |
|
2739 |
QCOMPARE(proxy2->isVisible(), false); |
|
2740 |
||
2741 |
} |
|
2742 |
||
2743 |
Q_DECLARE_METATYPE(QList<QRectF>) |
|
2744 |
void tst_QGraphicsProxyWidget::windowOpacity() |
|
2745 |
{ |
|
2746 |
QGraphicsScene scene; |
|
2747 |
QGraphicsView view(&scene); |
|
2748 |
||
2749 |
QWidget *widget = new QWidget; |
|
2750 |
widget->resize(100, 100); |
|
2751 |
QGraphicsProxyWidget *proxy = scene.addWidget(widget); |
|
2752 |
proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2753 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2754 |
QApplication::setActiveWindow(&view); |
0 | 2755 |
view.show(); |
2756 |
QTest::qWaitForWindowShown(&view); |
|
2757 |
QApplication::sendPostedEvents(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2758 |
QTRY_VERIFY(view.isActiveWindow()); |
0 | 2759 |
|
2760 |
qRegisterMetaType<QList<QRectF> >("QList<QRectF>"); |
|
2761 |
QSignalSpy signalSpy(&scene, SIGNAL(changed(const QList<QRectF> &))); |
|
2762 |
||
2763 |
EventSpy eventSpy(widget); |
|
2764 |
QVERIFY(widget->isVisible()); |
|
2765 |
||
2766 |
widget->setWindowOpacity(0.5); |
|
2767 |
QApplication::processEvents(); |
|
2768 |
||
2769 |
// Make sure setWindowOpacity triggers an update on the scene, |
|
2770 |
// and not on the widget or the proxy itself. The entire proxy needs an update |
|
2771 |
// in case it has a window decoration. Update: QGraphicsItem::CacheMode is |
|
2772 |
// disabled on platforms without alpha channel support in QPixmap (e.g., |
|
2773 |
// X11 without XRender). |
|
2774 |
int paints = 0; |
|
2775 |
#ifdef Q_WS_X11 |
|
2776 |
paints = !X11->use_xrender; |
|
2777 |
#endif |
|
2778 |
QTRY_COMPARE(eventSpy.counts[QEvent::UpdateRequest], 0); |
|
2779 |
QTRY_COMPARE(eventSpy.counts[QEvent::Paint], paints); |
|
2780 |
||
2781 |
QCOMPARE(signalSpy.count(), 1); |
|
2782 |
const QList<QVariant> arguments = signalSpy.takeFirst(); |
|
2783 |
const QList<QRectF> updateRects = qvariant_cast<QList<QRectF> >(arguments.at(0)); |
|
2784 |
QCOMPARE(updateRects.size(), 1); |
|
2785 |
QCOMPARE(updateRects.at(0), proxy->sceneBoundingRect()); |
|
2786 |
} |
|
2787 |
||
2788 |
void tst_QGraphicsProxyWidget::stylePropagation() |
|
2789 |
{ |
|
2790 |
QPointer<QWindowsStyle> windowsStyle = new QWindowsStyle; |
|
2791 |
||
2792 |
QLineEdit *edit = new QLineEdit; |
|
2793 |
QGraphicsProxyWidget proxy; |
|
2794 |
proxy.setWidget(edit); |
|
2795 |
||
2796 |
EventSpy editSpy(edit); |
|
2797 |
EventSpy proxySpy(&proxy); |
|
2798 |
||
2799 |
// Widget to proxy |
|
2800 |
QCOMPARE(proxy.style(), QApplication::style()); |
|
2801 |
edit->setStyle(windowsStyle); |
|
2802 |
QCOMPARE(editSpy.counts[QEvent::StyleChange], 1); |
|
2803 |
QCOMPARE(proxySpy.counts[QEvent::StyleChange], 1); |
|
2804 |
QCOMPARE(proxy.style(), (QStyle *)windowsStyle); |
|
2805 |
edit->setStyle(0); |
|
2806 |
QCOMPARE(editSpy.counts[QEvent::StyleChange], 2); |
|
2807 |
QCOMPARE(proxySpy.counts[QEvent::StyleChange], 2); |
|
2808 |
QCOMPARE(proxy.style(), QApplication::style()); |
|
2809 |
QCOMPARE(edit->style(), QApplication::style()); |
|
2810 |
QVERIFY(windowsStyle); // not deleted |
|
2811 |
||
2812 |
// Proxy to widget |
|
2813 |
proxy.setStyle(windowsStyle); |
|
2814 |
QCOMPARE(editSpy.counts[QEvent::StyleChange], 3); |
|
2815 |
QCOMPARE(proxySpy.counts[QEvent::StyleChange], 3); |
|
2816 |
QCOMPARE(edit->style(), (QStyle *)windowsStyle); |
|
2817 |
proxy.setStyle(0); |
|
2818 |
QCOMPARE(editSpy.counts[QEvent::StyleChange], 4); |
|
2819 |
QCOMPARE(proxySpy.counts[QEvent::StyleChange], 4); |
|
2820 |
QCOMPARE(proxy.style(), QApplication::style()); |
|
2821 |
QCOMPARE(edit->style(), QApplication::style()); |
|
2822 |
QVERIFY(windowsStyle); // not deleted |
|
2823 |
||
2824 |
delete windowsStyle; |
|
2825 |
} |
|
2826 |
||
2827 |
void tst_QGraphicsProxyWidget::palettePropagation() |
|
2828 |
{ |
|
2829 |
// Construct a palette with an unlikely setup |
|
2830 |
QPalette lineEditPalette = QApplication::palette("QLineEdit"); |
|
2831 |
QPalette palette = lineEditPalette; |
|
2832 |
palette.setBrush(QPalette::Text, Qt::red); |
|
2833 |
||
2834 |
QLineEdit *edit = new QLineEdit; |
|
2835 |
QGraphicsProxyWidget proxy; |
|
2836 |
proxy.setWidget(edit); |
|
2837 |
||
2838 |
EventSpy editSpy(edit); |
|
2839 |
EventSpy proxySpy(&proxy); |
|
2840 |
||
2841 |
// Widget to proxy (no change) |
|
2842 |
QVERIFY(!edit->testAttribute(Qt::WA_SetPalette)); |
|
2843 |
edit->setPalette(palette); |
|
2844 |
QCOMPARE(editSpy.counts[QEvent::PaletteChange], 1); |
|
2845 |
QCOMPARE(proxySpy.counts[QEvent::PaletteChange], 0); |
|
2846 |
QVERIFY(edit->testAttribute(Qt::WA_SetPalette)); |
|
2847 |
QVERIFY(!proxy.testAttribute(Qt::WA_SetPalette)); |
|
2848 |
QCOMPARE(proxy.palette(), QPalette()); |
|
2849 |
edit->setPalette(QPalette()); |
|
2850 |
QCOMPARE(editSpy.counts[QEvent::PaletteChange], 2); |
|
2851 |
QCOMPARE(proxySpy.counts[QEvent::PaletteChange], 0); |
|
2852 |
QVERIFY(!edit->testAttribute(Qt::WA_SetPalette)); |
|
2853 |
QVERIFY(!proxy.testAttribute(Qt::WA_SetPalette)); |
|
2854 |
QCOMPARE(proxy.palette(), QPalette()); |
|
2855 |
||
2856 |
// Proxy to widget |
|
2857 |
proxy.setPalette(palette); |
|
2858 |
QVERIFY(proxy.testAttribute(Qt::WA_SetPalette)); |
|
2859 |
QCOMPARE(editSpy.counts[QEvent::PaletteChange], 3); |
|
2860 |
QCOMPARE(proxySpy.counts[QEvent::PaletteChange], 1); |
|
2861 |
QVERIFY(!edit->testAttribute(Qt::WA_SetPalette)); |
|
2862 |
QCOMPARE(edit->palette(), palette); |
|
2863 |
QCOMPARE(edit->palette(), proxy.palette()); |
|
2864 |
QCOMPARE(edit->palette().color(QPalette::Text), QColor(Qt::red)); |
|
2865 |
proxy.setPalette(QPalette()); |
|
2866 |
QVERIFY(!proxy.testAttribute(Qt::WA_SetPalette)); |
|
2867 |
QVERIFY(!edit->testAttribute(Qt::WA_SetPalette)); |
|
2868 |
QCOMPARE(editSpy.counts[QEvent::PaletteChange], 4); |
|
2869 |
QCOMPARE(proxySpy.counts[QEvent::PaletteChange], 2); |
|
2870 |
QCOMPARE(edit->palette(), lineEditPalette); |
|
2871 |
} |
|
2872 |
||
2873 |
void tst_QGraphicsProxyWidget::fontPropagation() |
|
2874 |
{ |
|
2875 |
// Construct a font with an unlikely setup |
|
2876 |
QGraphicsScene scene; |
|
2877 |
QFont lineEditFont = QApplication::font("QLineEdit"); |
|
2878 |
QFont font = lineEditFont; |
|
2879 |
font.setPointSize(43); |
|
2880 |
||
2881 |
QLineEdit *edit = new QLineEdit; |
|
2882 |
QGraphicsProxyWidget proxy; |
|
2883 |
proxy.setWidget(edit); |
|
2884 |
||
2885 |
scene.addItem(&proxy); |
|
2886 |
EventSpy editSpy(edit); |
|
2887 |
EventSpy proxySpy(&proxy); |
|
2888 |
||
2889 |
// Widget to proxy (no change) |
|
2890 |
QVERIFY(!edit->testAttribute(Qt::WA_SetFont)); |
|
2891 |
edit->setFont(font); |
|
2892 |
QCOMPARE(editSpy.counts[QEvent::FontChange], 1); |
|
2893 |
QCOMPARE(proxySpy.counts[QEvent::FontChange], 0); |
|
2894 |
QVERIFY(edit->testAttribute(Qt::WA_SetFont)); |
|
2895 |
QVERIFY(!proxy.testAttribute(Qt::WA_SetFont)); |
|
2896 |
QCOMPARE(proxy.font(), lineEditFont); |
|
2897 |
edit->setFont(QFont()); |
|
2898 |
QCOMPARE(editSpy.counts[QEvent::FontChange], 2); |
|
2899 |
QCOMPARE(proxySpy.counts[QEvent::FontChange], 0); |
|
2900 |
QVERIFY(!edit->testAttribute(Qt::WA_SetFont)); |
|
2901 |
QVERIFY(!proxy.testAttribute(Qt::WA_SetFont)); |
|
2902 |
QCOMPARE(proxy.font(), lineEditFont); |
|
2903 |
||
2904 |
// Proxy to widget |
|
2905 |
proxy.setFont(font); |
|
2906 |
QApplication::processEvents(); // wait for QEvent::Polish |
|
2907 |
QVERIFY(proxy.testAttribute(Qt::WA_SetFont)); |
|
2908 |
QCOMPARE(editSpy.counts[QEvent::FontChange], 3); |
|
2909 |
QCOMPARE(proxySpy.counts[QEvent::FontChange], 1); |
|
2910 |
QVERIFY(!edit->testAttribute(Qt::WA_SetFont)); |
|
2911 |
QCOMPARE(edit->font(), font); |
|
2912 |
QCOMPARE(edit->font(), proxy.font()); |
|
2913 |
QCOMPARE(edit->font().pointSize(), 43); |
|
2914 |
proxy.setFont(QFont()); |
|
2915 |
QVERIFY(!proxy.testAttribute(Qt::WA_SetFont)); |
|
2916 |
QVERIFY(!edit->testAttribute(Qt::WA_SetFont)); |
|
2917 |
QCOMPARE(editSpy.counts[QEvent::FontChange], 4); |
|
2918 |
QCOMPARE(proxySpy.counts[QEvent::FontChange], 2); |
|
2919 |
QCOMPARE(edit->font(), lineEditFont); |
|
2920 |
||
2921 |
proxy.setFont(font); |
|
2922 |
QLineEdit *edit2 = new QLineEdit; |
|
2923 |
proxy.setWidget(edit2); |
|
2924 |
delete edit; |
|
2925 |
QCOMPARE(edit2->font().pointSize(), 43); |
|
2926 |
} |
|
2927 |
||
2928 |
class MainWidget : public QMainWindow |
|
2929 |
{ |
|
2930 |
Q_OBJECT |
|
2931 |
public: |
|
2932 |
MainWidget() : QMainWindow() { |
|
2933 |
view = new QGraphicsView(this); |
|
2934 |
scene = new QGraphicsScene(this); |
|
2935 |
item = new QGraphicsWidget(); |
|
2936 |
widget = new QGraphicsProxyWidget(item); |
|
2937 |
layout = new QGraphicsLinearLayout(item); |
|
2938 |
layout->addItem(widget); |
|
2939 |
item->setLayout(layout); |
|
2940 |
button = new QPushButton("Push me"); |
|
2941 |
widget->setWidget(button); |
|
2942 |
setCentralWidget(view); |
|
2943 |
scene->addItem(item); |
|
2944 |
view->setScene(scene); |
|
2945 |
scene->setFocusItem(item); |
|
2946 |
layout->activate(); |
|
2947 |
} |
|
2948 |
QGraphicsView* view; |
|
2949 |
QGraphicsScene* scene; |
|
2950 |
QGraphicsWidget * item; |
|
2951 |
QGraphicsLinearLayout * layout; |
|
2952 |
QGraphicsProxyWidget * widget; |
|
2953 |
QPushButton * button; |
|
2954 |
}; |
|
2955 |
||
2956 |
void tst_QGraphicsProxyWidget::dontCrashWhenDie() |
|
2957 |
{ |
|
2958 |
MainWidget *w = new MainWidget(); |
|
2959 |
w->show(); |
|
2960 |
QTest::qWaitForWindowShown(w); |
|
2961 |
QTest::qWait(100); |
|
2962 |
QTest::mouseMove(w->view->viewport(), w->view->mapFromScene(w->widget->mapToScene(w->widget->boundingRect().center()))); |
|
2963 |
delete w->item; |
|
2964 |
||
2965 |
QApplication::processEvents(); |
|
2966 |
delete w; |
|
2967 |
} |
|
2968 |
||
2969 |
void tst_QGraphicsProxyWidget::createProxyForChildWidget() |
|
2970 |
{ |
|
2971 |
QGraphicsScene scene; |
|
2972 |
||
2973 |
QLineEdit *edit1 = new QLineEdit; |
|
2974 |
edit1->setText("QLineEdit 1"); |
|
2975 |
QLineEdit *edit2 = new QLineEdit; |
|
2976 |
edit2->setText("QLineEdit 2"); |
|
2977 |
QCheckBox *checkbox = new QCheckBox("QCheckBox"); |
|
2978 |
QVBoxLayout *vlayout = new QVBoxLayout; |
|
2979 |
||
2980 |
vlayout->addWidget(edit1); |
|
2981 |
vlayout->addWidget(edit2); |
|
2982 |
vlayout->addWidget(checkbox); |
|
2983 |
vlayout->insertStretch(-1); |
|
2984 |
||
2985 |
QGroupBox *box = new QGroupBox("QGroupBox"); |
|
2986 |
box->setCheckable(true); |
|
2987 |
box->setChecked(true); |
|
2988 |
box->setLayout(vlayout); |
|
2989 |
||
2990 |
QDial *leftDial = new QDial; |
|
2991 |
QDial *rightDial = new QDial; |
|
2992 |
||
2993 |
QWidget window; |
|
2994 |
QHBoxLayout *layout = new QHBoxLayout; |
|
2995 |
layout->addWidget(leftDial); |
|
2996 |
layout->addWidget(box); |
|
2997 |
layout->addWidget(rightDial); |
|
2998 |
window.setLayout(layout); |
|
2999 |
||
3000 |
QVERIFY(window.graphicsProxyWidget() == 0); |
|
3001 |
QVERIFY(checkbox->graphicsProxyWidget() == 0); |
|
3002 |
||
3003 |
QGraphicsProxyWidget *windowProxy = scene.addWidget(&window); |
|
3004 |
QGraphicsView view(&scene); |
|
3005 |
view.show(); |
|
3006 |
view.resize(500,500); |
|
3007 |
||
3008 |
QVERIFY(window.graphicsProxyWidget() == windowProxy); |
|
3009 |
QVERIFY(box->graphicsProxyWidget() == 0); |
|
3010 |
QVERIFY(checkbox->graphicsProxyWidget() == 0); |
|
3011 |
||
3012 |
QPointer<QGraphicsProxyWidget> checkboxProxy = windowProxy->createProxyForChildWidget(checkbox); |
|
3013 |
||
3014 |
QGraphicsProxyWidget *boxProxy = box->graphicsProxyWidget(); |
|
3015 |
||
3016 |
QVERIFY(boxProxy); |
|
3017 |
QVERIFY(checkbox->graphicsProxyWidget() == checkboxProxy); |
|
3018 |
QVERIFY(checkboxProxy->parentItem() == boxProxy); |
|
3019 |
QVERIFY(boxProxy->parentItem() == windowProxy); |
|
3020 |
||
3021 |
QVERIFY(checkboxProxy->mapToScene(QPointF()) == checkbox->mapTo(&window, QPoint())); |
|
3022 |
QVERIFY(checkboxProxy->size() == checkbox->size()); |
|
3023 |
QVERIFY(boxProxy->size() == box->size()); |
|
3024 |
||
3025 |
window.resize(500,500); |
|
3026 |
QVERIFY(windowProxy->size() == QSize(500,500)); |
|
3027 |
QVERIFY(checkboxProxy->mapToScene(QPointF()) == checkbox->mapTo(&window, QPoint())); |
|
3028 |
QVERIFY(checkboxProxy->size() == checkbox->size()); |
|
3029 |
QVERIFY(boxProxy->size() == box->size()); |
|
3030 |
||
3031 |
QTest::qWait(10); |
|
3032 |
||
3033 |
||
3034 |
QSignalSpy spy(checkbox, SIGNAL(clicked())); |
|
3035 |
||
3036 |
QTest::mousePress(view.viewport(), Qt::LeftButton, 0, |
|
3037 |
view.mapFromScene(checkboxProxy->mapToScene(QPointF(8,8)))); |
|
3038 |
QTRY_COMPARE(spy.count(), 0); |
|
3039 |
QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, |
|
3040 |
view.mapFromScene(checkboxProxy->mapToScene(QPointF(8,8)))); |
|
3041 |
QTRY_COMPARE(spy.count(), 1); |
|
3042 |
||
3043 |
||
3044 |
||
3045 |
boxProxy->setWidget(0); |
|
3046 |
||
3047 |
QVERIFY(checkbox->graphicsProxyWidget() == 0); |
|
3048 |
QVERIFY(box->graphicsProxyWidget() == 0); |
|
3049 |
QVERIFY(checkboxProxy == 0); |
|
3050 |
||
3051 |
delete boxProxy; |
|
3052 |
} |
|
3053 |
||
3054 |
class ContextMenuWidget : public QWidget |
|
3055 |
{ |
|
3056 |
Q_OBJECT |
|
3057 |
public: |
|
3058 |
ContextMenuWidget() |
|
3059 |
: embeddedPopup(false), |
|
3060 |
gotContextMenuEvent(false) |
|
3061 |
{ } |
|
3062 |
bool embeddedPopup; |
|
3063 |
bool gotContextMenuEvent; |
|
3064 |
protected: |
|
3065 |
bool event(QEvent *event) |
|
3066 |
{ |
|
3067 |
if (event->type() == QEvent::ContextMenu) |
|
3068 |
QTimer::singleShot(0, this, SLOT(checkMenu())); |
|
3069 |
return QWidget::event(event); |
|
3070 |
} |
|
3071 |
void contextMenuEvent(QContextMenuEvent *) |
|
3072 |
{ |
|
3073 |
gotContextMenuEvent = true; |
|
3074 |
} |
|
3075 |
||
3076 |
private slots: |
|
3077 |
void checkMenu() |
|
3078 |
{ |
|
3079 |
if (qFindChild<QMenu *>(this)) |
|
3080 |
embeddedPopup = true; |
|
3081 |
hide(); |
|
3082 |
} |
|
3083 |
}; |
|
3084 |
||
3085 |
void tst_QGraphicsProxyWidget::actionsContextMenu_data() |
|
3086 |
{ |
|
3087 |
QTest::addColumn<bool>("actionsContextMenu"); |
|
3088 |
QTest::addColumn<bool>("hasFocus"); |
|
3089 |
||
3090 |
QTest::newRow("without actionsContextMenu and with focus") << false << true; |
|
3091 |
QTest::newRow("without actionsContextMenu and without focus") << false << false; |
|
3092 |
QTest::newRow("with actionsContextMenu and focus") << true << true; |
|
3093 |
QTest::newRow("with actionsContextMenu without focus") << true << false; |
|
3094 |
} |
|
3095 |
||
3096 |
void tst_QGraphicsProxyWidget::actionsContextMenu() |
|
3097 |
{ |
|
3098 |
QFETCH(bool, hasFocus); |
|
3099 |
QFETCH(bool, actionsContextMenu); |
|
3100 |
||
3101 |
ContextMenuWidget *widget = new ContextMenuWidget; |
|
3102 |
if (actionsContextMenu) { |
|
3103 |
widget->addAction(new QAction("item 1", widget)); |
|
3104 |
widget->addAction(new QAction("item 2", widget)); |
|
3105 |
widget->addAction(new QAction("item 3", widget)); |
|
3106 |
widget->setContextMenuPolicy(Qt::ActionsContextMenu); |
|
3107 |
} |
|
3108 |
QGraphicsScene scene; |
|
3109 |
||
3110 |
QGraphicsView view(&scene); |
|
3111 |
view.show(); |
|
3112 |
QApplication::setActiveWindow(&view); |
|
3113 |
QTest::qWaitForWindowShown(&view); |
|
3114 |
view.setFocus(); |
|
3115 |
QTRY_VERIFY(view.hasFocus()); |
|
3116 |
||
3117 |
if (hasFocus) |
|
3118 |
scene.addWidget(widget)->setFocus(); |
|
3119 |
else |
|
3120 |
scene.addWidget(widget)->clearFocus(); |
|
3121 |
||
3122 |
QApplication::processEvents(); |
|
3123 |
||
3124 |
QContextMenuEvent contextMenuEvent(QContextMenuEvent::Mouse, |
|
3125 |
view.viewport()->rect().center(), |
|
3126 |
view.viewport()->mapToGlobal(view.viewport()->rect().center())); |
|
3127 |
contextMenuEvent.accept(); |
|
3128 |
qApp->sendEvent(view.viewport(), &contextMenuEvent); |
|
3129 |
||
3130 |
if (hasFocus) { |
|
3131 |
if (actionsContextMenu) { |
|
3132 |
//actionsContextMenu embedded popup but no contextMenuEvent (widget has focus) |
|
3133 |
QVERIFY(widget->embeddedPopup); |
|
3134 |
QVERIFY(!widget->gotContextMenuEvent); |
|
3135 |
} else { |
|
3136 |
//no embedded popup but contextMenuEvent (widget has focus) |
|
3137 |
QVERIFY(!widget->embeddedPopup); |
|
3138 |
QVERIFY(widget->gotContextMenuEvent); |
|
3139 |
} |
|
3140 |
} else { |
|
3141 |
//qgraphicsproxywidget doesn't have the focus, the widget must not receive any contextMenuEvent and must not create any QMenu |
|
3142 |
QVERIFY(!widget->embeddedPopup); |
|
3143 |
QVERIFY(!widget->gotContextMenuEvent); |
|
3144 |
} |
|
3145 |
||
3146 |
} |
|
3147 |
||
3148 |
||
3149 |
void tst_QGraphicsProxyWidget::deleteProxyForChildWidget() |
|
3150 |
{ |
|
3151 |
QDialog dialog; |
|
3152 |
dialog.resize(320, 120); |
|
3153 |
dialog.move(80, 40); |
|
3154 |
||
3155 |
QGraphicsScene scene; |
|
3156 |
scene.setSceneRect(QRectF(0, 0, 640, 480)); |
|
3157 |
QGraphicsView view(&scene); |
|
3158 |
QComboBox *combo = new QComboBox; |
|
3159 |
combo->addItems(QStringList() << "red" << "green" << "blue" << "white" << "black" << "yellow" << "cyan" << "magenta"); |
|
3160 |
dialog.setLayout(new QVBoxLayout); |
|
3161 |
dialog.layout()->addWidget(combo); |
|
3162 |
||
3163 |
QGraphicsProxyWidget *proxy = scene.addWidget(&dialog); |
|
3164 |
view.show(); |
|
3165 |
||
3166 |
proxy->setWidget(0); |
|
3167 |
//just don't crash |
|
3168 |
QApplication::processEvents(); |
|
3169 |
delete combo; |
|
3170 |
} |
|
3171 |
||
3172 |
void tst_QGraphicsProxyWidget::bypassGraphicsProxyWidget_data() |
|
3173 |
{ |
|
3174 |
QTest::addColumn<bool>("bypass"); |
|
3175 |
||
3176 |
QTest::newRow("autoembed") << false; |
|
3177 |
QTest::newRow("bypass") << true; |
|
3178 |
} |
|
3179 |
||
3180 |
void tst_QGraphicsProxyWidget::bypassGraphicsProxyWidget() |
|
3181 |
{ |
|
3182 |
QFETCH(bool, bypass); |
|
3183 |
||
3184 |
QWidget *widget = new QWidget; |
|
3185 |
widget->resize(100, 100); |
|
3186 |
||
3187 |
QGraphicsScene scene; |
|
3188 |
QGraphicsView view(&scene); |
|
3189 |
view.show(); |
|
3190 |
||
3191 |
QGraphicsProxyWidget *proxy = scene.addWidget(widget); |
|
3192 |
||
3193 |
QCOMPARE(proxy->widget(), widget); |
|
3194 |
QVERIFY(proxy->childItems().isEmpty()); |
|
3195 |
||
3196 |
Qt::WindowFlags flags; |
|
3197 |
flags |= Qt::Dialog; |
|
3198 |
if (bypass) |
|
3199 |
flags |= Qt::BypassGraphicsProxyWidget; |
|
3200 |
QFileDialog *dialog = new QFileDialog(widget, flags); |
|
3201 |
dialog->setOption(QFileDialog::DontUseNativeDialog, true); |
|
3202 |
dialog->show(); |
|
3203 |
||
3204 |
QCOMPARE(proxy->childItems().size(), bypass ? 0 : 1); |
|
3205 |
if (!bypass) |
|
3206 |
QCOMPARE(((QGraphicsProxyWidget *)proxy->childItems().first())->widget(), (QWidget *)dialog); |
|
3207 |
||
3208 |
dialog->hide(); |
|
3209 |
QApplication::processEvents(); |
|
3210 |
delete dialog; |
|
3211 |
delete widget; |
|
3212 |
} |
|
3213 |
||
3214 |
static void makeDndEvent(QGraphicsSceneDragDropEvent *event, QGraphicsView *view, const QPointF &pos) |
|
3215 |
{ |
|
3216 |
event->setScenePos(pos); |
|
3217 |
event->setScreenPos(view->mapToGlobal(view->mapFromScene(pos))); |
|
3218 |
event->setButtons(Qt::LeftButton); |
|
3219 |
event->setModifiers(0); |
|
3220 |
event->setPossibleActions(Qt::CopyAction); |
|
3221 |
event->setProposedAction(Qt::CopyAction); |
|
3222 |
event->setDropAction(Qt::CopyAction); |
|
3223 |
event->setWidget(view->viewport()); |
|
3224 |
event->setSource(view->viewport()); |
|
3225 |
event->ignore(); |
|
3226 |
} |
|
3227 |
||
3228 |
void tst_QGraphicsProxyWidget::dragDrop() |
|
3229 |
{ |
|
3230 |
QPushButton *button = new QPushButton; // acceptDrops(false) |
|
3231 |
QLineEdit *edit = new QLineEdit; // acceptDrops(true) |
|
3232 |
||
3233 |
QGraphicsScene scene; |
|
3234 |
QGraphicsProxyWidget *buttonProxy = scene.addWidget(button); |
|
3235 |
QGraphicsProxyWidget *editProxy = scene.addWidget(edit); |
|
3236 |
QVERIFY(buttonProxy->acceptDrops()); |
|
3237 |
QVERIFY(editProxy->acceptDrops()); |
|
3238 |
||
3239 |
button->setGeometry(0, 0, 100, 50); |
|
3240 |
edit->setGeometry(0, 60, 100, 50); |
|
3241 |
||
3242 |
QGraphicsView view(&scene); |
|
3243 |
view.show(); |
|
3244 |
#ifdef Q_WS_X11 |
|
3245 |
qt_x11_wait_for_window_manager(&view); |
|
3246 |
#endif |
|
3247 |
||
3248 |
QMimeData data; |
|
3249 |
data.setText("hei"); |
|
3250 |
{ |
|
3251 |
QGraphicsSceneDragDropEvent event(QEvent::GraphicsSceneDragEnter); |
|
3252 |
makeDndEvent(&event, &view, QPointF(50, 25)); |
|
3253 |
event.setMimeData(&data); |
|
3254 |
qApp->sendEvent(&scene, &event); |
|
3255 |
QVERIFY(event.isAccepted()); |
|
3256 |
} |
|
3257 |
{ |
|
3258 |
QGraphicsSceneDragDropEvent event(QEvent::GraphicsSceneDragMove); |
|
3259 |
makeDndEvent(&event, &view, QPointF(50, 25)); |
|
3260 |
event.setMimeData(&data); |
|
3261 |
qApp->sendEvent(&scene, &event); |
|
3262 |
QVERIFY(!event.isAccepted()); |
|
3263 |
} |
|
3264 |
{ |
|
3265 |
QGraphicsSceneDragDropEvent event(QEvent::GraphicsSceneDragMove); |
|
3266 |
makeDndEvent(&event, &view, QPointF(50, 75)); |
|
3267 |
event.setMimeData(&data); |
|
3268 |
qApp->sendEvent(&scene, &event); |
|
3269 |
QVERIFY(event.isAccepted()); |
|
3270 |
} |
|
3271 |
{ |
|
3272 |
QGraphicsSceneDragDropEvent event(QEvent::GraphicsSceneDrop); |
|
3273 |
makeDndEvent(&event, &view, QPointF(50, 75)); |
|
3274 |
event.setMimeData(&data); |
|
3275 |
qApp->sendEvent(&scene, &event); |
|
3276 |
QVERIFY(event.isAccepted()); |
|
3277 |
} |
|
3278 |
QCOMPARE(edit->text(), QString("hei")); |
|
3279 |
} |
|
3280 |
||
3281 |
void tst_QGraphicsProxyWidget::windowFlags_data() |
|
3282 |
{ |
|
3283 |
QTest::addColumn<int>("proxyFlags"); |
|
3284 |
QTest::addColumn<int>("widgetFlags"); |
|
3285 |
QTest::addColumn<int>("resultingProxyFlags"); |
|
3286 |
QTest::addColumn<int>("resultingWidgetFlags"); |
|
3287 |
||
3288 |
QTest::newRow("proxy(0) widget(0)") << 0 << 0 << 0 << int(Qt::Window); |
|
3289 |
QTest::newRow("proxy(window)") << int(Qt::Window) << 0 << int(Qt::Window) << int(Qt::Window); |
|
3290 |
QTest::newRow("proxy(window) widget(window)") << int(Qt::Window) << int(Qt::Window) << int(Qt::Window) << int(Qt::Window); |
|
3291 |
QTest::newRow("proxy(0) widget(window)") << int(0) << int(Qt::Window) << int(0) << int(Qt::Window); |
|
3292 |
} |
|
3293 |
||
3294 |
void tst_QGraphicsProxyWidget::windowFlags() |
|
3295 |
{ |
|
3296 |
QFETCH(int, proxyFlags); |
|
3297 |
QFETCH(int, widgetFlags); |
|
3298 |
QFETCH(int, resultingProxyFlags); |
|
3299 |
QFETCH(int, resultingWidgetFlags); |
|
3300 |
Qt::WindowFlags proxyWFlags = Qt::WindowFlags(proxyFlags); |
|
3301 |
Qt::WindowFlags widgetWFlags = Qt::WindowFlags(widgetFlags); |
|
3302 |
Qt::WindowFlags resultingProxyWFlags = Qt::WindowFlags(resultingProxyFlags); |
|
3303 |
Qt::WindowFlags resultingWidgetWFlags = Qt::WindowFlags(resultingWidgetFlags); |
|
3304 |
||
3305 |
QGraphicsProxyWidget proxy(0, proxyWFlags); |
|
3306 |
QVERIFY((proxy.windowFlags() & proxyWFlags) == proxyWFlags); |
|
3307 |
||
3308 |
QWidget *widget = new QWidget(0, widgetWFlags); |
|
3309 |
QVERIFY((widget->windowFlags() & widgetWFlags) == widgetWFlags); |
|
3310 |
||
3311 |
proxy.setWidget(widget); |
|
3312 |
||
3313 |
if (resultingProxyFlags == 0) |
|
3314 |
QVERIFY(!proxy.windowFlags()); |
|
3315 |
else |
|
3316 |
QVERIFY((proxy.windowFlags() & resultingProxyWFlags) == resultingProxyWFlags); |
|
3317 |
QVERIFY((widget->windowFlags() & resultingWidgetWFlags) == resultingWidgetWFlags); |
|
3318 |
} |
|
3319 |
||
3320 |
void tst_QGraphicsProxyWidget::comboboxWindowFlags() |
|
3321 |
{ |
|
3322 |
QComboBox *comboBox = new QComboBox; |
|
3323 |
comboBox->addItem("Item 1"); |
|
3324 |
comboBox->addItem("Item 2"); |
|
3325 |
comboBox->addItem("Item 3"); |
|
3326 |
QWidget *embedWidget = comboBox; |
|
3327 |
||
3328 |
QGraphicsScene scene; |
|
3329 |
QGraphicsProxyWidget *proxy = scene.addWidget(embedWidget); |
|
3330 |
proxy->setWindowFlags(Qt::Window); |
|
3331 |
QVERIFY(embedWidget->isWindow()); |
|
3332 |
QVERIFY(proxy->isWindow()); |
|
3333 |
||
3334 |
comboBox->showPopup(); |
|
3335 |
||
3336 |
QCOMPARE(proxy->childItems().size(), 1); |
|
3337 |
QGraphicsItem *popupProxy = proxy->childItems().first(); |
|
3338 |
QVERIFY(popupProxy->isWindow()); |
|
3339 |
QVERIFY((static_cast<QGraphicsWidget *>(popupProxy)->windowFlags() & Qt::Popup) == Qt::Popup); |
|
3340 |
} |
|
3341 |
||
3342 |
void tst_QGraphicsProxyWidget::updateAndDelete() |
|
3343 |
{ |
|
3344 |
QGraphicsScene scene; |
|
3345 |
QGraphicsProxyWidget *proxy = scene.addWidget(new QPushButton("Hello World")); |
|
3346 |
View view(&scene); |
|
3347 |
view.show(); |
|
3348 |
#ifdef Q_WS_X11 |
|
3349 |
qt_x11_wait_for_window_manager(&view); |
|
3350 |
#endif |
|
3351 |
QTest::qWait(20); |
|
3352 |
QTRY_VERIFY(view.npaints > 0); |
|
3353 |
||
3354 |
const QRect itemDeviceBoundingRect = proxy->deviceTransform(view.viewportTransform()) |
|
3355 |
.mapRect(proxy->boundingRect()).toRect(); |
|
3356 |
const QRegion expectedRegion = itemDeviceBoundingRect.adjusted(-2, -2, 2, 2); |
|
3357 |
||
3358 |
view.npaints = 0; |
|
3359 |
view.paintEventRegion = QRegion(); |
|
3360 |
||
3361 |
// Update and hide. |
|
3362 |
proxy->update(); |
|
3363 |
proxy->hide(); |
|
3364 |
QTest::qWait(50); |
|
3365 |
QCOMPARE(view.npaints, 1); |
|
3366 |
QCOMPARE(view.paintEventRegion, expectedRegion); |
|
3367 |
||
3368 |
proxy->show(); |
|
3369 |
QTest::qWait(50); |
|
3370 |
view.npaints = 0; |
|
3371 |
view.paintEventRegion = QRegion(); |
|
3372 |
||
3373 |
// Update and delete. |
|
3374 |
proxy->update(); |
|
3375 |
delete proxy; |
|
3376 |
QTest::qWait(50); |
|
3377 |
QCOMPARE(view.npaints, 1); |
|
3378 |
QCOMPARE(view.paintEventRegion, expectedRegion); |
|
3379 |
} |
|
3380 |
||
3381 |
class InputMethod_LineEdit : public QLineEdit |
|
3382 |
{ |
|
3383 |
bool event(QEvent *e) |
|
3384 |
{ |
|
3385 |
if (e->type() == QEvent::InputMethod) |
|
3386 |
++inputMethodEvents; |
|
3387 |
return QLineEdit::event(e); |
|
3388 |
} |
|
3389 |
public: |
|
3390 |
int inputMethodEvents; |
|
3391 |
}; |
|
3392 |
||
3393 |
void tst_QGraphicsProxyWidget::inputMethod() |
|
3394 |
{ |
|
3395 |
QGraphicsScene scene; |
|
3396 |
||
3397 |
// check that the proxy is initialized with the correct input method sensitivity |
|
3398 |
for (int i = 0; i < 2; ++i) |
|
3399 |
{ |
|
3400 |
QLineEdit *lineEdit = new QLineEdit; |
|
3401 |
lineEdit->setAttribute(Qt::WA_InputMethodEnabled, !!i); |
|
3402 |
QGraphicsProxyWidget *proxy = scene.addWidget(lineEdit); |
|
3403 |
QCOMPARE(!!(proxy->flags() & QGraphicsItem::ItemAcceptsInputMethod), !!i); |
|
3404 |
} |
|
3405 |
||
3406 |
// check that input method events are only forwarded to widgets with focus |
|
3407 |
for (int i = 0; i < 2; ++i) |
|
3408 |
{ |
|
3409 |
InputMethod_LineEdit *lineEdit = new InputMethod_LineEdit; |
|
3410 |
lineEdit->setAttribute(Qt::WA_InputMethodEnabled, true); |
|
3411 |
QGraphicsProxyWidget *proxy = scene.addWidget(lineEdit); |
|
3412 |
||
3413 |
if (i) |
|
3414 |
lineEdit->setFocus(); |
|
3415 |
||
3416 |
lineEdit->inputMethodEvents = 0; |
|
3417 |
QInputMethodEvent event; |
|
3418 |
qApp->sendEvent(proxy, &event); |
|
3419 |
QCOMPARE(lineEdit->inputMethodEvents, i); |
|
3420 |
} |
|
3421 |
} |
|
3422 |
||
3423 |
void tst_QGraphicsProxyWidget::clickFocus() |
|
3424 |
{ |
|
3425 |
QGraphicsScene scene; |
|
3426 |
scene.setItemIndexMethod(QGraphicsScene::NoIndex); |
|
3427 |
QGraphicsProxyWidget *proxy = scene.addWidget(new QLineEdit); |
|
3428 |
||
3429 |
QGraphicsView view(&scene); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3430 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3431 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3432 |
EventSpy proxySpy(proxy); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3433 |
EventSpy widgetSpy(proxy->widget()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3434 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3435 |
view.setFrameStyle(0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3436 |
view.resize(300, 300); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3437 |
view.show(); |
0 | 3438 |
#ifdef Q_WS_X11 |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3439 |
qt_x11_wait_for_window_manager(&view); |
0 | 3440 |
#endif |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3441 |
QApplication::setActiveWindow(&view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3442 |
QTest::qWait(25); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3443 |
QTRY_COMPARE(QApplication::activeWindow(), &view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3444 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3445 |
QVERIFY(!proxy->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3446 |
QVERIFY(!proxy->widget()->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3447 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3448 |
QCOMPARE(proxySpy.counts[QEvent::FocusIn], 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3449 |
QCOMPARE(proxySpy.counts[QEvent::FocusOut], 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3450 |
QCOMPARE(widgetSpy.counts[QEvent::FocusIn], 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3451 |
QCOMPARE(widgetSpy.counts[QEvent::FocusOut], 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3452 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3453 |
QPointF lineEditCenter = proxy->mapToScene(proxy->boundingRect().center()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3454 |
// Spontaneous mouse click sets focus on a clickable widget. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3455 |
for (int retry = 0; retry < 50 && !proxy->hasFocus(); retry++) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3456 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(lineEditCenter)); |
0 | 3457 |
QVERIFY(proxy->hasFocus()); |
3458 |
QVERIFY(proxy->widget()->hasFocus()); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3459 |
QCOMPARE(proxySpy.counts[QEvent::FocusIn], 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3460 |
QCOMPARE(widgetSpy.counts[QEvent::FocusIn], 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3461 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3462 |
scene.setFocusItem(0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3463 |
QVERIFY(!proxy->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3464 |
QVERIFY(!proxy->widget()->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3465 |
QCOMPARE(proxySpy.counts[QEvent::FocusOut], 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3466 |
QCOMPARE(widgetSpy.counts[QEvent::FocusOut], 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3467 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3468 |
// Non-spontaneous mouse click sets focus if the widget has been clicked before |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3469 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3470 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3471 |
event.setScenePos(lineEditCenter); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3472 |
event.setButton(Qt::LeftButton); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3473 |
qApp->sendEvent(&scene, &event); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3474 |
QVERIFY(proxy->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3475 |
QVERIFY(proxy->widget()->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3476 |
QCOMPARE(proxySpy.counts[QEvent::FocusIn], 2); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3477 |
QCOMPARE(widgetSpy.counts[QEvent::FocusIn], 2); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3478 |
} |
0 | 3479 |
} |
3480 |
||
3481 |
scene.setFocusItem(0); |
|
3482 |
proxy->setWidget(new QLineEdit); // resets focusWidget |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3483 |
|
0 | 3484 |
{ |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3485 |
QPointF lineEditCenter = proxy->mapToScene(proxy->boundingRect().center()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3486 |
EventSpy proxySpy(proxy); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3487 |
EventSpy widgetSpy(proxy->widget()); |
0 | 3488 |
QVERIFY(!proxy->hasFocus()); |
3489 |
QVERIFY(!proxy->widget()->hasFocus()); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3490 |
QCOMPARE(proxySpy.counts[QEvent::FocusOut], 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3491 |
QCOMPARE(widgetSpy.counts[QEvent::FocusOut], 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3492 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3493 |
// Non-spontaneous mouse click does not set focus on the embedded widget. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3494 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3495 |
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3496 |
event.setScenePos(lineEditCenter); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3497 |
event.setButton(Qt::LeftButton); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3498 |
qApp->sendEvent(&scene, &event); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3499 |
QVERIFY(!proxy->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3500 |
QVERIFY(!proxy->widget()->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3501 |
QCOMPARE(proxySpy.counts[QEvent::FocusIn], 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3502 |
QCOMPARE(widgetSpy.counts[QEvent::FocusIn], 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3503 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3504 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3505 |
scene.setFocusItem(0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3506 |
QVERIFY(!proxy->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3507 |
QVERIFY(!proxy->widget()->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3508 |
QCOMPARE(proxySpy.counts[QEvent::FocusOut], 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3509 |
QCOMPARE(widgetSpy.counts[QEvent::FocusOut], 0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3510 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3511 |
// Spontaneous click on non-clickable widget does not give focus. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3512 |
proxy->widget()->setFocusPolicy(Qt::NoFocus); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3513 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(lineEditCenter)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3514 |
QVERIFY(!proxy->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3515 |
QVERIFY(!proxy->widget()->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3516 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3517 |
// Multiple clicks should only result in one FocusIn. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3518 |
proxy->widget()->setFocusPolicy(Qt::StrongFocus); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3519 |
scene.setFocusItem(0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3520 |
QVERIFY(!proxy->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3521 |
QVERIFY(!proxy->widget()->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3522 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(lineEditCenter)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3523 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(lineEditCenter)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3524 |
QVERIFY(proxy->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3525 |
QVERIFY(proxy->widget()->hasFocus()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3526 |
QCOMPARE(widgetSpy.counts[QEvent::FocusIn], 1); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3527 |
QCOMPARE(proxySpy.counts[QEvent::FocusIn], 1); |
0 | 3528 |
} |
3529 |
} |
|
3530 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3531 |
void tst_QGraphicsProxyWidget::windowFrameMargins() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3532 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3533 |
// Make sure the top margin is non-zero when passing Qt::Window. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3534 |
QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(0, Qt::Window); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3535 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3536 |
qreal left, top, right, bottom; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3537 |
proxy->getWindowFrameMargins(&left, &top, &right, &bottom); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3538 |
QVERIFY(top > 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3539 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3540 |
proxy->setWidget(new QPushButton("testtest")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3541 |
proxy->getWindowFrameMargins(&left, &top, &right, &bottom); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3542 |
QVERIFY(top > 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3543 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3544 |
QGraphicsScene scene; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3545 |
scene.addItem(proxy); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3546 |
proxy->getWindowFrameMargins(&left, &top, &right, &bottom); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3547 |
QVERIFY(top > 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3548 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3549 |
proxy->unsetWindowFrameMargins(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3550 |
proxy->getWindowFrameMargins(&left, &top, &right, &bottom); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3551 |
QVERIFY(top > 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3552 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3553 |
|
0 | 3554 |
QTEST_MAIN(tst_QGraphicsProxyWidget) |
3555 |
#include "tst_qgraphicsproxywidget.moc" |
|
3556 |
||
3557 |
#else // QT_NO_STYLE_CLEANLOOKS |
|
3558 |
QTEST_NOOP_MAIN |
|
3559 |
#endif |