author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 15 Mar 2010 12:43:09 +0200 | |
branch | RCL_3 |
changeset 6 | dee5afe5301f |
parent 5 | d3bac044e0f0 |
child 8 | 3f74d0d4af4c |
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 |
#if defined(QT3_SUPPORT) |
|
44 |
#include <q3hbox.h> |
|
45 |
#include <q3textedit.h> |
|
46 |
#endif |
|
47 |
#include <qboxlayout.h> |
|
48 |
#include <qapplication.h> |
|
49 |
#include <qbitmap.h> |
|
50 |
#include <qdebug.h> |
|
51 |
#include <qeventloop.h> |
|
52 |
#include <qlabel.h> |
|
53 |
#include <qlayout.h> |
|
54 |
#include <qlineedit.h> |
|
55 |
#include <qlistview.h> |
|
56 |
#include <qmessagebox.h> |
|
57 |
#include <qpainter.h> |
|
58 |
#include <qpoint.h> |
|
59 |
#include <qpushbutton.h> |
|
60 |
#include <qstyle.h> |
|
61 |
#include <qwidget.h> |
|
62 |
#include <qwindowsstyle.h> |
|
63 |
#include <qinputcontext.h> |
|
64 |
#include <qdesktopwidget.h> |
|
65 |
#include <private/qwidget_p.h> |
|
66 |
#include <private/qapplication_p.h> |
|
67 |
#include <qcalendarwidget.h> |
|
68 |
#include <qmainwindow.h> |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
69 |
#include <qdockwidget.h> |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
70 |
#include <qtoolbar.h> |
0 | 71 |
#include <QtGui/qpaintengine.h> |
72 |
#include <private/qbackingstore_p.h> |
|
73 |
||
74 |
#include <QtGui/QGraphicsView> |
|
75 |
#include <QtGui/QGraphicsProxyWidget> |
|
76 |
||
77 |
#include "../../shared/util.h" |
|
78 |
||
79 |
||
80 |
#ifdef Q_WS_S60 |
|
81 |
#include <avkon.hrh> // EEikStatusPaneUidTitle |
|
82 |
#include <akntitle.h> // CAknTitlePane |
|
83 |
#include <akncontext.h> // CAknContextPane |
|
84 |
#include <eikspane.h> // CEikStatusPane |
|
85 |
#include <eikbtgpc.h> // CEikButtonGroupContainer |
|
86 |
#endif |
|
87 |
||
88 |
#ifdef Q_WS_QWS |
|
89 |
# include <qscreen_qws.h> |
|
90 |
#endif |
|
91 |
||
92 |
// I *MUST* have QtTest afterwards or this test won't work with newer headers |
|
93 |
#if defined(Q_WS_MAC) |
|
94 |
# include <private/qt_mac_p.h> |
|
95 |
#undef verify |
|
96 |
#include "tst_qwidget_mac_helpers.h" // Abstract the ObjC stuff out so not everyone must run an ObjC++ compile. |
|
97 |
#endif |
|
98 |
||
99 |
#include <QtTest/QtTest> |
|
100 |
||
101 |
#if defined(Q_WS_WIN) |
|
102 |
# include <qt_windows.h> |
|
103 |
# if !defined(Q_OS_WINCE) |
|
104 |
#define Q_CHECK_PAINTEVENTS \ |
|
105 |
if (::SwitchDesktop(::GetThreadDesktop(::GetCurrentThreadId())) == 0) \ |
|
106 |
QSKIP("desktop is not visible, this test would fail", SkipSingle); |
|
107 |
# else |
|
108 |
# define Q_CHECK_PAINTEVENTS |
|
109 |
# endif |
|
110 |
#elif defined(Q_WS_X11) |
|
111 |
# include <private/qt_x11_p.h> |
|
112 |
# include <qx11info_x11.h> |
|
113 |
#elif defined(Q_WS_QWS) |
|
114 |
# include <qwindowsystem_qws.h> |
|
115 |
#endif |
|
116 |
||
117 |
#if !defined(Q_WS_WIN) |
|
118 |
#define Q_CHECK_PAINTEVENTS |
|
119 |
#endif |
|
120 |
||
121 |
#if defined(Q_OS_WINCE_WM) |
|
122 |
#include <qguifunctions_wince.h> |
|
123 |
// taken from qguifunctions_wce.cpp |
|
124 |
#define SPI_GETPLATFORMTYPE 257 |
|
125 |
bool qt_wince_is_platform(const QString &platformString) { |
|
126 |
wchar_t tszPlatform[64]; |
|
127 |
if (SystemParametersInfo(SPI_GETPLATFORMTYPE, |
|
128 |
sizeof(tszPlatform)/sizeof(*tszPlatform),tszPlatform,0)) |
|
129 |
if (0 == _tcsicmp(reinterpret_cast<const wchar_t *> (platformString.utf16()), tszPlatform)) |
|
130 |
return true; |
|
131 |
return false; |
|
132 |
} |
|
133 |
bool qt_wince_is_smartphone() { |
|
134 |
return qt_wince_is_platform(QString::fromLatin1("Smartphone")); |
|
135 |
} |
|
136 |
#endif |
|
137 |
||
138 |
#ifdef Q_WS_MAC |
|
139 |
#include <Security/AuthSession.h> |
|
140 |
bool macHasAccessToWindowsServer() |
|
141 |
{ |
|
142 |
SecuritySessionId mySession; |
|
143 |
SessionAttributeBits sessionInfo; |
|
144 |
SessionGetInfo(callerSecuritySession, &mySession, &sessionInfo); |
|
145 |
return (sessionInfo & sessionHasGraphicAccess); |
|
146 |
} |
|
147 |
#endif |
|
148 |
||
149 |
||
150 |
#if defined(Bool) |
|
151 |
#undef Bool |
|
152 |
#endif |
|
153 |
||
154 |
// Will try to wait for the condition while allowing event processing |
|
155 |
// for a maximum of 2 seconds. |
|
156 |
#define WAIT_FOR_CONDITION(expr, expected) \ |
|
157 |
do { \ |
|
158 |
const int step = 100; \ |
|
159 |
for (int i = 0; i < 2000 && expr != expected; i+=step) { \ |
|
160 |
QTest::qWait(step); \ |
|
161 |
} \ |
|
162 |
} while(0) |
|
163 |
||
164 |
//TESTED_CLASS= |
|
165 |
//TESTED_FILES= |
|
166 |
||
167 |
class tst_QWidget : public QObject |
|
168 |
{ |
|
169 |
Q_OBJECT |
|
170 |
||
171 |
public: |
|
172 |
tst_QWidget(); |
|
173 |
virtual ~tst_QWidget(); |
|
174 |
||
175 |
||
176 |
public slots: |
|
177 |
void initTestCase(); |
|
178 |
void cleanupTestCase(); |
|
179 |
void init(); |
|
180 |
void cleanup(); |
|
181 |
private slots: |
|
182 |
void getSetCheck(); |
|
183 |
void fontPropagation(); |
|
184 |
void fontPropagation2(); |
|
185 |
void palettePropagation(); |
|
186 |
void palettePropagation2(); |
|
187 |
void enabledPropagation(); |
|
188 |
void acceptDropsPropagation(); |
|
189 |
void isEnabledTo(); |
|
190 |
void visible(); |
|
191 |
void visible_setWindowOpacity(); |
|
192 |
void isVisibleTo(); |
|
193 |
void isHidden(); |
|
194 |
void fonts(); |
|
195 |
void mapToGlobal(); |
|
196 |
void mapFromAndTo_data(); |
|
197 |
void mapFromAndTo(); |
|
198 |
void checkFocus(); |
|
199 |
void focusChainOnHide(); |
|
200 |
void focusChainOnReparent(); |
|
201 |
void setTabOrder(); |
|
202 |
void activation(); |
|
203 |
void reparent(); |
|
204 |
void windowState(); |
|
205 |
void showMaximized(); |
|
206 |
void showFullScreen(); |
|
207 |
void showMinimized(); |
|
208 |
void showMinimizedKeepsFocus(); |
|
209 |
void icon(); |
|
210 |
void hideWhenFocusWidgetIsChild(); |
|
211 |
void normalGeometry(); |
|
212 |
void setGeometry(); |
|
213 |
void windowOpacity(); |
|
214 |
void raise(); |
|
215 |
void lower(); |
|
216 |
void stackUnder(); |
|
217 |
void testContentsPropagation(); |
|
218 |
void saveRestoreGeometry(); |
|
219 |
||
220 |
void restoreVersion1Geometry_data(); |
|
221 |
void restoreVersion1Geometry(); |
|
222 |
||
223 |
void windowTitle(); |
|
224 |
void windowModified(); |
|
225 |
void windowIconText(); |
|
226 |
||
227 |
void widgetAt(); |
|
228 |
#ifdef Q_WS_MAC |
|
229 |
void retainHIView(); |
|
230 |
void sheetOpacity(); |
|
231 |
void setMask(); |
|
232 |
#endif |
|
233 |
void optimizedResizeMove(); |
|
234 |
void optimizedResize_topLevel(); |
|
235 |
void resizeEvent(); |
|
236 |
void task110173(); |
|
237 |
||
238 |
void testDeletionInEventHandlers(); |
|
239 |
||
240 |
void childDeletesItsSibling(); |
|
241 |
||
242 |
void setMinimumSize(); |
|
243 |
void setMaximumSize(); |
|
244 |
void setFixedSize(); |
|
245 |
||
246 |
void ensureCreated(); |
|
247 |
void winIdChangeEvent(); |
|
248 |
#ifdef Q_OS_SYMBIAN |
|
249 |
void reparentCausesChildWinIdChange(); |
|
250 |
#else |
|
251 |
void persistentWinId(); |
|
252 |
#endif |
|
253 |
void qobject_castInDestroyedSlot(); |
|
254 |
||
255 |
void showHideEvent_data(); |
|
256 |
void showHideEvent(); |
|
257 |
||
258 |
void lostUpdatesOnHide(); |
|
259 |
||
260 |
void update(); |
|
261 |
void isOpaque(); |
|
262 |
||
263 |
#ifndef Q_WS_MAC |
|
264 |
void scroll(); |
|
265 |
#endif |
|
266 |
||
267 |
// tests QWidget::setGeometry() on windows only |
|
268 |
void setWindowGeometry_data(); |
|
269 |
void setWindowGeometry(); |
|
270 |
||
271 |
// tests QWidget::move() and resize() on windows only |
|
272 |
void windowMoveResize_data(); |
|
273 |
void windowMoveResize(); |
|
274 |
||
275 |
void moveChild_data(); |
|
276 |
void moveChild(); |
|
277 |
void showAndMoveChild(); |
|
278 |
||
279 |
void subtractOpaqueSiblings(); |
|
280 |
||
281 |
#ifdef Q_WS_WIN |
|
282 |
void getDC(); |
|
283 |
#ifndef Q_OS_WINCE |
|
284 |
void setGeometry_win(); |
|
285 |
#endif |
|
286 |
#endif |
|
287 |
||
288 |
void setLocale(); |
|
289 |
void deleteStyle(); |
|
290 |
void multipleToplevelFocusCheck(); |
|
291 |
void setFocus(); |
|
292 |
void setCursor(); |
|
293 |
void setToolTip(); |
|
294 |
void testWindowIconChangeEventPropagation(); |
|
295 |
#ifdef Q_WS_X11 |
|
296 |
void minAndMaxSizeWithX11BypassWindowManagerHint(); |
|
297 |
void showHideShow(); |
|
298 |
void clean_qt_x11_enforce_cursor(); |
|
299 |
#endif |
|
300 |
||
301 |
void compatibilityChildInsertedEvents(); |
|
302 |
void render(); |
|
303 |
void renderInvisible(); |
|
304 |
void renderWithPainter(); |
|
305 |
void render_task188133(); |
|
306 |
void render_task211796(); |
|
307 |
void render_task217815(); |
|
308 |
void render_windowOpacity(); |
|
309 |
void render_systemClip(); |
|
310 |
void render_systemClip2_data(); |
|
311 |
void render_systemClip2(); |
|
312 |
void render_systemClip3_data(); |
|
313 |
void render_systemClip3(); |
|
314 |
void render_task252837(); |
|
315 |
void render_worldTransform(); |
|
316 |
||
317 |
void setContentsMargins(); |
|
318 |
||
319 |
void moveWindowInShowEvent_data(); |
|
320 |
void moveWindowInShowEvent(); |
|
321 |
||
322 |
void repaintWhenChildDeleted(); |
|
323 |
void hideOpaqueChildWhileHidden(); |
|
324 |
void updateWhileMinimized(); |
|
325 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) |
|
326 |
void alienWidgets(); |
|
327 |
#endif |
|
328 |
void adjustSize(); |
|
329 |
void adjustSize_data(); |
|
330 |
void updateGeometry(); |
|
331 |
void updateGeometry_data(); |
|
332 |
void sendUpdateRequestImmediately(); |
|
333 |
void painterRedirection(); |
|
334 |
void doubleRepaint(); |
|
335 |
#ifndef Q_WS_MAC |
|
336 |
void resizeInPaintEvent(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
337 |
void opaqueChildren(); |
0 | 338 |
#endif |
339 |
||
340 |
void setMaskInResizeEvent(); |
|
341 |
void moveInResizeEvent(); |
|
342 |
||
343 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) |
|
344 |
// We don't support immediate repaint right after show on |
|
345 |
// other platforms. Must be compatible with Qt 4.3. |
|
346 |
void immediateRepaintAfterShow(); |
|
347 |
void immediateRepaintAfterInvalidateBuffer(); |
|
348 |
#endif |
|
349 |
void effectiveWinId(); |
|
350 |
void customDpi(); |
|
351 |
void customDpiProperty(); |
|
352 |
||
353 |
void quitOnCloseAttribute(); |
|
354 |
void moveRect(); |
|
355 |
||
356 |
#if defined (Q_WS_WIN) |
|
357 |
void gdiPainting(); |
|
358 |
void paintOnScreenPossible(); |
|
359 |
#endif |
|
360 |
void reparentStaticWidget(); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
361 |
void QTBUG6883_reparentStaticWidget2(); |
0 | 362 |
#ifdef Q_WS_QWS |
363 |
void updateOutsideSurfaceClip(); |
|
364 |
#endif |
|
365 |
void translucentWidget(); |
|
366 |
||
367 |
void setClearAndResizeMask(); |
|
368 |
void maskedUpdate(); |
|
369 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_QWS) |
|
370 |
void syntheticEnterLeave(); |
|
371 |
void taskQTBUG_4055_sendSyntheticEnterLeave(); |
|
372 |
#endif |
|
373 |
void windowFlags(); |
|
374 |
void initialPosForDontShowOnScreenWidgets(); |
|
375 |
#ifdef Q_WS_X11 |
|
376 |
void paintOutsidePaintEvent(); |
|
377 |
#endif |
|
378 |
void updateOnDestroyedSignal(); |
|
379 |
void toplevelLineEditFocus(); |
|
380 |
void inputFocus_task257832(); |
|
381 |
||
382 |
void focusWidget_task254563(); |
|
383 |
void rectOutsideCoordinatesLimit_task144779(); |
|
384 |
void setGraphicsEffect(); |
|
385 |
||
386 |
void destroyBackingStore(); |
|
387 |
||
388 |
void activateWindow(); |
|
389 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
void openModal_taskQTBUG_5804(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
391 |
|
0 | 392 |
#ifdef Q_OS_SYMBIAN |
393 |
void cbaVisibility(); |
|
394 |
#endif |
|
395 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
void focusProxyAndInputMethods(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
void scrollWithoutBackingStore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
|
0 | 399 |
private: |
400 |
bool ensureScreenSize(int width, int height); |
|
401 |
QWidget *testWidget; |
|
402 |
}; |
|
403 |
||
404 |
bool tst_QWidget::ensureScreenSize(int width, int height) |
|
405 |
{ |
|
406 |
QSize available; |
|
407 |
#ifdef Q_WS_QWS |
|
408 |
available = QDesktopWidget().availableGeometry().size(); |
|
409 |
if (available.width() < width || available.height() < height) { |
|
410 |
QScreen *screen = QScreen::instance(); |
|
411 |
if (!screen) |
|
412 |
return false; |
|
413 |
screen->setMode(width, height, screen->depth()); |
|
414 |
} |
|
415 |
#endif // Q_WS_QWS |
|
416 |
||
417 |
available = QDesktopWidget().availableGeometry().size(); |
|
418 |
return (available.width() >= width && available.height() >= height); |
|
419 |
} |
|
420 |
||
421 |
class MyInputContext : public QInputContext |
|
422 |
{ |
|
423 |
public: |
|
424 |
MyInputContext() : QInputContext() {} |
|
425 |
QString identifierName() { return QString("NoName"); } |
|
426 |
QString language() { return QString("NoLanguage"); } |
|
427 |
void reset() {} |
|
428 |
bool isComposing() const { return false; } |
|
429 |
}; |
|
430 |
||
431 |
// Testing get/set functions |
|
432 |
void tst_QWidget::getSetCheck() |
|
433 |
{ |
|
434 |
QWidget obj1; |
|
435 |
QWidget child1(&obj1); |
|
436 |
// QStyle * QWidget::style() |
|
437 |
// void QWidget::setStyle(QStyle *) |
|
438 |
QWindowsStyle *var1 = new QWindowsStyle; |
|
439 |
obj1.setStyle(var1); |
|
440 |
QCOMPARE(static_cast<QStyle *>(var1), obj1.style()); |
|
441 |
obj1.setStyle((QStyle *)0); |
|
442 |
QVERIFY(var1 != obj1.style()); |
|
443 |
QVERIFY(0 != obj1.style()); // style can never be 0 for a widget |
|
444 |
||
445 |
// int QWidget::minimumWidth() |
|
446 |
// void QWidget::setMinimumWidth(int) |
|
447 |
obj1.setMinimumWidth(0); |
|
448 |
QCOMPARE(obj1.minimumWidth(), 0); |
|
449 |
obj1.setMinimumWidth(INT_MIN); |
|
450 |
QCOMPARE(obj1.minimumWidth(), 0); // A widgets width can never be less than 0 |
|
451 |
obj1.setMinimumWidth(INT_MAX); |
|
452 |
#ifndef Q_WS_QWS //QWS doesn't allow toplevels to be bigger than the screen |
|
453 |
#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) |
|
454 |
QCOMPARE((long)obj1.minimumWidth(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium |
|
455 |
#else |
|
456 |
QCOMPARE(obj1.minimumWidth(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium |
|
457 |
#endif |
|
458 |
#endif |
|
459 |
||
460 |
child1.setMinimumWidth(0); |
|
461 |
QCOMPARE(child1.minimumWidth(), 0); |
|
462 |
child1.setMinimumWidth(INT_MIN); |
|
463 |
QCOMPARE(child1.minimumWidth(), 0); // A widgets width can never be less than 0 |
|
464 |
child1.setMinimumWidth(INT_MAX); |
|
465 |
#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) |
|
466 |
QCOMPARE((long)child1.minimumWidth(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium |
|
467 |
#else |
|
468 |
QCOMPARE(child1.minimumWidth(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium |
|
469 |
#endif |
|
470 |
||
471 |
// int QWidget::minimumHeight() |
|
472 |
// void QWidget::setMinimumHeight(int) |
|
473 |
obj1.setMinimumHeight(0); |
|
474 |
QCOMPARE(obj1.minimumHeight(), 0); |
|
475 |
obj1.setMinimumHeight(INT_MIN); |
|
476 |
QCOMPARE(obj1.minimumHeight(), 0); // A widgets height can never be less than 0 |
|
477 |
obj1.setMinimumHeight(INT_MAX); |
|
478 |
#ifndef Q_WS_QWS //QWS doesn't allow toplevels to be bigger than the screen |
|
479 |
#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) |
|
480 |
QCOMPARE((long)obj1.minimumHeight(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium |
|
481 |
#else |
|
482 |
QCOMPARE(obj1.minimumHeight(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium |
|
483 |
#endif |
|
484 |
#endif |
|
485 |
||
486 |
child1.setMinimumHeight(0); |
|
487 |
QCOMPARE(child1.minimumHeight(), 0); |
|
488 |
child1.setMinimumHeight(INT_MIN); |
|
489 |
QCOMPARE(child1.minimumHeight(), 0); // A widgets height can never be less than 0 |
|
490 |
child1.setMinimumHeight(INT_MAX); |
|
491 |
#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) |
|
492 |
QCOMPARE((long)child1.minimumHeight(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium |
|
493 |
#else |
|
494 |
QCOMPARE(child1.minimumHeight(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium |
|
495 |
#endif |
|
496 |
||
497 |
||
498 |
||
499 |
// int QWidget::maximumWidth() |
|
500 |
// void QWidget::setMaximumWidth(int) |
|
501 |
obj1.setMaximumWidth(0); |
|
502 |
QCOMPARE(obj1.maximumWidth(), 0); |
|
503 |
obj1.setMaximumWidth(INT_MIN); |
|
504 |
QCOMPARE(obj1.maximumWidth(), 0); // A widgets width can never be less than 0 |
|
505 |
obj1.setMaximumWidth(INT_MAX); |
|
506 |
#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) |
|
507 |
QCOMPARE((long)obj1.maximumWidth(), QWIDGETSIZE_MAX); // QWIDGETSIZE_MAX is the abs max, not INT_MAX |
|
508 |
#else |
|
509 |
QCOMPARE(obj1.maximumWidth(), QWIDGETSIZE_MAX); // QWIDGETSIZE_MAX is the abs max, not INT_MAX |
|
510 |
#endif |
|
511 |
||
512 |
// int QWidget::maximumHeight() |
|
513 |
// void QWidget::setMaximumHeight(int) |
|
514 |
obj1.setMaximumHeight(0); |
|
515 |
QCOMPARE(obj1.maximumHeight(), 0); |
|
516 |
obj1.setMaximumHeight(INT_MIN); |
|
517 |
QCOMPARE(obj1.maximumHeight(), 0); // A widgets height can never be less than 0 |
|
518 |
obj1.setMaximumHeight(INT_MAX); |
|
519 |
#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) |
|
520 |
QCOMPARE((long)obj1.maximumHeight(), QWIDGETSIZE_MAX); // QWIDGETSIZE_MAX is the abs max, not INT_MAX |
|
521 |
#else |
|
522 |
QCOMPARE(obj1.maximumHeight(), QWIDGETSIZE_MAX); // QWIDGETSIZE_MAX is the abs max, not INT_MAX |
|
523 |
#endif |
|
524 |
||
525 |
// back to normal |
|
526 |
obj1.setMinimumWidth(0); |
|
527 |
obj1.setMinimumHeight(0); |
|
528 |
obj1.setMaximumWidth(QWIDGETSIZE_MAX); |
|
529 |
obj1.setMaximumHeight(QWIDGETSIZE_MAX); |
|
530 |
||
531 |
// const QPalette & QWidget::palette() |
|
532 |
// void QWidget::setPalette(const QPalette &) |
|
533 |
QPalette var6; |
|
534 |
obj1.setPalette(var6); |
|
535 |
QCOMPARE(var6, obj1.palette()); |
|
536 |
obj1.setPalette(QPalette()); |
|
537 |
QCOMPARE(QPalette(), obj1.palette()); |
|
538 |
||
539 |
// const QFont & QWidget::font() |
|
540 |
// void QWidget::setFont(const QFont &) |
|
541 |
QFont var7; |
|
542 |
obj1.setFont(var7); |
|
543 |
QCOMPARE(var7, obj1.font()); |
|
544 |
obj1.setFont(QFont()); |
|
545 |
QCOMPARE(QFont(), obj1.font()); |
|
546 |
||
547 |
// qreal QWidget::windowOpacity() |
|
548 |
// void QWidget::setWindowOpacity(qreal) |
|
549 |
obj1.setWindowOpacity(0.0); |
|
550 |
QCOMPARE(0.0, obj1.windowOpacity()); |
|
551 |
obj1.setWindowOpacity(1.1f); |
|
552 |
QCOMPARE(1.0, obj1.windowOpacity()); // 1.0 is the fullest opacity possible |
|
553 |
||
554 |
// QWidget * QWidget::focusProxy() |
|
555 |
// void QWidget::setFocusProxy(QWidget *) |
|
556 |
QWidget *var9 = new QWidget(); |
|
557 |
obj1.setFocusProxy(var9); |
|
558 |
QCOMPARE(var9, obj1.focusProxy()); |
|
559 |
obj1.setFocusProxy((QWidget *)0); |
|
560 |
QCOMPARE((QWidget *)0, obj1.focusProxy()); |
|
561 |
delete var9; |
|
562 |
||
563 |
// const QRect & QWidget::geometry() |
|
564 |
// void QWidget::setGeometry(const QRect &) |
|
565 |
qApp->processEvents(); |
|
566 |
QRect var10(10, 10, 100, 100); |
|
567 |
obj1.setGeometry(var10); |
|
568 |
qApp->processEvents(); |
|
569 |
qDebug() << obj1.geometry(); |
|
570 |
QCOMPARE(var10, obj1.geometry()); |
|
571 |
obj1.setGeometry(QRect(0,0,0,0)); |
|
572 |
qDebug() << obj1.geometry(); |
|
573 |
QCOMPARE(QRect(0,0,0,0), obj1.geometry()); |
|
574 |
||
575 |
// QLayout * QWidget::layout() |
|
576 |
// void QWidget::setLayout(QLayout *) |
|
577 |
QBoxLayout *var11 = new QBoxLayout(QBoxLayout::LeftToRight); |
|
578 |
obj1.setLayout(var11); |
|
579 |
QCOMPARE(static_cast<QLayout *>(var11), obj1.layout()); |
|
580 |
obj1.setLayout((QLayout *)0); |
|
581 |
QCOMPARE(static_cast<QLayout *>(var11), obj1.layout()); // You cannot set a 0-pointer layout, that keeps the current |
|
582 |
delete var11; // This will remove the layout from the widget |
|
583 |
QCOMPARE((QLayout *)0, obj1.layout()); |
|
584 |
||
585 |
// bool QWidget::acceptDrops() |
|
586 |
// void QWidget::setAcceptDrops(bool) |
|
587 |
obj1.setAcceptDrops(false); |
|
588 |
QCOMPARE(false, obj1.acceptDrops()); |
|
589 |
obj1.setAcceptDrops(true); |
|
590 |
QCOMPARE(true, obj1.acceptDrops()); |
|
591 |
||
592 |
// QInputContext * QWidget::inputContext() |
|
593 |
// void QWidget::setInputContext(QInputContext *) |
|
594 |
MyInputContext *var13 = new MyInputContext; |
|
595 |
obj1.setInputContext(var13); |
|
596 |
QCOMPARE((QInputContext *)0, obj1.inputContext()); // The widget by default doesn't have the WA_InputMethodEnabled attribute |
|
597 |
obj1.setAttribute(Qt::WA_InputMethodEnabled); |
|
598 |
obj1.setInputContext(var13); |
|
599 |
QCOMPARE(static_cast<QInputContext *>(var13), obj1.inputContext()); |
|
600 |
obj1.setInputContext((QInputContext *)0); |
|
601 |
QCOMPARE(qApp->inputContext(), obj1.inputContext()); |
|
602 |
QVERIFY(qApp->inputContext() != var13); |
|
603 |
//delete var13; // No delete, since QWidget takes ownership |
|
604 |
||
605 |
// bool QWidget::autoFillBackground() |
|
606 |
// void QWidget::setAutoFillBackground(bool) |
|
607 |
obj1.setAutoFillBackground(false); |
|
608 |
QCOMPARE(false, obj1.autoFillBackground()); |
|
609 |
obj1.setAutoFillBackground(true); |
|
610 |
QCOMPARE(true, obj1.autoFillBackground()); |
|
611 |
||
612 |
delete var1; |
|
613 |
#if defined (Q_WS_WIN) && !defined(Q_OS_WINCE) |
|
614 |
obj1.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint); |
|
615 |
HWND handle = obj1.winId(); |
|
616 |
long flags = GetWindowLong(handle, GWL_STYLE); |
|
617 |
QVERIFY(flags & WS_POPUP); |
|
618 |
#endif |
|
619 |
} |
|
620 |
||
621 |
tst_QWidget::tst_QWidget() |
|
622 |
{ |
|
623 |
QFont font; |
|
624 |
font.setBold(true); |
|
625 |
font.setPointSize(42); |
|
626 |
qApp->setFont(font, "QPropagationTestWidget"); |
|
627 |
||
628 |
QPalette palette; |
|
629 |
palette.setColor(QPalette::ToolTipBase, QColor(12, 13, 14)); |
|
630 |
palette.setColor(QPalette::Text, QColor(21, 22, 23)); |
|
631 |
qApp->setPalette(palette, "QPropagationTestWidget"); |
|
632 |
||
633 |
testWidget = 0; |
|
634 |
} |
|
635 |
||
636 |
tst_QWidget::~tst_QWidget() |
|
637 |
{ |
|
638 |
} |
|
639 |
||
640 |
class BezierViewer : public QWidget { |
|
641 |
public: |
|
642 |
BezierViewer( QWidget* parent=0, const char* name=0 ); |
|
643 |
void paintEvent( QPaintEvent* ); |
|
644 |
void setPoints( const QPolygonF& poly ); |
|
645 |
private: |
|
646 |
QPolygonF points; |
|
647 |
||
648 |
}; |
|
649 |
||
650 |
void tst_QWidget::initTestCase() |
|
651 |
{ |
|
652 |
#ifdef Q_OS_WINCE //disable magic for WindowsCE |
|
653 |
qApp->setAutoMaximizeThreshold(-1); |
|
654 |
#endif |
|
655 |
// Create the test class |
|
656 |
testWidget = new BezierViewer( 0, "testObject"); |
|
657 |
testWidget->resize(200,200); |
|
658 |
#ifdef QT3_SUPPORT |
|
659 |
qApp->setMainWidget(testWidget); |
|
660 |
#endif |
|
661 |
testWidget->show(); |
|
662 |
QTest::qWaitForWindowShown(testWidget); |
|
663 |
QTest::qWait(50); |
|
664 |
} |
|
665 |
||
666 |
void tst_QWidget::cleanupTestCase() |
|
667 |
{ |
|
668 |
delete testWidget; |
|
669 |
testWidget = 0; |
|
670 |
} |
|
671 |
||
672 |
void tst_QWidget::init() |
|
673 |
{ |
|
674 |
// TODO: Add initialization code here. |
|
675 |
// This will be executed immediately before each test is run. |
|
676 |
testWidget->setFont(QFont()); |
|
677 |
testWidget->setPalette(QPalette()); |
|
678 |
} |
|
679 |
||
680 |
void tst_QWidget::cleanup() |
|
681 |
{ |
|
682 |
} |
|
683 |
||
684 |
// Helper class... |
|
685 |
||
686 |
BezierViewer::BezierViewer( QWidget* parent, const char* name ) |
|
687 |
: QWidget( parent ) |
|
688 |
{ |
|
689 |
setObjectName(name); |
|
690 |
QPalette pal; |
|
691 |
pal.setColor(backgroundRole(), Qt::white); |
|
692 |
setPalette(pal); |
|
693 |
} |
|
694 |
||
695 |
||
696 |
void BezierViewer::setPoints( const QPolygonF& a ) |
|
697 |
{ |
|
698 |
points = a; |
|
699 |
} |
|
700 |
||
701 |
#include "private/qbezier_p.h" |
|
702 |
void BezierViewer::paintEvent( QPaintEvent* ) |
|
703 |
{ |
|
704 |
if ( points.size() != 4 ) { |
|
705 |
#if defined(QT_CHECK_RANGE) |
|
706 |
qWarning( "QPolygon::bezier: The array must have 4 control points" ); |
|
707 |
#endif |
|
708 |
return; |
|
709 |
} |
|
710 |
||
711 |
/* Calculate Bezier curve */ |
|
712 |
QPolygonF bezier = QBezier::fromPoints(points.at(0),points.at(1),points.at(2),points.at(3)).toPolygon(); |
|
713 |
||
714 |
QPainter painter( this ); |
|
715 |
||
716 |
/* Calculate scale to fit in window */ |
|
717 |
QRectF br = bezier.boundingRect() | points.boundingRect(); |
|
718 |
QRectF pr = rect(); |
|
719 |
int scl = qMax( qMin(pr.width()/br.width(), pr.height()/br.height()), qreal(1.) ); |
|
720 |
int border = scl-1; |
|
721 |
||
722 |
/* Scale Bezier curve vertices */ |
|
723 |
for ( QPolygonF::Iterator it = bezier.begin(); it != bezier.end(); ++it ) { |
|
724 |
it->setX( (it->x()-br.x()) * scl + border ); |
|
725 |
it->setY( (it->y()-br.y()) * scl + border ); |
|
726 |
} |
|
727 |
||
728 |
/* Draw grid */ |
|
729 |
painter.setPen( Qt::lightGray ); |
|
730 |
int i; |
|
731 |
for ( i = border; i <= pr.width(); i += scl ) { |
|
732 |
painter.drawLine( i, 0, i, pr.height() ); |
|
733 |
} |
|
734 |
for ( int j = border; j <= pr.height(); j += scl ) { |
|
735 |
painter.drawLine( 0, j, pr.width(), j ); |
|
736 |
} |
|
737 |
||
738 |
/* Write number of vertices */ |
|
739 |
painter.setPen( Qt::red ); |
|
740 |
painter.setFont( QFont("Helvetica", 14, QFont::DemiBold, TRUE ) ); |
|
741 |
QString caption; |
|
742 |
caption.setNum( bezier.size() ); |
|
743 |
caption += QString::fromLatin1( " vertices" ); |
|
744 |
painter.drawText( 10, pr.height()-10, caption ); |
|
745 |
||
746 |
/* Draw Bezier curve */ |
|
747 |
painter.setPen( Qt::black ); |
|
748 |
painter.drawPolyline( bezier ); |
|
749 |
||
750 |
/* Scale and draw control points */ |
|
751 |
painter.setPen( Qt::darkGreen ); |
|
752 |
for ( QPolygonF::Iterator p1 = points.begin(); p1 != points.end(); ++p1 ) { |
|
753 |
int x = (p1->x()-br.x()) * scl + border; |
|
754 |
int y = (p1->y()-br.y()) * scl + border; |
|
755 |
painter.drawLine( x-4, y-4, x+4, y+4 ); |
|
756 |
painter.drawLine( x+4, y-4, x-4, y+4 ); |
|
757 |
} |
|
758 |
||
759 |
/* Draw vertices */ |
|
760 |
painter.setPen( Qt::red ); |
|
761 |
painter.setBrush( Qt::red ); |
|
762 |
for ( QPolygonF::Iterator p2 = bezier.begin(); p2 != bezier.end(); ++p2 ) |
|
763 |
painter.drawEllipse( p2->x()-1, p2->y()-1, 3, 3 ); |
|
764 |
} |
|
765 |
||
766 |
void tst_QWidget::fontPropagation() |
|
767 |
{ |
|
768 |
QFont font = testWidget->font(); |
|
769 |
QWidget* childWidget = new QWidget( testWidget ); |
|
770 |
childWidget->show(); |
|
771 |
QCOMPARE( font, childWidget->font() ); |
|
772 |
||
773 |
font.setBold( TRUE ); |
|
774 |
testWidget->setFont( font ); |
|
775 |
QCOMPARE( font, testWidget->font() ); |
|
776 |
QCOMPARE( font, childWidget->font() ); |
|
777 |
||
778 |
QFont newFont = font; |
|
779 |
newFont.setItalic( TRUE ); |
|
780 |
childWidget->setFont( newFont ); |
|
781 |
QWidget* grandChildWidget = new QWidget( childWidget ); |
|
782 |
QCOMPARE( font, testWidget->font() ); |
|
783 |
QCOMPARE( newFont, grandChildWidget->font() ); |
|
784 |
||
785 |
font.setUnderline( TRUE ); |
|
786 |
testWidget->setFont( font ); |
|
787 |
||
788 |
// the child and grand child should now have merged bold and |
|
789 |
// underline |
|
790 |
newFont.setUnderline( TRUE ); |
|
791 |
||
792 |
QCOMPARE( newFont, childWidget->font() ); |
|
793 |
QCOMPARE( newFont, grandChildWidget->font() ); |
|
794 |
||
795 |
// make sure font propagation continues working after reparenting |
|
796 |
font = testWidget->font(); |
|
797 |
font.setPointSize(font.pointSize() + 2); |
|
798 |
testWidget->setFont(font); |
|
799 |
||
800 |
QWidget *one = new QWidget(testWidget); |
|
801 |
QWidget *two = new QWidget(one); |
|
802 |
QWidget *three = new QWidget(two); |
|
803 |
QWidget *four = new QWidget(two); |
|
804 |
||
805 |
four->setParent(three); |
|
806 |
four->move(QPoint(0,0)); |
|
807 |
||
808 |
font.setPointSize(font.pointSize() + 2); |
|
809 |
testWidget->setFont(font); |
|
810 |
||
811 |
QCOMPARE(testWidget->font(), one->font()); |
|
812 |
QCOMPARE(one->font(), two->font()); |
|
813 |
QCOMPARE(two->font(), three->font()); |
|
814 |
QCOMPARE(three->font(), four->font()); |
|
815 |
||
816 |
QVERIFY(testWidget->testAttribute(Qt::WA_SetFont)); |
|
817 |
QVERIFY(! one->testAttribute(Qt::WA_SetFont)); |
|
818 |
QVERIFY(! two->testAttribute(Qt::WA_SetFont)); |
|
819 |
QVERIFY(! three->testAttribute(Qt::WA_SetFont)); |
|
820 |
QVERIFY(! four->testAttribute(Qt::WA_SetFont)); |
|
821 |
||
822 |
font.setPointSize(font.pointSize() + 2); |
|
823 |
one->setFont(font); |
|
824 |
||
825 |
QCOMPARE(one->font(), two->font()); |
|
826 |
QCOMPARE(two->font(), three->font()); |
|
827 |
QCOMPARE(three->font(), four->font()); |
|
828 |
||
829 |
QVERIFY(one->testAttribute(Qt::WA_SetFont)); |
|
830 |
QVERIFY(! two->testAttribute(Qt::WA_SetFont)); |
|
831 |
QVERIFY(! three->testAttribute(Qt::WA_SetFont)); |
|
832 |
QVERIFY(! four->testAttribute(Qt::WA_SetFont)); |
|
833 |
||
834 |
font.setPointSize(font.pointSize() + 2); |
|
835 |
two->setFont(font); |
|
836 |
||
837 |
QCOMPARE(two->font(), three->font()); |
|
838 |
QCOMPARE(three->font(), four->font()); |
|
839 |
||
840 |
QVERIFY(two->testAttribute(Qt::WA_SetFont)); |
|
841 |
QVERIFY(! three->testAttribute(Qt::WA_SetFont)); |
|
842 |
QVERIFY(! four->testAttribute(Qt::WA_SetFont)); |
|
843 |
||
844 |
font.setPointSize(font.pointSize() + 2); |
|
845 |
three->setFont(font); |
|
846 |
||
847 |
QCOMPARE(three->font(), four->font()); |
|
848 |
||
849 |
QVERIFY(three->testAttribute(Qt::WA_SetFont)); |
|
850 |
QVERIFY(! four->testAttribute(Qt::WA_SetFont)); |
|
851 |
||
852 |
font.setPointSize(font.pointSize() + 2); |
|
853 |
four->setFont(font); |
|
854 |
||
855 |
QVERIFY(four->testAttribute(Qt::WA_SetFont)); |
|
856 |
} |
|
857 |
||
858 |
class QPropagationTestWidget : public QWidget |
|
859 |
{ |
|
860 |
Q_OBJECT |
|
861 |
public: |
|
862 |
QPropagationTestWidget(QWidget *parent = 0) |
|
863 |
: QWidget(parent) |
|
864 |
{ } |
|
865 |
}; |
|
866 |
||
867 |
void tst_QWidget::fontPropagation2() |
|
868 |
{ |
|
869 |
// ! Note, the code below is executed in tst_QWidget's constructor. |
|
870 |
// QFont font; |
|
871 |
// font.setBold(true); |
|
872 |
// font.setPointSize(42); |
|
873 |
// qApp->setFont(font, "QPropagationTestWidget"); |
|
874 |
||
875 |
QWidget *root = new QWidget; |
|
876 |
QWidget *child0 = new QWidget(root); |
|
877 |
QWidget *child1 = new QWidget(child0); |
|
878 |
QWidget *child2 = new QPropagationTestWidget(child1); |
|
879 |
QWidget *child3 = new QWidget(child2); |
|
880 |
QWidget *child4 = new QWidget(child3); |
|
881 |
QWidget *child5 = new QWidget(child4); |
|
882 |
root->show(); |
|
883 |
||
884 |
// Check that only the application fonts apply. |
|
885 |
QCOMPARE(root->font(), QApplication::font()); |
|
886 |
QCOMPARE(child0->font(), QApplication::font()); |
|
887 |
QCOMPARE(child1->font(), QApplication::font()); |
|
888 |
QCOMPARE(child2->font().pointSize(), 42); |
|
889 |
QVERIFY(child2->font().bold()); |
|
890 |
QCOMPARE(child3->font().pointSize(), 42); |
|
891 |
QVERIFY(child3->font().bold()); |
|
892 |
QCOMPARE(child4->font().pointSize(), 42); |
|
893 |
QVERIFY(child4->font().bold()); |
|
894 |
QCOMPARE(child5->font().pointSize(), 42); |
|
895 |
QVERIFY(child5->font().bold()); |
|
896 |
||
897 |
// Set child0's font size to 15, and remove bold on child4. |
|
898 |
QFont font; |
|
899 |
font.setPointSize(15); |
|
900 |
child0->setFont(font); |
|
901 |
QFont unboldFont; |
|
902 |
unboldFont.setBold(false); |
|
903 |
child4->setFont(unboldFont); |
|
904 |
||
905 |
// Check that the above settings propagate correctly. |
|
906 |
QCOMPARE(root->font(), QApplication::font()); |
|
907 |
QCOMPARE(child0->font().pointSize(), 15); |
|
908 |
QVERIFY(!child0->font().bold()); |
|
909 |
QCOMPARE(child1->font().pointSize(), 15); |
|
910 |
QVERIFY(!child1->font().bold()); |
|
911 |
QCOMPARE(child2->font().pointSize(), 15); |
|
912 |
QVERIFY(child2->font().bold()); |
|
913 |
QCOMPARE(child3->font().pointSize(), 15); |
|
914 |
QVERIFY(child3->font().bold()); |
|
915 |
QCOMPARE(child4->font().pointSize(), 15); |
|
916 |
QVERIFY(!child4->font().bold()); |
|
917 |
QCOMPARE(child5->font().pointSize(), 15); |
|
918 |
QVERIFY(!child5->font().bold()); |
|
919 |
||
920 |
// Replace the app font for child2. Italic should propagate |
|
921 |
// but the size should still be ignored. The previous bold |
|
922 |
// setting is gone. |
|
923 |
QFont italicSizeFont; |
|
924 |
italicSizeFont.setItalic(true); |
|
925 |
italicSizeFont.setPointSize(33); |
|
926 |
qApp->setFont(italicSizeFont, "QPropagationTestWidget"); |
|
927 |
||
928 |
// Check that this propagates correctly. |
|
929 |
QCOMPARE(root->font(), QApplication::font()); |
|
930 |
QCOMPARE(child0->font().pointSize(), 15); |
|
931 |
QVERIFY(!child0->font().bold()); |
|
932 |
QVERIFY(!child0->font().italic()); |
|
933 |
QCOMPARE(child1->font().pointSize(), 15); |
|
934 |
QVERIFY(!child1->font().bold()); |
|
935 |
QVERIFY(!child1->font().italic()); |
|
936 |
QCOMPARE(child2->font().pointSize(), 15); |
|
937 |
QVERIFY(!child2->font().bold()); |
|
938 |
QVERIFY(child2->font().italic()); |
|
939 |
QCOMPARE(child3->font().pointSize(), 15); |
|
940 |
QVERIFY(!child3->font().bold()); |
|
941 |
QVERIFY(child3->font().italic()); |
|
942 |
QCOMPARE(child4->font().pointSize(), 15); |
|
943 |
QVERIFY(!child4->font().bold()); |
|
944 |
QVERIFY(child4->font().italic()); |
|
945 |
QCOMPARE(child5->font().pointSize(), 15); |
|
946 |
QVERIFY(!child5->font().bold()); |
|
947 |
QVERIFY(child5->font().italic()); |
|
948 |
} |
|
949 |
||
950 |
void tst_QWidget::palettePropagation() |
|
951 |
{ |
|
952 |
QPalette palette = testWidget->palette(); |
|
953 |
QWidget* childWidget = new QWidget( testWidget ); |
|
954 |
childWidget->show(); |
|
955 |
QCOMPARE( palette, childWidget->palette() ); |
|
956 |
||
957 |
palette.setColor( QPalette::Base, Qt::red ); |
|
958 |
testWidget->setPalette( palette ); |
|
959 |
QCOMPARE( palette, testWidget->palette() ); |
|
960 |
QCOMPARE( palette, childWidget->palette() ); |
|
961 |
||
962 |
QPalette newPalette = palette; |
|
963 |
newPalette.setColor( QPalette::Highlight, Qt::green ); |
|
964 |
childWidget->setPalette( newPalette ); |
|
965 |
QWidget* grandChildWidget = new QWidget( childWidget ); |
|
966 |
QCOMPARE( palette, testWidget->palette() ); |
|
967 |
QCOMPARE( newPalette, grandChildWidget->palette() ); |
|
968 |
||
969 |
palette.setColor( QPalette::Text, Qt::blue ); |
|
970 |
testWidget->setPalette( palette ); |
|
971 |
||
972 |
// the child and grand child should now have merged green |
|
973 |
// highlight and blue text |
|
974 |
newPalette.setColor( QPalette::Text, Qt::blue); |
|
975 |
||
976 |
QCOMPARE( newPalette, childWidget->palette() ); |
|
977 |
QCOMPARE( newPalette, grandChildWidget->palette() ); |
|
978 |
} |
|
979 |
||
980 |
void tst_QWidget::palettePropagation2() |
|
981 |
{ |
|
982 |
// ! Note, the code below is executed in tst_QWidget's constructor. |
|
983 |
// QPalette palette; |
|
984 |
// font.setColor(QPalette::ToolTipBase, QColor(12, 13, 14)); |
|
985 |
// font.setColor(QPalette::Text, QColor(21, 22, 23)); |
|
986 |
// qApp->setPalette(palette, "QPropagationTestWidget"); |
|
987 |
||
988 |
QWidget *root = new QWidget; |
|
989 |
QWidget *child0 = new QWidget(root); |
|
990 |
QWidget *child1 = new QWidget(child0); |
|
991 |
QWidget *child2 = new QPropagationTestWidget(child1); |
|
992 |
QWidget *child3 = new QWidget(child2); |
|
993 |
QWidget *child4 = new QWidget(child3); |
|
994 |
QWidget *child5 = new QWidget(child4); |
|
995 |
root->show(); |
|
996 |
QTest::qWait(100); |
|
997 |
||
998 |
// These colors are unlikely to be imposed on the default palette of |
|
999 |
// QWidget ;-). |
|
1000 |
QColor sysPalText(21, 22, 23); |
|
1001 |
QColor sysPalToolTipBase(12, 13, 14); |
|
1002 |
QColor overridePalText(42, 43, 44); |
|
1003 |
QColor overridePalToolTipBase(45, 46, 47); |
|
1004 |
QColor sysPalButton(99, 98, 97); |
|
1005 |
||
1006 |
// Check that only the application fonts apply. |
|
1007 |
QPalette appPal = QApplication::palette(); |
|
1008 |
QCOMPARE(root->palette(), appPal); |
|
1009 |
QCOMPARE(child0->palette(), appPal); |
|
1010 |
QCOMPARE(child1->palette(), appPal); |
|
1011 |
QCOMPARE(child2->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); |
|
1012 |
QCOMPARE(child2->palette().color(QPalette::Text), sysPalText); |
|
1013 |
QCOMPARE(child2->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1014 |
QCOMPARE(child3->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); |
|
1015 |
QCOMPARE(child3->palette().color(QPalette::Text), sysPalText); |
|
1016 |
QCOMPARE(child3->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1017 |
QCOMPARE(child4->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); |
|
1018 |
QCOMPARE(child4->palette().color(QPalette::Text), sysPalText); |
|
1019 |
QCOMPARE(child4->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1020 |
QCOMPARE(child5->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); |
|
1021 |
QCOMPARE(child5->palette().color(QPalette::Text), sysPalText); |
|
1022 |
QCOMPARE(child5->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1023 |
||
1024 |
// Set child0's Text, and set ToolTipBase on child4. |
|
1025 |
QPalette textPalette; |
|
1026 |
textPalette.setColor(QPalette::Text, overridePalText); |
|
1027 |
child0->setPalette(textPalette); |
|
1028 |
QPalette toolTipPalette; |
|
1029 |
toolTipPalette.setColor(QPalette::ToolTipBase, overridePalToolTipBase); |
|
1030 |
child4->setPalette(toolTipPalette); |
|
1031 |
||
1032 |
// Check that the above settings propagate correctly. |
|
1033 |
QCOMPARE(root->palette(), appPal); |
|
1034 |
QCOMPARE(child0->palette().color(QPalette::Text), overridePalText); |
|
1035 |
QCOMPARE(child0->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); |
|
1036 |
QCOMPARE(child0->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1037 |
QCOMPARE(child1->palette().color(QPalette::Text), overridePalText); |
|
1038 |
QCOMPARE(child1->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); |
|
1039 |
QCOMPARE(child1->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1040 |
QCOMPARE(child2->palette().color(QPalette::Text), overridePalText); |
|
1041 |
QCOMPARE(child2->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); |
|
1042 |
QCOMPARE(child2->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1043 |
QCOMPARE(child3->palette().color(QPalette::Text), overridePalText); |
|
1044 |
QCOMPARE(child3->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); |
|
1045 |
QCOMPARE(child3->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1046 |
QCOMPARE(child4->palette().color(QPalette::Text), overridePalText); |
|
1047 |
QCOMPARE(child4->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); |
|
1048 |
QCOMPARE(child4->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1049 |
QCOMPARE(child5->palette().color(QPalette::Text), overridePalText); |
|
1050 |
QCOMPARE(child5->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); |
|
1051 |
QCOMPARE(child5->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1052 |
||
1053 |
// Replace the app palette for child2. Button should propagate but Text |
|
1054 |
// should still be ignored. The previous ToolTipBase setting is gone. |
|
1055 |
QPalette buttonPalette; |
|
1056 |
buttonPalette.setColor(QPalette::ToolTipText, sysPalButton); |
|
1057 |
qApp->setPalette(buttonPalette, "QPropagationTestWidget"); |
|
1058 |
||
1059 |
// Check that the above settings propagate correctly. |
|
1060 |
QCOMPARE(root->palette(), appPal); |
|
1061 |
QCOMPARE(child0->palette().color(QPalette::Text), overridePalText); |
|
1062 |
QCOMPARE(child0->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); |
|
1063 |
QCOMPARE(child0->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1064 |
QCOMPARE(child1->palette().color(QPalette::Text), overridePalText); |
|
1065 |
QCOMPARE(child1->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); |
|
1066 |
QCOMPARE(child1->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1067 |
QCOMPARE(child2->palette().color(QPalette::Text), overridePalText); |
|
1068 |
QCOMPARE(child2->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); |
|
1069 |
QCOMPARE(child2->palette().color(QPalette::ToolTipText), sysPalButton); |
|
1070 |
QCOMPARE(child3->palette().color(QPalette::Text), overridePalText); |
|
1071 |
QCOMPARE(child3->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); |
|
1072 |
QCOMPARE(child3->palette().color(QPalette::ToolTipText), sysPalButton); |
|
1073 |
QCOMPARE(child4->palette().color(QPalette::Text), overridePalText); |
|
1074 |
QCOMPARE(child4->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); |
|
1075 |
QCOMPARE(child4->palette().color(QPalette::ToolTipText), sysPalButton); |
|
1076 |
QCOMPARE(child5->palette().color(QPalette::Text), overridePalText); |
|
1077 |
QCOMPARE(child5->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); |
|
1078 |
QCOMPARE(child5->palette().color(QPalette::ToolTipText), sysPalButton); |
|
1079 |
} |
|
1080 |
||
1081 |
void tst_QWidget::enabledPropagation() |
|
1082 |
{ |
|
1083 |
QWidget* childWidget = new QWidget( testWidget ); |
|
1084 |
childWidget->show(); |
|
1085 |
QVERIFY( testWidget->isEnabled() ); |
|
1086 |
QVERIFY( childWidget->isEnabled() ); |
|
1087 |
||
1088 |
testWidget->setEnabled( FALSE ); |
|
1089 |
QVERIFY( !testWidget->isEnabled() ); |
|
1090 |
QVERIFY( !childWidget->isEnabled() ); |
|
1091 |
||
1092 |
testWidget->setDisabled( FALSE ); |
|
1093 |
QVERIFY( testWidget->isEnabled() ); |
|
1094 |
QVERIFY( childWidget->isEnabled() ); |
|
1095 |
||
1096 |
QWidget* grandChildWidget = new QWidget( childWidget ); |
|
1097 |
QVERIFY( grandChildWidget->isEnabled() ); |
|
1098 |
||
1099 |
testWidget->setDisabled( TRUE ); |
|
1100 |
QVERIFY( !testWidget->isEnabled() ); |
|
1101 |
QVERIFY( !childWidget->isEnabled() ); |
|
1102 |
QVERIFY( !grandChildWidget->isEnabled() ); |
|
1103 |
||
1104 |
grandChildWidget->setEnabled( FALSE ); |
|
1105 |
testWidget->setEnabled( TRUE ); |
|
1106 |
QVERIFY( testWidget->isEnabled() ); |
|
1107 |
QVERIFY( childWidget->isEnabled() ); |
|
1108 |
QVERIFY( !grandChildWidget->isEnabled() ); |
|
1109 |
||
1110 |
grandChildWidget->setEnabled( TRUE ); |
|
1111 |
testWidget->setEnabled( FALSE ); |
|
1112 |
childWidget->setDisabled( TRUE ); |
|
1113 |
testWidget->setEnabled( TRUE ); |
|
1114 |
QVERIFY( testWidget->isEnabled() ); |
|
1115 |
QVERIFY( !childWidget->isEnabled() ); |
|
1116 |
QVERIFY( !grandChildWidget->isEnabled() ); |
|
1117 |
} |
|
1118 |
||
1119 |
void tst_QWidget::acceptDropsPropagation() |
|
1120 |
{ |
|
1121 |
#ifdef QT_NO_DRAGANDDROP |
|
1122 |
QSKIP("Drag'n drop disabled in this build", SkipAll); |
|
1123 |
#else |
|
1124 |
QWidget *childWidget = new QWidget(testWidget); |
|
1125 |
childWidget->show(); |
|
1126 |
QVERIFY(!testWidget->acceptDrops()); |
|
1127 |
QVERIFY(!childWidget->acceptDrops()); |
|
1128 |
||
1129 |
testWidget->setAcceptDrops(true); |
|
1130 |
QVERIFY(testWidget->acceptDrops()); |
|
1131 |
QVERIFY(!childWidget->acceptDrops()); |
|
1132 |
QVERIFY(childWidget->testAttribute(Qt::WA_DropSiteRegistered)); |
|
1133 |
||
1134 |
testWidget->setAcceptDrops(false); |
|
1135 |
QVERIFY(!testWidget->acceptDrops()); |
|
1136 |
QVERIFY(!childWidget->acceptDrops()); |
|
1137 |
QVERIFY(!childWidget->testAttribute(Qt::WA_DropSiteRegistered)); |
|
1138 |
||
1139 |
QWidget *grandChildWidget = new QWidget(childWidget); |
|
1140 |
QVERIFY(!grandChildWidget->acceptDrops()); |
|
1141 |
QVERIFY(!grandChildWidget->testAttribute(Qt::WA_DropSiteRegistered)); |
|
1142 |
||
1143 |
testWidget->setAcceptDrops(true); |
|
1144 |
QVERIFY(testWidget->acceptDrops()); |
|
1145 |
QVERIFY(!childWidget->acceptDrops()); |
|
1146 |
QVERIFY(childWidget->testAttribute(Qt::WA_DropSiteRegistered)); |
|
1147 |
QVERIFY(!grandChildWidget->acceptDrops()); |
|
1148 |
QVERIFY(grandChildWidget->testAttribute(Qt::WA_DropSiteRegistered)); |
|
1149 |
||
1150 |
grandChildWidget->setAcceptDrops(true); |
|
1151 |
testWidget->setAcceptDrops(false); |
|
1152 |
QVERIFY(!testWidget->acceptDrops()); |
|
1153 |
QVERIFY(!childWidget->acceptDrops()); |
|
1154 |
QVERIFY(grandChildWidget->acceptDrops()); |
|
1155 |
QVERIFY(grandChildWidget->testAttribute(Qt::WA_DropSiteRegistered)); |
|
1156 |
||
1157 |
||
1158 |
grandChildWidget->setAcceptDrops(false); |
|
1159 |
QVERIFY(!grandChildWidget->testAttribute(Qt::WA_DropSiteRegistered)); |
|
1160 |
testWidget->setAcceptDrops(true); |
|
1161 |
childWidget->setAcceptDrops(true); |
|
1162 |
testWidget->setAcceptDrops(false); |
|
1163 |
QVERIFY(!testWidget->acceptDrops()); |
|
1164 |
QVERIFY(childWidget->acceptDrops()); |
|
1165 |
QVERIFY(!grandChildWidget->acceptDrops()); |
|
1166 |
QVERIFY(grandChildWidget->testAttribute(Qt::WA_DropSiteRegistered)); |
|
1167 |
#endif |
|
1168 |
} |
|
1169 |
||
1170 |
void tst_QWidget::isEnabledTo() |
|
1171 |
{ |
|
1172 |
QWidget* childWidget = new QWidget( testWidget ); |
|
1173 |
QWidget* grandChildWidget = new QWidget( childWidget ); |
|
1174 |
||
1175 |
QVERIFY( childWidget->isEnabledTo( testWidget ) ); |
|
1176 |
QVERIFY( grandChildWidget->isEnabledTo( testWidget ) ); |
|
1177 |
||
1178 |
childWidget->setEnabled( FALSE ); |
|
1179 |
QVERIFY( !childWidget->isEnabledTo( testWidget ) ); |
|
1180 |
QVERIFY( grandChildWidget->isEnabledTo( childWidget ) ); |
|
1181 |
QVERIFY( !grandChildWidget->isEnabledTo( testWidget ) ); |
|
1182 |
} |
|
1183 |
||
1184 |
void tst_QWidget::visible() |
|
1185 |
{ |
|
1186 |
// Ensure that the testWidget is hidden for this test at the |
|
1187 |
// start |
|
1188 |
||
1189 |
testWidget->hide(); |
|
1190 |
QVERIFY( !testWidget->isVisible() ); |
|
1191 |
QWidget* childWidget = new QWidget( testWidget ); |
|
1192 |
QVERIFY( !childWidget->isVisible() ); |
|
1193 |
||
1194 |
testWidget->show(); |
|
1195 |
QVERIFY( testWidget->isVisible() ); |
|
1196 |
QVERIFY( childWidget->isVisible() ); |
|
1197 |
||
1198 |
QWidget* grandChildWidget = new QWidget( childWidget ); |
|
1199 |
QVERIFY( !grandChildWidget->isVisible() ); |
|
1200 |
grandChildWidget->show(); |
|
1201 |
QVERIFY( grandChildWidget->isVisible() ); |
|
1202 |
||
1203 |
grandChildWidget->hide(); |
|
1204 |
testWidget->hide(); |
|
1205 |
testWidget->show(); |
|
1206 |
QVERIFY( !grandChildWidget->isVisible() ); |
|
1207 |
QVERIFY( testWidget->isVisible() ); |
|
1208 |
QVERIFY( childWidget->isVisible() ); |
|
1209 |
||
1210 |
grandChildWidget->show(); |
|
1211 |
childWidget->hide(); |
|
1212 |
testWidget->hide(); |
|
1213 |
testWidget->show(); |
|
1214 |
QVERIFY( testWidget->isVisible() ); |
|
1215 |
QVERIFY( !childWidget->isVisible() ); |
|
1216 |
QVERIFY( !grandChildWidget->isVisible() ); |
|
1217 |
||
1218 |
grandChildWidget->show(); |
|
1219 |
QVERIFY( !grandChildWidget->isVisible() ); |
|
1220 |
} |
|
1221 |
||
1222 |
void tst_QWidget::setLocale() |
|
1223 |
{ |
|
1224 |
QWidget w; |
|
1225 |
QCOMPARE(w.locale(), QLocale()); |
|
1226 |
||
1227 |
w.setLocale(QLocale::Italian); |
|
1228 |
QCOMPARE(w.locale(), QLocale(QLocale::Italian)); |
|
1229 |
||
1230 |
QWidget child1(&w); |
|
1231 |
QCOMPARE(child1.locale(), QLocale(QLocale::Italian)); |
|
1232 |
||
1233 |
w.unsetLocale(); |
|
1234 |
QCOMPARE(w.locale(), QLocale()); |
|
1235 |
QCOMPARE(child1.locale(), QLocale()); |
|
1236 |
||
1237 |
w.setLocale(QLocale::French); |
|
1238 |
QCOMPARE(w.locale(), QLocale(QLocale::French)); |
|
1239 |
QCOMPARE(child1.locale(), QLocale(QLocale::French)); |
|
1240 |
||
1241 |
child1.setLocale(QLocale::Italian); |
|
1242 |
QCOMPARE(w.locale(), QLocale(QLocale::French)); |
|
1243 |
QCOMPARE(child1.locale(), QLocale(QLocale::Italian)); |
|
1244 |
||
1245 |
child1.unsetLocale(); |
|
1246 |
QCOMPARE(w.locale(), QLocale(QLocale::French)); |
|
1247 |
QCOMPARE(child1.locale(), QLocale(QLocale::French)); |
|
1248 |
||
1249 |
QWidget child2; |
|
1250 |
QCOMPARE(child2.locale(), QLocale()); |
|
1251 |
child2.setParent(&w); |
|
1252 |
QCOMPARE(child2.locale(), QLocale(QLocale::French)); |
|
1253 |
} |
|
1254 |
||
1255 |
void tst_QWidget::visible_setWindowOpacity() |
|
1256 |
{ |
|
1257 |
testWidget->hide(); |
|
1258 |
QVERIFY( !testWidget->isVisible() ); |
|
1259 |
testWidget->setWindowOpacity(0.5); |
|
1260 |
#ifdef Q_OS_WIN |
|
1261 |
QVERIFY(::IsWindowVisible(testWidget->winId()) == FALSE); |
|
1262 |
#endif |
|
1263 |
testWidget->setWindowOpacity(1.0); |
|
1264 |
} |
|
1265 |
||
1266 |
void tst_QWidget::isVisibleTo() |
|
1267 |
{ |
|
1268 |
// Ensure that the testWidget is hidden for this test at the |
|
1269 |
// start |
|
1270 |
||
1271 |
testWidget->hide(); |
|
1272 |
QWidget* childWidget = new QWidget( testWidget ); |
|
1273 |
QVERIFY( childWidget->isVisibleTo( testWidget ) ); |
|
1274 |
childWidget->hide(); |
|
1275 |
QVERIFY( !childWidget->isVisibleTo( testWidget ) ); |
|
1276 |
||
1277 |
QWidget* grandChildWidget = new QWidget( childWidget ); |
|
1278 |
QVERIFY( !grandChildWidget->isVisibleTo( testWidget ) ); |
|
1279 |
QVERIFY( grandChildWidget->isVisibleTo( childWidget ) ); |
|
1280 |
||
1281 |
testWidget->show(); |
|
1282 |
childWidget->show(); |
|
1283 |
||
1284 |
QVERIFY( childWidget->isVisibleTo( testWidget ) ); |
|
1285 |
grandChildWidget->hide(); |
|
1286 |
QVERIFY( !grandChildWidget->isVisibleTo( childWidget ) ); |
|
1287 |
QVERIFY( !grandChildWidget->isVisibleTo( testWidget ) ); |
|
1288 |
||
1289 |
} |
|
1290 |
||
1291 |
void tst_QWidget::isHidden() |
|
1292 |
{ |
|
1293 |
// Ensure that the testWidget is hidden for this test at the |
|
1294 |
// start |
|
1295 |
||
1296 |
testWidget->hide(); |
|
1297 |
QVERIFY( testWidget->isHidden() ); |
|
1298 |
QWidget* childWidget = new QWidget( testWidget ); |
|
1299 |
QVERIFY( !childWidget->isHidden() ); |
|
1300 |
||
1301 |
testWidget->show(); |
|
1302 |
QVERIFY( !testWidget->isHidden() ); |
|
1303 |
QVERIFY( !childWidget->isHidden() ); |
|
1304 |
||
1305 |
QWidget* grandChildWidget = new QWidget( childWidget ); |
|
1306 |
QVERIFY( grandChildWidget->isHidden() ); |
|
1307 |
grandChildWidget->show(); |
|
1308 |
QVERIFY( !grandChildWidget->isHidden() ); |
|
1309 |
||
1310 |
grandChildWidget->hide(); |
|
1311 |
testWidget->hide(); |
|
1312 |
testWidget->show(); |
|
1313 |
QVERIFY( grandChildWidget->isHidden() ); |
|
1314 |
QVERIFY( !testWidget->isHidden() ); |
|
1315 |
QVERIFY( !childWidget->isHidden() ); |
|
1316 |
||
1317 |
grandChildWidget->show(); |
|
1318 |
childWidget->hide(); |
|
1319 |
testWidget->hide(); |
|
1320 |
testWidget->show(); |
|
1321 |
QVERIFY( !testWidget->isHidden() ); |
|
1322 |
QVERIFY( childWidget->isHidden() ); |
|
1323 |
QVERIFY( !grandChildWidget->isHidden() ); |
|
1324 |
||
1325 |
grandChildWidget->show(); |
|
1326 |
QVERIFY( !grandChildWidget->isHidden() ); |
|
1327 |
} |
|
1328 |
||
1329 |
void tst_QWidget::fonts() |
|
1330 |
{ |
|
1331 |
// Tests setFont(), ownFont() and unsetFont() |
|
1332 |
QWidget* cleanTestWidget = new QWidget( testWidget ); |
|
1333 |
QFont originalFont = cleanTestWidget->font(); |
|
1334 |
||
1335 |
QVERIFY( !cleanTestWidget->testAttribute(Qt::WA_SetFont) ); |
|
1336 |
cleanTestWidget->setFont(QFont()); |
|
1337 |
QVERIFY( !cleanTestWidget->testAttribute(Qt::WA_SetFont) ); |
|
1338 |
||
1339 |
QFont newFont( "times", 18 ); |
|
1340 |
cleanTestWidget->setFont( newFont ); |
|
1341 |
newFont = newFont.resolve( testWidget->font() ); |
|
1342 |
||
1343 |
QVERIFY( cleanTestWidget->testAttribute(Qt::WA_SetFont) ); |
|
1344 |
QVERIFY( cleanTestWidget->font() == newFont ); |
|
1345 |
||
1346 |
cleanTestWidget->setFont(QFont()); |
|
1347 |
QVERIFY( !cleanTestWidget->testAttribute(Qt::WA_SetFont) ); |
|
1348 |
QVERIFY( cleanTestWidget->font() == originalFont ); |
|
1349 |
} |
|
1350 |
||
1351 |
void tst_QWidget::mapToGlobal() |
|
1352 |
{ |
|
1353 |
#if !defined(QT3_SUPPORT) |
|
1354 |
QSKIP("No Qt3 Support", SkipAll); |
|
1355 |
#else |
|
1356 |
QPoint vis = testWidget->mapToGlobal(QPoint(0,0)); |
|
1357 |
testWidget->hide(); |
|
1358 |
QCOMPARE(testWidget->mapToGlobal(QPoint(0,0)), vis); |
|
1359 |
testWidget->show(); |
|
1360 |
||
1361 |
// test in a layout and witha move |
|
1362 |
Q3HBox * qhb = new Q3HBox(testWidget); |
|
1363 |
QWidget * qw = new QWidget(qhb); |
|
1364 |
qw->move(6,12); |
|
1365 |
QPoint wVis = qw->mapToGlobal(QPoint(0,0)); |
|
1366 |
qw->hide(); |
|
1367 |
QCOMPARE(qw->mapToGlobal(QPoint(0,0)), wVis); |
|
1368 |
delete qhb; |
|
1369 |
#endif // QT3_SUPPORT |
|
1370 |
} |
|
1371 |
||
1372 |
void tst_QWidget::mapFromAndTo_data() |
|
1373 |
{ |
|
1374 |
QTest::addColumn<bool>("windowHidden"); |
|
1375 |
QTest::addColumn<bool>("subWindow1Hidden"); |
|
1376 |
QTest::addColumn<bool>("subWindow2Hidden"); |
|
1377 |
QTest::addColumn<bool>("subSubWindowHidden"); |
|
1378 |
QTest::addColumn<bool>("windowMinimized"); |
|
1379 |
QTest::addColumn<bool>("subWindow1Minimized"); |
|
1380 |
||
1381 |
QTest::newRow("window 1 sub1 1 sub2 1 subsub 1") << false << false << false << false << false << false; |
|
1382 |
QTest::newRow("window 0 sub1 1 sub2 1 subsub 1") << true << false << false << false << false << false; |
|
1383 |
QTest::newRow("window 1 sub1 0 sub2 1 subsub 1") << false << true << false << false << false << false; |
|
1384 |
QTest::newRow("window 0 sub1 0 sub2 1 subsub 1") << true << true << false << false << false << false; |
|
1385 |
QTest::newRow("window 1 sub1 1 sub2 0 subsub 1") << false << false << true << false << false << false; |
|
1386 |
QTest::newRow("window 0 sub1 1 sub2 0 subsub 1") << true << false << true << false << false << false; |
|
1387 |
QTest::newRow("window 1 sub1 0 sub2 0 subsub 1") << false << true << true << false << false << false; |
|
1388 |
QTest::newRow("window 0 sub1 0 sub2 0 subsub 1") << true << true << true << false << false << false; |
|
1389 |
QTest::newRow("window 1 sub1 1 sub2 1 subsub 0") << false << false << false << true << false << false; |
|
1390 |
QTest::newRow("window 0 sub1 1 sub2 1 subsub 0") << true << false << false << true << false << false; |
|
1391 |
QTest::newRow("window 1 sub1 0 sub2 1 subsub 0") << false << true << false << true << false << false; |
|
1392 |
QTest::newRow("window 0 sub1 0 sub2 1 subsub 0") << true << true << false << true << false << false; |
|
1393 |
QTest::newRow("window 1 sub1 1 sub2 0 subsub 0") << false << false << true << true << false << false; |
|
1394 |
QTest::newRow("window 0 sub1 1 sub2 0 subsub 0") << true << false << true << true << false << false; |
|
1395 |
QTest::newRow("window 1 sub1 0 sub2 0 subsub 0") << false << true << true << true << false << false; |
|
1396 |
QTest::newRow("window 0 sub1 0 sub2 0 subsub 0") << true << true << true << true << false << false; |
|
1397 |
QTest::newRow("window 1 sub1 1 sub2 1 subsub 1 windowMinimized") << false << false << false << false << true << false; |
|
1398 |
QTest::newRow("window 0 sub1 1 sub2 1 subsub 1 windowMinimized") << true << false << false << false << true << false; |
|
1399 |
QTest::newRow("window 1 sub1 0 sub2 1 subsub 1 windowMinimized") << false << true << false << false << true << false; |
|
1400 |
QTest::newRow("window 0 sub1 0 sub2 1 subsub 1 windowMinimized") << true << true << false << false << true << false; |
|
1401 |
QTest::newRow("window 1 sub1 1 sub2 0 subsub 1 windowMinimized") << false << false << true << false << true << false; |
|
1402 |
QTest::newRow("window 0 sub1 1 sub2 0 subsub 1 windowMinimized") << true << false << true << false << true << false; |
|
1403 |
QTest::newRow("window 1 sub1 0 sub2 0 subsub 1 windowMinimized") << false << true << true << false << true << false; |
|
1404 |
QTest::newRow("window 0 sub1 0 sub2 0 subsub 1 windowMinimized") << true << true << true << false << true << false; |
|
1405 |
QTest::newRow("window 1 sub1 1 sub2 1 subsub 0 windowMinimized") << false << false << false << true << true << false; |
|
1406 |
QTest::newRow("window 0 sub1 1 sub2 1 subsub 0 windowMinimized") << true << false << false << true << true << false; |
|
1407 |
QTest::newRow("window 1 sub1 0 sub2 1 subsub 0 windowMinimized") << false << true << false << true << true << false; |
|
1408 |
QTest::newRow("window 0 sub1 0 sub2 1 subsub 0 windowMinimized") << true << true << false << true << true << false; |
|
1409 |
QTest::newRow("window 1 sub1 1 sub2 0 subsub 0 windowMinimized") << false << false << true << true << true << false; |
|
1410 |
QTest::newRow("window 0 sub1 1 sub2 0 subsub 0 windowMinimized") << true << false << true << true << true << false; |
|
1411 |
QTest::newRow("window 1 sub1 0 sub2 0 subsub 0 windowMinimized") << false << true << true << true << true << false; |
|
1412 |
QTest::newRow("window 0 sub1 0 sub2 0 subsub 0 windowMinimized") << true << true << true << true << true << false; |
|
1413 |
QTest::newRow("window 1 sub1 1 sub2 1 subsub 1 subWindow1Minimized") << false << false << false << false << false << true; |
|
1414 |
QTest::newRow("window 0 sub1 1 sub2 1 subsub 1 subWindow1Minimized") << true << false << false << false << false << true; |
|
1415 |
QTest::newRow("window 1 sub1 0 sub2 1 subsub 1 subWindow1Minimized") << false << true << false << false << false << true; |
|
1416 |
QTest::newRow("window 0 sub1 0 sub2 1 subsub 1 subWindow1Minimized") << true << true << false << false << false << true; |
|
1417 |
QTest::newRow("window 1 sub1 1 sub2 0 subsub 1 subWindow1Minimized") << false << false << true << false << false << true; |
|
1418 |
QTest::newRow("window 0 sub1 1 sub2 0 subsub 1 subWindow1Minimized") << true << false << true << false << false << true; |
|
1419 |
QTest::newRow("window 1 sub1 0 sub2 0 subsub 1 subWindow1Minimized") << false << true << true << false << false << true; |
|
1420 |
QTest::newRow("window 0 sub1 0 sub2 0 subsub 1 subWindow1Minimized") << true << true << true << false << false << true; |
|
1421 |
QTest::newRow("window 1 sub1 1 sub2 1 subsub 0 subWindow1Minimized") << false << false << false << true << false << true; |
|
1422 |
QTest::newRow("window 0 sub1 1 sub2 1 subsub 0 subWindow1Minimized") << true << false << false << true << false << true; |
|
1423 |
QTest::newRow("window 1 sub1 0 sub2 1 subsub 0 subWindow1Minimized") << false << true << false << true << false << true; |
|
1424 |
QTest::newRow("window 0 sub1 0 sub2 1 subsub 0 subWindow1Minimized") << true << true << false << true << false << true; |
|
1425 |
QTest::newRow("window 1 sub1 1 sub2 0 subsub 0 subWindow1Minimized") << false << false << true << true << false << true; |
|
1426 |
QTest::newRow("window 0 sub1 1 sub2 0 subsub 0 subWindow1Minimized") << true << false << true << true << false << true; |
|
1427 |
QTest::newRow("window 1 sub1 0 sub2 0 subsub 0 subWindow1Minimized") << false << true << true << true << false << true; |
|
1428 |
QTest::newRow("window 0 sub1 0 sub2 0 subsub 0 subWindow1Minimized") << true << true << true << true << false << true; |
|
1429 |
||
1430 |
||
1431 |
} |
|
1432 |
||
1433 |
void tst_QWidget::mapFromAndTo() |
|
1434 |
{ |
|
1435 |
QFETCH(bool, windowHidden); |
|
1436 |
QFETCH(bool, subWindow1Hidden); |
|
1437 |
QFETCH(bool, subWindow2Hidden); |
|
1438 |
QFETCH(bool, subSubWindowHidden); |
|
1439 |
QFETCH(bool, windowMinimized); |
|
1440 |
QFETCH(bool, subWindow1Minimized); |
|
1441 |
||
1442 |
// create a toplevel and two overlapping siblings |
|
1443 |
QWidget window; |
|
1444 |
window.setWindowFlags(window.windowFlags() | Qt::X11BypassWindowManagerHint); |
|
1445 |
QWidget *subWindow1 = new QWidget(&window); |
|
1446 |
QWidget *subWindow2 = new QWidget(&window); |
|
1447 |
QWidget *subSubWindow = new QWidget(subWindow1); |
|
1448 |
||
1449 |
// set their geometries |
|
1450 |
window.setGeometry(100, 100, 100, 100); |
|
1451 |
subWindow1->setGeometry(50, 50, 100, 100); |
|
1452 |
subWindow2->setGeometry(75, 75, 100, 100); |
|
1453 |
subSubWindow->setGeometry(10, 10, 10, 10); |
|
1454 |
||
1455 |
#if !defined (Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) //still no proper minimizing |
|
1456 |
//update visibility |
|
1457 |
if (windowMinimized) { |
|
1458 |
if (!windowHidden) { |
|
1459 |
window.showMinimized(); |
|
1460 |
QVERIFY(window.isMinimized()); |
|
1461 |
} |
|
1462 |
} else { |
|
1463 |
window.setVisible(!windowHidden); |
|
1464 |
} |
|
1465 |
if (subWindow1Minimized) { |
|
1466 |
subWindow1->hide(); |
|
1467 |
subWindow1->showMinimized(); |
|
1468 |
QVERIFY(subWindow1->isMinimized()); |
|
1469 |
} else { |
|
1470 |
subWindow1->setVisible(!subWindow1Hidden); |
|
1471 |
} |
|
1472 |
#else |
|
1473 |
Q_UNUSED(windowHidden); |
|
1474 |
Q_UNUSED(subWindow1Hidden); |
|
1475 |
Q_UNUSED(windowMinimized); |
|
1476 |
Q_UNUSED(subWindow1Minimized); |
|
1477 |
#endif |
|
1478 |
||
1479 |
subWindow2->setVisible(!subWindow2Hidden); |
|
1480 |
subSubWindow->setVisible(!subSubWindowHidden); |
|
1481 |
||
1482 |
// window |
|
1483 |
QCOMPARE(window.mapToGlobal(QPoint(0, 0)), QPoint(100, 100)); |
|
1484 |
QCOMPARE(window.mapToGlobal(QPoint(10, 0)), QPoint(110, 100)); |
|
1485 |
QCOMPARE(window.mapToGlobal(QPoint(0, 10)), QPoint(100, 110)); |
|
1486 |
QCOMPARE(window.mapToGlobal(QPoint(-10, 0)), QPoint(90, 100)); |
|
1487 |
QCOMPARE(window.mapToGlobal(QPoint(0, -10)), QPoint(100, 90)); |
|
1488 |
QCOMPARE(window.mapToGlobal(QPoint(100, 100)), QPoint(200, 200)); |
|
1489 |
QCOMPARE(window.mapToGlobal(QPoint(110, 100)), QPoint(210, 200)); |
|
1490 |
QCOMPARE(window.mapToGlobal(QPoint(100, 110)), QPoint(200, 210)); |
|
1491 |
QCOMPARE(window.mapFromGlobal(QPoint(100, 100)), QPoint(0, 0)); |
|
1492 |
QCOMPARE(window.mapFromGlobal(QPoint(110, 100)), QPoint(10, 0)); |
|
1493 |
QCOMPARE(window.mapFromGlobal(QPoint(100, 110)), QPoint(0, 10)); |
|
1494 |
QCOMPARE(window.mapFromGlobal(QPoint(90, 100)), QPoint(-10, 0)); |
|
1495 |
QCOMPARE(window.mapFromGlobal(QPoint(100, 90)), QPoint(0, -10)); |
|
1496 |
QCOMPARE(window.mapFromGlobal(QPoint(200, 200)), QPoint(100, 100)); |
|
1497 |
QCOMPARE(window.mapFromGlobal(QPoint(210, 200)), QPoint(110, 100)); |
|
1498 |
QCOMPARE(window.mapFromGlobal(QPoint(200, 210)), QPoint(100, 110)); |
|
1499 |
QCOMPARE(window.mapToParent(QPoint(0, 0)), QPoint(100, 100)); |
|
1500 |
QCOMPARE(window.mapToParent(QPoint(10, 0)), QPoint(110, 100)); |
|
1501 |
QCOMPARE(window.mapToParent(QPoint(0, 10)), QPoint(100, 110)); |
|
1502 |
QCOMPARE(window.mapToParent(QPoint(-10, 0)), QPoint(90, 100)); |
|
1503 |
QCOMPARE(window.mapToParent(QPoint(0, -10)), QPoint(100, 90)); |
|
1504 |
QCOMPARE(window.mapToParent(QPoint(100, 100)), QPoint(200, 200)); |
|
1505 |
QCOMPARE(window.mapToParent(QPoint(110, 100)), QPoint(210, 200)); |
|
1506 |
QCOMPARE(window.mapToParent(QPoint(100, 110)), QPoint(200, 210)); |
|
1507 |
QCOMPARE(window.mapFromParent(QPoint(100, 100)), QPoint(0, 0)); |
|
1508 |
QCOMPARE(window.mapFromParent(QPoint(110, 100)), QPoint(10, 0)); |
|
1509 |
QCOMPARE(window.mapFromParent(QPoint(100, 110)), QPoint(0, 10)); |
|
1510 |
QCOMPARE(window.mapFromParent(QPoint(90, 100)), QPoint(-10, 0)); |
|
1511 |
QCOMPARE(window.mapFromParent(QPoint(100, 90)), QPoint(0, -10)); |
|
1512 |
QCOMPARE(window.mapFromParent(QPoint(200, 200)), QPoint(100, 100)); |
|
1513 |
QCOMPARE(window.mapFromParent(QPoint(210, 200)), QPoint(110, 100)); |
|
1514 |
QCOMPARE(window.mapFromParent(QPoint(200, 210)), QPoint(100, 110)); |
|
1515 |
||
1516 |
// first subwindow |
|
1517 |
QCOMPARE(subWindow1->mapToGlobal(QPoint(0, 0)), QPoint(150, 150)); |
|
1518 |
QCOMPARE(subWindow1->mapToGlobal(QPoint(10, 0)), QPoint(160, 150)); |
|
1519 |
QCOMPARE(subWindow1->mapToGlobal(QPoint(0, 10)), QPoint(150, 160)); |
|
1520 |
QCOMPARE(subWindow1->mapToGlobal(QPoint(-10, 0)), QPoint(140, 150)); |
|
1521 |
QCOMPARE(subWindow1->mapToGlobal(QPoint(0, -10)), QPoint(150, 140)); |
|
1522 |
QCOMPARE(subWindow1->mapToGlobal(QPoint(100, 100)), QPoint(250, 250)); |
|
1523 |
QCOMPARE(subWindow1->mapToGlobal(QPoint(110, 100)), QPoint(260, 250)); |
|
1524 |
QCOMPARE(subWindow1->mapToGlobal(QPoint(100, 110)), QPoint(250, 260)); |
|
1525 |
QCOMPARE(subWindow1->mapFromGlobal(QPoint(150, 150)), QPoint(0, 0)); |
|
1526 |
QCOMPARE(subWindow1->mapFromGlobal(QPoint(160, 150)), QPoint(10, 0)); |
|
1527 |
QCOMPARE(subWindow1->mapFromGlobal(QPoint(150, 160)), QPoint(0, 10)); |
|
1528 |
QCOMPARE(subWindow1->mapFromGlobal(QPoint(140, 150)), QPoint(-10, 0)); |
|
1529 |
QCOMPARE(subWindow1->mapFromGlobal(QPoint(150, 140)), QPoint(0, -10)); |
|
1530 |
QCOMPARE(subWindow1->mapFromGlobal(QPoint(250, 250)), QPoint(100, 100)); |
|
1531 |
QCOMPARE(subWindow1->mapFromGlobal(QPoint(260, 250)), QPoint(110, 100)); |
|
1532 |
QCOMPARE(subWindow1->mapFromGlobal(QPoint(250, 260)), QPoint(100, 110)); |
|
1533 |
QCOMPARE(subWindow1->mapToParent(QPoint(0, 0)), QPoint(50, 50)); |
|
1534 |
QCOMPARE(subWindow1->mapToParent(QPoint(10, 0)), QPoint(60, 50)); |
|
1535 |
QCOMPARE(subWindow1->mapToParent(QPoint(0, 10)), QPoint(50, 60)); |
|
1536 |
QCOMPARE(subWindow1->mapToParent(QPoint(-10, 0)), QPoint(40, 50)); |
|
1537 |
QCOMPARE(subWindow1->mapToParent(QPoint(0, -10)), QPoint(50, 40)); |
|
1538 |
QCOMPARE(subWindow1->mapToParent(QPoint(100, 100)), QPoint(150, 150)); |
|
1539 |
QCOMPARE(subWindow1->mapToParent(QPoint(110, 100)), QPoint(160, 150)); |
|
1540 |
QCOMPARE(subWindow1->mapToParent(QPoint(100, 110)), QPoint(150, 160)); |
|
1541 |
QCOMPARE(subWindow1->mapFromParent(QPoint(50, 50)), QPoint(0, 0)); |
|
1542 |
QCOMPARE(subWindow1->mapFromParent(QPoint(60, 50)), QPoint(10, 0)); |
|
1543 |
QCOMPARE(subWindow1->mapFromParent(QPoint(50, 60)), QPoint(0, 10)); |
|
1544 |
QCOMPARE(subWindow1->mapFromParent(QPoint(40, 50)), QPoint(-10, 0)); |
|
1545 |
QCOMPARE(subWindow1->mapFromParent(QPoint(50, 40)), QPoint(0, -10)); |
|
1546 |
QCOMPARE(subWindow1->mapFromParent(QPoint(150, 150)), QPoint(100, 100)); |
|
1547 |
QCOMPARE(subWindow1->mapFromParent(QPoint(160, 150)), QPoint(110, 100)); |
|
1548 |
QCOMPARE(subWindow1->mapFromParent(QPoint(150, 160)), QPoint(100, 110)); |
|
1549 |
||
1550 |
// subsubwindow |
|
1551 |
QCOMPARE(subSubWindow->mapToGlobal(QPoint(0, 0)), QPoint(160, 160)); |
|
1552 |
QCOMPARE(subSubWindow->mapToGlobal(QPoint(10, 0)), QPoint(170, 160)); |
|
1553 |
QCOMPARE(subSubWindow->mapToGlobal(QPoint(0, 10)), QPoint(160, 170)); |
|
1554 |
QCOMPARE(subSubWindow->mapToGlobal(QPoint(-10, 0)), QPoint(150, 160)); |
|
1555 |
QCOMPARE(subSubWindow->mapToGlobal(QPoint(0, -10)), QPoint(160, 150)); |
|
1556 |
QCOMPARE(subSubWindow->mapToGlobal(QPoint(100, 100)), QPoint(260, 260)); |
|
1557 |
QCOMPARE(subSubWindow->mapToGlobal(QPoint(110, 100)), QPoint(270, 260)); |
|
1558 |
QCOMPARE(subSubWindow->mapToGlobal(QPoint(100, 110)), QPoint(260, 270)); |
|
1559 |
QCOMPARE(subSubWindow->mapFromGlobal(QPoint(160, 160)), QPoint(0, 0)); |
|
1560 |
QCOMPARE(subSubWindow->mapFromGlobal(QPoint(170, 160)), QPoint(10, 0)); |
|
1561 |
QCOMPARE(subSubWindow->mapFromGlobal(QPoint(160, 170)), QPoint(0, 10)); |
|
1562 |
QCOMPARE(subSubWindow->mapFromGlobal(QPoint(150, 160)), QPoint(-10, 0)); |
|
1563 |
QCOMPARE(subSubWindow->mapFromGlobal(QPoint(160, 150)), QPoint(0, -10)); |
|
1564 |
QCOMPARE(subSubWindow->mapFromGlobal(QPoint(260, 260)), QPoint(100, 100)); |
|
1565 |
QCOMPARE(subSubWindow->mapFromGlobal(QPoint(270, 260)), QPoint(110, 100)); |
|
1566 |
QCOMPARE(subSubWindow->mapFromGlobal(QPoint(260, 270)), QPoint(100, 110)); |
|
1567 |
QCOMPARE(subSubWindow->mapToParent(QPoint(0, 0)), QPoint(10, 10)); |
|
1568 |
QCOMPARE(subSubWindow->mapToParent(QPoint(10, 0)), QPoint(20, 10)); |
|
1569 |
QCOMPARE(subSubWindow->mapToParent(QPoint(0, 10)), QPoint(10, 20)); |
|
1570 |
QCOMPARE(subSubWindow->mapToParent(QPoint(-10, 0)), QPoint(0, 10)); |
|
1571 |
QCOMPARE(subSubWindow->mapToParent(QPoint(0, -10)), QPoint(10, 0)); |
|
1572 |
QCOMPARE(subSubWindow->mapToParent(QPoint(100, 100)), QPoint(110, 110)); |
|
1573 |
QCOMPARE(subSubWindow->mapToParent(QPoint(110, 100)), QPoint(120, 110)); |
|
1574 |
QCOMPARE(subSubWindow->mapToParent(QPoint(100, 110)), QPoint(110, 120)); |
|
1575 |
QCOMPARE(subSubWindow->mapFromParent(QPoint(10, 10)), QPoint(0, 0)); |
|
1576 |
QCOMPARE(subSubWindow->mapFromParent(QPoint(20, 10)), QPoint(10, 0)); |
|
1577 |
QCOMPARE(subSubWindow->mapFromParent(QPoint(10, 20)), QPoint(0, 10)); |
|
1578 |
QCOMPARE(subSubWindow->mapFromParent(QPoint(0, 10)), QPoint(-10, 0)); |
|
1579 |
QCOMPARE(subSubWindow->mapFromParent(QPoint(10, 0)), QPoint(0, -10)); |
|
1580 |
QCOMPARE(subSubWindow->mapFromParent(QPoint(110, 110)), QPoint(100, 100)); |
|
1581 |
QCOMPARE(subSubWindow->mapFromParent(QPoint(120, 110)), QPoint(110, 100)); |
|
1582 |
QCOMPARE(subSubWindow->mapFromParent(QPoint(110, 120)), QPoint(100, 110)); |
|
1583 |
} |
|
1584 |
||
1585 |
void tst_QWidget::focusChainOnReparent() |
|
1586 |
{ |
|
1587 |
QWidget window; |
|
1588 |
QWidget *child1 = new QWidget(&window); |
|
1589 |
QWidget *child2 = new QWidget(&window); |
|
1590 |
QWidget *child3 = new QWidget(&window); |
|
1591 |
QWidget *child21 = new QWidget(child2); |
|
1592 |
QWidget *child22 = new QWidget(child2); |
|
1593 |
QWidget *child4 = new QWidget(&window); |
|
1594 |
||
1595 |
QWidget *expectedOriginalChain[8] = {&window, child1, child2, child3, child21, child22, child4, &window}; |
|
1596 |
QWidget *w = &window; |
|
1597 |
for (int i = 0; i <8; ++i) { |
|
1598 |
QCOMPARE(w, expectedOriginalChain[i]); |
|
1599 |
w = w->nextInFocusChain(); |
|
1600 |
} |
|
1601 |
for (int i = 7; i >= 0; --i) { |
|
1602 |
w = w->previousInFocusChain(); |
|
1603 |
QCOMPARE(w, expectedOriginalChain[i]); |
|
1604 |
} |
|
1605 |
||
1606 |
QWidget window2; |
|
1607 |
child2->setParent(&window2); |
|
1608 |
||
1609 |
QWidget *expectedNewChain[5] = {&window2, child2, child21, child22, &window2}; |
|
1610 |
w = &window2; |
|
1611 |
for (int i = 0; i <5; ++i) { |
|
1612 |
QCOMPARE(w, expectedNewChain[i]); |
|
1613 |
w = w->nextInFocusChain(); |
|
1614 |
} |
|
1615 |
for (int i = 4; i >= 0; --i) { |
|
1616 |
w = w->previousInFocusChain(); |
|
1617 |
QCOMPARE(w, expectedNewChain[i]); |
|
1618 |
} |
|
1619 |
||
1620 |
QWidget *expectedOldChain[5] = {&window, child1, child3, child4, &window}; |
|
1621 |
w = &window; |
|
1622 |
for (int i = 0; i <5; ++i) { |
|
1623 |
QCOMPARE(w, expectedOldChain[i]); |
|
1624 |
w = w->nextInFocusChain(); |
|
1625 |
} |
|
1626 |
for (int i = 4; i >= 0; --i) { |
|
1627 |
w = w->previousInFocusChain(); |
|
1628 |
QCOMPARE(w, expectedOldChain[i]); |
|
1629 |
} |
|
1630 |
} |
|
1631 |
||
1632 |
||
1633 |
void tst_QWidget::focusChainOnHide() |
|
1634 |
{ |
|
1635 |
testWidget->hide(); // We do not want to get disturbed by other widgets |
|
1636 |
// focus should move to the next widget in the focus chain when we hide it. |
|
1637 |
QWidget *parent = new QWidget(); |
|
1638 |
parent->setObjectName(QLatin1String("Parent")); |
|
1639 |
parent->setFocusPolicy(Qt::StrongFocus); |
|
1640 |
QWidget *child = new QWidget(parent); |
|
1641 |
child->setObjectName(QLatin1String("child")); |
|
1642 |
child->setFocusPolicy(Qt::StrongFocus); |
|
1643 |
QWidget::setTabOrder(child, parent); |
|
1644 |
||
1645 |
parent->show(); |
|
1646 |
qApp->setActiveWindow(parent->window()); |
|
1647 |
child->activateWindow(); |
|
1648 |
child->setFocus(); |
|
1649 |
qApp->processEvents(); |
|
1650 |
||
1651 |
WAIT_FOR_CONDITION(child->hasFocus(), true); |
|
1652 |
QCOMPARE(child->hasFocus(), true); |
|
1653 |
child->hide(); |
|
1654 |
qApp->processEvents(); |
|
1655 |
||
1656 |
WAIT_FOR_CONDITION(parent->hasFocus(), true); |
|
1657 |
QCOMPARE(parent->hasFocus(), true); |
|
1658 |
QCOMPARE(parent, qApp->focusWidget()); |
|
1659 |
||
1660 |
delete parent; |
|
1661 |
testWidget->show(); //don't disturb later tests |
|
1662 |
} |
|
1663 |
||
1664 |
void tst_QWidget::checkFocus() |
|
1665 |
{ |
|
1666 |
#if !defined(QT3_SUPPORT) |
|
1667 |
QSKIP("No Qt3 Support", SkipAll); |
|
1668 |
#else |
|
1669 |
// This is a very specific test for a specific bug, the bug was |
|
1670 |
// that when setEnabled(FALSE) then setEnabled(TRUE) was called on |
|
1671 |
// the parent of a child widget which had focus while hidden, then |
|
1672 |
// when the widget was shown, the focus would be in the wrong place. |
|
1673 |
||
1674 |
Q3HBox widget; |
|
1675 |
QLineEdit *focusWidget = new QLineEdit( &widget ); |
|
1676 |
new QLineEdit( &widget ); |
|
1677 |
new QPushButton( &widget ); |
|
1678 |
focusWidget->setFocus(); |
|
1679 |
widget.setEnabled( FALSE ); |
|
1680 |
widget.setEnabled( TRUE ); |
|
1681 |
widget.show(); |
|
1682 |
#ifdef Q_WS_X11 |
|
1683 |
qt_x11_wait_for_window_manager(&widget); |
|
1684 |
#endif |
|
1685 |
QTest::qWait( 100 ); |
|
1686 |
widget.activateWindow(); |
|
1687 |
// next call is necessary since the window manager may not give the focus to the widget when |
|
1688 |
// it is shown, which causes the QVERIFY to fail |
|
1689 |
QApplication::setActiveWindow(&widget); |
|
1690 |
QVERIFY( qApp->focusWidget() == focusWidget ); |
|
1691 |
#endif // QT3_SUPPORT |
|
1692 |
} |
|
1693 |
||
1694 |
class Container : public QWidget |
|
1695 |
{ |
|
1696 |
public: |
|
1697 |
QVBoxLayout* box; |
|
1698 |
||
1699 |
Container() |
|
1700 |
{ |
|
1701 |
box = new QVBoxLayout(this); |
|
1702 |
//(new QVBoxLayout(this))->setAutoAdd(true); |
|
1703 |
} |
|
1704 |
||
1705 |
void tab() |
|
1706 |
{ |
|
1707 |
focusNextPrevChild(TRUE); |
|
1708 |
} |
|
1709 |
||
1710 |
void backTab() |
|
1711 |
{ |
|
1712 |
focusNextPrevChild(FALSE); |
|
1713 |
} |
|
1714 |
}; |
|
1715 |
||
1716 |
class Composite : public QFrame |
|
1717 |
{ |
|
1718 |
public: |
|
1719 |
Composite(QWidget* parent = 0, const char* name = 0) |
|
1720 |
: QFrame(parent) |
|
1721 |
{ |
|
1722 |
setObjectName(name); |
|
1723 |
//QHBoxLayout* hbox = new QHBoxLayout(this, 2, 0); |
|
1724 |
//hbox->setAutoAdd(true); |
|
1725 |
QHBoxLayout* hbox = new QHBoxLayout(this); |
|
1726 |
||
1727 |
lineEdit = new QLineEdit(this); |
|
1728 |
hbox->addWidget(lineEdit); |
|
1729 |
||
1730 |
button = new QPushButton(this); |
|
1731 |
hbox->addWidget(button); |
|
1732 |
button->setFocusPolicy( Qt::NoFocus ); |
|
1733 |
||
1734 |
setFocusProxy( lineEdit ); |
|
1735 |
setFocusPolicy( Qt::StrongFocus ); |
|
1736 |
||
1737 |
setTabOrder(lineEdit, button); |
|
1738 |
} |
|
1739 |
||
1740 |
private: |
|
1741 |
QLineEdit* lineEdit; |
|
1742 |
QPushButton* button; |
|
1743 |
}; |
|
1744 |
||
1745 |
#define NUM_WIDGETS 4 |
|
1746 |
||
1747 |
void tst_QWidget::setTabOrder() |
|
1748 |
{ |
|
1749 |
QTest::qWait(100); |
|
1750 |
||
1751 |
Container container; |
|
1752 |
||
1753 |
Composite* comp[NUM_WIDGETS]; |
|
1754 |
||
1755 |
QLineEdit *firstEdit = new QLineEdit(&container); |
|
1756 |
container.box->addWidget(firstEdit); |
|
1757 |
||
1758 |
int i = 0; |
|
1759 |
for(i = 0; i < NUM_WIDGETS; i++) { |
|
1760 |
comp[i] = new Composite(&container); |
|
1761 |
container.box->addWidget(comp[i]); |
|
1762 |
} |
|
1763 |
||
1764 |
QLineEdit *lastEdit = new QLineEdit(&container); |
|
1765 |
container.box->addWidget(lastEdit); |
|
1766 |
||
1767 |
container.setTabOrder(lastEdit, comp[NUM_WIDGETS-1]); |
|
1768 |
for(i = NUM_WIDGETS-1; i > 0; i--) { |
|
1769 |
container.setTabOrder(comp[i], comp[i-1]); |
|
1770 |
} |
|
1771 |
container.setTabOrder(comp[0], firstEdit); |
|
1772 |
||
1773 |
int current = NUM_WIDGETS-1; |
|
1774 |
lastEdit->setFocus(); |
|
1775 |
||
1776 |
container.show(); |
|
1777 |
container.activateWindow(); |
|
1778 |
qApp->setActiveWindow(&container); |
|
1779 |
#ifdef Q_WS_X11 |
|
1780 |
QTest::qWaitForWindowShown(&container); |
|
1781 |
QTest::qWait(50); |
|
1782 |
#endif |
|
1783 |
||
1784 |
QTest::qWait(100); |
|
1785 |
||
1786 |
QTRY_VERIFY(lastEdit->hasFocus()); |
|
1787 |
container.tab(); |
|
1788 |
do { |
|
1789 |
QVERIFY(comp[current]->focusProxy()->hasFocus()); |
|
1790 |
container.tab(); |
|
1791 |
current--; |
|
1792 |
} while (current >= 0); |
|
1793 |
||
1794 |
QVERIFY(firstEdit->hasFocus()); |
|
1795 |
} |
|
1796 |
||
1797 |
void tst_QWidget::activation() |
|
1798 |
{ |
|
1799 |
#if !defined(Q_WS_WIN) |
|
1800 |
QSKIP("This test is Windows-only.", SkipAll); |
|
1801 |
#endif |
|
1802 |
Q_CHECK_PAINTEVENTS |
|
1803 |
||
1804 |
#if defined(Q_OS_WINCE) |
|
1805 |
int waitTime = 1000; |
|
1806 |
#else |
|
1807 |
int waitTime = 100; |
|
1808 |
#endif |
|
1809 |
||
1810 |
#ifdef Q_OS_WINCE |
|
1811 |
qApp->processEvents(); |
|
1812 |
#endif |
|
1813 |
QWidget widget1; |
|
1814 |
widget1.setWindowTitle("Widget1"); |
|
1815 |
||
1816 |
QWidget widget2; |
|
1817 |
widget2.setWindowTitle("Widget2"); |
|
1818 |
||
1819 |
widget1.show(); |
|
1820 |
widget2.show(); |
|
1821 |
||
1822 |
QTest::qWait(waitTime); |
|
1823 |
QVERIFY(qApp->activeWindow() == &widget2); |
|
1824 |
widget2.showMinimized(); |
|
1825 |
QTest::qWait(waitTime); |
|
1826 |
||
1827 |
QVERIFY(qApp->activeWindow() == &widget1); |
|
1828 |
widget2.showMaximized(); |
|
1829 |
QTest::qWait(waitTime); |
|
1830 |
QVERIFY(qApp->activeWindow() == &widget2); |
|
1831 |
widget2.showMinimized(); |
|
1832 |
QTest::qWait(waitTime); |
|
1833 |
QVERIFY(qApp->activeWindow() == &widget1); |
|
1834 |
widget2.showNormal(); |
|
1835 |
QTest::qWait(waitTime); |
|
1836 |
#if defined(Q_WS_WIN) && !defined(Q_OS_WINCE) |
|
1837 |
if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA) |
|
1838 |
QEXPECT_FAIL("", "MS introduced new behavior after XP", Continue); |
|
1839 |
#endif |
|
1840 |
QTest::qWait(waitTime); |
|
1841 |
QVERIFY(qApp->activeWindow() == &widget2); |
|
1842 |
widget2.hide(); |
|
1843 |
QTest::qWait(waitTime); |
|
1844 |
QVERIFY(qApp->activeWindow() == &widget1); |
|
1845 |
} |
|
1846 |
||
1847 |
void tst_QWidget::windowState() |
|
1848 |
{ |
|
1849 |
#ifdef Q_WS_X11 |
|
1850 |
QSKIP("Many window managers do not support window state properly, which causes this " |
|
1851 |
"test to fail.", SkipAll); |
|
1852 |
#else |
|
1853 |
#ifdef Q_OS_WINCE_WM |
|
1854 |
QPoint pos(500, 500); |
|
1855 |
QSize size(200, 200); |
|
1856 |
if (qt_wince_is_smartphone()) { //small screen |
|
1857 |
pos = QPoint(10,10); |
|
1858 |
size = QSize(100,100); |
|
1859 |
} |
|
1860 |
#elif defined(Q_WS_S60) |
|
1861 |
QPoint pos = QPoint(10,10); |
|
1862 |
QSize size = QSize(100,100); |
|
1863 |
#else |
|
1864 |
const QPoint pos(500, 500); |
|
1865 |
const QSize size(200, 200); |
|
1866 |
#endif |
|
1867 |
||
1868 |
QWidget widget1; |
|
1869 |
widget1.move(pos); |
|
1870 |
widget1.resize(size); |
|
1871 |
QCOMPARE(widget1.pos(), pos); |
|
1872 |
QCOMPARE(widget1.size(), size); |
|
1873 |
QTest::qWait(100); |
|
1874 |
widget1.setWindowTitle("Widget1"); |
|
1875 |
QCOMPARE(widget1.pos(), pos); |
|
1876 |
QCOMPARE(widget1.size(), size); |
|
1877 |
||
1878 |
#define VERIFY_STATE(s) QCOMPARE(int(widget1.windowState() & stateMask), int(s)) |
|
1879 |
||
1880 |
const int stateMask = Qt::WindowMaximized|Qt::WindowMinimized|Qt::WindowFullScreen; |
|
1881 |
||
1882 |
widget1.setWindowState(Qt::WindowMaximized); |
|
1883 |
QTest::qWait(100); |
|
1884 |
VERIFY_STATE(Qt::WindowMaximized); |
|
1885 |
||
1886 |
widget1.show(); |
|
1887 |
QTest::qWait(100); |
|
1888 |
VERIFY_STATE(Qt::WindowMaximized); |
|
1889 |
||
1890 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMaximized); |
|
1891 |
QTest::qWait(100); |
|
1892 |
QVERIFY(!(widget1.windowState() & Qt::WindowMaximized)); |
|
1893 |
QCOMPARE(widget1.pos(), pos); |
|
1894 |
||
1895 |
widget1.setWindowState(Qt::WindowMinimized); |
|
1896 |
QTest::qWait(100); |
|
1897 |
VERIFY_STATE(Qt::WindowMinimized); |
|
1898 |
||
1899 |
widget1.setWindowState(widget1.windowState() | Qt::WindowMaximized); |
|
1900 |
QTest::qWait(100); |
|
1901 |
VERIFY_STATE((Qt::WindowMinimized|Qt::WindowMaximized)); |
|
1902 |
||
1903 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMinimized); |
|
1904 |
QTest::qWait(100); |
|
1905 |
VERIFY_STATE(Qt::WindowMaximized); |
|
1906 |
||
1907 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMaximized); |
|
1908 |
QTest::qWait(100); |
|
1909 |
QVERIFY(!(widget1.windowState() & (Qt::WindowMinimized|Qt::WindowMaximized))); |
|
1910 |
QCOMPARE(widget1.pos(), pos); |
|
1911 |
||
1912 |
widget1.setWindowState(Qt::WindowFullScreen); |
|
1913 |
QTest::qWait(100); |
|
1914 |
VERIFY_STATE(Qt::WindowFullScreen); |
|
1915 |
||
1916 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMinimized); |
|
1917 |
QTest::qWait(100); |
|
1918 |
VERIFY_STATE((Qt::WindowFullScreen|Qt::WindowMinimized)); |
|
1919 |
||
1920 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMinimized); |
|
1921 |
QTest::qWait(100); |
|
1922 |
VERIFY_STATE(Qt::WindowFullScreen); |
|
1923 |
||
1924 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMaximized); |
|
1925 |
QTest::qWait(100); |
|
1926 |
VERIFY_STATE((Qt::WindowFullScreen|Qt::WindowMaximized)); |
|
1927 |
||
1928 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMinimized); |
|
1929 |
QTest::qWait(100); |
|
1930 |
VERIFY_STATE((Qt::WindowFullScreen|Qt::WindowMaximized|Qt::WindowMinimized)); |
|
1931 |
||
1932 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMinimized); |
|
1933 |
QTest::qWait(100); |
|
1934 |
VERIFY_STATE((Qt::WindowFullScreen|Qt::WindowMaximized)); |
|
1935 |
||
1936 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowFullScreen); |
|
1937 |
QTest::qWait(100); |
|
1938 |
VERIFY_STATE(Qt::WindowMaximized); |
|
1939 |
||
1940 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMaximized); |
|
1941 |
QTest::qWait(100); |
|
1942 |
QVERIFY(!(widget1.windowState() & stateMask)); |
|
1943 |
||
1944 |
QCOMPARE(widget1.pos(), pos); |
|
1945 |
QCOMPARE(widget1.size(), size); |
|
1946 |
#endif |
|
1947 |
} |
|
1948 |
||
1949 |
void tst_QWidget::showMaximized() |
|
1950 |
{ |
|
1951 |
QWidget plain; |
|
1952 |
QHBoxLayout *layout; |
|
1953 |
layout = new QHBoxLayout; |
|
1954 |
QWidget layouted; |
|
1955 |
QLineEdit le; |
|
1956 |
QLineEdit le2; |
|
1957 |
QLineEdit le3; |
|
1958 |
||
1959 |
layout->addWidget(&le); |
|
1960 |
layout->addWidget(&le2); |
|
1961 |
layout->addWidget(&le3); |
|
1962 |
||
1963 |
layouted.setLayout(layout); |
|
1964 |
||
1965 |
plain.showMaximized(); |
|
1966 |
QVERIFY(plain.windowState() & Qt::WindowMaximized); |
|
1967 |
||
1968 |
plain.showNormal(); |
|
1969 |
QVERIFY(!(plain.windowState() & Qt::WindowMaximized)); |
|
1970 |
||
1971 |
layouted.showMaximized(); |
|
1972 |
QVERIFY(layouted.windowState() & Qt::WindowMaximized); |
|
1973 |
||
1974 |
layouted.showNormal(); |
|
1975 |
QVERIFY(!(layouted.windowState() & Qt::WindowMaximized)); |
|
1976 |
||
1977 |
#if !defined(Q_WS_QWS) && !defined(Q_OS_WINCE) && !defined(Q_WS_S60) |
|
1978 |
//embedded may choose a different size to fit on the screen. |
|
1979 |
QCOMPARE(layouted.size(), layouted.sizeHint()); |
|
1980 |
#endif |
|
1981 |
layouted.showMaximized(); |
|
1982 |
QVERIFY(layouted.isMaximized()); |
|
1983 |
QVERIFY(layouted.isVisible()); |
|
1984 |
||
1985 |
layouted.hide(); |
|
1986 |
QVERIFY(layouted.isMaximized()); |
|
1987 |
QVERIFY(!layouted.isVisible()); |
|
1988 |
||
1989 |
layouted.showMaximized(); |
|
1990 |
QVERIFY(layouted.isMaximized()); |
|
1991 |
QVERIFY(layouted.isVisible()); |
|
1992 |
||
1993 |
layouted.showMinimized(); |
|
1994 |
QVERIFY(layouted.isMinimized()); |
|
1995 |
QVERIFY(layouted.isMaximized()); |
|
1996 |
||
1997 |
layouted.showMaximized(); |
|
1998 |
QVERIFY(!layouted.isMinimized()); |
|
1999 |
QVERIFY(layouted.isMaximized()); |
|
2000 |
QVERIFY(layouted.isVisible()); |
|
2001 |
||
2002 |
layouted.showMinimized(); |
|
2003 |
QVERIFY(layouted.isMinimized()); |
|
2004 |
QVERIFY(layouted.isMaximized()); |
|
2005 |
||
2006 |
layouted.showMaximized(); |
|
2007 |
QVERIFY(!layouted.isMinimized()); |
|
2008 |
QVERIFY(layouted.isMaximized()); |
|
2009 |
QVERIFY(layouted.isVisible()); |
|
2010 |
||
2011 |
{ |
|
2012 |
QWidget frame; |
|
2013 |
QWidget widget(&frame); |
|
2014 |
widget.showMaximized(); |
|
2015 |
QVERIFY(widget.isMaximized()); |
|
2016 |
} |
|
2017 |
||
2018 |
{ |
|
2019 |
QWidget widget; |
|
2020 |
widget.setGeometry(0, 0, 10, 10); |
|
2021 |
widget.showMaximized(); |
|
2022 |
QTRY_VERIFY(widget.size().width() > 20 && widget.size().height() > 20); |
|
2023 |
} |
|
2024 |
||
2025 |
#ifdef QT3_SUPPORT |
|
2026 |
#if !defined(Q_WS_QWS) |
|
2027 |
//embedded respects max/min sizes by design -- maybe wrong design, but that's the way it is now. |
|
2028 |
{ |
|
2029 |
Q3HBox box; |
|
2030 |
QWidget widget(&box); |
|
2031 |
widget.setMinimumSize(500, 500); |
|
2032 |
box.showMaximized(); |
|
2033 |
QVERIFY(box.isMaximized()); |
|
2034 |
} |
|
2035 |
||
2036 |
{ |
|
2037 |
Q3HBox box; |
|
2038 |
QWidget widget(&box); |
|
2039 |
widget.setMaximumSize(500, 500); |
|
2040 |
||
2041 |
box.showMaximized(); |
|
2042 |
QVERIFY(box.isMaximized()); |
|
2043 |
} |
|
2044 |
#endif |
|
2045 |
#endif // QT3_SUPPORT |
|
2046 |
} |
|
2047 |
||
2048 |
void tst_QWidget::showFullScreen() |
|
2049 |
{ |
|
2050 |
QWidget plain; |
|
2051 |
QHBoxLayout *layout; |
|
2052 |
QWidget layouted; |
|
2053 |
QLineEdit le; |
|
2054 |
QLineEdit le2; |
|
2055 |
QLineEdit le3; |
|
2056 |
layout = new QHBoxLayout; |
|
2057 |
||
2058 |
layout->addWidget(&le); |
|
2059 |
layout->addWidget(&le2); |
|
2060 |
layout->addWidget(&le3); |
|
2061 |
||
2062 |
layouted.setLayout(layout); |
|
2063 |
||
2064 |
plain.showFullScreen(); |
|
2065 |
QVERIFY(plain.windowState() & Qt::WindowFullScreen); |
|
2066 |
||
2067 |
plain.showNormal(); |
|
2068 |
QVERIFY(!(plain.windowState() & Qt::WindowFullScreen)); |
|
2069 |
||
2070 |
layouted.showFullScreen(); |
|
2071 |
QVERIFY(layouted.windowState() & Qt::WindowFullScreen); |
|
2072 |
||
2073 |
layouted.showNormal(); |
|
2074 |
QVERIFY(!(layouted.windowState() & Qt::WindowFullScreen)); |
|
2075 |
||
2076 |
#if !defined(Q_WS_QWS) && !defined(Q_OS_WINCE) && !defined (Q_WS_S60) |
|
2077 |
//embedded may choose a different size to fit on the screen. |
|
2078 |
QCOMPARE(layouted.size(), layouted.sizeHint()); |
|
2079 |
#endif |
|
2080 |
||
2081 |
layouted.showFullScreen(); |
|
2082 |
QVERIFY(layouted.isFullScreen()); |
|
2083 |
QVERIFY(layouted.isVisible()); |
|
2084 |
||
2085 |
layouted.hide(); |
|
2086 |
QVERIFY(layouted.isFullScreen()); |
|
2087 |
QVERIFY(!layouted.isVisible()); |
|
2088 |
||
2089 |
layouted.showFullScreen(); |
|
2090 |
QVERIFY(layouted.isFullScreen()); |
|
2091 |
QVERIFY(layouted.isVisible()); |
|
2092 |
||
2093 |
layouted.showMinimized(); |
|
2094 |
QVERIFY(layouted.isMinimized()); |
|
2095 |
QVERIFY(layouted.isFullScreen()); |
|
2096 |
||
2097 |
layouted.showFullScreen(); |
|
2098 |
QVERIFY(!layouted.isMinimized()); |
|
2099 |
QVERIFY(layouted.isFullScreen()); |
|
2100 |
QVERIFY(layouted.isVisible()); |
|
2101 |
||
2102 |
layouted.showMinimized(); |
|
2103 |
QVERIFY(layouted.isMinimized()); |
|
2104 |
QVERIFY(layouted.isFullScreen()); |
|
2105 |
||
2106 |
layouted.showFullScreen(); |
|
2107 |
QVERIFY(!layouted.isMinimized()); |
|
2108 |
QVERIFY(layouted.isFullScreen()); |
|
2109 |
QVERIFY(layouted.isVisible()); |
|
2110 |
||
2111 |
{ |
|
2112 |
QWidget frame; |
|
2113 |
QWidget widget(&frame); |
|
2114 |
widget.showFullScreen(); |
|
2115 |
QVERIFY(widget.isFullScreen()); |
|
2116 |
} |
|
2117 |
||
2118 |
#ifdef QT3_SUPPORT |
|
2119 |
#if !defined(Q_WS_QWS) |
|
2120 |
//embedded respects max/min sizes by design -- maybe wrong design, but that's the way it is now. |
|
2121 |
{ |
|
2122 |
Q3HBox box; |
|
2123 |
QWidget widget(&box); |
|
2124 |
widget.setMinimumSize(500, 500); |
|
2125 |
box.showFullScreen(); |
|
2126 |
QVERIFY(box.isFullScreen()); |
|
2127 |
} |
|
2128 |
||
2129 |
{ |
|
2130 |
Q3HBox box; |
|
2131 |
QWidget widget(&box); |
|
2132 |
widget.setMaximumSize(500, 500); |
|
2133 |
||
2134 |
box.showFullScreen(); |
|
2135 |
QVERIFY(box.isFullScreen()); |
|
2136 |
} |
|
2137 |
#endif |
|
2138 |
#endif // QT3_SUPPORT |
|
2139 |
} |
|
2140 |
||
2141 |
class ResizeWidget : public QWidget { |
|
2142 |
public: |
|
2143 |
ResizeWidget(QWidget *p = 0) : QWidget(p) |
|
2144 |
{ |
|
2145 |
m_resizeEventCount = 0; |
|
2146 |
} |
|
2147 |
protected: |
|
2148 |
void resizeEvent(QResizeEvent *e){ |
|
2149 |
QCOMPARE(size(), e->size()); |
|
2150 |
++m_resizeEventCount; |
|
2151 |
} |
|
2152 |
||
2153 |
public: |
|
2154 |
int m_resizeEventCount; |
|
2155 |
}; |
|
2156 |
||
2157 |
void tst_QWidget::resizeEvent() |
|
2158 |
{ |
|
2159 |
{ |
|
2160 |
QWidget wParent; |
|
2161 |
ResizeWidget wChild(&wParent); |
|
2162 |
wParent.show(); |
|
2163 |
QCOMPARE (wChild.m_resizeEventCount, 1); // initial resize event before paint |
|
2164 |
wParent.hide(); |
|
2165 |
wChild.resize(QSize(640,480)); |
|
2166 |
QCOMPARE (wChild.m_resizeEventCount, 1); |
|
2167 |
wParent.show(); |
|
2168 |
QCOMPARE (wChild.m_resizeEventCount, 2); |
|
2169 |
} |
|
2170 |
||
2171 |
{ |
|
2172 |
ResizeWidget wTopLevel; |
|
2173 |
wTopLevel.show(); |
|
2174 |
QCOMPARE (wTopLevel.m_resizeEventCount, 1); // initial resize event before paint for toplevels |
|
2175 |
wTopLevel.hide(); |
|
2176 |
wTopLevel.resize(QSize(640,480)); |
|
2177 |
QCOMPARE (wTopLevel.m_resizeEventCount, 1); |
|
2178 |
wTopLevel.show(); |
|
2179 |
QCOMPARE (wTopLevel.m_resizeEventCount, 2); |
|
2180 |
} |
|
2181 |
} |
|
2182 |
||
2183 |
void tst_QWidget::showMinimized() |
|
2184 |
{ |
|
2185 |
QWidget plain; |
|
2186 |
plain.move(100, 100); |
|
2187 |
plain.resize(200, 200); |
|
2188 |
QPoint pos = plain.pos(); |
|
2189 |
||
2190 |
plain.showMinimized(); |
|
2191 |
QVERIFY(plain.isMinimized()); |
|
2192 |
QVERIFY(plain.isVisible()); |
|
2193 |
QCOMPARE(plain.pos(), pos); |
|
2194 |
||
2195 |
plain.showNormal(); |
|
2196 |
QVERIFY(!plain.isMinimized()); |
|
2197 |
QVERIFY(plain.isVisible()); |
|
2198 |
QCOMPARE(plain.pos(), pos); |
|
2199 |
||
2200 |
plain.showMinimized(); |
|
2201 |
QVERIFY(plain.isMinimized()); |
|
2202 |
QVERIFY(plain.isVisible()); |
|
2203 |
QCOMPARE(plain.pos(), pos); |
|
2204 |
||
2205 |
plain.hide(); |
|
2206 |
QVERIFY(plain.isMinimized()); |
|
2207 |
QVERIFY(!plain.isVisible()); |
|
2208 |
||
2209 |
plain.showMinimized(); |
|
2210 |
QVERIFY(plain.isMinimized()); |
|
2211 |
QVERIFY(plain.isVisible()); |
|
2212 |
||
2213 |
plain.setGeometry(200, 200, 300, 300); |
|
2214 |
plain.showNormal(); |
|
2215 |
QCOMPARE(plain.geometry(), QRect(200, 200, 300, 300)); |
|
2216 |
||
2217 |
{ |
|
2218 |
QWidget frame; |
|
2219 |
QWidget widget(&frame); |
|
2220 |
widget.showMinimized(); |
|
2221 |
QVERIFY(widget.isMinimized()); |
|
2222 |
} |
|
2223 |
} |
|
2224 |
||
2225 |
void tst_QWidget::showMinimizedKeepsFocus() |
|
2226 |
{ |
|
2227 |
//here we test that minimizing a widget and restoring it doesn't change the focus inside of it |
|
2228 |
{ |
|
2229 |
QWidget window; |
|
2230 |
QWidget child1(&window), child2(&window); |
|
2231 |
child1.setFocusPolicy(Qt::StrongFocus); |
|
2232 |
child2.setFocusPolicy(Qt::StrongFocus); |
|
2233 |
window.show(); |
|
2234 |
qApp->setActiveWindow(&window); |
|
2235 |
QTest::qWaitForWindowShown(&window); |
|
2236 |
child2.setFocus(); |
|
2237 |
QTest::qWait(50); |
|
2238 |
||
2239 |
QTRY_COMPARE(window.focusWidget(), &child2); |
|
2240 |
QTRY_COMPARE(qApp->focusWidget(), &child2); |
|
2241 |
||
2242 |
window.showMinimized(); |
|
2243 |
QTest::qWait(10); |
|
2244 |
QTRY_VERIFY(window.isMinimized()); |
|
2245 |
QTRY_COMPARE(window.focusWidget(), &child2); |
|
2246 |
||
2247 |
window.showNormal(); |
|
2248 |
QTest::qWait(10); |
|
2249 |
QTRY_COMPARE(window.focusWidget(), &child2); |
|
2250 |
} |
|
2251 |
||
2252 |
//testing deletion of the focusWidget |
|
2253 |
{ |
|
2254 |
QWidget window; |
|
2255 |
QWidget *child = new QWidget(&window); |
|
2256 |
child->setFocusPolicy(Qt::StrongFocus); |
|
2257 |
window.show(); |
|
2258 |
qApp->setActiveWindow(&window); |
|
2259 |
QTest::qWaitForWindowShown(&window); |
|
2260 |
child->setFocus(); |
|
2261 |
QTest::qWait(50); |
|
2262 |
QTRY_COMPARE(window.focusWidget(), child); |
|
2263 |
QTRY_COMPARE(qApp->focusWidget(), child); |
|
2264 |
||
2265 |
delete child; |
|
2266 |
QCOMPARE(window.focusWidget(), static_cast<QWidget*>(0)); |
|
2267 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget*>(0)); |
|
2268 |
} |
|
2269 |
||
2270 |
//testing reparenting the focus widget |
|
2271 |
{ |
|
2272 |
QWidget window; |
|
2273 |
QWidget *child = new QWidget(&window); |
|
2274 |
child->setFocusPolicy(Qt::StrongFocus); |
|
2275 |
window.show(); |
|
2276 |
qApp->setActiveWindow(&window); |
|
2277 |
QTest::qWaitForWindowShown(&window); |
|
2278 |
child->setFocus(); |
|
2279 |
QTest::qWait(50); |
|
2280 |
QTRY_COMPARE(window.focusWidget(), child); |
|
2281 |
QTRY_COMPARE(qApp->focusWidget(), child); |
|
2282 |
||
2283 |
child->setParent(0); |
|
2284 |
QCOMPARE(window.focusWidget(), static_cast<QWidget*>(0)); |
|
2285 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget*>(0)); |
|
2286 |
} |
|
2287 |
||
2288 |
//testing setEnabled(false) |
|
2289 |
{ |
|
2290 |
QWidget window; |
|
2291 |
QWidget *child = new QWidget(&window); |
|
2292 |
child->setFocusPolicy(Qt::StrongFocus); |
|
2293 |
window.show(); |
|
2294 |
qApp->setActiveWindow(&window); |
|
2295 |
QTest::qWaitForWindowShown(&window); |
|
2296 |
child->setFocus(); |
|
2297 |
QTest::qWait(10); |
|
2298 |
QTRY_COMPARE(window.focusWidget(), child); |
|
2299 |
QTRY_COMPARE(qApp->focusWidget(), child); |
|
2300 |
||
2301 |
child->setEnabled(false); |
|
2302 |
QCOMPARE(window.focusWidget(), static_cast<QWidget*>(0)); |
|
2303 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget*>(0)); |
|
2304 |
} |
|
2305 |
||
2306 |
//testing clearFocus |
|
2307 |
{ |
|
2308 |
QWidget window; |
|
2309 |
QWidget *firstchild = new QWidget(&window); |
|
2310 |
firstchild->setFocusPolicy(Qt::StrongFocus); |
|
2311 |
QWidget *child = new QWidget(&window); |
|
2312 |
child->setFocusPolicy(Qt::StrongFocus); |
|
2313 |
window.show(); |
|
2314 |
qApp->setActiveWindow(&window); |
|
2315 |
QTest::qWaitForWindowShown(&window); |
|
2316 |
child->setFocus(); |
|
2317 |
QTest::qWait(10); |
|
2318 |
QTRY_COMPARE(window.focusWidget(), child); |
|
2319 |
QTRY_COMPARE(qApp->focusWidget(), child); |
|
2320 |
||
2321 |
child->clearFocus(); |
|
2322 |
QCOMPARE(window.focusWidget(), static_cast<QWidget*>(0)); |
|
2323 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget*>(0)); |
|
2324 |
||
2325 |
window.showMinimized(); |
|
2326 |
QTest::qWait(30); |
|
2327 |
QTRY_VERIFY(window.isMinimized()); |
|
2328 |
#ifdef Q_WS_QWS |
|
2329 |
QEXPECT_FAIL("", "QWS does not implement showMinimized()", Continue); |
|
2330 |
#endif |
|
2331 |
QCOMPARE(window.focusWidget(), static_cast<QWidget*>(0)); |
|
2332 |
#ifdef Q_WS_QWS |
|
2333 |
QEXPECT_FAIL("", "QWS does not implement showMinimized()", Continue); |
|
2334 |
#endif |
|
2335 |
QTRY_COMPARE(qApp->focusWidget(), static_cast<QWidget*>(0)); |
|
2336 |
||
2337 |
window.showNormal(); |
|
2338 |
qApp->setActiveWindow(&window); |
|
2339 |
QTest::qWaitForWindowShown(&window); |
|
2340 |
QTest::qWait(30); |
|
2341 |
#ifdef Q_WS_MAC |
|
2342 |
if (!macHasAccessToWindowsServer()) |
|
2343 |
QEXPECT_FAIL("", "When not having WindowServer access, we lose focus.", Continue); |
|
2344 |
#endif |
|
2345 |
QTRY_COMPARE(window.focusWidget(), firstchild); |
|
2346 |
#ifdef Q_WS_MAC |
|
2347 |
if (!macHasAccessToWindowsServer()) |
|
2348 |
QEXPECT_FAIL("", "When not having WindowServer access, we lose focus.", Continue); |
|
2349 |
#endif |
|
2350 |
QTRY_COMPARE(qApp->focusWidget(), firstchild); |
|
2351 |
} |
|
2352 |
} |
|
2353 |
||
2354 |
||
2355 |
void tst_QWidget::reparent() |
|
2356 |
{ |
|
2357 |
QWidget parent; |
|
2358 |
parent.setWindowTitle("Toplevel"); |
|
2359 |
parent.setGeometry(300, 300, 200, 150); |
|
2360 |
||
2361 |
QWidget child(0); |
|
2362 |
child.setObjectName("child"); |
|
2363 |
child.setGeometry(10, 10, 180, 130); |
|
2364 |
QPalette pal1; |
|
2365 |
pal1.setColor(child.backgroundRole(), Qt::white); |
|
2366 |
child.setPalette(pal1); |
|
2367 |
||
2368 |
QWidget childTLW(&child, Qt::Window); |
|
2369 |
childTLW.setObjectName("childTLW"); |
|
2370 |
childTLW.setGeometry(100, 100, 50, 50); |
|
2371 |
QPalette pal2; |
|
2372 |
pal2.setColor(childTLW.backgroundRole(), Qt::yellow); |
|
2373 |
childTLW.setPalette(pal2); |
|
2374 |
||
2375 |
parent.show(); |
|
2376 |
childTLW.show(); |
|
2377 |
QTest::qWaitForWindowShown(&parent); |
|
2378 |
||
2379 |
#ifdef Q_OS_WINCE |
|
2380 |
parent.move(50, 50); |
|
2381 |
#else |
|
2382 |
parent.move(300, 300); |
|
2383 |
#endif |
|
2384 |
||
2385 |
QPoint childPos = parent.mapToGlobal(child.pos()); |
|
2386 |
QPoint tlwPos = childTLW.pos(); |
|
2387 |
||
2388 |
child.setParent(0, child.windowFlags() & ~Qt::WindowType_Mask); |
|
2389 |
child.setGeometry(childPos.x(), childPos.y(), child.width(), child.height()); |
|
2390 |
child.show(); |
|
2391 |
||
2392 |
#ifdef Q_WS_X11 |
|
2393 |
// On X11, the window manager will apply NorthWestGravity rules to 'child', which |
|
2394 |
// means the top-left corner of the window frame will be placed at 'childPos', |
|
2395 |
// causing this test to fail |
|
2396 |
#else |
|
2397 |
QCOMPARE(child.geometry().topLeft(), childPos); |
|
2398 |
#endif |
|
2399 |
QTRY_COMPARE(childTLW.pos(), tlwPos); |
|
2400 |
||
2401 |
#ifdef Q_WS_WIN |
|
2402 |
QWidget childTLWChild(&childTLW); |
|
2403 |
childTLWChild.setObjectName("childTLWChild"); |
|
2404 |
||
2405 |
QWidget grandChild(&child); |
|
2406 |
grandChild.setObjectName("grandChild"); |
|
2407 |
grandChild.setGeometry(10, 10, 160, 110); |
|
2408 |
QPalette pal3; |
|
2409 |
pal3.setColor(grandChild.backgroundRole(), Qt::red); |
|
2410 |
grandChild.setPalette(pal3); |
|
2411 |
//grandChild.setPaletteBackgroundColor(Qt::red); |
|
2412 |
||
2413 |
QWidget grandChildTLW(&grandChild, Qt::Window); |
|
2414 |
grandChildTLW.setObjectName("grandChildTLW"); |
|
2415 |
grandChildTLW.setGeometry(200, 200, 50, 50); |
|
2416 |
QPalette pal4; |
|
2417 |
pal4.setColor(grandChildTLW.backgroundRole(), Qt::yellow); |
|
2418 |
grandChildTLW.setPalette(pal4); |
|
2419 |
//grandChildTLW.setPaletteBackgroundColor(Qt::yellow); |
|
2420 |
||
2421 |
QWidget grandChildTLWChild(&grandChildTLW); |
|
2422 |
grandChildTLWChild.setObjectName("grandChildTLWChild"); |
|
2423 |
||
2424 |
QVERIFY(IsWindow(childTLW.winId())); |
|
2425 |
QVERIFY(IsWindow(childTLWChild.winId())); |
|
2426 |
QVERIFY(IsWindow(grandChildTLW.winId())); |
|
2427 |
QVERIFY(IsWindow(grandChildTLWChild.winId())); |
|
2428 |
||
2429 |
parent.show(); |
|
2430 |
||
2431 |
QVERIFY(IsWindow(childTLW.winId())); |
|
2432 |
QVERIFY(IsWindow(childTLWChild.winId())); |
|
2433 |
QVERIFY(IsWindow(grandChildTLW.winId())); |
|
2434 |
QVERIFY(IsWindow(grandChildTLWChild.winId())); |
|
2435 |
||
2436 |
child.setParent(&parent); |
|
2437 |
child.move(10,10); |
|
2438 |
child.show(); |
|
2439 |
||
2440 |
// this appears to stabelize results |
|
2441 |
qApp->processEvents(); |
|
2442 |
||
2443 |
QVERIFY(IsWindow(childTLW.winId())); |
|
2444 |
QVERIFY(IsWindow(childTLWChild.winId())); |
|
2445 |
||
2446 |
QVERIFY(IsWindow(grandChildTLW.winId())); |
|
2447 |
QVERIFY(IsWindow(grandChildTLWChild.winId())); |
|
2448 |
#else |
|
2449 |
QSKIP("This test makes only sense on Windows", SkipAll); |
|
2450 |
#endif |
|
2451 |
} |
|
2452 |
||
2453 |
void tst_QWidget::icon() |
|
2454 |
{ |
|
2455 |
#if defined(Q_WS_QWS) |
|
2456 |
QSKIP("Qt/Embedded does it differently", SkipAll); |
|
2457 |
#else |
|
2458 |
QPixmap p(20,20); |
|
2459 |
p.fill(Qt::red); |
|
2460 |
testWidget->setWindowIcon(p); |
|
2461 |
||
2462 |
QVERIFY(!testWidget->windowIcon().isNull()); |
|
2463 |
testWidget->show(); |
|
2464 |
QVERIFY(!testWidget->windowIcon().isNull()); |
|
2465 |
testWidget->showFullScreen(); |
|
2466 |
QVERIFY(!testWidget->windowIcon().isNull()); |
|
2467 |
testWidget->showNormal(); |
|
2468 |
QVERIFY(!testWidget->windowIcon().isNull()); |
|
2469 |
#endif |
|
2470 |
} |
|
2471 |
||
2472 |
void tst_QWidget::hideWhenFocusWidgetIsChild() |
|
2473 |
{ |
|
2474 |
testWidget->activateWindow(); |
|
2475 |
QWidget *parentWidget = new QWidget(testWidget); |
|
2476 |
parentWidget->setObjectName("parentWidget"); |
|
2477 |
parentWidget->setGeometry(0, 0, 100, 100); |
|
2478 |
QLineEdit *edit = new QLineEdit(parentWidget); |
|
2479 |
edit->setObjectName("edit1"); |
|
2480 |
QLineEdit *edit3 = new QLineEdit(parentWidget); |
|
2481 |
edit3->setObjectName("edit3"); |
|
2482 |
edit3->move(0,50); |
|
2483 |
parentWidget->show(); |
|
2484 |
QLineEdit *edit2 = new QLineEdit(testWidget); |
|
2485 |
edit2->setObjectName("edit2"); |
|
2486 |
edit2->show(); |
|
2487 |
edit2->move(110, 100); |
|
2488 |
edit->setFocus(); |
|
2489 |
qApp->processEvents(); |
|
2490 |
QString actualFocusWidget, expectedFocusWidget; |
|
2491 |
#ifdef Q_WS_X11 |
|
2492 |
if (!qApp->focusWidget()) |
|
2493 |
QSKIP("Your window manager is too broken for this test", SkipAll); |
|
2494 |
#endif |
|
2495 |
QVERIFY(qApp->focusWidget()); |
|
2496 |
actualFocusWidget.sprintf("%p %s %s", qApp->focusWidget(), qApp->focusWidget()->objectName().toLatin1().constData(), qApp->focusWidget()->metaObject()->className()); |
|
2497 |
expectedFocusWidget.sprintf("%p %s %s", edit, edit->objectName().toLatin1().constData(), edit->metaObject()->className()); |
|
2498 |
QCOMPARE(actualFocusWidget, expectedFocusWidget); |
|
2499 |
||
2500 |
parentWidget->hide(); |
|
2501 |
qApp->processEvents(); |
|
2502 |
actualFocusWidget.sprintf("%p %s %s", qApp->focusWidget(), qApp->focusWidget()->objectName().toLatin1().constData(), qApp->focusWidget()->metaObject()->className()); |
|
2503 |
expectedFocusWidget.sprintf("%p %s %s", edit2, edit2->objectName().toLatin1().constData(), edit2->metaObject()->className()); |
|
2504 |
QCOMPARE(actualFocusWidget, expectedFocusWidget); |
|
2505 |
||
2506 |
delete edit2; |
|
2507 |
delete parentWidget; |
|
2508 |
} |
|
2509 |
||
2510 |
void tst_QWidget::normalGeometry() |
|
2511 |
{ |
|
2512 |
#ifdef Q_OS_IRIX |
|
2513 |
QSKIP("4DWM issues on IRIX makes this test fail", SkipAll); |
|
2514 |
#endif |
|
2515 |
QWidget parent; |
|
2516 |
parent.setWindowTitle("NormalGeometry parent"); |
|
2517 |
QWidget *child = new QWidget(&parent); |
|
2518 |
||
2519 |
QCOMPARE(parent.normalGeometry(), parent.geometry()); |
|
2520 |
QCOMPARE(child->normalGeometry(), QRect()); |
|
2521 |
||
2522 |
parent.setGeometry(100, 100, 200, 200); |
|
2523 |
parent.show(); |
|
2524 |
QTest::qWaitForWindowShown(&parent); |
|
2525 |
QApplication::processEvents(); |
|
2526 |
||
2527 |
QRect geom = parent.geometry(); |
|
2528 |
// ### the window manager places the top-left corner at |
|
2529 |
// ### 100,100... making geom something like 102,124 (offset by |
|
2530 |
// ### the frame/frame)... this indicates a rather large different |
|
2531 |
// ### between how X11 and Windows works |
|
2532 |
// QCOMPARE(geom, QRect(100, 100, 200, 200)); |
|
2533 |
QCOMPARE(parent.normalGeometry(), geom); |
|
2534 |
||
2535 |
parent.setWindowState(parent.windowState() ^ Qt::WindowMaximized); |
|
2536 |
QTest::qWait(10); |
|
2537 |
QTRY_VERIFY(parent.windowState() & Qt::WindowMaximized); |
|
2538 |
QTRY_VERIFY(parent.geometry() != geom); |
|
2539 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2540 |
||
2541 |
parent.setWindowState(parent.windowState() ^ Qt::WindowMaximized); |
|
2542 |
QTest::qWait(10); |
|
2543 |
QTRY_VERIFY(!(parent.windowState() & Qt::WindowMaximized)); |
|
2544 |
QTRY_COMPARE(parent.geometry(), geom); |
|
2545 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2546 |
||
2547 |
parent.showMaximized(); |
|
2548 |
QTest::qWait(10); |
|
2549 |
QTRY_VERIFY(parent.windowState() & Qt::WindowMaximized); |
|
2550 |
QTRY_VERIFY(parent.geometry() != geom); |
|
2551 |
QCOMPARE(parent.normalGeometry(), geom); |
|
2552 |
||
2553 |
parent.showNormal(); |
|
2554 |
QTest::qWait(10); |
|
2555 |
QTRY_VERIFY(!(parent.windowState() & Qt::WindowMaximized)); |
|
2556 |
QTRY_COMPARE(parent.geometry(), geom); |
|
2557 |
QCOMPARE(parent.normalGeometry(), geom); |
|
2558 |
||
2559 |
parent.setWindowState(parent.windowState() ^ Qt::WindowMinimized); |
|
2560 |
QTest::qWait(10); |
|
2561 |
parent.setWindowState(parent.windowState() ^ Qt::WindowMaximized); |
|
2562 |
QTest::qWait(10); |
|
2563 |
QTRY_VERIFY(parent.windowState() & (Qt::WindowMinimized|Qt::WindowMaximized)); |
|
2564 |
// ### when minimized and maximized at the same time, the geometry |
|
2565 |
// ### does *NOT* have to be the normal geometry, it could be the |
|
2566 |
// ### maximized geometry. |
|
2567 |
// QCOMPARE(parent.geometry(), geom); |
|
2568 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2569 |
||
2570 |
parent.setWindowState(parent.windowState() ^ Qt::WindowMinimized); |
|
2571 |
QTest::qWait(10); |
|
2572 |
QTRY_VERIFY(!(parent.windowState() & Qt::WindowMinimized)); |
|
2573 |
QTRY_VERIFY(parent.windowState() & Qt::WindowMaximized); |
|
2574 |
QTRY_VERIFY(parent.geometry() != geom); |
|
2575 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2576 |
||
2577 |
parent.setWindowState(parent.windowState() ^ Qt::WindowMaximized); |
|
2578 |
QTest::qWait(10); |
|
2579 |
QTRY_VERIFY(!(parent.windowState() & Qt::WindowMaximized)); |
|
2580 |
QTRY_COMPARE(parent.geometry(), geom); |
|
2581 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2582 |
||
2583 |
parent.setWindowState(parent.windowState() ^ Qt::WindowFullScreen); |
|
2584 |
QTest::qWait(10); |
|
2585 |
QTRY_VERIFY(parent.windowState() & Qt::WindowFullScreen); |
|
2586 |
QTRY_VERIFY(parent.geometry() != geom); |
|
2587 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2588 |
||
2589 |
parent.setWindowState(parent.windowState() ^ Qt::WindowFullScreen); |
|
2590 |
QTest::qWait(10); |
|
2591 |
QVERIFY(!(parent.windowState() & Qt::WindowFullScreen)); |
|
2592 |
QTRY_COMPARE(parent.geometry(), geom); |
|
2593 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2594 |
||
2595 |
parent.showFullScreen(); |
|
2596 |
QTest::qWait(10); |
|
2597 |
QTRY_VERIFY(parent.windowState() & Qt::WindowFullScreen); |
|
2598 |
QTRY_VERIFY(parent.geometry() != geom); |
|
2599 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2600 |
||
2601 |
parent.showNormal(); |
|
2602 |
QTest::qWait(10); |
|
2603 |
QTRY_VERIFY(!(parent.windowState() & Qt::WindowFullScreen)); |
|
2604 |
QTRY_COMPARE(parent.geometry(), geom); |
|
2605 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2606 |
||
2607 |
parent.showNormal(); |
|
2608 |
parent.setWindowState(Qt:: WindowFullScreen | Qt::WindowMaximized); |
|
2609 |
parent.setWindowState(Qt::WindowMinimized | Qt:: WindowFullScreen | Qt::WindowMaximized); |
|
2610 |
parent.setWindowState(Qt:: WindowFullScreen | Qt::WindowMaximized); |
|
2611 |
QTest::qWait(10); |
|
2612 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2613 |
} |
|
2614 |
||
2615 |
||
2616 |
void tst_QWidget::setGeometry() |
|
2617 |
{ |
|
2618 |
QWidget tlw; |
|
2619 |
QWidget child(&tlw); |
|
2620 |
||
2621 |
QRect tr(100,100,200,200); |
|
2622 |
QRect cr(50,50,50,50); |
|
2623 |
tlw.setGeometry(tr); |
|
2624 |
child.setGeometry(cr); |
|
2625 |
tlw.show(); |
|
2626 |
QTest::qWait(50); |
|
2627 |
QCOMPARE(tlw.geometry().size(), tr.size()); |
|
2628 |
QCOMPARE(child.geometry(), cr); |
|
2629 |
||
2630 |
tlw.setParent(0, Qt::Window|Qt::FramelessWindowHint); |
|
2631 |
tr = QRect(0,0,100,100); |
|
2632 |
tr.moveTopLeft(QApplication::desktop()->availableGeometry().topLeft()); |
|
2633 |
tlw.setGeometry(tr); |
|
2634 |
QCOMPARE(tlw.geometry(), tr); |
|
2635 |
tlw.show(); |
|
2636 |
QTest::qWait(50); |
|
2637 |
if (tlw.frameGeometry() != tlw.geometry()) |
|
2638 |
QSKIP("Your window manager is too broken for this test", SkipAll); |
|
2639 |
QCOMPARE(tlw.geometry(), tr); |
|
2640 |
||
2641 |
} |
|
2642 |
||
2643 |
void tst_QWidget::windowOpacity() |
|
2644 |
{ |
|
2645 |
#ifdef Q_OS_WINCE |
|
2646 |
QSKIP( "Windows CE does not support windowOpacity", SkipAll); |
|
2647 |
#endif |
|
2648 |
QWidget widget; |
|
2649 |
QWidget child(&widget); |
|
2650 |
||
2651 |
// Initial value should be 1.0 |
|
2652 |
QCOMPARE(widget.windowOpacity(), 1.0); |
|
2653 |
// children should always return 1.0 |
|
2654 |
QCOMPARE(child.windowOpacity(), 1.0); |
|
2655 |
||
2656 |
widget.setWindowOpacity(0.0); |
|
2657 |
QCOMPARE(widget.windowOpacity(), 0.0); |
|
2658 |
child.setWindowOpacity(0.0); |
|
2659 |
QCOMPARE(child.windowOpacity(), 1.0); |
|
2660 |
||
2661 |
widget.setWindowOpacity(1.0); |
|
2662 |
QCOMPARE(widget.windowOpacity(), 1.0); |
|
2663 |
child.setWindowOpacity(1.0); |
|
2664 |
QCOMPARE(child.windowOpacity(), 1.0); |
|
2665 |
||
2666 |
widget.setWindowOpacity(2.0); |
|
2667 |
QCOMPARE(widget.windowOpacity(), 1.0); |
|
2668 |
child.setWindowOpacity(2.0); |
|
2669 |
QCOMPARE(child.windowOpacity(), 1.0); |
|
2670 |
||
2671 |
widget.setWindowOpacity(-1.0); |
|
2672 |
QCOMPARE(widget.windowOpacity(), 0.0); |
|
2673 |
child.setWindowOpacity(-1.0); |
|
2674 |
QCOMPARE(child.windowOpacity(), 1.0); |
|
2675 |
} |
|
2676 |
||
2677 |
class UpdateWidget : public QWidget |
|
2678 |
{ |
|
2679 |
public: |
|
2680 |
UpdateWidget(QWidget *parent = 0) : QWidget(parent) { |
|
2681 |
reset(); |
|
2682 |
} |
|
2683 |
||
2684 |
void paintEvent(QPaintEvent *e) { |
|
2685 |
paintedRegion += e->region(); |
|
2686 |
++numPaintEvents; |
|
2687 |
if (resizeInPaintEvent) { |
|
2688 |
resizeInPaintEvent = false; |
|
2689 |
resize(size() + QSize(2, 2)); |
|
2690 |
} |
|
2691 |
} |
|
2692 |
||
2693 |
bool event(QEvent *event) |
|
2694 |
{ |
|
2695 |
switch (event->type()) { |
|
2696 |
case QEvent::ZOrderChange: |
|
2697 |
++numZOrderChangeEvents; |
|
2698 |
break; |
|
2699 |
case QEvent::UpdateRequest: |
|
2700 |
++numUpdateRequestEvents; |
|
2701 |
break; |
|
2702 |
case QEvent::ActivationChange: |
|
2703 |
case QEvent::FocusIn: |
|
2704 |
case QEvent::FocusOut: |
|
2705 |
case QEvent::WindowActivate: |
|
2706 |
case QEvent::WindowDeactivate: |
|
2707 |
if (!updateOnActivationChangeAndFocusIn) |
|
2708 |
return true; // Filter out to avoid update() calls in QWidget. |
|
2709 |
break; |
|
2710 |
default: |
|
2711 |
break; |
|
2712 |
} |
|
2713 |
return QWidget::event(event); |
|
2714 |
} |
|
2715 |
||
2716 |
void reset() { |
|
2717 |
numPaintEvents = 0; |
|
2718 |
numZOrderChangeEvents = 0; |
|
2719 |
numUpdateRequestEvents = 0; |
|
2720 |
updateOnActivationChangeAndFocusIn = false; |
|
2721 |
resizeInPaintEvent = false; |
|
2722 |
paintedRegion = QRegion(); |
|
2723 |
} |
|
2724 |
||
2725 |
int numPaintEvents; |
|
2726 |
int numZOrderChangeEvents; |
|
2727 |
int numUpdateRequestEvents; |
|
2728 |
bool updateOnActivationChangeAndFocusIn; |
|
2729 |
bool resizeInPaintEvent; |
|
2730 |
QRegion paintedRegion; |
|
2731 |
}; |
|
2732 |
||
2733 |
void tst_QWidget::lostUpdatesOnHide() |
|
2734 |
{ |
|
2735 |
#ifndef Q_WS_MAC |
|
2736 |
UpdateWidget widget; |
|
2737 |
widget.setAttribute(Qt::WA_DontShowOnScreen); |
|
2738 |
widget.show(); |
|
2739 |
widget.hide(); |
|
2740 |
QTest::qWait(50); |
|
2741 |
widget.show(); |
|
2742 |
QTest::qWait(50); |
|
2743 |
||
2744 |
QCOMPARE(widget.numPaintEvents, 1); |
|
2745 |
#endif |
|
2746 |
} |
|
2747 |
||
2748 |
void tst_QWidget::raise() |
|
2749 |
{ |
|
2750 |
#ifdef QT_MAC_USE_COCOA |
|
2751 |
QSKIP("Cocoa has no Z-Order for views, we hack it, but it results in paint events.", SkipAll); |
|
2752 |
#endif |
|
2753 |
QTest::qWait(10); |
|
2754 |
QWidget *parent = new QWidget(0); |
|
2755 |
QList<UpdateWidget *> allChildren; |
|
2756 |
||
2757 |
UpdateWidget *child1 = new UpdateWidget(parent); |
|
2758 |
child1->setAutoFillBackground(true); |
|
2759 |
allChildren.append(child1); |
|
2760 |
||
2761 |
UpdateWidget *child2 = new UpdateWidget(parent); |
|
2762 |
child2->setAutoFillBackground(true); |
|
2763 |
allChildren.append(child2); |
|
2764 |
||
2765 |
UpdateWidget *child3 = new UpdateWidget(parent); |
|
2766 |
child3->setAutoFillBackground(true); |
|
2767 |
allChildren.append(child3); |
|
2768 |
||
2769 |
UpdateWidget *child4 = new UpdateWidget(parent); |
|
2770 |
child4->setAutoFillBackground(true); |
|
2771 |
allChildren.append(child4); |
|
2772 |
||
2773 |
parent->show(); |
|
2774 |
QTest::qWaitForWindowShown(parent); |
|
2775 |
QTest::qWait(10); |
|
2776 |
||
2777 |
QList<QObject *> list1; |
|
2778 |
list1 << child1 << child2 << child3 << child4; |
|
2779 |
QVERIFY(parent->children() == list1); |
|
2780 |
QCOMPARE(allChildren.count(), list1.count()); |
|
2781 |
||
2782 |
foreach (UpdateWidget *child, allChildren) { |
|
2783 |
int expectedPaintEvents = child == child4 ? 1 : 0; |
|
2784 |
if (expectedPaintEvents == 0) { |
|
2785 |
QVERIFY(child->numPaintEvents == 0); |
|
2786 |
} else { |
|
2787 |
// show() issues multiple paint events on some window managers |
|
2788 |
QTRY_VERIFY(child->numPaintEvents >= expectedPaintEvents); |
|
2789 |
} |
|
2790 |
QCOMPARE(child->numZOrderChangeEvents, 0); |
|
2791 |
child->reset(); |
|
2792 |
} |
|
2793 |
||
2794 |
for (int i = 0; i < 5; ++i) |
|
2795 |
child2->raise(); |
|
2796 |
QTest::qWait(50); |
|
2797 |
||
2798 |
foreach (UpdateWidget *child, allChildren) { |
|
2799 |
int expectedPaintEvents = child == child2 ? 1 : 0; |
|
2800 |
int expectedZOrderChangeEvents = child == child2 ? 1 : 0; |
|
2801 |
QTRY_COMPARE(child->numPaintEvents, expectedPaintEvents); |
|
2802 |
QCOMPARE(child->numZOrderChangeEvents, expectedZOrderChangeEvents); |
|
2803 |
child->reset(); |
|
2804 |
} |
|
2805 |
||
2806 |
QList<QObject *> list2; |
|
2807 |
list2 << child1 << child3 << child4 << child2; |
|
2808 |
QVERIFY(parent->children() == list2); |
|
2809 |
||
2810 |
// Creates a widget on top of all the children and checks that raising one of |
|
2811 |
// the children underneath doesn't trigger a repaint on the covering widget. |
|
2812 |
QWidget topLevel; |
|
2813 |
parent->setParent(&topLevel); |
|
2814 |
topLevel.show(); |
|
2815 |
QTest::qWaitForWindowShown(&topLevel); |
|
2816 |
QTest::qWait(50); |
|
2817 |
||
2818 |
UpdateWidget *onTop = new UpdateWidget(&topLevel); |
|
2819 |
onTop->reset(); |
|
2820 |
onTop->resize(topLevel.size()); |
|
2821 |
onTop->setAutoFillBackground(true); |
|
2822 |
onTop->show(); |
|
2823 |
QTest::qWait(50); |
|
2824 |
QTRY_VERIFY(onTop->numPaintEvents > 0); |
|
2825 |
onTop->reset(); |
|
2826 |
||
2827 |
// Reset all the children. |
|
2828 |
foreach (UpdateWidget *child, allChildren) |
|
2829 |
child->reset(); |
|
2830 |
||
2831 |
for (int i = 0; i < 5; ++i) |
|
2832 |
child3->raise(); |
|
2833 |
QTest::qWait(50); |
|
2834 |
||
2835 |
QCOMPARE(onTop->numPaintEvents, 0); |
|
2836 |
QCOMPARE(onTop->numZOrderChangeEvents, 0); |
|
2837 |
||
2838 |
QList<QObject *> list3; |
|
2839 |
list3 << child1 << child4 << child2 << child3; |
|
2840 |
QVERIFY(parent->children() == list3); |
|
2841 |
||
2842 |
foreach (UpdateWidget *child, allChildren) { |
|
2843 |
int expectedPaintEvents = 0; |
|
2844 |
int expectedZOrderChangeEvents = child == child3 ? 1 : 0; |
|
2845 |
QTRY_COMPARE(child->numPaintEvents, expectedPaintEvents); |
|
2846 |
QCOMPARE(child->numZOrderChangeEvents, expectedZOrderChangeEvents); |
|
2847 |
child->reset(); |
|
2848 |
} |
|
2849 |
} |
|
2850 |
||
2851 |
void tst_QWidget::lower() |
|
2852 |
{ |
|
2853 |
#ifdef QT_MAC_USE_COCOA |
|
2854 |
QSKIP("Cocoa has no Z-Order for views, we hack it, but it results in paint events.", SkipAll); |
|
2855 |
#endif |
|
2856 |
QWidget *parent = new QWidget(0); |
|
2857 |
QList<UpdateWidget *> allChildren; |
|
2858 |
||
2859 |
UpdateWidget *child1 = new UpdateWidget(parent); |
|
2860 |
child1->setAutoFillBackground(true); |
|
2861 |
allChildren.append(child1); |
|
2862 |
||
2863 |
UpdateWidget *child2 = new UpdateWidget(parent); |
|
2864 |
child2->setAutoFillBackground(true); |
|
2865 |
allChildren.append(child2); |
|
2866 |
||
2867 |
UpdateWidget *child3 = new UpdateWidget(parent); |
|
2868 |
child3->setAutoFillBackground(true); |
|
2869 |
allChildren.append(child3); |
|
2870 |
||
2871 |
UpdateWidget *child4 = new UpdateWidget(parent); |
|
2872 |
child4->setAutoFillBackground(true); |
|
2873 |
allChildren.append(child4); |
|
2874 |
||
2875 |
parent->show(); |
|
2876 |
QTest::qWaitForWindowShown(parent); |
|
2877 |
QTest::qWait(100); |
|
2878 |
||
2879 |
QList<QObject *> list1; |
|
2880 |
list1 << child1 << child2 << child3 << child4; |
|
2881 |
QVERIFY(parent->children() == list1); |
|
2882 |
QCOMPARE(allChildren.count(), list1.count()); |
|
2883 |
||
2884 |
foreach (UpdateWidget *child, allChildren) { |
|
2885 |
int expectedPaintEvents = child == child4 ? 1 : 0; |
|
2886 |
if (expectedPaintEvents == 0) { |
|
2887 |
QVERIFY(child->numPaintEvents == 0); |
|
2888 |
} else { |
|
2889 |
// show() issues multiple paint events on some window managers |
|
2890 |
QTRY_VERIFY(child->numPaintEvents >= expectedPaintEvents); |
|
2891 |
} |
|
2892 |
QCOMPARE(child->numZOrderChangeEvents, 0); |
|
2893 |
child->reset(); |
|
2894 |
} |
|
2895 |
||
2896 |
for (int i = 0; i < 5; ++i) |
|
2897 |
child4->lower(); |
|
2898 |
||
2899 |
QTest::qWait(100); |
|
2900 |
||
2901 |
foreach (UpdateWidget *child, allChildren) { |
|
2902 |
int expectedPaintEvents = child == child3 ? 1 : 0; |
|
2903 |
int expectedZOrderChangeEvents = child == child4 ? 1 : 0; |
|
2904 |
QTRY_COMPARE(child->numZOrderChangeEvents, expectedZOrderChangeEvents); |
|
2905 |
QTRY_COMPARE(child->numPaintEvents, expectedPaintEvents); |
|
2906 |
child->reset(); |
|
2907 |
} |
|
2908 |
||
2909 |
QList<QObject *> list2; |
|
2910 |
list2 << child4 << child1 << child2 << child3; |
|
2911 |
QVERIFY(parent->children() == list2); |
|
2912 |
||
2913 |
delete parent; |
|
2914 |
} |
|
2915 |
||
2916 |
void tst_QWidget::stackUnder() |
|
2917 |
{ |
|
2918 |
#ifdef QT_MAC_USE_COCOA |
|
2919 |
QSKIP("Cocoa has no Z-Order for views, we hack it, but it results in paint events.", SkipAll); |
|
2920 |
#endif |
|
2921 |
QTest::qWait(10); |
|
2922 |
QWidget *parent = new QWidget(0); |
|
2923 |
QList<UpdateWidget *> allChildren; |
|
2924 |
||
2925 |
UpdateWidget *child1 = new UpdateWidget(parent); |
|
2926 |
child1->setAutoFillBackground(true); |
|
2927 |
allChildren.append(child1); |
|
2928 |
||
2929 |
UpdateWidget *child2 = new UpdateWidget(parent); |
|
2930 |
child2->setAutoFillBackground(true); |
|
2931 |
allChildren.append(child2); |
|
2932 |
||
2933 |
UpdateWidget *child3 = new UpdateWidget(parent); |
|
2934 |
child3->setAutoFillBackground(true); |
|
2935 |
allChildren.append(child3); |
|
2936 |
||
2937 |
UpdateWidget *child4 = new UpdateWidget(parent); |
|
2938 |
child4->setAutoFillBackground(true); |
|
2939 |
allChildren.append(child4); |
|
2940 |
||
2941 |
parent->show(); |
|
2942 |
QTest::qWaitForWindowShown(parent); |
|
2943 |
QTest::qWait(10); |
|
2944 |
#ifdef Q_WS_QWS |
|
2945 |
QApplication::sendPostedEvents(); //glib workaround |
|
2946 |
#endif |
|
2947 |
||
2948 |
QList<QObject *> list1; |
|
2949 |
list1 << child1 << child2 << child3 << child4; |
|
2950 |
QVERIFY(parent->children() == list1); |
|
2951 |
||
2952 |
foreach (UpdateWidget *child, allChildren) { |
|
2953 |
int expectedPaintEvents = child == child4 ? 1 : 0; |
|
2954 |
#if defined(Q_WS_WIN) || defined(Q_WS_MAC) |
|
2955 |
if (expectedPaintEvents == 1 && child->numPaintEvents == 2) |
|
2956 |
QEXPECT_FAIL(0, "Mac and Windows issues double repaints for Z-Order change", Continue); |
|
2957 |
#endif |
|
2958 |
QTRY_COMPARE(child->numPaintEvents, expectedPaintEvents); |
|
2959 |
QCOMPARE(child->numZOrderChangeEvents, 0); |
|
2960 |
child->reset(); |
|
2961 |
} |
|
2962 |
||
2963 |
for (int i = 0; i < 5; ++i) |
|
2964 |
child4->stackUnder(child2); |
|
2965 |
QTest::qWait(10); |
|
2966 |
||
2967 |
QList<QObject *> list2; |
|
2968 |
list2 << child1 << child4 << child2 << child3; |
|
2969 |
QVERIFY(parent->children() == list2); |
|
2970 |
||
2971 |
foreach (UpdateWidget *child, allChildren) { |
|
2972 |
int expectedPaintEvents = child == child3 ? 1 : 0; |
|
2973 |
int expectedZOrderChangeEvents = child == child4 ? 1 : 0; |
|
2974 |
QTRY_COMPARE(child->numPaintEvents, expectedPaintEvents); |
|
2975 |
QTRY_COMPARE(child->numZOrderChangeEvents, expectedZOrderChangeEvents); |
|
2976 |
child->reset(); |
|
2977 |
} |
|
2978 |
||
2979 |
for (int i = 0; i < 5; ++i) |
|
2980 |
child1->stackUnder(child3); |
|
2981 |
QTest::qWait(10); |
|
2982 |
||
2983 |
QList<QObject *> list3; |
|
2984 |
list3 << child4 << child2 << child1 << child3; |
|
2985 |
QVERIFY(parent->children() == list3); |
|
2986 |
||
2987 |
foreach (UpdateWidget *child, allChildren) { |
|
2988 |
int expectedZOrderChangeEvents = child == child1 ? 1 : 0; |
|
2989 |
if (child == child3) { |
|
2990 |
#ifdef Q_OS_WINCE |
|
2991 |
qApp->processEvents(); |
|
2992 |
#endif |
|
2993 |
#ifndef Q_WS_MAC |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2994 |
QEXPECT_FAIL(0, "See QTBUG-493", Continue); |
0 | 2995 |
#endif |
2996 |
QCOMPARE(child->numPaintEvents, 0); |
|
2997 |
} else { |
|
2998 |
QCOMPARE(child->numPaintEvents, 0); |
|
2999 |
} |
|
3000 |
QTRY_COMPARE(child->numZOrderChangeEvents, expectedZOrderChangeEvents); |
|
3001 |
child->reset(); |
|
3002 |
} |
|
3003 |
||
3004 |
delete parent; |
|
3005 |
} |
|
3006 |
||
3007 |
void drawPolygon(QPaintDevice *dev, int w, int h) |
|
3008 |
{ |
|
3009 |
QPainter p(dev); |
|
3010 |
p.fillRect(0, 0, w, h, Qt::white); |
|
3011 |
||
3012 |
QPolygon a; |
|
3013 |
a << QPoint(0, 0) << QPoint(w/2, h/2) << QPoint(w, 0) |
|
3014 |
<< QPoint(w/2, h) << QPoint(0, 0); |
|
3015 |
||
3016 |
p.setPen(QPen(Qt::black, 1)); |
|
3017 |
p.setBrush(Qt::DiagCrossPattern); |
|
3018 |
p.drawPolygon(a); |
|
3019 |
} |
|
3020 |
||
3021 |
class ContentsPropagationWidget : public QWidget |
|
3022 |
{ |
|
3023 |
Q_OBJECT |
|
3024 |
public: |
|
3025 |
ContentsPropagationWidget(QWidget *parent = 0) : QWidget(parent) |
|
3026 |
{ |
|
3027 |
QWidget *child = this; |
|
3028 |
for (int i=0; i<32; ++i) { |
|
3029 |
child = new QWidget(child); |
|
3030 |
child->setGeometry(i, i, 400 - i*2, 400 - i*2); |
|
3031 |
} |
|
3032 |
} |
|
3033 |
||
3034 |
void setContentsPropagation(bool enable) { |
|
3035 |
foreach (QObject *child, children()) |
|
3036 |
qobject_cast<QWidget *>(child)->setAutoFillBackground(!enable); |
|
3037 |
} |
|
3038 |
||
3039 |
protected: |
|
3040 |
void paintEvent(QPaintEvent *) |
|
3041 |
{ |
|
3042 |
int w = width(), h = height(); |
|
3043 |
drawPolygon(this, w, h); |
|
3044 |
} |
|
3045 |
||
3046 |
QSize sizeHint() const { return QSize(500, 500); } |
|
3047 |
}; |
|
3048 |
||
3049 |
void tst_QWidget::testContentsPropagation() |
|
3050 |
{ |
|
3051 |
#ifdef Q_WS_MAC |
|
3052 |
QSKIP("Pixmap is not antialiased whereas widget is.", SkipAll); |
|
3053 |
#endif |
|
3054 |
ContentsPropagationWidget widget; |
|
3055 |
#ifdef Q_WS_QWS |
|
3056 |
widget.resize(500,500); |
|
3057 |
#else |
|
3058 |
widget.setFixedSize(500, 500); |
|
3059 |
#endif |
|
3060 |
widget.setContentsPropagation(false); |
|
3061 |
QPixmap widgetSnapshot = QPixmap::grabWidget(&widget); |
|
3062 |
||
3063 |
QPixmap correct(500, 500); |
|
3064 |
drawPolygon(&correct, 500, 500); |
|
3065 |
//correct.save("correct.png", "PNG"); |
|
3066 |
||
3067 |
//widgetSnapshot.save("snap1.png", "PNG"); |
|
3068 |
QVERIFY(widgetSnapshot.toImage() != correct.toImage()); |
|
3069 |
||
3070 |
widget.setContentsPropagation(true); |
|
3071 |
widgetSnapshot = QPixmap::grabWidget(&widget); |
|
3072 |
//widgetSnapshot.save("snap2.png", "PNG"); |
|
3073 |
||
3074 |
QCOMPARE(widgetSnapshot, correct); |
|
3075 |
} |
|
3076 |
||
3077 |
/* |
|
3078 |
Test that saving and restoring window geometry with |
|
3079 |
saveGeometry() and restoreGeometry() works. |
|
3080 |
*/ |
|
3081 |
void tst_QWidget::saveRestoreGeometry() |
|
3082 |
{ |
|
3083 |
#ifdef Q_OS_IRIX |
|
3084 |
QSKIP("4DWM issues on IRIX makes this test fail", SkipAll); |
|
3085 |
#endif |
|
3086 |
const QPoint position(100, 100); |
|
3087 |
const QSize size(200, 200); |
|
3088 |
||
3089 |
QByteArray savedGeometry; |
|
3090 |
||
3091 |
{ |
|
3092 |
QWidget widget; |
|
3093 |
widget.move(position); |
|
3094 |
widget.resize(size); |
|
3095 |
widget.show(); |
|
3096 |
QTest::qWaitForWindowShown(&widget); |
|
3097 |
QApplication::processEvents(); |
|
3098 |
||
3099 |
QTRY_COMPARE(widget.pos(), position); |
|
3100 |
QCOMPARE(widget.size(), size); |
|
3101 |
savedGeometry = widget.saveGeometry(); |
|
3102 |
} |
|
3103 |
||
3104 |
{ |
|
3105 |
QWidget widget; |
|
3106 |
||
3107 |
const QByteArray empty; |
|
3108 |
const QByteArray one("a"); |
|
3109 |
const QByteArray two("ab"); |
|
3110 |
const QByteArray three("abc"); |
|
3111 |
const QByteArray four("abca"); |
|
3112 |
const QByteArray garbage("abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"); |
|
3113 |
||
3114 |
QVERIFY(widget.restoreGeometry(empty) == false); |
|
3115 |
QVERIFY(widget.restoreGeometry(one) == false); |
|
3116 |
QVERIFY(widget.restoreGeometry(two) == false); |
|
3117 |
QVERIFY(widget.restoreGeometry(three) == false); |
|
3118 |
QVERIFY(widget.restoreGeometry(four) == false); |
|
3119 |
QVERIFY(widget.restoreGeometry(garbage) == false); |
|
3120 |
||
3121 |
QVERIFY(widget.restoreGeometry(savedGeometry)); |
|
3122 |
widget.show(); |
|
3123 |
QTest::qWaitForWindowShown(&widget); |
|
3124 |
QApplication::processEvents(); |
|
3125 |
||
3126 |
QTRY_COMPARE(widget.pos(), position); |
|
3127 |
QCOMPARE(widget.size(), size); |
|
3128 |
widget.show(); |
|
3129 |
QCOMPARE(widget.pos(), position); |
|
3130 |
QCOMPARE(widget.size(), size); |
|
3131 |
} |
|
3132 |
||
3133 |
{ |
|
3134 |
QWidget widget; |
|
3135 |
widget.move(position); |
|
3136 |
widget.resize(size); |
|
3137 |
widget.show(); |
|
3138 |
QTest::qWaitForWindowShown(&widget); |
|
3139 |
QTest::qWait(500); |
|
3140 |
QTRY_COMPARE(widget.geometry().size(), size); |
|
3141 |
||
3142 |
QRect geom; |
|
3143 |
||
3144 |
//Restore from Full screen |
|
3145 |
savedGeometry = widget.saveGeometry(); |
|
3146 |
geom = widget.geometry(); |
|
3147 |
widget.setWindowState(widget.windowState() | Qt::WindowFullScreen); |
|
3148 |
QTRY_VERIFY((widget.windowState() & Qt::WindowFullScreen)); |
|
3149 |
QTest::qWait(500); |
|
3150 |
QVERIFY(widget.restoreGeometry(savedGeometry)); |
|
3151 |
QTest::qWait(120); |
|
3152 |
QTRY_VERIFY(!(widget.windowState() & Qt::WindowFullScreen)); |
|
3153 |
QTRY_COMPARE(widget.geometry(), geom); |
|
3154 |
||
3155 |
//Restore to full screen |
|
3156 |
widget.setWindowState(widget.windowState() | Qt::WindowFullScreen); |
|
3157 |
QTest::qWait(120); |
|
3158 |
QTRY_VERIFY((widget.windowState() & Qt::WindowFullScreen)); |
|
3159 |
QTest::qWait(500); |
|
3160 |
savedGeometry = widget.saveGeometry(); |
|
3161 |
geom = widget.geometry(); |
|
3162 |
widget.setWindowState(widget.windowState() ^ Qt::WindowFullScreen); |
|
3163 |
QTest::qWait(120); |
|
3164 |
QTRY_VERIFY(!(widget.windowState() & Qt::WindowFullScreen)); |
|
3165 |
QTest::qWait(400); |
|
3166 |
QVERIFY(widget.restoreGeometry(savedGeometry)); |
|
3167 |
QTest::qWait(120); |
|
3168 |
QTRY_VERIFY((widget.windowState() & Qt::WindowFullScreen)); |
|
3169 |
QTRY_COMPARE(widget.geometry(), geom); |
|
3170 |
QVERIFY((widget.windowState() & Qt::WindowFullScreen)); |
|
3171 |
widget.setWindowState(widget.windowState() ^ Qt::WindowFullScreen); |
|
3172 |
QTest::qWait(120); |
|
3173 |
QTRY_VERIFY(!(widget.windowState() & Qt::WindowFullScreen)); |
|
3174 |
QTest::qWait(120); |
|
3175 |
||
3176 |
//Restore from Maximised |
|
3177 |
widget.move(position); |
|
3178 |
widget.resize(size); |
|
3179 |
QTest::qWait(10); |
|
3180 |
QTRY_COMPARE(widget.size(), size); |
|
3181 |
QTest::qWait(500); |
|
3182 |
savedGeometry = widget.saveGeometry(); |
|
3183 |
geom = widget.geometry(); |
|
3184 |
widget.setWindowState(widget.windowState() | Qt::WindowMaximized); |
|
3185 |
QTest::qWait(120); |
|
3186 |
QTRY_VERIFY((widget.windowState() & Qt::WindowMaximized)); |
|
3187 |
QTRY_VERIFY(widget.geometry() != geom); |
|
3188 |
QTest::qWait(500); |
|
3189 |
QVERIFY(widget.restoreGeometry(savedGeometry)); |
|
3190 |
QTest::qWait(120); |
|
3191 |
QTRY_COMPARE(widget.geometry(), geom); |
|
3192 |
||
3193 |
QVERIFY(!(widget.windowState() & Qt::WindowMaximized)); |
|
3194 |
||
3195 |
//Restore to maximised |
|
3196 |
widget.setWindowState(widget.windowState() | Qt::WindowMaximized); |
|
3197 |
QTest::qWait(120); |
|
3198 |
QTRY_VERIFY((widget.windowState() & Qt::WindowMaximized)); |
|
3199 |
QTest::qWait(500); |
|
3200 |
geom = widget.geometry(); |
|
3201 |
savedGeometry = widget.saveGeometry(); |
|
3202 |
widget.setWindowState(widget.windowState() ^ Qt::WindowMaximized); |
|
3203 |
QTest::qWait(120); |
|
3204 |
QTRY_VERIFY(!(widget.windowState() & Qt::WindowMaximized)); |
|
3205 |
QTest::qWait(500); |
|
3206 |
QVERIFY(widget.restoreGeometry(savedGeometry)); |
|
3207 |
QTest::qWait(120); |
|
3208 |
QTRY_VERIFY((widget.windowState() & Qt::WindowMaximized)); |
|
3209 |
QTRY_COMPARE(widget.geometry(), geom); |
|
3210 |
} |
|
3211 |
} |
|
3212 |
||
3213 |
void tst_QWidget::restoreVersion1Geometry_data() |
|
3214 |
{ |
|
3215 |
QTest::addColumn<QString>("fileName"); |
|
3216 |
QTest::addColumn<uint>("expectedWindowState"); |
|
3217 |
QTest::addColumn<QPoint>("expectedPosition"); |
|
3218 |
QTest::addColumn<QSize>("expectedSize"); |
|
3219 |
QTest::addColumn<QRect>("expectedNormalGeometry"); |
|
3220 |
const QPoint position(100, 100); |
|
3221 |
const QSize size(200, 200); |
|
3222 |
const QRect normalGeometry(102, 124, 200, 200); |
|
3223 |
||
3224 |
QTest::newRow("geometry.dat") << ":geometry.dat" << uint(Qt::WindowNoState) << position << size << normalGeometry; |
|
3225 |
QTest::newRow("geometry-maximized.dat") << ":geometry-maximized.dat" << uint(Qt::WindowMaximized) << position << size << normalGeometry; |
|
3226 |
QTest::newRow("geometry-fullscreen.dat") << ":geometry-fullscreen.dat" << uint(Qt::WindowFullScreen) << position << size << normalGeometry; |
|
3227 |
} |
|
3228 |
||
3229 |
/* |
|
3230 |
Test that the current version of restoreGeometry() can restore geometry |
|
3231 |
saved width saveGeometry() version 1.0. |
|
3232 |
*/ |
|
3233 |
void tst_QWidget::restoreVersion1Geometry() |
|
3234 |
{ |
|
3235 |
#ifdef Q_OS_IRIX |
|
3236 |
QSKIP("4DWM issues on IRIX makes this test fail", SkipAll); |
|
3237 |
#endif |
|
3238 |
||
3239 |
QFETCH(QString, fileName); |
|
3240 |
QFETCH(uint, expectedWindowState); |
|
3241 |
QFETCH(QPoint, expectedPosition); |
|
3242 |
QFETCH(QSize, expectedSize); |
|
3243 |
QFETCH(QRect, expectedNormalGeometry); |
|
3244 |
||
3245 |
// WindowActive is uninteresting for this test |
|
3246 |
const uint WindowStateMask = Qt::WindowFullScreen | Qt::WindowMaximized | Qt::WindowMinimized; |
|
3247 |
||
3248 |
QFile f(fileName); |
|
3249 |
QVERIFY(f.exists()); |
|
3250 |
f.open(QIODevice::ReadOnly); |
|
3251 |
const QByteArray savedGeometry = f.readAll(); |
|
3252 |
QCOMPARE(savedGeometry.count(), 46); |
|
3253 |
f.close(); |
|
3254 |
||
3255 |
QWidget widget; |
|
3256 |
||
3257 |
QVERIFY(widget.restoreGeometry(savedGeometry)); |
|
3258 |
||
3259 |
QCOMPARE(uint(widget.windowState() & WindowStateMask), expectedWindowState); |
|
3260 |
if (expectedWindowState == Qt::WindowNoState) { |
|
3261 |
QCOMPARE(widget.pos(), expectedPosition); |
|
3262 |
QCOMPARE(widget.size(), expectedSize); |
|
3263 |
} |
|
3264 |
widget.show(); |
|
3265 |
QTest::qWaitForWindowShown(&widget); |
|
3266 |
QTest::qWait(100); |
|
3267 |
||
3268 |
if (expectedWindowState == Qt::WindowNoState) { |
|
3269 |
QTRY_COMPARE(widget.pos(), expectedPosition); |
|
3270 |
QTRY_COMPARE(widget.size(), expectedSize); |
|
3271 |
} |
|
3272 |
||
3273 |
widget.showNormal(); |
|
3274 |
QTest::qWait(10); |
|
3275 |
||
3276 |
if (expectedWindowState != Qt::WindowNoState) { |
|
3277 |
// restoring from maximized or fullscreen, we can only restore to the normal geometry |
|
3278 |
QTRY_COMPARE(widget.geometry(), expectedNormalGeometry); |
|
3279 |
} else { |
|
3280 |
QTRY_COMPARE(widget.pos(), expectedPosition); |
|
3281 |
QTRY_COMPARE(widget.size(), expectedSize); |
|
3282 |
} |
|
3283 |
||
3284 |
#if 0 |
|
3285 |
// Code for saving a new geometry*.dat files |
|
3286 |
{ |
|
3287 |
QWidget widgetToSave; |
|
3288 |
widgetToSave.move(expectedPosition); |
|
3289 |
widgetToSave.resize(expectedSize); |
|
3290 |
widgetToSave.show(); |
|
3291 |
#ifdef Q_WS_X11 |
|
3292 |
qt_x11_wait_for_window_manager(&widget); |
|
3293 |
#endif |
|
3294 |
QTest::qWait(500); // stabilize |
|
3295 |
widgetToSave.setWindowState(Qt::WindowStates(expectedWindowState)); |
|
3296 |
QTest::qWait(500); // stabilize |
|
3297 |
||
3298 |
QByteArray geometryToSave = widgetToSave.saveGeometry(); |
|
3299 |
||
3300 |
// Code for saving a new geometry.dat file. |
|
3301 |
f.setFileName(fileName.mid(1)); |
|
3302 |
QVERIFY(f.open(QIODevice::WriteOnly)); // did you forget to 'p4 edit *.dat'? :) |
|
3303 |
f.write(geometryToSave); |
|
3304 |
f.close(); |
|
3305 |
} |
|
3306 |
#endif |
|
3307 |
||
3308 |
} |
|
3309 |
||
3310 |
void tst_QWidget::widgetAt() |
|
3311 |
{ |
|
3312 |
Q_CHECK_PAINTEVENTS |
|
3313 |
||
3314 |
QWidget *w1 = new QWidget(0, Qt::X11BypassWindowManagerHint); |
|
3315 |
w1->setGeometry(0,0,150,150); |
|
3316 |
w1->setObjectName("w1"); |
|
3317 |
||
3318 |
QWidget *w2 = new QWidget(0, Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); |
|
3319 |
w2->setGeometry(50,50,100,100); |
|
3320 |
w2->setObjectName("w2"); |
|
3321 |
w1->show(); |
|
3322 |
QTest::qWaitForWindowShown(w1); |
|
3323 |
qApp->processEvents(); |
|
3324 |
QWidget *wr; |
|
3325 |
QTRY_VERIFY((wr = QApplication::widgetAt(100, 100))); |
|
3326 |
QCOMPARE(wr->objectName(), QString("w1")); |
|
3327 |
||
3328 |
w2->show(); |
|
3329 |
QTest::qWaitForWindowShown(w2); |
|
3330 |
qApp->processEvents(); |
|
3331 |
qApp->processEvents(); |
|
3332 |
qApp->processEvents(); |
|
3333 |
QTRY_VERIFY((wr = QApplication::widgetAt(100, 100))); |
|
3334 |
QCOMPARE(wr->objectName(), QString("w2")); |
|
3335 |
||
3336 |
w2->lower(); |
|
3337 |
qApp->processEvents(); |
|
3338 |
QTRY_VERIFY((wr = QApplication::widgetAt(100, 100))); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3339 |
const bool match = (wr->objectName() == QString("w1")); |
0 | 3340 |
w2->raise(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3341 |
QVERIFY(match); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3342 |
|
0 | 3343 |
qApp->processEvents(); |
3344 |
QTRY_VERIFY((wr = QApplication::widgetAt(100, 100))); |
|
3345 |
QCOMPARE(wr->objectName(), QString("w2")); |
|
3346 |
||
3347 |
||
3348 |
QWidget *w3 = new QWidget(w2); |
|
3349 |
w3->setGeometry(10,10,50,50); |
|
3350 |
w3->setObjectName("w3"); |
|
3351 |
w3->show(); |
|
3352 |
qApp->processEvents(); |
|
3353 |
QTRY_VERIFY((wr = QApplication::widgetAt(100,100))); |
|
3354 |
QCOMPARE(wr->objectName(), QString("w3")); |
|
3355 |
||
3356 |
w3->setAttribute(Qt::WA_TransparentForMouseEvents); |
|
3357 |
qApp->processEvents(); |
|
3358 |
QTRY_VERIFY((wr = QApplication::widgetAt(100, 100))); |
|
3359 |
QCOMPARE(wr->objectName(), QString("w2")); |
|
3360 |
||
3361 |
QRegion rgn = QRect(QPoint(0,0), w2->size()); |
|
3362 |
QPoint point = w2->mapFromGlobal(QPoint(100,100)); |
|
3363 |
rgn -= QRect(point, QSize(1,1)); |
|
3364 |
w2->setMask(rgn); |
|
3365 |
qApp->processEvents(); |
|
3366 |
QTest::qWait(10); |
|
3367 |
#if defined(Q_OS_WINCE) |
|
3368 |
QEXPECT_FAIL("", "Windows CE does only support rectangular regions", Continue); //See also task 147191 |
|
3369 |
#endif |
|
3370 |
#if defined(Q_OS_SYMBIAN) |
|
3371 |
QEXPECT_FAIL("", "Symbian/S60 does only support rectangular regions", Continue); //See also task 147191 |
|
3372 |
#endif |
|
3373 |
QTRY_COMPARE(QApplication::widgetAt(100,100)->objectName(), w1->objectName()); |
|
3374 |
QTRY_COMPARE(QApplication::widgetAt(101,101)->objectName(), w2->objectName()); |
|
3375 |
||
3376 |
QBitmap bitmap(w2->size()); |
|
3377 |
QPainter p(&bitmap); |
|
3378 |
p.fillRect(bitmap.rect(), Qt::color1); |
|
3379 |
p.setPen(Qt::color0); |
|
3380 |
p.drawPoint(w2->mapFromGlobal(QPoint(100,100))); |
|
3381 |
p.end(); |
|
3382 |
w2->setMask(bitmap); |
|
3383 |
qApp->processEvents(); |
|
3384 |
QTest::qWait(10); |
|
3385 |
#if defined(Q_OS_WINCE) |
|
3386 |
QEXPECT_FAIL("", "Windows CE does only support rectangular regions", Continue); //See also task 147191 |
|
3387 |
#endif |
|
3388 |
#if defined(Q_OS_SYMBIAN) |
|
3389 |
QEXPECT_FAIL("", "Symbian/S60 does only support rectangular regions", Continue); //See also task 147191 |
|
3390 |
#endif |
|
3391 |
QTRY_VERIFY(QApplication::widgetAt(100,100) == w1); |
|
3392 |
QTRY_VERIFY(QApplication::widgetAt(101,101) == w2); |
|
3393 |
||
3394 |
delete w2; |
|
3395 |
delete w1; |
|
3396 |
} |
|
3397 |
||
3398 |
#if defined(Q_WS_X11) |
|
3399 |
bool getProperty(Display *display, Window target, Atom type, Atom property, |
|
3400 |
unsigned char** data, unsigned long* count) |
|
3401 |
{ |
|
3402 |
Atom atom_return; |
|
3403 |
int size; |
|
3404 |
unsigned long nitems, bytes_left; |
|
3405 |
||
3406 |
int ret = XGetWindowProperty(display, target, property, |
|
3407 |
0l, 1l, false, |
|
3408 |
type, &atom_return, &size, |
|
3409 |
&nitems, &bytes_left, data); |
|
3410 |
if (ret != Success || nitems < 1) |
|
3411 |
return false; |
|
3412 |
||
3413 |
if (bytes_left != 0) { |
|
3414 |
XFree(*data); |
|
3415 |
unsigned long remain = ((size / 8) * nitems) + bytes_left; |
|
3416 |
ret = XGetWindowProperty(display, target, |
|
3417 |
property, 0l, remain, false, |
|
3418 |
type, &atom_return, &size, |
|
3419 |
&nitems, &bytes_left, data); |
|
3420 |
if (ret != Success) |
|
3421 |
return false; |
|
3422 |
} |
|
3423 |
||
3424 |
*count = nitems; |
|
3425 |
return true; |
|
3426 |
} |
|
3427 |
||
3428 |
QString textPropertyToString(Display *display, XTextProperty& text_prop) |
|
3429 |
{ |
|
3430 |
QString ret; |
|
3431 |
if (text_prop.value && text_prop.nitems > 0) { |
|
3432 |
if (text_prop.encoding == XA_STRING) { |
|
3433 |
ret = reinterpret_cast<char *>(text_prop.value); |
|
3434 |
} else { |
|
3435 |
text_prop.nitems = strlen(reinterpret_cast<char *>(text_prop.value)); |
|
3436 |
char **list; |
|
3437 |
int num; |
|
3438 |
if (XmbTextPropertyToTextList(display, &text_prop, &list, &num) == Success |
|
3439 |
&& num > 0 && *list) { |
|
3440 |
ret = QString::fromLocal8Bit(*list); |
|
3441 |
XFreeStringList(list); |
|
3442 |
} |
|
3443 |
} |
|
3444 |
} |
|
3445 |
return ret; |
|
3446 |
} |
|
3447 |
||
3448 |
#endif |
|
3449 |
||
3450 |
#if defined(Q_WS_S60) |
|
3451 |
// Returns the application's status pane control, if not present returns NULL. |
|
3452 |
static CCoeControl* GetStatusPaneControl( TInt aPaneId ) |
|
3453 |
{ |
|
3454 |
const TUid paneUid = { aPaneId }; |
|
3455 |
||
3456 |
CEikStatusPane* statusPane = CEikonEnv::Static()->AppUiFactory()->StatusPane(); |
|
3457 |
if (statusPane && statusPane->PaneCapabilities(paneUid).IsPresent()){ |
|
3458 |
CCoeControl* control = NULL; |
|
3459 |
// ControlL shouldn't leave because the pane is present |
|
3460 |
TRAPD(err, control = statusPane->ControlL(paneUid)); |
|
3461 |
return err != KErrNone ? NULL : control; |
|
3462 |
} |
|
3463 |
return NULL; |
|
3464 |
} |
|
3465 |
// Returns the application's title pane, if not present returns NULL. |
|
3466 |
static CAknTitlePane* TitlePane() |
|
3467 |
{ |
|
3468 |
return static_cast<CAknTitlePane*>(GetStatusPaneControl(EEikStatusPaneUidTitle)); |
|
3469 |
} |
|
3470 |
||
3471 |
// Returns the application's title pane, if not present returns NULL. |
|
3472 |
static CAknContextPane* ContextPane() |
|
3473 |
{ |
|
3474 |
return static_cast<CAknContextPane*>(GetStatusPaneControl(EEikStatusPaneUidContext)); |
|
3475 |
} |
|
3476 |
#endif |
|
3477 |
||
3478 |
static QString visibleWindowTitle(QWidget *window, Qt::WindowState state = Qt::WindowNoState) |
|
3479 |
{ |
|
3480 |
QString vTitle; |
|
3481 |
||
3482 |
#ifdef Q_WS_WIN |
|
3483 |
Q_UNUSED(state); |
|
3484 |
const size_t maxTitleLength = 256; |
|
3485 |
wchar_t title[maxTitleLength]; |
|
3486 |
GetWindowText(window->winId(), title, maxTitleLength); |
|
3487 |
vTitle = QString::fromWCharArray(title); |
|
3488 |
#elif defined(Q_WS_X11) |
|
3489 |
/* |
|
3490 |
We can't check what the window manager displays, but we can |
|
3491 |
check what we tell the window manager to display. This will |
|
3492 |
have to do. |
|
3493 |
*/ |
|
3494 |
Atom UTF8_STRING = XInternAtom(window->x11Info().display(), "UTF8_STRING", false); |
|
3495 |
Atom _NET_WM_NAME = XInternAtom(window->x11Info().display(), "_NET_WM_NAME", false); |
|
3496 |
Atom _NET_WM_ICON_NAME = XInternAtom(window->x11Info().display(), "_NET_WM_ICON_NAME", false); |
|
3497 |
uchar *data = 0; |
|
3498 |
ulong length = 0; |
|
3499 |
if (state == Qt::WindowMinimized) { |
|
3500 |
if (getProperty(window->x11Info().display(), window->winId(), |
|
3501 |
UTF8_STRING, _NET_WM_ICON_NAME, &data, &length)) { |
|
3502 |
vTitle = QString::fromUtf8((char *) data, length); |
|
3503 |
XFree(data); |
|
3504 |
} else { |
|
3505 |
XTextProperty text_prop; |
|
3506 |
if (XGetWMIconName(window->x11Info().display(), window->winId(), &text_prop)) { |
|
3507 |
vTitle = textPropertyToString(window->x11Info().display(), text_prop); |
|
3508 |
XFree((char *) text_prop.value); |
|
3509 |
} |
|
3510 |
} |
|
3511 |
} else { |
|
3512 |
if (getProperty(window->x11Info().display(), window->winId(), |
|
3513 |
UTF8_STRING, _NET_WM_NAME, &data, &length)) { |
|
3514 |
vTitle = QString::fromUtf8((char *) data, length); |
|
3515 |
XFree(data); |
|
3516 |
} else { |
|
3517 |
XTextProperty text_prop; |
|
3518 |
if (XGetWMName(window->x11Info().display(), window->winId(), &text_prop)) { |
|
3519 |
vTitle = textPropertyToString(window->x11Info().display(), text_prop); |
|
3520 |
XFree((char *) text_prop.value); |
|
3521 |
} |
|
3522 |
} |
|
3523 |
} |
|
3524 |
#elif defined(Q_WS_MAC) |
|
3525 |
vTitle = nativeWindowTitle(window, state); |
|
3526 |
#elif defined(Q_WS_QWS) |
|
3527 |
if (qwsServer) { |
|
3528 |
const QWSWindow *win = 0; |
|
3529 |
const QList<QWSWindow*> windows = qwsServer->clientWindows(); |
|
3530 |
for (int i = 0; i < windows.count(); ++i) { |
|
3531 |
const QWSWindow* w = windows.at(i); |
|
3532 |
if (w->winId() == window->winId()) { |
|
3533 |
win = w; |
|
3534 |
break; |
|
3535 |
} |
|
3536 |
} |
|
3537 |
if (win) |
|
3538 |
vTitle = win->caption(); |
|
3539 |
} |
|
3540 |
#elif defined (Q_WS_S60) |
|
3541 |
CAknTitlePane* titlePane = TitlePane(); |
|
3542 |
if(titlePane) |
|
3543 |
{ |
|
3544 |
const TDesC* nTitle = titlePane->Text(); |
|
3545 |
vTitle = QString::fromUtf16(nTitle->Ptr(), nTitle->Length()); |
|
3546 |
} |
|
3547 |
#endif |
|
3548 |
||
3549 |
return vTitle; |
|
3550 |
} |
|
3551 |
||
3552 |
void tst_QWidget::windowTitle() |
|
3553 |
{ |
|
3554 |
QWidget widget(0); |
|
3555 |
widget.setWindowTitle("Application Name"); |
|
3556 |
widget.winId(); // Make sure the window is created... |
|
3557 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3558 |
||
3559 |
widget.setWindowTitle("Application Name *"); |
|
3560 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name *")); |
|
3561 |
||
3562 |
widget.setWindowTitle("Application Name[*]"); |
|
3563 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3564 |
||
3565 |
widget.setWindowTitle("Application Name[*][*]"); |
|
3566 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name[*]")); |
|
3567 |
||
3568 |
widget.setWindowTitle("Application Name[*][*][*]"); |
|
3569 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name[*]")); |
|
3570 |
||
3571 |
widget.setWindowTitle("Application Name[*][*][*][*]"); |
|
3572 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name[*][*]")); |
|
3573 |
} |
|
3574 |
||
3575 |
void tst_QWidget::windowIconText() |
|
3576 |
{ |
|
3577 |
#ifdef Q_OS_SYMBIAN |
|
3578 |
QSKIP("Symbian/S60 windows don't have window icon text", SkipAll); |
|
3579 |
#endif |
|
3580 |
QWidget widget(0); |
|
3581 |
||
3582 |
widget.setWindowTitle("Application Name"); |
|
3583 |
widget.setWindowIconText("Application Minimized"); |
|
3584 |
widget.showNormal(); |
|
3585 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3586 |
widget.showMinimized(); |
|
3587 |
#if defined(Q_WS_QWS) || defined(Q_OS_WINCE) |
|
3588 |
QEXPECT_FAIL(0, "Qt/Embedded/WinCE does not implement showMinimized()", Continue); |
|
3589 |
//See task 147193 for WinCE |
|
3590 |
#endif |
|
3591 |
QApplication::instance()->processEvents(); |
|
3592 |
QCOMPARE(visibleWindowTitle(&widget, Qt::WindowMinimized), |
|
3593 |
QString("Application Minimized")); |
|
3594 |
||
3595 |
widget.setWindowTitle("Application Name[*]"); |
|
3596 |
widget.setWindowIconText("Application Minimized[*]"); |
|
3597 |
widget.showNormal(); |
|
3598 |
QApplication::instance()->processEvents(); |
|
3599 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3600 |
widget.showMinimized(); |
|
3601 |
#if defined (Q_WS_QWS) || defined(Q_OS_WINCE) |
|
3602 |
QEXPECT_FAIL(0, "Qt/Embedded/WinCE does not implement showMinimized()", Continue); |
|
3603 |
//See task 147193 for WinCE |
|
3604 |
#endif |
|
3605 |
QApplication::instance()->processEvents(); |
|
3606 |
QCOMPARE(visibleWindowTitle(&widget, Qt::WindowMinimized), |
|
3607 |
QString("Application Minimized")); |
|
3608 |
||
3609 |
widget.setWindowModified(true); |
|
3610 |
widget.showNormal(); |
|
3611 |
QApplication::instance()->processEvents(); |
|
3612 |
if (widget.style()->styleHint(QStyle::SH_TitleBar_ModifyNotification, 0, &widget)) |
|
3613 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name*")); |
|
3614 |
else |
|
3615 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3616 |
widget.showMinimized(); |
|
3617 |
#if defined (Q_WS_QWS) || defined(Q_OS_WINCE) |
|
3618 |
QEXPECT_FAIL(0, "Qt/Embedded/WinCE does not implement showMinimized()", Continue); |
|
3619 |
//See task 147193 for WinCE |
|
3620 |
#endif |
|
3621 |
QApplication::instance()->processEvents(); |
|
3622 |
#ifdef Q_WS_MAC |
|
3623 |
QCOMPARE(visibleWindowTitle(&widget, Qt::WindowMinimized), |
|
3624 |
QString("Application Minimized")); |
|
3625 |
QVERIFY(nativeWindowModified(&widget)); |
|
3626 |
#else |
|
3627 |
QCOMPARE(visibleWindowTitle(&widget, Qt::WindowMinimized), |
|
3628 |
QString("Application Minimized*")); |
|
3629 |
#endif |
|
3630 |
} |
|
3631 |
||
3632 |
void tst_QWidget::windowModified() |
|
3633 |
{ |
|
3634 |
QWidget widget(0); |
|
3635 |
widget.show(); |
|
3636 |
QTest::qWaitForWindowShown(&widget); |
|
3637 |
#ifndef Q_WS_MAC |
|
3638 |
QTest::ignoreMessage(QtWarningMsg, "QWidget::setWindowModified: The window title does not contain a '[*]' placeholder"); |
|
3639 |
#endif |
|
3640 |
widget.setWindowTitle("Application Name"); |
|
3641 |
QTest::qWait(10); |
|
3642 |
QTRY_COMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3643 |
||
3644 |
#ifdef Q_WS_MAC |
|
3645 |
widget.setWindowModified(true); |
|
3646 |
QVERIFY(nativeWindowModified(&widget)); |
|
3647 |
#else |
|
3648 |
widget.setWindowModified(true); |
|
3649 |
QApplication::instance()->processEvents(); |
|
3650 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3651 |
||
3652 |
widget.setWindowModified(false); |
|
3653 |
QApplication::instance()->processEvents(); |
|
3654 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3655 |
||
3656 |
widget.setWindowTitle("Application Name[*]"); |
|
3657 |
||
3658 |
widget.setWindowModified(true); |
|
3659 |
QApplication::instance()->processEvents(); |
|
3660 |
if (widget.style()->styleHint(QStyle::SH_TitleBar_ModifyNotification, 0, &widget)) |
|
3661 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name*")); |
|
3662 |
else |
|
3663 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3664 |
||
3665 |
widget.setWindowModified(false); |
|
3666 |
QApplication::instance()->processEvents(); |
|
3667 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3668 |
||
3669 |
widget.setWindowTitle("Application[*] Name[*]"); |
|
3670 |
||
3671 |
widget.setWindowModified(true); |
|
3672 |
QApplication::instance()->processEvents(); |
|
3673 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application* Name*")); |
|
3674 |
||
3675 |
widget.setWindowModified(false); |
|
3676 |
QApplication::instance()->processEvents(); |
|
3677 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3678 |
||
3679 |
widget.setWindowTitle("Application Name[*][*]"); |
|
3680 |
||
3681 |
widget.setWindowModified(true); |
|
3682 |
QApplication::instance()->processEvents(); |
|
3683 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name[*]")); |
|
3684 |
||
3685 |
widget.setWindowModified(false); |
|
3686 |
QApplication::instance()->processEvents(); |
|
3687 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name[*]")); |
|
3688 |
||
3689 |
widget.setWindowTitle("Application[*][*] Name[*][*]"); |
|
3690 |
||
3691 |
widget.setWindowModified(true); |
|
3692 |
QApplication::instance()->processEvents(); |
|
3693 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application[*] Name[*]")); |
|
3694 |
||
3695 |
widget.setWindowModified(false); |
|
3696 |
QApplication::instance()->processEvents(); |
|
3697 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application[*] Name[*]")); |
|
3698 |
||
3699 |
widget.setWindowTitle("Application[*] Name[*][*][*]"); |
|
3700 |
||
3701 |
widget.setWindowModified(true); |
|
3702 |
QApplication::instance()->processEvents(); |
|
3703 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application* Name[*]*")); |
|
3704 |
||
3705 |
widget.setWindowModified(false); |
|
3706 |
QApplication::instance()->processEvents(); |
|
3707 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name[*]")); |
|
3708 |
||
3709 |
widget.setWindowTitle("Application[*][*][*] Name[*][*][*]"); |
|
3710 |
||
3711 |
widget.setWindowModified(true); |
|
3712 |
QApplication::instance()->processEvents(); |
|
3713 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application[*]* Name[*]*")); |
|
3714 |
||
3715 |
widget.setWindowModified(false); |
|
3716 |
QApplication::instance()->processEvents(); |
|
3717 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application[*] Name[*]")); |
|
3718 |
#endif |
|
3719 |
} |
|
3720 |
||
3721 |
void tst_QWidget::task110173() |
|
3722 |
{ |
|
3723 |
QWidget w; |
|
3724 |
||
3725 |
QPushButton *pb1 = new QPushButton("click", &w); |
|
3726 |
pb1->setFocusPolicy(Qt::ClickFocus); |
|
3727 |
pb1->move(100, 100); |
|
3728 |
||
3729 |
QPushButton *pb2 = new QPushButton("push", &w); |
|
3730 |
pb2->setFocusPolicy(Qt::ClickFocus); |
|
3731 |
pb2->move(300, 300); |
|
3732 |
||
3733 |
QTest::keyClick( &w, Qt::Key_Tab ); |
|
3734 |
w.show(); |
|
3735 |
QTest::qWaitForWindowShown(&w); |
|
3736 |
QTest::qWait(200); |
|
3737 |
} |
|
3738 |
||
3739 |
class Widget : public QWidget |
|
3740 |
{ |
|
3741 |
public: |
|
3742 |
Widget() : deleteThis(false) { setFocusPolicy(Qt::StrongFocus); } |
|
3743 |
void actionEvent(QActionEvent *) { if (deleteThis) delete this; } |
|
3744 |
void changeEvent(QEvent *) { if (deleteThis) delete this; } |
|
3745 |
void closeEvent(QCloseEvent *) { if (deleteThis) delete this; } |
|
3746 |
void hideEvent(QHideEvent *) { if (deleteThis) delete this; } |
|
3747 |
void focusOutEvent(QFocusEvent *) { if (deleteThis) delete this; } |
|
3748 |
void keyPressEvent(QKeyEvent *) { if (deleteThis) delete this; } |
|
3749 |
void keyReleaseEvent(QKeyEvent *) { if (deleteThis) delete this; } |
|
3750 |
void mouseDoubleClickEvent(QMouseEvent *) { if (deleteThis) delete this; } |
|
3751 |
void mousePressEvent(QMouseEvent *) { if (deleteThis) delete this; } |
|
3752 |
void mouseReleaseEvent(QMouseEvent *) { if (deleteThis) delete this; } |
|
3753 |
void mouseMoveEvent(QMouseEvent *) { if (deleteThis) delete this; } |
|
3754 |
||
3755 |
bool deleteThis; |
|
3756 |
}; |
|
3757 |
||
3758 |
void tst_QWidget::testDeletionInEventHandlers() |
|
3759 |
{ |
|
3760 |
// closeEvent |
|
3761 |
QPointer<Widget> w = new Widget; |
|
3762 |
w->deleteThis = true; |
|
3763 |
w->close(); |
|
3764 |
QVERIFY(w == 0); |
|
3765 |
delete w; |
|
3766 |
||
3767 |
// focusOut (crashes) |
|
3768 |
//w = new Widget; |
|
3769 |
//w->show(); |
|
3770 |
//w->setFocus(); |
|
3771 |
//QVERIFY(qApp->focusWidget() == w); |
|
3772 |
//w->deleteThis = true; |
|
3773 |
//w->clearFocus(); |
|
3774 |
//QVERIFY(w == 0); |
|
3775 |
||
3776 |
// key press |
|
3777 |
w = new Widget; |
|
3778 |
w->show(); |
|
3779 |
w->deleteThis = true; |
|
3780 |
QTest::keyPress(w, Qt::Key_A); |
|
3781 |
QVERIFY(w == 0); |
|
3782 |
delete w; |
|
3783 |
||
3784 |
// key release |
|
3785 |
w = new Widget; |
|
3786 |
w->show(); |
|
3787 |
w->deleteThis = true; |
|
3788 |
QTest::keyRelease(w, Qt::Key_A); |
|
3789 |
QVERIFY(w == 0); |
|
3790 |
delete w; |
|
3791 |
||
3792 |
// mouse press |
|
3793 |
w = new Widget; |
|
3794 |
w->show(); |
|
3795 |
w->deleteThis = true; |
|
3796 |
QTest::mousePress(w, Qt::LeftButton); |
|
3797 |
QVERIFY(w == 0); |
|
3798 |
delete w; |
|
3799 |
||
3800 |
// mouse release |
|
3801 |
w = new Widget; |
|
3802 |
w->show(); |
|
3803 |
w->deleteThis = true; |
|
3804 |
QTest::mouseRelease(w, Qt::LeftButton); |
|
3805 |
QVERIFY(w == 0); |
|
3806 |
delete w; |
|
3807 |
||
3808 |
// mouse double click |
|
3809 |
w = new Widget; |
|
3810 |
w->show(); |
|
3811 |
w->deleteThis = true; |
|
3812 |
QTest::mouseDClick(w, Qt::LeftButton); |
|
3813 |
QVERIFY(w == 0); |
|
3814 |
delete w; |
|
3815 |
||
3816 |
// hide event (crashes) |
|
3817 |
//w = new Widget; |
|
3818 |
//w->show(); |
|
3819 |
//w->deleteThis = true; |
|
3820 |
//w->hide(); |
|
3821 |
//QVERIFY(w == 0); |
|
3822 |
||
3823 |
// action event |
|
3824 |
w = new Widget; |
|
3825 |
w->deleteThis = true; |
|
3826 |
w->addAction(new QAction(w)); |
|
3827 |
QVERIFY(w == 0); |
|
3828 |
delete w; |
|
3829 |
||
3830 |
// change event |
|
3831 |
w = new Widget; |
|
3832 |
w->show(); |
|
3833 |
w->deleteThis = true; |
|
3834 |
w->setMouseTracking(true); |
|
3835 |
QVERIFY(w == 0); |
|
3836 |
delete w; |
|
3837 |
||
3838 |
w = new Widget; |
|
3839 |
w->setMouseTracking(true); |
|
3840 |
w->show(); |
|
3841 |
w->deleteThis = true; |
|
3842 |
QMouseEvent me(QEvent::MouseMove, QPoint(0, 0), Qt::NoButton, Qt::NoButton, Qt::NoModifier); |
|
3843 |
QApplication::sendEvent(w, &me); |
|
3844 |
QVERIFY(w == 0); |
|
3845 |
delete w; |
|
3846 |
} |
|
3847 |
||
3848 |
#ifdef Q_WS_MAC |
|
3849 |
||
3850 |
bool testAndRelease(const HIViewRef view) |
|
3851 |
{ |
|
3852 |
// qDebug() << CFGetRetainCount(view); |
|
3853 |
if (CFGetRetainCount(view) != 2) |
|
3854 |
return false; |
|
3855 |
CFRelease(view); |
|
3856 |
CFRelease(view); |
|
3857 |
return true; |
|
3858 |
} |
|
3859 |
||
3860 |
typedef QPair<QWidget *, HIViewRef> WidgetViewPair; |
|
3861 |
||
3862 |
WidgetViewPair createAndRetain(QWidget * const parent = 0) |
|
3863 |
{ |
|
3864 |
QWidget * const widget = new QWidget(parent); |
|
3865 |
const HIViewRef view = (HIViewRef)widget->winId(); |
|
3866 |
// Retain twice so we can safely call CFGetRetaintCount even if the retain count |
|
3867 |
// is off by one because of a double release. |
|
3868 |
CFRetain(view); |
|
3869 |
CFRetain(view); |
|
3870 |
return qMakePair(widget, view); |
|
3871 |
} |
|
3872 |
||
3873 |
/* |
|
3874 |
Test that retaining and releasing the HIView returned by QWidget::winId() |
|
3875 |
works even if the widget itself is deleted. |
|
3876 |
*/ |
|
3877 |
void tst_QWidget::retainHIView() |
|
3878 |
{ |
|
3879 |
// Single window |
|
3880 |
{ |
|
3881 |
const WidgetViewPair window = createAndRetain(); |
|
3882 |
delete window.first; |
|
3883 |
QVERIFY(testAndRelease(window.second)); |
|
3884 |
} |
|
3885 |
||
3886 |
// Child widget |
|
3887 |
{ |
|
3888 |
const WidgetViewPair parent = createAndRetain(); |
|
3889 |
const WidgetViewPair child = createAndRetain(parent.first); |
|
3890 |
||
3891 |
delete parent.first; |
|
3892 |
QVERIFY(testAndRelease(parent.second)); |
|
3893 |
QVERIFY(testAndRelease(child.second)); |
|
3894 |
} |
|
3895 |
||
3896 |
// Multiple children |
|
3897 |
{ |
|
3898 |
const WidgetViewPair parent = createAndRetain(); |
|
3899 |
const WidgetViewPair child1 = createAndRetain(parent.first); |
|
3900 |
const WidgetViewPair child2 = createAndRetain(parent.first); |
|
3901 |
||
3902 |
delete parent.first; |
|
3903 |
QVERIFY(testAndRelease(parent.second)); |
|
3904 |
QVERIFY(testAndRelease(child1.second)); |
|
3905 |
QVERIFY(testAndRelease(child2.second)); |
|
3906 |
} |
|
3907 |
||
3908 |
// Grandchild widget |
|
3909 |
{ |
|
3910 |
const WidgetViewPair parent = createAndRetain(); |
|
3911 |
const WidgetViewPair child = createAndRetain(parent.first); |
|
3912 |
const WidgetViewPair grandchild = createAndRetain(child.first); |
|
3913 |
||
3914 |
delete parent.first; |
|
3915 |
QVERIFY(testAndRelease(parent.second)); |
|
3916 |
QVERIFY(testAndRelease(child.second)); |
|
3917 |
QVERIFY(testAndRelease(grandchild.second)); |
|
3918 |
} |
|
3919 |
||
3920 |
// Reparent child widget |
|
3921 |
{ |
|
3922 |
const WidgetViewPair parent1 = createAndRetain(); |
|
3923 |
const WidgetViewPair parent2 = createAndRetain(); |
|
3924 |
const WidgetViewPair child = createAndRetain(parent1.first); |
|
3925 |
||
3926 |
child.first->setParent(parent2.first); |
|
3927 |
||
3928 |
delete parent1.first; |
|
3929 |
QVERIFY(testAndRelease(parent1.second)); |
|
3930 |
delete parent2.first; |
|
3931 |
QVERIFY(testAndRelease(parent2.second)); |
|
3932 |
QVERIFY(testAndRelease(child.second)); |
|
3933 |
} |
|
3934 |
||
3935 |
// Reparent window |
|
3936 |
{ |
|
3937 |
const WidgetViewPair window1 = createAndRetain(); |
|
3938 |
const WidgetViewPair window2 = createAndRetain(); |
|
3939 |
const WidgetViewPair child1 = createAndRetain(window1.first); |
|
3940 |
const WidgetViewPair child2 = createAndRetain(window2.first); |
|
3941 |
||
3942 |
window2.first->setParent(window1.first); |
|
3943 |
||
3944 |
delete window2.first; |
|
3945 |
QVERIFY(testAndRelease(window2.second)); |
|
3946 |
QVERIFY(testAndRelease(child2.second)); |
|
3947 |
delete window1.first; |
|
3948 |
QVERIFY(testAndRelease(window1.second)); |
|
3949 |
QVERIFY(testAndRelease(child1.second)); |
|
3950 |
} |
|
3951 |
||
3952 |
// Delete child widget |
|
3953 |
{ |
|
3954 |
const WidgetViewPair parent = createAndRetain(); |
|
3955 |
const WidgetViewPair child = createAndRetain(parent.first); |
|
3956 |
||
3957 |
delete child.first; |
|
3958 |
QVERIFY(testAndRelease(child.second)); |
|
3959 |
delete parent.first; |
|
3960 |
QVERIFY(testAndRelease(parent.second)); |
|
3961 |
} |
|
3962 |
} |
|
3963 |
||
3964 |
void tst_QWidget::sheetOpacity() |
|
3965 |
{ |
|
3966 |
QWidget tmpWindow; |
|
3967 |
QWidget sheet(&tmpWindow, Qt::Sheet); |
|
3968 |
tmpWindow.show(); |
|
3969 |
sheet.show(); |
|
3970 |
QCOMPARE(int(sheet.windowOpacity() * 255), 242); // 95% |
|
3971 |
sheet.setParent(0, Qt::Dialog); |
|
3972 |
QCOMPARE(int(sheet.windowOpacity() * 255), 255); |
|
3973 |
} |
|
3974 |
||
3975 |
class MaskedPainter : public QWidget |
|
3976 |
{ |
|
3977 |
public: |
|
3978 |
QRect mask; |
|
3979 |
||
3980 |
MaskedPainter() |
|
3981 |
: mask(20, 20, 50, 50) |
|
3982 |
{ |
|
3983 |
setMask(mask); |
|
3984 |
} |
|
3985 |
||
3986 |
void paintEvent(QPaintEvent *) |
|
3987 |
{ |
|
3988 |
QPainter p(this); |
|
3989 |
p.fillRect(mask, QColor(Qt::red)); |
|
3990 |
} |
|
3991 |
}; |
|
3992 |
||
3993 |
/* |
|
3994 |
Verifies that the entire area inside the mask is painted red. |
|
3995 |
*/ |
|
3996 |
bool verifyWidgetMask(QWidget *widget, QRect mask) |
|
3997 |
{ |
|
3998 |
const QImage image = QPixmap::grabWindow(widget->winId()).toImage(); |
|
3999 |
||
4000 |
const QImage masked = image.copy(mask); |
|
4001 |
QImage red(masked); |
|
4002 |
red.fill(QColor(Qt::red).rgb()); |
|
4003 |
||
4004 |
return (masked == red); |
|
4005 |
} |
|
4006 |
||
4007 |
void tst_QWidget::setMask() |
|
4008 |
{ |
|
4009 |
testWidget->hide(); // get this out of the way. |
|
4010 |
||
4011 |
{ |
|
4012 |
MaskedPainter w; |
|
4013 |
w.resize(200, 200); |
|
4014 |
w.show(); |
|
4015 |
QTest::qWait(100); |
|
4016 |
QVERIFY(verifyWidgetMask(&w, w.mask)); |
|
4017 |
} |
|
4018 |
{ |
|
4019 |
MaskedPainter w; |
|
4020 |
w.resize(200, 200); |
|
4021 |
w.setWindowFlags(w.windowFlags() | Qt::FramelessWindowHint); |
|
4022 |
w.show(); |
|
4023 |
QTest::qWait(100); |
|
4024 |
QRect mask = w.mask; |
|
4025 |
||
4026 |
QVERIFY(verifyWidgetMask(&w, mask)); |
|
4027 |
} |
|
4028 |
} |
|
4029 |
#endif |
|
4030 |
||
4031 |
class StaticWidget : public QWidget |
|
4032 |
{ |
|
4033 |
Q_OBJECT |
|
4034 |
public: |
|
4035 |
bool partial; |
|
4036 |
bool gotPaintEvent; |
|
4037 |
QRegion paintedRegion; |
|
4038 |
||
4039 |
StaticWidget(QWidget *parent = 0) |
|
4040 |
:QWidget(parent) |
|
4041 |
{ |
|
4042 |
setAttribute(Qt::WA_StaticContents); |
|
4043 |
setAttribute(Qt::WA_OpaquePaintEvent); |
|
4044 |
setPalette(Qt::red); // Make sure we have an opaque palette. |
|
4045 |
setAutoFillBackground(true); |
|
4046 |
gotPaintEvent = false; |
|
4047 |
} |
|
4048 |
||
4049 |
void paintEvent(QPaintEvent *e) |
|
4050 |
{ |
|
4051 |
paintedRegion += e->region(); |
|
4052 |
gotPaintEvent = true; |
|
4053 |
// qDebug() << "paint" << e->region(); |
|
4054 |
// Look for a full update, set partial to false if found. |
|
4055 |
foreach(QRect r, e->region().rects()) { |
|
4056 |
partial = (r != rect()); |
|
4057 |
if (partial == false) |
|
4058 |
break; |
|
4059 |
} |
|
4060 |
} |
|
4061 |
}; |
|
4062 |
||
4063 |
/* |
|
4064 |
Test that widget resizes and moves can be done with minimal repaints when WA_StaticContents |
|
4065 |
and WA_OpaquePaintEvent is set. Test is mac-only for now. |
|
4066 |
*/ |
|
4067 |
void tst_QWidget::optimizedResizeMove() |
|
4068 |
{ |
|
4069 |
QWidget parent; |
|
4070 |
parent.resize(400, 400); |
|
4071 |
||
4072 |
StaticWidget staticWidget(&parent); |
|
4073 |
staticWidget.gotPaintEvent = false; |
|
4074 |
staticWidget.move(150, 150); |
|
4075 |
staticWidget.resize(150, 150); |
|
4076 |
parent.show(); |
|
4077 |
QTest::qWaitForWindowShown(&parent); |
|
4078 |
QTest::qWait(20); |
|
4079 |
QTRY_COMPARE(staticWidget.gotPaintEvent, true); |
|
4080 |
||
4081 |
staticWidget.gotPaintEvent = false; |
|
4082 |
staticWidget.move(staticWidget.pos() + QPoint(10, 10)); |
|
4083 |
QTest::qWait(20); |
|
4084 |
QCOMPARE(staticWidget.gotPaintEvent, false); |
|
4085 |
||
4086 |
staticWidget.gotPaintEvent = false; |
|
4087 |
staticWidget.move(staticWidget.pos() + QPoint(-10, -10)); |
|
4088 |
QTest::qWait(20); |
|
4089 |
QCOMPARE(staticWidget.gotPaintEvent, false); |
|
4090 |
||
4091 |
staticWidget.gotPaintEvent = false; |
|
4092 |
staticWidget.move(staticWidget.pos() + QPoint(-10, 10)); |
|
4093 |
QTest::qWait(20); |
|
4094 |
QCOMPARE(staticWidget.gotPaintEvent, false); |
|
4095 |
||
4096 |
staticWidget.gotPaintEvent = false; |
|
4097 |
staticWidget.resize(staticWidget.size() + QSize(10, 10)); |
|
4098 |
QTest::qWait(20); |
|
4099 |
QCOMPARE(staticWidget.gotPaintEvent, true); |
|
4100 |
QCOMPARE(staticWidget.partial, true); |
|
4101 |
||
4102 |
staticWidget.gotPaintEvent = false; |
|
4103 |
staticWidget.resize(staticWidget.size() + QSize(-10, -10)); |
|
4104 |
QTest::qWait(20); |
|
4105 |
QCOMPARE(staticWidget.gotPaintEvent, false); |
|
4106 |
||
4107 |
staticWidget.gotPaintEvent = false; |
|
4108 |
staticWidget.resize(staticWidget.size() + QSize(10, -10)); |
|
4109 |
QTest::qWait(20); |
|
4110 |
QCOMPARE(staticWidget.gotPaintEvent, true); |
|
4111 |
QCOMPARE(staticWidget.partial, true); |
|
4112 |
||
4113 |
staticWidget.gotPaintEvent = false; |
|
4114 |
staticWidget.move(staticWidget.pos() + QPoint(10, 10)); |
|
4115 |
staticWidget.resize(staticWidget.size() + QSize(-10, -10)); |
|
4116 |
QTest::qWait(20); |
|
4117 |
QCOMPARE(staticWidget.gotPaintEvent, false); |
|
4118 |
||
4119 |
staticWidget.gotPaintEvent = false; |
|
4120 |
staticWidget.move(staticWidget.pos() + QPoint(10, 10)); |
|
4121 |
staticWidget.resize(staticWidget.size() + QSize(10, 10)); |
|
4122 |
QTest::qWait(20); |
|
4123 |
QCOMPARE(staticWidget.gotPaintEvent, true); |
|
4124 |
QCOMPARE(staticWidget.partial, true); |
|
4125 |
||
4126 |
staticWidget.gotPaintEvent = false; |
|
4127 |
staticWidget.move(staticWidget.pos() + QPoint(-10, -10)); |
|
4128 |
staticWidget.resize(staticWidget.size() + QSize(-10, -10)); |
|
4129 |
QTest::qWait(20); |
|
4130 |
QCOMPARE(staticWidget.gotPaintEvent, false); |
|
4131 |
||
4132 |
staticWidget.setAttribute(Qt::WA_StaticContents, false); |
|
4133 |
staticWidget.gotPaintEvent = false; |
|
4134 |
staticWidget.move(staticWidget.pos() + QPoint(-10, -10)); |
|
4135 |
staticWidget.resize(staticWidget.size() + QSize(-10, -10)); |
|
4136 |
QTest::qWait(20); |
|
4137 |
QCOMPARE(staticWidget.gotPaintEvent, true); |
|
4138 |
QCOMPARE(staticWidget.partial, false); |
|
4139 |
staticWidget.setAttribute(Qt::WA_StaticContents, true); |
|
4140 |
||
4141 |
staticWidget.setAttribute(Qt::WA_StaticContents, false); |
|
4142 |
staticWidget.gotPaintEvent = false; |
|
4143 |
staticWidget.move(staticWidget.pos() + QPoint(10, 10)); |
|
4144 |
QTest::qWait(20); |
|
4145 |
QCOMPARE(staticWidget.gotPaintEvent, false); |
|
4146 |
staticWidget.setAttribute(Qt::WA_StaticContents, true); |
|
4147 |
} |
|
4148 |
||
4149 |
void tst_QWidget::optimizedResize_topLevel() |
|
4150 |
{ |
|
4151 |
#if defined(Q_WS_MAC) || defined(Q_WS_QWS) |
|
4152 |
QSKIP("We do not yet have static contents support for *top-levels* on this platform", SkipAll); |
|
4153 |
#endif |
|
4154 |
||
4155 |
StaticWidget topLevel; |
|
4156 |
topLevel.gotPaintEvent = false; |
|
4157 |
topLevel.show(); |
|
4158 |
QTest::qWaitForWindowShown(&topLevel); |
|
4159 |
QTest::qWait(10); |
|
4160 |
QTRY_COMPARE(topLevel.gotPaintEvent, true); |
|
4161 |
||
4162 |
topLevel.gotPaintEvent = false; |
|
4163 |
topLevel.partial = false; |
|
4164 |
topLevel.paintedRegion = QRegion(); |
|
4165 |
||
4166 |
#ifndef Q_WS_WIN |
|
4167 |
topLevel.resize(topLevel.size() + QSize(10, 10)); |
|
4168 |
#else |
|
4169 |
// Static contents does not work when programmatically resizing |
|
4170 |
// top-levels with QWidget::resize. We do some funky stuff in |
|
4171 |
// setGeometry_sys. However, resizing it with the mouse or with |
|
4172 |
// a native function call works (it basically has to go through |
|
4173 |
// WM_RESIZE in QApplication). This is a corner case, though. |
|
4174 |
// See task 243708 |
|
4175 |
const QRect frame = topLevel.frameGeometry(); |
|
4176 |
MoveWindow(topLevel.winId(), frame.x(), frame.y(), |
|
4177 |
frame.width() + 10, frame.height() + 10, |
|
4178 |
true); |
|
4179 |
#endif |
|
4180 |
||
4181 |
QTest::qWait(100); |
|
4182 |
||
4183 |
// Expected update region: New rect - old rect. |
|
4184 |
QRegion expectedUpdateRegion(topLevel.rect()); |
|
4185 |
expectedUpdateRegion -= QRect(QPoint(), topLevel.size() - QSize(10, 10)); |
|
4186 |
||
4187 |
QTRY_COMPARE(topLevel.gotPaintEvent, true); |
|
4188 |
QCOMPARE(topLevel.partial, true); |
|
4189 |
QCOMPARE(topLevel.paintedRegion, expectedUpdateRegion); |
|
4190 |
} |
|
4191 |
||
4192 |
class SiblingDeleter : public QWidget |
|
4193 |
{ |
|
4194 |
public: |
|
4195 |
inline SiblingDeleter(QWidget *sibling, QWidget *parent) |
|
4196 |
: QWidget(parent), sibling(sibling) {} |
|
4197 |
inline virtual ~SiblingDeleter() { delete sibling; } |
|
4198 |
||
4199 |
private: |
|
4200 |
QPointer<QWidget> sibling; |
|
4201 |
}; |
|
4202 |
||
4203 |
||
4204 |
void tst_QWidget::childDeletesItsSibling() |
|
4205 |
{ |
|
4206 |
QWidget *commonParent = new QWidget(0); |
|
4207 |
QPointer<QWidget> child = new QWidget(0); |
|
4208 |
QPointer<QWidget> siblingDeleter = new SiblingDeleter(child, commonParent); |
|
4209 |
child->setParent(commonParent); |
|
4210 |
delete commonParent; // don't crash |
|
4211 |
QVERIFY(!child); |
|
4212 |
QVERIFY(!siblingDeleter); |
|
4213 |
||
4214 |
} |
|
4215 |
||
4216 |
#ifdef Q_WS_QWS |
|
4217 |
# define SET_SAFE_SIZE(w) \ |
|
4218 |
do { \ |
|
4219 |
QSize safeSize(qt_screen->width() - 250, qt_screen->height() - 250); \ |
|
4220 |
if (!safeSize.isValid()) \ |
|
4221 |
QSKIP("Screen size too small", SkipAll); \ |
|
4222 |
if (defaultSize.width() > safeSize.width() || defaultSize.height() > safeSize.height()) { \ |
|
4223 |
defaultSize = safeSize; \ |
|
4224 |
w.resize(defaultSize); \ |
|
4225 |
w.setAttribute(Qt::WA_Resized, false); \ |
|
4226 |
} \ |
|
4227 |
} while (false) |
|
4228 |
#else |
|
4229 |
# define SET_SAFE_SIZE(w) |
|
4230 |
#endif |
|
4231 |
||
4232 |
||
4233 |
void tst_QWidget::setMinimumSize() |
|
4234 |
{ |
|
4235 |
QWidget w; |
|
4236 |
QSize defaultSize = w.size(); |
|
4237 |
SET_SAFE_SIZE(w); |
|
4238 |
||
4239 |
w.setMinimumSize(defaultSize + QSize(100, 100)); |
|
4240 |
QCOMPARE(w.size(), defaultSize + QSize(100, 100)); |
|
4241 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
|
4242 |
||
4243 |
w.setMinimumSize(defaultSize + QSize(50, 50)); |
|
4244 |
QCOMPARE(w.size(), defaultSize + QSize(100, 100)); |
|
4245 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
|
4246 |
||
4247 |
w.setMinimumSize(defaultSize + QSize(200, 200)); |
|
4248 |
QCOMPARE(w.size(), defaultSize + QSize(200, 200)); |
|
4249 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
|
4250 |
||
4251 |
#ifdef Q_OS_WINCE |
|
4252 |
QSKIP("Setting a minimum size larger than the desktop does not work", SkipAll); |
|
4253 |
#endif |
|
4254 |
QSize nonDefaultSize = defaultSize + QSize(5,5); |
|
4255 |
w.setMinimumSize(nonDefaultSize); |
|
4256 |
w.show(); |
|
4257 |
QTest::qWait(50); |
|
4258 |
QVERIFY(w.height() >= nonDefaultSize.height()); |
|
4259 |
QVERIFY(w.width() >= nonDefaultSize.width()); |
|
4260 |
} |
|
4261 |
||
4262 |
void tst_QWidget::setMaximumSize() |
|
4263 |
{ |
|
4264 |
QWidget w; |
|
4265 |
QSize defaultSize = w.size(); |
|
4266 |
SET_SAFE_SIZE(w); |
|
4267 |
||
4268 |
w.setMinimumSize(defaultSize + QSize(100, 100)); |
|
4269 |
QCOMPARE(w.size(), defaultSize + QSize(100, 100)); |
|
4270 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
|
4271 |
w.setMinimumSize(defaultSize); |
|
4272 |
||
4273 |
w.setMaximumSize(defaultSize + QSize(200, 200)); |
|
4274 |
QCOMPARE(w.size(), defaultSize + QSize(100, 100)); |
|
4275 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
|
4276 |
||
4277 |
w.setMaximumSize(defaultSize + QSize(50, 50)); |
|
4278 |
QCOMPARE(w.size(), defaultSize + QSize(50, 50)); |
|
4279 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
|
4280 |
||
4281 |
#if 0 |
|
4282 |
//we don't enforce maximum size on show, apparently |
|
4283 |
QSize nonDefaultSize = defaultSize - QSize(5,5); |
|
4284 |
w.setMaximumSize(nonDefaultSize); |
|
4285 |
w.show(); |
|
4286 |
QTest::qWait(50); |
|
4287 |
qDebug() << nonDefaultSize << w.size(); |
|
4288 |
QVERIFY(w.height() <= nonDefaultSize.height()); |
|
4289 |
QVERIFY(w.width() <= nonDefaultSize.width()); |
|
4290 |
#endif |
|
4291 |
} |
|
4292 |
||
4293 |
void tst_QWidget::setFixedSize() |
|
4294 |
{ |
|
4295 |
QWidget w; |
|
4296 |
QSize defaultSize = w.size(); |
|
4297 |
SET_SAFE_SIZE(w); |
|
4298 |
||
4299 |
w.setFixedSize(defaultSize + QSize(100, 100)); |
|
4300 |
QCOMPARE(w.size(), defaultSize + QSize(100, 100)); |
|
4301 |
QVERIFY(w.testAttribute(Qt::WA_Resized)); |
|
4302 |
||
4303 |
w.setFixedSize(defaultSize + QSize(200, 200)); |
|
4304 |
||
4305 |
QCOMPARE(w.minimumSize(), defaultSize + QSize(200,200)); |
|
4306 |
QCOMPARE(w.maximumSize(), defaultSize + QSize(200,200)); |
|
4307 |
QCOMPARE(w.size(), defaultSize + QSize(200, 200)); |
|
4308 |
QVERIFY(w.testAttribute(Qt::WA_Resized)); |
|
4309 |
||
4310 |
w.setFixedSize(defaultSize + QSize(50, 50)); |
|
4311 |
QCOMPARE(w.size(), defaultSize + QSize(50, 50)); |
|
4312 |
QVERIFY(w.testAttribute(Qt::WA_Resized)); |
|
4313 |
||
4314 |
w.setAttribute(Qt::WA_Resized, false); |
|
4315 |
w.setFixedSize(defaultSize + QSize(50, 50)); |
|
4316 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
|
4317 |
||
4318 |
w.setFixedSize(defaultSize + QSize(150, 150)); |
|
4319 |
w.show(); |
|
4320 |
QTest::qWait(50); |
|
4321 |
QVERIFY(w.size() == defaultSize + QSize(150,150)); |
|
4322 |
} |
|
4323 |
||
4324 |
void tst_QWidget::ensureCreated() |
|
4325 |
{ |
|
4326 |
{ |
|
4327 |
QWidget widget; |
|
4328 |
WId widgetWinId = widget.winId(); |
|
4329 |
Q_UNUSED(widgetWinId); |
|
4330 |
QVERIFY(widget.testAttribute(Qt::WA_WState_Created)); |
|
4331 |
} |
|
4332 |
||
4333 |
{ |
|
4334 |
QWidget window; |
|
4335 |
||
4336 |
QDialog dialog(&window); |
|
4337 |
dialog.setWindowModality(Qt::NonModal); |
|
4338 |
||
4339 |
WId dialogWinId = dialog.winId(); |
|
4340 |
Q_UNUSED(dialogWinId); |
|
4341 |
QVERIFY(dialog.testAttribute(Qt::WA_WState_Created)); |
|
4342 |
QVERIFY(window.testAttribute(Qt::WA_WState_Created)); |
|
4343 |
} |
|
4344 |
||
4345 |
{ |
|
4346 |
QWidget window; |
|
4347 |
||
4348 |
QDialog dialog(&window); |
|
4349 |
dialog.setWindowModality(Qt::WindowModal); |
|
4350 |
||
4351 |
WId dialogWinId = dialog.winId(); |
|
4352 |
Q_UNUSED(dialogWinId); |
|
4353 |
QVERIFY(dialog.testAttribute(Qt::WA_WState_Created)); |
|
4354 |
QVERIFY(window.testAttribute(Qt::WA_WState_Created)); |
|
4355 |
} |
|
4356 |
||
4357 |
{ |
|
4358 |
QWidget window; |
|
4359 |
||
4360 |
QDialog dialog(&window); |
|
4361 |
dialog.setWindowModality(Qt::ApplicationModal); |
|
4362 |
||
4363 |
WId dialogWinId = dialog.winId(); |
|
4364 |
Q_UNUSED(dialogWinId); |
|
4365 |
QVERIFY(dialog.testAttribute(Qt::WA_WState_Created)); |
|
4366 |
QVERIFY(window.testAttribute(Qt::WA_WState_Created)); |
|
4367 |
} |
|
4368 |
} |
|
4369 |
||
4370 |
class WinIdChangeWidget : public QWidget { |
|
4371 |
public: |
|
4372 |
WinIdChangeWidget(QWidget *p = 0) |
|
4373 |
: QWidget(p) |
|
4374 |
, m_winIdChangeEventCount(0) |
|
4375 |
{ |
|
4376 |
||
4377 |
} |
|
4378 |
protected: |
|
4379 |
bool event(QEvent *e) |
|
4380 |
{ |
|
4381 |
if (e->type() == QEvent::WinIdChange) { |
|
4382 |
++m_winIdChangeEventCount; |
|
4383 |
return true; |
|
4384 |
} |
|
4385 |
return QWidget::event(e); |
|
4386 |
} |
|
4387 |
public: |
|
4388 |
int m_winIdChangeEventCount; |
|
4389 |
}; |
|
4390 |
||
4391 |
void tst_QWidget::winIdChangeEvent() |
|
4392 |
{ |
|
4393 |
{ |
|
4394 |
// Transforming an alien widget into a native widget |
|
4395 |
WinIdChangeWidget widget; |
|
4396 |
const WId winIdBefore = widget.internalWinId(); |
|
4397 |
const WId winIdAfter = widget.winId(); |
|
4398 |
QVERIFY(winIdBefore != winIdAfter); |
|
4399 |
QCOMPARE(widget.m_winIdChangeEventCount, 1); |
|
4400 |
} |
|
4401 |
||
4402 |
{ |
|
4403 |
// Changing parent of a native widget |
|
4404 |
// Should cause winId of child to change, on all platforms |
|
4405 |
QWidget parent1, parent2; |
|
4406 |
WinIdChangeWidget child(&parent1); |
|
4407 |
const WId winIdBefore = child.winId(); |
|
4408 |
QCOMPARE(child.m_winIdChangeEventCount, 1); |
|
4409 |
child.setParent(&parent2); |
|
4410 |
const WId winIdAfter = child.internalWinId(); |
|
4411 |
QVERIFY(winIdBefore != winIdAfter); |
|
4412 |
QCOMPARE(child.m_winIdChangeEventCount, 2); |
|
4413 |
} |
|
4414 |
||
4415 |
{ |
|
4416 |
// Changing grandparent of a native widget |
|
4417 |
// Should cause winId of grandchild to change only on Symbian |
|
4418 |
QWidget grandparent1, grandparent2; |
|
4419 |
QWidget parent(&grandparent1); |
|
4420 |
WinIdChangeWidget child(&parent); |
|
4421 |
const WId winIdBefore = child.winId(); |
|
4422 |
QCOMPARE(child.m_winIdChangeEventCount, 1); |
|
4423 |
parent.setParent(&grandparent2); |
|
4424 |
const WId winIdAfter = child.internalWinId(); |
|
4425 |
#ifdef Q_OS_SYMBIAN |
|
4426 |
QVERIFY(winIdBefore != winIdAfter); |
|
4427 |
QCOMPARE(child.m_winIdChangeEventCount, 2); |
|
4428 |
#else |
|
4429 |
QCOMPARE(winIdBefore, winIdAfter); |
|
4430 |
QCOMPARE(child.m_winIdChangeEventCount, 1); |
|
4431 |
#endif |
|
4432 |
} |
|
4433 |
||
4434 |
{ |
|
4435 |
// Changing parent of an alien widget |
|
4436 |
QWidget parent1, parent2; |
|
4437 |
WinIdChangeWidget child(&parent1); |
|
4438 |
const WId winIdBefore = child.internalWinId(); |
|
4439 |
child.setParent(&parent2); |
|
4440 |
const WId winIdAfter = child.internalWinId(); |
|
4441 |
QCOMPARE(winIdBefore, winIdAfter); |
|
4442 |
QCOMPARE(child.m_winIdChangeEventCount, 0); |
|
4443 |
} |
|
4444 |
||
4445 |
{ |
|
4446 |
// Making native child widget into a top-level window |
|
4447 |
QWidget parent; |
|
4448 |
WinIdChangeWidget child(&parent); |
|
4449 |
child.winId(); |
|
4450 |
const WId winIdBefore = child.internalWinId(); |
|
4451 |
QCOMPARE(child.m_winIdChangeEventCount, 1); |
|
4452 |
const Qt::WindowFlags flags = child.windowFlags(); |
|
4453 |
child.setWindowFlags(flags | Qt::Window); |
|
4454 |
const WId winIdAfter = child.internalWinId(); |
|
4455 |
QVERIFY(winIdBefore != winIdAfter); |
|
4456 |
QCOMPARE(child.m_winIdChangeEventCount, 2); |
|
4457 |
} |
|
4458 |
} |
|
4459 |
||
4460 |
#ifdef Q_OS_SYMBIAN |
|
4461 |
void tst_QWidget::reparentCausesChildWinIdChange() |
|
4462 |
{ |
|
4463 |
QWidget *parent = new QWidget; |
|
4464 |
QWidget *w1 = new QWidget; |
|
4465 |
QWidget *w2 = new QWidget; |
|
4466 |
QWidget *w3 = new QWidget; |
|
4467 |
w1->setParent(parent); |
|
4468 |
w2->setParent(w1); |
|
4469 |
w3->setParent(w2); |
|
4470 |
||
4471 |
WId winId1 = w1->winId(); |
|
4472 |
WId winId2 = w2->winId(); |
|
4473 |
WId winId3 = w3->winId(); |
|
4474 |
||
4475 |
// reparenting causes winIds of the widget being reparented, and all of its children, to change |
|
4476 |
w1->setParent(0); |
|
4477 |
QVERIFY(w1->winId() != winId1); |
|
4478 |
winId1 = w1->winId(); |
|
4479 |
QVERIFY(w2->winId() != winId2); |
|
4480 |
winId2 = w2->winId(); |
|
4481 |
QVERIFY(w3->winId() != winId3); |
|
4482 |
winId3 = w3->winId(); |
|
4483 |
||
4484 |
w1->setParent(parent); |
|
4485 |
QVERIFY(w1->winId() != winId1); |
|
4486 |
winId1 = w1->winId(); |
|
4487 |
QVERIFY(w2->winId() != winId2); |
|
4488 |
winId2 = w2->winId(); |
|
4489 |
QVERIFY(w3->winId() != winId3); |
|
4490 |
winId3 = w3->winId(); |
|
4491 |
||
4492 |
w2->setParent(0); |
|
4493 |
QVERIFY(w2->winId() != winId2); |
|
4494 |
winId2 = w2->winId(); |
|
4495 |
QVERIFY(w3->winId() != winId3); |
|
4496 |
winId3 = w3->winId(); |
|
4497 |
||
4498 |
w2->setParent(parent); |
|
4499 |
QVERIFY(w2->winId() != winId2); |
|
4500 |
winId2 = w2->winId(); |
|
4501 |
QVERIFY(w3->winId() != winId3); |
|
4502 |
winId3 = w3->winId(); |
|
4503 |
||
4504 |
w2->setParent(w1); |
|
4505 |
QVERIFY(w2->winId() != winId2); |
|
4506 |
winId2 = w2->winId(); |
|
4507 |
QVERIFY(w3->winId() != winId3); |
|
4508 |
winId3 = w3->winId(); |
|
4509 |
||
4510 |
w3->setParent(0); |
|
4511 |
QVERIFY(w3->winId() != winId3); |
|
4512 |
winId3 = w3->winId(); |
|
4513 |
||
4514 |
w3->setParent(w1); |
|
4515 |
QVERIFY(w3->winId() != winId3); |
|
4516 |
winId3 = w3->winId(); |
|
4517 |
||
4518 |
w3->setParent(w2); |
|
4519 |
QVERIFY(w3->winId() != winId3); |
|
4520 |
winId3 = w3->winId(); |
|
4521 |
||
4522 |
delete parent; |
|
4523 |
} |
|
4524 |
#else |
|
4525 |
void tst_QWidget::persistentWinId() |
|
4526 |
{ |
|
4527 |
QWidget *parent = new QWidget; |
|
4528 |
QWidget *w1 = new QWidget; |
|
4529 |
QWidget *w2 = new QWidget; |
|
4530 |
QWidget *w3 = new QWidget; |
|
4531 |
w1->setParent(parent); |
|
4532 |
w2->setParent(w1); |
|
4533 |
w3->setParent(w2); |
|
4534 |
||
4535 |
WId winId1 = w1->winId(); |
|
4536 |
WId winId2 = w2->winId(); |
|
4537 |
WId winId3 = w3->winId(); |
|
4538 |
||
4539 |
// reparenting should change the winId of the widget being reparented, but not of its children |
|
4540 |
w1->setParent(0); |
|
4541 |
QVERIFY(w1->winId() != winId1); |
|
4542 |
winId1 = w1->winId(); |
|
4543 |
QCOMPARE(w2->winId(), winId2); |
|
4544 |
QCOMPARE(w3->winId(), winId3); |
|
4545 |
||
4546 |
w1->setParent(parent); |
|
4547 |
QVERIFY(w1->winId() != winId1); |
|
4548 |
winId1 = w1->winId(); |
|
4549 |
QCOMPARE(w2->winId(), winId2); |
|
4550 |
QCOMPARE(w3->winId(), winId3); |
|
4551 |
||
4552 |
w2->setParent(0); |
|
4553 |
QVERIFY(w2->winId() != winId2); |
|
4554 |
winId2 = w2->winId(); |
|
4555 |
QCOMPARE(w3->winId(), winId3); |
|
4556 |
||
4557 |
w2->setParent(parent); |
|
4558 |
QVERIFY(w2->winId() != winId2); |
|
4559 |
winId2 = w2->winId(); |
|
4560 |
QCOMPARE(w3->winId(), winId3); |
|
4561 |
||
4562 |
w2->setParent(w1); |
|
4563 |
QVERIFY(w2->winId() != winId2); |
|
4564 |
winId2 = w2->winId(); |
|
4565 |
QCOMPARE(w3->winId(), winId3); |
|
4566 |
||
4567 |
w3->setParent(0); |
|
4568 |
QVERIFY(w3->winId() != winId3); |
|
4569 |
winId3 = w3->winId(); |
|
4570 |
||
4571 |
w3->setParent(w1); |
|
4572 |
QVERIFY(w3->winId() != winId3); |
|
4573 |
winId3 = w3->winId(); |
|
4574 |
||
4575 |
w3->setParent(w2); |
|
4576 |
QVERIFY(w3->winId() != winId3); |
|
4577 |
winId3 = w3->winId(); |
|
4578 |
||
4579 |
delete parent; |
|
4580 |
} |
|
4581 |
#endif // Q_OS_SYMBIAN |
|
4582 |
||
4583 |
class ShowHideEventWidget : public QWidget |
|
4584 |
{ |
|
4585 |
public: |
|
4586 |
int numberOfShowEvents, numberOfHideEvents; |
|
4587 |
||
4588 |
ShowHideEventWidget(QWidget *parent = 0) |
|
4589 |
: QWidget(parent), numberOfShowEvents(0), numberOfHideEvents(0) |
|
4590 |
{ } |
|
4591 |
||
4592 |
void create() |
|
4593 |
{ QWidget::create(); } |
|
4594 |
||
4595 |
void showEvent(QShowEvent *) |
|
4596 |
{ ++numberOfShowEvents; } |
|
4597 |
||
4598 |
void hideEvent(QHideEvent *) |
|
4599 |
{ ++numberOfHideEvents; } |
|
4600 |
}; |
|
4601 |
||
4602 |
void tst_QWidget::showHideEvent_data() |
|
4603 |
{ |
|
4604 |
QTest::addColumn<bool>("show"); |
|
4605 |
QTest::addColumn<bool>("hide"); |
|
4606 |
QTest::addColumn<bool>("create"); |
|
4607 |
QTest::addColumn<int>("expectedShowEvents"); |
|
4608 |
QTest::addColumn<int>("expectedHideEvents"); |
|
4609 |
||
4610 |
QTest::newRow("window: only show") |
|
4611 |
<< true |
|
4612 |
<< false |
|
4613 |
<< false |
|
4614 |
<< 1 |
|
4615 |
<< 0; |
|
4616 |
QTest::newRow("window: show/hide") |
|
4617 |
<< true |
|
4618 |
<< true |
|
4619 |
<< false |
|
4620 |
<< 1 |
|
4621 |
<< 1; |
|
4622 |
QTest::newRow("window: show/hide/create") |
|
4623 |
<< true |
|
4624 |
<< true |
|
4625 |
<< true |
|
4626 |
<< 1 |
|
4627 |
<< 1; |
|
4628 |
QTest::newRow("window: hide/create") |
|
4629 |
<< false |
|
4630 |
<< true |
|
4631 |
<< true |
|
4632 |
<< 0 |
|
4633 |
<< 0; |
|
4634 |
QTest::newRow("window: only hide") |
|
4635 |
<< false |
|
4636 |
<< true |
|
4637 |
<< false |
|
4638 |
<< 0 |
|
4639 |
<< 0; |
|
4640 |
QTest::newRow("window: nothing") |
|
4641 |
<< false |
|
4642 |
<< false |
|
4643 |
<< false |
|
4644 |
<< 0 |
|
4645 |
<< 0; |
|
4646 |
} |
|
4647 |
||
4648 |
void tst_QWidget::showHideEvent() |
|
4649 |
{ |
|
4650 |
QFETCH(bool, show); |
|
4651 |
QFETCH(bool, hide); |
|
4652 |
QFETCH(bool, create); |
|
4653 |
QFETCH(int, expectedShowEvents); |
|
4654 |
QFETCH(int, expectedHideEvents); |
|
4655 |
||
4656 |
ShowHideEventWidget widget; |
|
4657 |
if (show) |
|
4658 |
widget.show(); |
|
4659 |
if (hide) |
|
4660 |
widget.hide(); |
|
4661 |
if (create && !widget.testAttribute(Qt::WA_WState_Created)) |
|
4662 |
widget.create(); |
|
4663 |
||
4664 |
QCOMPARE(widget.numberOfShowEvents, expectedShowEvents); |
|
4665 |
QCOMPARE(widget.numberOfHideEvents, expectedHideEvents); |
|
4666 |
} |
|
4667 |
||
4668 |
void tst_QWidget::update() |
|
4669 |
{ |
|
4670 |
QTest::qWait(10); // Wait for the initStuff to do it's stuff. |
|
4671 |
Q_CHECK_PAINTEVENTS |
|
4672 |
||
4673 |
UpdateWidget w; |
|
4674 |
w.setGeometry(50, 50, 100, 100); |
|
4675 |
w.show(); |
|
4676 |
QTest::qWaitForWindowShown(&w); |
|
4677 |
||
4678 |
QApplication::processEvents(); |
|
4679 |
QApplication::processEvents(); |
|
4680 |
||
4681 |
QTRY_COMPARE(w.numPaintEvents, 1); |
|
4682 |
||
4683 |
QCOMPARE(w.visibleRegion(), QRegion(w.rect())); |
|
4684 |
QCOMPARE(w.paintedRegion, w.visibleRegion()); |
|
4685 |
w.reset(); |
|
4686 |
||
4687 |
UpdateWidget child(&w); |
|
4688 |
child.setGeometry(10, 10, 80, 80); |
|
4689 |
child.show(); |
|
4690 |
||
4691 |
QPoint childOffset = child.mapToParent(QPoint()); |
|
4692 |
||
4693 |
// widgets are transparent by default, so both should get repaints |
|
4694 |
{ |
|
4695 |
QApplication::processEvents(); |
|
4696 |
QApplication::processEvents(); |
|
4697 |
QCOMPARE(child.numPaintEvents, 1); |
|
4698 |
QCOMPARE(child.visibleRegion(), QRegion(child.rect())); |
|
4699 |
QCOMPARE(child.paintedRegion, child.visibleRegion()); |
|
4700 |
QCOMPARE(w.numPaintEvents, 1); |
|
4701 |
QCOMPARE(w.visibleRegion(), QRegion(w.rect())); |
|
4702 |
QCOMPARE(w.paintedRegion, child.visibleRegion().translated(childOffset)); |
|
4703 |
||
4704 |
w.reset(); |
|
4705 |
child.reset(); |
|
4706 |
||
4707 |
w.update(); |
|
4708 |
QApplication::processEvents(); |
|
4709 |
QApplication::processEvents(); |
|
4710 |
QCOMPARE(child.numPaintEvents, 1); |
|
4711 |
QCOMPARE(child.visibleRegion(), QRegion(child.rect())); |
|
4712 |
QCOMPARE(child.paintedRegion, child.visibleRegion()); |
|
4713 |
QCOMPARE(w.numPaintEvents, 1); |
|
4714 |
QCOMPARE(w.visibleRegion(), QRegion(w.rect())); |
|
4715 |
QCOMPARE(w.paintedRegion, w.visibleRegion()); |
|
4716 |
} |
|
4717 |
||
4718 |
QPalette opaquePalette = child.palette(); |
|
4719 |
opaquePalette.setColor(child.backgroundRole(), QColor(Qt::red)); |
|
4720 |
||
4721 |
// setting an opaque background on the child should prevent paint-events |
|
4722 |
// for the parent in the child area |
|
4723 |
{ |
|
4724 |
child.setPalette(opaquePalette); |
|
4725 |
child.setAutoFillBackground(true); |
|
4726 |
QApplication::processEvents(); |
|
4727 |
||
4728 |
w.reset(); |
|
4729 |
child.reset(); |
|
4730 |
||
4731 |
w.update(); |
|
4732 |
QApplication::processEvents(); |
|
4733 |
QApplication::processEvents(); |
|
4734 |
||
4735 |
QCOMPARE(w.numPaintEvents, 1); |
|
4736 |
QRegion expectedVisible = QRegion(w.rect()) |
|
4737 |
- child.visibleRegion().translated(childOffset); |
|
4738 |
QCOMPARE(w.visibleRegion(), expectedVisible); |
|
4739 |
#ifdef QT_MAC_USE_COCOA |
|
4740 |
QEXPECT_FAIL(0, "Cocoa compositor paints the content view", Continue); |
|
4741 |
#endif |
|
4742 |
QCOMPARE(w.paintedRegion, expectedVisible); |
|
4743 |
#ifdef QT_MAC_USE_COCOA |
|
4744 |
QEXPECT_FAIL(0, "Cocoa compositor says to paint this.", Continue); |
|
4745 |
#endif |
|
4746 |
QCOMPARE(child.numPaintEvents, 0); |
|
4747 |
||
4748 |
w.reset(); |
|
4749 |
child.reset(); |
|
4750 |
||
4751 |
child.update(); |
|
4752 |
QApplication::processEvents(); |
|
4753 |
QApplication::processEvents(); |
|
4754 |
||
4755 |
QCOMPARE(w.numPaintEvents, 0); |
|
4756 |
QCOMPARE(child.numPaintEvents, 1); |
|
4757 |
QCOMPARE(child.paintedRegion, child.visibleRegion()); |
|
4758 |
||
4759 |
w.reset(); |
|
4760 |
child.reset(); |
|
4761 |
} |
|
4762 |
||
4763 |
// overlapping sibling |
|
4764 |
UpdateWidget sibling(&w); |
|
4765 |
child.setGeometry(10, 10, 20, 20); |
|
4766 |
sibling.setGeometry(15, 15, 20, 20); |
|
4767 |
sibling.show(); |
|
4768 |
||
4769 |
QApplication::processEvents(); |
|
4770 |
w.reset(); |
|
4771 |
child.reset(); |
|
4772 |
sibling.reset(); |
|
4773 |
||
4774 |
const QPoint siblingOffset = sibling.mapToParent(QPoint()); |
|
4775 |
||
4776 |
sibling.update(); |
|
4777 |
QApplication::processEvents(); |
|
4778 |
QApplication::processEvents(); |
|
4779 |
||
4780 |
// child is opaque, sibling transparent |
|
4781 |
{ |
|
4782 |
QCOMPARE(sibling.numPaintEvents, 1); |
|
4783 |
QCOMPARE(sibling.paintedRegion, sibling.visibleRegion()); |
|
4784 |
||
4785 |
QCOMPARE(child.numPaintEvents, 1); |
|
4786 |
QCOMPARE(child.paintedRegion.translated(childOffset), |
|
4787 |
child.visibleRegion().translated(childOffset) |
|
4788 |
& sibling.visibleRegion().translated(siblingOffset)); |
|
4789 |
||
4790 |
QCOMPARE(w.numPaintEvents, 1); |
|
4791 |
#ifdef QT_MAC_USE_COCOA |
|
4792 |
QEXPECT_FAIL(0, "Cocoa compositor paints the content view", Continue); |
|
4793 |
#endif |
|
4794 |
QCOMPARE(w.paintedRegion, |
|
4795 |
w.visibleRegion() & sibling.visibleRegion().translated(siblingOffset)); |
|
4796 |
#ifdef QT_MAC_USE_COCOA |
|
4797 |
QEXPECT_FAIL(0, "Cocoa compositor paints the content view", Continue); |
|
4798 |
#endif |
|
4799 |
QCOMPARE(w.paintedRegion, |
|
4800 |
(w.visibleRegion() - child.visibleRegion().translated(childOffset)) |
|
4801 |
& sibling.visibleRegion().translated(siblingOffset)); |
|
4802 |
||
4803 |
} |
|
4804 |
w.reset(); |
|
4805 |
child.reset(); |
|
4806 |
sibling.reset(); |
|
4807 |
||
4808 |
sibling.setPalette(opaquePalette); |
|
4809 |
sibling.setAutoFillBackground(true); |
|
4810 |
||
4811 |
sibling.update(); |
|
4812 |
QApplication::processEvents(); |
|
4813 |
QApplication::processEvents(); |
|
4814 |
||
4815 |
// child opaque, sibling opaque |
|
4816 |
{ |
|
4817 |
QCOMPARE(sibling.numPaintEvents, 1); |
|
4818 |
QCOMPARE(sibling.paintedRegion, sibling.visibleRegion()); |
|
4819 |
||
4820 |
#ifdef QT_MAC_USE_COCOA |
|
4821 |
QEXPECT_FAIL(0, "Cocoa compositor paints child and sibling", Continue); |
|
4822 |
#endif |
|
4823 |
QCOMPARE(child.numPaintEvents, 0); |
|
4824 |
QCOMPARE(child.visibleRegion(), |
|
4825 |
QRegion(child.rect()) |
|
4826 |
- sibling.visibleRegion().translated(siblingOffset - childOffset)); |
|
4827 |
||
4828 |
QCOMPARE(w.numPaintEvents, 0); |
|
4829 |
QCOMPARE(w.visibleRegion(), |
|
4830 |
QRegion(w.rect()) |
|
4831 |
- child.visibleRegion().translated(childOffset) |
|
4832 |
- sibling.visibleRegion().translated(siblingOffset)); |
|
4833 |
} |
|
4834 |
} |
|
4835 |
||
4836 |
static inline bool isOpaque(QWidget *widget) |
|
4837 |
{ |
|
4838 |
if (!widget) |
|
4839 |
return false; |
|
4840 |
return qt_widget_private(widget)->isOpaque; |
|
4841 |
} |
|
4842 |
||
4843 |
void tst_QWidget::isOpaque() |
|
4844 |
{ |
|
4845 |
#ifndef Q_WS_MAC |
|
4846 |
QWidget w; |
|
4847 |
QVERIFY(::isOpaque(&w)); |
|
4848 |
||
4849 |
QWidget child(&w); |
|
4850 |
QVERIFY(!::isOpaque(&child)); |
|
4851 |
||
4852 |
child.setAutoFillBackground(true); |
|
4853 |
QVERIFY(::isOpaque(&child)); |
|
4854 |
||
4855 |
QPalette palette; |
|
4856 |
||
4857 |
// background color |
|
4858 |
||
4859 |
palette = child.palette(); |
|
4860 |
palette.setColor(child.backgroundRole(), QColor(255, 0, 0, 127)); |
|
4861 |
child.setPalette(palette); |
|
4862 |
QVERIFY(!::isOpaque(&child)); |
|
4863 |
||
4864 |
palette.setColor(child.backgroundRole(), QColor(255, 0, 0, 255)); |
|
4865 |
child.setPalette(palette); |
|
4866 |
QVERIFY(::isOpaque(&child)); |
|
4867 |
||
4868 |
palette.setColor(QPalette::Window, QColor(0, 0, 255, 127)); |
|
4869 |
w.setPalette(palette); |
|
4870 |
||
4871 |
QVERIFY(!::isOpaque(&w)); |
|
4872 |
||
4873 |
child.setAutoFillBackground(false); |
|
4874 |
QVERIFY(!::isOpaque(&child)); |
|
4875 |
||
4876 |
// Qt::WA_OpaquePaintEvent |
|
4877 |
||
4878 |
child.setAttribute(Qt::WA_OpaquePaintEvent); |
|
4879 |
QVERIFY(::isOpaque(&child)); |
|
4880 |
||
4881 |
child.setAttribute(Qt::WA_OpaquePaintEvent, false); |
|
4882 |
QVERIFY(!::isOpaque(&child)); |
|
4883 |
||
4884 |
// Qt::WA_NoSystemBackground |
|
4885 |
||
4886 |
child.setAttribute(Qt::WA_NoSystemBackground); |
|
4887 |
QVERIFY(!::isOpaque(&child)); |
|
4888 |
||
4889 |
child.setAttribute(Qt::WA_NoSystemBackground, false); |
|
4890 |
QVERIFY(!::isOpaque(&child)); |
|
4891 |
||
4892 |
palette.setColor(QPalette::Window, QColor(0, 0, 255, 255)); |
|
4893 |
w.setPalette(palette); |
|
4894 |
QVERIFY(::isOpaque(&w)); |
|
4895 |
||
4896 |
w.setAttribute(Qt::WA_NoSystemBackground); |
|
4897 |
QVERIFY(!::isOpaque(&w)); |
|
4898 |
||
4899 |
w.setAttribute(Qt::WA_NoSystemBackground, false); |
|
4900 |
QVERIFY(::isOpaque(&w)); |
|
4901 |
||
4902 |
{ |
|
4903 |
QPalette palette = QApplication::palette(); |
|
4904 |
QPalette old = palette; |
|
4905 |
palette.setColor(QPalette::Window, Qt::transparent); |
|
4906 |
QApplication::setPalette(palette); |
|
4907 |
||
4908 |
QWidget widget; |
|
4909 |
QVERIFY(!::isOpaque(&widget)); |
|
4910 |
||
4911 |
QApplication::setPalette(old); |
|
4912 |
QCOMPARE(::isOpaque(&widget), old.color(QPalette::Window).alpha() == 255); |
|
4913 |
} |
|
4914 |
#endif |
|
4915 |
} |
|
4916 |
||
4917 |
#ifndef Q_WS_MAC |
|
4918 |
/* |
|
4919 |
Test that scrolling of a widget invalidates the correct regions |
|
4920 |
*/ |
|
4921 |
void tst_QWidget::scroll() |
|
4922 |
{ |
|
4923 |
UpdateWidget updateWidget; |
|
4924 |
updateWidget.resize(500, 500); |
|
4925 |
updateWidget.reset(); |
|
4926 |
updateWidget.show(); |
|
4927 |
QTest::qWaitForWindowShown(&updateWidget); |
|
4928 |
QTest::qWait(50); |
|
4929 |
qApp->processEvents(); |
|
4930 |
QTRY_VERIFY(updateWidget.numPaintEvents > 0); |
|
4931 |
||
4932 |
{ |
|
4933 |
updateWidget.reset(); |
|
4934 |
updateWidget.scroll(10, 10); |
|
4935 |
qApp->processEvents(); |
|
4936 |
QRegion dirty(QRect(0, 0, 500, 10)); |
|
4937 |
dirty += QRegion(QRect(0, 10, 10, 490)); |
|
4938 |
QCOMPARE(updateWidget.paintedRegion, dirty); |
|
4939 |
} |
|
4940 |
||
4941 |
{ |
|
4942 |
updateWidget.reset(); |
|
4943 |
updateWidget.update(0, 0, 10, 10); |
|
4944 |
updateWidget.scroll(0, 10); |
|
4945 |
qApp->processEvents(); |
|
4946 |
QRegion dirty(QRect(0, 0, 500, 10)); |
|
4947 |
dirty += QRegion(QRect(0, 10, 10, 10)); |
|
4948 |
QCOMPARE(updateWidget.paintedRegion, dirty); |
|
4949 |
} |
|
4950 |
||
4951 |
{ |
|
4952 |
updateWidget.reset(); |
|
4953 |
updateWidget.update(0, 0, 100, 100); |
|
4954 |
updateWidget.scroll(10, 10, QRect(50, 50, 100, 100)); |
|
4955 |
qApp->processEvents(); |
|
4956 |
QRegion dirty(QRect(0, 0, 100, 50)); |
|
4957 |
dirty += QRegion(QRect(0, 50, 150, 10)); |
|
4958 |
dirty += QRegion(QRect(0, 60, 110, 40)); |
|
4959 |
dirty += QRegion(QRect(50, 100, 60, 10)); |
|
4960 |
dirty += QRegion(QRect(50, 110, 10, 40)); |
|
4961 |
QCOMPARE(updateWidget.paintedRegion, dirty); |
|
4962 |
} |
|
4963 |
||
4964 |
{ |
|
4965 |
updateWidget.reset(); |
|
4966 |
updateWidget.update(0, 0, 100, 100); |
|
4967 |
updateWidget.scroll(10, 10, QRect(100, 100, 100, 100)); |
|
4968 |
qApp->processEvents(); |
|
4969 |
QRegion dirty(QRect(0, 0, 100, 100)); |
|
4970 |
dirty += QRegion(QRect(100, 100, 100, 10)); |
|
4971 |
dirty += QRegion(QRect(100, 110, 10, 90)); |
|
4972 |
QCOMPARE(updateWidget.paintedRegion, dirty); |
|
4973 |
} |
|
4974 |
} |
|
4975 |
#endif |
|
4976 |
||
4977 |
class DestroyedSlotChecker : public QObject |
|
4978 |
{ |
|
4979 |
Q_OBJECT |
|
4980 |
||
4981 |
public: |
|
4982 |
bool wasQWidget; |
|
4983 |
||
4984 |
DestroyedSlotChecker() |
|
4985 |
: wasQWidget(false) |
|
4986 |
{ |
|
4987 |
} |
|
4988 |
||
4989 |
public slots: |
|
4990 |
void destroyedSlot(QObject *object) |
|
4991 |
{ |
|
4992 |
wasQWidget = (qobject_cast<QWidget *>(object) != 0 || object->isWidgetType()); |
|
4993 |
} |
|
4994 |
}; |
|
4995 |
||
4996 |
/* |
|
4997 |
Test that qobject_cast<QWidget*> returns 0 in a slot |
|
4998 |
connected to QObject::destroyed. |
|
4999 |
*/ |
|
5000 |
void tst_QWidget::qobject_castInDestroyedSlot() |
|
5001 |
{ |
|
5002 |
DestroyedSlotChecker checker; |
|
5003 |
QWidget *widget = new QWidget(); |
|
5004 |
||
5005 |
QObject::connect(widget, SIGNAL(destroyed(QObject *)), &checker, SLOT(destroyedSlot(QObject *))); |
|
5006 |
delete widget; |
|
5007 |
||
5008 |
QVERIFY(checker.wasQWidget == true); |
|
5009 |
} |
|
5010 |
||
5011 |
Q_DECLARE_METATYPE(QList<QRect>) |
|
5012 |
||
5013 |
void tst_QWidget::setWindowGeometry_data() |
|
5014 |
{ |
|
5015 |
QTest::addColumn<QList<QRect> >("rects"); |
|
5016 |
QTest::addColumn<int>("windowFlags"); |
|
5017 |
||
5018 |
QList<QList<QRect> > rects; |
|
5019 |
rects << (QList<QRect>() |
|
5020 |
<< QRect(100, 100, 200, 200) |
|
5021 |
<< QApplication::desktop()->availableGeometry().adjusted(100, 100, -100, -100) |
|
5022 |
<< QRect(130, 100, 0, 200) |
|
5023 |
<< QRect(100, 50, 200, 0) |
|
5024 |
<< QRect(130, 50, 0, 0)) |
|
5025 |
<< (QList<QRect>() |
|
5026 |
<< QApplication::desktop()->availableGeometry().adjusted(100, 100, -100, -100) |
|
5027 |
<< QRect(130, 100, 0, 200) |
|
5028 |
<< QRect(100, 50, 200, 0) |
|
5029 |
<< QRect(130, 50, 0, 0) |
|
5030 |
<< QRect(100, 100, 200, 200)) |
|
5031 |
<< (QList<QRect>() |
|
5032 |
<< QRect(130, 100, 0, 200) |
|
5033 |
<< QRect(100, 50, 200, 0) |
|
5034 |
<< QRect(130, 50, 0, 0) |
|
5035 |
<< QRect(100, 100, 200, 200) |
|
5036 |
<< QApplication::desktop()->availableGeometry().adjusted(100, 100, -100, -100)) |
|
5037 |
<< (QList<QRect>() |
|
5038 |
<< QRect(100, 50, 200, 0) |
|
5039 |
<< QRect(130, 50, 0, 0) |
|
5040 |
<< QRect(100, 100, 200, 200) |
|
5041 |
<< QApplication::desktop()->availableGeometry().adjusted(100, 100, -100, -100) |
|
5042 |
<< QRect(130, 100, 0, 200)) |
|
5043 |
<< (QList<QRect>() |
|
5044 |
<< QRect(130, 50, 0, 0) |
|
5045 |
<< QRect(100, 100, 200, 200) |
|
5046 |
<< QApplication::desktop()->availableGeometry().adjusted(100, 100, -100, -100) |
|
5047 |
<< QRect(130, 100, 0, 200) |
|
5048 |
<< QRect(100, 50, 200, 0)); |
|
5049 |
||
5050 |
QList<int> windowFlags; |
|
5051 |
windowFlags << 0 |
|
5052 |
<< Qt::FramelessWindowHint |
|
5053 |
#ifdef Q_WS_X11 |
|
5054 |
<< Qt::X11BypassWindowManagerHint |
|
5055 |
#endif |
|
5056 |
; |
|
5057 |
||
5058 |
foreach (QList<QRect> l, rects) { |
|
5059 |
QRect rect = l.first(); |
|
5060 |
foreach (int windowFlag, windowFlags) { |
|
5061 |
QTest::newRow(QString("%1,%2 %3x%4, flags %5") |
|
5062 |
.arg(rect.x()) |
|
5063 |
.arg(rect.y()) |
|
5064 |
.arg(rect.width()) |
|
5065 |
.arg(rect.height()) |
|
5066 |
.arg(windowFlag, 0, 16).toAscii()) |
|
5067 |
<< l |
|
5068 |
<< windowFlag; |
|
5069 |
} |
|
5070 |
} |
|
5071 |
} |
|
5072 |
||
5073 |
void tst_QWidget::setWindowGeometry() |
|
5074 |
{ |
|
5075 |
#ifdef Q_WS_X11 |
|
5076 |
//Since WindowManager operation are all assync, and we have no way to know if the window |
|
5077 |
// manager has finished playing with the window geometry, this test can't be reliable. |
|
5078 |
QSKIP("Window Manager behaviour are too random for this test", SkipAll); |
|
5079 |
#endif |
|
5080 |
QFETCH(QList<QRect>, rects); |
|
5081 |
QFETCH(int, windowFlags); |
|
5082 |
QRect rect = rects.takeFirst(); |
|
5083 |
||
5084 |
{ |
|
5085 |
// test setGeometry() without actually showing the window |
|
5086 |
QWidget widget; |
|
5087 |
if (windowFlags != 0) |
|
5088 |
widget.setWindowFlags(Qt::WindowFlags(windowFlags)); |
|
5089 |
||
5090 |
widget.setGeometry(rect); |
|
5091 |
QTest::qWait(100); |
|
5092 |
QCOMPARE(widget.geometry(), rect); |
|
5093 |
||
5094 |
// setGeometry() without showing |
|
5095 |
foreach (QRect r, rects) { |
|
5096 |
widget.setGeometry(r); |
|
5097 |
QTest::qWait(100); |
|
5098 |
QCOMPARE(widget.geometry(), r); |
|
5099 |
} |
|
5100 |
} |
|
5101 |
||
5102 |
{ |
|
5103 |
// setGeometry() first, then show() |
|
5104 |
QWidget widget; |
|
5105 |
if (windowFlags != 0) |
|
5106 |
widget.setWindowFlags(Qt::WindowFlags(windowFlags)); |
|
5107 |
||
5108 |
widget.setGeometry(rect); |
|
5109 |
widget.show(); |
|
5110 |
QTest::qWaitForWindowShown(&widget); |
|
5111 |
QTest::qWait(20); |
|
5112 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5113 |
||
5114 |
// setGeometry() while shown |
|
5115 |
foreach (QRect r, rects) { |
|
5116 |
widget.setGeometry(r); |
|
5117 |
QTest::qWait(10); |
|
5118 |
QTRY_COMPARE(widget.geometry(), r); |
|
5119 |
} |
|
5120 |
widget.setGeometry(rect); |
|
5121 |
QTest::qWait(20); |
|
5122 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5123 |
||
5124 |
// now hide |
|
5125 |
widget.hide(); |
|
5126 |
QTest::qWait(20); |
|
5127 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5128 |
||
5129 |
// setGeometry() after hide() |
|
5130 |
foreach (QRect r, rects) { |
|
5131 |
widget.setGeometry(r); |
|
5132 |
QTest::qWait(10); |
|
5133 |
QTRY_COMPARE(widget.geometry(), r); |
|
5134 |
} |
|
5135 |
widget.setGeometry(rect); |
|
5136 |
QTest::qWait(10); |
|
5137 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5138 |
||
5139 |
// show() again, geometry() should still be the same |
|
5140 |
widget.show(); |
|
5141 |
QTest::qWaitForWindowShown(&widget); |
|
5142 |
QTest::qWait(10); |
|
5143 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5144 |
||
5145 |
// final hide(), again geometry() should be unchanged |
|
5146 |
widget.hide(); |
|
5147 |
QTest::qWait(10); |
|
5148 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5149 |
} |
|
5150 |
||
5151 |
{ |
|
5152 |
// show() first, then setGeometry() |
|
5153 |
QWidget widget; |
|
5154 |
if (windowFlags != 0) |
|
5155 |
widget.setWindowFlags(Qt::WindowFlags(windowFlags)); |
|
5156 |
||
5157 |
widget.show(); |
|
5158 |
QTest::qWaitForWindowShown(&widget); |
|
5159 |
widget.setGeometry(rect); |
|
5160 |
QTest::qWait(10); |
|
5161 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5162 |
||
5163 |
// setGeometry() while shown |
|
5164 |
foreach (QRect r, rects) { |
|
5165 |
widget.setGeometry(r); |
|
5166 |
QTest::qWait(10); |
|
5167 |
QTRY_COMPARE(widget.geometry(), r); |
|
5168 |
} |
|
5169 |
widget.setGeometry(rect); |
|
5170 |
QTest::qWait(10); |
|
5171 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5172 |
||
5173 |
// now hide |
|
5174 |
widget.hide(); |
|
5175 |
QTest::qWait(10); |
|
5176 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5177 |
||
5178 |
// setGeometry() after hide() |
|
5179 |
foreach (QRect r, rects) { |
|
5180 |
widget.setGeometry(r); |
|
5181 |
QTest::qWait(10); |
|
5182 |
QTRY_COMPARE(widget.geometry(), r); |
|
5183 |
} |
|
5184 |
widget.setGeometry(rect); |
|
5185 |
QTest::qWait(10); |
|
5186 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5187 |
||
5188 |
// show() again, geometry() should still be the same |
|
5189 |
widget.show(); |
|
5190 |
QTest::qWaitForWindowShown(&widget); |
|
5191 |
QTest::qWait(10); |
|
5192 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5193 |
||
5194 |
// final hide(), again geometry() should be unchanged |
|
5195 |
widget.hide(); |
|
5196 |
QTest::qWait(10); |
|
5197 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5198 |
} |
|
5199 |
} |
|
5200 |
||
5201 |
#if defined (Q_WS_WIN) && !defined(Q_OS_WINCE) |
|
5202 |
void tst_QWidget::setGeometry_win() |
|
5203 |
{ |
|
5204 |
QWidget widget; |
|
5205 |
widget.setGeometry(0, 600, 100,100); |
|
5206 |
widget.show(); |
|
5207 |
widget.setWindowState(widget.windowState() | Qt::WindowMaximized); |
|
5208 |
QRect geom = widget.normalGeometry(); |
|
5209 |
widget.close(); |
|
5210 |
widget.setGeometry(geom); |
|
5211 |
widget.setWindowState(widget.windowState() | Qt::WindowMaximized); |
|
5212 |
widget.show(); |
|
5213 |
RECT rt; |
|
5214 |
::GetWindowRect(widget.internalWinId(), &rt); |
|
5215 |
QVERIFY(rt.left <= 0); |
|
5216 |
QVERIFY(rt.top <= 0); |
|
5217 |
} |
|
5218 |
#endif |
|
5219 |
||
5220 |
void tst_QWidget::windowMoveResize_data() |
|
5221 |
{ |
|
5222 |
setWindowGeometry_data(); |
|
5223 |
} |
|
5224 |
||
5225 |
void tst_QWidget::windowMoveResize() |
|
5226 |
{ |
|
5227 |
#ifdef Q_WS_X11 |
|
5228 |
//Since WindowManager operation are all assync, and we have no way to know if the window |
|
5229 |
// manager has finished playing with the window geometry, this test can't be reliable. |
|
5230 |
QSKIP("Window Manager behaviour are too random for this test", SkipAll); |
|
5231 |
#endif |
|
5232 |
#ifdef Q_OS_IRIX |
|
5233 |
QSKIP("4DWM issues on IRIX makes this test fail", SkipAll); |
|
5234 |
#endif |
|
5235 |
QFETCH(QList<QRect>, rects); |
|
5236 |
QFETCH(int, windowFlags); |
|
5237 |
||
5238 |
QRect rect = rects.takeFirst(); |
|
5239 |
||
5240 |
{ |
|
5241 |
// test setGeometry() without actually showing the window |
|
5242 |
QWidget widget; |
|
5243 |
if (windowFlags != 0) |
|
5244 |
widget.setWindowFlags(Qt::WindowFlags(windowFlags)); |
|
5245 |
||
5246 |
widget.move(rect.topLeft()); |
|
5247 |
widget.resize(rect.size()); |
|
5248 |
QTest::qWait(10); |
|
5249 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5250 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5251 |
||
5252 |
// move() without showing |
|
5253 |
foreach (QRect r, rects) { |
|
5254 |
widget.move(r.topLeft()); |
|
5255 |
widget.resize(r.size()); |
|
5256 |
QApplication::processEvents(); |
|
5257 |
QTRY_COMPARE(widget.pos(), r.topLeft()); |
|
5258 |
QTRY_COMPARE(widget.size(), r.size()); |
|
5259 |
} |
|
5260 |
} |
|
5261 |
||
5262 |
{ |
|
5263 |
// move() first, then show() |
|
5264 |
QWidget widget; |
|
5265 |
if (windowFlags != 0) |
|
5266 |
widget.setWindowFlags(Qt::WindowFlags(windowFlags)); |
|
5267 |
||
5268 |
widget.move(rect.topLeft()); |
|
5269 |
widget.resize(rect.size()); |
|
5270 |
widget.show(); |
|
5271 |
||
5272 |
QTest::qWait(10); |
|
5273 |
#if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA) |
|
5274 |
QEXPECT_FAIL("130,50 0x0, flags 0", |
|
5275 |
"Showing a window with 0x0 size shifts it up.", |
|
5276 |
Continue); |
|
5277 |
#endif |
|
5278 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5279 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5280 |
||
5281 |
// move() while shown |
|
5282 |
foreach (QRect r, rects) { |
|
5283 |
#ifdef Q_WS_X11 |
|
5284 |
if ((widget.width() == 0 || widget.height() == 0) && r.width() != 0 && r.height() != 0) { |
|
5285 |
QEXPECT_FAIL("130,100 0x200, flags 0", |
|
5286 |
"First resize after show of zero-sized gets wrong win_gravity.", |
|
5287 |
Continue); |
|
5288 |
QEXPECT_FAIL("100,50 200x0, flags 0", |
|
5289 |
"First resize after show of zero-sized gets wrong win_gravity.", |
|
5290 |
Continue); |
|
5291 |
QEXPECT_FAIL("130,50 0x0, flags 0", |
|
5292 |
"First resize after show of zero-sized gets wrong win_gravity.", |
|
5293 |
Continue); |
|
5294 |
} |
|
5295 |
#endif |
|
5296 |
widget.move(r.topLeft()); |
|
5297 |
widget.resize(r.size()); |
|
5298 |
QApplication::processEvents(); |
|
5299 |
QTRY_COMPARE(widget.pos(), r.topLeft()); |
|
5300 |
QTRY_COMPARE(widget.size(), r.size()); |
|
5301 |
} |
|
5302 |
widget.move(rect.topLeft()); |
|
5303 |
widget.resize(rect.size()); |
|
5304 |
QApplication::processEvents(); |
|
5305 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5306 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5307 |
||
5308 |
// now hide |
|
5309 |
widget.hide(); |
|
5310 |
QTest::qWait(10); |
|
5311 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5312 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5313 |
||
5314 |
// move() after hide() |
|
5315 |
foreach (QRect r, rects) { |
|
5316 |
widget.move(r.topLeft()); |
|
5317 |
widget.resize(r.size()); |
|
5318 |
QApplication::processEvents(); |
|
5319 |
#if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA) |
|
5320 |
if (r.width() == 0 && r.height() > 0) { |
|
5321 |
widget.move(r.topLeft()); |
|
5322 |
widget.resize(r.size()); |
|
5323 |
} |
|
5324 |
#endif |
|
5325 |
QTRY_COMPARE(widget.pos(), r.topLeft()); |
|
5326 |
QTRY_COMPARE(widget.size(), r.size()); |
|
5327 |
} |
|
5328 |
widget.move(rect.topLeft()); |
|
5329 |
widget.resize(rect.size()); |
|
5330 |
QTest::qWait(10); |
|
5331 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5332 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5333 |
||
5334 |
// show() again, pos() should be the same |
|
5335 |
widget.show(); |
|
5336 |
QTest::qWaitForWindowShown(&widget); |
|
5337 |
QApplication::processEvents(); |
|
5338 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5339 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5340 |
||
5341 |
// final hide(), again pos() should be unchanged |
|
5342 |
widget.hide(); |
|
5343 |
QApplication::processEvents(); |
|
5344 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5345 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5346 |
} |
|
5347 |
||
5348 |
{ |
|
5349 |
// show() first, then move() |
|
5350 |
QWidget widget; |
|
5351 |
if (windowFlags != 0) |
|
5352 |
widget.setWindowFlags(Qt::WindowFlags(windowFlags)); |
|
5353 |
||
5354 |
widget.show(); |
|
5355 |
QTest::qWaitForWindowShown(&widget); |
|
5356 |
QApplication::processEvents(); |
|
5357 |
widget.move(rect.topLeft()); |
|
5358 |
widget.resize(rect.size()); |
|
5359 |
QApplication::processEvents(); |
|
5360 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5361 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5362 |
||
5363 |
// move() while shown |
|
5364 |
foreach (QRect r, rects) { |
|
5365 |
widget.move(r.topLeft()); |
|
5366 |
widget.resize(r.size()); |
|
5367 |
QApplication::processEvents(); |
|
5368 |
QTRY_COMPARE(widget.pos(), r.topLeft()); |
|
5369 |
QTRY_COMPARE(widget.size(), r.size()); |
|
5370 |
} |
|
5371 |
widget.move(rect.topLeft()); |
|
5372 |
widget.resize(rect.size()); |
|
5373 |
QApplication::processEvents(); |
|
5374 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5375 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5376 |
||
5377 |
// now hide |
|
5378 |
widget.hide(); |
|
5379 |
QApplication::processEvents(); |
|
5380 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5381 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5382 |
||
5383 |
// move() after hide() |
|
5384 |
foreach (QRect r, rects) { |
|
5385 |
widget.move(r.topLeft()); |
|
5386 |
widget.resize(r.size()); |
|
5387 |
QApplication::processEvents(); |
|
5388 |
#if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA) |
|
5389 |
if (r.width() == 0 && r.height() > 0) { |
|
5390 |
widget.move(r.topLeft()); |
|
5391 |
widget.resize(r.size()); |
|
5392 |
} |
|
5393 |
#endif |
|
5394 |
QTRY_COMPARE(widget.pos(), r.topLeft()); |
|
5395 |
QTRY_COMPARE(widget.size(), r.size()); |
|
5396 |
} |
|
5397 |
widget.move(rect.topLeft()); |
|
5398 |
widget.resize(rect.size()); |
|
5399 |
QApplication::processEvents(); |
|
5400 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5401 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5402 |
||
5403 |
// show() again, pos() should be the same |
|
5404 |
widget.show(); |
|
5405 |
QTest::qWaitForWindowShown(&widget); |
|
5406 |
QTest::qWait(10); |
|
5407 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5408 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5409 |
||
5410 |
// final hide(), again pos() should be unchanged |
|
5411 |
widget.hide(); |
|
5412 |
QTest::qWait(10); |
|
5413 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5414 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5415 |
} |
|
5416 |
} |
|
5417 |
||
5418 |
class ColorWidget : public QWidget |
|
5419 |
{ |
|
5420 |
public: |
|
5421 |
ColorWidget(QWidget *parent = 0, const QColor &c = QColor(Qt::red)) |
|
5422 |
: QWidget(parent, Qt::FramelessWindowHint), color(c) |
|
5423 |
{ |
|
5424 |
QPalette opaquePalette = palette(); |
|
5425 |
opaquePalette.setColor(backgroundRole(), color); |
|
5426 |
setPalette(opaquePalette); |
|
5427 |
setAutoFillBackground(true); |
|
5428 |
} |
|
5429 |
||
5430 |
void paintEvent(QPaintEvent *e) { |
|
5431 |
r += e->region(); |
|
5432 |
} |
|
5433 |
||
5434 |
void reset() { |
|
5435 |
r = QRegion(); |
|
5436 |
} |
|
5437 |
||
5438 |
QColor color; |
|
5439 |
QRegion r; |
|
5440 |
}; |
|
5441 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5442 |
#define VERIFY_COLOR(region, color) { \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5443 |
const QRegion r = QRegion(region); \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5444 |
for (int i = 0; i < r.rects().size(); ++i) { \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5445 |
const QRect rect = r.rects().at(i); \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5446 |
for (int t = 0; t < 5; t++) { \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5447 |
const QPixmap pixmap = QPixmap::grabWindow(QDesktopWidget().winId(), \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5448 |
rect.left(), rect.top(), \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5449 |
rect.width(), rect.height()); \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5450 |
QCOMPARE(pixmap.size(), rect.size()); \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5451 |
QPixmap expectedPixmap(pixmap); /* ensure equal formats */ \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5452 |
expectedPixmap.fill(color); \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5453 |
if (pixmap.toImage().pixel(0,0) != QColor(color).rgb() && t < 4 ) \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5454 |
{ QTest::qWait(200); continue; } \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5455 |
QCOMPARE(pixmap.toImage().pixel(0,0), QColor(color).rgb()); \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5456 |
QCOMPARE(pixmap, expectedPixmap); \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5457 |
break; \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5458 |
} \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5459 |
} \ |
0 | 5460 |
} |
5461 |
||
5462 |
void tst_QWidget::moveChild_data() |
|
5463 |
{ |
|
5464 |
QTest::addColumn<QPoint>("offset"); |
|
5465 |
||
5466 |
QTest::newRow("right") << QPoint(20, 0); |
|
5467 |
QTest::newRow("down") << QPoint(0, 20); |
|
5468 |
QTest::newRow("left") << QPoint(-20, 0); |
|
5469 |
QTest::newRow("up") << QPoint(0, -20); |
|
5470 |
} |
|
5471 |
||
5472 |
void tst_QWidget::moveChild() |
|
5473 |
{ |
|
5474 |
QFETCH(QPoint, offset); |
|
5475 |
||
5476 |
ColorWidget parent; |
|
5477 |
// prevent custom styles |
|
5478 |
parent.setStyle(new QWindowsStyle); |
|
5479 |
ColorWidget child(&parent, Qt::blue); |
|
5480 |
||
5481 |
#ifndef Q_OS_WINCE |
|
5482 |
parent.setGeometry(QRect(QPoint(QApplication::desktop()->availableGeometry(&parent).topLeft()), |
|
5483 |
QSize(100, 100))); |
|
5484 |
#else |
|
5485 |
parent.setGeometry(60, 60, 150, 150); |
|
5486 |
#endif |
|
5487 |
child.setGeometry(25, 25, 50, 50); |
|
5488 |
QPoint childOffset = child.mapToGlobal(QPoint()); |
|
5489 |
||
5490 |
parent.show(); |
|
5491 |
QTest::qWaitForWindowShown(&parent); |
|
5492 |
QTest::qWait(30); |
|
5493 |
const QPoint tlwOffset = parent.geometry().topLeft(); |
|
5494 |
||
5495 |
#ifdef QT_MAC_USE_COCOA |
|
5496 |
QEXPECT_FAIL(0, "Cocoa compositor paints the entire content view, even when opaque", Continue); |
|
5497 |
#endif |
|
5498 |
QTRY_COMPARE(parent.r, QRegion(parent.rect()) - child.geometry()); |
|
5499 |
QTRY_COMPARE(child.r, QRegion(child.rect())); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5500 |
VERIFY_COLOR(child.geometry().translated(tlwOffset), |
0 | 5501 |
child.color); |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5502 |
VERIFY_COLOR(QRegion(parent.geometry()) - child.geometry().translated(tlwOffset), |
0 | 5503 |
parent.color); |
5504 |
parent.reset(); |
|
5505 |
child.reset(); |
|
5506 |
||
5507 |
// move |
|
5508 |
||
5509 |
const QRect oldGeometry = child.geometry(); |
|
5510 |
||
5511 |
QPoint pos = child.pos() + offset; |
|
5512 |
child.move(pos); |
|
5513 |
QTest::qWait(100); |
|
5514 |
QTRY_COMPARE(pos, child.pos()); |
|
5515 |
||
5516 |
QCOMPARE(parent.r, QRegion(oldGeometry) - child.geometry()); |
|
5517 |
#if !defined(Q_WS_MAC) |
|
5518 |
// should be scrolled in backingstore |
|
5519 |
QCOMPARE(child.r, QRegion()); |
|
5520 |
#endif |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5521 |
VERIFY_COLOR(child.geometry().translated(tlwOffset), |
0 | 5522 |
child.color); |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5523 |
VERIFY_COLOR(QRegion(parent.geometry()) - child.geometry().translated(tlwOffset), |
0 | 5524 |
parent.color); |
5525 |
} |
|
5526 |
||
5527 |
void tst_QWidget::showAndMoveChild() |
|
5528 |
{ |
|
5529 |
QWidget parent(0, Qt::FramelessWindowHint); |
|
5530 |
// prevent custom styles |
|
5531 |
parent.setStyle(new QWindowsStyle); |
|
5532 |
||
5533 |
QDesktopWidget desktop; |
|
5534 |
QRect desktopDimensions = desktop.availableGeometry(&parent); |
|
5535 |
||
5536 |
parent.setGeometry(desktopDimensions); |
|
5537 |
parent.setPalette(Qt::red); |
|
5538 |
parent.show(); |
|
5539 |
QTest::qWaitForWindowShown(&parent); |
|
5540 |
QTest::qWait(10); |
|
5541 |
||
5542 |
const QPoint tlwOffset = parent.geometry().topLeft(); |
|
5543 |
QWidget child(&parent); |
|
5544 |
child.resize(desktopDimensions.width()/2, desktopDimensions.height()/2); |
|
5545 |
child.setPalette(Qt::blue); |
|
5546 |
child.setAutoFillBackground(true); |
|
5547 |
||
5548 |
// Ensure that the child is repainted correctly when moved right after show. |
|
5549 |
// NB! Do NOT processEvents() (or qWait()) in between show() and move(). |
|
5550 |
child.show(); |
|
5551 |
child.move(desktopDimensions.width()/2, desktopDimensions.height()/2); |
|
5552 |
qApp->processEvents(); |
|
5553 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5554 |
VERIFY_COLOR(child.geometry().translated(tlwOffset), Qt::blue); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5555 |
VERIFY_COLOR(QRegion(parent.geometry()) - child.geometry().translated(tlwOffset), Qt::red); |
0 | 5556 |
} |
5557 |
||
5558 |
void tst_QWidget::subtractOpaqueSiblings() |
|
5559 |
{ |
|
5560 |
#ifdef QT_MAC_USE_COCOA |
|
5561 |
QSKIP("Cocoa only has rect granularity.", SkipAll); |
|
5562 |
#else |
|
5563 |
QWidget w; |
|
5564 |
w.setGeometry(50, 50, 300, 300); |
|
5565 |
||
5566 |
ColorWidget *large = new ColorWidget(&w, Qt::red); |
|
5567 |
large->setGeometry(50, 50, 200, 200); |
|
5568 |
||
5569 |
ColorWidget *medium = new ColorWidget(large, Qt::gray); |
|
5570 |
medium->setGeometry(50, 50, 100, 100); |
|
5571 |
||
5572 |
ColorWidget *tall = new ColorWidget(&w, Qt::blue); |
|
5573 |
tall->setGeometry(100, 30, 50, 100); |
|
5574 |
||
5575 |
w.show(); |
|
5576 |
QTest::qWaitForWindowShown(&w); |
|
5577 |
QTest::qWait(10); |
|
5578 |
||
5579 |
large->reset(); |
|
5580 |
medium->reset(); |
|
5581 |
tall->reset(); |
|
5582 |
||
5583 |
medium->update(); |
|
5584 |
QTest::qWait(10); |
|
5585 |
||
5586 |
// QWidgetPrivate::subtractOpaqueSiblings() should prevent parts of medium |
|
5587 |
// to be repainted and tall from be repainted at all. |
|
5588 |
||
5589 |
QTRY_COMPARE(large->r, QRegion()); |
|
5590 |
QTRY_COMPARE(tall->r, QRegion()); |
|
5591 |
QTRY_COMPARE(medium->r.translated(medium->mapTo(&w, QPoint())), |
|
5592 |
QRegion(medium->geometry().translated(large->pos())) |
|
5593 |
- tall->geometry()); |
|
5594 |
#endif |
|
5595 |
} |
|
5596 |
||
5597 |
void tst_QWidget::deleteStyle() |
|
5598 |
{ |
|
5599 |
QWidget widget; |
|
5600 |
widget.setStyle(new QWindowsStyle); |
|
5601 |
widget.show(); |
|
5602 |
delete widget.style(); |
|
5603 |
qApp->processEvents(); |
|
5604 |
} |
|
5605 |
||
5606 |
#ifdef Q_WS_WIN |
|
5607 |
void tst_QWidget::getDC() |
|
5608 |
{ |
|
5609 |
QWidget widget; |
|
5610 |
widget.setGeometry(0, 0, 2, 4); |
|
5611 |
||
5612 |
HDC dc = widget.getDC(); |
|
5613 |
QVERIFY(dc != 0); |
|
5614 |
||
5615 |
widget.releaseDC(dc); |
|
5616 |
} |
|
5617 |
#endif |
|
5618 |
||
5619 |
class TopLevelFocusCheck: public QWidget |
|
5620 |
{ |
|
5621 |
Q_OBJECT |
|
5622 |
public: |
|
5623 |
QLineEdit* edit; |
|
5624 |
TopLevelFocusCheck(QWidget* parent = 0) : QWidget(parent) |
|
5625 |
{ |
|
5626 |
edit = new QLineEdit(this); |
|
5627 |
edit->hide(); |
|
5628 |
edit->installEventFilter(this); |
|
5629 |
} |
|
5630 |
||
5631 |
public slots: |
|
5632 |
void mouseDoubleClickEvent ( QMouseEvent * /*event*/ ) |
|
5633 |
{ |
|
5634 |
edit->show(); |
|
5635 |
edit->setFocus(Qt::OtherFocusReason); |
|
5636 |
qApp->processEvents(); |
|
5637 |
} |
|
5638 |
bool eventFilter(QObject *obj, QEvent *event) |
|
5639 |
{ |
|
5640 |
if (obj == edit && event->type()== QEvent::FocusOut) { |
|
5641 |
edit->hide(); |
|
5642 |
return true; |
|
5643 |
} |
|
5644 |
return false; |
|
5645 |
} |
|
5646 |
}; |
|
5647 |
||
5648 |
void tst_QWidget::multipleToplevelFocusCheck() |
|
5649 |
{ |
|
5650 |
TopLevelFocusCheck w1; |
|
5651 |
TopLevelFocusCheck w2; |
|
5652 |
||
5653 |
w1.resize(200, 200); |
|
5654 |
w1.show(); |
|
5655 |
QTest::qWaitForWindowShown(&w1); |
|
5656 |
w2.resize(200,200); |
|
5657 |
w2.show(); |
|
5658 |
QTest::qWaitForWindowShown(&w2); |
|
5659 |
||
5660 |
QTest::qWait(100); |
|
5661 |
||
5662 |
QApplication::setActiveWindow(&w1); |
|
5663 |
w1.activateWindow(); |
|
5664 |
QApplication::processEvents(); |
|
5665 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w1)); |
|
5666 |
QTest::qWait(50); |
|
5667 |
QTest::mouseDClick(&w1, Qt::LeftButton); |
|
5668 |
QTRY_COMPARE(QApplication::focusWidget(), static_cast<QWidget *>(w1.edit)); |
|
5669 |
||
5670 |
w2.activateWindow(); |
|
5671 |
QApplication::setActiveWindow(&w2); |
|
5672 |
QApplication::processEvents(); |
|
5673 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w2)); |
|
5674 |
QTest::mouseClick(&w2, Qt::LeftButton); |
|
5675 |
#ifdef Q_WS_QWS |
|
5676 |
QEXPECT_FAIL("", "embedded toplevels take focus anyway", Continue); |
|
5677 |
#endif |
|
5678 |
QTRY_COMPARE(QApplication::focusWidget(), (QWidget *)0); |
|
5679 |
||
5680 |
QTest::mouseDClick(&w2, Qt::LeftButton); |
|
5681 |
QTRY_COMPARE(QApplication::focusWidget(), static_cast<QWidget *>(w2.edit)); |
|
5682 |
||
5683 |
w1.activateWindow(); |
|
5684 |
QApplication::setActiveWindow(&w1); |
|
5685 |
QApplication::processEvents(); |
|
5686 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w1)); |
|
5687 |
QTest::mouseDClick(&w1, Qt::LeftButton); |
|
5688 |
QTRY_COMPARE(QApplication::focusWidget(), static_cast<QWidget *>(w1.edit)); |
|
5689 |
||
5690 |
w2.activateWindow(); |
|
5691 |
QApplication::setActiveWindow(&w2); |
|
5692 |
QApplication::processEvents(); |
|
5693 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w2)); |
|
5694 |
QTest::mouseClick(&w2, Qt::LeftButton); |
|
5695 |
QTRY_COMPARE(QApplication::focusWidget(), (QWidget *)0); |
|
5696 |
} |
|
5697 |
||
5698 |
void tst_QWidget::setFocus() |
|
5699 |
{ |
|
5700 |
{ |
|
5701 |
// move focus to another window |
|
5702 |
testWidget->activateWindow(); |
|
5703 |
QApplication::setActiveWindow(testWidget); |
|
5704 |
if (testWidget->focusWidget()) |
|
5705 |
testWidget->focusWidget()->clearFocus(); |
|
5706 |
else |
|
5707 |
testWidget->clearFocus(); |
|
5708 |
||
5709 |
// window and children never shown, nobody gets focus |
|
5710 |
QWidget window; |
|
5711 |
||
5712 |
QWidget child1(&window); |
|
5713 |
child1.setFocusPolicy(Qt::StrongFocus); |
|
5714 |
||
5715 |
QWidget child2(&window); |
|
5716 |
child2.setFocusPolicy(Qt::StrongFocus); |
|
5717 |
||
5718 |
child1.setFocus(); |
|
5719 |
QVERIFY(!child1.hasFocus()); |
|
5720 |
QCOMPARE(window.focusWidget(), &child1); |
|
5721 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5722 |
||
5723 |
child2.setFocus(); |
|
5724 |
QVERIFY(!child2.hasFocus()); |
|
5725 |
QCOMPARE(window.focusWidget(), &child2); |
|
5726 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5727 |
} |
|
5728 |
||
5729 |
{ |
|
5730 |
// window and children show, but window not active, nobody gets focus |
|
5731 |
QWidget window; |
|
5732 |
||
5733 |
QWidget child1(&window); |
|
5734 |
child1.setFocusPolicy(Qt::StrongFocus); |
|
5735 |
||
5736 |
QWidget child2(&window); |
|
5737 |
child2.setFocusPolicy(Qt::StrongFocus); |
|
5738 |
||
5739 |
window.show(); |
|
5740 |
||
5741 |
// note: window may be active, but we don't want it to be |
|
5742 |
testWidget->activateWindow(); |
|
5743 |
QApplication::setActiveWindow(testWidget); |
|
5744 |
if (testWidget->focusWidget()) |
|
5745 |
testWidget->focusWidget()->clearFocus(); |
|
5746 |
else |
|
5747 |
testWidget->clearFocus(); |
|
5748 |
||
5749 |
child1.setFocus(); |
|
5750 |
QVERIFY(!child1.hasFocus()); |
|
5751 |
QCOMPARE(window.focusWidget(), &child1); |
|
5752 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5753 |
||
5754 |
child2.setFocus(); |
|
5755 |
QVERIFY(!child2.hasFocus()); |
|
5756 |
QCOMPARE(window.focusWidget(), &child2); |
|
5757 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5758 |
} |
|
5759 |
||
5760 |
{ |
|
5761 |
// window and children show, but window *is* active, children get focus |
|
5762 |
QWidget window; |
|
5763 |
||
5764 |
QWidget child1(&window); |
|
5765 |
child1.setFocusPolicy(Qt::StrongFocus); |
|
5766 |
||
5767 |
QWidget child2(&window); |
|
5768 |
child2.setFocusPolicy(Qt::StrongFocus); |
|
5769 |
||
5770 |
window.show(); |
|
5771 |
#ifdef Q_WS_X11 |
|
5772 |
QApplication::setActiveWindow(&window); |
|
5773 |
QTest::qWaitForWindowShown(&window); |
|
5774 |
#else |
|
5775 |
window.activateWindow(); |
|
5776 |
QApplication::processEvents(); |
|
5777 |
#endif |
|
5778 |
||
5779 |
child1.setFocus(); |
|
5780 |
QTRY_VERIFY(child1.hasFocus()); |
|
5781 |
QCOMPARE(window.focusWidget(), &child1); |
|
5782 |
QCOMPARE(QApplication::focusWidget(), &child1); |
|
5783 |
||
5784 |
child2.setFocus(); |
|
5785 |
QVERIFY(child2.hasFocus()); |
|
5786 |
QCOMPARE(window.focusWidget(), &child2); |
|
5787 |
QCOMPARE(QApplication::focusWidget(), &child2); |
|
5788 |
} |
|
5789 |
||
5790 |
{ |
|
5791 |
// window shown and active, children created, don't get focus, but get focus when shown |
|
5792 |
QWidget window; |
|
5793 |
||
5794 |
window.show(); |
|
5795 |
#ifdef Q_WS_X11 |
|
5796 |
QApplication::setActiveWindow(&window); |
|
5797 |
QTest::qWaitForWindowShown(&window); |
|
5798 |
#else |
|
5799 |
window.activateWindow(); |
|
5800 |
#endif |
|
5801 |
||
5802 |
QWidget child1(&window); |
|
5803 |
child1.setFocusPolicy(Qt::StrongFocus); |
|
5804 |
||
5805 |
QWidget child2(&window); |
|
5806 |
child2.setFocusPolicy(Qt::StrongFocus); |
|
5807 |
||
5808 |
child1.setFocus(); |
|
5809 |
QVERIFY(!child1.hasFocus()); |
|
5810 |
QCOMPARE(window.focusWidget(), static_cast<QWidget *>(0)); |
|
5811 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5812 |
||
5813 |
child1.show(); |
|
5814 |
#ifdef Q_WS_X11 |
|
5815 |
QApplication::setActiveWindow(&child1); |
|
5816 |
child1.activateWindow(); |
|
5817 |
#endif |
|
5818 |
QApplication::processEvents(); |
|
5819 |
QTRY_VERIFY(child1.hasFocus()); |
|
5820 |
QCOMPARE(window.focusWidget(), &child1); |
|
5821 |
QCOMPARE(QApplication::focusWidget(), &child1); |
|
5822 |
||
5823 |
child2.setFocus(); |
|
5824 |
QVERIFY(!child2.hasFocus()); |
|
5825 |
QCOMPARE(window.focusWidget(), &child1); |
|
5826 |
QCOMPARE(QApplication::focusWidget(), &child1); |
|
5827 |
||
5828 |
child2.show(); |
|
5829 |
QVERIFY(child2.hasFocus()); |
|
5830 |
QCOMPARE(window.focusWidget(), &child2); |
|
5831 |
QCOMPARE(QApplication::focusWidget(), &child2); |
|
5832 |
} |
|
5833 |
||
5834 |
{ |
|
5835 |
// window shown and active, children created, don't get focus, |
|
5836 |
// even after setFocus(), hide(), then show() |
|
5837 |
QWidget window; |
|
5838 |
||
5839 |
window.show(); |
|
5840 |
#ifdef Q_WS_X11 |
|
5841 |
QApplication::setActiveWindow(&window); |
|
5842 |
QTest::qWaitForWindowShown(&window); |
|
5843 |
#else |
|
5844 |
window.activateWindow(); |
|
5845 |
#endif |
|
5846 |
||
5847 |
QWidget child1(&window); |
|
5848 |
child1.setFocusPolicy(Qt::StrongFocus); |
|
5849 |
||
5850 |
QWidget child2(&window); |
|
5851 |
child2.setFocusPolicy(Qt::StrongFocus); |
|
5852 |
||
5853 |
child1.setFocus(); |
|
5854 |
QVERIFY(!child1.hasFocus()); |
|
5855 |
QCOMPARE(window.focusWidget(), static_cast<QWidget *>(0)); |
|
5856 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5857 |
||
5858 |
child1.hide(); |
|
5859 |
QVERIFY(!child1.hasFocus()); |
|
5860 |
QCOMPARE(window.focusWidget(), static_cast<QWidget *>(0)); |
|
5861 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5862 |
||
5863 |
child1.show(); |
|
5864 |
QVERIFY(!child1.hasFocus()); |
|
5865 |
QCOMPARE(window.focusWidget(), static_cast<QWidget *>(0)); |
|
5866 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5867 |
||
5868 |
child2.setFocus(); |
|
5869 |
QVERIFY(!child2.hasFocus()); |
|
5870 |
QCOMPARE(window.focusWidget(), static_cast<QWidget *>(0)); |
|
5871 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5872 |
||
5873 |
child2.hide(); |
|
5874 |
QVERIFY(!child2.hasFocus()); |
|
5875 |
QCOMPARE(window.focusWidget(), static_cast<QWidget *>(0)); |
|
5876 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5877 |
||
5878 |
child2.show(); |
|
5879 |
QVERIFY(!child2.hasFocus()); |
|
5880 |
QCOMPARE(window.focusWidget(), static_cast<QWidget *>(0)); |
|
5881 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5882 |
} |
|
5883 |
} |
|
5884 |
||
5885 |
class EventSpy : public QObject |
|
5886 |
{ |
|
5887 |
public: |
|
5888 |
EventSpy(QWidget *widget, QEvent::Type event) |
|
5889 |
: m_widget(widget), eventToSpy(event), m_count(0) |
|
5890 |
{ |
|
5891 |
if (m_widget) |
|
5892 |
m_widget->installEventFilter(this); |
|
5893 |
} |
|
5894 |
||
5895 |
QWidget *widget() const { return m_widget; } |
|
5896 |
int count() const { return m_count; } |
|
5897 |
void clear() { m_count = 0; } |
|
5898 |
||
5899 |
protected: |
|
5900 |
bool eventFilter(QObject *object, QEvent *event) |
|
5901 |
{ |
|
5902 |
if (event->type() == eventToSpy) |
|
5903 |
++m_count; |
|
5904 |
return QObject::eventFilter(object, event); |
|
5905 |
} |
|
5906 |
||
5907 |
private: |
|
5908 |
QWidget *m_widget; |
|
5909 |
QEvent::Type eventToSpy; |
|
5910 |
int m_count; |
|
5911 |
}; |
|
5912 |
||
5913 |
void tst_QWidget::setCursor() |
|
5914 |
{ |
|
5915 |
#ifndef QT_NO_CURSOR |
|
5916 |
{ |
|
5917 |
QWidget window; |
|
5918 |
QWidget child(&window); |
|
5919 |
||
5920 |
QVERIFY(!window.testAttribute(Qt::WA_SetCursor)); |
|
5921 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5922 |
||
5923 |
window.setCursor(window.cursor()); |
|
5924 |
QVERIFY(window.testAttribute(Qt::WA_SetCursor)); |
|
5925 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5926 |
QCOMPARE(child.cursor().shape(), window.cursor().shape()); |
|
5927 |
} |
|
5928 |
||
5929 |
// do it again, but with window show()n |
|
5930 |
{ |
|
5931 |
QWidget window; |
|
5932 |
QWidget child(&window); |
|
5933 |
window.show(); |
|
5934 |
||
5935 |
QVERIFY(!window.testAttribute(Qt::WA_SetCursor)); |
|
5936 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5937 |
||
5938 |
window.setCursor(window.cursor()); |
|
5939 |
QVERIFY(window.testAttribute(Qt::WA_SetCursor)); |
|
5940 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5941 |
QCOMPARE(child.cursor().shape(), window.cursor().shape()); |
|
5942 |
} |
|
5943 |
||
5944 |
||
5945 |
{ |
|
5946 |
QWidget window; |
|
5947 |
QWidget child(&window); |
|
5948 |
||
5949 |
window.setCursor(Qt::WaitCursor); |
|
5950 |
QVERIFY(window.testAttribute(Qt::WA_SetCursor)); |
|
5951 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5952 |
QCOMPARE(child.cursor().shape(), window.cursor().shape()); |
|
5953 |
} |
|
5954 |
||
5955 |
// same thing again, just with window show()n |
|
5956 |
{ |
|
5957 |
QWidget window; |
|
5958 |
QWidget child(&window); |
|
5959 |
||
5960 |
window.show(); |
|
5961 |
window.setCursor(Qt::WaitCursor); |
|
5962 |
QVERIFY(window.testAttribute(Qt::WA_SetCursor)); |
|
5963 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5964 |
QCOMPARE(child.cursor().shape(), window.cursor().shape()); |
|
5965 |
} |
|
5966 |
||
5967 |
// reparenting child should not cause the WA_SetCursor to become set |
|
5968 |
{ |
|
5969 |
QWidget window; |
|
5970 |
QWidget window2; |
|
5971 |
QWidget child(&window); |
|
5972 |
||
5973 |
window.setCursor(Qt::WaitCursor); |
|
5974 |
||
5975 |
child.setParent(0); |
|
5976 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5977 |
QCOMPARE(child.cursor().shape(), QCursor().shape()); |
|
5978 |
||
5979 |
child.setParent(&window2); |
|
5980 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5981 |
QCOMPARE(child.cursor().shape(), window2.cursor().shape()); |
|
5982 |
||
5983 |
window2.setCursor(Qt::WaitCursor); |
|
5984 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5985 |
QCOMPARE(child.cursor().shape(), window2.cursor().shape()); |
|
5986 |
} |
|
5987 |
||
5988 |
// again, with windows show()n |
|
5989 |
{ |
|
5990 |
QWidget window; |
|
5991 |
QWidget window2; |
|
5992 |
QWidget child(&window); |
|
5993 |
||
5994 |
window.setCursor(Qt::WaitCursor); |
|
5995 |
window.show(); |
|
5996 |
||
5997 |
child.setParent(0); |
|
5998 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5999 |
QCOMPARE(child.cursor().shape(), QCursor().shape()); |
|
6000 |
||
6001 |
child.setParent(&window2); |
|
6002 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
6003 |
QCOMPARE(child.cursor().shape(), window2.cursor().shape()); |
|
6004 |
||
6005 |
window2.show(); |
|
6006 |
window2.setCursor(Qt::WaitCursor); |
|
6007 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
6008 |
QCOMPARE(child.cursor().shape(), window2.cursor().shape()); |
|
6009 |
} |
|
6010 |
||
6011 |
// test if CursorChange is sent |
|
6012 |
{ |
|
6013 |
QWidget widget; |
|
6014 |
EventSpy spy(&widget, QEvent::CursorChange); |
|
6015 |
QCOMPARE(spy.count(), 0); |
|
6016 |
widget.setCursor(QCursor(Qt::WaitCursor)); |
|
6017 |
QCOMPARE(spy.count(), 1); |
|
6018 |
widget.unsetCursor(); |
|
6019 |
QCOMPARE(spy.count(), 2); |
|
6020 |
} |
|
6021 |
#endif |
|
6022 |
} |
|
6023 |
||
6024 |
void tst_QWidget::setToolTip() |
|
6025 |
{ |
|
6026 |
QWidget widget; |
|
6027 |
EventSpy spy(&widget, QEvent::ToolTipChange); |
|
6028 |
QCOMPARE(spy.count(), 0); |
|
6029 |
||
6030 |
QCOMPARE(widget.toolTip(), QString()); |
|
6031 |
widget.setToolTip(QString("Hello")); |
|
6032 |
QCOMPARE(widget.toolTip(), QString("Hello")); |
|
6033 |
QCOMPARE(spy.count(), 1); |
|
6034 |
widget.setToolTip(QString()); |
|
6035 |
QCOMPARE(widget.toolTip(), QString()); |
|
6036 |
QCOMPARE(spy.count(), 2); |
|
6037 |
||
6038 |
#ifdef Q_OS_WINCE_WM |
|
6039 |
QSKIP("Mouse over doesn't work on Windows mobile.", SkipAll); |
|
6040 |
#endif |
|
6041 |
||
6042 |
for (int pass = 0; pass < 2; ++pass) { |
|
6043 |
QWidget *popup = new QWidget(0, Qt::Popup); |
|
6044 |
popup->resize(150, 50); |
|
6045 |
QFrame *frame = new QFrame(popup); |
|
6046 |
frame->setGeometry(0, 0, 50, 50); |
|
6047 |
frame->setFrameStyle(QFrame::Box | QFrame::Plain); |
|
6048 |
EventSpy spy1(frame, QEvent::ToolTip); |
|
6049 |
EventSpy spy2(popup, QEvent::ToolTip); |
|
6050 |
frame->setMouseTracking(pass == 0 ? false : true); |
|
6051 |
frame->setToolTip(QLatin1String("TOOLTIP FRAME")); |
|
6052 |
popup->setToolTip(QLatin1String("TOOLTIP POPUP")); |
|
6053 |
popup->show(); |
|
6054 |
QTest::qWaitForWindowShown(popup); |
|
6055 |
QTest::qWait(10); |
|
6056 |
QTest::mouseMove(frame); |
|
6057 |
QTest::qWait(900); // delay is 700 |
|
6058 |
||
6059 |
QCOMPARE(spy1.count(), 1); |
|
6060 |
QCOMPARE(spy2.count(), 0); |
|
6061 |
if (pass == 0) |
|
6062 |
QTest::qWait(2200); // delay is 2000 |
|
6063 |
QTest::mouseMove(popup); |
|
6064 |
delete popup; |
|
6065 |
} |
|
6066 |
} |
|
6067 |
||
6068 |
void tst_QWidget::testWindowIconChangeEventPropagation() |
|
6069 |
{ |
|
6070 |
// Create widget hierarchy. |
|
6071 |
QWidget topLevelWidget; |
|
6072 |
QWidget topLevelChild(&topLevelWidget); |
|
6073 |
||
6074 |
QDialog dialog(&topLevelWidget); |
|
6075 |
QWidget dialogChild(&dialog); |
|
6076 |
||
6077 |
QWidgetList widgets; |
|
6078 |
widgets << &topLevelWidget << &topLevelChild |
|
6079 |
<< &dialog << &dialogChild; |
|
6080 |
QCOMPARE(widgets.count(), 4); |
|
6081 |
||
6082 |
// Create spy lists. |
|
6083 |
QList <EventSpy *> applicationEventSpies; |
|
6084 |
QList <EventSpy *> widgetEventSpies; |
|
6085 |
foreach (QWidget *widget, widgets) { |
|
6086 |
applicationEventSpies.append(new EventSpy(widget, QEvent::ApplicationWindowIconChange)); |
|
6087 |
widgetEventSpies.append(new EventSpy(widget, QEvent::WindowIconChange)); |
|
6088 |
} |
|
6089 |
||
6090 |
// QApplication::setWindowIcon |
|
6091 |
const QIcon windowIcon = qApp->style()->standardIcon(QStyle::SP_TitleBarMenuButton); |
|
6092 |
qApp->setWindowIcon(windowIcon); |
|
6093 |
||
6094 |
for (int i = 0; i < widgets.count(); ++i) { |
|
6095 |
// Check QEvent::ApplicationWindowIconChange |
|
6096 |
EventSpy *spy = applicationEventSpies.at(i); |
|
6097 |
QWidget *widget = spy->widget(); |
|
6098 |
if (widget->isWindow()) { |
|
6099 |
QCOMPARE(spy->count(), 1); |
|
6100 |
QCOMPARE(widget->windowIcon(), windowIcon); |
|
6101 |
} else { |
|
6102 |
QCOMPARE(spy->count(), 0); |
|
6103 |
} |
|
6104 |
spy->clear(); |
|
6105 |
||
6106 |
// Check QEvent::WindowIconChange |
|
6107 |
spy = widgetEventSpies.at(i); |
|
6108 |
QCOMPARE(spy->count(), 1); |
|
6109 |
spy->clear(); |
|
6110 |
} |
|
6111 |
||
6112 |
// Set icon on a top-level widget. |
|
6113 |
topLevelWidget.setWindowIcon(*new QIcon); |
|
6114 |
||
6115 |
for (int i = 0; i < widgets.count(); ++i) { |
|
6116 |
// Check QEvent::ApplicationWindowIconChange |
|
6117 |
EventSpy *spy = applicationEventSpies.at(i); |
|
6118 |
QCOMPARE(spy->count(), 0); |
|
6119 |
spy->clear(); |
|
6120 |
||
6121 |
// Check QEvent::WindowIconChange |
|
6122 |
spy = widgetEventSpies.at(i); |
|
6123 |
QWidget *widget = spy->widget(); |
|
6124 |
if (widget == &topLevelWidget) { |
|
6125 |
QCOMPARE(widget->windowIcon(), QIcon()); |
|
6126 |
QCOMPARE(spy->count(), 1); |
|
6127 |
} else if (topLevelWidget.isAncestorOf(widget)) { |
|
6128 |
QCOMPARE(spy->count(), 1); |
|
6129 |
} else { |
|
6130 |
QCOMPARE(spy->count(), 0); |
|
6131 |
} |
|
6132 |
spy->clear(); |
|
6133 |
} |
|
6134 |
||
6135 |
// Cleanup. |
|
6136 |
for (int i = 0; i < widgets.count(); ++i) { |
|
6137 |
delete applicationEventSpies.at(i); |
|
6138 |
delete widgetEventSpies.at(i); |
|
6139 |
} |
|
6140 |
qApp->setWindowIcon(QIcon()); |
|
6141 |
} |
|
6142 |
||
6143 |
#ifdef Q_WS_X11 |
|
6144 |
void tst_QWidget::minAndMaxSizeWithX11BypassWindowManagerHint() |
|
6145 |
{ |
|
6146 |
// Same size as in QWidget::create_sys(). |
|
6147 |
const QSize desktopSize = QApplication::desktop()->size(); |
|
6148 |
const QSize originalSize(desktopSize.width() / 2, desktopSize.height() * 4 / 10); |
|
6149 |
||
6150 |
{ // Maximum size. |
|
6151 |
QWidget widget(0, Qt::X11BypassWindowManagerHint); |
|
6152 |
||
6153 |
const QSize newMaximumSize = widget.size().boundedTo(originalSize) - QSize(10, 10); |
|
6154 |
widget.setMaximumSize(newMaximumSize); |
|
6155 |
QCOMPARE(widget.size(), newMaximumSize); |
|
6156 |
||
6157 |
widget.show(); |
|
6158 |
qt_x11_wait_for_window_manager(&widget); |
|
6159 |
QCOMPARE(widget.size(), newMaximumSize); |
|
6160 |
} |
|
6161 |
||
6162 |
{ // Minimum size. |
|
6163 |
QWidget widget(0, Qt::X11BypassWindowManagerHint); |
|
6164 |
||
6165 |
const QSize newMinimumSize = widget.size().expandedTo(originalSize) + QSize(10, 10); |
|
6166 |
widget.setMinimumSize(newMinimumSize); |
|
6167 |
QCOMPARE(widget.size(), newMinimumSize); |
|
6168 |
||
6169 |
widget.show(); |
|
6170 |
qt_x11_wait_for_window_manager(&widget); |
|
6171 |
QCOMPARE(widget.size(), newMinimumSize); |
|
6172 |
} |
|
6173 |
} |
|
6174 |
||
6175 |
class ShowHideShowWidget : public QWidget |
|
6176 |
{ |
|
6177 |
Q_OBJECT |
|
6178 |
||
6179 |
int state; |
|
6180 |
public: |
|
6181 |
bool gotExpectedMapNotify; |
|
6182 |
||
6183 |
ShowHideShowWidget() |
|
6184 |
: state(0), gotExpectedMapNotify(false) |
|
6185 |
{ |
|
6186 |
startTimer(1000); |
|
6187 |
} |
|
6188 |
||
6189 |
void timerEvent(QTimerEvent *) |
|
6190 |
{ |
|
6191 |
switch (state++) { |
|
6192 |
case 0: |
|
6193 |
show(); |
|
6194 |
break; |
|
6195 |
case 1: |
|
6196 |
emit done(); |
|
6197 |
break; |
|
6198 |
} |
|
6199 |
} |
|
6200 |
||
6201 |
bool x11Event(XEvent *event) |
|
6202 |
{ |
|
6203 |
if (state == 1 && event->type == MapNotify) |
|
6204 |
gotExpectedMapNotify = true; |
|
6205 |
return false; |
|
6206 |
} |
|
6207 |
||
6208 |
signals: |
|
6209 |
void done(); |
|
6210 |
}; |
|
6211 |
||
6212 |
void tst_QWidget::showHideShow() |
|
6213 |
{ |
|
6214 |
ShowHideShowWidget w; |
|
6215 |
w.show(); |
|
6216 |
w.hide(); |
|
6217 |
||
6218 |
QEventLoop eventLoop; |
|
6219 |
connect(&w, SIGNAL(done()), &eventLoop, SLOT(quit())); |
|
6220 |
eventLoop.exec(); |
|
6221 |
||
6222 |
QVERIFY(w.gotExpectedMapNotify); |
|
6223 |
} |
|
6224 |
||
6225 |
void tst_QWidget::clean_qt_x11_enforce_cursor() |
|
6226 |
{ |
|
6227 |
{ |
|
6228 |
QWidget window; |
|
6229 |
QWidget *w = new QWidget(&window); |
|
6230 |
QWidget *child = new QWidget(w); |
|
6231 |
child->setAttribute(Qt::WA_SetCursor, true); |
|
6232 |
||
6233 |
window.show(); |
|
6234 |
QApplication::setActiveWindow(&window); |
|
6235 |
QTest::qWaitForWindowShown(&window); |
|
6236 |
QTest::qWait(100); |
|
6237 |
QCursor::setPos(window.geometry().center()); |
|
6238 |
QTest::qWait(100); |
|
6239 |
||
6240 |
child->setFocus(); |
|
6241 |
QApplication::processEvents(); |
|
6242 |
QTest::qWait(100); |
|
6243 |
||
6244 |
delete w; |
|
6245 |
} |
|
6246 |
||
6247 |
QGraphicsScene scene; |
|
6248 |
QLineEdit *edit = new QLineEdit; |
|
6249 |
scene.addWidget(edit); |
|
6250 |
||
6251 |
// If the test didn't crash, then it passed. |
|
6252 |
} |
|
6253 |
#endif |
|
6254 |
||
6255 |
class EventRecorder : public QObject |
|
6256 |
{ |
|
6257 |
Q_OBJECT |
|
6258 |
||
6259 |
public: |
|
6260 |
typedef QList<QPair<QWidget *, QEvent::Type> > EventList; |
|
6261 |
||
6262 |
EventRecorder(QObject *parent = 0) |
|
6263 |
: QObject(parent) |
|
6264 |
{ } |
|
6265 |
||
6266 |
EventList eventList() |
|
6267 |
{ |
|
6268 |
return events; |
|
6269 |
} |
|
6270 |
||
6271 |
void clear() |
|
6272 |
{ |
|
6273 |
events.clear(); |
|
6274 |
} |
|
6275 |
||
6276 |
bool eventFilter(QObject *object, QEvent *event) |
|
6277 |
{ |
|
6278 |
QWidget *widget = qobject_cast<QWidget *>(object); |
|
6279 |
if (widget && !event->spontaneous()) |
|
6280 |
events.append(qMakePair(widget, event->type())); |
|
6281 |
return false; |
|
6282 |
} |
|
6283 |
||
6284 |
private: |
|
6285 |
EventList events; |
|
6286 |
}; |
|
6287 |
||
6288 |
void tst_QWidget::compatibilityChildInsertedEvents() |
|
6289 |
{ |
|
6290 |
EventRecorder::EventList expected; |
|
6291 |
bool accessibilityEnabled = false; |
|
6292 |
#if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA) |
|
6293 |
accessibilityEnabled = AXAPIEnabled(); |
|
6294 |
#endif |
|
6295 |
||
6296 |
// Move away the cursor; otherwise it might result in an enter event if it's |
|
6297 |
// inside the widget when the widget is shown. |
|
6298 |
QCursor::setPos(qApp->desktop()->availableGeometry().bottomRight()); |
|
6299 |
QTest::qWait(100); |
|
6300 |
||
6301 |
{ |
|
6302 |
// no children created, not shown |
|
6303 |
QWidget widget; |
|
6304 |
EventRecorder spy; |
|
6305 |
widget.installEventFilter(&spy); |
|
6306 |
||
6307 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 1))); |
|
6308 |
||
6309 |
QCoreApplication::sendPostedEvents(); |
|
6310 |
||
6311 |
expected = |
|
6312 |
EventRecorder::EventList() |
|
6313 |
<< qMakePair(&widget, QEvent::PolishRequest) |
|
6314 |
<< qMakePair(&widget, QEvent::Polish) |
|
6315 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1)); |
|
6316 |
QCOMPARE(spy.eventList(), expected); |
|
6317 |
} |
|
6318 |
||
6319 |
{ |
|
6320 |
// no children, shown |
|
6321 |
QWidget widget; |
|
6322 |
EventRecorder spy; |
|
6323 |
widget.installEventFilter(&spy); |
|
6324 |
||
6325 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 1))); |
|
6326 |
||
6327 |
widget.show(); |
|
6328 |
expected = |
|
6329 |
EventRecorder::EventList() |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6330 |
<< qMakePair(&widget, QEvent::WinIdChange) |
0 | 6331 |
<< qMakePair(&widget, QEvent::Polish) |
6332 |
<< qMakePair(&widget, QEvent::Move) |
|
6333 |
<< qMakePair(&widget, QEvent::Resize) |
|
6334 |
<< qMakePair(&widget, QEvent::Show); |
|
6335 |
||
6336 |
if (accessibilityEnabled) |
|
6337 |
expected << qMakePair(&widget, QEvent::AccessibilityPrepare); |
|
6338 |
expected << qMakePair(&widget, QEvent::ShowToParent); |
|
6339 |
QCOMPARE(spy.eventList(), expected); |
|
6340 |
spy.clear(); |
|
6341 |
||
6342 |
QCoreApplication::sendPostedEvents(); |
|
6343 |
expected = |
|
6344 |
EventRecorder::EventList() |
|
6345 |
<< qMakePair(&widget, QEvent::PolishRequest) |
|
6346 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1)) |
|
6347 |
#if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_QWS) || defined(Q_WS_S60) |
|
6348 |
<< qMakePair(&widget, QEvent::UpdateRequest) |
|
6349 |
#endif |
|
6350 |
; |
|
6351 |
QCOMPARE(spy.eventList(), expected); |
|
6352 |
} |
|
6353 |
||
6354 |
{ |
|
6355 |
// 2 children, not shown |
|
6356 |
QWidget widget; |
|
6357 |
EventRecorder spy; |
|
6358 |
widget.installEventFilter(&spy); |
|
6359 |
||
6360 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 1))); |
|
6361 |
||
6362 |
QWidget child1(&widget); |
|
6363 |
QWidget child2; |
|
6364 |
child2.setParent(&widget); |
|
6365 |
||
6366 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 2))); |
|
6367 |
||
6368 |
expected = |
|
6369 |
EventRecorder::EventList() |
|
6370 |
<< qMakePair(&widget, QEvent::ChildAdded) |
|
6371 |
<< qMakePair(&widget, QEvent::ChildAdded); |
|
6372 |
QCOMPARE(spy.eventList(), expected); |
|
6373 |
spy.clear(); |
|
6374 |
||
6375 |
QCoreApplication::sendPostedEvents(); |
|
6376 |
expected = |
|
6377 |
EventRecorder::EventList() |
|
6378 |
#ifdef QT_HAS_QT3SUPPORT |
|
6379 |
<< qMakePair(&widget, QEvent::ChildInsertedRequest) |
|
6380 |
<< qMakePair(&widget, QEvent::ChildInserted) |
|
6381 |
<< qMakePair(&widget, QEvent::ChildInserted) |
|
6382 |
#endif |
|
6383 |
<< qMakePair(&widget, QEvent::PolishRequest) |
|
6384 |
<< qMakePair(&widget, QEvent::Polish) |
|
6385 |
<< qMakePair(&widget, QEvent::ChildPolished) |
|
6386 |
<< qMakePair(&widget, QEvent::ChildPolished) |
|
6387 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1)) |
|
6388 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 2)); |
|
6389 |
QCOMPARE(spy.eventList(), expected); |
|
6390 |
} |
|
6391 |
||
6392 |
{ |
|
6393 |
// 2 children, widget shown |
|
6394 |
QWidget widget; |
|
6395 |
EventRecorder spy; |
|
6396 |
widget.installEventFilter(&spy); |
|
6397 |
||
6398 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 1))); |
|
6399 |
||
6400 |
QWidget child1(&widget); |
|
6401 |
QWidget child2; |
|
6402 |
child2.setParent(&widget); |
|
6403 |
||
6404 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 2))); |
|
6405 |
||
6406 |
expected = |
|
6407 |
EventRecorder::EventList() |
|
6408 |
<< qMakePair(&widget, QEvent::ChildAdded) |
|
6409 |
<< qMakePair(&widget, QEvent::ChildAdded); |
|
6410 |
QCOMPARE(spy.eventList(), expected); |
|
6411 |
spy.clear(); |
|
6412 |
||
6413 |
widget.show(); |
|
6414 |
expected = |
|
6415 |
EventRecorder::EventList() |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6416 |
<< qMakePair(&widget, QEvent::WinIdChange) |
0 | 6417 |
<< qMakePair(&widget, QEvent::Polish) |
6418 |
#ifdef QT_HAS_QT3SUPPORT |
|
6419 |
<< qMakePair(&widget, QEvent::ChildInserted) |
|
6420 |
<< qMakePair(&widget, QEvent::ChildInserted) |
|
6421 |
#endif |
|
6422 |
<< qMakePair(&widget, QEvent::ChildPolished) |
|
6423 |
<< qMakePair(&widget, QEvent::ChildPolished) |
|
6424 |
<< qMakePair(&widget, QEvent::Move) |
|
6425 |
<< qMakePair(&widget, QEvent::Resize) |
|
6426 |
<< qMakePair(&widget, QEvent::Show); |
|
6427 |
||
6428 |
if (accessibilityEnabled) |
|
6429 |
expected << qMakePair(&widget, QEvent::AccessibilityPrepare); |
|
6430 |
expected << qMakePair(&widget, QEvent::ShowToParent); |
|
6431 |
QCOMPARE(spy.eventList(), expected); |
|
6432 |
spy.clear(); |
|
6433 |
||
6434 |
QCoreApplication::sendPostedEvents(); |
|
6435 |
expected = |
|
6436 |
EventRecorder::EventList() |
|
6437 |
#ifdef QT_HAS_QT3SUPPORT |
|
6438 |
<< qMakePair(&widget, QEvent::ChildInsertedRequest) |
|
6439 |
#endif |
|
6440 |
<< qMakePair(&widget, QEvent::PolishRequest) |
|
6441 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1)) |
|
6442 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 2)) |
|
6443 |
#if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_QWS) || defined(Q_WS_S60) |
|
6444 |
<< qMakePair(&widget, QEvent::UpdateRequest) |
|
6445 |
#endif |
|
6446 |
; |
|
6447 |
QCOMPARE(spy.eventList(), expected); |
|
6448 |
} |
|
6449 |
||
6450 |
{ |
|
6451 |
// 2 children, but one is reparented away, not shown |
|
6452 |
QWidget widget; |
|
6453 |
EventRecorder spy; |
|
6454 |
widget.installEventFilter(&spy); |
|
6455 |
||
6456 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 1))); |
|
6457 |
||
6458 |
QWidget child1(&widget); |
|
6459 |
QWidget child2; |
|
6460 |
child2.setParent(&widget); |
|
6461 |
child2.setParent(0); |
|
6462 |
||
6463 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 2))); |
|
6464 |
||
6465 |
expected = |
|
6466 |
EventRecorder::EventList() |
|
6467 |
<< qMakePair(&widget, QEvent::ChildAdded) |
|
6468 |
<< qMakePair(&widget, QEvent::ChildAdded) |
|
6469 |
<< qMakePair(&widget, QEvent::ChildRemoved); |
|
6470 |
QCOMPARE(spy.eventList(), expected); |
|
6471 |
spy.clear(); |
|
6472 |
||
6473 |
QCoreApplication::sendPostedEvents(); |
|
6474 |
expected = |
|
6475 |
EventRecorder::EventList() |
|
6476 |
#ifdef QT_HAS_QT3SUPPORT |
|
6477 |
<< qMakePair(&widget, QEvent::ChildInsertedRequest) |
|
6478 |
<< qMakePair(&widget, QEvent::ChildInserted) |
|
6479 |
#endif |
|
6480 |
<< qMakePair(&widget, QEvent::PolishRequest) |
|
6481 |
<< qMakePair(&widget, QEvent::Polish) |
|
6482 |
<< qMakePair(&widget, QEvent::ChildPolished) |
|
6483 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1)) |
|
6484 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 2)); |
|
6485 |
QCOMPARE(spy.eventList(), expected); |
|
6486 |
} |
|
6487 |
||
6488 |
{ |
|
6489 |
// 2 children, but one is reparented away, then widget is shown |
|
6490 |
QWidget widget; |
|
6491 |
EventRecorder spy; |
|
6492 |
widget.installEventFilter(&spy); |
|
6493 |
||
6494 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 1))); |
|
6495 |
||
6496 |
QWidget child1(&widget); |
|
6497 |
QWidget child2; |
|
6498 |
child2.setParent(&widget); |
|
6499 |
child2.setParent(0); |
|
6500 |
||
6501 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 2))); |
|
6502 |
||
6503 |
expected = |
|
6504 |
EventRecorder::EventList() |
|
6505 |
<< qMakePair(&widget, QEvent::ChildAdded) |
|
6506 |
<< qMakePair(&widget, QEvent::ChildAdded) |
|
6507 |
<< qMakePair(&widget, QEvent::ChildRemoved); |
|
6508 |
QCOMPARE(spy.eventList(), expected); |
|
6509 |
spy.clear(); |
|
6510 |
||
6511 |
widget.show(); |
|
6512 |
expected = |
|
6513 |
EventRecorder::EventList() |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6514 |
<< qMakePair(&widget, QEvent::WinIdChange) |
0 | 6515 |
<< qMakePair(&widget, QEvent::Polish) |
6516 |
#ifdef QT_HAS_QT3SUPPORT |
|
6517 |
<< qMakePair(&widget, QEvent::ChildInserted) |
|
6518 |
#endif |
|
6519 |
<< qMakePair(&widget, QEvent::ChildPolished) |
|
6520 |
<< qMakePair(&widget, QEvent::Move) |
|
6521 |
<< qMakePair(&widget, QEvent::Resize) |
|
6522 |
<< qMakePair(&widget, QEvent::Show); |
|
6523 |
||
6524 |
if (accessibilityEnabled) |
|
6525 |
expected << qMakePair(&widget, QEvent::AccessibilityPrepare); |
|
6526 |
expected << qMakePair(&widget, QEvent::ShowToParent); |
|
6527 |
QCOMPARE(spy.eventList(), expected); |
|
6528 |
spy.clear(); |
|
6529 |
||
6530 |
QCoreApplication::sendPostedEvents(); |
|
6531 |
expected = |
|
6532 |
EventRecorder::EventList() |
|
6533 |
#ifdef QT_HAS_QT3SUPPORT |
|
6534 |
<< qMakePair(&widget, QEvent::ChildInsertedRequest) |
|
6535 |
#endif |
|
6536 |
<< qMakePair(&widget, QEvent::PolishRequest) |
|
6537 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1)) |
|
6538 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 2)) |
|
6539 |
#if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_QWS) || defined(Q_WS_S60) |
|
6540 |
<< qMakePair(&widget, QEvent::UpdateRequest) |
|
6541 |
#endif |
|
6542 |
; |
|
6543 |
QCOMPARE(spy.eventList(), expected); |
|
6544 |
} |
|
6545 |
} |
|
6546 |
||
6547 |
class RenderWidget : public QWidget |
|
6548 |
{ |
|
6549 |
public: |
|
6550 |
RenderWidget(QWidget *source) |
|
6551 |
: source(source), ellipse(false) {} |
|
6552 |
||
6553 |
void setEllipseEnabled(bool enable = true) |
|
6554 |
{ |
|
6555 |
ellipse = enable; |
|
6556 |
update(); |
|
6557 |
} |
|
6558 |
||
6559 |
protected: |
|
6560 |
void paintEvent(QPaintEvent *) |
|
6561 |
{ |
|
6562 |
if (ellipse) { |
|
6563 |
QPainter painter(this); |
|
6564 |
painter.fillRect(rect(), Qt::red); |
|
6565 |
painter.end(); |
|
6566 |
QRegion regionToRender = QRegion(0, 0, source->width(), source->height() / 2, |
|
6567 |
QRegion::Ellipse); |
|
6568 |
source->render(this, QPoint(0, 30), regionToRender); |
|
6569 |
} else { |
|
6570 |
source->render(this); |
|
6571 |
} |
|
6572 |
} |
|
6573 |
||
6574 |
private: |
|
6575 |
QWidget *source; |
|
6576 |
bool ellipse; |
|
6577 |
}; |
|
6578 |
||
6579 |
void tst_QWidget::render() |
|
6580 |
{ |
|
6581 |
return; |
|
6582 |
QCalendarWidget source; |
|
6583 |
// disable anti-aliasing to eliminate potential differences when subpixel antialiasing |
|
6584 |
// is enabled on the screen |
|
6585 |
QFont f; |
|
6586 |
f.setStyleStrategy(QFont::NoAntialias); |
|
6587 |
source.setFont(f); |
|
6588 |
source.show(); |
|
6589 |
QTest::qWaitForWindowShown(&source); |
|
6590 |
||
6591 |
// Render the entire source into target. |
|
6592 |
RenderWidget target(&source); |
|
6593 |
target.resize(source.size()); |
|
6594 |
target.show(); |
|
6595 |
||
6596 |
qApp->processEvents(); |
|
6597 |
qApp->sendPostedEvents(); |
|
6598 |
QTest::qWait(250); |
|
6599 |
||
6600 |
QImage sourceImage = QPixmap::grabWidget(&source).toImage(); |
|
6601 |
qApp->processEvents(); |
|
6602 |
QImage targetImage = QPixmap::grabWidget(&target).toImage(); |
|
6603 |
qApp->processEvents(); |
|
6604 |
QCOMPARE(sourceImage, targetImage); |
|
6605 |
||
6606 |
// Fill target.rect() will Qt::red and render |
|
6607 |
// QRegion(0, 0, source->width(), source->height() / 2, QRegion::Ellipse) |
|
6608 |
// of source into target with offset (0, 30). |
|
6609 |
target.setEllipseEnabled(); |
|
6610 |
qApp->processEvents(); |
|
6611 |
qApp->sendPostedEvents(); |
|
6612 |
||
6613 |
targetImage = QPixmap::grabWidget(&target).toImage(); |
|
6614 |
QVERIFY(sourceImage != targetImage); |
|
6615 |
||
6616 |
QCOMPARE(targetImage.pixel(target.width() / 2, 29), QColor(Qt::red).rgb()); |
|
6617 |
QCOMPARE(targetImage.pixel(target.width() / 2, 30), sourceImage.pixel(source.width() / 2, 0)); |
|
6618 |
||
6619 |
// Test that a child widget properly fills its background |
|
6620 |
{ |
|
6621 |
QWidget window; |
|
6622 |
window.resize(100, 100); |
|
6623 |
// prevent custom styles |
|
6624 |
window.setStyle(new QWindowsStyle); |
|
6625 |
window.show(); |
|
6626 |
QTest::qWaitForWindowShown(&window); |
|
6627 |
QWidget child(&window); |
|
6628 |
child.resize(window.size()); |
|
6629 |
child.show(); |
|
6630 |
||
6631 |
qApp->processEvents(); |
|
6632 |
QCOMPARE(QPixmap::grabWidget(&child), QPixmap::grabWidget(&window)); |
|
6633 |
} |
|
6634 |
||
6635 |
{ // Check that the target offset is correct. |
|
6636 |
QWidget widget; |
|
6637 |
widget.resize(200, 200); |
|
6638 |
widget.setAutoFillBackground(true); |
|
6639 |
widget.setPalette(Qt::red); |
|
6640 |
// prevent custom styles |
|
6641 |
widget.setStyle(new QWindowsStyle); |
|
6642 |
widget.show(); |
|
6643 |
QTest::qWaitForWindowShown(&widget); |
|
6644 |
QImage image(widget.size(), QImage::Format_RGB32); |
|
6645 |
image.fill(QColor(Qt::blue).rgb()); |
|
6646 |
||
6647 |
// Target offset (0, 0) |
|
6648 |
widget.render(&image, QPoint(), QRect(20, 20, 100, 100)); |
|
6649 |
QCOMPARE(image.pixel(0, 0), QColor(Qt::red).rgb()); |
|
6650 |
QCOMPARE(image.pixel(99, 99), QColor(Qt::red).rgb()); |
|
6651 |
QCOMPARE(image.pixel(100, 100), QColor(Qt::blue).rgb()); |
|
6652 |
||
6653 |
// Target offset (20, 20). |
|
6654 |
image.fill(QColor(Qt::blue).rgb()); |
|
6655 |
widget.render(&image, QPoint(20, 20), QRect(20, 20, 100, 100)); |
|
6656 |
QCOMPARE(image.pixel(0, 0), QColor(Qt::blue).rgb()); |
|
6657 |
QCOMPARE(image.pixel(19, 19), QColor(Qt::blue).rgb()); |
|
6658 |
QCOMPARE(image.pixel(20, 20), QColor(Qt::red).rgb()); |
|
6659 |
QCOMPARE(image.pixel(119, 119), QColor(Qt::red).rgb()); |
|
6660 |
QCOMPARE(image.pixel(120, 120), QColor(Qt::blue).rgb()); |
|
6661 |
} |
|
6662 |
} |
|
6663 |
||
6664 |
// On Windows the active palette is used instead of the inactive palette even |
|
6665 |
// though the widget is invisible. This is probably related to task 178507/168682, |
|
6666 |
// but for the renderInvisible test it doesn't matter, we're mostly interested |
|
6667 |
// in testing the geometry so just workaround the palette issue for now. |
|
6668 |
static void workaroundPaletteIssue(QWidget *widget) |
|
6669 |
{ |
|
6670 |
#ifndef Q_WS_WIN |
|
6671 |
return; |
|
6672 |
#endif |
|
6673 |
if (!widget) |
|
6674 |
return; |
|
6675 |
||
6676 |
QWidget *navigationBar = qFindChild<QWidget *>(widget, QLatin1String("qt_calendar_navigationbar")); |
|
6677 |
QVERIFY(navigationBar); |
|
6678 |
||
6679 |
QPalette palette = navigationBar->palette(); |
|
6680 |
const QColor background = palette.color(QPalette::Inactive, navigationBar->backgroundRole()); |
|
6681 |
const QColor highlightedText = palette.color(QPalette::Inactive, QPalette::HighlightedText); |
|
6682 |
palette.setColor(QPalette::Active, navigationBar->backgroundRole(), background); |
|
6683 |
palette.setColor(QPalette::Active, QPalette::HighlightedText, highlightedText); |
|
6684 |
navigationBar->setPalette(palette); |
|
6685 |
} |
|
6686 |
||
6687 |
//#define RENDER_DEBUG |
|
6688 |
void tst_QWidget::renderInvisible() |
|
6689 |
{ |
|
6690 |
QCalendarWidget *calendar = new QCalendarWidget; |
|
6691 |
// disable anti-aliasing to eliminate potential differences when subpixel antialiasing |
|
6692 |
// is enabled on the screen |
|
6693 |
QFont f; |
|
6694 |
f.setStyleStrategy(QFont::NoAntialias); |
|
6695 |
calendar->setFont(f); |
|
6696 |
calendar->show(); |
|
6697 |
QTest::qWaitForWindowShown(calendar); |
|
6698 |
||
6699 |
// Create a dummy focus widget to get rid of focus rect in reference image. |
|
6700 |
QLineEdit dummyFocusWidget; |
|
6701 |
dummyFocusWidget.show(); |
|
6702 |
QTest::qWaitForWindowShown(&dummyFocusWidget); |
|
6703 |
qApp->processEvents(); |
|
6704 |
QTest::qWait(120); |
|
6705 |
||
6706 |
// Create normal reference image. |
|
6707 |
const QSize calendarSize = calendar->size(); |
|
6708 |
QImage referenceImage(calendarSize, QImage::Format_ARGB32); |
|
6709 |
calendar->render(&referenceImage); |
|
6710 |
#ifdef RENDER_DEBUG |
|
6711 |
referenceImage.save("referenceImage.png"); |
|
6712 |
#endif |
|
6713 |
QVERIFY(!referenceImage.isNull()); |
|
6714 |
||
6715 |
// Create resized reference image. |
|
6716 |
const QSize calendarSizeResized = calendar->size() + QSize(50, 50); |
|
6717 |
calendar->resize(calendarSizeResized); |
|
6718 |
qApp->processEvents(); |
|
6719 |
QTest::qWait(30); |
|
6720 |
QImage referenceImageResized(calendarSizeResized, QImage::Format_ARGB32); |
|
6721 |
calendar->render(&referenceImageResized); |
|
6722 |
#ifdef RENDER_DEBUG |
|
6723 |
referenceImageResized.save("referenceImageResized.png"); |
|
6724 |
#endif |
|
6725 |
QVERIFY(!referenceImageResized.isNull()); |
|
6726 |
||
6727 |
// Explicitly hide the calendar. |
|
6728 |
calendar->hide(); |
|
6729 |
qApp->processEvents(); |
|
6730 |
QTest::qWait(30); |
|
6731 |
workaroundPaletteIssue(calendar); |
|
6732 |
||
6733 |
{ // Make sure we get the same image when the calendar is explicitly hidden. |
|
6734 |
QImage testImage(calendarSizeResized, QImage::Format_ARGB32); |
|
6735 |
calendar->render(&testImage); |
|
6736 |
#ifdef RENDER_DEBUG |
|
6737 |
testImage.save("explicitlyHiddenCalendarResized.png"); |
|
6738 |
#endif |
|
6739 |
QCOMPARE(testImage, referenceImageResized); |
|
6740 |
} |
|
6741 |
||
6742 |
// Now that we have reference images we can delete the source and re-create |
|
6743 |
// the calendar and check that we get the same images from a calendar which has never |
|
6744 |
// been visible, laid out or created (Qt::WA_WState_Created). |
|
6745 |
delete calendar; |
|
6746 |
calendar = new QCalendarWidget; |
|
6747 |
calendar->setFont(f); |
|
6748 |
workaroundPaletteIssue(calendar); |
|
6749 |
||
6750 |
{ // Never been visible, created or laid out. |
|
6751 |
QImage testImage(calendarSize, QImage::Format_ARGB32); |
|
6752 |
calendar->render(&testImage); |
|
6753 |
#ifdef RENDER_DEBUG |
|
6754 |
testImage.save("neverBeenVisibleCreatedOrLaidOut.png"); |
|
6755 |
#endif |
|
6756 |
QCOMPARE(testImage, referenceImage); |
|
6757 |
} |
|
6758 |
||
6759 |
calendar->hide(); |
|
6760 |
qApp->processEvents(); |
|
6761 |
QTest::qWait(30); |
|
6762 |
||
6763 |
{ // Calendar explicitly hidden. |
|
6764 |
QImage testImage(calendarSize, QImage::Format_ARGB32); |
|
6765 |
calendar->render(&testImage); |
|
6766 |
#ifdef RENDER_DEBUG |
|
6767 |
testImage.save("explicitlyHiddenCalendar.png"); |
|
6768 |
#endif |
|
6769 |
QCOMPARE(testImage, referenceImage); |
|
6770 |
} |
|
6771 |
||
6772 |
// Get navigation bar and explicitly hide it. |
|
6773 |
QWidget *navigationBar = qFindChild<QWidget *>(calendar, QLatin1String("qt_calendar_navigationbar")); |
|
6774 |
QVERIFY(navigationBar); |
|
6775 |
navigationBar->hide(); |
|
6776 |
||
6777 |
{ // Check that the navigation bar isn't drawn when rendering the entire calendar. |
|
6778 |
QImage testImage(calendarSize, QImage::Format_ARGB32); |
|
6779 |
calendar->render(&testImage); |
|
6780 |
#ifdef RENDER_DEBUG |
|
6781 |
testImage.save("calendarWithoutNavigationBar.png"); |
|
6782 |
#endif |
|
6783 |
QVERIFY(testImage != referenceImage); |
|
6784 |
} |
|
6785 |
||
6786 |
{ // Make sure the navigation bar renders correctly even though it's hidden. |
|
6787 |
QImage testImage(navigationBar->size(), QImage::Format_ARGB32); |
|
6788 |
navigationBar->render(&testImage); |
|
6789 |
#ifdef RENDER_DEBUG |
|
6790 |
testImage.save("explicitlyHiddenNavigationBar.png"); |
|
6791 |
#endif |
|
6792 |
QCOMPARE(testImage, referenceImage.copy(navigationBar->rect())); |
|
6793 |
} |
|
6794 |
||
6795 |
// Get next month button. |
|
6796 |
QWidget *nextMonthButton = qFindChild<QWidget *>(navigationBar, QLatin1String("qt_calendar_nextmonth")); |
|
6797 |
QVERIFY(nextMonthButton); |
|
6798 |
||
6799 |
{ // Render next month button. |
|
6800 |
// Fill test image with correct background color. |
|
6801 |
QImage testImage(nextMonthButton->size(), QImage::Format_ARGB32); |
|
6802 |
navigationBar->render(&testImage, QPoint(), QRegion(), QWidget::RenderFlags()); |
|
6803 |
#ifdef RENDER_DEBUG |
|
6804 |
testImage.save("nextMonthButtonBackground.png"); |
|
6805 |
#endif |
|
6806 |
||
6807 |
// Set the button's background color to Qt::transparent; otherwise it will fill the |
|
6808 |
// background with QPalette::Window. |
|
6809 |
const QPalette originalPalette = nextMonthButton->palette(); |
|
6810 |
QPalette palette = originalPalette; |
|
6811 |
palette.setColor(QPalette::Window, Qt::transparent); |
|
6812 |
nextMonthButton->setPalette(palette); |
|
6813 |
||
6814 |
// Render the button on top of the background. |
|
6815 |
nextMonthButton->render(&testImage); |
|
6816 |
#ifdef RENDER_DEBUG |
|
6817 |
testImage.save("nextMonthButton.png"); |
|
6818 |
#endif |
|
6819 |
const QRect buttonRect(nextMonthButton->mapTo(calendar, QPoint()), nextMonthButton->size()); |
|
6820 |
QCOMPARE(testImage, referenceImage.copy(buttonRect)); |
|
6821 |
||
6822 |
// Restore palette. |
|
6823 |
nextMonthButton->setPalette(originalPalette); |
|
6824 |
} |
|
6825 |
||
6826 |
// Navigation bar isn't explicitly hidden anymore. |
|
6827 |
navigationBar->show(); |
|
6828 |
qApp->processEvents(); |
|
6829 |
QTest::qWait(30); |
|
6830 |
QVERIFY(!calendar->isVisible()); |
|
6831 |
||
6832 |
// Now, completely mess up the layout. This will trigger an update on the layout |
|
6833 |
// when the calendar is visible or shown, but it's not. QWidget::render must therefore |
|
6834 |
// make sure the layout is activated before rendering. |
|
6835 |
QVERIFY(!calendar->isVisible()); |
|
6836 |
calendar->resize(calendarSizeResized); |
|
6837 |
qApp->processEvents(); |
|
6838 |
||
6839 |
{ // Make sure we get an image equal to the resized reference image. |
|
6840 |
QImage testImage(calendarSizeResized, QImage::Format_ARGB32); |
|
6841 |
calendar->render(&testImage); |
|
6842 |
#ifdef RENDER_DEBUG |
|
6843 |
testImage.save("calendarResized.png"); |
|
6844 |
#endif |
|
6845 |
QCOMPARE(testImage, referenceImageResized); |
|
6846 |
} |
|
6847 |
||
6848 |
{ // Make sure we lay out the widget correctly the first time it's rendered. |
|
6849 |
QCalendarWidget calendar; |
|
6850 |
const QSize calendarSize = calendar.sizeHint(); |
|
6851 |
||
6852 |
QImage image(2 * calendarSize, QImage::Format_ARGB32); |
|
6853 |
image.fill(QColor(Qt::red).rgb()); |
|
6854 |
calendar.render(&image); |
|
6855 |
||
6856 |
for (int i = calendarSize.height(); i < 2 * calendarSize.height(); ++i) |
|
6857 |
for (int j = calendarSize.width(); j < 2 * calendarSize.width(); ++j) |
|
6858 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
6859 |
} |
|
6860 |
||
6861 |
{ // Ensure that we don't call adjustSize() on invisible top-levels if render() is called |
|
6862 |
// right after widgets have been added/removed to/from its layout. |
|
6863 |
QWidget topLevel; |
|
6864 |
topLevel.setLayout(new QVBoxLayout); |
|
6865 |
||
6866 |
QWidget *widget = new QLineEdit; |
|
6867 |
topLevel.layout()->addWidget(widget); |
|
6868 |
||
6869 |
const QSize initialSize = topLevel.size(); |
|
6870 |
QPixmap pixmap(topLevel.sizeHint()); |
|
6871 |
topLevel.render(&pixmap); // triggers adjustSize() |
|
6872 |
const QSize finalSize = topLevel.size(); |
|
6873 |
QVERIFY(finalSize != initialSize); |
|
6874 |
||
6875 |
topLevel.layout()->removeWidget(widget); |
|
6876 |
QCOMPARE(topLevel.size(), finalSize); |
|
6877 |
topLevel.render(&pixmap); |
|
6878 |
QCOMPARE(topLevel.size(), finalSize); |
|
6879 |
||
6880 |
topLevel.layout()->addWidget(widget); |
|
6881 |
QCOMPARE(topLevel.size(), finalSize); |
|
6882 |
topLevel.render(&pixmap); |
|
6883 |
QCOMPARE(topLevel.size(), finalSize); |
|
6884 |
} |
|
6885 |
} |
|
6886 |
||
6887 |
void tst_QWidget::renderWithPainter() |
|
6888 |
{ |
|
6889 |
QWidget widget; |
|
6890 |
// prevent custom styles |
|
6891 |
widget.setStyle(new QWindowsStyle); |
|
6892 |
widget.show(); |
|
6893 |
widget.resize(70, 50); |
|
6894 |
widget.setAutoFillBackground(true); |
|
6895 |
widget.setPalette(Qt::black); |
|
6896 |
||
6897 |
// Render the entire widget onto the image. |
|
6898 |
QImage image(QSize(70, 50), QImage::Format_ARGB32); |
|
6899 |
image.fill(QColor(Qt::red).rgb()); |
|
6900 |
QPainter painter(&image); |
|
6901 |
widget.render(&painter); |
|
6902 |
||
6903 |
for (int i = 0; i < image.height(); ++i) { |
|
6904 |
for (int j = 0; j < image.width(); ++j) |
|
6905 |
QCOMPARE(image.pixel(j, i), QColor(Qt::black).rgb()); |
|
6906 |
} |
|
6907 |
||
6908 |
// Translate painter (10, 10). |
|
6909 |
painter.save(); |
|
6910 |
image.fill(QColor(Qt::red).rgb()); |
|
6911 |
painter.translate(10, 10); |
|
6912 |
widget.render(&painter); |
|
6913 |
painter.restore(); |
|
6914 |
||
6915 |
for (int i = 0; i < image.height(); ++i) { |
|
6916 |
for (int j = 0; j < image.width(); ++j) { |
|
6917 |
if (i < 10 || j < 10) |
|
6918 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
6919 |
else |
|
6920 |
QCOMPARE(image.pixel(j, i), QColor(Qt::black).rgb()); |
|
6921 |
} |
|
6922 |
} |
|
6923 |
||
6924 |
// Pass target offset (10, 10) (the same as QPainter::translate). |
|
6925 |
image.fill(QColor(Qt::red).rgb()); |
|
6926 |
widget.render(&painter, QPoint(10, 10)); |
|
6927 |
||
6928 |
for (int i = 0; i < image.height(); ++i) { |
|
6929 |
for (int j = 0; j < image.width(); ++j) { |
|
6930 |
if (i < 10 || j < 10) |
|
6931 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
6932 |
else |
|
6933 |
QCOMPARE(image.pixel(j, i), QColor(Qt::black).rgb()); |
|
6934 |
} |
|
6935 |
} |
|
6936 |
||
6937 |
// Translate (10, 10) and pass target offset (10, 10). |
|
6938 |
painter.save(); |
|
6939 |
image.fill(QColor(Qt::red).rgb()); |
|
6940 |
painter.translate(10, 10); |
|
6941 |
widget.render(&painter, QPoint(10, 10)); |
|
6942 |
painter.restore(); |
|
6943 |
||
6944 |
for (int i = 0; i < image.height(); ++i) { |
|
6945 |
for (int j = 0; j < image.width(); ++j) { |
|
6946 |
if (i < 20 || j < 20) |
|
6947 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
6948 |
else |
|
6949 |
QCOMPARE(image.pixel(j, i), QColor(Qt::black).rgb()); |
|
6950 |
} |
|
6951 |
} |
|
6952 |
||
6953 |
// Rotate painter 90 degrees. |
|
6954 |
painter.save(); |
|
6955 |
image.fill(QColor(Qt::red).rgb()); |
|
6956 |
painter.rotate(90); |
|
6957 |
widget.render(&painter); |
|
6958 |
painter.restore(); |
|
6959 |
||
6960 |
for (int i = 0; i < image.height(); ++i) { |
|
6961 |
for (int j = 0; j < image.width(); ++j) |
|
6962 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
6963 |
} |
|
6964 |
||
6965 |
// Translate and rotate. |
|
6966 |
image.fill(QColor(Qt::red).rgb()); |
|
6967 |
widget.resize(40, 10); |
|
6968 |
painter.translate(10, 10); |
|
6969 |
painter.rotate(90); |
|
6970 |
widget.render(&painter); |
|
6971 |
||
6972 |
for (int i = 0; i < image.height(); ++i) { |
|
6973 |
for (int j = 0; j < image.width(); ++j) { |
|
6974 |
if (i >= 10 && j >= 0 && j < 10) |
|
6975 |
QCOMPARE(image.pixel(j, i), QColor(Qt::black).rgb()); |
|
6976 |
else |
|
6977 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
6978 |
} |
|
6979 |
} |
|
6980 |
||
6981 |
// Make sure QWidget::render does not modify the render hints set on the painter. |
|
6982 |
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform |
|
6983 |
| QPainter::NonCosmeticDefaultPen | QPainter::TextAntialiasing); |
|
6984 |
QPainter::RenderHints oldRenderHints = painter.renderHints(); |
|
6985 |
widget.render(&painter); |
|
6986 |
QCOMPARE(painter.renderHints(), oldRenderHints); |
|
6987 |
} |
|
6988 |
||
6989 |
void tst_QWidget::render_task188133() |
|
6990 |
{ |
|
6991 |
QMainWindow mainWindow; |
|
6992 |
#if defined(QT3_SUPPORT) |
|
6993 |
mainWindow.setCentralWidget(new Q3TextEdit); |
|
6994 |
#endif |
|
6995 |
// Make sure QWidget::render does not trigger QWidget::repaint/update |
|
6996 |
// and asserts for Qt::WA_WState_Created. |
|
6997 |
QPixmap pixmap = QPixmap::grabWidget(&mainWindow); |
|
6998 |
} |
|
6999 |
||
7000 |
void tst_QWidget::render_task211796() |
|
7001 |
{ |
|
7002 |
class MyWidget : public QWidget |
|
7003 |
{ |
|
7004 |
void resizeEvent(QResizeEvent *) |
|
7005 |
{ |
|
7006 |
QPixmap pixmap(size()); |
|
7007 |
render(&pixmap); |
|
7008 |
} |
|
7009 |
}; |
|
7010 |
||
7011 |
{ // Please don't die in a resize recursion. |
|
7012 |
MyWidget widget; |
|
7013 |
widget.resize(200, 200); |
|
7014 |
widget.show(); |
|
7015 |
} |
|
7016 |
||
7017 |
{ // Same check with a deeper hierarchy. |
|
7018 |
QWidget widget; |
|
7019 |
widget.show(); |
|
7020 |
QWidget child(&widget); |
|
7021 |
MyWidget grandChild; |
|
7022 |
grandChild.setParent(&child); |
|
7023 |
grandChild.resize(100, 100); |
|
7024 |
child.show(); |
|
7025 |
} |
|
7026 |
} |
|
7027 |
||
7028 |
void tst_QWidget::render_task217815() |
|
7029 |
{ |
|
7030 |
// Make sure we don't change the size of the widget when calling |
|
7031 |
// render() and the widget has an explicit size set. |
|
7032 |
// This was a problem on Windows because we called createWinId(), |
|
7033 |
// which in turn enforced the size to be bigger than the smallest |
|
7034 |
// possible native window size (which is (115,something) on WinXP). |
|
7035 |
QWidget widget; |
|
7036 |
const QSize explicitSize(80, 20); |
|
7037 |
widget.resize(explicitSize); |
|
7038 |
QCOMPARE(widget.size(), explicitSize); |
|
7039 |
||
7040 |
QPixmap pixmap(explicitSize); |
|
7041 |
widget.render(&pixmap); |
|
7042 |
||
7043 |
QCOMPARE(widget.size(), explicitSize); |
|
7044 |
} |
|
7045 |
||
7046 |
void tst_QWidget::render_windowOpacity() |
|
7047 |
{ |
|
7048 |
#ifdef Q_OS_WINCE |
|
7049 |
QSKIP("Window Opacity is not supported on Windows CE", SkipAll); |
|
7050 |
#endif |
|
7051 |
||
7052 |
const qreal opacity = 0.5; |
|
7053 |
||
7054 |
{ // Check that the painter opacity effects the widget drawing. |
|
7055 |
QWidget topLevel; |
|
7056 |
QWidget child(&topLevel); |
|
7057 |
child.resize(50, 50); |
|
7058 |
child.setPalette(Qt::red); |
|
7059 |
child.setAutoFillBackground(true); |
|
7060 |
||
7061 |
QPixmap expected(child.size()); |
|
7062 |
#ifdef Q_WS_X11 |
|
7063 |
if (expected.depth() < 24) { |
|
7064 |
QSKIP("This test won't give correct results with dithered pixmaps", SkipAll); |
|
7065 |
} |
|
7066 |
#endif |
|
7067 |
expected.fill(Qt::green); |
|
7068 |
QPainter painter(&expected); |
|
7069 |
painter.setOpacity(opacity); |
|
7070 |
painter.fillRect(QRect(QPoint(0, 0), child.size()), Qt::red); |
|
7071 |
painter.end(); |
|
7072 |
||
7073 |
QPixmap result(child.size()); |
|
7074 |
result.fill(Qt::green); |
|
7075 |
painter.begin(&result); |
|
7076 |
painter.setOpacity(opacity); |
|
7077 |
child.render(&painter); |
|
7078 |
painter.end(); |
|
7079 |
QCOMPARE(result, expected); |
|
7080 |
} |
|
7081 |
||
7082 |
{ // Combine the opacity set on the painter with the widget opacity. |
|
7083 |
class MyWidget : public QWidget |
|
7084 |
{ |
|
7085 |
public: |
|
7086 |
void paintEvent(QPaintEvent *) |
|
7087 |
{ |
|
7088 |
QPainter painter(this); |
|
7089 |
painter.setOpacity(opacity); |
|
7090 |
QCOMPARE(painter.opacity(), opacity); |
|
7091 |
painter.fillRect(rect(), Qt::red); |
|
7092 |
} |
|
7093 |
qreal opacity; |
|
7094 |
}; |
|
7095 |
||
7096 |
MyWidget widget; |
|
7097 |
widget.resize(50, 50); |
|
7098 |
widget.opacity = opacity; |
|
7099 |
widget.setPalette(Qt::blue); |
|
7100 |
widget.setAutoFillBackground(true); |
|
7101 |
||
7102 |
QPixmap expected(widget.size()); |
|
7103 |
expected.fill(Qt::green); |
|
7104 |
QPainter painter(&expected); |
|
7105 |
painter.setOpacity(opacity); |
|
7106 |
QPixmap pixmap(widget.size()); |
|
7107 |
pixmap.fill(Qt::blue); |
|
7108 |
QPainter pixmapPainter(&pixmap); |
|
7109 |
pixmapPainter.setOpacity(opacity); |
|
7110 |
pixmapPainter.fillRect(QRect(QPoint(), widget.size()), Qt::red); |
|
7111 |
painter.drawPixmap(QPoint(), pixmap); |
|
7112 |
painter.end(); |
|
7113 |
||
7114 |
QPixmap result(widget.size()); |
|
7115 |
result.fill(Qt::green); |
|
7116 |
painter.begin(&result); |
|
7117 |
painter.setOpacity(opacity); |
|
7118 |
widget.render(&painter); |
|
7119 |
painter.end(); |
|
7120 |
QCOMPARE(result, expected); |
|
7121 |
} |
|
7122 |
} |
|
7123 |
||
7124 |
void tst_QWidget::render_systemClip() |
|
7125 |
{ |
|
7126 |
QWidget widget; |
|
7127 |
widget.setPalette(Qt::blue); |
|
7128 |
widget.resize(100, 100); |
|
7129 |
||
7130 |
QImage image(widget.size(), QImage::Format_RGB32); |
|
7131 |
image.fill(QColor(Qt::red).rgb()); |
|
7132 |
||
7133 |
QPaintEngine *paintEngine = image.paintEngine(); |
|
7134 |
QVERIFY(paintEngine); |
|
7135 |
paintEngine->setSystemClip(QRegion(0, 0, 50, 50)); |
|
7136 |
||
7137 |
QPainter painter(&image); |
|
7138 |
// Make sure we're using the same paint engine and has the right clip set. |
|
7139 |
QCOMPARE(painter.paintEngine(), paintEngine); |
|
7140 |
QCOMPARE(paintEngine->systemClip(), QRegion(0, 0, 50, 50)); |
|
7141 |
||
7142 |
// Translate painter outside system clip. |
|
7143 |
painter.translate(50, 0); |
|
7144 |
widget.render(&painter); |
|
7145 |
||
7146 |
#ifdef RENDER_DEBUG |
|
7147 |
image.save("outside_systemclip.png"); |
|
7148 |
#endif |
|
7149 |
||
7150 |
// All pixels should be red. |
|
7151 |
for (int i = 0; i < image.height(); ++i) { |
|
7152 |
for (int j = 0; j < image.width(); ++j) |
|
7153 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
7154 |
} |
|
7155 |
||
7156 |
// Restore painter and refill image with red. |
|
7157 |
image.fill(QColor(Qt::red).rgb()); |
|
7158 |
painter.translate(-50, 0); |
|
7159 |
||
7160 |
// Set transform on the painter. |
|
7161 |
QTransform transform; |
|
7162 |
transform.shear(0, 1); |
|
7163 |
painter.setTransform(transform); |
|
7164 |
widget.render(&painter); |
|
7165 |
||
7166 |
#ifdef RENDER_DEBUG |
|
7167 |
image.save("blue_triangle.png"); |
|
7168 |
#endif |
|
7169 |
||
7170 |
// We should now have a blue triangle starting at scan line 1, and the rest should be red. |
|
7171 |
// rrrrrrrrrr |
|
7172 |
// brrrrrrrrr |
|
7173 |
// bbrrrrrrrr |
|
7174 |
// bbbrrrrrrr |
|
7175 |
// bbbbrrrrrr |
|
7176 |
// rrrrrrrrrr |
|
7177 |
// ... |
|
7178 |
||
7179 |
#ifndef Q_WS_MAC |
|
7180 |
for (int i = 0; i < image.height(); ++i) { |
|
7181 |
for (int j = 0; j < image.width(); ++j) { |
|
7182 |
if (i < 50 && j < i) |
|
7183 |
QCOMPARE(image.pixel(j, i), QColor(Qt::blue).rgb()); |
|
7184 |
else |
|
7185 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
7186 |
} |
|
7187 |
} |
|
7188 |
#else |
|
7189 |
// We don't paint directly on the image on the Mac, so we cannot do the pixel comparison |
|
7190 |
// as above due to QPainter::SmoothPixmapTransform. We therefore need to generate an |
|
7191 |
// expected image by first painting on a pixmap, and then draw the pixmap onto |
|
7192 |
// the image using QPainter::SmoothPixmapTransform. Then we can compare pixels :) |
|
7193 |
// The check is basically the same, except that it takes the smoothening into account. |
|
7194 |
QPixmap pixmap(50, 50); |
|
7195 |
const QRegion sysClip(0, 0, 50, 50); |
|
7196 |
widget.render(&pixmap, QPoint(), sysClip); |
|
7197 |
||
7198 |
QImage expectedImage(widget.size(), QImage::Format_RGB32); |
|
7199 |
expectedImage.fill(QColor(Qt::red).rgb()); |
|
7200 |
expectedImage.paintEngine()->setSystemClip(sysClip); |
|
7201 |
||
7202 |
QPainter expectedImagePainter(&expectedImage); |
|
7203 |
expectedImagePainter.setTransform(QTransform().shear(0, 1)); |
|
7204 |
// NB! This is the important part (SmoothPixmapTransform). |
|
7205 |
expectedImagePainter.setRenderHints(QPainter::SmoothPixmapTransform); |
|
7206 |
expectedImagePainter.drawPixmap(QPoint(0, 0), pixmap); |
|
7207 |
expectedImagePainter.end(); |
|
7208 |
||
7209 |
QCOMPARE(image, expectedImage); |
|
7210 |
#endif |
|
7211 |
} |
|
7212 |
||
7213 |
void tst_QWidget::render_systemClip2_data() |
|
7214 |
{ |
|
7215 |
QTest::addColumn<bool>("autoFillBackground"); |
|
7216 |
QTest::addColumn<bool>("usePaintEvent"); |
|
7217 |
QTest::addColumn<QColor>("expectedColor"); |
|
7218 |
||
7219 |
QTest::newRow("Only auto-fill background") << true << false << QColor(Qt::blue); |
|
7220 |
QTest::newRow("Only draw in paintEvent") << false << true << QColor(Qt::green); |
|
7221 |
QTest::newRow("Auto-fill background and draw in paintEvent") << true << true << QColor(Qt::green); |
|
7222 |
} |
|
7223 |
||
7224 |
void tst_QWidget::render_systemClip2() |
|
7225 |
{ |
|
7226 |
QFETCH(bool, autoFillBackground); |
|
7227 |
QFETCH(bool, usePaintEvent); |
|
7228 |
QFETCH(QColor, expectedColor); |
|
7229 |
||
7230 |
Q_ASSERT_X(expectedColor != QColor(Qt::red), Q_FUNC_INFO, |
|
7231 |
"Qt::red is the reference color for the image, pick another color"); |
|
7232 |
||
7233 |
class MyWidget : public QWidget |
|
7234 |
{ |
|
7235 |
public: |
|
7236 |
bool usePaintEvent; |
|
7237 |
void paintEvent(QPaintEvent *) |
|
7238 |
{ |
|
7239 |
if (usePaintEvent) |
|
7240 |
QPainter(this).fillRect(rect(), Qt::green); |
|
7241 |
} |
|
7242 |
}; |
|
7243 |
||
7244 |
MyWidget widget; |
|
7245 |
widget.usePaintEvent = usePaintEvent; |
|
7246 |
widget.setPalette(Qt::blue); |
|
7247 |
// NB! widget.setAutoFillBackground(autoFillBackground) won't do the |
|
7248 |
// trick here since the widget is a top-level. The background is filled |
|
7249 |
// regardless, unless Qt::WA_OpaquePaintEvent or Qt::WA_NoSystemBackground |
|
7250 |
// is set. We therefore use the opaque attribute to turn off auto-fill. |
|
7251 |
if (!autoFillBackground) |
|
7252 |
widget.setAttribute(Qt::WA_OpaquePaintEvent); |
|
7253 |
widget.resize(100, 100); |
|
7254 |
||
7255 |
QImage image(widget.size(), QImage::Format_RGB32); |
|
7256 |
image.fill(QColor(Qt::red).rgb()); |
|
7257 |
||
7258 |
QPaintEngine *paintEngine = image.paintEngine(); |
|
7259 |
QVERIFY(paintEngine); |
|
7260 |
||
7261 |
QRegion systemClip(QRegion(50, 0, 50, 10)); |
|
7262 |
systemClip += QRegion(90, 10, 10, 40); |
|
7263 |
paintEngine->setSystemClip(systemClip); |
|
7264 |
||
7265 |
// Render entire widget directly onto device. |
|
7266 |
widget.render(&image); |
|
7267 |
||
7268 |
#ifdef RENDER_DEBUG |
|
7269 |
image.save("systemclip_with_device.png"); |
|
7270 |
#endif |
|
7271 |
// All pixels within the system clip should now be |
|
7272 |
// the expectedColor, and the rest should be red. |
|
7273 |
for (int i = 0; i < image.height(); ++i) { |
|
7274 |
for (int j = 0; j < image.width(); ++j) { |
|
7275 |
if (systemClip.contains(QPoint(j, i))) |
|
7276 |
QCOMPARE(image.pixel(j, i), expectedColor.rgb()); |
|
7277 |
else |
|
7278 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
7279 |
} |
|
7280 |
} |
|
7281 |
||
7282 |
// Refill image with red. |
|
7283 |
image.fill(QColor(Qt::red).rgb()); |
|
7284 |
paintEngine->setSystemClip(systemClip); |
|
7285 |
||
7286 |
// Do the same with an untransformed painter. |
|
7287 |
QPainter painter(&image); |
|
7288 |
//Make sure we're using the same paint engine and has the right clip set. |
|
7289 |
QCOMPARE(painter.paintEngine(), paintEngine); |
|
7290 |
QCOMPARE(paintEngine->systemClip(), systemClip); |
|
7291 |
||
7292 |
widget.render(&painter); |
|
7293 |
||
7294 |
#ifdef RENDER_DEBUG |
|
7295 |
image.save("systemclip_with_untransformed_painter.png"); |
|
7296 |
#endif |
|
7297 |
// All pixels within the system clip should now be |
|
7298 |
// the expectedColor, and the rest should be red. |
|
7299 |
for (int i = 0; i < image.height(); ++i) { |
|
7300 |
for (int j = 0; j < image.width(); ++j) { |
|
7301 |
if (systemClip.contains(QPoint(j, i))) |
|
7302 |
QCOMPARE(image.pixel(j, i), expectedColor.rgb()); |
|
7303 |
else |
|
7304 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
7305 |
} |
|
7306 |
} |
|
7307 |
} |
|
7308 |
||
7309 |
void tst_QWidget::render_systemClip3_data() |
|
7310 |
{ |
|
7311 |
QTest::addColumn<QSize>("size"); |
|
7312 |
QTest::addColumn<bool>("useSystemClip"); |
|
7313 |
||
7314 |
// Reference: http://en.wikipedia.org/wiki/Flag_of_Norway |
|
7315 |
QTest::newRow("Norwegian Civil Flag") << QSize(220, 160) << false; |
|
7316 |
QTest::newRow("Norwegian War Flag") << QSize(270, 160) << true; |
|
7317 |
} |
|
7318 |
||
7319 |
// This test ensures that the current engine clip (systemClip + painter clip) |
|
7320 |
// is preserved after QPainter::setClipRegion(..., Qt::ReplaceClip); |
|
7321 |
void tst_QWidget::render_systemClip3() |
|
7322 |
{ |
|
7323 |
QFETCH(QSize, size); |
|
7324 |
QFETCH(bool, useSystemClip); |
|
7325 |
||
7326 |
// Calculate the inner/outer cross of the flag. |
|
7327 |
QRegion outerCross(0, 0, size.width(), size.height()); |
|
7328 |
outerCross -= QRect(0, 0, 60, 60); |
|
7329 |
outerCross -= QRect(100, 0, size.width() - 100, 60); |
|
7330 |
outerCross -= QRect(0, 100, 60, 60); |
|
7331 |
outerCross -= QRect(100, 100, size.width() - 100, 60); |
|
7332 |
||
7333 |
QRegion innerCross(0, 0, size.width(), size.height()); |
|
7334 |
innerCross -= QRect(0, 0, 70, 70); |
|
7335 |
innerCross -= QRect(90, 0, size.width() - 90, 70); |
|
7336 |
innerCross -= QRect(0, 90, 70, 70); |
|
7337 |
innerCross -= QRect(90, 90, size.width() - 90, 70); |
|
7338 |
||
7339 |
const QRegion redArea(QRegion(0, 0, size.width(), size.height()) - outerCross); |
|
7340 |
const QRegion whiteArea(outerCross - innerCross); |
|
7341 |
const QRegion blueArea(innerCross); |
|
7342 |
QRegion systemClip; |
|
7343 |
||
7344 |
// Okay, here's the image that should look like a Norwegian civil/war flag in the end. |
|
7345 |
QImage flag(size, QImage::Format_ARGB32); |
|
7346 |
flag.fill(QColor(Qt::transparent).rgba()); |
|
7347 |
||
7348 |
if (useSystemClip) { |
|
7349 |
QPainterPath warClip(QPoint(size.width(), 0)); |
|
7350 |
warClip.lineTo(size.width() - 110, 60); |
|
7351 |
warClip.lineTo(size.width(), 80); |
|
7352 |
warClip.lineTo(size.width() - 110, 100); |
|
7353 |
warClip.lineTo(size.width(), 160); |
|
7354 |
warClip.closeSubpath(); |
|
7355 |
systemClip = QRegion(0, 0, size.width(), size.height()) - QRegion(warClip.toFillPolygon().toPolygon()); |
|
7356 |
flag.paintEngine()->setSystemClip(systemClip); |
|
7357 |
} |
|
7358 |
||
7359 |
QPainter painter(&flag); |
|
7360 |
painter.fillRect(QRect(QPoint(), size), Qt::red); // Fill image background with red. |
|
7361 |
painter.setClipRegion(outerCross); // Limit widget painting to inside the outer cross. |
|
7362 |
||
7363 |
// Here's the widget that's supposed to draw the inner/outer cross of the flag. |
|
7364 |
// The outer cross (white) should be drawn when the background is auto-filled, and |
|
7365 |
// the inner cross (blue) should be drawn in the paintEvent. |
|
7366 |
class MyWidget : public QWidget |
|
7367 |
{ public: |
|
7368 |
void paintEvent(QPaintEvent *) |
|
7369 |
{ |
|
7370 |
QPainter painter(this); |
|
7371 |
// Be evil and try to paint outside the outer cross. This should not be |
|
7372 |
// possible since the shared painter is clipped to the outer cross. |
|
7373 |
painter.setClipRect(0, 0, 60, 60, Qt::ReplaceClip); |
|
7374 |
painter.fillRect(rect(), Qt::green); |
|
7375 |
painter.setClipRegion(clip, Qt::ReplaceClip); |
|
7376 |
painter.fillRect(rect(), Qt::blue); |
|
7377 |
} |
|
7378 |
QRegion clip; |
|
7379 |
}; |
|
7380 |
||
7381 |
MyWidget widget; |
|
7382 |
widget.clip = innerCross; |
|
7383 |
widget.setFixedSize(size); |
|
7384 |
widget.setPalette(Qt::white); |
|
7385 |
widget.setAutoFillBackground(true); |
|
7386 |
widget.render(&painter); |
|
7387 |
||
7388 |
#ifdef RENDER_DEBUG |
|
7389 |
flag.save("flag.png"); |
|
7390 |
#endif |
|
7391 |
||
7392 |
// Let's make sure we got a Norwegian flag. |
|
7393 |
for (int i = 0; i < flag.height(); ++i) { |
|
7394 |
for (int j = 0; j < flag.width(); ++j) { |
|
7395 |
const QPoint pixel(j, i); |
|
7396 |
const QRgb pixelValue = flag.pixel(pixel); |
|
7397 |
if (useSystemClip && !systemClip.contains(pixel)) |
|
7398 |
QCOMPARE(pixelValue, QColor(Qt::transparent).rgba()); |
|
7399 |
else if (redArea.contains(pixel)) |
|
7400 |
QCOMPARE(pixelValue, QColor(Qt::red).rgba()); |
|
7401 |
else if (whiteArea.contains(pixel)) |
|
7402 |
QCOMPARE(pixelValue, QColor(Qt::white).rgba()); |
|
7403 |
else |
|
7404 |
QCOMPARE(pixelValue, QColor(Qt::blue).rgba()); |
|
7405 |
} |
|
7406 |
} |
|
7407 |
} |
|
7408 |
||
7409 |
void tst_QWidget::render_task252837() |
|
7410 |
{ |
|
7411 |
QWidget widget; |
|
7412 |
widget.resize(200, 200); |
|
7413 |
||
7414 |
QPixmap pixmap(widget.size()); |
|
7415 |
QPainter painter(&pixmap); |
|
7416 |
// Please do not crash. |
|
7417 |
widget.render(&painter); |
|
7418 |
} |
|
7419 |
||
7420 |
void tst_QWidget::render_worldTransform() |
|
7421 |
{ |
|
7422 |
class MyWidget : public QWidget |
|
7423 |
{ public: |
|
7424 |
void paintEvent(QPaintEvent *) |
|
7425 |
{ |
|
7426 |
QPainter painter(this); |
|
7427 |
// Make sure world transform is identity. |
|
7428 |
QCOMPARE(painter.worldTransform(), QTransform()); |
|
7429 |
||
7430 |
// Make sure device transform is correct. |
|
7431 |
const QPoint widgetOffset = geometry().topLeft(); |
|
7432 |
QTransform expectedDeviceTransform = QTransform::fromTranslate(105, 5); |
|
7433 |
expectedDeviceTransform.rotate(90); |
|
7434 |
expectedDeviceTransform.translate(widgetOffset.x(), widgetOffset.y()); |
|
7435 |
QCOMPARE(painter.deviceTransform(), expectedDeviceTransform); |
|
7436 |
||
7437 |
// Set new world transform. |
|
7438 |
QTransform newWorldTransform = QTransform::fromTranslate(10, 10); |
|
7439 |
newWorldTransform.rotate(90); |
|
7440 |
painter.setWorldTransform(newWorldTransform); |
|
7441 |
QCOMPARE(painter.worldTransform(), newWorldTransform); |
|
7442 |
||
7443 |
// Again, check device transform. |
|
7444 |
expectedDeviceTransform.translate(10, 10); |
|
7445 |
expectedDeviceTransform.rotate(90); |
|
7446 |
QCOMPARE(painter.deviceTransform(), expectedDeviceTransform); |
|
7447 |
||
7448 |
painter.fillRect(QRect(0, 0, 20, 10), Qt::green); |
|
7449 |
} |
|
7450 |
}; |
|
7451 |
||
7452 |
MyWidget widget; |
|
7453 |
widget.setFixedSize(100, 100); |
|
7454 |
widget.setPalette(Qt::red); |
|
7455 |
widget.setAutoFillBackground(true); |
|
7456 |
||
7457 |
MyWidget child; |
|
7458 |
child.setParent(&widget); |
|
7459 |
child.move(50, 50); |
|
7460 |
child.setFixedSize(50, 50); |
|
7461 |
child.setPalette(Qt::blue); |
|
7462 |
child.setAutoFillBackground(true); |
|
7463 |
||
7464 |
QImage image(QSize(110, 110), QImage::Format_RGB32); |
|
7465 |
image.fill(QColor(Qt::black).rgb()); |
|
7466 |
||
7467 |
QPainter painter(&image); |
|
7468 |
painter.translate(105, 5); |
|
7469 |
painter.rotate(90); |
|
7470 |
||
7471 |
const QTransform worldTransform = painter.worldTransform(); |
|
7472 |
const QTransform deviceTransform = painter.deviceTransform(); |
|
7473 |
||
7474 |
// Render widgets onto image. |
|
7475 |
widget.render(&painter); |
|
7476 |
#ifdef RENDER_DEBUG |
|
7477 |
image.save("render_worldTransform_image.png"); |
|
7478 |
#endif |
|
7479 |
||
7480 |
// Ensure the transforms are unchanged after render. |
|
7481 |
QCOMPARE(painter.worldTransform(), painter.worldTransform()); |
|
7482 |
QCOMPARE(painter.deviceTransform(), painter.deviceTransform()); |
|
7483 |
painter.end(); |
|
7484 |
||
7485 |
// Paint expected image. |
|
7486 |
QImage expected(QSize(110, 110), QImage::Format_RGB32); |
|
7487 |
expected.fill(QColor(Qt::black).rgb()); |
|
7488 |
||
7489 |
QPainter expectedPainter(&expected); |
|
7490 |
expectedPainter.translate(105, 5); |
|
7491 |
expectedPainter.rotate(90); |
|
7492 |
expectedPainter.save(); |
|
7493 |
expectedPainter.fillRect(widget.rect(),Qt::red); |
|
7494 |
expectedPainter.translate(10, 10); |
|
7495 |
expectedPainter.rotate(90); |
|
7496 |
expectedPainter.fillRect(QRect(0, 0, 20, 10), Qt::green); |
|
7497 |
expectedPainter.restore(); |
|
7498 |
expectedPainter.translate(50, 50); |
|
7499 |
expectedPainter.fillRect(child.rect(),Qt::blue); |
|
7500 |
expectedPainter.translate(10, 10); |
|
7501 |
expectedPainter.rotate(90); |
|
7502 |
expectedPainter.fillRect(QRect(0, 0, 20, 10), Qt::green); |
|
7503 |
expectedPainter.end(); |
|
7504 |
||
7505 |
#ifdef RENDER_DEBUG |
|
7506 |
expected.save("render_worldTransform_expected.png"); |
|
7507 |
#endif |
|
7508 |
||
7509 |
QCOMPARE(image, expected); |
|
7510 |
} |
|
7511 |
||
7512 |
void tst_QWidget::setContentsMargins() |
|
7513 |
{ |
|
7514 |
QLabel label("why does it always rain on me?"); |
|
7515 |
QSize oldSize = label.sizeHint(); |
|
7516 |
label.setFrameStyle(QFrame::Sunken | QFrame::Box); |
|
7517 |
QSize newSize = label.sizeHint(); |
|
7518 |
QVERIFY(oldSize != newSize); |
|
7519 |
||
7520 |
QLabel label2("why does it always rain on me?"); |
|
7521 |
label2.show(); |
|
7522 |
label2.setFrameStyle(QFrame::Sunken | QFrame::Box); |
|
7523 |
QCOMPARE(newSize, label2.sizeHint()); |
|
7524 |
||
7525 |
QLabel label3("why does it always rain on me?"); |
|
7526 |
label3.setFrameStyle(QFrame::Sunken | QFrame::Box); |
|
7527 |
QCOMPARE(newSize, label3.sizeHint()); |
|
7528 |
} |
|
7529 |
||
7530 |
void tst_QWidget::moveWindowInShowEvent_data() |
|
7531 |
{ |
|
7532 |
QTest::addColumn<QPoint>("initial"); |
|
7533 |
QTest::addColumn<QPoint>("position"); |
|
7534 |
||
7535 |
QPoint p = QApplication::desktop()->availableGeometry().topLeft(); |
|
7536 |
||
7537 |
QTest::newRow("1") << p << (p + QPoint(10, 10)); |
|
7538 |
QTest::newRow("2") << (p + QPoint(10,10)) << p; |
|
7539 |
} |
|
7540 |
||
7541 |
void tst_QWidget::moveWindowInShowEvent() |
|
7542 |
{ |
|
7543 |
#ifdef Q_OS_IRIX |
|
7544 |
QSKIP("4DWM issues on IRIX makes this test fail", SkipAll); |
|
7545 |
#endif |
|
7546 |
QFETCH(QPoint, initial); |
|
7547 |
QFETCH(QPoint, position); |
|
7548 |
||
7549 |
class MoveWindowInShowEventWidget : public QWidget |
|
7550 |
{ |
|
7551 |
public: |
|
7552 |
QPoint position; |
|
7553 |
void showEvent(QShowEvent *) |
|
7554 |
{ |
|
7555 |
move(position); |
|
7556 |
} |
|
7557 |
}; |
|
7558 |
||
7559 |
MoveWindowInShowEventWidget widget; |
|
7560 |
widget.resize(QSize(qApp->desktop()->availableGeometry().size() / 3).expandedTo(QSize(1, 1))); |
|
7561 |
// move to this position in showEvent() |
|
7562 |
widget.position = position; |
|
7563 |
||
7564 |
// put the widget in it's starting position |
|
7565 |
widget.move(initial); |
|
7566 |
QCOMPARE(widget.pos(), initial); |
|
7567 |
||
7568 |
// show it |
|
7569 |
widget.show(); |
|
7570 |
#ifdef Q_WS_X11 |
|
7571 |
qt_x11_wait_for_window_manager(&widget); |
|
7572 |
#endif |
|
7573 |
QTest::qWait(100); |
|
7574 |
// it should have moved |
|
7575 |
QCOMPARE(widget.pos(), position); |
|
7576 |
} |
|
7577 |
||
7578 |
void tst_QWidget::repaintWhenChildDeleted() |
|
7579 |
{ |
|
7580 |
#ifdef Q_WS_WIN |
|
7581 |
if (QSysInfo::WindowsVersion & QSysInfo::WV_VISTA) { |
|
7582 |
QTest::qWait(1000); |
|
7583 |
} |
|
7584 |
#endif |
|
7585 |
ColorWidget w(0, Qt::red); |
|
7586 |
#if !defined(Q_OS_WINCE) && !defined(Q_WS_S60) |
|
7587 |
QPoint startPoint = QApplication::desktop()->availableGeometry(&w).topLeft(); |
|
7588 |
startPoint.rx() += 50; |
|
7589 |
startPoint.ry() += 50; |
|
7590 |
w.setGeometry(QRect(startPoint, QSize(100, 100))); |
|
7591 |
#else |
|
7592 |
w.setGeometry(60, 60, 110, 110); |
|
7593 |
#endif |
|
7594 |
w.show(); |
|
7595 |
QTest::qWaitForWindowShown(&w); |
|
7596 |
QTest::qWait(10); |
|
7597 |
QTRY_COMPARE(w.r, QRegion(w.rect())); |
|
7598 |
w.r = QRegion(); |
|
7599 |
||
7600 |
{ |
|
7601 |
const QPoint tlwOffset = w.geometry().topLeft(); |
|
7602 |
ColorWidget child(&w, Qt::blue); |
|
7603 |
child.setGeometry(10, 10, 10, 10); |
|
7604 |
child.show(); |
|
7605 |
QTest::qWait(10); |
|
7606 |
QTRY_COMPARE(child.r, QRegion(child.rect())); |
|
7607 |
w.r = QRegion(); |
|
7608 |
} |
|
7609 |
||
7610 |
QTest::qWait(10); |
|
7611 |
QTRY_COMPARE(w.r, QRegion(10, 10, 10, 10)); |
|
7612 |
} |
|
7613 |
||
7614 |
// task 175114 |
|
7615 |
void tst_QWidget::hideOpaqueChildWhileHidden() |
|
7616 |
{ |
|
7617 |
ColorWidget w(0, Qt::red); |
|
7618 |
#if !defined(Q_OS_WINCE) && !defined(Q_WS_S60) |
|
7619 |
QPoint startPoint = QApplication::desktop()->availableGeometry(&w).topLeft(); |
|
7620 |
startPoint.rx() += 50; |
|
7621 |
startPoint.ry() += 50; |
|
7622 |
w.setGeometry(QRect(startPoint, QSize(100, 100))); |
|
7623 |
#else |
|
7624 |
w.setGeometry(60, 60, 110, 110); |
|
7625 |
#endif |
|
7626 |
||
7627 |
ColorWidget child(&w, Qt::blue); |
|
7628 |
child.setGeometry(10, 10, 80, 80); |
|
7629 |
||
7630 |
ColorWidget child2(&child, Qt::white); |
|
7631 |
child2.setGeometry(10, 10, 60, 60); |
|
7632 |
||
7633 |
w.show(); |
|
7634 |
QTest::qWaitForWindowShown(&w); |
|
7635 |
QTest::qWait(10); |
|
7636 |
QTRY_COMPARE(child2.r, QRegion(child2.rect())); |
|
7637 |
child.r = QRegion(); |
|
7638 |
child2.r = QRegion(); |
|
7639 |
w.r = QRegion(); |
|
7640 |
||
7641 |
child.hide(); |
|
7642 |
child2.hide(); |
|
7643 |
QTest::qWait(100); |
|
7644 |
||
7645 |
QCOMPARE(w.r, QRegion(child.geometry())); |
|
7646 |
||
7647 |
child.show(); |
|
7648 |
QTest::qWait(100); |
|
7649 |
QCOMPARE(child.r, QRegion(child.rect())); |
|
7650 |
QCOMPARE(child2.r, QRegion()); |
|
7651 |
} |
|
7652 |
||
7653 |
void tst_QWidget::updateWhileMinimized() |
|
7654 |
{ |
|
7655 |
#if defined(Q_OS_WINCE) || defined(Q_WS_QWS) |
|
7656 |
QSKIP("This test doesn't make sense without support for showMinimized()", SkipAll); |
|
7657 |
#endif |
|
7658 |
||
7659 |
UpdateWidget widget; |
|
7660 |
// Filter out activation change and focus events to avoid update() calls in QWidget. |
|
7661 |
widget.updateOnActivationChangeAndFocusIn = false; |
|
7662 |
widget.reset(); |
|
7663 |
widget.show(); |
|
7664 |
QTest::qWaitForWindowShown(&widget); |
|
7665 |
QApplication::processEvents(); |
|
7666 |
QTRY_VERIFY(widget.numPaintEvents > 0); |
|
7667 |
QTest::qWait(150); |
|
7668 |
||
7669 |
// Minimize window. |
|
7670 |
widget.showMinimized(); |
|
7671 |
QTest::qWait(110); |
|
7672 |
||
7673 |
widget.reset(); |
|
7674 |
||
7675 |
// The widget is not visible on the screen (but isVisible() still returns true). |
|
7676 |
// Make sure update requests are discarded until the widget is shown again. |
|
7677 |
widget.update(0, 0, 50, 50); |
|
7678 |
QTest::qWait(10); |
|
7679 |
QCOMPARE(widget.numPaintEvents, 0); |
|
7680 |
||
7681 |
// Restore window. |
|
7682 |
widget.showNormal(); |
|
7683 |
QTest::qWait(30); |
|
7684 |
QTRY_COMPARE(widget.numPaintEvents, 1); |
|
7685 |
QCOMPARE(widget.paintedRegion, QRegion(0, 0, 50, 50)); |
|
7686 |
} |
|
7687 |
||
7688 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) |
|
7689 |
class PaintOnScreenWidget: public QWidget |
|
7690 |
{ |
|
7691 |
public: |
|
7692 |
PaintOnScreenWidget(QWidget *parent = 0, Qt::WindowFlags f = 0) |
|
7693 |
:QWidget(parent, f) |
|
7694 |
{ |
|
7695 |
} |
|
7696 |
#if defined(Q_WS_WIN) |
|
7697 |
// This is the only way to enable PaintOnScreen on Windows. |
|
7698 |
QPaintEngine * paintEngine () const {return 0;} |
|
7699 |
#endif |
|
7700 |
}; |
|
7701 |
||
7702 |
void tst_QWidget::alienWidgets() |
|
7703 |
{ |
|
7704 |
qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); |
|
7705 |
QWidget parent; |
|
7706 |
QWidget child(&parent); |
|
7707 |
QWidget grandChild(&child); |
|
7708 |
QWidget greatGrandChild(&grandChild); |
|
7709 |
parent.show(); |
|
7710 |
||
7711 |
#ifdef Q_WS_X11 |
|
7712 |
qt_x11_wait_for_window_manager(&parent); |
|
7713 |
#endif |
|
7714 |
||
7715 |
// Verify that the WA_WState_Created attribute is set |
|
7716 |
// and the top-level is the only native window. |
|
7717 |
QVERIFY(parent.testAttribute(Qt::WA_WState_Created)); |
|
7718 |
QVERIFY(parent.internalWinId()); |
|
7719 |
||
7720 |
QVERIFY(child.testAttribute(Qt::WA_WState_Created)); |
|
7721 |
QVERIFY(!child.internalWinId()); |
|
7722 |
||
7723 |
QVERIFY(grandChild.testAttribute(Qt::WA_WState_Created)); |
|
7724 |
QVERIFY(!grandChild.internalWinId()); |
|
7725 |
||
7726 |
QVERIFY(greatGrandChild.testAttribute(Qt::WA_WState_Created)); |
|
7727 |
QVERIFY(!greatGrandChild.internalWinId()); |
|
7728 |
||
7729 |
// Enforce native windows all the way up in the parent hierarchy |
|
7730 |
// if not WA_DontCreateNativeAncestors is set. |
|
7731 |
grandChild.setAttribute(Qt::WA_DontCreateNativeAncestors); |
|
7732 |
greatGrandChild.setAttribute(Qt::WA_NativeWindow); |
|
7733 |
QVERIFY(greatGrandChild.internalWinId()); |
|
7734 |
QVERIFY(grandChild.internalWinId()); |
|
7735 |
QVERIFY(!child.internalWinId()); |
|
7736 |
||
7737 |
{ |
|
7738 |
// Ensure that hide() on an ancestor of a widget with |
|
7739 |
// Qt::WA_DontCreateNativeAncestors still gets unmapped |
|
7740 |
QWidget window; |
|
7741 |
QWidget widget(&window); |
|
7742 |
QWidget child(&widget); |
|
7743 |
child.setAttribute(Qt::WA_NativeWindow); |
|
7744 |
child.setAttribute(Qt::WA_DontCreateNativeAncestors); |
|
7745 |
window.show(); |
|
7746 |
QVERIFY(child.testAttribute(Qt::WA_Mapped)); |
|
7747 |
widget.hide(); |
|
7748 |
QVERIFY(!child.testAttribute(Qt::WA_Mapped)); |
|
7749 |
} |
|
7750 |
||
7751 |
// Enforce a native window when calling QWidget::winId. |
|
7752 |
QVERIFY(child.winId()); |
|
7753 |
QVERIFY(child.internalWinId()); |
|
7754 |
||
7755 |
// Check that paint on screen widgets (incl. children) are native. |
|
7756 |
PaintOnScreenWidget paintOnScreen(&parent); |
|
7757 |
QWidget paintOnScreenChild(&paintOnScreen); |
|
7758 |
paintOnScreen.show(); |
|
7759 |
QVERIFY(paintOnScreen.testAttribute(Qt::WA_WState_Created)); |
|
7760 |
QVERIFY(!paintOnScreen.testAttribute(Qt::WA_NativeWindow)); |
|
7761 |
QVERIFY(!paintOnScreen.internalWinId()); |
|
7762 |
QVERIFY(!paintOnScreenChild.testAttribute(Qt::WA_NativeWindow)); |
|
7763 |
QVERIFY(!paintOnScreenChild.internalWinId()); |
|
7764 |
||
7765 |
paintOnScreen.setAttribute(Qt::WA_PaintOnScreen); |
|
7766 |
QVERIFY(paintOnScreen.testAttribute(Qt::WA_NativeWindow)); |
|
7767 |
QVERIFY(paintOnScreen.internalWinId()); |
|
7768 |
QVERIFY(paintOnScreenChild.testAttribute(Qt::WA_NativeWindow)); |
|
7769 |
QVERIFY(paintOnScreenChild.internalWinId()); |
|
7770 |
||
7771 |
// Check that widgets with the Qt::MSWindowsOwnDC attribute set |
|
7772 |
// are native. |
|
7773 |
QWidget msWindowsOwnDC(&parent, Qt::MSWindowsOwnDC); |
|
7774 |
msWindowsOwnDC.show(); |
|
7775 |
QVERIFY(msWindowsOwnDC.testAttribute(Qt::WA_WState_Created)); |
|
7776 |
QVERIFY(msWindowsOwnDC.testAttribute(Qt::WA_NativeWindow)); |
|
7777 |
QVERIFY(msWindowsOwnDC.internalWinId()); |
|
7778 |
||
7779 |
{ // Enforce a native window when calling QWidget::handle() (on X11) or QWidget::getDC() (on Windows). |
|
7780 |
QWidget widget(&parent); |
|
7781 |
widget.show(); |
|
7782 |
QVERIFY(widget.testAttribute(Qt::WA_WState_Created)); |
|
7783 |
QVERIFY(!widget.internalWinId()); |
|
7784 |
#ifdef Q_WS_X11 |
|
7785 |
widget.handle(); |
|
7786 |
#else |
|
7787 |
widget.getDC(); |
|
7788 |
#endif |
|
7789 |
QVERIFY(widget.internalWinId()); |
|
7790 |
} |
|
7791 |
||
7792 |
#ifdef Q_WS_X11 |
|
7793 |
#ifndef QT_NO_XRENDER |
|
7794 |
{ // Enforce a native window when calling QWidget::x11PictureHandle(). |
|
7795 |
QWidget widget(&parent); |
|
7796 |
widget.show(); |
|
7797 |
QVERIFY(widget.testAttribute(Qt::WA_WState_Created)); |
|
7798 |
QVERIFY(!widget.internalWinId()); |
|
7799 |
widget.x11PictureHandle(); |
|
7800 |
QVERIFY(widget.internalWinId()); |
|
7801 |
} |
|
7802 |
#endif |
|
7803 |
||
7804 |
{ // Make sure we don't create native windows when setting Qt::WA_X11NetWmWindowType attributes |
|
7805 |
// on alien widgets (see task 194231). |
|
7806 |
QWidget dummy; |
|
7807 |
QVERIFY(dummy.winId()); |
|
7808 |
QWidget widget(&dummy); |
|
7809 |
widget.setAttribute(Qt::WA_X11NetWmWindowTypeToolBar); |
|
7810 |
QVERIFY(!widget.internalWinId()); |
|
7811 |
} |
|
7812 |
#endif |
|
7813 |
||
7814 |
||
7815 |
{ // Make sure we create native ancestors when setting Qt::WA_PaintOnScreen before show(). |
|
7816 |
QWidget topLevel; |
|
7817 |
QWidget child(&topLevel); |
|
7818 |
QWidget grandChild(&child); |
|
7819 |
PaintOnScreenWidget greatGrandChild(&grandChild); |
|
7820 |
||
7821 |
greatGrandChild.setAttribute(Qt::WA_PaintOnScreen); |
|
7822 |
QVERIFY(!child.internalWinId()); |
|
7823 |
QVERIFY(!grandChild.internalWinId()); |
|
7824 |
QVERIFY(!greatGrandChild.internalWinId()); |
|
7825 |
||
7826 |
topLevel.show(); |
|
7827 |
QVERIFY(child.internalWinId()); |
|
7828 |
QVERIFY(grandChild.internalWinId()); |
|
7829 |
QVERIFY(greatGrandChild.internalWinId()); |
|
7830 |
} |
|
7831 |
||
7832 |
{ // Ensure that widgets reparented into Qt::WA_PaintOnScreen widgets become native. |
|
7833 |
QWidget topLevel; |
|
7834 |
QWidget *widget = new PaintOnScreenWidget(&topLevel); |
|
7835 |
widget->setAttribute(Qt::WA_PaintOnScreen); |
|
7836 |
QWidget *child = new QWidget; |
|
7837 |
QWidget *dummy = new QWidget(child); |
|
7838 |
QWidget *grandChild = new QWidget(child); |
|
7839 |
QWidget *dummy2 = new QWidget(grandChild); |
|
7840 |
||
7841 |
child->setParent(widget); |
|
7842 |
||
7843 |
QVERIFY(!topLevel.internalWinId()); |
|
7844 |
QVERIFY(!child->internalWinId()); |
|
7845 |
QVERIFY(!dummy->internalWinId()); |
|
7846 |
QVERIFY(!grandChild->internalWinId()); |
|
7847 |
QVERIFY(!dummy2->internalWinId()); |
|
7848 |
||
7849 |
topLevel.show(); |
|
7850 |
QVERIFY(topLevel.internalWinId()); |
|
7851 |
QVERIFY(widget->testAttribute(Qt::WA_NativeWindow)); |
|
7852 |
QVERIFY(child->internalWinId()); |
|
7853 |
QVERIFY(child->testAttribute(Qt::WA_NativeWindow)); |
|
7854 |
QVERIFY(!child->testAttribute(Qt::WA_PaintOnScreen)); |
|
7855 |
QVERIFY(!dummy->internalWinId()); |
|
7856 |
QVERIFY(!dummy->testAttribute(Qt::WA_NativeWindow)); |
|
7857 |
QVERIFY(!grandChild->internalWinId()); |
|
7858 |
QVERIFY(!grandChild->testAttribute(Qt::WA_NativeWindow)); |
|
7859 |
QVERIFY(!dummy2->internalWinId()); |
|
7860 |
QVERIFY(!dummy2->testAttribute(Qt::WA_NativeWindow)); |
|
7861 |
} |
|
7862 |
||
7863 |
{ // Ensure that ancestors of a Qt::WA_PaintOnScreen widget stay native |
|
7864 |
// if they are re-created (typically in QWidgetPrivate::setParent_sys) (task 210822). |
|
7865 |
QWidget window; |
|
7866 |
QWidget child(&window); |
|
7867 |
||
7868 |
QWidget grandChild; |
|
7869 |
grandChild.setWindowTitle("This causes the widget to be created"); |
|
7870 |
||
7871 |
PaintOnScreenWidget paintOnScreenWidget; |
|
7872 |
paintOnScreenWidget.setAttribute(Qt::WA_PaintOnScreen); |
|
7873 |
paintOnScreenWidget.setParent(&grandChild); |
|
7874 |
||
7875 |
grandChild.setParent(&child); |
|
7876 |
||
7877 |
window.show(); |
|
7878 |
||
7879 |
QVERIFY(window.internalWinId()); |
|
7880 |
QVERIFY(child.internalWinId()); |
|
7881 |
QVERIFY(child.testAttribute(Qt::WA_NativeWindow)); |
|
7882 |
QVERIFY(grandChild.internalWinId()); |
|
7883 |
QVERIFY(grandChild.testAttribute(Qt::WA_NativeWindow)); |
|
7884 |
QVERIFY(paintOnScreenWidget.internalWinId()); |
|
7885 |
QVERIFY(paintOnScreenWidget.testAttribute(Qt::WA_NativeWindow)); |
|
7886 |
} |
|
7887 |
||
7888 |
{ // Ensure that all siblings are native unless Qt::AA_DontCreateNativeWidgetSiblings is set. |
|
7889 |
qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, false); |
|
7890 |
QWidget mainWindow; |
|
7891 |
QWidget *toolBar = new QWidget(&mainWindow); |
|
7892 |
QWidget *dockWidget = new QWidget(&mainWindow); |
|
7893 |
QWidget *centralWidget = new QWidget(&mainWindow); |
|
7894 |
||
7895 |
QWidget *button = new QWidget(centralWidget); |
|
7896 |
QWidget *mdiArea = new QWidget(centralWidget); |
|
7897 |
||
7898 |
QWidget *horizontalScroll = new QWidget(mdiArea); |
|
7899 |
QWidget *verticalScroll = new QWidget(mdiArea); |
|
7900 |
QWidget *viewport = new QWidget(mdiArea); |
|
7901 |
||
7902 |
viewport->setAttribute(Qt::WA_NativeWindow); |
|
7903 |
mainWindow.show(); |
|
7904 |
||
7905 |
// Ensure that the viewport and its siblings are native: |
|
7906 |
QVERIFY(verticalScroll->testAttribute(Qt::WA_NativeWindow)); |
|
7907 |
QVERIFY(verticalScroll->testAttribute(Qt::WA_NativeWindow)); |
|
7908 |
QVERIFY(horizontalScroll->testAttribute(Qt::WA_NativeWindow)); |
|
7909 |
||
7910 |
// Ensure that the mdi area and its siblings are native: |
|
7911 |
QVERIFY(mdiArea->testAttribute(Qt::WA_NativeWindow)); |
|
7912 |
QVERIFY(button->testAttribute(Qt::WA_NativeWindow)); |
|
7913 |
||
7914 |
// Ensure that the central widget and its siblings are native: |
|
7915 |
QVERIFY(centralWidget->testAttribute(Qt::WA_NativeWindow)); |
|
7916 |
QVERIFY(dockWidget->testAttribute(Qt::WA_NativeWindow)); |
|
7917 |
QVERIFY(toolBar->testAttribute(Qt::WA_NativeWindow)); |
|
7918 |
} |
|
7919 |
} |
|
7920 |
#endif // Q_WS_WIN / Q_WS_X11 |
|
7921 |
||
7922 |
class ASWidget : public QWidget |
|
7923 |
{ |
|
7924 |
public: |
|
7925 |
ASWidget(QSize sizeHint, QSizePolicy sizePolicy, bool layout, bool hfwLayout, QWidget *parent = 0) |
|
7926 |
: QWidget(parent), mySizeHint(sizeHint) |
|
7927 |
{ |
|
7928 |
setSizePolicy(sizePolicy); |
|
7929 |
if (layout) { |
|
7930 |
QSizePolicy sp = QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
|
7931 |
sp.setHeightForWidth(hfwLayout); |
|
7932 |
||
7933 |
QVBoxLayout *vbox = new QVBoxLayout; |
|
7934 |
vbox->setMargin(0); |
|
7935 |
vbox->addWidget(new ASWidget(sizeHint + QSize(30, 20), sp, false, false)); |
|
7936 |
setLayout(vbox); |
|
7937 |
} |
|
7938 |
} |
|
7939 |
||
7940 |
QSize sizeHint() const { |
|
7941 |
if (layout()) |
|
7942 |
return layout()->totalSizeHint(); |
|
7943 |
return mySizeHint; |
|
7944 |
} |
|
7945 |
int heightForWidth(int width) const { |
|
7946 |
if (sizePolicy().hasHeightForWidth()) { |
|
7947 |
return width * 2; |
|
7948 |
} else { |
|
7949 |
return -1; |
|
7950 |
} |
|
7951 |
} |
|
7952 |
||
7953 |
QSize mySizeHint; |
|
7954 |
}; |
|
7955 |
||
7956 |
void tst_QWidget::adjustSize_data() |
|
7957 |
{ |
|
7958 |
const int MagicW = 200; |
|
7959 |
const int MagicH = 100; |
|
7960 |
||
7961 |
QTest::addColumn<QSize>("sizeHint"); |
|
7962 |
QTest::addColumn<int>("hPolicy"); |
|
7963 |
QTest::addColumn<int>("vPolicy"); |
|
7964 |
QTest::addColumn<bool>("hfwSP"); |
|
7965 |
QTest::addColumn<bool>("layout"); |
|
7966 |
QTest::addColumn<bool>("hfwLayout"); |
|
7967 |
QTest::addColumn<bool>("haveParent"); |
|
7968 |
QTest::addColumn<QSize>("expectedSize"); |
|
7969 |
||
7970 |
QTest::newRow("1") << QSize(5, 6) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7971 |
<< false << false << false << false << QSize(5, qMax(6, MagicH)); |
|
7972 |
QTest::newRow("2") << QSize(5, 6) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7973 |
<< true << false << false << false << QSize(5, qMax(10, MagicH)); |
|
7974 |
QTest::newRow("3") << QSize(5, 6) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7975 |
<< false << true << false << false << QSize(35, 26); |
|
7976 |
QTest::newRow("4") << QSize(5, 6) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7977 |
<< false << true << true << false << QSize(35, 70); |
|
7978 |
QTest::newRow("5") << QSize(40001, 30001) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7979 |
<< false << false << false << false << QSize(100000, 100000); |
|
7980 |
QTest::newRow("6") << QSize(40001, 30001) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7981 |
<< true << false << false << false << QSize(100000, 100000); |
|
7982 |
QTest::newRow("7") << QSize(40001, 30001) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7983 |
<< false << true << false << false << QSize(100000, 100000); |
|
7984 |
QTest::newRow("8") << QSize(40001, 30001) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7985 |
<< false << true << true << false << QSize(100000, 100000); |
|
7986 |
QTest::newRow("9") << QSize(5, 6) << int(QSizePolicy::Expanding) << int(QSizePolicy::Minimum) |
|
7987 |
<< true << false << false << false << QSize(qMax(5, MagicW), 10); |
|
7988 |
||
7989 |
QTest::newRow("1c") << QSize(5, 6) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7990 |
<< false << false << false << true << QSize(5, 6); |
|
7991 |
QTest::newRow("2c") << QSize(5, 6) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7992 |
<< true << false << false << true << QSize(5, 6 /* or 10 would be OK too, since hfw contradicts sizeHint() */); |
|
7993 |
QTest::newRow("3c") << QSize(5, 6) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7994 |
<< false << true << false << true << QSize(35, 26); |
|
7995 |
QTest::newRow("4c") << QSize(5, 6) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7996 |
<< false << true << true << true << QSize(35, 70); |
|
7997 |
QTest::newRow("5c") << QSize(40001, 30001) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7998 |
<< false << false << false << true << QSize(40001, 30001); |
|
7999 |
QTest::newRow("6c") << QSize(40001, 30001) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
8000 |
<< true << false << false << true << QSize(40001, 30001 /* or 80002 would be OK too, since hfw contradicts sizeHint() */); |
|
8001 |
QTest::newRow("7c") << QSize(40001, 30001) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
8002 |
<< false << true << false << true << QSize(40001 + 30, 30001 + 20); |
|
8003 |
QTest::newRow("8c") << QSize(40001, 30001) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
8004 |
<< false << true << true << true << QSize(40001 + 30, 80002 + 60); |
|
8005 |
QTest::newRow("9c") << QSize(5, 6) << int(QSizePolicy::Expanding) << int(QSizePolicy::Minimum) |
|
8006 |
<< true << false << false << true << QSize(5, 6); |
|
8007 |
} |
|
8008 |
||
8009 |
void tst_QWidget::adjustSize() |
|
8010 |
{ |
|
8011 |
QFETCH(QSize, sizeHint); |
|
8012 |
QFETCH(int, hPolicy); |
|
8013 |
QFETCH(int, vPolicy); |
|
8014 |
QFETCH(bool, hfwSP); |
|
8015 |
QFETCH(bool, layout); |
|
8016 |
QFETCH(bool, hfwLayout); |
|
8017 |
QFETCH(bool, haveParent); |
|
8018 |
QFETCH(QSize, expectedSize); |
|
8019 |
||
8020 |
QWidget *parent = new QWidget; |
|
8021 |
||
8022 |
QSizePolicy sp = QSizePolicy(QSizePolicy::Policy(hPolicy), QSizePolicy::Policy(vPolicy)); |
|
8023 |
sp.setHeightForWidth(hfwSP); |
|
8024 |
||
8025 |
QWidget *child = new ASWidget(sizeHint, sp, layout, hfwLayout, haveParent ? parent : 0); |
|
8026 |
child->resize(123, 456); |
|
8027 |
child->adjustSize(); |
|
8028 |
if (expectedSize == QSize(100000, 100000)) { |
|
8029 |
QVERIFY(child->size().width() < sizeHint.width()); |
|
8030 |
QVERIFY(child->size().height() < sizeHint.height()); |
|
8031 |
} else { |
|
8032 |
#if defined (Q_OS_WINCE) |
|
8033 |
if (!haveParent) { |
|
8034 |
const QRect& desktopRect = qApp->desktop()->availableGeometry(); |
|
8035 |
expectedSize.setWidth(qMin(expectedSize.width(), desktopRect.width())); |
|
8036 |
expectedSize.setHeight(qMin(expectedSize.height(), desktopRect.height())); |
|
8037 |
} |
|
8038 |
#endif |
|
8039 |
QCOMPARE(child->size(), expectedSize); |
|
8040 |
} |
|
8041 |
||
8042 |
delete parent; |
|
8043 |
} |
|
8044 |
||
8045 |
class TestLayout : public QVBoxLayout |
|
8046 |
{ |
|
8047 |
Q_OBJECT |
|
8048 |
public: |
|
8049 |
TestLayout(QWidget *w = 0) : QVBoxLayout(w) |
|
8050 |
{ |
|
8051 |
invalidated = false; |
|
8052 |
} |
|
8053 |
||
8054 |
void invalidate() |
|
8055 |
{ |
|
8056 |
invalidated = true; |
|
8057 |
} |
|
8058 |
||
8059 |
bool invalidated; |
|
8060 |
}; |
|
8061 |
||
8062 |
void tst_QWidget::updateGeometry_data() |
|
8063 |
{ |
|
8064 |
QTest::addColumn<QSize>("minSize"); |
|
8065 |
QTest::addColumn<bool>("shouldInvalidate"); |
|
8066 |
QTest::addColumn<QSize>("maxSize"); |
|
8067 |
QTest::addColumn<bool>("shouldInvalidate2"); |
|
8068 |
QTest::addColumn<int>("verticalSizePolicy"); |
|
8069 |
QTest::addColumn<bool>("shouldInvalidate3"); |
|
8070 |
QTest::addColumn<bool>("setVisible"); |
|
8071 |
QTest::addColumn<bool>("shouldInvalidate4"); |
|
8072 |
||
8073 |
QTest::newRow("setMinimumSize") |
|
8074 |
<< QSize(100, 100) << true |
|
8075 |
<< QSize() << false |
|
8076 |
<< int(QSizePolicy::Preferred) << false |
|
8077 |
<< true << false; |
|
8078 |
QTest::newRow("setMaximumSize") |
|
8079 |
<< QSize() << false |
|
8080 |
<< QSize(100, 100) << true |
|
8081 |
<< int(QSizePolicy::Preferred) << false |
|
8082 |
<< true << false; |
|
8083 |
QTest::newRow("setMinimumSize, then maximumSize to a different size") |
|
8084 |
<< QSize(100, 100) << true |
|
8085 |
<< QSize(300, 300) << true |
|
8086 |
<< int(QSizePolicy::Preferred) << false |
|
8087 |
<< true << false; |
|
8088 |
QTest::newRow("setMinimumSize, then maximumSize to the same size") |
|
8089 |
<< QSize(100, 100) << true |
|
8090 |
<< QSize(100, 100) << true |
|
8091 |
<< int(QSizePolicy::Preferred) << false |
|
8092 |
<< true << false; |
|
8093 |
QTest::newRow("setMinimumSize, then maximumSize to the same size and then hide it") |
|
8094 |
<< QSize(100, 100) << true |
|
8095 |
<< QSize(100, 100) << true |
|
8096 |
<< int(QSizePolicy::Preferred) << false |
|
8097 |
<< false << true; |
|
8098 |
QTest::newRow("Change sizePolicy") |
|
8099 |
<< QSize() << false |
|
8100 |
<< QSize() << false |
|
8101 |
<< int(QSizePolicy::Minimum) << true |
|
8102 |
<< true << false; |
|
8103 |
||
8104 |
} |
|
8105 |
||
8106 |
void tst_QWidget::updateGeometry() |
|
8107 |
{ |
|
8108 |
QFETCH(QSize, minSize); |
|
8109 |
QFETCH(bool, shouldInvalidate); |
|
8110 |
QFETCH(QSize, maxSize); |
|
8111 |
QFETCH(bool, shouldInvalidate2); |
|
8112 |
QFETCH(int, verticalSizePolicy); |
|
8113 |
QFETCH(bool, shouldInvalidate3); |
|
8114 |
QFETCH(bool, setVisible); |
|
8115 |
QFETCH(bool, shouldInvalidate4); |
|
8116 |
QWidget parent; |
|
8117 |
parent.resize(200, 200); |
|
8118 |
TestLayout *lout = new TestLayout(); |
|
8119 |
parent.setLayout(lout); |
|
8120 |
QWidget *child = new QWidget(&parent); |
|
8121 |
lout->addWidget(child); |
|
8122 |
parent.show(); |
|
8123 |
QApplication::processEvents(); |
|
8124 |
||
8125 |
lout->invalidated = false; |
|
8126 |
if (minSize.isValid()) |
|
8127 |
child->setMinimumSize(minSize); |
|
8128 |
QCOMPARE(lout->invalidated, shouldInvalidate); |
|
8129 |
||
8130 |
lout->invalidated = false; |
|
8131 |
if (maxSize.isValid()) |
|
8132 |
child->setMaximumSize(maxSize); |
|
8133 |
QCOMPARE(lout->invalidated, shouldInvalidate2); |
|
8134 |
||
8135 |
lout->invalidated = false; |
|
8136 |
child->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, (QSizePolicy::Policy)verticalSizePolicy)); |
|
8137 |
if (shouldInvalidate3) |
|
8138 |
QCOMPARE(lout->invalidated, true); |
|
8139 |
||
8140 |
lout->invalidated = false; |
|
8141 |
if (!setVisible) |
|
8142 |
child->setVisible(false); |
|
8143 |
QCOMPARE(lout->invalidated, shouldInvalidate4); |
|
8144 |
} |
|
8145 |
||
8146 |
void tst_QWidget::sendUpdateRequestImmediately() |
|
8147 |
{ |
|
8148 |
#ifdef Q_WS_MAC |
|
8149 |
if (!QApplicationPrivate::graphicsSystem()) |
|
8150 |
QSKIP("We only send update requests on the Mac when passing -graphicssystem", SkipAll); |
|
8151 |
#endif |
|
8152 |
||
8153 |
UpdateWidget updateWidget; |
|
8154 |
updateWidget.show(); |
|
8155 |
#ifdef Q_WS_X11 |
|
8156 |
qt_x11_wait_for_window_manager(&updateWidget); |
|
8157 |
#endif |
|
8158 |
||
8159 |
qApp->processEvents(); |
|
8160 |
#ifdef Q_WS_QWS |
|
8161 |
QApplication::sendPostedEvents(); //glib workaround |
|
8162 |
#endif |
|
8163 |
updateWidget.reset(); |
|
8164 |
||
8165 |
QCOMPARE(updateWidget.numUpdateRequestEvents, 0); |
|
8166 |
updateWidget.repaint(); |
|
8167 |
QCOMPARE(updateWidget.numUpdateRequestEvents, 1); |
|
8168 |
} |
|
8169 |
||
8170 |
class RedirectedWidget : public QWidget |
|
8171 |
{ |
|
8172 |
protected: |
|
8173 |
void paintEvent(QPaintEvent *) |
|
8174 |
{ |
|
8175 |
// Verify that the widget has a redirection set. The widget is redirected to |
|
8176 |
// the backing store on all platforms using it; otherwise to itself if the wrect |
|
8177 |
// does not start in (0, 0) or it has a mask set. |
|
8178 |
QPaintDevice *oldRedirection = QPainter::redirected(this); |
|
8179 |
#ifndef Q_WS_MAC |
|
8180 |
QVERIFY(oldRedirection); |
|
8181 |
#endif |
|
8182 |
||
8183 |
QImage image(size(), QImage::Format_RGB32); |
|
8184 |
image.fill(Qt::blue); |
|
8185 |
||
8186 |
{ |
|
8187 |
QPainter painter(this); |
|
8188 |
QCOMPARE(painter.device(), static_cast<QPaintDevice *>(this)); |
|
8189 |
} |
|
8190 |
||
8191 |
QPainter::setRedirected(this, &image); |
|
8192 |
QCOMPARE(QPainter::redirected(this), static_cast<QPaintDevice *>(&image)); |
|
8193 |
||
8194 |
QPainter painter(this); |
|
8195 |
painter.fillRect(rect(), Qt::red); |
|
8196 |
||
8197 |
QPainter::restoreRedirected(this); |
|
8198 |
QCOMPARE(QPainter::redirected(this), oldRedirection); |
|
8199 |
||
8200 |
for (int i = 0; i < image.height(); ++i) |
|
8201 |
for (int j = 0; j < image.width(); ++j) |
|
8202 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
8203 |
} |
|
8204 |
||
8205 |
}; |
|
8206 |
||
8207 |
// Test to make sure we're compatible in the particular case where QPainter::setRedirected |
|
8208 |
// actually works. It has been broken for all other cases since Qt 4.1.4 (backing store). |
|
8209 |
// QWidget::render is the modern and more powerful way of doing the same. |
|
8210 |
void tst_QWidget::painterRedirection() |
|
8211 |
{ |
|
8212 |
RedirectedWidget widget; |
|
8213 |
// Set FramelessWindowHint and mask to trigger internal painter redirection on the Mac. |
|
8214 |
widget.setWindowFlags(widget.windowFlags() | Qt::FramelessWindowHint); |
|
8215 |
widget.setMask(QRect(10, 10, 50, 50)); |
|
8216 |
widget.setFixedSize(100, 200); |
|
8217 |
widget.show(); |
|
8218 |
#ifdef Q_WS_X11 |
|
8219 |
qt_x11_wait_for_window_manager(&widget); |
|
8220 |
#endif |
|
8221 |
QPixmap pixmap(widget.size()); |
|
8222 |
QPainter::setRedirected(&widget, &pixmap, QPoint()); |
|
8223 |
widget.repaint(); |
|
8224 |
QCOMPARE(QPainter::redirected(&widget), static_cast<QPaintDevice *>(&pixmap)); |
|
8225 |
} |
|
8226 |
||
8227 |
||
8228 |
void tst_QWidget::doubleRepaint() |
|
8229 |
{ |
|
8230 |
#ifdef Q_OS_IRIX |
|
8231 |
QSKIP("4DWM issues on IRIX makes this test fail", SkipAll); |
|
8232 |
#elif defined(Q_WS_MAC) |
|
8233 |
if (!macHasAccessToWindowsServer()) |
|
8234 |
QSKIP("Not having window server access causes the wrong number of repaints to be issues", SkipAll); |
|
8235 |
#endif |
|
8236 |
UpdateWidget widget; |
|
8237 |
widget.setFocusPolicy(Qt::StrongFocus); |
|
8238 |
// Filter out activation change and focus events to avoid update() calls in QWidget. |
|
8239 |
widget.updateOnActivationChangeAndFocusIn = false; |
|
8240 |
||
8241 |
// Show: 1 repaint |
|
8242 |
int expectedRepaints = 1; |
|
8243 |
widget.show(); |
|
8244 |
QTest::qWaitForWindowShown(&widget); |
|
8245 |
QTest::qWait(10); |
|
8246 |
QTRY_COMPARE(widget.numPaintEvents, expectedRepaints); |
|
8247 |
widget.numPaintEvents = 0; |
|
8248 |
||
8249 |
// Minmize: Should not trigger a repaint. |
|
8250 |
widget.showMinimized(); |
|
8251 |
QTest::qWait(10); |
|
8252 |
QCOMPARE(widget.numPaintEvents, 0); |
|
8253 |
widget.numPaintEvents = 0; |
|
8254 |
||
8255 |
// Restore: Should not trigger a repaint. |
|
8256 |
widget.showNormal(); |
|
8257 |
QTest::qWaitForWindowShown(&widget); |
|
8258 |
QTest::qWait(10); |
|
8259 |
QCOMPARE(widget.numPaintEvents, 0); |
|
8260 |
} |
|
8261 |
||
8262 |
#ifndef Q_WS_MAC |
|
8263 |
// This test only makes sense on the Mac when passing -graphicssystem. |
|
8264 |
void tst_QWidget::resizeInPaintEvent() |
|
8265 |
{ |
|
8266 |
QWidget window; |
|
8267 |
UpdateWidget widget(&window); |
|
8268 |
window.show(); |
|
8269 |
QTest::qWaitForWindowShown(&window); |
|
8270 |
QTRY_VERIFY(widget.numPaintEvents > 0); |
|
8271 |
||
8272 |
widget.reset(); |
|
8273 |
QCOMPARE(widget.numPaintEvents, 0); |
|
8274 |
||
8275 |
widget.resizeInPaintEvent = true; |
|
8276 |
// This will call resize in the paintEvent, which in turn will call |
|
8277 |
// invalidateBuffer() and a new update request should be posted. |
|
8278 |
widget.repaint(); |
|
8279 |
QCOMPARE(widget.numPaintEvents, 1); |
|
8280 |
widget.numPaintEvents = 0; |
|
8281 |
||
8282 |
QTest::qWait(10); |
|
8283 |
// Make sure the resize triggers another update. |
|
8284 |
QTRY_COMPARE(widget.numPaintEvents, 1); |
|
8285 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8286 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8287 |
void tst_QWidget::opaqueChildren() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8288 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8289 |
QWidget widget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8290 |
widget.resize(200, 200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8291 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8292 |
QWidget child(&widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8293 |
child.setGeometry(-700, -700, 200, 200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8294 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8295 |
QWidget grandChild(&child); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8296 |
grandChild.resize(200, 200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8297 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8298 |
QWidget greatGrandChild(&grandChild); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8299 |
greatGrandChild.setGeometry(50, 50, 200, 200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8300 |
greatGrandChild.setPalette(Qt::red); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8301 |
greatGrandChild.setAutoFillBackground(true); // Opaque child widget. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8302 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8303 |
widget.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8304 |
#ifdef Q_WS_X11 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8305 |
qt_x11_wait_for_window_manager(&widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8306 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8307 |
QTest::qWait(100); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8308 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8309 |
// Child, grandChild and greatGrandChild are outside the ancestor clip. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8310 |
QRegion expectedOpaqueRegion(50, 50, 150, 150); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8311 |
QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), expectedOpaqueRegion); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8312 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8313 |
// Now they are all inside the ancestor clip. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8314 |
child.setGeometry(50, 50, 150, 150); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8315 |
QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), expectedOpaqueRegion); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8316 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8317 |
// Set mask on greatGrandChild. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8318 |
const QRegion mask(10, 10, 50, 50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8319 |
greatGrandChild.setMask(mask); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8320 |
expectedOpaqueRegion &= mask.translated(50, 50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8321 |
QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), expectedOpaqueRegion); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8322 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8323 |
// Make greatGrandChild "transparent". |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8324 |
greatGrandChild.setAutoFillBackground(false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8325 |
QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), QRegion()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8326 |
} |
0 | 8327 |
#endif |
8328 |
||
8329 |
||
8330 |
class MaskSetWidget : public QWidget |
|
8331 |
{ |
|
8332 |
Q_OBJECT |
|
8333 |
public: |
|
8334 |
MaskSetWidget(QWidget* p =0) |
|
8335 |
: QWidget(p) {} |
|
8336 |
||
8337 |
void paintEvent(QPaintEvent* event) { |
|
8338 |
QPainter p(this); |
|
8339 |
||
8340 |
paintedRegion += event->region(); |
|
8341 |
foreach(QRect r, event->region().rects()) |
|
8342 |
p.fillRect(r, Qt::red); |
|
8343 |
} |
|
8344 |
||
8345 |
void resizeEvent(QResizeEvent*) { |
|
8346 |
setMask(QRegion(QRect(0, 0, width(), 10).normalized())); |
|
8347 |
} |
|
8348 |
||
8349 |
QRegion paintedRegion; |
|
8350 |
||
8351 |
public slots: |
|
8352 |
void resizeDown() { |
|
8353 |
setGeometry(QRect(0, 50, 50, 50)); |
|
8354 |
} |
|
8355 |
||
8356 |
void resizeUp() { |
|
8357 |
setGeometry(QRect(0, 50, 150, 50)); |
|
8358 |
} |
|
8359 |
||
8360 |
}; |
|
8361 |
||
8362 |
void tst_QWidget::setMaskInResizeEvent() |
|
8363 |
{ |
|
8364 |
UpdateWidget w; |
|
8365 |
w.reset(); |
|
8366 |
w.resize(200, 200); |
|
8367 |
w.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); |
|
8368 |
w.raise(); |
|
8369 |
||
8370 |
MaskSetWidget testWidget(&w); |
|
8371 |
testWidget.setGeometry(0, 0, 100, 100); |
|
8372 |
testWidget.setMask(QRegion(QRect(0,0,100,10))); |
|
8373 |
testWidget.show(); |
|
8374 |
w.show(); |
|
8375 |
QTest::qWaitForWindowShown(&w); |
|
8376 |
QTest::qWait(30); |
|
8377 |
QTRY_VERIFY(w.numPaintEvents > 0); |
|
8378 |
||
8379 |
w.reset(); |
|
8380 |
testWidget.paintedRegion = QRegion(); |
|
8381 |
QTimer::singleShot(0, &testWidget, SLOT(resizeDown())); |
|
8382 |
QTest::qWait(100); |
|
8383 |
||
8384 |
QRegion expectedParentUpdate(0, 0, 100, 10); // Old testWidget area. |
|
8385 |
expectedParentUpdate += testWidget.geometry(); // New testWidget area. |
|
8386 |
QCOMPARE(w.paintedRegion, expectedParentUpdate); |
|
8387 |
QCOMPARE(testWidget.paintedRegion, testWidget.mask()); |
|
8388 |
||
8389 |
testWidget.paintedRegion = QRegion(); |
|
8390 |
// Now resize the widget again, but in the oposite direction |
|
8391 |
QTimer::singleShot(0, &testWidget, SLOT(resizeUp())); |
|
8392 |
QTest::qWait(100); |
|
8393 |
||
8394 |
QTRY_COMPARE(testWidget.paintedRegion, testWidget.mask()); |
|
8395 |
} |
|
8396 |
||
8397 |
class MoveInResizeWidget : public QWidget |
|
8398 |
{ |
|
8399 |
Q_OBJECT |
|
8400 |
public: |
|
8401 |
MoveInResizeWidget(QWidget* p = 0) |
|
8402 |
: QWidget(p) |
|
8403 |
{ |
|
8404 |
setWindowFlags(Qt::FramelessWindowHint); |
|
8405 |
} |
|
8406 |
||
8407 |
void resizeEvent(QResizeEvent*) { |
|
8408 |
||
8409 |
move(QPoint(100,100)); |
|
8410 |
||
8411 |
static bool firstTime = true; |
|
8412 |
if (firstTime) |
|
8413 |
QTimer::singleShot(250, this, SLOT(resizeMe())); |
|
8414 |
||
8415 |
firstTime = false; |
|
8416 |
} |
|
8417 |
||
8418 |
public slots: |
|
8419 |
void resizeMe() { |
|
8420 |
resize(100, 100); |
|
8421 |
} |
|
8422 |
}; |
|
8423 |
||
8424 |
void tst_QWidget::moveInResizeEvent() |
|
8425 |
{ |
|
8426 |
MoveInResizeWidget testWidget; |
|
8427 |
testWidget.setGeometry(50, 50, 200, 200); |
|
8428 |
testWidget.show(); |
|
8429 |
QTest::qWaitForWindowShown(&testWidget); |
|
8430 |
QTest::qWait(300); |
|
8431 |
||
8432 |
QRect expectedGeometry(100,100, 100, 100); |
|
8433 |
QTRY_COMPARE(testWidget.geometry(), expectedGeometry); |
|
8434 |
} |
|
8435 |
||
8436 |
||
8437 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) |
|
8438 |
void tst_QWidget::immediateRepaintAfterShow() |
|
8439 |
{ |
|
8440 |
UpdateWidget widget; |
|
8441 |
widget.show(); |
|
8442 |
qApp->processEvents(); |
|
8443 |
// On X11 in particular, we are now waiting for a MapNotify event before |
|
8444 |
// syncing the backing store. However, if someone request a repaint() |
|
8445 |
// we must repaint immediately regardless of the current state. |
|
8446 |
widget.numPaintEvents = 0; |
|
8447 |
widget.repaint(); |
|
8448 |
QCOMPARE(widget.numPaintEvents, 1); |
|
8449 |
} |
|
8450 |
||
8451 |
void tst_QWidget::immediateRepaintAfterInvalidateBuffer() |
|
8452 |
{ |
|
8453 |
QWidget *widget = new UpdateWidget; |
|
8454 |
widget->show(); |
|
8455 |
#ifdef Q_WS_X11 |
|
8456 |
qt_x11_wait_for_window_manager(widget); |
|
8457 |
#endif |
|
8458 |
QTest::qWait(200); |
|
8459 |
||
8460 |
static_cast<UpdateWidget *>(widget)->numPaintEvents = 0; |
|
8461 |
||
8462 |
// Marks the area covered by the widget as dirty in the backing store and |
|
8463 |
// posts an UpdateRequest event. |
|
8464 |
qt_widget_private(widget)->invalidateBuffer(widget->rect()); |
|
8465 |
QCOMPARE(static_cast<UpdateWidget *>(widget)->numPaintEvents, 0); |
|
8466 |
||
8467 |
// The entire widget is already dirty, but this time we want to update immediately |
|
8468 |
// by calling repaint(), and thus we have to repaint the widget and not wait for |
|
8469 |
// the UpdateRequest to be sent when we get back to the event loop. |
|
8470 |
widget->repaint(); |
|
8471 |
QCOMPARE(static_cast<UpdateWidget *>(widget)->numPaintEvents, 1); |
|
8472 |
||
8473 |
delete widget; |
|
8474 |
} |
|
8475 |
#endif |
|
8476 |
||
8477 |
void tst_QWidget::effectiveWinId() |
|
8478 |
{ |
|
8479 |
QWidget parent; |
|
8480 |
QWidget child(&parent); |
|
8481 |
||
8482 |
// Shouldn't crash. |
|
8483 |
QVERIFY(!parent.effectiveWinId()); |
|
8484 |
QVERIFY(!child.effectiveWinId()); |
|
8485 |
||
8486 |
parent.show(); |
|
8487 |
||
8488 |
QVERIFY(parent.effectiveWinId()); |
|
8489 |
QVERIFY(child.effectiveWinId()); |
|
8490 |
} |
|
8491 |
||
8492 |
class CustomWidget : public QWidget |
|
8493 |
{ |
|
8494 |
public: |
|
8495 |
mutable int metricCallCount; |
|
8496 |
||
8497 |
CustomWidget(QWidget *parent = 0) : QWidget(parent), metricCallCount(0) {} |
|
8498 |
||
8499 |
virtual int metric(PaintDeviceMetric metric) const { |
|
8500 |
++metricCallCount; |
|
8501 |
return QWidget::metric(metric); |
|
8502 |
} |
|
8503 |
}; |
|
8504 |
||
8505 |
void tst_QWidget::customDpi() |
|
8506 |
{ |
|
8507 |
QWidget *topLevel = new QWidget; |
|
8508 |
CustomWidget *custom = new CustomWidget(topLevel); |
|
8509 |
QWidget *child = new QWidget(custom); |
|
8510 |
||
8511 |
custom->metricCallCount = 0; |
|
8512 |
topLevel->logicalDpiX(); |
|
8513 |
QCOMPARE(custom->metricCallCount, 0); |
|
8514 |
custom->logicalDpiX(); |
|
8515 |
QCOMPARE(custom->metricCallCount, 1); |
|
8516 |
child->logicalDpiX(); |
|
8517 |
#ifdef Q_WS_S60 |
|
8518 |
// QWidget::metric is not recursive on Symbian |
|
8519 |
QCOMPARE(custom->metricCallCount, 1); |
|
8520 |
#else |
|
8521 |
QCOMPARE(custom->metricCallCount, 2); |
|
8522 |
#endif |
|
8523 |
||
8524 |
delete topLevel; |
|
8525 |
} |
|
8526 |
||
8527 |
void tst_QWidget::customDpiProperty() |
|
8528 |
{ |
|
8529 |
QWidget *topLevel = new QWidget; |
|
8530 |
QWidget *middle = new CustomWidget(topLevel); |
|
8531 |
QWidget *child = new QWidget(middle); |
|
8532 |
||
8533 |
const int initialDpiX = topLevel->logicalDpiX(); |
|
8534 |
const int initialDpiY = topLevel->logicalDpiY(); |
|
8535 |
||
8536 |
middle->setProperty("_q_customDpiX", 300); |
|
8537 |
middle->setProperty("_q_customDpiY", 400); |
|
8538 |
||
8539 |
QCOMPARE(topLevel->logicalDpiX(), initialDpiX); |
|
8540 |
QCOMPARE(topLevel->logicalDpiY(), initialDpiY); |
|
8541 |
||
8542 |
QCOMPARE(middle->logicalDpiX(), 300); |
|
8543 |
QCOMPARE(middle->logicalDpiY(), 400); |
|
8544 |
||
8545 |
QCOMPARE(child->logicalDpiX(), 300); |
|
8546 |
QCOMPARE(child->logicalDpiY(), 400); |
|
8547 |
||
8548 |
middle->setProperty("_q_customDpiX", QVariant()); |
|
8549 |
middle->setProperty("_q_customDpiY", QVariant()); |
|
8550 |
||
8551 |
QCOMPARE(topLevel->logicalDpiX(), initialDpiX); |
|
8552 |
QCOMPARE(topLevel->logicalDpiY(), initialDpiY); |
|
8553 |
||
8554 |
QCOMPARE(middle->logicalDpiX(), initialDpiX); |
|
8555 |
QCOMPARE(middle->logicalDpiY(), initialDpiY); |
|
8556 |
||
8557 |
QCOMPARE(child->logicalDpiX(), initialDpiX); |
|
8558 |
QCOMPARE(child->logicalDpiY(), initialDpiY); |
|
8559 |
||
8560 |
delete topLevel; |
|
8561 |
} |
|
8562 |
||
8563 |
void tst_QWidget::quitOnCloseAttribute() |
|
8564 |
{ |
|
8565 |
QWidget w; |
|
8566 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), true); |
|
8567 |
w.setAttribute(Qt::WA_QuitOnClose, false); |
|
8568 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), false); |
|
8569 |
||
8570 |
w.setAttribute(Qt::WA_QuitOnClose); |
|
8571 |
w.setWindowFlags(Qt::Tool); |
|
8572 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), false); |
|
8573 |
||
8574 |
w.setAttribute(Qt::WA_QuitOnClose); |
|
8575 |
w.setWindowFlags(Qt::Popup); |
|
8576 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), false); |
|
8577 |
||
8578 |
w.setAttribute(Qt::WA_QuitOnClose); |
|
8579 |
w.setWindowFlags(Qt::ToolTip); |
|
8580 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), false); |
|
8581 |
||
8582 |
w.setAttribute(Qt::WA_QuitOnClose); |
|
8583 |
w.setWindowFlags(Qt::SplashScreen); |
|
8584 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), false); |
|
8585 |
||
8586 |
w.setAttribute(Qt::WA_QuitOnClose); |
|
8587 |
w.setWindowFlags(Qt::SubWindow); |
|
8588 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), false); |
|
8589 |
||
8590 |
w.setAttribute(Qt::WA_QuitOnClose); |
|
8591 |
w.setWindowFlags(Qt::Dialog); |
|
8592 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), true); |
|
8593 |
w.show(); |
|
8594 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), true); |
|
8595 |
w.setWindowFlags(Qt::Tool); |
|
8596 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), false); |
|
8597 |
} |
|
8598 |
||
8599 |
void tst_QWidget::moveRect() |
|
8600 |
{ |
|
8601 |
QWidget widget; |
|
8602 |
widget.setUpdatesEnabled(false); |
|
8603 |
QWidget child(&widget); |
|
8604 |
child.setUpdatesEnabled(false); |
|
8605 |
child.setAttribute(Qt::WA_OpaquePaintEvent); |
|
8606 |
widget.show(); |
|
8607 |
QTest::qWait(200); |
|
8608 |
child.move(10, 10); // Don't crash. |
|
8609 |
} |
|
8610 |
||
8611 |
#ifdef Q_WS_WIN |
|
8612 |
class GDIWidget : public QDialog |
|
8613 |
{ |
|
8614 |
public: |
|
8615 |
GDIWidget() { setAttribute(Qt::WA_PaintOnScreen); } |
|
8616 |
QPaintEngine *paintEngine() const { return 0; } |
|
8617 |
||
8618 |
||
8619 |
void paintEvent(QPaintEvent *) { |
|
8620 |
HDC hdc = getDC(); |
|
8621 |
SelectObject(hdc, CreateSolidBrush(RGB(255, 0, 0))); |
|
8622 |
Rectangle(hdc, 0, 0, 10, 10); |
|
8623 |
||
8624 |
releaseDC(hdc); |
|
8625 |
||
8626 |
QImage im = QPixmap::grabWindow(winId(), 0, 0, width(), height()).toImage(); |
|
8627 |
color = im.pixel(1, 1); |
|
8628 |
||
8629 |
accept(); |
|
8630 |
} |
|
8631 |
||
8632 |
QSize sizeHint() const { |
|
8633 |
return QSize(400, 300); |
|
8634 |
} |
|
8635 |
||
8636 |
QColor color; |
|
8637 |
}; |
|
8638 |
||
8639 |
void tst_QWidget::gdiPainting() |
|
8640 |
{ |
|
8641 |
GDIWidget w; |
|
8642 |
w.exec(); |
|
8643 |
||
8644 |
QCOMPARE(w.color, QColor(255, 0, 0)); |
|
8645 |
||
8646 |
} |
|
8647 |
||
8648 |
void tst_QWidget::paintOnScreenPossible() |
|
8649 |
{ |
|
8650 |
QWidget w1; |
|
8651 |
w1.setAttribute(Qt::WA_PaintOnScreen); |
|
8652 |
QVERIFY(!w1.testAttribute(Qt::WA_PaintOnScreen)); |
|
8653 |
||
8654 |
GDIWidget w2; |
|
8655 |
w2.setAttribute(Qt::WA_PaintOnScreen); |
|
8656 |
QVERIFY(w2.testAttribute(Qt::WA_PaintOnScreen)); |
|
8657 |
} |
|
8658 |
#endif |
|
8659 |
||
8660 |
void tst_QWidget::reparentStaticWidget() |
|
8661 |
{ |
|
8662 |
QWidget window1; |
|
8663 |
||
8664 |
QWidget *child = new QWidget(&window1); |
|
8665 |
child->setPalette(Qt::red); |
|
8666 |
child->setAutoFillBackground(true); |
|
8667 |
child->setAttribute(Qt::WA_StaticContents); |
|
8668 |
child->resize(100, 100); |
|
8669 |
||
8670 |
QWidget *grandChild = new QWidget(child); |
|
8671 |
grandChild->setPalette(Qt::blue); |
|
8672 |
grandChild->setAutoFillBackground(true); |
|
8673 |
grandChild->resize(50, 50); |
|
8674 |
grandChild->setAttribute(Qt::WA_StaticContents); |
|
8675 |
window1.show(); |
|
8676 |
QTest::qWaitForWindowShown(&window1); |
|
8677 |
||
8678 |
QWidget window2; |
|
8679 |
window2.show(); |
|
8680 |
QTest::qWaitForWindowShown(&window2); |
|
8681 |
QTest::qWait(20); |
|
8682 |
||
8683 |
// Reparent into another top-level. |
|
8684 |
child->setParent(&window2); |
|
8685 |
child->show(); |
|
8686 |
||
8687 |
// Please don't crash. |
|
8688 |
window1.resize(window1.size() + QSize(2, 2)); |
|
8689 |
QTest::qWait(20); |
|
8690 |
||
8691 |
// Make sure we move all static children even though |
|
8692 |
// the reparented widget itself is non-static. |
|
8693 |
child->setAttribute(Qt::WA_StaticContents, false); |
|
8694 |
child->setParent(&window1); |
|
8695 |
child->show(); |
|
8696 |
||
8697 |
// Please don't crash. |
|
8698 |
window2.resize(window2.size() + QSize(2, 2)); |
|
8699 |
QTest::qWait(20); |
|
8700 |
||
8701 |
child->setParent(0); |
|
8702 |
child->show(); |
|
8703 |
QTest::qWait(20); |
|
8704 |
||
8705 |
// Please don't crash. |
|
8706 |
child->resize(child->size() + QSize(2, 2)); |
|
8707 |
window2.resize(window2.size() + QSize(2, 2)); |
|
8708 |
QTest::qWait(20); |
|
8709 |
||
8710 |
QWidget *siblingOfGrandChild = new QWidget(child); |
|
8711 |
siblingOfGrandChild->show(); |
|
8712 |
QTest::qWait(20); |
|
8713 |
||
8714 |
// Nothing should happen when reparenting within the same top-level. |
|
8715 |
grandChild->setParent(siblingOfGrandChild); |
|
8716 |
grandChild->show(); |
|
8717 |
QTest::qWait(20); |
|
8718 |
||
8719 |
QWidget paintOnScreen; |
|
8720 |
paintOnScreen.setAttribute(Qt::WA_PaintOnScreen); |
|
8721 |
paintOnScreen.show(); |
|
8722 |
QTest::qWaitForWindowShown(&paintOnScreen); |
|
8723 |
QTest::qWait(20); |
|
8724 |
||
8725 |
child->setParent(&paintOnScreen); |
|
8726 |
child->show(); |
|
8727 |
QTest::qWait(20); |
|
8728 |
||
8729 |
// Please don't crash. |
|
8730 |
paintOnScreen.resize(paintOnScreen.size() + QSize(2, 2)); |
|
8731 |
QTest::qWait(20); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8732 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8733 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8734 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8735 |
void tst_QWidget::QTBUG6883_reparentStaticWidget2() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8736 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8737 |
QMainWindow mw; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8738 |
QDockWidget *one = new QDockWidget("one", &mw); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8739 |
mw.addDockWidget(Qt::LeftDockWidgetArea, one , Qt::Vertical); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8740 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8741 |
QWidget *child = new QWidget(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8742 |
child->setPalette(Qt::red); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8743 |
child->setAutoFillBackground(true); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8744 |
child->setAttribute(Qt::WA_StaticContents); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8745 |
child->resize(100, 100); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8746 |
one->setWidget(child); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8747 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8748 |
QToolBar *mainTools = mw.addToolBar("Main Tools"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8749 |
mainTools->addWidget(new QLineEdit); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8750 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8751 |
mw.show(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8752 |
QTest::qWaitForWindowShown(&mw); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8753 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8754 |
one->setFloating(true); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8755 |
QTest::qWait(20); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8756 |
//do not crash |
0 | 8757 |
} |
8758 |
||
8759 |
#ifdef Q_WS_QWS |
|
8760 |
void tst_QWidget::updateOutsideSurfaceClip() |
|
8761 |
{ |
|
8762 |
UpdateWidget widget; |
|
8763 |
widget.setWindowFlags(Qt::FramelessWindowHint); |
|
8764 |
widget.resize(100, 100); |
|
8765 |
widget.raise(); |
|
8766 |
widget.show(); |
|
8767 |
QTest::qWait(200); |
|
8768 |
widget.reset(); |
|
8769 |
||
8770 |
// Move widget partially outside buffer and change the surface clip. |
|
8771 |
widget.move(-50, 0); |
|
8772 |
QTest::qWait(100); |
|
8773 |
||
8774 |
// Update region is outside the surface clip and should not trigger a repaint. |
|
8775 |
widget.update(0, 0, 20, 20); |
|
8776 |
QTest::qWait(100); |
|
8777 |
QCOMPARE(widget.numPaintEvents, 0); |
|
8778 |
||
8779 |
// Now, move the widget back so that the update region is inside the clip |
|
8780 |
// and make sure we get a repaint of the dirty area. |
|
8781 |
widget.move(0, 0); |
|
8782 |
QTest::qWait(100); |
|
8783 |
QCOMPARE(widget.numPaintEvents, 1); |
|
8784 |
QCOMPARE(widget.paintedRegion, QRegion(0, 0, 20, 20)); |
|
8785 |
} |
|
8786 |
#endif |
|
8787 |
class ColorRedWidget : public QWidget |
|
8788 |
{ |
|
8789 |
public: |
|
8790 |
ColorRedWidget(QWidget *parent = 0) |
|
8791 |
: QWidget(parent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::ToolTip) |
|
8792 |
{ |
|
8793 |
} |
|
8794 |
||
8795 |
void paintEvent(QPaintEvent *) { |
|
8796 |
QPainter p(this); |
|
8797 |
p.fillRect(rect(),Qt::red); |
|
8798 |
} |
|
8799 |
}; |
|
8800 |
||
8801 |
void tst_QWidget::translucentWidget() |
|
8802 |
{ |
|
8803 |
QPixmap pm(16,16); |
|
8804 |
pm.fill(Qt::red); |
|
8805 |
ColorRedWidget label; |
|
8806 |
label.setFixedSize(16,16); |
|
8807 |
label.setAttribute(Qt::WA_TranslucentBackground); |
|
8808 |
label.move(qApp->desktop()->availableGeometry().topLeft()); |
|
8809 |
label.show(); |
|
8810 |
#ifdef Q_WS_X11 |
|
8811 |
qt_x11_wait_for_window_manager(&label); |
|
8812 |
#endif |
|
8813 |
QTest::qWait(200); |
|
8814 |
||
8815 |
QPixmap widgetSnapshot = QPixmap::grabWindow(label.winId()); |
|
8816 |
QImage actual = widgetSnapshot.toImage().convertToFormat(QImage::Format_RGB32); |
|
8817 |
QImage expected = pm.toImage().convertToFormat(QImage::Format_RGB32); |
|
8818 |
QCOMPARE(actual.size(),expected.size()); |
|
8819 |
QCOMPARE(actual,expected); |
|
8820 |
} |
|
8821 |
||
8822 |
class MaskResizeTestWidget : public QWidget |
|
8823 |
{ |
|
8824 |
Q_OBJECT |
|
8825 |
public: |
|
8826 |
MaskResizeTestWidget(QWidget* p =0) |
|
8827 |
: QWidget(p) { |
|
8828 |
setMask(QRegion(QRect(0, 0, 100, 100).normalized())); |
|
8829 |
} |
|
8830 |
||
8831 |
void paintEvent(QPaintEvent* event) { |
|
8832 |
QPainter p(this); |
|
8833 |
||
8834 |
paintedRegion += event->region(); |
|
8835 |
foreach(QRect r, event->region().rects()) |
|
8836 |
p.fillRect(r, Qt::red); |
|
8837 |
} |
|
8838 |
||
8839 |
QRegion paintedRegion; |
|
8840 |
||
8841 |
public slots: |
|
8842 |
void enlargeMask() { |
|
8843 |
QRegion newMask(QRect(0, 0, 150, 150).normalized()); |
|
8844 |
setMask(newMask); |
|
8845 |
} |
|
8846 |
||
8847 |
void shrinkMask() { |
|
8848 |
QRegion newMask(QRect(0, 0, 50, 50).normalized()); |
|
8849 |
setMask(newMask); |
|
8850 |
} |
|
8851 |
||
8852 |
}; |
|
8853 |
||
8854 |
void tst_QWidget::setClearAndResizeMask() |
|
8855 |
{ |
|
8856 |
UpdateWidget topLevel; |
|
8857 |
topLevel.resize(150, 150); |
|
8858 |
topLevel.show(); |
|
8859 |
QTest::qWaitForWindowShown(&topLevel); |
|
8860 |
QTRY_VERIFY(topLevel.numPaintEvents > 0); |
|
8861 |
topLevel.reset(); |
|
8862 |
||
8863 |
// Mask top-level widget |
|
8864 |
const QRegion topLevelMask(0, 0, 100, 100, QRegion::Ellipse); |
|
8865 |
topLevel.setMask(topLevelMask); |
|
8866 |
QCOMPARE(topLevel.mask(), topLevelMask); |
|
8867 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) // We don't control what's happening on other platforms. |
|
8868 |
// and ensure that the top-level doesn't get any update. |
|
8869 |
QCOMPARE(topLevel.numPaintEvents, 0); |
|
8870 |
#endif |
|
8871 |
||
8872 |
topLevel.reset(); |
|
8873 |
||
8874 |
// Clear top-level mask |
|
8875 |
topLevel.clearMask(); |
|
8876 |
QCOMPARE(topLevel.mask(), QRegion()); |
|
8877 |
QTest::qWait(10); |
|
8878 |
QRegion outsideOldMask(topLevel.rect()); |
|
8879 |
outsideOldMask -= topLevelMask; |
|
8880 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) // We don't control what's happening on other platforms. |
|
8881 |
// and ensure that the top-level gets an update for the area outside the old mask. |
|
8882 |
QTRY_VERIFY(topLevel.numPaintEvents > 0); |
|
8883 |
QTRY_COMPARE(topLevel.paintedRegion, outsideOldMask); |
|
8884 |
#endif |
|
8885 |
||
8886 |
UpdateWidget child(&topLevel); |
|
8887 |
child.setAutoFillBackground(true); // NB! Opaque child. |
|
8888 |
child.resize(100, 100); |
|
8889 |
child.show(); |
|
8890 |
QTest::qWait(10); |
|
8891 |
||
8892 |
child.reset(); |
|
8893 |
topLevel.reset(); |
|
8894 |
||
8895 |
// Mask child widget with a mask that is smaller than the rect |
|
8896 |
const QRegion childMask(0, 0, 50, 50); |
|
8897 |
child.setMask(childMask); |
|
8898 |
QTRY_COMPARE(child.mask(), childMask); |
|
8899 |
QTest::qWait(50); |
|
8900 |
// and ensure that the child widget doesn't get any update. |
|
8901 |
#ifdef Q_WS_MAC |
|
8902 |
// Mac always issues a full update when calling setMask, and we cannot force it to not do so. |
|
8903 |
QCOMPARE(child.numPaintEvents, 1); |
|
8904 |
#else |
|
8905 |
QCOMPARE(child.numPaintEvents, 0); |
|
8906 |
#endif |
|
8907 |
// and the parent widget gets an update for the newly exposed area. |
|
8908 |
QTRY_COMPARE(topLevel.numPaintEvents, 1); |
|
8909 |
QRegion expectedParentExpose(child.rect()); |
|
8910 |
expectedParentExpose -= childMask; |
|
8911 |
QCOMPARE(topLevel.paintedRegion, expectedParentExpose); |
|
8912 |
||
8913 |
child.reset(); |
|
8914 |
topLevel.reset(); |
|
8915 |
||
8916 |
// Clear child widget mask |
|
8917 |
child.clearMask(); |
|
8918 |
QTRY_COMPARE(child.mask(), QRegion()); |
|
8919 |
QTest::qWait(10); |
|
8920 |
// and ensure that that the child widget gets an update for the area outside the old mask. |
|
8921 |
QTRY_COMPARE(child.numPaintEvents, 1); |
|
8922 |
outsideOldMask = child.rect(); |
|
8923 |
#ifndef Q_WS_MAC |
|
8924 |
// Mac always issues a full update when calling setMask, and we cannot force it to not do so. |
|
8925 |
outsideOldMask -= childMask; |
|
8926 |
#endif |
|
8927 |
QCOMPARE(child.paintedRegion, outsideOldMask); |
|
8928 |
// and the parent widget doesn't get any update. |
|
8929 |
QCOMPARE(topLevel.numPaintEvents, 0); |
|
8930 |
||
8931 |
child.reset(); |
|
8932 |
topLevel.reset(); |
|
8933 |
||
8934 |
// Mask child widget with a mask that is bigger than the rect |
|
8935 |
child.setMask(QRegion(0, 0, 1000, 1000)); |
|
8936 |
QTest::qWait(100); |
|
8937 |
#ifdef Q_WS_MAC |
|
8938 |
// Mac always issues a full update when calling setMask, and we cannot force it to not do so. |
|
8939 |
QTRY_COMPARE(child.numPaintEvents, 1); |
|
8940 |
#else |
|
8941 |
// and ensure that we don't get any updates at all. |
|
8942 |
QTRY_COMPARE(child.numPaintEvents, 0); |
|
8943 |
#endif |
|
8944 |
QCOMPARE(topLevel.numPaintEvents, 0); |
|
8945 |
||
8946 |
// ...and the same applies when clearing the mask. |
|
8947 |
child.clearMask(); |
|
8948 |
QTest::qWait(100); |
|
8949 |
#ifdef Q_WS_MAC |
|
8950 |
// Mac always issues a full update when calling setMask, and we cannot force it to not do so. |
|
8951 |
QTRY_VERIFY(child.numPaintEvents > 0); |
|
8952 |
#else |
|
8953 |
QCOMPARE(child.numPaintEvents, 0); |
|
8954 |
#endif |
|
8955 |
QCOMPARE(topLevel.numPaintEvents, 0); |
|
8956 |
||
8957 |
QWidget resizeParent; |
|
8958 |
MaskResizeTestWidget resizeChild(&resizeParent); |
|
8959 |
||
8960 |
resizeParent.resize(300,300); |
|
8961 |
resizeParent.raise(); |
|
8962 |
resizeParent.setWindowFlags(Qt::WindowStaysOnTopHint); |
|
8963 |
resizeChild.setGeometry(50,50,200,200); |
|
8964 |
QPalette pal = resizeParent.palette(); |
|
8965 |
pal.setColor(QPalette::Window, QColor(Qt::white)); |
|
8966 |
resizeParent.setPalette(pal); |
|
8967 |
||
8968 |
resizeParent.show(); |
|
8969 |
QTest::qWaitForWindowShown(&resizeParent); |
|
8970 |
// Disable the size grip on the Mac; otherwise it'll be included when grabbing the window. |
|
8971 |
resizeParent.setFixedSize(resizeParent.size()); |
|
8972 |
resizeChild.show(); |
|
8973 |
QTest::qWait(100); |
|
8974 |
resizeChild.paintedRegion = QRegion(); |
|
8975 |
||
8976 |
QTimer::singleShot(100, &resizeChild, SLOT(shrinkMask())); |
|
8977 |
QTest::qWait(200); |
|
8978 |
#ifdef Q_WS_MAC |
|
8979 |
// Mac always issues a full update when calling setMask, and we cannot force it to not do so. |
|
8980 |
QTRY_COMPARE(resizeChild.paintedRegion, resizeChild.mask()); |
|
8981 |
#else |
|
8982 |
QTRY_COMPARE(resizeChild.paintedRegion, QRegion()); |
|
8983 |
#endif |
|
8984 |
||
8985 |
resizeChild.paintedRegion = QRegion(); |
|
8986 |
const QRegion oldMask = resizeChild.mask(); |
|
8987 |
QTimer::singleShot(0, &resizeChild, SLOT(enlargeMask())); |
|
8988 |
QTest::qWait(100); |
|
8989 |
#ifdef Q_WS_MAC |
|
8990 |
// Mac always issues a full update when calling setMask, and we cannot force it to not do so. |
|
8991 |
QTRY_COMPARE(resizeChild.paintedRegion, resizeChild.mask()); |
|
8992 |
#else |
|
8993 |
QTRY_COMPARE(resizeChild.paintedRegion, resizeChild.mask() - oldMask); |
|
8994 |
#endif |
|
8995 |
} |
|
8996 |
||
8997 |
void tst_QWidget::maskedUpdate() |
|
8998 |
{ |
|
8999 |
UpdateWidget topLevel; |
|
9000 |
topLevel.resize(200, 200); |
|
9001 |
const QRegion topLevelMask(50, 50, 70, 70); |
|
9002 |
topLevel.setMask(topLevelMask); |
|
9003 |
||
9004 |
UpdateWidget child(&topLevel); |
|
9005 |
child.setGeometry(20, 20, 180, 180); |
|
9006 |
const QRegion childMask(60, 60, 30, 30); |
|
9007 |
child.setMask(childMask); |
|
9008 |
||
9009 |
UpdateWidget grandChild(&child); |
|
9010 |
grandChild.setGeometry(50, 50, 100, 100); |
|
9011 |
const QRegion grandChildMask(20, 20, 10, 10); |
|
9012 |
grandChild.setMask(grandChildMask); |
|
9013 |
||
9014 |
topLevel.show(); |
|
9015 |
QTest::qWaitForWindowShown(&topLevel); |
|
9016 |
QTRY_VERIFY(topLevel.numPaintEvents > 0); |
|
9017 |
||
9018 |
||
9019 |
#define RESET_WIDGETS \ |
|
9020 |
topLevel.reset(); \ |
|
9021 |
child.reset(); \ |
|
9022 |
grandChild.reset(); |
|
9023 |
||
9024 |
#define CLEAR_MASK(widget) \ |
|
9025 |
widget.clearMask(); \ |
|
9026 |
QTest::qWait(100); \ |
|
9027 |
RESET_WIDGETS; |
|
9028 |
||
9029 |
// All widgets are transparent at this point, so any call to update() will result |
|
9030 |
// in composition, i.e. the update propagates to ancestors and children. |
|
9031 |
||
9032 |
// TopLevel update. |
|
9033 |
RESET_WIDGETS; |
|
9034 |
topLevel.update(); |
|
9035 |
QTest::qWait(10); |
|
9036 |
||
9037 |
QTRY_COMPARE(topLevel.paintedRegion, topLevelMask); |
|
9038 |
QTRY_COMPARE(child.paintedRegion, childMask); |
|
9039 |
QTRY_COMPARE(grandChild.paintedRegion, grandChildMask); |
|
9040 |
||
9041 |
// Child update. |
|
9042 |
RESET_WIDGETS; |
|
9043 |
child.update(); |
|
9044 |
QTest::qWait(10); |
|
9045 |
||
9046 |
QTRY_COMPARE(topLevel.paintedRegion, childMask.translated(child.pos())); |
|
9047 |
QTRY_COMPARE(child.paintedRegion, childMask); |
|
9048 |
QTRY_COMPARE(grandChild.paintedRegion, grandChildMask); |
|
9049 |
||
9050 |
// GrandChild update. |
|
9051 |
RESET_WIDGETS; |
|
9052 |
grandChild.update(); |
|
9053 |
QTest::qWait(10); |
|
9054 |
||
9055 |
QTRY_COMPARE(topLevel.paintedRegion, grandChildMask.translated(grandChild.mapTo(&topLevel, QPoint()))); |
|
9056 |
QTRY_COMPARE(child.paintedRegion, grandChildMask.translated(grandChild.pos())); |
|
9057 |
QTRY_COMPARE(grandChild.paintedRegion, grandChildMask); |
|
9058 |
||
9059 |
topLevel.setAttribute(Qt::WA_OpaquePaintEvent); |
|
9060 |
child.setAttribute(Qt::WA_OpaquePaintEvent); |
|
9061 |
grandChild.setAttribute(Qt::WA_OpaquePaintEvent); |
|
9062 |
||
9063 |
// All widgets are now opaque, which means no composition, i.e. |
|
9064 |
// the update does not propate to ancestors and children. |
|
9065 |
||
9066 |
// TopLevel update. |
|
9067 |
RESET_WIDGETS; |
|
9068 |
topLevel.update(); |
|
9069 |
QTest::qWait(10); |
|
9070 |
||
9071 |
QRegion expectedTopLevelUpdate = topLevelMask; |
|
9072 |
expectedTopLevelUpdate -= childMask.translated(child.pos()); // Subtract opaque children. |
|
9073 |
QTRY_COMPARE(topLevel.paintedRegion, expectedTopLevelUpdate); |
|
9074 |
QTRY_COMPARE(child.paintedRegion, QRegion()); |
|
9075 |
QTRY_COMPARE(grandChild.paintedRegion, QRegion()); |
|
9076 |
||
9077 |
// Child update. |
|
9078 |
RESET_WIDGETS; |
|
9079 |
child.update(); |
|
9080 |
QTest::qWait(10); |
|
9081 |
||
9082 |
QTRY_COMPARE(topLevel.paintedRegion, QRegion()); |
|
9083 |
QRegion expectedChildUpdate = childMask; |
|
9084 |
expectedChildUpdate -= grandChildMask.translated(grandChild.pos()); // Subtract oapque children. |
|
9085 |
QTRY_COMPARE(child.paintedRegion, expectedChildUpdate); |
|
9086 |
QTRY_COMPARE(grandChild.paintedRegion, QRegion()); |
|
9087 |
||
9088 |
// GrandChild update. |
|
9089 |
RESET_WIDGETS; |
|
9090 |
grandChild.update(); |
|
9091 |
QTest::qWait(10); |
|
9092 |
||
9093 |
QTRY_COMPARE(topLevel.paintedRegion, QRegion()); |
|
9094 |
QTRY_COMPARE(child.paintedRegion, QRegion()); |
|
9095 |
QTRY_COMPARE(grandChild.paintedRegion, grandChildMask); |
|
9096 |
||
9097 |
// GrandChild update. |
|
9098 |
CLEAR_MASK(grandChild); |
|
9099 |
grandChild.update(); |
|
9100 |
QTest::qWait(10); |
|
9101 |
||
9102 |
QTRY_COMPARE(topLevel.paintedRegion, QRegion()); |
|
9103 |
QTRY_COMPARE(child.paintedRegion, QRegion()); |
|
9104 |
QRegion expectedGrandChildUpdate = grandChild.rect(); |
|
9105 |
// Clip with parent's mask. |
|
9106 |
expectedGrandChildUpdate &= childMask.translated(-grandChild.pos()); |
|
9107 |
QCOMPARE(grandChild.paintedRegion, expectedGrandChildUpdate); |
|
9108 |
||
9109 |
// GrandChild update. |
|
9110 |
CLEAR_MASK(child); |
|
9111 |
grandChild.update(); |
|
9112 |
QTest::qWait(10); |
|
9113 |
||
9114 |
QTRY_COMPARE(topLevel.paintedRegion, QRegion()); |
|
9115 |
QTRY_COMPARE(child.paintedRegion, QRegion()); |
|
9116 |
expectedGrandChildUpdate = grandChild.rect(); |
|
9117 |
// Clip with parent's mask. |
|
9118 |
expectedGrandChildUpdate &= topLevelMask.translated(-grandChild.mapTo(&topLevel, QPoint())); |
|
9119 |
QTRY_COMPARE(grandChild.paintedRegion, expectedGrandChildUpdate); |
|
9120 |
||
9121 |
// Child update. |
|
9122 |
RESET_WIDGETS; |
|
9123 |
child.update(); |
|
9124 |
QTest::qWait(10); |
|
9125 |
||
9126 |
QTRY_COMPARE(topLevel.paintedRegion, QRegion()); |
|
9127 |
expectedChildUpdate = child.rect(); |
|
9128 |
// Clip with parent's mask. |
|
9129 |
expectedChildUpdate &= topLevelMask.translated(-child.pos()); |
|
9130 |
expectedChildUpdate -= grandChild.geometry(); // Subtract opaque children. |
|
9131 |
QTRY_COMPARE(child.paintedRegion, expectedChildUpdate); |
|
9132 |
QTRY_COMPARE(grandChild.paintedRegion, QRegion()); |
|
9133 |
||
9134 |
// GrandChild update. |
|
9135 |
CLEAR_MASK(topLevel); |
|
9136 |
grandChild.update(); |
|
9137 |
QTest::qWait(10); |
|
9138 |
||
9139 |
QTRY_COMPARE(topLevel.paintedRegion, QRegion()); |
|
9140 |
QTRY_COMPARE(child.paintedRegion, QRegion()); |
|
9141 |
QTRY_COMPARE(grandChild.paintedRegion, QRegion(grandChild.rect())); // Full update. |
|
9142 |
} |
|
9143 |
||
9144 |
#if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_QWS) |
|
9145 |
void tst_QWidget::syntheticEnterLeave() |
|
9146 |
{ |
|
9147 |
class MyWidget : public QWidget |
|
9148 |
{ |
|
9149 |
public: |
|
9150 |
MyWidget(QWidget *parent = 0) : QWidget(parent), numEnterEvents(0), numLeaveEvents(0) {} |
|
9151 |
void enterEvent(QEvent *) { ++numEnterEvents; } |
|
9152 |
void leaveEvent(QEvent *) { ++numLeaveEvents; } |
|
9153 |
int numEnterEvents; |
|
9154 |
int numLeaveEvents; |
|
9155 |
}; |
|
9156 |
||
9157 |
QCursor::setPos(QPoint(0,0)); |
|
9158 |
||
9159 |
MyWidget window; |
|
9160 |
window.setWindowFlags(Qt::WindowStaysOnTopHint); |
|
9161 |
window.resize(200, 200); |
|
9162 |
||
9163 |
MyWidget *child1 = new MyWidget(&window); |
|
9164 |
child1->setPalette(Qt::blue); |
|
9165 |
child1->setAutoFillBackground(true); |
|
9166 |
child1->resize(200, 200); |
|
9167 |
child1->setCursor(Qt::OpenHandCursor); |
|
9168 |
||
9169 |
MyWidget *child2 = new MyWidget(&window); |
|
9170 |
child2->resize(200, 200); |
|
9171 |
||
9172 |
MyWidget *grandChild = new MyWidget(child2); |
|
9173 |
grandChild->setPalette(Qt::red); |
|
9174 |
grandChild->setAutoFillBackground(true); |
|
9175 |
grandChild->resize(200, 200); |
|
9176 |
grandChild->setCursor(Qt::WaitCursor); |
|
9177 |
||
9178 |
window.show(); |
|
9179 |
window.raise(); |
|
9180 |
#ifdef Q_WS_X11 |
|
9181 |
qt_x11_wait_for_window_manager(&window); |
|
9182 |
#endif |
|
9183 |
QTest::qWait(300); |
|
9184 |
||
9185 |
#define RESET_EVENT_COUNTS \ |
|
9186 |
window.numEnterEvents = 0; \ |
|
9187 |
window.numLeaveEvents = 0; \ |
|
9188 |
child1->numEnterEvents = 0; \ |
|
9189 |
child1->numLeaveEvents = 0; \ |
|
9190 |
child2->numEnterEvents = 0; \ |
|
9191 |
child2->numLeaveEvents = 0; \ |
|
9192 |
grandChild->numEnterEvents = 0; \ |
|
9193 |
grandChild->numLeaveEvents = 0; |
|
9194 |
||
9195 |
// Position the cursor in the middle of the window. |
|
9196 |
const QPoint globalPos = window.mapToGlobal(QPoint(100, 100)); |
|
9197 |
QCursor::setPos(globalPos); // Enter child2 and grandChild. |
|
9198 |
QTest::qWait(300); |
|
9199 |
||
9200 |
#ifdef Q_OS_WINCE_WM |
|
9201 |
QSKIP("Windows Mobile has no proper cursor support", SkipAll); |
|
9202 |
#endif |
|
9203 |
||
9204 |
QCOMPARE(window.numLeaveEvents, 0); |
|
9205 |
QCOMPARE(child2->numLeaveEvents, 0); |
|
9206 |
QCOMPARE(grandChild->numLeaveEvents, 0); |
|
9207 |
QCOMPARE(child1->numLeaveEvents, 0); |
|
9208 |
||
9209 |
QCOMPARE(window.numEnterEvents, 1); |
|
9210 |
QCOMPARE(child2->numEnterEvents, 1); |
|
9211 |
QCOMPARE(grandChild->numEnterEvents, 1); |
|
9212 |
QCOMPARE(child1->numEnterEvents, 0); |
|
9213 |
||
9214 |
RESET_EVENT_COUNTS; |
|
9215 |
child2->hide(); // Leave child2 and grandChild, enter child1. |
|
9216 |
||
9217 |
QCOMPARE(window.numLeaveEvents, 0); |
|
9218 |
QCOMPARE(child2->numLeaveEvents, 1); |
|
9219 |
QCOMPARE(grandChild->numLeaveEvents, 1); |
|
9220 |
QCOMPARE(child1->numLeaveEvents, 0); |
|
9221 |
||
9222 |
QCOMPARE(window.numEnterEvents, 0); |
|
9223 |
QCOMPARE(child2->numEnterEvents, 0); |
|
9224 |
QCOMPARE(grandChild->numEnterEvents, 0); |
|
9225 |
QCOMPARE(child1->numEnterEvents, 1); |
|
9226 |
||
9227 |
RESET_EVENT_COUNTS; |
|
9228 |
child2->show(); // Leave child1, enter child2 and grandChild. |
|
9229 |
||
9230 |
QCOMPARE(window.numLeaveEvents, 0); |
|
9231 |
QCOMPARE(child2->numLeaveEvents, 0); |
|
9232 |
QCOMPARE(grandChild->numLeaveEvents, 0); |
|
9233 |
QCOMPARE(child1->numLeaveEvents, 1); |
|
9234 |
||
9235 |
QCOMPARE(window.numEnterEvents, 0); |
|
9236 |
QCOMPARE(child2->numEnterEvents, 1); |
|
9237 |
QCOMPARE(grandChild->numEnterEvents, 1); |
|
9238 |
QCOMPARE(child1->numEnterEvents, 0); |
|
9239 |
||
9240 |
RESET_EVENT_COUNTS; |
|
9241 |
delete child2; // Enter child1 (and do not send leave events to child2 and grandChild). |
|
9242 |
||
9243 |
QCOMPARE(window.numLeaveEvents, 0); |
|
9244 |
QCOMPARE(child1->numLeaveEvents, 0); |
|
9245 |
||
9246 |
QCOMPARE(window.numEnterEvents, 0); |
|
9247 |
QCOMPARE(child1->numEnterEvents, 1); |
|
9248 |
} |
|
9249 |
||
9250 |
void tst_QWidget::taskQTBUG_4055_sendSyntheticEnterLeave() |
|
9251 |
{ |
|
9252 |
#ifdef Q_OS_WINCE_WM |
|
9253 |
QSKIP("Windows Mobile has no proper cursor support", SkipAll); |
|
9254 |
#endif |
|
9255 |
class SELParent : public QWidget |
|
9256 |
{ |
|
9257 |
public: |
|
9258 |
SELParent(QWidget *parent = 0): QWidget(parent) { } |
|
9259 |
||
9260 |
void mousePressEvent(QMouseEvent *) { child->show(); } |
|
9261 |
QWidget *child; |
|
9262 |
}; |
|
9263 |
||
9264 |
class SELChild : public QWidget |
|
9265 |
{ |
|
9266 |
public: |
|
9267 |
SELChild(QWidget *parent = 0) : QWidget(parent), numEnterEvents(0), numMouseMoveEvents(0) {} |
|
9268 |
void enterEvent(QEvent *) { ++numEnterEvents; } |
|
9269 |
void mouseMoveEvent(QMouseEvent *event) |
|
9270 |
{ |
|
9271 |
QCOMPARE(event->button(), Qt::NoButton); |
|
9272 |
QCOMPARE(event->buttons(), Qt::MouseButtons(Qt::NoButton)); |
|
9273 |
++numMouseMoveEvents; |
|
9274 |
} |
|
9275 |
void reset() { numEnterEvents = numMouseMoveEvents = 0; } |
|
9276 |
int numEnterEvents, numMouseMoveEvents; |
|
9277 |
}; |
|
9278 |
||
9279 |
QCursor::setPos(QPoint(0,0)); |
|
9280 |
||
9281 |
SELParent parent; |
|
9282 |
parent.resize(200, 200); |
|
9283 |
SELChild child(&parent); |
|
9284 |
child.resize(200, 200); |
|
9285 |
parent.show(); |
|
9286 |
#ifdef Q_WS_X11 |
|
9287 |
qt_x11_wait_for_window_manager(&parent); |
|
9288 |
#endif |
|
9289 |
QTest::qWait(150); |
|
9290 |
||
9291 |
QCursor::setPos(child.mapToGlobal(QPoint(100, 100))); |
|
9292 |
// Make sure the cursor has entered the child. |
|
9293 |
QTRY_VERIFY(child.numEnterEvents > 0); |
|
9294 |
||
9295 |
child.hide(); |
|
9296 |
child.reset(); |
|
9297 |
child.show(); |
|
9298 |
||
9299 |
// Make sure the child gets enter event and no mouse move event. |
|
9300 |
QCOMPARE(child.numEnterEvents, 1); |
|
9301 |
QCOMPARE(child.numMouseMoveEvents, 0); |
|
9302 |
||
9303 |
child.hide(); |
|
9304 |
child.reset(); |
|
9305 |
child.setMouseTracking(true); |
|
9306 |
child.show(); |
|
9307 |
||
9308 |
// Make sure the child gets enter event and mouse move event. |
|
9309 |
// Note that we verify event->button() and event->buttons() |
|
9310 |
// in SELChild::mouseMoveEvent(). |
|
9311 |
QCOMPARE(child.numEnterEvents, 1); |
|
9312 |
QCOMPARE(child.numMouseMoveEvents, 1); |
|
9313 |
||
9314 |
// Sending synthetic enter/leave trough the parent's mousePressEvent handler. |
|
9315 |
parent.child = &child; |
|
9316 |
||
9317 |
child.hide(); |
|
9318 |
child.reset(); |
|
9319 |
QTest::mouseClick(&parent, Qt::LeftButton); |
|
9320 |
||
9321 |
// Make sure the child gets enter event and one mouse move event. |
|
9322 |
QCOMPARE(child.numEnterEvents, 1); |
|
9323 |
QCOMPARE(child.numMouseMoveEvents, 1); |
|
9324 |
||
9325 |
child.hide(); |
|
9326 |
child.reset(); |
|
9327 |
child.setMouseTracking(false); |
|
9328 |
QTest::mouseClick(&parent, Qt::LeftButton); |
|
9329 |
||
9330 |
// Make sure the child gets enter event and no mouse move event. |
|
9331 |
QCOMPARE(child.numEnterEvents, 1); |
|
9332 |
QCOMPARE(child.numMouseMoveEvents, 0); |
|
9333 |
} |
|
9334 |
#endif |
|
9335 |
||
9336 |
void tst_QWidget::windowFlags() |
|
9337 |
{ |
|
9338 |
QWidget w; |
|
9339 |
w.setWindowFlags(w.windowFlags() | Qt::FramelessWindowHint); |
|
9340 |
QVERIFY(w.windowFlags() & Qt::FramelessWindowHint); |
|
9341 |
} |
|
9342 |
||
9343 |
void tst_QWidget::initialPosForDontShowOnScreenWidgets() |
|
9344 |
{ |
|
9345 |
{ // Check default position. |
|
9346 |
const QPoint expectedPos(0, 0); |
|
9347 |
QWidget widget; |
|
9348 |
widget.setAttribute(Qt::WA_DontShowOnScreen); |
|
9349 |
widget.winId(); // Make sure create_sys is called. |
|
9350 |
QCOMPARE(widget.pos(), expectedPos); |
|
9351 |
QCOMPARE(widget.geometry().topLeft(), expectedPos); |
|
9352 |
} |
|
9353 |
||
9354 |
{ // Explicitly move to a position. |
|
9355 |
const QPoint expectedPos(100, 100); |
|
9356 |
QWidget widget; |
|
9357 |
widget.setAttribute(Qt::WA_DontShowOnScreen); |
|
9358 |
widget.move(expectedPos); |
|
9359 |
widget.winId(); // Make sure create_sys is called. |
|
9360 |
QCOMPARE(widget.pos(), expectedPos); |
|
9361 |
QCOMPARE(widget.geometry().topLeft(), expectedPos); |
|
9362 |
} |
|
9363 |
} |
|
9364 |
||
9365 |
#ifdef Q_WS_X11 |
|
9366 |
void tst_QWidget::paintOutsidePaintEvent() |
|
9367 |
{ |
|
9368 |
QWidget widget; |
|
9369 |
widget.resize(200, 200); |
|
9370 |
||
9371 |
QWidget child1(&widget); |
|
9372 |
child1.resize(100, 100); |
|
9373 |
child1.setPalette(Qt::red); |
|
9374 |
child1.setAutoFillBackground(true); |
|
9375 |
||
9376 |
QWidget child2(&widget); |
|
9377 |
child2.setGeometry(50, 50, 100, 100); |
|
9378 |
child2.setPalette(Qt::blue); |
|
9379 |
child2.setAutoFillBackground(true); |
|
9380 |
||
9381 |
widget.show(); |
|
9382 |
QTest::qWaitForWindowShown(&widget); |
|
9383 |
QTest::qWait(60); |
|
9384 |
||
9385 |
const QPixmap before = QPixmap::grabWindow(widget.winId()); |
|
9386 |
||
9387 |
// Child 1 should be clipped by child 2, so nothing should change. |
|
9388 |
child1.setAttribute(Qt::WA_PaintOutsidePaintEvent); |
|
9389 |
QPainter painter(&child1); |
|
9390 |
painter.fillRect(child1.rect(), Qt::red); |
|
9391 |
painter.end(); |
|
9392 |
XSync(QX11Info::display(), false); // Flush output buffer. |
|
9393 |
QTest::qWait(60); |
|
9394 |
||
9395 |
const QPixmap after = QPixmap::grabWindow(widget.winId()); |
|
9396 |
||
9397 |
QCOMPARE(before, after); |
|
9398 |
} |
|
9399 |
#endif |
|
9400 |
||
9401 |
class MyEvilObject : public QObject |
|
9402 |
{ |
|
9403 |
Q_OBJECT |
|
9404 |
public: |
|
9405 |
MyEvilObject(QWidget *widgetToCrash) : QObject(), widget(widgetToCrash) |
|
9406 |
{ |
|
9407 |
connect(widget, SIGNAL(destroyed(QObject *)), this, SLOT(beEvil(QObject *))); |
|
9408 |
delete widget; |
|
9409 |
} |
|
9410 |
QWidget *widget; |
|
9411 |
||
9412 |
private slots: |
|
9413 |
void beEvil(QObject *) { widget->update(0, 0, 150, 150); } |
|
9414 |
}; |
|
9415 |
||
9416 |
void tst_QWidget::updateOnDestroyedSignal() |
|
9417 |
{ |
|
9418 |
QWidget widget; |
|
9419 |
||
9420 |
QWidget *child = new QWidget(&widget); |
|
9421 |
child->resize(100, 100); |
|
9422 |
child->setAutoFillBackground(true); |
|
9423 |
child->setPalette(Qt::red); |
|
9424 |
||
9425 |
widget.show(); |
|
9426 |
#ifdef Q_WS_X11 |
|
9427 |
qt_x11_wait_for_window_manager(&widget); |
|
9428 |
#endif |
|
9429 |
QTest::qWait(200); |
|
9430 |
||
9431 |
// Please do not crash. |
|
9432 |
MyEvilObject evil(child); |
|
9433 |
QTest::qWait(200); |
|
9434 |
} |
|
9435 |
||
9436 |
void tst_QWidget::toplevelLineEditFocus() |
|
9437 |
{ |
|
9438 |
testWidget->hide(); |
|
9439 |
||
9440 |
QLineEdit w; |
|
9441 |
w.show(); |
|
9442 |
QTest::qWaitForWindowShown(&w); |
|
9443 |
QTest::qWait(20); |
|
9444 |
||
9445 |
QTRY_COMPARE(QApplication::activeWindow(), (QWidget*)&w); |
|
9446 |
QTRY_COMPARE(QApplication::focusWidget(), (QWidget*)&w); |
|
9447 |
} |
|
9448 |
||
9449 |
void tst_QWidget::focusWidget_task254563() |
|
9450 |
{ |
|
9451 |
//having different visibility for widget is important |
|
9452 |
QWidget top; |
|
9453 |
top.show(); |
|
9454 |
QWidget container(&top); |
|
9455 |
QWidget *widget = new QWidget(&container); |
|
9456 |
widget->show(); |
|
9457 |
||
9458 |
widget->setFocus(); //set focus (will set the focus widget up to the toplevel to be 'widget') |
|
9459 |
container.setFocus(); |
|
9460 |
delete widget; // will call clearFocus but that doesn't help |
|
9461 |
QVERIFY(top.focusWidget() != widget); //dangling pointer |
|
9462 |
} |
|
9463 |
||
9464 |
void tst_QWidget::destroyBackingStore() |
|
9465 |
{ |
|
9466 |
#ifdef QT_BUILD_INTERNAL |
|
9467 |
UpdateWidget w; |
|
9468 |
w.reset(); |
|
9469 |
w.show(); |
|
9470 |
||
9471 |
QTest::qWaitForWindowShown(&w); |
|
9472 |
QApplication::processEvents(); |
|
9473 |
QTRY_VERIFY(w.numPaintEvents > 0); |
|
9474 |
w.reset(); |
|
9475 |
w.update(); |
|
9476 |
delete qt_widget_private(&w)->topData()->backingStore; |
|
9477 |
qt_widget_private(&w)->topData()->backingStore = 0; |
|
9478 |
qt_widget_private(&w)->topData()->backingStore = new QWidgetBackingStore(&w); |
|
9479 |
||
9480 |
w.update(); |
|
9481 |
QApplication::processEvents(); |
|
9482 |
#ifdef Q_WS_QWS |
|
9483 |
QApplication::processEvents(); |
|
9484 |
#endif |
|
9485 |
QCOMPARE(w.numPaintEvents, 1); |
|
9486 |
||
9487 |
// Check one more time, because the second time around does more caching. |
|
9488 |
w.update(); |
|
9489 |
QApplication::processEvents(); |
|
9490 |
QCOMPARE(w.numPaintEvents, 2); |
|
9491 |
#endif |
|
9492 |
} |
|
9493 |
||
9494 |
void tst_QWidget::rectOutsideCoordinatesLimit_task144779() |
|
9495 |
{ |
|
9496 |
#ifdef Q_OS_WINCE_WM |
|
9497 |
QSKIP( "Tables of 5000 elements do not make sense on Windows Mobile.", SkipAll); |
|
9498 |
#endif |
|
9499 |
QApplication::setOverrideCursor(Qt::BlankCursor); //keep the cursor out of screen grabs |
|
9500 |
QWidget main(0,Qt::FramelessWindowHint); //don't get confused by the size of the window frame |
|
9501 |
QPalette palette; |
|
9502 |
palette.setColor(QPalette::Window, Qt::red); |
|
9503 |
main.setPalette(palette); |
|
9504 |
||
9505 |
QDesktopWidget desktop; |
|
9506 |
QRect desktopDimensions = desktop.availableGeometry(&main); |
|
9507 |
QSize mainSize(400, 400); |
|
9508 |
mainSize = mainSize.boundedTo(desktopDimensions.size()); |
|
9509 |
main.resize(mainSize); |
|
9510 |
||
9511 |
QWidget *offsetWidget = new QWidget(&main); |
|
9512 |
offsetWidget->setGeometry(0, -(15000 - mainSize.height()), mainSize.width(), 15000); |
|
9513 |
||
9514 |
// big widget is too big for the coordinates, it must be limited by wrect |
|
9515 |
// if wrect is not at the right position because of offsetWidget, bigwidget |
|
9516 |
// is not painted correctly |
|
9517 |
QWidget *bigWidget = new QWidget(offsetWidget); |
|
9518 |
bigWidget->setGeometry(0, 0, mainSize.width(), 50000); |
|
9519 |
palette.setColor(QPalette::Window, Qt::green); |
|
9520 |
bigWidget->setPalette(palette); |
|
9521 |
bigWidget->setAutoFillBackground(true); |
|
9522 |
||
9523 |
main.show(); |
|
9524 |
QTest::qWaitForWindowShown(&main); |
|
9525 |
||
9526 |
QPixmap correct(main.size()); |
|
9527 |
correct.fill(Qt::green); |
|
9528 |
||
9529 |
QTRY_COMPARE(QPixmap::grabWindow(main.winId()).toImage().convertToFormat(QImage::Format_RGB32), |
|
9530 |
correct.toImage().convertToFormat(QImage::Format_RGB32)); |
|
9531 |
QApplication::restoreOverrideCursor(); |
|
9532 |
} |
|
9533 |
||
9534 |
void tst_QWidget::inputFocus_task257832() |
|
9535 |
{ |
|
9536 |
QLineEdit *widget = new QLineEdit; |
|
9537 |
QInputContext *context = widget->inputContext(); |
|
9538 |
if (!context) |
|
9539 |
QSKIP("No input context", SkipSingle); |
|
9540 |
widget->setFocus(); |
|
9541 |
widget->winId(); // make sure, widget has been created |
|
9542 |
context->setFocusWidget(widget); |
|
9543 |
QCOMPARE(context->focusWidget(), static_cast<QWidget*>(widget)); |
|
9544 |
widget->setReadOnly(true); |
|
9545 |
QVERIFY(!context->focusWidget()); |
|
9546 |
delete widget; |
|
9547 |
} |
|
9548 |
||
9549 |
void tst_QWidget::setGraphicsEffect() |
|
9550 |
{ |
|
9551 |
// Check that we don't have any effect by default. |
|
9552 |
QWidget *widget = new QWidget; |
|
9553 |
QVERIFY(!widget->graphicsEffect()); |
|
9554 |
||
9555 |
// SetGet check. |
|
9556 |
QPointer<QGraphicsEffect> blurEffect = new QGraphicsBlurEffect; |
|
9557 |
widget->setGraphicsEffect(blurEffect); |
|
9558 |
QCOMPARE(widget->graphicsEffect(), static_cast<QGraphicsEffect *>(blurEffect)); |
|
9559 |
||
9560 |
// Ensure the existing effect is deleted when setting a new one. |
|
9561 |
QPointer<QGraphicsEffect> shadowEffect = new QGraphicsDropShadowEffect; |
|
9562 |
widget->setGraphicsEffect(shadowEffect); |
|
9563 |
QVERIFY(!blurEffect); |
|
9564 |
QCOMPARE(widget->graphicsEffect(), static_cast<QGraphicsEffect *>(shadowEffect)); |
|
9565 |
blurEffect = new QGraphicsBlurEffect; |
|
9566 |
||
9567 |
// Ensure the effect is uninstalled when setting it on a new target. |
|
9568 |
QWidget *anotherWidget = new QWidget; |
|
9569 |
anotherWidget->setGraphicsEffect(blurEffect); |
|
9570 |
widget->setGraphicsEffect(blurEffect); |
|
9571 |
QVERIFY(!anotherWidget->graphicsEffect()); |
|
9572 |
QVERIFY(!shadowEffect); |
|
9573 |
||
9574 |
// Ensure the existing effect is deleted when deleting the widget. |
|
9575 |
delete widget; |
|
9576 |
QVERIFY(!blurEffect); |
|
9577 |
delete anotherWidget; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9578 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9579 |
// Ensure the effect is uninstalled when deleting it |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9580 |
widget = new QWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9581 |
blurEffect = new QGraphicsBlurEffect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9582 |
widget->setGraphicsEffect(blurEffect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9583 |
delete blurEffect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9584 |
QVERIFY(!widget->graphicsEffect()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9585 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9586 |
// Ensure the existing effect is uninstalled and deleted when setting a null effect |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9587 |
blurEffect = new QGraphicsBlurEffect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9588 |
widget->setGraphicsEffect(blurEffect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9589 |
widget->setGraphicsEffect(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9590 |
QVERIFY(!widget->graphicsEffect()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9591 |
QVERIFY(!blurEffect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9592 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9593 |
delete widget; |
0 | 9594 |
} |
9595 |
||
9596 |
void tst_QWidget::activateWindow() |
|
9597 |
{ |
|
9598 |
// Test case for task 260685 |
|
9599 |
||
9600 |
// Create first mainwindow and set it active |
|
9601 |
QMainWindow* mainwindow = new QMainWindow(); |
|
9602 |
QLabel* label = new QLabel(mainwindow); |
|
9603 |
mainwindow->setCentralWidget(label); |
|
9604 |
mainwindow->setVisible(true); |
|
9605 |
mainwindow->activateWindow(); |
|
9606 |
QTest::qWaitForWindowShown(mainwindow); |
|
9607 |
qApp->processEvents(); |
|
9608 |
||
9609 |
QTRY_VERIFY(mainwindow->isActiveWindow()); |
|
9610 |
||
9611 |
// Create second mainwindow and set it active |
|
9612 |
QMainWindow* mainwindow2 = new QMainWindow(); |
|
9613 |
QLabel* label2 = new QLabel(mainwindow2); |
|
9614 |
mainwindow2->setCentralWidget(label2); |
|
9615 |
mainwindow2->setVisible(true); |
|
9616 |
mainwindow2->activateWindow(); |
|
9617 |
qApp->processEvents(); |
|
9618 |
||
9619 |
QTRY_VERIFY(!mainwindow->isActiveWindow()); |
|
9620 |
QTRY_VERIFY(mainwindow2->isActiveWindow()); |
|
9621 |
||
9622 |
// Revert first mainwindow back to visible active |
|
9623 |
mainwindow->setVisible(true); |
|
9624 |
mainwindow->activateWindow(); |
|
9625 |
qApp->processEvents(); |
|
9626 |
||
9627 |
QTRY_VERIFY(mainwindow->isActiveWindow()); |
|
9628 |
QTRY_VERIFY(!mainwindow2->isActiveWindow()); |
|
9629 |
} |
|
9630 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9631 |
void tst_QWidget::openModal_taskQTBUG_5804() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9632 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9633 |
class Widget : public QWidget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9634 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9635 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9636 |
Widget(QWidget *parent) : QWidget(parent) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9637 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9638 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9639 |
~Widget() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9640 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9641 |
QMessageBox msgbox; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9642 |
QTimer::singleShot(10, &msgbox, SLOT(accept())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9643 |
msgbox.exec(); //open a modal dialog |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9644 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9645 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9646 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9647 |
QWidget *win = new QWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9648 |
new Widget(win); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9649 |
win->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9650 |
QTest::qWaitForWindowShown(win); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9651 |
delete win; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9652 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9653 |
|
0 | 9654 |
#ifdef Q_OS_SYMBIAN |
9655 |
void tst_QWidget::cbaVisibility() |
|
9656 |
{ |
|
9657 |
// Test case for task 261048 |
|
9658 |
||
9659 |
// Create first mainwindow in fullsreen and activate it |
|
9660 |
QMainWindow* mainwindow = new QMainWindow(); |
|
9661 |
QLabel* label = new QLabel(mainwindow); |
|
9662 |
mainwindow->setCentralWidget(label); |
|
9663 |
mainwindow->setWindowState(Qt::WindowFullScreen); |
|
9664 |
mainwindow->setVisible(true); |
|
9665 |
mainwindow->activateWindow(); |
|
9666 |
qApp->processEvents(); |
|
9667 |
||
9668 |
QVERIFY(mainwindow->isActiveWindow()); |
|
9669 |
QVERIFY(QDesktopWidget().availableGeometry().size() == mainwindow->size()); |
|
9670 |
||
9671 |
// Create second mainwindow in maximized and activate it |
|
9672 |
QMainWindow* mainwindow2 = new QMainWindow(); |
|
9673 |
QLabel* label2 = new QLabel(mainwindow2); |
|
9674 |
mainwindow2->setCentralWidget(label2); |
|
9675 |
mainwindow2->setWindowState(Qt::WindowMaximized); |
|
9676 |
mainwindow2->setVisible(true); |
|
9677 |
mainwindow2->activateWindow(); |
|
9678 |
qApp->processEvents(); |
|
9679 |
||
9680 |
QVERIFY(!mainwindow->isActiveWindow()); |
|
9681 |
QVERIFY(mainwindow2->isActiveWindow()); |
|
9682 |
QVERIFY(QDesktopWidget().availableGeometry().size() == mainwindow2->size()); |
|
9683 |
||
9684 |
// Verify window decorations i.e. status pane and CBA are visible. |
|
9685 |
CEikStatusPane* statusPane = CEikonEnv::Static()->AppUiFactory()->StatusPane(); |
|
9686 |
QVERIFY(statusPane->IsVisible()); |
|
9687 |
CEikButtonGroupContainer* buttonGroup = CEikonEnv::Static()->AppUiFactory()->Cba(); |
|
9688 |
QVERIFY(buttonGroup->IsVisible()); |
|
9689 |
} |
|
9690 |
#endif |
|
9691 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9692 |
class InputContextTester : public QInputContext |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9693 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9694 |
Q_OBJECT |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9695 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9696 |
QString identifierName() { return QString(); } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9697 |
bool isComposing() const { return false; } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9698 |
QString language() { return QString(); } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9699 |
void reset() { ++resets; } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9700 |
int resets; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9701 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9702 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9703 |
void tst_QWidget::focusProxyAndInputMethods() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9704 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9705 |
InputContextTester *inputContext = new InputContextTester; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9706 |
QWidget *toplevel = new QWidget(0, Qt::X11BypassWindowManagerHint); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9707 |
toplevel->setAttribute(Qt::WA_InputMethodEnabled, true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9708 |
toplevel->setInputContext(inputContext); // ownership is transferred |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9709 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9710 |
QWidget *child = new QWidget(toplevel); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9711 |
child->setFocusProxy(toplevel); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9712 |
child->setAttribute(Qt::WA_InputMethodEnabled, true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9713 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9714 |
toplevel->setFocusPolicy(Qt::WheelFocus); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9715 |
child->setFocusPolicy(Qt::WheelFocus); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9716 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9717 |
QVERIFY(!child->hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9718 |
QVERIFY(!toplevel->hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9719 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9720 |
toplevel->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9721 |
QTest::qWaitForWindowShown(toplevel); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9722 |
QApplication::setActiveWindow(toplevel); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9723 |
QVERIFY(toplevel->hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9724 |
QVERIFY(child->hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9725 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9726 |
// verify that toggling input methods on the child widget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9727 |
// correctly propagate to the focus proxy's input method |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9728 |
// and that the input method gets the focus proxy passed |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9729 |
// as the focus widget instead of the child widget. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9730 |
// otherwise input method queries go to the wrong widget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9731 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9732 |
QCOMPARE(inputContext->focusWidget(), toplevel); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9733 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9734 |
child->setAttribute(Qt::WA_InputMethodEnabled, false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9735 |
QVERIFY(!inputContext->focusWidget()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9736 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9737 |
child->setAttribute(Qt::WA_InputMethodEnabled, true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9738 |
QCOMPARE(inputContext->focusWidget(), toplevel); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9739 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9740 |
child->setEnabled(false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9741 |
QVERIFY(!inputContext->focusWidget()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9742 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9743 |
child->setEnabled(true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9744 |
QCOMPARE(inputContext->focusWidget(), toplevel); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9745 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9746 |
delete toplevel; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9747 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9748 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9749 |
class scrollWidgetWBS : public QWidget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9750 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9751 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9752 |
void deleteBackingStore() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9753 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9754 |
if (static_cast<QWidgetPrivate*>(d_ptr.data())->maybeBackingStore()) { |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
9755 |
delete static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->backingStore; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9756 |
static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->backingStore = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9757 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9758 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9759 |
void enableBackingStore() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9760 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9761 |
if (!static_cast<QWidgetPrivate*>(d_ptr.data())->maybeBackingStore()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9762 |
static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->backingStore = new QWidgetBackingStore(this); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9763 |
static_cast<QWidgetPrivate*>(d_ptr.data())->invalidateBuffer(this->rect()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9764 |
repaint(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9765 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9766 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9767 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9768 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9769 |
void tst_QWidget::scrollWithoutBackingStore() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9770 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9771 |
scrollWidgetWBS scrollable; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9772 |
scrollable.resize(100,100); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9773 |
QLabel child(QString("@"),&scrollable); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9774 |
child.resize(50,50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9775 |
scrollable.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9776 |
QTest::qWaitForWindowShown(&scrollable); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9777 |
scrollable.scroll(50,50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9778 |
QCOMPARE(child.pos(),QPoint(50,50)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9779 |
scrollable.deleteBackingStore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9780 |
scrollable.scroll(-25,-25); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9781 |
QCOMPARE(child.pos(),QPoint(25,25)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9782 |
scrollable.enableBackingStore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9783 |
QCOMPARE(child.pos(),QPoint(25,25)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9784 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9785 |
|
0 | 9786 |
QTEST_MAIN(tst_QWidget) |
9787 |
#include "tst_qwidget.moc" |