author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 7 | 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 |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
253 |
void showNativeChild(); |
0 | 254 |
void qobject_castInDestroyedSlot(); |
255 |
||
256 |
void showHideEvent_data(); |
|
257 |
void showHideEvent(); |
|
258 |
||
259 |
void lostUpdatesOnHide(); |
|
260 |
||
261 |
void update(); |
|
262 |
void isOpaque(); |
|
263 |
||
264 |
#ifndef Q_WS_MAC |
|
265 |
void scroll(); |
|
266 |
#endif |
|
267 |
||
268 |
// tests QWidget::setGeometry() on windows only |
|
269 |
void setWindowGeometry_data(); |
|
270 |
void setWindowGeometry(); |
|
271 |
||
272 |
// tests QWidget::move() and resize() on windows only |
|
273 |
void windowMoveResize_data(); |
|
274 |
void windowMoveResize(); |
|
275 |
||
276 |
void moveChild_data(); |
|
277 |
void moveChild(); |
|
278 |
void showAndMoveChild(); |
|
279 |
||
280 |
void subtractOpaqueSiblings(); |
|
281 |
||
282 |
#ifdef Q_WS_WIN |
|
283 |
void getDC(); |
|
284 |
#ifndef Q_OS_WINCE |
|
285 |
void setGeometry_win(); |
|
286 |
#endif |
|
287 |
#endif |
|
288 |
||
289 |
void setLocale(); |
|
290 |
void deleteStyle(); |
|
291 |
void multipleToplevelFocusCheck(); |
|
292 |
void setFocus(); |
|
293 |
void setCursor(); |
|
294 |
void setToolTip(); |
|
295 |
void testWindowIconChangeEventPropagation(); |
|
296 |
#ifdef Q_WS_X11 |
|
297 |
void minAndMaxSizeWithX11BypassWindowManagerHint(); |
|
298 |
void showHideShow(); |
|
299 |
void clean_qt_x11_enforce_cursor(); |
|
300 |
#endif |
|
301 |
||
302 |
void compatibilityChildInsertedEvents(); |
|
303 |
void render(); |
|
304 |
void renderInvisible(); |
|
305 |
void renderWithPainter(); |
|
306 |
void render_task188133(); |
|
307 |
void render_task211796(); |
|
308 |
void render_task217815(); |
|
309 |
void render_windowOpacity(); |
|
310 |
void render_systemClip(); |
|
311 |
void render_systemClip2_data(); |
|
312 |
void render_systemClip2(); |
|
313 |
void render_systemClip3_data(); |
|
314 |
void render_systemClip3(); |
|
315 |
void render_task252837(); |
|
316 |
void render_worldTransform(); |
|
317 |
||
318 |
void setContentsMargins(); |
|
319 |
||
320 |
void moveWindowInShowEvent_data(); |
|
321 |
void moveWindowInShowEvent(); |
|
322 |
||
323 |
void repaintWhenChildDeleted(); |
|
324 |
void hideOpaqueChildWhileHidden(); |
|
325 |
void updateWhileMinimized(); |
|
326 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) |
|
327 |
void alienWidgets(); |
|
328 |
#endif |
|
329 |
void adjustSize(); |
|
330 |
void adjustSize_data(); |
|
331 |
void updateGeometry(); |
|
332 |
void updateGeometry_data(); |
|
333 |
void sendUpdateRequestImmediately(); |
|
334 |
void painterRedirection(); |
|
335 |
void doubleRepaint(); |
|
336 |
#ifndef Q_WS_MAC |
|
337 |
void resizeInPaintEvent(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
338 |
void opaqueChildren(); |
0 | 339 |
#endif |
340 |
||
341 |
void setMaskInResizeEvent(); |
|
342 |
void moveInResizeEvent(); |
|
343 |
||
344 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) |
|
345 |
// We don't support immediate repaint right after show on |
|
346 |
// other platforms. Must be compatible with Qt 4.3. |
|
347 |
void immediateRepaintAfterShow(); |
|
348 |
void immediateRepaintAfterInvalidateBuffer(); |
|
349 |
#endif |
|
350 |
void effectiveWinId(); |
|
351 |
void customDpi(); |
|
352 |
void customDpiProperty(); |
|
353 |
||
354 |
void quitOnCloseAttribute(); |
|
355 |
void moveRect(); |
|
356 |
||
357 |
#if defined (Q_WS_WIN) |
|
358 |
void gdiPainting(); |
|
359 |
void paintOnScreenPossible(); |
|
360 |
#endif |
|
361 |
void reparentStaticWidget(); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
362 |
void QTBUG6883_reparentStaticWidget2(); |
0 | 363 |
#ifdef Q_WS_QWS |
364 |
void updateOutsideSurfaceClip(); |
|
365 |
#endif |
|
366 |
void translucentWidget(); |
|
367 |
||
368 |
void setClearAndResizeMask(); |
|
369 |
void maskedUpdate(); |
|
370 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_QWS) |
|
371 |
void syntheticEnterLeave(); |
|
372 |
void taskQTBUG_4055_sendSyntheticEnterLeave(); |
|
373 |
#endif |
|
374 |
void windowFlags(); |
|
375 |
void initialPosForDontShowOnScreenWidgets(); |
|
376 |
#ifdef Q_WS_X11 |
|
377 |
void paintOutsidePaintEvent(); |
|
378 |
#endif |
|
379 |
void updateOnDestroyedSignal(); |
|
380 |
void toplevelLineEditFocus(); |
|
381 |
void inputFocus_task257832(); |
|
382 |
||
383 |
void focusWidget_task254563(); |
|
384 |
void rectOutsideCoordinatesLimit_task144779(); |
|
385 |
void setGraphicsEffect(); |
|
386 |
||
387 |
void destroyBackingStore(); |
|
388 |
||
389 |
void activateWindow(); |
|
390 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
391 |
void openModal_taskQTBUG_5804(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
392 |
|
0 | 393 |
#ifdef Q_OS_SYMBIAN |
394 |
void cbaVisibility(); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
395 |
void fullScreenWindowModeTransitions(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
396 |
void maximizedWindowModeTransitions(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
397 |
void minimizedWindowModeTransitions(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
398 |
void normalWindowModeTransitions(); |
0 | 399 |
#endif |
400 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
void focusProxyAndInputMethods(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
void scrollWithoutBackingStore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
404 |
void taskQTBUG_7532_tabOrderWithFocusProxy(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
405 |
void movedAndResizedAttributes(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
406 |
|
0 | 407 |
private: |
408 |
bool ensureScreenSize(int width, int height); |
|
409 |
QWidget *testWidget; |
|
410 |
}; |
|
411 |
||
412 |
bool tst_QWidget::ensureScreenSize(int width, int height) |
|
413 |
{ |
|
414 |
QSize available; |
|
415 |
#ifdef Q_WS_QWS |
|
416 |
available = QDesktopWidget().availableGeometry().size(); |
|
417 |
if (available.width() < width || available.height() < height) { |
|
418 |
QScreen *screen = QScreen::instance(); |
|
419 |
if (!screen) |
|
420 |
return false; |
|
421 |
screen->setMode(width, height, screen->depth()); |
|
422 |
} |
|
423 |
#endif // Q_WS_QWS |
|
424 |
||
425 |
available = QDesktopWidget().availableGeometry().size(); |
|
426 |
return (available.width() >= width && available.height() >= height); |
|
427 |
} |
|
428 |
||
429 |
class MyInputContext : public QInputContext |
|
430 |
{ |
|
431 |
public: |
|
432 |
MyInputContext() : QInputContext() {} |
|
433 |
QString identifierName() { return QString("NoName"); } |
|
434 |
QString language() { return QString("NoLanguage"); } |
|
435 |
void reset() {} |
|
436 |
bool isComposing() const { return false; } |
|
437 |
}; |
|
438 |
||
439 |
// Testing get/set functions |
|
440 |
void tst_QWidget::getSetCheck() |
|
441 |
{ |
|
442 |
QWidget obj1; |
|
443 |
QWidget child1(&obj1); |
|
444 |
// QStyle * QWidget::style() |
|
445 |
// void QWidget::setStyle(QStyle *) |
|
446 |
QWindowsStyle *var1 = new QWindowsStyle; |
|
447 |
obj1.setStyle(var1); |
|
448 |
QCOMPARE(static_cast<QStyle *>(var1), obj1.style()); |
|
449 |
obj1.setStyle((QStyle *)0); |
|
450 |
QVERIFY(var1 != obj1.style()); |
|
451 |
QVERIFY(0 != obj1.style()); // style can never be 0 for a widget |
|
452 |
||
453 |
// int QWidget::minimumWidth() |
|
454 |
// void QWidget::setMinimumWidth(int) |
|
455 |
obj1.setMinimumWidth(0); |
|
456 |
QCOMPARE(obj1.minimumWidth(), 0); |
|
457 |
obj1.setMinimumWidth(INT_MIN); |
|
458 |
QCOMPARE(obj1.minimumWidth(), 0); // A widgets width can never be less than 0 |
|
459 |
obj1.setMinimumWidth(INT_MAX); |
|
460 |
#ifndef Q_WS_QWS //QWS doesn't allow toplevels to be bigger than the screen |
|
461 |
#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) |
|
462 |
QCOMPARE((long)obj1.minimumWidth(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium |
|
463 |
#else |
|
464 |
QCOMPARE(obj1.minimumWidth(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium |
|
465 |
#endif |
|
466 |
#endif |
|
467 |
||
468 |
child1.setMinimumWidth(0); |
|
469 |
QCOMPARE(child1.minimumWidth(), 0); |
|
470 |
child1.setMinimumWidth(INT_MIN); |
|
471 |
QCOMPARE(child1.minimumWidth(), 0); // A widgets width can never be less than 0 |
|
472 |
child1.setMinimumWidth(INT_MAX); |
|
473 |
#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) |
|
474 |
QCOMPARE((long)child1.minimumWidth(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium |
|
475 |
#else |
|
476 |
QCOMPARE(child1.minimumWidth(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium |
|
477 |
#endif |
|
478 |
||
479 |
// int QWidget::minimumHeight() |
|
480 |
// void QWidget::setMinimumHeight(int) |
|
481 |
obj1.setMinimumHeight(0); |
|
482 |
QCOMPARE(obj1.minimumHeight(), 0); |
|
483 |
obj1.setMinimumHeight(INT_MIN); |
|
484 |
QCOMPARE(obj1.minimumHeight(), 0); // A widgets height can never be less than 0 |
|
485 |
obj1.setMinimumHeight(INT_MAX); |
|
486 |
#ifndef Q_WS_QWS //QWS doesn't allow toplevels to be bigger than the screen |
|
487 |
#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) |
|
488 |
QCOMPARE((long)obj1.minimumHeight(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium |
|
489 |
#else |
|
490 |
QCOMPARE(obj1.minimumHeight(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium |
|
491 |
#endif |
|
492 |
#endif |
|
493 |
||
494 |
child1.setMinimumHeight(0); |
|
495 |
QCOMPARE(child1.minimumHeight(), 0); |
|
496 |
child1.setMinimumHeight(INT_MIN); |
|
497 |
QCOMPARE(child1.minimumHeight(), 0); // A widgets height can never be less than 0 |
|
498 |
child1.setMinimumHeight(INT_MAX); |
|
499 |
#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) |
|
500 |
QCOMPARE((long)child1.minimumHeight(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium |
|
501 |
#else |
|
502 |
QCOMPARE(child1.minimumHeight(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium |
|
503 |
#endif |
|
504 |
||
505 |
||
506 |
||
507 |
// int QWidget::maximumWidth() |
|
508 |
// void QWidget::setMaximumWidth(int) |
|
509 |
obj1.setMaximumWidth(0); |
|
510 |
QCOMPARE(obj1.maximumWidth(), 0); |
|
511 |
obj1.setMaximumWidth(INT_MIN); |
|
512 |
QCOMPARE(obj1.maximumWidth(), 0); // A widgets width can never be less than 0 |
|
513 |
obj1.setMaximumWidth(INT_MAX); |
|
514 |
#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) |
|
515 |
QCOMPARE((long)obj1.maximumWidth(), QWIDGETSIZE_MAX); // QWIDGETSIZE_MAX is the abs max, not INT_MAX |
|
516 |
#else |
|
517 |
QCOMPARE(obj1.maximumWidth(), QWIDGETSIZE_MAX); // QWIDGETSIZE_MAX is the abs max, not INT_MAX |
|
518 |
#endif |
|
519 |
||
520 |
// int QWidget::maximumHeight() |
|
521 |
// void QWidget::setMaximumHeight(int) |
|
522 |
obj1.setMaximumHeight(0); |
|
523 |
QCOMPARE(obj1.maximumHeight(), 0); |
|
524 |
obj1.setMaximumHeight(INT_MIN); |
|
525 |
QCOMPARE(obj1.maximumHeight(), 0); // A widgets height can never be less than 0 |
|
526 |
obj1.setMaximumHeight(INT_MAX); |
|
527 |
#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) |
|
528 |
QCOMPARE((long)obj1.maximumHeight(), QWIDGETSIZE_MAX); // QWIDGETSIZE_MAX is the abs max, not INT_MAX |
|
529 |
#else |
|
530 |
QCOMPARE(obj1.maximumHeight(), QWIDGETSIZE_MAX); // QWIDGETSIZE_MAX is the abs max, not INT_MAX |
|
531 |
#endif |
|
532 |
||
533 |
// back to normal |
|
534 |
obj1.setMinimumWidth(0); |
|
535 |
obj1.setMinimumHeight(0); |
|
536 |
obj1.setMaximumWidth(QWIDGETSIZE_MAX); |
|
537 |
obj1.setMaximumHeight(QWIDGETSIZE_MAX); |
|
538 |
||
539 |
// const QPalette & QWidget::palette() |
|
540 |
// void QWidget::setPalette(const QPalette &) |
|
541 |
QPalette var6; |
|
542 |
obj1.setPalette(var6); |
|
543 |
QCOMPARE(var6, obj1.palette()); |
|
544 |
obj1.setPalette(QPalette()); |
|
545 |
QCOMPARE(QPalette(), obj1.palette()); |
|
546 |
||
547 |
// const QFont & QWidget::font() |
|
548 |
// void QWidget::setFont(const QFont &) |
|
549 |
QFont var7; |
|
550 |
obj1.setFont(var7); |
|
551 |
QCOMPARE(var7, obj1.font()); |
|
552 |
obj1.setFont(QFont()); |
|
553 |
QCOMPARE(QFont(), obj1.font()); |
|
554 |
||
555 |
// qreal QWidget::windowOpacity() |
|
556 |
// void QWidget::setWindowOpacity(qreal) |
|
557 |
obj1.setWindowOpacity(0.0); |
|
558 |
QCOMPARE(0.0, obj1.windowOpacity()); |
|
559 |
obj1.setWindowOpacity(1.1f); |
|
560 |
QCOMPARE(1.0, obj1.windowOpacity()); // 1.0 is the fullest opacity possible |
|
561 |
||
562 |
// QWidget * QWidget::focusProxy() |
|
563 |
// void QWidget::setFocusProxy(QWidget *) |
|
564 |
QWidget *var9 = new QWidget(); |
|
565 |
obj1.setFocusProxy(var9); |
|
566 |
QCOMPARE(var9, obj1.focusProxy()); |
|
567 |
obj1.setFocusProxy((QWidget *)0); |
|
568 |
QCOMPARE((QWidget *)0, obj1.focusProxy()); |
|
569 |
delete var9; |
|
570 |
||
571 |
// const QRect & QWidget::geometry() |
|
572 |
// void QWidget::setGeometry(const QRect &) |
|
573 |
qApp->processEvents(); |
|
574 |
QRect var10(10, 10, 100, 100); |
|
575 |
obj1.setGeometry(var10); |
|
576 |
qApp->processEvents(); |
|
577 |
qDebug() << obj1.geometry(); |
|
578 |
QCOMPARE(var10, obj1.geometry()); |
|
579 |
obj1.setGeometry(QRect(0,0,0,0)); |
|
580 |
qDebug() << obj1.geometry(); |
|
581 |
QCOMPARE(QRect(0,0,0,0), obj1.geometry()); |
|
582 |
||
583 |
// QLayout * QWidget::layout() |
|
584 |
// void QWidget::setLayout(QLayout *) |
|
585 |
QBoxLayout *var11 = new QBoxLayout(QBoxLayout::LeftToRight); |
|
586 |
obj1.setLayout(var11); |
|
587 |
QCOMPARE(static_cast<QLayout *>(var11), obj1.layout()); |
|
588 |
obj1.setLayout((QLayout *)0); |
|
589 |
QCOMPARE(static_cast<QLayout *>(var11), obj1.layout()); // You cannot set a 0-pointer layout, that keeps the current |
|
590 |
delete var11; // This will remove the layout from the widget |
|
591 |
QCOMPARE((QLayout *)0, obj1.layout()); |
|
592 |
||
593 |
// bool QWidget::acceptDrops() |
|
594 |
// void QWidget::setAcceptDrops(bool) |
|
595 |
obj1.setAcceptDrops(false); |
|
596 |
QCOMPARE(false, obj1.acceptDrops()); |
|
597 |
obj1.setAcceptDrops(true); |
|
598 |
QCOMPARE(true, obj1.acceptDrops()); |
|
599 |
||
600 |
// QInputContext * QWidget::inputContext() |
|
601 |
// void QWidget::setInputContext(QInputContext *) |
|
602 |
MyInputContext *var13 = new MyInputContext; |
|
603 |
obj1.setInputContext(var13); |
|
604 |
QCOMPARE((QInputContext *)0, obj1.inputContext()); // The widget by default doesn't have the WA_InputMethodEnabled attribute |
|
605 |
obj1.setAttribute(Qt::WA_InputMethodEnabled); |
|
606 |
obj1.setInputContext(var13); |
|
607 |
QCOMPARE(static_cast<QInputContext *>(var13), obj1.inputContext()); |
|
608 |
obj1.setInputContext((QInputContext *)0); |
|
609 |
QCOMPARE(qApp->inputContext(), obj1.inputContext()); |
|
610 |
QVERIFY(qApp->inputContext() != var13); |
|
611 |
//delete var13; // No delete, since QWidget takes ownership |
|
612 |
||
613 |
// bool QWidget::autoFillBackground() |
|
614 |
// void QWidget::setAutoFillBackground(bool) |
|
615 |
obj1.setAutoFillBackground(false); |
|
616 |
QCOMPARE(false, obj1.autoFillBackground()); |
|
617 |
obj1.setAutoFillBackground(true); |
|
618 |
QCOMPARE(true, obj1.autoFillBackground()); |
|
619 |
||
620 |
delete var1; |
|
621 |
#if defined (Q_WS_WIN) && !defined(Q_OS_WINCE) |
|
622 |
obj1.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint); |
|
623 |
HWND handle = obj1.winId(); |
|
624 |
long flags = GetWindowLong(handle, GWL_STYLE); |
|
625 |
QVERIFY(flags & WS_POPUP); |
|
626 |
#endif |
|
627 |
} |
|
628 |
||
629 |
tst_QWidget::tst_QWidget() |
|
630 |
{ |
|
631 |
QFont font; |
|
632 |
font.setBold(true); |
|
633 |
font.setPointSize(42); |
|
634 |
qApp->setFont(font, "QPropagationTestWidget"); |
|
635 |
||
636 |
QPalette palette; |
|
637 |
palette.setColor(QPalette::ToolTipBase, QColor(12, 13, 14)); |
|
638 |
palette.setColor(QPalette::Text, QColor(21, 22, 23)); |
|
639 |
qApp->setPalette(palette, "QPropagationTestWidget"); |
|
640 |
||
641 |
testWidget = 0; |
|
642 |
} |
|
643 |
||
644 |
tst_QWidget::~tst_QWidget() |
|
645 |
{ |
|
646 |
} |
|
647 |
||
648 |
class BezierViewer : public QWidget { |
|
649 |
public: |
|
650 |
BezierViewer( QWidget* parent=0, const char* name=0 ); |
|
651 |
void paintEvent( QPaintEvent* ); |
|
652 |
void setPoints( const QPolygonF& poly ); |
|
653 |
private: |
|
654 |
QPolygonF points; |
|
655 |
||
656 |
}; |
|
657 |
||
658 |
void tst_QWidget::initTestCase() |
|
659 |
{ |
|
660 |
#ifdef Q_OS_WINCE //disable magic for WindowsCE |
|
661 |
qApp->setAutoMaximizeThreshold(-1); |
|
662 |
#endif |
|
663 |
// Create the test class |
|
664 |
testWidget = new BezierViewer( 0, "testObject"); |
|
665 |
testWidget->resize(200,200); |
|
666 |
#ifdef QT3_SUPPORT |
|
667 |
qApp->setMainWidget(testWidget); |
|
668 |
#endif |
|
669 |
testWidget->show(); |
|
670 |
QTest::qWaitForWindowShown(testWidget); |
|
671 |
QTest::qWait(50); |
|
672 |
} |
|
673 |
||
674 |
void tst_QWidget::cleanupTestCase() |
|
675 |
{ |
|
676 |
delete testWidget; |
|
677 |
testWidget = 0; |
|
678 |
} |
|
679 |
||
680 |
void tst_QWidget::init() |
|
681 |
{ |
|
682 |
// TODO: Add initialization code here. |
|
683 |
// This will be executed immediately before each test is run. |
|
684 |
testWidget->setFont(QFont()); |
|
685 |
testWidget->setPalette(QPalette()); |
|
686 |
} |
|
687 |
||
688 |
void tst_QWidget::cleanup() |
|
689 |
{ |
|
690 |
} |
|
691 |
||
692 |
// Helper class... |
|
693 |
||
694 |
BezierViewer::BezierViewer( QWidget* parent, const char* name ) |
|
695 |
: QWidget( parent ) |
|
696 |
{ |
|
697 |
setObjectName(name); |
|
698 |
QPalette pal; |
|
699 |
pal.setColor(backgroundRole(), Qt::white); |
|
700 |
setPalette(pal); |
|
701 |
} |
|
702 |
||
703 |
||
704 |
void BezierViewer::setPoints( const QPolygonF& a ) |
|
705 |
{ |
|
706 |
points = a; |
|
707 |
} |
|
708 |
||
709 |
#include "private/qbezier_p.h" |
|
710 |
void BezierViewer::paintEvent( QPaintEvent* ) |
|
711 |
{ |
|
712 |
if ( points.size() != 4 ) { |
|
713 |
#if defined(QT_CHECK_RANGE) |
|
714 |
qWarning( "QPolygon::bezier: The array must have 4 control points" ); |
|
715 |
#endif |
|
716 |
return; |
|
717 |
} |
|
718 |
||
719 |
/* Calculate Bezier curve */ |
|
720 |
QPolygonF bezier = QBezier::fromPoints(points.at(0),points.at(1),points.at(2),points.at(3)).toPolygon(); |
|
721 |
||
722 |
QPainter painter( this ); |
|
723 |
||
724 |
/* Calculate scale to fit in window */ |
|
725 |
QRectF br = bezier.boundingRect() | points.boundingRect(); |
|
726 |
QRectF pr = rect(); |
|
727 |
int scl = qMax( qMin(pr.width()/br.width(), pr.height()/br.height()), qreal(1.) ); |
|
728 |
int border = scl-1; |
|
729 |
||
730 |
/* Scale Bezier curve vertices */ |
|
731 |
for ( QPolygonF::Iterator it = bezier.begin(); it != bezier.end(); ++it ) { |
|
732 |
it->setX( (it->x()-br.x()) * scl + border ); |
|
733 |
it->setY( (it->y()-br.y()) * scl + border ); |
|
734 |
} |
|
735 |
||
736 |
/* Draw grid */ |
|
737 |
painter.setPen( Qt::lightGray ); |
|
738 |
int i; |
|
739 |
for ( i = border; i <= pr.width(); i += scl ) { |
|
740 |
painter.drawLine( i, 0, i, pr.height() ); |
|
741 |
} |
|
742 |
for ( int j = border; j <= pr.height(); j += scl ) { |
|
743 |
painter.drawLine( 0, j, pr.width(), j ); |
|
744 |
} |
|
745 |
||
746 |
/* Write number of vertices */ |
|
747 |
painter.setPen( Qt::red ); |
|
748 |
painter.setFont( QFont("Helvetica", 14, QFont::DemiBold, TRUE ) ); |
|
749 |
QString caption; |
|
750 |
caption.setNum( bezier.size() ); |
|
751 |
caption += QString::fromLatin1( " vertices" ); |
|
752 |
painter.drawText( 10, pr.height()-10, caption ); |
|
753 |
||
754 |
/* Draw Bezier curve */ |
|
755 |
painter.setPen( Qt::black ); |
|
756 |
painter.drawPolyline( bezier ); |
|
757 |
||
758 |
/* Scale and draw control points */ |
|
759 |
painter.setPen( Qt::darkGreen ); |
|
760 |
for ( QPolygonF::Iterator p1 = points.begin(); p1 != points.end(); ++p1 ) { |
|
761 |
int x = (p1->x()-br.x()) * scl + border; |
|
762 |
int y = (p1->y()-br.y()) * scl + border; |
|
763 |
painter.drawLine( x-4, y-4, x+4, y+4 ); |
|
764 |
painter.drawLine( x+4, y-4, x-4, y+4 ); |
|
765 |
} |
|
766 |
||
767 |
/* Draw vertices */ |
|
768 |
painter.setPen( Qt::red ); |
|
769 |
painter.setBrush( Qt::red ); |
|
770 |
for ( QPolygonF::Iterator p2 = bezier.begin(); p2 != bezier.end(); ++p2 ) |
|
771 |
painter.drawEllipse( p2->x()-1, p2->y()-1, 3, 3 ); |
|
772 |
} |
|
773 |
||
774 |
void tst_QWidget::fontPropagation() |
|
775 |
{ |
|
776 |
QFont font = testWidget->font(); |
|
777 |
QWidget* childWidget = new QWidget( testWidget ); |
|
778 |
childWidget->show(); |
|
779 |
QCOMPARE( font, childWidget->font() ); |
|
780 |
||
781 |
font.setBold( TRUE ); |
|
782 |
testWidget->setFont( font ); |
|
783 |
QCOMPARE( font, testWidget->font() ); |
|
784 |
QCOMPARE( font, childWidget->font() ); |
|
785 |
||
786 |
QFont newFont = font; |
|
787 |
newFont.setItalic( TRUE ); |
|
788 |
childWidget->setFont( newFont ); |
|
789 |
QWidget* grandChildWidget = new QWidget( childWidget ); |
|
790 |
QCOMPARE( font, testWidget->font() ); |
|
791 |
QCOMPARE( newFont, grandChildWidget->font() ); |
|
792 |
||
793 |
font.setUnderline( TRUE ); |
|
794 |
testWidget->setFont( font ); |
|
795 |
||
796 |
// the child and grand child should now have merged bold and |
|
797 |
// underline |
|
798 |
newFont.setUnderline( TRUE ); |
|
799 |
||
800 |
QCOMPARE( newFont, childWidget->font() ); |
|
801 |
QCOMPARE( newFont, grandChildWidget->font() ); |
|
802 |
||
803 |
// make sure font propagation continues working after reparenting |
|
804 |
font = testWidget->font(); |
|
805 |
font.setPointSize(font.pointSize() + 2); |
|
806 |
testWidget->setFont(font); |
|
807 |
||
808 |
QWidget *one = new QWidget(testWidget); |
|
809 |
QWidget *two = new QWidget(one); |
|
810 |
QWidget *three = new QWidget(two); |
|
811 |
QWidget *four = new QWidget(two); |
|
812 |
||
813 |
four->setParent(three); |
|
814 |
four->move(QPoint(0,0)); |
|
815 |
||
816 |
font.setPointSize(font.pointSize() + 2); |
|
817 |
testWidget->setFont(font); |
|
818 |
||
819 |
QCOMPARE(testWidget->font(), one->font()); |
|
820 |
QCOMPARE(one->font(), two->font()); |
|
821 |
QCOMPARE(two->font(), three->font()); |
|
822 |
QCOMPARE(three->font(), four->font()); |
|
823 |
||
824 |
QVERIFY(testWidget->testAttribute(Qt::WA_SetFont)); |
|
825 |
QVERIFY(! one->testAttribute(Qt::WA_SetFont)); |
|
826 |
QVERIFY(! two->testAttribute(Qt::WA_SetFont)); |
|
827 |
QVERIFY(! three->testAttribute(Qt::WA_SetFont)); |
|
828 |
QVERIFY(! four->testAttribute(Qt::WA_SetFont)); |
|
829 |
||
830 |
font.setPointSize(font.pointSize() + 2); |
|
831 |
one->setFont(font); |
|
832 |
||
833 |
QCOMPARE(one->font(), two->font()); |
|
834 |
QCOMPARE(two->font(), three->font()); |
|
835 |
QCOMPARE(three->font(), four->font()); |
|
836 |
||
837 |
QVERIFY(one->testAttribute(Qt::WA_SetFont)); |
|
838 |
QVERIFY(! two->testAttribute(Qt::WA_SetFont)); |
|
839 |
QVERIFY(! three->testAttribute(Qt::WA_SetFont)); |
|
840 |
QVERIFY(! four->testAttribute(Qt::WA_SetFont)); |
|
841 |
||
842 |
font.setPointSize(font.pointSize() + 2); |
|
843 |
two->setFont(font); |
|
844 |
||
845 |
QCOMPARE(two->font(), three->font()); |
|
846 |
QCOMPARE(three->font(), four->font()); |
|
847 |
||
848 |
QVERIFY(two->testAttribute(Qt::WA_SetFont)); |
|
849 |
QVERIFY(! three->testAttribute(Qt::WA_SetFont)); |
|
850 |
QVERIFY(! four->testAttribute(Qt::WA_SetFont)); |
|
851 |
||
852 |
font.setPointSize(font.pointSize() + 2); |
|
853 |
three->setFont(font); |
|
854 |
||
855 |
QCOMPARE(three->font(), four->font()); |
|
856 |
||
857 |
QVERIFY(three->testAttribute(Qt::WA_SetFont)); |
|
858 |
QVERIFY(! four->testAttribute(Qt::WA_SetFont)); |
|
859 |
||
860 |
font.setPointSize(font.pointSize() + 2); |
|
861 |
four->setFont(font); |
|
862 |
||
863 |
QVERIFY(four->testAttribute(Qt::WA_SetFont)); |
|
864 |
} |
|
865 |
||
866 |
class QPropagationTestWidget : public QWidget |
|
867 |
{ |
|
868 |
Q_OBJECT |
|
869 |
public: |
|
870 |
QPropagationTestWidget(QWidget *parent = 0) |
|
871 |
: QWidget(parent) |
|
872 |
{ } |
|
873 |
}; |
|
874 |
||
875 |
void tst_QWidget::fontPropagation2() |
|
876 |
{ |
|
877 |
// ! Note, the code below is executed in tst_QWidget's constructor. |
|
878 |
// QFont font; |
|
879 |
// font.setBold(true); |
|
880 |
// font.setPointSize(42); |
|
881 |
// qApp->setFont(font, "QPropagationTestWidget"); |
|
882 |
||
883 |
QWidget *root = new QWidget; |
|
884 |
QWidget *child0 = new QWidget(root); |
|
885 |
QWidget *child1 = new QWidget(child0); |
|
886 |
QWidget *child2 = new QPropagationTestWidget(child1); |
|
887 |
QWidget *child3 = new QWidget(child2); |
|
888 |
QWidget *child4 = new QWidget(child3); |
|
889 |
QWidget *child5 = new QWidget(child4); |
|
890 |
root->show(); |
|
891 |
||
892 |
// Check that only the application fonts apply. |
|
893 |
QCOMPARE(root->font(), QApplication::font()); |
|
894 |
QCOMPARE(child0->font(), QApplication::font()); |
|
895 |
QCOMPARE(child1->font(), QApplication::font()); |
|
896 |
QCOMPARE(child2->font().pointSize(), 42); |
|
897 |
QVERIFY(child2->font().bold()); |
|
898 |
QCOMPARE(child3->font().pointSize(), 42); |
|
899 |
QVERIFY(child3->font().bold()); |
|
900 |
QCOMPARE(child4->font().pointSize(), 42); |
|
901 |
QVERIFY(child4->font().bold()); |
|
902 |
QCOMPARE(child5->font().pointSize(), 42); |
|
903 |
QVERIFY(child5->font().bold()); |
|
904 |
||
905 |
// Set child0's font size to 15, and remove bold on child4. |
|
906 |
QFont font; |
|
907 |
font.setPointSize(15); |
|
908 |
child0->setFont(font); |
|
909 |
QFont unboldFont; |
|
910 |
unboldFont.setBold(false); |
|
911 |
child4->setFont(unboldFont); |
|
912 |
||
913 |
// Check that the above settings propagate correctly. |
|
914 |
QCOMPARE(root->font(), QApplication::font()); |
|
915 |
QCOMPARE(child0->font().pointSize(), 15); |
|
916 |
QVERIFY(!child0->font().bold()); |
|
917 |
QCOMPARE(child1->font().pointSize(), 15); |
|
918 |
QVERIFY(!child1->font().bold()); |
|
919 |
QCOMPARE(child2->font().pointSize(), 15); |
|
920 |
QVERIFY(child2->font().bold()); |
|
921 |
QCOMPARE(child3->font().pointSize(), 15); |
|
922 |
QVERIFY(child3->font().bold()); |
|
923 |
QCOMPARE(child4->font().pointSize(), 15); |
|
924 |
QVERIFY(!child4->font().bold()); |
|
925 |
QCOMPARE(child5->font().pointSize(), 15); |
|
926 |
QVERIFY(!child5->font().bold()); |
|
927 |
||
928 |
// Replace the app font for child2. Italic should propagate |
|
929 |
// but the size should still be ignored. The previous bold |
|
930 |
// setting is gone. |
|
931 |
QFont italicSizeFont; |
|
932 |
italicSizeFont.setItalic(true); |
|
933 |
italicSizeFont.setPointSize(33); |
|
934 |
qApp->setFont(italicSizeFont, "QPropagationTestWidget"); |
|
935 |
||
936 |
// Check that this propagates correctly. |
|
937 |
QCOMPARE(root->font(), QApplication::font()); |
|
938 |
QCOMPARE(child0->font().pointSize(), 15); |
|
939 |
QVERIFY(!child0->font().bold()); |
|
940 |
QVERIFY(!child0->font().italic()); |
|
941 |
QCOMPARE(child1->font().pointSize(), 15); |
|
942 |
QVERIFY(!child1->font().bold()); |
|
943 |
QVERIFY(!child1->font().italic()); |
|
944 |
QCOMPARE(child2->font().pointSize(), 15); |
|
945 |
QVERIFY(!child2->font().bold()); |
|
946 |
QVERIFY(child2->font().italic()); |
|
947 |
QCOMPARE(child3->font().pointSize(), 15); |
|
948 |
QVERIFY(!child3->font().bold()); |
|
949 |
QVERIFY(child3->font().italic()); |
|
950 |
QCOMPARE(child4->font().pointSize(), 15); |
|
951 |
QVERIFY(!child4->font().bold()); |
|
952 |
QVERIFY(child4->font().italic()); |
|
953 |
QCOMPARE(child5->font().pointSize(), 15); |
|
954 |
QVERIFY(!child5->font().bold()); |
|
955 |
QVERIFY(child5->font().italic()); |
|
956 |
} |
|
957 |
||
958 |
void tst_QWidget::palettePropagation() |
|
959 |
{ |
|
960 |
QPalette palette = testWidget->palette(); |
|
961 |
QWidget* childWidget = new QWidget( testWidget ); |
|
962 |
childWidget->show(); |
|
963 |
QCOMPARE( palette, childWidget->palette() ); |
|
964 |
||
965 |
palette.setColor( QPalette::Base, Qt::red ); |
|
966 |
testWidget->setPalette( palette ); |
|
967 |
QCOMPARE( palette, testWidget->palette() ); |
|
968 |
QCOMPARE( palette, childWidget->palette() ); |
|
969 |
||
970 |
QPalette newPalette = palette; |
|
971 |
newPalette.setColor( QPalette::Highlight, Qt::green ); |
|
972 |
childWidget->setPalette( newPalette ); |
|
973 |
QWidget* grandChildWidget = new QWidget( childWidget ); |
|
974 |
QCOMPARE( palette, testWidget->palette() ); |
|
975 |
QCOMPARE( newPalette, grandChildWidget->palette() ); |
|
976 |
||
977 |
palette.setColor( QPalette::Text, Qt::blue ); |
|
978 |
testWidget->setPalette( palette ); |
|
979 |
||
980 |
// the child and grand child should now have merged green |
|
981 |
// highlight and blue text |
|
982 |
newPalette.setColor( QPalette::Text, Qt::blue); |
|
983 |
||
984 |
QCOMPARE( newPalette, childWidget->palette() ); |
|
985 |
QCOMPARE( newPalette, grandChildWidget->palette() ); |
|
986 |
} |
|
987 |
||
988 |
void tst_QWidget::palettePropagation2() |
|
989 |
{ |
|
990 |
// ! Note, the code below is executed in tst_QWidget's constructor. |
|
991 |
// QPalette palette; |
|
992 |
// font.setColor(QPalette::ToolTipBase, QColor(12, 13, 14)); |
|
993 |
// font.setColor(QPalette::Text, QColor(21, 22, 23)); |
|
994 |
// qApp->setPalette(palette, "QPropagationTestWidget"); |
|
995 |
||
996 |
QWidget *root = new QWidget; |
|
997 |
QWidget *child0 = new QWidget(root); |
|
998 |
QWidget *child1 = new QWidget(child0); |
|
999 |
QWidget *child2 = new QPropagationTestWidget(child1); |
|
1000 |
QWidget *child3 = new QWidget(child2); |
|
1001 |
QWidget *child4 = new QWidget(child3); |
|
1002 |
QWidget *child5 = new QWidget(child4); |
|
1003 |
root->show(); |
|
1004 |
QTest::qWait(100); |
|
1005 |
||
1006 |
// These colors are unlikely to be imposed on the default palette of |
|
1007 |
// QWidget ;-). |
|
1008 |
QColor sysPalText(21, 22, 23); |
|
1009 |
QColor sysPalToolTipBase(12, 13, 14); |
|
1010 |
QColor overridePalText(42, 43, 44); |
|
1011 |
QColor overridePalToolTipBase(45, 46, 47); |
|
1012 |
QColor sysPalButton(99, 98, 97); |
|
1013 |
||
1014 |
// Check that only the application fonts apply. |
|
1015 |
QPalette appPal = QApplication::palette(); |
|
1016 |
QCOMPARE(root->palette(), appPal); |
|
1017 |
QCOMPARE(child0->palette(), appPal); |
|
1018 |
QCOMPARE(child1->palette(), appPal); |
|
1019 |
QCOMPARE(child2->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); |
|
1020 |
QCOMPARE(child2->palette().color(QPalette::Text), sysPalText); |
|
1021 |
QCOMPARE(child2->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1022 |
QCOMPARE(child3->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); |
|
1023 |
QCOMPARE(child3->palette().color(QPalette::Text), sysPalText); |
|
1024 |
QCOMPARE(child3->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1025 |
QCOMPARE(child4->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); |
|
1026 |
QCOMPARE(child4->palette().color(QPalette::Text), sysPalText); |
|
1027 |
QCOMPARE(child4->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1028 |
QCOMPARE(child5->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); |
|
1029 |
QCOMPARE(child5->palette().color(QPalette::Text), sysPalText); |
|
1030 |
QCOMPARE(child5->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1031 |
||
1032 |
// Set child0's Text, and set ToolTipBase on child4. |
|
1033 |
QPalette textPalette; |
|
1034 |
textPalette.setColor(QPalette::Text, overridePalText); |
|
1035 |
child0->setPalette(textPalette); |
|
1036 |
QPalette toolTipPalette; |
|
1037 |
toolTipPalette.setColor(QPalette::ToolTipBase, overridePalToolTipBase); |
|
1038 |
child4->setPalette(toolTipPalette); |
|
1039 |
||
1040 |
// Check that the above settings propagate correctly. |
|
1041 |
QCOMPARE(root->palette(), appPal); |
|
1042 |
QCOMPARE(child0->palette().color(QPalette::Text), overridePalText); |
|
1043 |
QCOMPARE(child0->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); |
|
1044 |
QCOMPARE(child0->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1045 |
QCOMPARE(child1->palette().color(QPalette::Text), overridePalText); |
|
1046 |
QCOMPARE(child1->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); |
|
1047 |
QCOMPARE(child1->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1048 |
QCOMPARE(child2->palette().color(QPalette::Text), overridePalText); |
|
1049 |
QCOMPARE(child2->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); |
|
1050 |
QCOMPARE(child2->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1051 |
QCOMPARE(child3->palette().color(QPalette::Text), overridePalText); |
|
1052 |
QCOMPARE(child3->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); |
|
1053 |
QCOMPARE(child3->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1054 |
QCOMPARE(child4->palette().color(QPalette::Text), overridePalText); |
|
1055 |
QCOMPARE(child4->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); |
|
1056 |
QCOMPARE(child4->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1057 |
QCOMPARE(child5->palette().color(QPalette::Text), overridePalText); |
|
1058 |
QCOMPARE(child5->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); |
|
1059 |
QCOMPARE(child5->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1060 |
||
1061 |
// Replace the app palette for child2. Button should propagate but Text |
|
1062 |
// should still be ignored. The previous ToolTipBase setting is gone. |
|
1063 |
QPalette buttonPalette; |
|
1064 |
buttonPalette.setColor(QPalette::ToolTipText, sysPalButton); |
|
1065 |
qApp->setPalette(buttonPalette, "QPropagationTestWidget"); |
|
1066 |
||
1067 |
// Check that the above settings propagate correctly. |
|
1068 |
QCOMPARE(root->palette(), appPal); |
|
1069 |
QCOMPARE(child0->palette().color(QPalette::Text), overridePalText); |
|
1070 |
QCOMPARE(child0->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); |
|
1071 |
QCOMPARE(child0->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1072 |
QCOMPARE(child1->palette().color(QPalette::Text), overridePalText); |
|
1073 |
QCOMPARE(child1->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); |
|
1074 |
QCOMPARE(child1->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); |
|
1075 |
QCOMPARE(child2->palette().color(QPalette::Text), overridePalText); |
|
1076 |
QCOMPARE(child2->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); |
|
1077 |
QCOMPARE(child2->palette().color(QPalette::ToolTipText), sysPalButton); |
|
1078 |
QCOMPARE(child3->palette().color(QPalette::Text), overridePalText); |
|
1079 |
QCOMPARE(child3->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); |
|
1080 |
QCOMPARE(child3->palette().color(QPalette::ToolTipText), sysPalButton); |
|
1081 |
QCOMPARE(child4->palette().color(QPalette::Text), overridePalText); |
|
1082 |
QCOMPARE(child4->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); |
|
1083 |
QCOMPARE(child4->palette().color(QPalette::ToolTipText), sysPalButton); |
|
1084 |
QCOMPARE(child5->palette().color(QPalette::Text), overridePalText); |
|
1085 |
QCOMPARE(child5->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); |
|
1086 |
QCOMPARE(child5->palette().color(QPalette::ToolTipText), sysPalButton); |
|
1087 |
} |
|
1088 |
||
1089 |
void tst_QWidget::enabledPropagation() |
|
1090 |
{ |
|
1091 |
QWidget* childWidget = new QWidget( testWidget ); |
|
1092 |
childWidget->show(); |
|
1093 |
QVERIFY( testWidget->isEnabled() ); |
|
1094 |
QVERIFY( childWidget->isEnabled() ); |
|
1095 |
||
1096 |
testWidget->setEnabled( FALSE ); |
|
1097 |
QVERIFY( !testWidget->isEnabled() ); |
|
1098 |
QVERIFY( !childWidget->isEnabled() ); |
|
1099 |
||
1100 |
testWidget->setDisabled( FALSE ); |
|
1101 |
QVERIFY( testWidget->isEnabled() ); |
|
1102 |
QVERIFY( childWidget->isEnabled() ); |
|
1103 |
||
1104 |
QWidget* grandChildWidget = new QWidget( childWidget ); |
|
1105 |
QVERIFY( grandChildWidget->isEnabled() ); |
|
1106 |
||
1107 |
testWidget->setDisabled( TRUE ); |
|
1108 |
QVERIFY( !testWidget->isEnabled() ); |
|
1109 |
QVERIFY( !childWidget->isEnabled() ); |
|
1110 |
QVERIFY( !grandChildWidget->isEnabled() ); |
|
1111 |
||
1112 |
grandChildWidget->setEnabled( FALSE ); |
|
1113 |
testWidget->setEnabled( TRUE ); |
|
1114 |
QVERIFY( testWidget->isEnabled() ); |
|
1115 |
QVERIFY( childWidget->isEnabled() ); |
|
1116 |
QVERIFY( !grandChildWidget->isEnabled() ); |
|
1117 |
||
1118 |
grandChildWidget->setEnabled( TRUE ); |
|
1119 |
testWidget->setEnabled( FALSE ); |
|
1120 |
childWidget->setDisabled( TRUE ); |
|
1121 |
testWidget->setEnabled( TRUE ); |
|
1122 |
QVERIFY( testWidget->isEnabled() ); |
|
1123 |
QVERIFY( !childWidget->isEnabled() ); |
|
1124 |
QVERIFY( !grandChildWidget->isEnabled() ); |
|
1125 |
} |
|
1126 |
||
1127 |
void tst_QWidget::acceptDropsPropagation() |
|
1128 |
{ |
|
1129 |
#ifdef QT_NO_DRAGANDDROP |
|
1130 |
QSKIP("Drag'n drop disabled in this build", SkipAll); |
|
1131 |
#else |
|
1132 |
QWidget *childWidget = new QWidget(testWidget); |
|
1133 |
childWidget->show(); |
|
1134 |
QVERIFY(!testWidget->acceptDrops()); |
|
1135 |
QVERIFY(!childWidget->acceptDrops()); |
|
1136 |
||
1137 |
testWidget->setAcceptDrops(true); |
|
1138 |
QVERIFY(testWidget->acceptDrops()); |
|
1139 |
QVERIFY(!childWidget->acceptDrops()); |
|
1140 |
QVERIFY(childWidget->testAttribute(Qt::WA_DropSiteRegistered)); |
|
1141 |
||
1142 |
testWidget->setAcceptDrops(false); |
|
1143 |
QVERIFY(!testWidget->acceptDrops()); |
|
1144 |
QVERIFY(!childWidget->acceptDrops()); |
|
1145 |
QVERIFY(!childWidget->testAttribute(Qt::WA_DropSiteRegistered)); |
|
1146 |
||
1147 |
QWidget *grandChildWidget = new QWidget(childWidget); |
|
1148 |
QVERIFY(!grandChildWidget->acceptDrops()); |
|
1149 |
QVERIFY(!grandChildWidget->testAttribute(Qt::WA_DropSiteRegistered)); |
|
1150 |
||
1151 |
testWidget->setAcceptDrops(true); |
|
1152 |
QVERIFY(testWidget->acceptDrops()); |
|
1153 |
QVERIFY(!childWidget->acceptDrops()); |
|
1154 |
QVERIFY(childWidget->testAttribute(Qt::WA_DropSiteRegistered)); |
|
1155 |
QVERIFY(!grandChildWidget->acceptDrops()); |
|
1156 |
QVERIFY(grandChildWidget->testAttribute(Qt::WA_DropSiteRegistered)); |
|
1157 |
||
1158 |
grandChildWidget->setAcceptDrops(true); |
|
1159 |
testWidget->setAcceptDrops(false); |
|
1160 |
QVERIFY(!testWidget->acceptDrops()); |
|
1161 |
QVERIFY(!childWidget->acceptDrops()); |
|
1162 |
QVERIFY(grandChildWidget->acceptDrops()); |
|
1163 |
QVERIFY(grandChildWidget->testAttribute(Qt::WA_DropSiteRegistered)); |
|
1164 |
||
1165 |
||
1166 |
grandChildWidget->setAcceptDrops(false); |
|
1167 |
QVERIFY(!grandChildWidget->testAttribute(Qt::WA_DropSiteRegistered)); |
|
1168 |
testWidget->setAcceptDrops(true); |
|
1169 |
childWidget->setAcceptDrops(true); |
|
1170 |
testWidget->setAcceptDrops(false); |
|
1171 |
QVERIFY(!testWidget->acceptDrops()); |
|
1172 |
QVERIFY(childWidget->acceptDrops()); |
|
1173 |
QVERIFY(!grandChildWidget->acceptDrops()); |
|
1174 |
QVERIFY(grandChildWidget->testAttribute(Qt::WA_DropSiteRegistered)); |
|
1175 |
#endif |
|
1176 |
} |
|
1177 |
||
1178 |
void tst_QWidget::isEnabledTo() |
|
1179 |
{ |
|
1180 |
QWidget* childWidget = new QWidget( testWidget ); |
|
1181 |
QWidget* grandChildWidget = new QWidget( childWidget ); |
|
1182 |
||
1183 |
QVERIFY( childWidget->isEnabledTo( testWidget ) ); |
|
1184 |
QVERIFY( grandChildWidget->isEnabledTo( testWidget ) ); |
|
1185 |
||
1186 |
childWidget->setEnabled( FALSE ); |
|
1187 |
QVERIFY( !childWidget->isEnabledTo( testWidget ) ); |
|
1188 |
QVERIFY( grandChildWidget->isEnabledTo( childWidget ) ); |
|
1189 |
QVERIFY( !grandChildWidget->isEnabledTo( testWidget ) ); |
|
1190 |
} |
|
1191 |
||
1192 |
void tst_QWidget::visible() |
|
1193 |
{ |
|
1194 |
// Ensure that the testWidget is hidden for this test at the |
|
1195 |
// start |
|
1196 |
||
1197 |
testWidget->hide(); |
|
1198 |
QVERIFY( !testWidget->isVisible() ); |
|
1199 |
QWidget* childWidget = new QWidget( testWidget ); |
|
1200 |
QVERIFY( !childWidget->isVisible() ); |
|
1201 |
||
1202 |
testWidget->show(); |
|
1203 |
QVERIFY( testWidget->isVisible() ); |
|
1204 |
QVERIFY( childWidget->isVisible() ); |
|
1205 |
||
1206 |
QWidget* grandChildWidget = new QWidget( childWidget ); |
|
1207 |
QVERIFY( !grandChildWidget->isVisible() ); |
|
1208 |
grandChildWidget->show(); |
|
1209 |
QVERIFY( grandChildWidget->isVisible() ); |
|
1210 |
||
1211 |
grandChildWidget->hide(); |
|
1212 |
testWidget->hide(); |
|
1213 |
testWidget->show(); |
|
1214 |
QVERIFY( !grandChildWidget->isVisible() ); |
|
1215 |
QVERIFY( testWidget->isVisible() ); |
|
1216 |
QVERIFY( childWidget->isVisible() ); |
|
1217 |
||
1218 |
grandChildWidget->show(); |
|
1219 |
childWidget->hide(); |
|
1220 |
testWidget->hide(); |
|
1221 |
testWidget->show(); |
|
1222 |
QVERIFY( testWidget->isVisible() ); |
|
1223 |
QVERIFY( !childWidget->isVisible() ); |
|
1224 |
QVERIFY( !grandChildWidget->isVisible() ); |
|
1225 |
||
1226 |
grandChildWidget->show(); |
|
1227 |
QVERIFY( !grandChildWidget->isVisible() ); |
|
1228 |
} |
|
1229 |
||
1230 |
void tst_QWidget::setLocale() |
|
1231 |
{ |
|
1232 |
QWidget w; |
|
1233 |
QCOMPARE(w.locale(), QLocale()); |
|
1234 |
||
1235 |
w.setLocale(QLocale::Italian); |
|
1236 |
QCOMPARE(w.locale(), QLocale(QLocale::Italian)); |
|
1237 |
||
1238 |
QWidget child1(&w); |
|
1239 |
QCOMPARE(child1.locale(), QLocale(QLocale::Italian)); |
|
1240 |
||
1241 |
w.unsetLocale(); |
|
1242 |
QCOMPARE(w.locale(), QLocale()); |
|
1243 |
QCOMPARE(child1.locale(), QLocale()); |
|
1244 |
||
1245 |
w.setLocale(QLocale::French); |
|
1246 |
QCOMPARE(w.locale(), QLocale(QLocale::French)); |
|
1247 |
QCOMPARE(child1.locale(), QLocale(QLocale::French)); |
|
1248 |
||
1249 |
child1.setLocale(QLocale::Italian); |
|
1250 |
QCOMPARE(w.locale(), QLocale(QLocale::French)); |
|
1251 |
QCOMPARE(child1.locale(), QLocale(QLocale::Italian)); |
|
1252 |
||
1253 |
child1.unsetLocale(); |
|
1254 |
QCOMPARE(w.locale(), QLocale(QLocale::French)); |
|
1255 |
QCOMPARE(child1.locale(), QLocale(QLocale::French)); |
|
1256 |
||
1257 |
QWidget child2; |
|
1258 |
QCOMPARE(child2.locale(), QLocale()); |
|
1259 |
child2.setParent(&w); |
|
1260 |
QCOMPARE(child2.locale(), QLocale(QLocale::French)); |
|
1261 |
} |
|
1262 |
||
1263 |
void tst_QWidget::visible_setWindowOpacity() |
|
1264 |
{ |
|
1265 |
testWidget->hide(); |
|
1266 |
QVERIFY( !testWidget->isVisible() ); |
|
1267 |
testWidget->setWindowOpacity(0.5); |
|
1268 |
#ifdef Q_OS_WIN |
|
1269 |
QVERIFY(::IsWindowVisible(testWidget->winId()) == FALSE); |
|
1270 |
#endif |
|
1271 |
testWidget->setWindowOpacity(1.0); |
|
1272 |
} |
|
1273 |
||
1274 |
void tst_QWidget::isVisibleTo() |
|
1275 |
{ |
|
1276 |
// Ensure that the testWidget is hidden for this test at the |
|
1277 |
// start |
|
1278 |
||
1279 |
testWidget->hide(); |
|
1280 |
QWidget* childWidget = new QWidget( testWidget ); |
|
1281 |
QVERIFY( childWidget->isVisibleTo( testWidget ) ); |
|
1282 |
childWidget->hide(); |
|
1283 |
QVERIFY( !childWidget->isVisibleTo( testWidget ) ); |
|
1284 |
||
1285 |
QWidget* grandChildWidget = new QWidget( childWidget ); |
|
1286 |
QVERIFY( !grandChildWidget->isVisibleTo( testWidget ) ); |
|
1287 |
QVERIFY( grandChildWidget->isVisibleTo( childWidget ) ); |
|
1288 |
||
1289 |
testWidget->show(); |
|
1290 |
childWidget->show(); |
|
1291 |
||
1292 |
QVERIFY( childWidget->isVisibleTo( testWidget ) ); |
|
1293 |
grandChildWidget->hide(); |
|
1294 |
QVERIFY( !grandChildWidget->isVisibleTo( childWidget ) ); |
|
1295 |
QVERIFY( !grandChildWidget->isVisibleTo( testWidget ) ); |
|
1296 |
||
1297 |
} |
|
1298 |
||
1299 |
void tst_QWidget::isHidden() |
|
1300 |
{ |
|
1301 |
// Ensure that the testWidget is hidden for this test at the |
|
1302 |
// start |
|
1303 |
||
1304 |
testWidget->hide(); |
|
1305 |
QVERIFY( testWidget->isHidden() ); |
|
1306 |
QWidget* childWidget = new QWidget( testWidget ); |
|
1307 |
QVERIFY( !childWidget->isHidden() ); |
|
1308 |
||
1309 |
testWidget->show(); |
|
1310 |
QVERIFY( !testWidget->isHidden() ); |
|
1311 |
QVERIFY( !childWidget->isHidden() ); |
|
1312 |
||
1313 |
QWidget* grandChildWidget = new QWidget( childWidget ); |
|
1314 |
QVERIFY( grandChildWidget->isHidden() ); |
|
1315 |
grandChildWidget->show(); |
|
1316 |
QVERIFY( !grandChildWidget->isHidden() ); |
|
1317 |
||
1318 |
grandChildWidget->hide(); |
|
1319 |
testWidget->hide(); |
|
1320 |
testWidget->show(); |
|
1321 |
QVERIFY( grandChildWidget->isHidden() ); |
|
1322 |
QVERIFY( !testWidget->isHidden() ); |
|
1323 |
QVERIFY( !childWidget->isHidden() ); |
|
1324 |
||
1325 |
grandChildWidget->show(); |
|
1326 |
childWidget->hide(); |
|
1327 |
testWidget->hide(); |
|
1328 |
testWidget->show(); |
|
1329 |
QVERIFY( !testWidget->isHidden() ); |
|
1330 |
QVERIFY( childWidget->isHidden() ); |
|
1331 |
QVERIFY( !grandChildWidget->isHidden() ); |
|
1332 |
||
1333 |
grandChildWidget->show(); |
|
1334 |
QVERIFY( !grandChildWidget->isHidden() ); |
|
1335 |
} |
|
1336 |
||
1337 |
void tst_QWidget::fonts() |
|
1338 |
{ |
|
1339 |
// Tests setFont(), ownFont() and unsetFont() |
|
1340 |
QWidget* cleanTestWidget = new QWidget( testWidget ); |
|
1341 |
QFont originalFont = cleanTestWidget->font(); |
|
1342 |
||
1343 |
QVERIFY( !cleanTestWidget->testAttribute(Qt::WA_SetFont) ); |
|
1344 |
cleanTestWidget->setFont(QFont()); |
|
1345 |
QVERIFY( !cleanTestWidget->testAttribute(Qt::WA_SetFont) ); |
|
1346 |
||
1347 |
QFont newFont( "times", 18 ); |
|
1348 |
cleanTestWidget->setFont( newFont ); |
|
1349 |
newFont = newFont.resolve( testWidget->font() ); |
|
1350 |
||
1351 |
QVERIFY( cleanTestWidget->testAttribute(Qt::WA_SetFont) ); |
|
1352 |
QVERIFY( cleanTestWidget->font() == newFont ); |
|
1353 |
||
1354 |
cleanTestWidget->setFont(QFont()); |
|
1355 |
QVERIFY( !cleanTestWidget->testAttribute(Qt::WA_SetFont) ); |
|
1356 |
QVERIFY( cleanTestWidget->font() == originalFont ); |
|
1357 |
} |
|
1358 |
||
1359 |
void tst_QWidget::mapToGlobal() |
|
1360 |
{ |
|
1361 |
#if !defined(QT3_SUPPORT) |
|
1362 |
QSKIP("No Qt3 Support", SkipAll); |
|
1363 |
#else |
|
1364 |
QPoint vis = testWidget->mapToGlobal(QPoint(0,0)); |
|
1365 |
testWidget->hide(); |
|
1366 |
QCOMPARE(testWidget->mapToGlobal(QPoint(0,0)), vis); |
|
1367 |
testWidget->show(); |
|
1368 |
||
1369 |
// test in a layout and witha move |
|
1370 |
Q3HBox * qhb = new Q3HBox(testWidget); |
|
1371 |
QWidget * qw = new QWidget(qhb); |
|
1372 |
qw->move(6,12); |
|
1373 |
QPoint wVis = qw->mapToGlobal(QPoint(0,0)); |
|
1374 |
qw->hide(); |
|
1375 |
QCOMPARE(qw->mapToGlobal(QPoint(0,0)), wVis); |
|
1376 |
delete qhb; |
|
1377 |
#endif // QT3_SUPPORT |
|
1378 |
} |
|
1379 |
||
1380 |
void tst_QWidget::mapFromAndTo_data() |
|
1381 |
{ |
|
1382 |
QTest::addColumn<bool>("windowHidden"); |
|
1383 |
QTest::addColumn<bool>("subWindow1Hidden"); |
|
1384 |
QTest::addColumn<bool>("subWindow2Hidden"); |
|
1385 |
QTest::addColumn<bool>("subSubWindowHidden"); |
|
1386 |
QTest::addColumn<bool>("windowMinimized"); |
|
1387 |
QTest::addColumn<bool>("subWindow1Minimized"); |
|
1388 |
||
1389 |
QTest::newRow("window 1 sub1 1 sub2 1 subsub 1") << false << false << false << false << false << false; |
|
1390 |
QTest::newRow("window 0 sub1 1 sub2 1 subsub 1") << true << false << false << false << false << false; |
|
1391 |
QTest::newRow("window 1 sub1 0 sub2 1 subsub 1") << false << true << false << false << false << false; |
|
1392 |
QTest::newRow("window 0 sub1 0 sub2 1 subsub 1") << true << true << false << false << false << false; |
|
1393 |
QTest::newRow("window 1 sub1 1 sub2 0 subsub 1") << false << false << true << false << false << false; |
|
1394 |
QTest::newRow("window 0 sub1 1 sub2 0 subsub 1") << true << false << true << false << false << false; |
|
1395 |
QTest::newRow("window 1 sub1 0 sub2 0 subsub 1") << false << true << true << false << false << false; |
|
1396 |
QTest::newRow("window 0 sub1 0 sub2 0 subsub 1") << true << true << true << false << false << false; |
|
1397 |
QTest::newRow("window 1 sub1 1 sub2 1 subsub 0") << false << false << false << true << false << false; |
|
1398 |
QTest::newRow("window 0 sub1 1 sub2 1 subsub 0") << true << false << false << true << false << false; |
|
1399 |
QTest::newRow("window 1 sub1 0 sub2 1 subsub 0") << false << true << false << true << false << false; |
|
1400 |
QTest::newRow("window 0 sub1 0 sub2 1 subsub 0") << true << true << false << true << false << false; |
|
1401 |
QTest::newRow("window 1 sub1 1 sub2 0 subsub 0") << false << false << true << true << false << false; |
|
1402 |
QTest::newRow("window 0 sub1 1 sub2 0 subsub 0") << true << false << true << true << false << false; |
|
1403 |
QTest::newRow("window 1 sub1 0 sub2 0 subsub 0") << false << true << true << true << false << false; |
|
1404 |
QTest::newRow("window 0 sub1 0 sub2 0 subsub 0") << true << true << true << true << false << false; |
|
1405 |
QTest::newRow("window 1 sub1 1 sub2 1 subsub 1 windowMinimized") << false << false << false << false << true << false; |
|
1406 |
QTest::newRow("window 0 sub1 1 sub2 1 subsub 1 windowMinimized") << true << false << false << false << true << false; |
|
1407 |
QTest::newRow("window 1 sub1 0 sub2 1 subsub 1 windowMinimized") << false << true << false << false << true << false; |
|
1408 |
QTest::newRow("window 0 sub1 0 sub2 1 subsub 1 windowMinimized") << true << true << false << false << true << false; |
|
1409 |
QTest::newRow("window 1 sub1 1 sub2 0 subsub 1 windowMinimized") << false << false << true << false << true << false; |
|
1410 |
QTest::newRow("window 0 sub1 1 sub2 0 subsub 1 windowMinimized") << true << false << true << false << true << false; |
|
1411 |
QTest::newRow("window 1 sub1 0 sub2 0 subsub 1 windowMinimized") << false << true << true << false << true << false; |
|
1412 |
QTest::newRow("window 0 sub1 0 sub2 0 subsub 1 windowMinimized") << true << true << true << false << true << false; |
|
1413 |
QTest::newRow("window 1 sub1 1 sub2 1 subsub 0 windowMinimized") << false << false << false << true << true << false; |
|
1414 |
QTest::newRow("window 0 sub1 1 sub2 1 subsub 0 windowMinimized") << true << false << false << true << true << false; |
|
1415 |
QTest::newRow("window 1 sub1 0 sub2 1 subsub 0 windowMinimized") << false << true << false << true << true << false; |
|
1416 |
QTest::newRow("window 0 sub1 0 sub2 1 subsub 0 windowMinimized") << true << true << false << true << true << false; |
|
1417 |
QTest::newRow("window 1 sub1 1 sub2 0 subsub 0 windowMinimized") << false << false << true << true << true << false; |
|
1418 |
QTest::newRow("window 0 sub1 1 sub2 0 subsub 0 windowMinimized") << true << false << true << true << true << false; |
|
1419 |
QTest::newRow("window 1 sub1 0 sub2 0 subsub 0 windowMinimized") << false << true << true << true << true << false; |
|
1420 |
QTest::newRow("window 0 sub1 0 sub2 0 subsub 0 windowMinimized") << true << true << true << true << true << false; |
|
1421 |
QTest::newRow("window 1 sub1 1 sub2 1 subsub 1 subWindow1Minimized") << false << false << false << false << false << true; |
|
1422 |
QTest::newRow("window 0 sub1 1 sub2 1 subsub 1 subWindow1Minimized") << true << false << false << false << false << true; |
|
1423 |
QTest::newRow("window 1 sub1 0 sub2 1 subsub 1 subWindow1Minimized") << false << true << false << false << false << true; |
|
1424 |
QTest::newRow("window 0 sub1 0 sub2 1 subsub 1 subWindow1Minimized") << true << true << false << false << false << true; |
|
1425 |
QTest::newRow("window 1 sub1 1 sub2 0 subsub 1 subWindow1Minimized") << false << false << true << false << false << true; |
|
1426 |
QTest::newRow("window 0 sub1 1 sub2 0 subsub 1 subWindow1Minimized") << true << false << true << false << false << true; |
|
1427 |
QTest::newRow("window 1 sub1 0 sub2 0 subsub 1 subWindow1Minimized") << false << true << true << false << false << true; |
|
1428 |
QTest::newRow("window 0 sub1 0 sub2 0 subsub 1 subWindow1Minimized") << true << true << true << false << false << true; |
|
1429 |
QTest::newRow("window 1 sub1 1 sub2 1 subsub 0 subWindow1Minimized") << false << false << false << true << false << true; |
|
1430 |
QTest::newRow("window 0 sub1 1 sub2 1 subsub 0 subWindow1Minimized") << true << false << false << true << false << true; |
|
1431 |
QTest::newRow("window 1 sub1 0 sub2 1 subsub 0 subWindow1Minimized") << false << true << false << true << false << true; |
|
1432 |
QTest::newRow("window 0 sub1 0 sub2 1 subsub 0 subWindow1Minimized") << true << true << false << true << false << true; |
|
1433 |
QTest::newRow("window 1 sub1 1 sub2 0 subsub 0 subWindow1Minimized") << false << false << true << true << false << true; |
|
1434 |
QTest::newRow("window 0 sub1 1 sub2 0 subsub 0 subWindow1Minimized") << true << false << true << true << false << true; |
|
1435 |
QTest::newRow("window 1 sub1 0 sub2 0 subsub 0 subWindow1Minimized") << false << true << true << true << false << true; |
|
1436 |
QTest::newRow("window 0 sub1 0 sub2 0 subsub 0 subWindow1Minimized") << true << true << true << true << false << true; |
|
1437 |
||
1438 |
||
1439 |
} |
|
1440 |
||
1441 |
void tst_QWidget::mapFromAndTo() |
|
1442 |
{ |
|
1443 |
QFETCH(bool, windowHidden); |
|
1444 |
QFETCH(bool, subWindow1Hidden); |
|
1445 |
QFETCH(bool, subWindow2Hidden); |
|
1446 |
QFETCH(bool, subSubWindowHidden); |
|
1447 |
QFETCH(bool, windowMinimized); |
|
1448 |
QFETCH(bool, subWindow1Minimized); |
|
1449 |
||
1450 |
// create a toplevel and two overlapping siblings |
|
1451 |
QWidget window; |
|
1452 |
window.setWindowFlags(window.windowFlags() | Qt::X11BypassWindowManagerHint); |
|
1453 |
QWidget *subWindow1 = new QWidget(&window); |
|
1454 |
QWidget *subWindow2 = new QWidget(&window); |
|
1455 |
QWidget *subSubWindow = new QWidget(subWindow1); |
|
1456 |
||
1457 |
// set their geometries |
|
1458 |
window.setGeometry(100, 100, 100, 100); |
|
1459 |
subWindow1->setGeometry(50, 50, 100, 100); |
|
1460 |
subWindow2->setGeometry(75, 75, 100, 100); |
|
1461 |
subSubWindow->setGeometry(10, 10, 10, 10); |
|
1462 |
||
1463 |
#if !defined (Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) //still no proper minimizing |
|
1464 |
//update visibility |
|
1465 |
if (windowMinimized) { |
|
1466 |
if (!windowHidden) { |
|
1467 |
window.showMinimized(); |
|
1468 |
QVERIFY(window.isMinimized()); |
|
1469 |
} |
|
1470 |
} else { |
|
1471 |
window.setVisible(!windowHidden); |
|
1472 |
} |
|
1473 |
if (subWindow1Minimized) { |
|
1474 |
subWindow1->hide(); |
|
1475 |
subWindow1->showMinimized(); |
|
1476 |
QVERIFY(subWindow1->isMinimized()); |
|
1477 |
} else { |
|
1478 |
subWindow1->setVisible(!subWindow1Hidden); |
|
1479 |
} |
|
1480 |
#else |
|
1481 |
Q_UNUSED(windowHidden); |
|
1482 |
Q_UNUSED(subWindow1Hidden); |
|
1483 |
Q_UNUSED(windowMinimized); |
|
1484 |
Q_UNUSED(subWindow1Minimized); |
|
1485 |
#endif |
|
1486 |
||
1487 |
subWindow2->setVisible(!subWindow2Hidden); |
|
1488 |
subSubWindow->setVisible(!subSubWindowHidden); |
|
1489 |
||
1490 |
// window |
|
1491 |
QCOMPARE(window.mapToGlobal(QPoint(0, 0)), QPoint(100, 100)); |
|
1492 |
QCOMPARE(window.mapToGlobal(QPoint(10, 0)), QPoint(110, 100)); |
|
1493 |
QCOMPARE(window.mapToGlobal(QPoint(0, 10)), QPoint(100, 110)); |
|
1494 |
QCOMPARE(window.mapToGlobal(QPoint(-10, 0)), QPoint(90, 100)); |
|
1495 |
QCOMPARE(window.mapToGlobal(QPoint(0, -10)), QPoint(100, 90)); |
|
1496 |
QCOMPARE(window.mapToGlobal(QPoint(100, 100)), QPoint(200, 200)); |
|
1497 |
QCOMPARE(window.mapToGlobal(QPoint(110, 100)), QPoint(210, 200)); |
|
1498 |
QCOMPARE(window.mapToGlobal(QPoint(100, 110)), QPoint(200, 210)); |
|
1499 |
QCOMPARE(window.mapFromGlobal(QPoint(100, 100)), QPoint(0, 0)); |
|
1500 |
QCOMPARE(window.mapFromGlobal(QPoint(110, 100)), QPoint(10, 0)); |
|
1501 |
QCOMPARE(window.mapFromGlobal(QPoint(100, 110)), QPoint(0, 10)); |
|
1502 |
QCOMPARE(window.mapFromGlobal(QPoint(90, 100)), QPoint(-10, 0)); |
|
1503 |
QCOMPARE(window.mapFromGlobal(QPoint(100, 90)), QPoint(0, -10)); |
|
1504 |
QCOMPARE(window.mapFromGlobal(QPoint(200, 200)), QPoint(100, 100)); |
|
1505 |
QCOMPARE(window.mapFromGlobal(QPoint(210, 200)), QPoint(110, 100)); |
|
1506 |
QCOMPARE(window.mapFromGlobal(QPoint(200, 210)), QPoint(100, 110)); |
|
1507 |
QCOMPARE(window.mapToParent(QPoint(0, 0)), QPoint(100, 100)); |
|
1508 |
QCOMPARE(window.mapToParent(QPoint(10, 0)), QPoint(110, 100)); |
|
1509 |
QCOMPARE(window.mapToParent(QPoint(0, 10)), QPoint(100, 110)); |
|
1510 |
QCOMPARE(window.mapToParent(QPoint(-10, 0)), QPoint(90, 100)); |
|
1511 |
QCOMPARE(window.mapToParent(QPoint(0, -10)), QPoint(100, 90)); |
|
1512 |
QCOMPARE(window.mapToParent(QPoint(100, 100)), QPoint(200, 200)); |
|
1513 |
QCOMPARE(window.mapToParent(QPoint(110, 100)), QPoint(210, 200)); |
|
1514 |
QCOMPARE(window.mapToParent(QPoint(100, 110)), QPoint(200, 210)); |
|
1515 |
QCOMPARE(window.mapFromParent(QPoint(100, 100)), QPoint(0, 0)); |
|
1516 |
QCOMPARE(window.mapFromParent(QPoint(110, 100)), QPoint(10, 0)); |
|
1517 |
QCOMPARE(window.mapFromParent(QPoint(100, 110)), QPoint(0, 10)); |
|
1518 |
QCOMPARE(window.mapFromParent(QPoint(90, 100)), QPoint(-10, 0)); |
|
1519 |
QCOMPARE(window.mapFromParent(QPoint(100, 90)), QPoint(0, -10)); |
|
1520 |
QCOMPARE(window.mapFromParent(QPoint(200, 200)), QPoint(100, 100)); |
|
1521 |
QCOMPARE(window.mapFromParent(QPoint(210, 200)), QPoint(110, 100)); |
|
1522 |
QCOMPARE(window.mapFromParent(QPoint(200, 210)), QPoint(100, 110)); |
|
1523 |
||
1524 |
// first subwindow |
|
1525 |
QCOMPARE(subWindow1->mapToGlobal(QPoint(0, 0)), QPoint(150, 150)); |
|
1526 |
QCOMPARE(subWindow1->mapToGlobal(QPoint(10, 0)), QPoint(160, 150)); |
|
1527 |
QCOMPARE(subWindow1->mapToGlobal(QPoint(0, 10)), QPoint(150, 160)); |
|
1528 |
QCOMPARE(subWindow1->mapToGlobal(QPoint(-10, 0)), QPoint(140, 150)); |
|
1529 |
QCOMPARE(subWindow1->mapToGlobal(QPoint(0, -10)), QPoint(150, 140)); |
|
1530 |
QCOMPARE(subWindow1->mapToGlobal(QPoint(100, 100)), QPoint(250, 250)); |
|
1531 |
QCOMPARE(subWindow1->mapToGlobal(QPoint(110, 100)), QPoint(260, 250)); |
|
1532 |
QCOMPARE(subWindow1->mapToGlobal(QPoint(100, 110)), QPoint(250, 260)); |
|
1533 |
QCOMPARE(subWindow1->mapFromGlobal(QPoint(150, 150)), QPoint(0, 0)); |
|
1534 |
QCOMPARE(subWindow1->mapFromGlobal(QPoint(160, 150)), QPoint(10, 0)); |
|
1535 |
QCOMPARE(subWindow1->mapFromGlobal(QPoint(150, 160)), QPoint(0, 10)); |
|
1536 |
QCOMPARE(subWindow1->mapFromGlobal(QPoint(140, 150)), QPoint(-10, 0)); |
|
1537 |
QCOMPARE(subWindow1->mapFromGlobal(QPoint(150, 140)), QPoint(0, -10)); |
|
1538 |
QCOMPARE(subWindow1->mapFromGlobal(QPoint(250, 250)), QPoint(100, 100)); |
|
1539 |
QCOMPARE(subWindow1->mapFromGlobal(QPoint(260, 250)), QPoint(110, 100)); |
|
1540 |
QCOMPARE(subWindow1->mapFromGlobal(QPoint(250, 260)), QPoint(100, 110)); |
|
1541 |
QCOMPARE(subWindow1->mapToParent(QPoint(0, 0)), QPoint(50, 50)); |
|
1542 |
QCOMPARE(subWindow1->mapToParent(QPoint(10, 0)), QPoint(60, 50)); |
|
1543 |
QCOMPARE(subWindow1->mapToParent(QPoint(0, 10)), QPoint(50, 60)); |
|
1544 |
QCOMPARE(subWindow1->mapToParent(QPoint(-10, 0)), QPoint(40, 50)); |
|
1545 |
QCOMPARE(subWindow1->mapToParent(QPoint(0, -10)), QPoint(50, 40)); |
|
1546 |
QCOMPARE(subWindow1->mapToParent(QPoint(100, 100)), QPoint(150, 150)); |
|
1547 |
QCOMPARE(subWindow1->mapToParent(QPoint(110, 100)), QPoint(160, 150)); |
|
1548 |
QCOMPARE(subWindow1->mapToParent(QPoint(100, 110)), QPoint(150, 160)); |
|
1549 |
QCOMPARE(subWindow1->mapFromParent(QPoint(50, 50)), QPoint(0, 0)); |
|
1550 |
QCOMPARE(subWindow1->mapFromParent(QPoint(60, 50)), QPoint(10, 0)); |
|
1551 |
QCOMPARE(subWindow1->mapFromParent(QPoint(50, 60)), QPoint(0, 10)); |
|
1552 |
QCOMPARE(subWindow1->mapFromParent(QPoint(40, 50)), QPoint(-10, 0)); |
|
1553 |
QCOMPARE(subWindow1->mapFromParent(QPoint(50, 40)), QPoint(0, -10)); |
|
1554 |
QCOMPARE(subWindow1->mapFromParent(QPoint(150, 150)), QPoint(100, 100)); |
|
1555 |
QCOMPARE(subWindow1->mapFromParent(QPoint(160, 150)), QPoint(110, 100)); |
|
1556 |
QCOMPARE(subWindow1->mapFromParent(QPoint(150, 160)), QPoint(100, 110)); |
|
1557 |
||
1558 |
// subsubwindow |
|
1559 |
QCOMPARE(subSubWindow->mapToGlobal(QPoint(0, 0)), QPoint(160, 160)); |
|
1560 |
QCOMPARE(subSubWindow->mapToGlobal(QPoint(10, 0)), QPoint(170, 160)); |
|
1561 |
QCOMPARE(subSubWindow->mapToGlobal(QPoint(0, 10)), QPoint(160, 170)); |
|
1562 |
QCOMPARE(subSubWindow->mapToGlobal(QPoint(-10, 0)), QPoint(150, 160)); |
|
1563 |
QCOMPARE(subSubWindow->mapToGlobal(QPoint(0, -10)), QPoint(160, 150)); |
|
1564 |
QCOMPARE(subSubWindow->mapToGlobal(QPoint(100, 100)), QPoint(260, 260)); |
|
1565 |
QCOMPARE(subSubWindow->mapToGlobal(QPoint(110, 100)), QPoint(270, 260)); |
|
1566 |
QCOMPARE(subSubWindow->mapToGlobal(QPoint(100, 110)), QPoint(260, 270)); |
|
1567 |
QCOMPARE(subSubWindow->mapFromGlobal(QPoint(160, 160)), QPoint(0, 0)); |
|
1568 |
QCOMPARE(subSubWindow->mapFromGlobal(QPoint(170, 160)), QPoint(10, 0)); |
|
1569 |
QCOMPARE(subSubWindow->mapFromGlobal(QPoint(160, 170)), QPoint(0, 10)); |
|
1570 |
QCOMPARE(subSubWindow->mapFromGlobal(QPoint(150, 160)), QPoint(-10, 0)); |
|
1571 |
QCOMPARE(subSubWindow->mapFromGlobal(QPoint(160, 150)), QPoint(0, -10)); |
|
1572 |
QCOMPARE(subSubWindow->mapFromGlobal(QPoint(260, 260)), QPoint(100, 100)); |
|
1573 |
QCOMPARE(subSubWindow->mapFromGlobal(QPoint(270, 260)), QPoint(110, 100)); |
|
1574 |
QCOMPARE(subSubWindow->mapFromGlobal(QPoint(260, 270)), QPoint(100, 110)); |
|
1575 |
QCOMPARE(subSubWindow->mapToParent(QPoint(0, 0)), QPoint(10, 10)); |
|
1576 |
QCOMPARE(subSubWindow->mapToParent(QPoint(10, 0)), QPoint(20, 10)); |
|
1577 |
QCOMPARE(subSubWindow->mapToParent(QPoint(0, 10)), QPoint(10, 20)); |
|
1578 |
QCOMPARE(subSubWindow->mapToParent(QPoint(-10, 0)), QPoint(0, 10)); |
|
1579 |
QCOMPARE(subSubWindow->mapToParent(QPoint(0, -10)), QPoint(10, 0)); |
|
1580 |
QCOMPARE(subSubWindow->mapToParent(QPoint(100, 100)), QPoint(110, 110)); |
|
1581 |
QCOMPARE(subSubWindow->mapToParent(QPoint(110, 100)), QPoint(120, 110)); |
|
1582 |
QCOMPARE(subSubWindow->mapToParent(QPoint(100, 110)), QPoint(110, 120)); |
|
1583 |
QCOMPARE(subSubWindow->mapFromParent(QPoint(10, 10)), QPoint(0, 0)); |
|
1584 |
QCOMPARE(subSubWindow->mapFromParent(QPoint(20, 10)), QPoint(10, 0)); |
|
1585 |
QCOMPARE(subSubWindow->mapFromParent(QPoint(10, 20)), QPoint(0, 10)); |
|
1586 |
QCOMPARE(subSubWindow->mapFromParent(QPoint(0, 10)), QPoint(-10, 0)); |
|
1587 |
QCOMPARE(subSubWindow->mapFromParent(QPoint(10, 0)), QPoint(0, -10)); |
|
1588 |
QCOMPARE(subSubWindow->mapFromParent(QPoint(110, 110)), QPoint(100, 100)); |
|
1589 |
QCOMPARE(subSubWindow->mapFromParent(QPoint(120, 110)), QPoint(110, 100)); |
|
1590 |
QCOMPARE(subSubWindow->mapFromParent(QPoint(110, 120)), QPoint(100, 110)); |
|
1591 |
} |
|
1592 |
||
1593 |
void tst_QWidget::focusChainOnReparent() |
|
1594 |
{ |
|
1595 |
QWidget window; |
|
1596 |
QWidget *child1 = new QWidget(&window); |
|
1597 |
QWidget *child2 = new QWidget(&window); |
|
1598 |
QWidget *child3 = new QWidget(&window); |
|
1599 |
QWidget *child21 = new QWidget(child2); |
|
1600 |
QWidget *child22 = new QWidget(child2); |
|
1601 |
QWidget *child4 = new QWidget(&window); |
|
1602 |
||
1603 |
QWidget *expectedOriginalChain[8] = {&window, child1, child2, child3, child21, child22, child4, &window}; |
|
1604 |
QWidget *w = &window; |
|
1605 |
for (int i = 0; i <8; ++i) { |
|
1606 |
QCOMPARE(w, expectedOriginalChain[i]); |
|
1607 |
w = w->nextInFocusChain(); |
|
1608 |
} |
|
1609 |
for (int i = 7; i >= 0; --i) { |
|
1610 |
w = w->previousInFocusChain(); |
|
1611 |
QCOMPARE(w, expectedOriginalChain[i]); |
|
1612 |
} |
|
1613 |
||
1614 |
QWidget window2; |
|
1615 |
child2->setParent(&window2); |
|
1616 |
||
1617 |
QWidget *expectedNewChain[5] = {&window2, child2, child21, child22, &window2}; |
|
1618 |
w = &window2; |
|
1619 |
for (int i = 0; i <5; ++i) { |
|
1620 |
QCOMPARE(w, expectedNewChain[i]); |
|
1621 |
w = w->nextInFocusChain(); |
|
1622 |
} |
|
1623 |
for (int i = 4; i >= 0; --i) { |
|
1624 |
w = w->previousInFocusChain(); |
|
1625 |
QCOMPARE(w, expectedNewChain[i]); |
|
1626 |
} |
|
1627 |
||
1628 |
QWidget *expectedOldChain[5] = {&window, child1, child3, child4, &window}; |
|
1629 |
w = &window; |
|
1630 |
for (int i = 0; i <5; ++i) { |
|
1631 |
QCOMPARE(w, expectedOldChain[i]); |
|
1632 |
w = w->nextInFocusChain(); |
|
1633 |
} |
|
1634 |
for (int i = 4; i >= 0; --i) { |
|
1635 |
w = w->previousInFocusChain(); |
|
1636 |
QCOMPARE(w, expectedOldChain[i]); |
|
1637 |
} |
|
1638 |
} |
|
1639 |
||
1640 |
||
1641 |
void tst_QWidget::focusChainOnHide() |
|
1642 |
{ |
|
1643 |
testWidget->hide(); // We do not want to get disturbed by other widgets |
|
1644 |
// focus should move to the next widget in the focus chain when we hide it. |
|
1645 |
QWidget *parent = new QWidget(); |
|
1646 |
parent->setObjectName(QLatin1String("Parent")); |
|
1647 |
parent->setFocusPolicy(Qt::StrongFocus); |
|
1648 |
QWidget *child = new QWidget(parent); |
|
1649 |
child->setObjectName(QLatin1String("child")); |
|
1650 |
child->setFocusPolicy(Qt::StrongFocus); |
|
1651 |
QWidget::setTabOrder(child, parent); |
|
1652 |
||
1653 |
parent->show(); |
|
1654 |
qApp->setActiveWindow(parent->window()); |
|
1655 |
child->activateWindow(); |
|
1656 |
child->setFocus(); |
|
1657 |
qApp->processEvents(); |
|
1658 |
||
1659 |
WAIT_FOR_CONDITION(child->hasFocus(), true); |
|
1660 |
QCOMPARE(child->hasFocus(), true); |
|
1661 |
child->hide(); |
|
1662 |
qApp->processEvents(); |
|
1663 |
||
1664 |
WAIT_FOR_CONDITION(parent->hasFocus(), true); |
|
1665 |
QCOMPARE(parent->hasFocus(), true); |
|
1666 |
QCOMPARE(parent, qApp->focusWidget()); |
|
1667 |
||
1668 |
delete parent; |
|
1669 |
testWidget->show(); //don't disturb later tests |
|
1670 |
} |
|
1671 |
||
1672 |
void tst_QWidget::checkFocus() |
|
1673 |
{ |
|
1674 |
#if !defined(QT3_SUPPORT) |
|
1675 |
QSKIP("No Qt3 Support", SkipAll); |
|
1676 |
#else |
|
1677 |
// This is a very specific test for a specific bug, the bug was |
|
1678 |
// that when setEnabled(FALSE) then setEnabled(TRUE) was called on |
|
1679 |
// the parent of a child widget which had focus while hidden, then |
|
1680 |
// when the widget was shown, the focus would be in the wrong place. |
|
1681 |
||
1682 |
Q3HBox widget; |
|
1683 |
QLineEdit *focusWidget = new QLineEdit( &widget ); |
|
1684 |
new QLineEdit( &widget ); |
|
1685 |
new QPushButton( &widget ); |
|
1686 |
focusWidget->setFocus(); |
|
1687 |
widget.setEnabled( FALSE ); |
|
1688 |
widget.setEnabled( TRUE ); |
|
1689 |
widget.show(); |
|
1690 |
#ifdef Q_WS_X11 |
|
1691 |
qt_x11_wait_for_window_manager(&widget); |
|
1692 |
#endif |
|
1693 |
QTest::qWait( 100 ); |
|
1694 |
widget.activateWindow(); |
|
1695 |
// next call is necessary since the window manager may not give the focus to the widget when |
|
1696 |
// it is shown, which causes the QVERIFY to fail |
|
1697 |
QApplication::setActiveWindow(&widget); |
|
1698 |
QVERIFY( qApp->focusWidget() == focusWidget ); |
|
1699 |
#endif // QT3_SUPPORT |
|
1700 |
} |
|
1701 |
||
1702 |
class Container : public QWidget |
|
1703 |
{ |
|
1704 |
public: |
|
1705 |
QVBoxLayout* box; |
|
1706 |
||
1707 |
Container() |
|
1708 |
{ |
|
1709 |
box = new QVBoxLayout(this); |
|
1710 |
//(new QVBoxLayout(this))->setAutoAdd(true); |
|
1711 |
} |
|
1712 |
||
1713 |
void tab() |
|
1714 |
{ |
|
1715 |
focusNextPrevChild(TRUE); |
|
1716 |
} |
|
1717 |
||
1718 |
void backTab() |
|
1719 |
{ |
|
1720 |
focusNextPrevChild(FALSE); |
|
1721 |
} |
|
1722 |
}; |
|
1723 |
||
1724 |
class Composite : public QFrame |
|
1725 |
{ |
|
1726 |
public: |
|
1727 |
Composite(QWidget* parent = 0, const char* name = 0) |
|
1728 |
: QFrame(parent) |
|
1729 |
{ |
|
1730 |
setObjectName(name); |
|
1731 |
//QHBoxLayout* hbox = new QHBoxLayout(this, 2, 0); |
|
1732 |
//hbox->setAutoAdd(true); |
|
1733 |
QHBoxLayout* hbox = new QHBoxLayout(this); |
|
1734 |
||
1735 |
lineEdit = new QLineEdit(this); |
|
1736 |
hbox->addWidget(lineEdit); |
|
1737 |
||
1738 |
button = new QPushButton(this); |
|
1739 |
hbox->addWidget(button); |
|
1740 |
button->setFocusPolicy( Qt::NoFocus ); |
|
1741 |
||
1742 |
setFocusProxy( lineEdit ); |
|
1743 |
setFocusPolicy( Qt::StrongFocus ); |
|
1744 |
||
1745 |
setTabOrder(lineEdit, button); |
|
1746 |
} |
|
1747 |
||
1748 |
private: |
|
1749 |
QLineEdit* lineEdit; |
|
1750 |
QPushButton* button; |
|
1751 |
}; |
|
1752 |
||
1753 |
#define NUM_WIDGETS 4 |
|
1754 |
||
1755 |
void tst_QWidget::setTabOrder() |
|
1756 |
{ |
|
1757 |
QTest::qWait(100); |
|
1758 |
||
1759 |
Container container; |
|
1760 |
||
1761 |
Composite* comp[NUM_WIDGETS]; |
|
1762 |
||
1763 |
QLineEdit *firstEdit = new QLineEdit(&container); |
|
1764 |
container.box->addWidget(firstEdit); |
|
1765 |
||
1766 |
int i = 0; |
|
1767 |
for(i = 0; i < NUM_WIDGETS; i++) { |
|
1768 |
comp[i] = new Composite(&container); |
|
1769 |
container.box->addWidget(comp[i]); |
|
1770 |
} |
|
1771 |
||
1772 |
QLineEdit *lastEdit = new QLineEdit(&container); |
|
1773 |
container.box->addWidget(lastEdit); |
|
1774 |
||
1775 |
container.setTabOrder(lastEdit, comp[NUM_WIDGETS-1]); |
|
1776 |
for(i = NUM_WIDGETS-1; i > 0; i--) { |
|
1777 |
container.setTabOrder(comp[i], comp[i-1]); |
|
1778 |
} |
|
1779 |
container.setTabOrder(comp[0], firstEdit); |
|
1780 |
||
1781 |
int current = NUM_WIDGETS-1; |
|
1782 |
lastEdit->setFocus(); |
|
1783 |
||
1784 |
container.show(); |
|
1785 |
container.activateWindow(); |
|
1786 |
qApp->setActiveWindow(&container); |
|
1787 |
#ifdef Q_WS_X11 |
|
1788 |
QTest::qWaitForWindowShown(&container); |
|
1789 |
QTest::qWait(50); |
|
1790 |
#endif |
|
1791 |
||
1792 |
QTest::qWait(100); |
|
1793 |
||
1794 |
QTRY_VERIFY(lastEdit->hasFocus()); |
|
1795 |
container.tab(); |
|
1796 |
do { |
|
1797 |
QVERIFY(comp[current]->focusProxy()->hasFocus()); |
|
1798 |
container.tab(); |
|
1799 |
current--; |
|
1800 |
} while (current >= 0); |
|
1801 |
||
1802 |
QVERIFY(firstEdit->hasFocus()); |
|
1803 |
} |
|
1804 |
||
1805 |
void tst_QWidget::activation() |
|
1806 |
{ |
|
1807 |
#if !defined(Q_WS_WIN) |
|
1808 |
QSKIP("This test is Windows-only.", SkipAll); |
|
1809 |
#endif |
|
1810 |
Q_CHECK_PAINTEVENTS |
|
1811 |
||
1812 |
#if defined(Q_OS_WINCE) |
|
1813 |
int waitTime = 1000; |
|
1814 |
#else |
|
1815 |
int waitTime = 100; |
|
1816 |
#endif |
|
1817 |
||
1818 |
#ifdef Q_OS_WINCE |
|
1819 |
qApp->processEvents(); |
|
1820 |
#endif |
|
1821 |
QWidget widget1; |
|
1822 |
widget1.setWindowTitle("Widget1"); |
|
1823 |
||
1824 |
QWidget widget2; |
|
1825 |
widget2.setWindowTitle("Widget2"); |
|
1826 |
||
1827 |
widget1.show(); |
|
1828 |
widget2.show(); |
|
1829 |
||
1830 |
QTest::qWait(waitTime); |
|
1831 |
QVERIFY(qApp->activeWindow() == &widget2); |
|
1832 |
widget2.showMinimized(); |
|
1833 |
QTest::qWait(waitTime); |
|
1834 |
||
1835 |
QVERIFY(qApp->activeWindow() == &widget1); |
|
1836 |
widget2.showMaximized(); |
|
1837 |
QTest::qWait(waitTime); |
|
1838 |
QVERIFY(qApp->activeWindow() == &widget2); |
|
1839 |
widget2.showMinimized(); |
|
1840 |
QTest::qWait(waitTime); |
|
1841 |
QVERIFY(qApp->activeWindow() == &widget1); |
|
1842 |
widget2.showNormal(); |
|
1843 |
QTest::qWait(waitTime); |
|
1844 |
#if defined(Q_WS_WIN) && !defined(Q_OS_WINCE) |
|
1845 |
if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA) |
|
1846 |
QEXPECT_FAIL("", "MS introduced new behavior after XP", Continue); |
|
1847 |
#endif |
|
1848 |
QTest::qWait(waitTime); |
|
1849 |
QVERIFY(qApp->activeWindow() == &widget2); |
|
1850 |
widget2.hide(); |
|
1851 |
QTest::qWait(waitTime); |
|
1852 |
QVERIFY(qApp->activeWindow() == &widget1); |
|
1853 |
} |
|
1854 |
||
1855 |
void tst_QWidget::windowState() |
|
1856 |
{ |
|
1857 |
#ifdef Q_WS_X11 |
|
1858 |
QSKIP("Many window managers do not support window state properly, which causes this " |
|
1859 |
"test to fail.", SkipAll); |
|
1860 |
#else |
|
1861 |
#ifdef Q_OS_WINCE_WM |
|
1862 |
QPoint pos(500, 500); |
|
1863 |
QSize size(200, 200); |
|
1864 |
if (qt_wince_is_smartphone()) { //small screen |
|
1865 |
pos = QPoint(10,10); |
|
1866 |
size = QSize(100,100); |
|
1867 |
} |
|
1868 |
#elif defined(Q_WS_S60) |
|
1869 |
QPoint pos = QPoint(10,10); |
|
1870 |
QSize size = QSize(100,100); |
|
1871 |
#else |
|
1872 |
const QPoint pos(500, 500); |
|
1873 |
const QSize size(200, 200); |
|
1874 |
#endif |
|
1875 |
||
1876 |
QWidget widget1; |
|
1877 |
widget1.move(pos); |
|
1878 |
widget1.resize(size); |
|
1879 |
QCOMPARE(widget1.pos(), pos); |
|
1880 |
QCOMPARE(widget1.size(), size); |
|
1881 |
QTest::qWait(100); |
|
1882 |
widget1.setWindowTitle("Widget1"); |
|
1883 |
QCOMPARE(widget1.pos(), pos); |
|
1884 |
QCOMPARE(widget1.size(), size); |
|
1885 |
||
1886 |
#define VERIFY_STATE(s) QCOMPARE(int(widget1.windowState() & stateMask), int(s)) |
|
1887 |
||
1888 |
const int stateMask = Qt::WindowMaximized|Qt::WindowMinimized|Qt::WindowFullScreen; |
|
1889 |
||
1890 |
widget1.setWindowState(Qt::WindowMaximized); |
|
1891 |
QTest::qWait(100); |
|
1892 |
VERIFY_STATE(Qt::WindowMaximized); |
|
1893 |
||
1894 |
widget1.show(); |
|
1895 |
QTest::qWait(100); |
|
1896 |
VERIFY_STATE(Qt::WindowMaximized); |
|
1897 |
||
1898 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMaximized); |
|
1899 |
QTest::qWait(100); |
|
1900 |
QVERIFY(!(widget1.windowState() & Qt::WindowMaximized)); |
|
1901 |
QCOMPARE(widget1.pos(), pos); |
|
1902 |
||
1903 |
widget1.setWindowState(Qt::WindowMinimized); |
|
1904 |
QTest::qWait(100); |
|
1905 |
VERIFY_STATE(Qt::WindowMinimized); |
|
1906 |
||
1907 |
widget1.setWindowState(widget1.windowState() | Qt::WindowMaximized); |
|
1908 |
QTest::qWait(100); |
|
1909 |
VERIFY_STATE((Qt::WindowMinimized|Qt::WindowMaximized)); |
|
1910 |
||
1911 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMinimized); |
|
1912 |
QTest::qWait(100); |
|
1913 |
VERIFY_STATE(Qt::WindowMaximized); |
|
1914 |
||
1915 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMaximized); |
|
1916 |
QTest::qWait(100); |
|
1917 |
QVERIFY(!(widget1.windowState() & (Qt::WindowMinimized|Qt::WindowMaximized))); |
|
1918 |
QCOMPARE(widget1.pos(), pos); |
|
1919 |
||
1920 |
widget1.setWindowState(Qt::WindowFullScreen); |
|
1921 |
QTest::qWait(100); |
|
1922 |
VERIFY_STATE(Qt::WindowFullScreen); |
|
1923 |
||
1924 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMinimized); |
|
1925 |
QTest::qWait(100); |
|
1926 |
VERIFY_STATE((Qt::WindowFullScreen|Qt::WindowMinimized)); |
|
1927 |
||
1928 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMinimized); |
|
1929 |
QTest::qWait(100); |
|
1930 |
VERIFY_STATE(Qt::WindowFullScreen); |
|
1931 |
||
1932 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMaximized); |
|
1933 |
QTest::qWait(100); |
|
1934 |
VERIFY_STATE((Qt::WindowFullScreen|Qt::WindowMaximized)); |
|
1935 |
||
1936 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMinimized); |
|
1937 |
QTest::qWait(100); |
|
1938 |
VERIFY_STATE((Qt::WindowFullScreen|Qt::WindowMaximized|Qt::WindowMinimized)); |
|
1939 |
||
1940 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMinimized); |
|
1941 |
QTest::qWait(100); |
|
1942 |
VERIFY_STATE((Qt::WindowFullScreen|Qt::WindowMaximized)); |
|
1943 |
||
1944 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowFullScreen); |
|
1945 |
QTest::qWait(100); |
|
1946 |
VERIFY_STATE(Qt::WindowMaximized); |
|
1947 |
||
1948 |
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMaximized); |
|
1949 |
QTest::qWait(100); |
|
1950 |
QVERIFY(!(widget1.windowState() & stateMask)); |
|
1951 |
||
1952 |
QCOMPARE(widget1.pos(), pos); |
|
1953 |
QCOMPARE(widget1.size(), size); |
|
1954 |
#endif |
|
1955 |
} |
|
1956 |
||
1957 |
void tst_QWidget::showMaximized() |
|
1958 |
{ |
|
1959 |
QWidget plain; |
|
1960 |
QHBoxLayout *layout; |
|
1961 |
layout = new QHBoxLayout; |
|
1962 |
QWidget layouted; |
|
1963 |
QLineEdit le; |
|
1964 |
QLineEdit le2; |
|
1965 |
QLineEdit le3; |
|
1966 |
||
1967 |
layout->addWidget(&le); |
|
1968 |
layout->addWidget(&le2); |
|
1969 |
layout->addWidget(&le3); |
|
1970 |
||
1971 |
layouted.setLayout(layout); |
|
1972 |
||
1973 |
plain.showMaximized(); |
|
1974 |
QVERIFY(plain.windowState() & Qt::WindowMaximized); |
|
1975 |
||
1976 |
plain.showNormal(); |
|
1977 |
QVERIFY(!(plain.windowState() & Qt::WindowMaximized)); |
|
1978 |
||
1979 |
layouted.showMaximized(); |
|
1980 |
QVERIFY(layouted.windowState() & Qt::WindowMaximized); |
|
1981 |
||
1982 |
layouted.showNormal(); |
|
1983 |
QVERIFY(!(layouted.windowState() & Qt::WindowMaximized)); |
|
1984 |
||
1985 |
#if !defined(Q_WS_QWS) && !defined(Q_OS_WINCE) && !defined(Q_WS_S60) |
|
1986 |
//embedded may choose a different size to fit on the screen. |
|
1987 |
QCOMPARE(layouted.size(), layouted.sizeHint()); |
|
1988 |
#endif |
|
1989 |
layouted.showMaximized(); |
|
1990 |
QVERIFY(layouted.isMaximized()); |
|
1991 |
QVERIFY(layouted.isVisible()); |
|
1992 |
||
1993 |
layouted.hide(); |
|
1994 |
QVERIFY(layouted.isMaximized()); |
|
1995 |
QVERIFY(!layouted.isVisible()); |
|
1996 |
||
1997 |
layouted.showMaximized(); |
|
1998 |
QVERIFY(layouted.isMaximized()); |
|
1999 |
QVERIFY(layouted.isVisible()); |
|
2000 |
||
2001 |
layouted.showMinimized(); |
|
2002 |
QVERIFY(layouted.isMinimized()); |
|
2003 |
QVERIFY(layouted.isMaximized()); |
|
2004 |
||
2005 |
layouted.showMaximized(); |
|
2006 |
QVERIFY(!layouted.isMinimized()); |
|
2007 |
QVERIFY(layouted.isMaximized()); |
|
2008 |
QVERIFY(layouted.isVisible()); |
|
2009 |
||
2010 |
layouted.showMinimized(); |
|
2011 |
QVERIFY(layouted.isMinimized()); |
|
2012 |
QVERIFY(layouted.isMaximized()); |
|
2013 |
||
2014 |
layouted.showMaximized(); |
|
2015 |
QVERIFY(!layouted.isMinimized()); |
|
2016 |
QVERIFY(layouted.isMaximized()); |
|
2017 |
QVERIFY(layouted.isVisible()); |
|
2018 |
||
2019 |
{ |
|
2020 |
QWidget frame; |
|
2021 |
QWidget widget(&frame); |
|
2022 |
widget.showMaximized(); |
|
2023 |
QVERIFY(widget.isMaximized()); |
|
2024 |
} |
|
2025 |
||
2026 |
{ |
|
2027 |
QWidget widget; |
|
2028 |
widget.setGeometry(0, 0, 10, 10); |
|
2029 |
widget.showMaximized(); |
|
2030 |
QTRY_VERIFY(widget.size().width() > 20 && widget.size().height() > 20); |
|
2031 |
} |
|
2032 |
||
2033 |
#ifdef QT3_SUPPORT |
|
2034 |
#if !defined(Q_WS_QWS) |
|
2035 |
//embedded respects max/min sizes by design -- maybe wrong design, but that's the way it is now. |
|
2036 |
{ |
|
2037 |
Q3HBox box; |
|
2038 |
QWidget widget(&box); |
|
2039 |
widget.setMinimumSize(500, 500); |
|
2040 |
box.showMaximized(); |
|
2041 |
QVERIFY(box.isMaximized()); |
|
2042 |
} |
|
2043 |
||
2044 |
{ |
|
2045 |
Q3HBox box; |
|
2046 |
QWidget widget(&box); |
|
2047 |
widget.setMaximumSize(500, 500); |
|
2048 |
||
2049 |
box.showMaximized(); |
|
2050 |
QVERIFY(box.isMaximized()); |
|
2051 |
} |
|
2052 |
#endif |
|
2053 |
#endif // QT3_SUPPORT |
|
2054 |
} |
|
2055 |
||
2056 |
void tst_QWidget::showFullScreen() |
|
2057 |
{ |
|
2058 |
QWidget plain; |
|
2059 |
QHBoxLayout *layout; |
|
2060 |
QWidget layouted; |
|
2061 |
QLineEdit le; |
|
2062 |
QLineEdit le2; |
|
2063 |
QLineEdit le3; |
|
2064 |
layout = new QHBoxLayout; |
|
2065 |
||
2066 |
layout->addWidget(&le); |
|
2067 |
layout->addWidget(&le2); |
|
2068 |
layout->addWidget(&le3); |
|
2069 |
||
2070 |
layouted.setLayout(layout); |
|
2071 |
||
2072 |
plain.showFullScreen(); |
|
2073 |
QVERIFY(plain.windowState() & Qt::WindowFullScreen); |
|
2074 |
||
2075 |
plain.showNormal(); |
|
2076 |
QVERIFY(!(plain.windowState() & Qt::WindowFullScreen)); |
|
2077 |
||
2078 |
layouted.showFullScreen(); |
|
2079 |
QVERIFY(layouted.windowState() & Qt::WindowFullScreen); |
|
2080 |
||
2081 |
layouted.showNormal(); |
|
2082 |
QVERIFY(!(layouted.windowState() & Qt::WindowFullScreen)); |
|
2083 |
||
2084 |
#if !defined(Q_WS_QWS) && !defined(Q_OS_WINCE) && !defined (Q_WS_S60) |
|
2085 |
//embedded may choose a different size to fit on the screen. |
|
2086 |
QCOMPARE(layouted.size(), layouted.sizeHint()); |
|
2087 |
#endif |
|
2088 |
||
2089 |
layouted.showFullScreen(); |
|
2090 |
QVERIFY(layouted.isFullScreen()); |
|
2091 |
QVERIFY(layouted.isVisible()); |
|
2092 |
||
2093 |
layouted.hide(); |
|
2094 |
QVERIFY(layouted.isFullScreen()); |
|
2095 |
QVERIFY(!layouted.isVisible()); |
|
2096 |
||
2097 |
layouted.showFullScreen(); |
|
2098 |
QVERIFY(layouted.isFullScreen()); |
|
2099 |
QVERIFY(layouted.isVisible()); |
|
2100 |
||
2101 |
layouted.showMinimized(); |
|
2102 |
QVERIFY(layouted.isMinimized()); |
|
2103 |
QVERIFY(layouted.isFullScreen()); |
|
2104 |
||
2105 |
layouted.showFullScreen(); |
|
2106 |
QVERIFY(!layouted.isMinimized()); |
|
2107 |
QVERIFY(layouted.isFullScreen()); |
|
2108 |
QVERIFY(layouted.isVisible()); |
|
2109 |
||
2110 |
layouted.showMinimized(); |
|
2111 |
QVERIFY(layouted.isMinimized()); |
|
2112 |
QVERIFY(layouted.isFullScreen()); |
|
2113 |
||
2114 |
layouted.showFullScreen(); |
|
2115 |
QVERIFY(!layouted.isMinimized()); |
|
2116 |
QVERIFY(layouted.isFullScreen()); |
|
2117 |
QVERIFY(layouted.isVisible()); |
|
2118 |
||
2119 |
{ |
|
2120 |
QWidget frame; |
|
2121 |
QWidget widget(&frame); |
|
2122 |
widget.showFullScreen(); |
|
2123 |
QVERIFY(widget.isFullScreen()); |
|
2124 |
} |
|
2125 |
||
2126 |
#ifdef QT3_SUPPORT |
|
2127 |
#if !defined(Q_WS_QWS) |
|
2128 |
//embedded respects max/min sizes by design -- maybe wrong design, but that's the way it is now. |
|
2129 |
{ |
|
2130 |
Q3HBox box; |
|
2131 |
QWidget widget(&box); |
|
2132 |
widget.setMinimumSize(500, 500); |
|
2133 |
box.showFullScreen(); |
|
2134 |
QVERIFY(box.isFullScreen()); |
|
2135 |
} |
|
2136 |
||
2137 |
{ |
|
2138 |
Q3HBox box; |
|
2139 |
QWidget widget(&box); |
|
2140 |
widget.setMaximumSize(500, 500); |
|
2141 |
||
2142 |
box.showFullScreen(); |
|
2143 |
QVERIFY(box.isFullScreen()); |
|
2144 |
} |
|
2145 |
#endif |
|
2146 |
#endif // QT3_SUPPORT |
|
2147 |
} |
|
2148 |
||
2149 |
class ResizeWidget : public QWidget { |
|
2150 |
public: |
|
2151 |
ResizeWidget(QWidget *p = 0) : QWidget(p) |
|
2152 |
{ |
|
2153 |
m_resizeEventCount = 0; |
|
2154 |
} |
|
2155 |
protected: |
|
2156 |
void resizeEvent(QResizeEvent *e){ |
|
2157 |
QCOMPARE(size(), e->size()); |
|
2158 |
++m_resizeEventCount; |
|
2159 |
} |
|
2160 |
||
2161 |
public: |
|
2162 |
int m_resizeEventCount; |
|
2163 |
}; |
|
2164 |
||
2165 |
void tst_QWidget::resizeEvent() |
|
2166 |
{ |
|
2167 |
{ |
|
2168 |
QWidget wParent; |
|
2169 |
ResizeWidget wChild(&wParent); |
|
2170 |
wParent.show(); |
|
2171 |
QCOMPARE (wChild.m_resizeEventCount, 1); // initial resize event before paint |
|
2172 |
wParent.hide(); |
|
2173 |
wChild.resize(QSize(640,480)); |
|
2174 |
QCOMPARE (wChild.m_resizeEventCount, 1); |
|
2175 |
wParent.show(); |
|
2176 |
QCOMPARE (wChild.m_resizeEventCount, 2); |
|
2177 |
} |
|
2178 |
||
2179 |
{ |
|
2180 |
ResizeWidget wTopLevel; |
|
2181 |
wTopLevel.show(); |
|
2182 |
QCOMPARE (wTopLevel.m_resizeEventCount, 1); // initial resize event before paint for toplevels |
|
2183 |
wTopLevel.hide(); |
|
2184 |
wTopLevel.resize(QSize(640,480)); |
|
2185 |
QCOMPARE (wTopLevel.m_resizeEventCount, 1); |
|
2186 |
wTopLevel.show(); |
|
2187 |
QCOMPARE (wTopLevel.m_resizeEventCount, 2); |
|
2188 |
} |
|
2189 |
} |
|
2190 |
||
2191 |
void tst_QWidget::showMinimized() |
|
2192 |
{ |
|
2193 |
QWidget plain; |
|
2194 |
plain.move(100, 100); |
|
2195 |
plain.resize(200, 200); |
|
2196 |
QPoint pos = plain.pos(); |
|
2197 |
||
2198 |
plain.showMinimized(); |
|
2199 |
QVERIFY(plain.isMinimized()); |
|
2200 |
QVERIFY(plain.isVisible()); |
|
2201 |
QCOMPARE(plain.pos(), pos); |
|
2202 |
||
2203 |
plain.showNormal(); |
|
2204 |
QVERIFY(!plain.isMinimized()); |
|
2205 |
QVERIFY(plain.isVisible()); |
|
2206 |
QCOMPARE(plain.pos(), pos); |
|
2207 |
||
2208 |
plain.showMinimized(); |
|
2209 |
QVERIFY(plain.isMinimized()); |
|
2210 |
QVERIFY(plain.isVisible()); |
|
2211 |
QCOMPARE(plain.pos(), pos); |
|
2212 |
||
2213 |
plain.hide(); |
|
2214 |
QVERIFY(plain.isMinimized()); |
|
2215 |
QVERIFY(!plain.isVisible()); |
|
2216 |
||
2217 |
plain.showMinimized(); |
|
2218 |
QVERIFY(plain.isMinimized()); |
|
2219 |
QVERIFY(plain.isVisible()); |
|
2220 |
||
2221 |
plain.setGeometry(200, 200, 300, 300); |
|
2222 |
plain.showNormal(); |
|
2223 |
QCOMPARE(plain.geometry(), QRect(200, 200, 300, 300)); |
|
2224 |
||
2225 |
{ |
|
2226 |
QWidget frame; |
|
2227 |
QWidget widget(&frame); |
|
2228 |
widget.showMinimized(); |
|
2229 |
QVERIFY(widget.isMinimized()); |
|
2230 |
} |
|
2231 |
} |
|
2232 |
||
2233 |
void tst_QWidget::showMinimizedKeepsFocus() |
|
2234 |
{ |
|
2235 |
//here we test that minimizing a widget and restoring it doesn't change the focus inside of it |
|
2236 |
{ |
|
2237 |
QWidget window; |
|
2238 |
QWidget child1(&window), child2(&window); |
|
2239 |
child1.setFocusPolicy(Qt::StrongFocus); |
|
2240 |
child2.setFocusPolicy(Qt::StrongFocus); |
|
2241 |
window.show(); |
|
2242 |
qApp->setActiveWindow(&window); |
|
2243 |
QTest::qWaitForWindowShown(&window); |
|
2244 |
child2.setFocus(); |
|
2245 |
QTest::qWait(50); |
|
2246 |
||
2247 |
QTRY_COMPARE(window.focusWidget(), &child2); |
|
2248 |
QTRY_COMPARE(qApp->focusWidget(), &child2); |
|
2249 |
||
2250 |
window.showMinimized(); |
|
2251 |
QTest::qWait(10); |
|
2252 |
QTRY_VERIFY(window.isMinimized()); |
|
2253 |
QTRY_COMPARE(window.focusWidget(), &child2); |
|
2254 |
||
2255 |
window.showNormal(); |
|
2256 |
QTest::qWait(10); |
|
2257 |
QTRY_COMPARE(window.focusWidget(), &child2); |
|
2258 |
} |
|
2259 |
||
2260 |
//testing deletion of the focusWidget |
|
2261 |
{ |
|
2262 |
QWidget window; |
|
2263 |
QWidget *child = new QWidget(&window); |
|
2264 |
child->setFocusPolicy(Qt::StrongFocus); |
|
2265 |
window.show(); |
|
2266 |
qApp->setActiveWindow(&window); |
|
2267 |
QTest::qWaitForWindowShown(&window); |
|
2268 |
child->setFocus(); |
|
2269 |
QTest::qWait(50); |
|
2270 |
QTRY_COMPARE(window.focusWidget(), child); |
|
2271 |
QTRY_COMPARE(qApp->focusWidget(), child); |
|
2272 |
||
2273 |
delete child; |
|
2274 |
QCOMPARE(window.focusWidget(), static_cast<QWidget*>(0)); |
|
2275 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget*>(0)); |
|
2276 |
} |
|
2277 |
||
2278 |
//testing reparenting the focus widget |
|
2279 |
{ |
|
2280 |
QWidget window; |
|
2281 |
QWidget *child = new QWidget(&window); |
|
2282 |
child->setFocusPolicy(Qt::StrongFocus); |
|
2283 |
window.show(); |
|
2284 |
qApp->setActiveWindow(&window); |
|
2285 |
QTest::qWaitForWindowShown(&window); |
|
2286 |
child->setFocus(); |
|
2287 |
QTest::qWait(50); |
|
2288 |
QTRY_COMPARE(window.focusWidget(), child); |
|
2289 |
QTRY_COMPARE(qApp->focusWidget(), child); |
|
2290 |
||
2291 |
child->setParent(0); |
|
2292 |
QCOMPARE(window.focusWidget(), static_cast<QWidget*>(0)); |
|
2293 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget*>(0)); |
|
2294 |
} |
|
2295 |
||
2296 |
//testing setEnabled(false) |
|
2297 |
{ |
|
2298 |
QWidget window; |
|
2299 |
QWidget *child = new QWidget(&window); |
|
2300 |
child->setFocusPolicy(Qt::StrongFocus); |
|
2301 |
window.show(); |
|
2302 |
qApp->setActiveWindow(&window); |
|
2303 |
QTest::qWaitForWindowShown(&window); |
|
2304 |
child->setFocus(); |
|
2305 |
QTest::qWait(10); |
|
2306 |
QTRY_COMPARE(window.focusWidget(), child); |
|
2307 |
QTRY_COMPARE(qApp->focusWidget(), child); |
|
2308 |
||
2309 |
child->setEnabled(false); |
|
2310 |
QCOMPARE(window.focusWidget(), static_cast<QWidget*>(0)); |
|
2311 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget*>(0)); |
|
2312 |
} |
|
2313 |
||
2314 |
//testing clearFocus |
|
2315 |
{ |
|
2316 |
QWidget window; |
|
2317 |
QWidget *firstchild = new QWidget(&window); |
|
2318 |
firstchild->setFocusPolicy(Qt::StrongFocus); |
|
2319 |
QWidget *child = new QWidget(&window); |
|
2320 |
child->setFocusPolicy(Qt::StrongFocus); |
|
2321 |
window.show(); |
|
2322 |
qApp->setActiveWindow(&window); |
|
2323 |
QTest::qWaitForWindowShown(&window); |
|
2324 |
child->setFocus(); |
|
2325 |
QTest::qWait(10); |
|
2326 |
QTRY_COMPARE(window.focusWidget(), child); |
|
2327 |
QTRY_COMPARE(qApp->focusWidget(), child); |
|
2328 |
||
2329 |
child->clearFocus(); |
|
2330 |
QCOMPARE(window.focusWidget(), static_cast<QWidget*>(0)); |
|
2331 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget*>(0)); |
|
2332 |
||
2333 |
window.showMinimized(); |
|
2334 |
QTest::qWait(30); |
|
2335 |
QTRY_VERIFY(window.isMinimized()); |
|
2336 |
#ifdef Q_WS_QWS |
|
2337 |
QEXPECT_FAIL("", "QWS does not implement showMinimized()", Continue); |
|
2338 |
#endif |
|
2339 |
QCOMPARE(window.focusWidget(), static_cast<QWidget*>(0)); |
|
2340 |
#ifdef Q_WS_QWS |
|
2341 |
QEXPECT_FAIL("", "QWS does not implement showMinimized()", Continue); |
|
2342 |
#endif |
|
2343 |
QTRY_COMPARE(qApp->focusWidget(), static_cast<QWidget*>(0)); |
|
2344 |
||
2345 |
window.showNormal(); |
|
2346 |
qApp->setActiveWindow(&window); |
|
2347 |
QTest::qWaitForWindowShown(&window); |
|
2348 |
QTest::qWait(30); |
|
2349 |
#ifdef Q_WS_MAC |
|
2350 |
if (!macHasAccessToWindowsServer()) |
|
2351 |
QEXPECT_FAIL("", "When not having WindowServer access, we lose focus.", Continue); |
|
2352 |
#endif |
|
2353 |
QTRY_COMPARE(window.focusWidget(), firstchild); |
|
2354 |
#ifdef Q_WS_MAC |
|
2355 |
if (!macHasAccessToWindowsServer()) |
|
2356 |
QEXPECT_FAIL("", "When not having WindowServer access, we lose focus.", Continue); |
|
2357 |
#endif |
|
2358 |
QTRY_COMPARE(qApp->focusWidget(), firstchild); |
|
2359 |
} |
|
2360 |
} |
|
2361 |
||
2362 |
||
2363 |
void tst_QWidget::reparent() |
|
2364 |
{ |
|
2365 |
QWidget parent; |
|
2366 |
parent.setWindowTitle("Toplevel"); |
|
2367 |
parent.setGeometry(300, 300, 200, 150); |
|
2368 |
||
2369 |
QWidget child(0); |
|
2370 |
child.setObjectName("child"); |
|
2371 |
child.setGeometry(10, 10, 180, 130); |
|
2372 |
QPalette pal1; |
|
2373 |
pal1.setColor(child.backgroundRole(), Qt::white); |
|
2374 |
child.setPalette(pal1); |
|
2375 |
||
2376 |
QWidget childTLW(&child, Qt::Window); |
|
2377 |
childTLW.setObjectName("childTLW"); |
|
2378 |
childTLW.setGeometry(100, 100, 50, 50); |
|
2379 |
QPalette pal2; |
|
2380 |
pal2.setColor(childTLW.backgroundRole(), Qt::yellow); |
|
2381 |
childTLW.setPalette(pal2); |
|
2382 |
||
2383 |
parent.show(); |
|
2384 |
childTLW.show(); |
|
2385 |
QTest::qWaitForWindowShown(&parent); |
|
2386 |
||
2387 |
#ifdef Q_OS_WINCE |
|
2388 |
parent.move(50, 50); |
|
2389 |
#else |
|
2390 |
parent.move(300, 300); |
|
2391 |
#endif |
|
2392 |
||
2393 |
QPoint childPos = parent.mapToGlobal(child.pos()); |
|
2394 |
QPoint tlwPos = childTLW.pos(); |
|
2395 |
||
2396 |
child.setParent(0, child.windowFlags() & ~Qt::WindowType_Mask); |
|
2397 |
child.setGeometry(childPos.x(), childPos.y(), child.width(), child.height()); |
|
2398 |
child.show(); |
|
2399 |
||
2400 |
#ifdef Q_WS_X11 |
|
2401 |
// On X11, the window manager will apply NorthWestGravity rules to 'child', which |
|
2402 |
// means the top-left corner of the window frame will be placed at 'childPos', |
|
2403 |
// causing this test to fail |
|
2404 |
#else |
|
2405 |
QCOMPARE(child.geometry().topLeft(), childPos); |
|
2406 |
#endif |
|
2407 |
QTRY_COMPARE(childTLW.pos(), tlwPos); |
|
2408 |
||
2409 |
#ifdef Q_WS_WIN |
|
2410 |
QWidget childTLWChild(&childTLW); |
|
2411 |
childTLWChild.setObjectName("childTLWChild"); |
|
2412 |
||
2413 |
QWidget grandChild(&child); |
|
2414 |
grandChild.setObjectName("grandChild"); |
|
2415 |
grandChild.setGeometry(10, 10, 160, 110); |
|
2416 |
QPalette pal3; |
|
2417 |
pal3.setColor(grandChild.backgroundRole(), Qt::red); |
|
2418 |
grandChild.setPalette(pal3); |
|
2419 |
//grandChild.setPaletteBackgroundColor(Qt::red); |
|
2420 |
||
2421 |
QWidget grandChildTLW(&grandChild, Qt::Window); |
|
2422 |
grandChildTLW.setObjectName("grandChildTLW"); |
|
2423 |
grandChildTLW.setGeometry(200, 200, 50, 50); |
|
2424 |
QPalette pal4; |
|
2425 |
pal4.setColor(grandChildTLW.backgroundRole(), Qt::yellow); |
|
2426 |
grandChildTLW.setPalette(pal4); |
|
2427 |
//grandChildTLW.setPaletteBackgroundColor(Qt::yellow); |
|
2428 |
||
2429 |
QWidget grandChildTLWChild(&grandChildTLW); |
|
2430 |
grandChildTLWChild.setObjectName("grandChildTLWChild"); |
|
2431 |
||
2432 |
QVERIFY(IsWindow(childTLW.winId())); |
|
2433 |
QVERIFY(IsWindow(childTLWChild.winId())); |
|
2434 |
QVERIFY(IsWindow(grandChildTLW.winId())); |
|
2435 |
QVERIFY(IsWindow(grandChildTLWChild.winId())); |
|
2436 |
||
2437 |
parent.show(); |
|
2438 |
||
2439 |
QVERIFY(IsWindow(childTLW.winId())); |
|
2440 |
QVERIFY(IsWindow(childTLWChild.winId())); |
|
2441 |
QVERIFY(IsWindow(grandChildTLW.winId())); |
|
2442 |
QVERIFY(IsWindow(grandChildTLWChild.winId())); |
|
2443 |
||
2444 |
child.setParent(&parent); |
|
2445 |
child.move(10,10); |
|
2446 |
child.show(); |
|
2447 |
||
2448 |
// this appears to stabelize results |
|
2449 |
qApp->processEvents(); |
|
2450 |
||
2451 |
QVERIFY(IsWindow(childTLW.winId())); |
|
2452 |
QVERIFY(IsWindow(childTLWChild.winId())); |
|
2453 |
||
2454 |
QVERIFY(IsWindow(grandChildTLW.winId())); |
|
2455 |
QVERIFY(IsWindow(grandChildTLWChild.winId())); |
|
2456 |
#else |
|
2457 |
QSKIP("This test makes only sense on Windows", SkipAll); |
|
2458 |
#endif |
|
2459 |
} |
|
2460 |
||
2461 |
void tst_QWidget::icon() |
|
2462 |
{ |
|
2463 |
#if defined(Q_WS_QWS) |
|
2464 |
QSKIP("Qt/Embedded does it differently", SkipAll); |
|
2465 |
#else |
|
2466 |
QPixmap p(20,20); |
|
2467 |
p.fill(Qt::red); |
|
2468 |
testWidget->setWindowIcon(p); |
|
2469 |
||
2470 |
QVERIFY(!testWidget->windowIcon().isNull()); |
|
2471 |
testWidget->show(); |
|
2472 |
QVERIFY(!testWidget->windowIcon().isNull()); |
|
2473 |
testWidget->showFullScreen(); |
|
2474 |
QVERIFY(!testWidget->windowIcon().isNull()); |
|
2475 |
testWidget->showNormal(); |
|
2476 |
QVERIFY(!testWidget->windowIcon().isNull()); |
|
2477 |
#endif |
|
2478 |
} |
|
2479 |
||
2480 |
void tst_QWidget::hideWhenFocusWidgetIsChild() |
|
2481 |
{ |
|
2482 |
testWidget->activateWindow(); |
|
2483 |
QWidget *parentWidget = new QWidget(testWidget); |
|
2484 |
parentWidget->setObjectName("parentWidget"); |
|
2485 |
parentWidget->setGeometry(0, 0, 100, 100); |
|
2486 |
QLineEdit *edit = new QLineEdit(parentWidget); |
|
2487 |
edit->setObjectName("edit1"); |
|
2488 |
QLineEdit *edit3 = new QLineEdit(parentWidget); |
|
2489 |
edit3->setObjectName("edit3"); |
|
2490 |
edit3->move(0,50); |
|
2491 |
parentWidget->show(); |
|
2492 |
QLineEdit *edit2 = new QLineEdit(testWidget); |
|
2493 |
edit2->setObjectName("edit2"); |
|
2494 |
edit2->show(); |
|
2495 |
edit2->move(110, 100); |
|
2496 |
edit->setFocus(); |
|
2497 |
qApp->processEvents(); |
|
2498 |
QString actualFocusWidget, expectedFocusWidget; |
|
2499 |
#ifdef Q_WS_X11 |
|
2500 |
if (!qApp->focusWidget()) |
|
2501 |
QSKIP("Your window manager is too broken for this test", SkipAll); |
|
2502 |
#endif |
|
2503 |
QVERIFY(qApp->focusWidget()); |
|
2504 |
actualFocusWidget.sprintf("%p %s %s", qApp->focusWidget(), qApp->focusWidget()->objectName().toLatin1().constData(), qApp->focusWidget()->metaObject()->className()); |
|
2505 |
expectedFocusWidget.sprintf("%p %s %s", edit, edit->objectName().toLatin1().constData(), edit->metaObject()->className()); |
|
2506 |
QCOMPARE(actualFocusWidget, expectedFocusWidget); |
|
2507 |
||
2508 |
parentWidget->hide(); |
|
2509 |
qApp->processEvents(); |
|
2510 |
actualFocusWidget.sprintf("%p %s %s", qApp->focusWidget(), qApp->focusWidget()->objectName().toLatin1().constData(), qApp->focusWidget()->metaObject()->className()); |
|
2511 |
expectedFocusWidget.sprintf("%p %s %s", edit2, edit2->objectName().toLatin1().constData(), edit2->metaObject()->className()); |
|
2512 |
QCOMPARE(actualFocusWidget, expectedFocusWidget); |
|
2513 |
||
2514 |
delete edit2; |
|
2515 |
delete parentWidget; |
|
2516 |
} |
|
2517 |
||
2518 |
void tst_QWidget::normalGeometry() |
|
2519 |
{ |
|
2520 |
#ifdef Q_OS_IRIX |
|
2521 |
QSKIP("4DWM issues on IRIX makes this test fail", SkipAll); |
|
2522 |
#endif |
|
2523 |
QWidget parent; |
|
2524 |
parent.setWindowTitle("NormalGeometry parent"); |
|
2525 |
QWidget *child = new QWidget(&parent); |
|
2526 |
||
2527 |
QCOMPARE(parent.normalGeometry(), parent.geometry()); |
|
2528 |
QCOMPARE(child->normalGeometry(), QRect()); |
|
2529 |
||
2530 |
parent.setGeometry(100, 100, 200, 200); |
|
2531 |
parent.show(); |
|
2532 |
QTest::qWaitForWindowShown(&parent); |
|
2533 |
QApplication::processEvents(); |
|
2534 |
||
2535 |
QRect geom = parent.geometry(); |
|
2536 |
// ### the window manager places the top-left corner at |
|
2537 |
// ### 100,100... making geom something like 102,124 (offset by |
|
2538 |
// ### the frame/frame)... this indicates a rather large different |
|
2539 |
// ### between how X11 and Windows works |
|
2540 |
// QCOMPARE(geom, QRect(100, 100, 200, 200)); |
|
2541 |
QCOMPARE(parent.normalGeometry(), geom); |
|
2542 |
||
2543 |
parent.setWindowState(parent.windowState() ^ Qt::WindowMaximized); |
|
2544 |
QTest::qWait(10); |
|
2545 |
QTRY_VERIFY(parent.windowState() & Qt::WindowMaximized); |
|
2546 |
QTRY_VERIFY(parent.geometry() != geom); |
|
2547 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2548 |
||
2549 |
parent.setWindowState(parent.windowState() ^ Qt::WindowMaximized); |
|
2550 |
QTest::qWait(10); |
|
2551 |
QTRY_VERIFY(!(parent.windowState() & Qt::WindowMaximized)); |
|
2552 |
QTRY_COMPARE(parent.geometry(), geom); |
|
2553 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2554 |
||
2555 |
parent.showMaximized(); |
|
2556 |
QTest::qWait(10); |
|
2557 |
QTRY_VERIFY(parent.windowState() & Qt::WindowMaximized); |
|
2558 |
QTRY_VERIFY(parent.geometry() != geom); |
|
2559 |
QCOMPARE(parent.normalGeometry(), geom); |
|
2560 |
||
2561 |
parent.showNormal(); |
|
2562 |
QTest::qWait(10); |
|
2563 |
QTRY_VERIFY(!(parent.windowState() & Qt::WindowMaximized)); |
|
2564 |
QTRY_COMPARE(parent.geometry(), geom); |
|
2565 |
QCOMPARE(parent.normalGeometry(), geom); |
|
2566 |
||
2567 |
parent.setWindowState(parent.windowState() ^ Qt::WindowMinimized); |
|
2568 |
QTest::qWait(10); |
|
2569 |
parent.setWindowState(parent.windowState() ^ Qt::WindowMaximized); |
|
2570 |
QTest::qWait(10); |
|
2571 |
QTRY_VERIFY(parent.windowState() & (Qt::WindowMinimized|Qt::WindowMaximized)); |
|
2572 |
// ### when minimized and maximized at the same time, the geometry |
|
2573 |
// ### does *NOT* have to be the normal geometry, it could be the |
|
2574 |
// ### maximized geometry. |
|
2575 |
// QCOMPARE(parent.geometry(), geom); |
|
2576 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2577 |
||
2578 |
parent.setWindowState(parent.windowState() ^ Qt::WindowMinimized); |
|
2579 |
QTest::qWait(10); |
|
2580 |
QTRY_VERIFY(!(parent.windowState() & Qt::WindowMinimized)); |
|
2581 |
QTRY_VERIFY(parent.windowState() & Qt::WindowMaximized); |
|
2582 |
QTRY_VERIFY(parent.geometry() != geom); |
|
2583 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2584 |
||
2585 |
parent.setWindowState(parent.windowState() ^ Qt::WindowMaximized); |
|
2586 |
QTest::qWait(10); |
|
2587 |
QTRY_VERIFY(!(parent.windowState() & Qt::WindowMaximized)); |
|
2588 |
QTRY_COMPARE(parent.geometry(), geom); |
|
2589 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2590 |
||
2591 |
parent.setWindowState(parent.windowState() ^ Qt::WindowFullScreen); |
|
2592 |
QTest::qWait(10); |
|
2593 |
QTRY_VERIFY(parent.windowState() & Qt::WindowFullScreen); |
|
2594 |
QTRY_VERIFY(parent.geometry() != geom); |
|
2595 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2596 |
||
2597 |
parent.setWindowState(parent.windowState() ^ Qt::WindowFullScreen); |
|
2598 |
QTest::qWait(10); |
|
2599 |
QVERIFY(!(parent.windowState() & Qt::WindowFullScreen)); |
|
2600 |
QTRY_COMPARE(parent.geometry(), geom); |
|
2601 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2602 |
||
2603 |
parent.showFullScreen(); |
|
2604 |
QTest::qWait(10); |
|
2605 |
QTRY_VERIFY(parent.windowState() & Qt::WindowFullScreen); |
|
2606 |
QTRY_VERIFY(parent.geometry() != geom); |
|
2607 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2608 |
||
2609 |
parent.showNormal(); |
|
2610 |
QTest::qWait(10); |
|
2611 |
QTRY_VERIFY(!(parent.windowState() & Qt::WindowFullScreen)); |
|
2612 |
QTRY_COMPARE(parent.geometry(), geom); |
|
2613 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2614 |
||
2615 |
parent.showNormal(); |
|
2616 |
parent.setWindowState(Qt:: WindowFullScreen | Qt::WindowMaximized); |
|
2617 |
parent.setWindowState(Qt::WindowMinimized | Qt:: WindowFullScreen | Qt::WindowMaximized); |
|
2618 |
parent.setWindowState(Qt:: WindowFullScreen | Qt::WindowMaximized); |
|
2619 |
QTest::qWait(10); |
|
2620 |
QTRY_COMPARE(parent.normalGeometry(), geom); |
|
2621 |
} |
|
2622 |
||
2623 |
||
2624 |
void tst_QWidget::setGeometry() |
|
2625 |
{ |
|
2626 |
QWidget tlw; |
|
2627 |
QWidget child(&tlw); |
|
2628 |
||
2629 |
QRect tr(100,100,200,200); |
|
2630 |
QRect cr(50,50,50,50); |
|
2631 |
tlw.setGeometry(tr); |
|
2632 |
child.setGeometry(cr); |
|
2633 |
tlw.show(); |
|
2634 |
QTest::qWait(50); |
|
2635 |
QCOMPARE(tlw.geometry().size(), tr.size()); |
|
2636 |
QCOMPARE(child.geometry(), cr); |
|
2637 |
||
2638 |
tlw.setParent(0, Qt::Window|Qt::FramelessWindowHint); |
|
2639 |
tr = QRect(0,0,100,100); |
|
2640 |
tr.moveTopLeft(QApplication::desktop()->availableGeometry().topLeft()); |
|
2641 |
tlw.setGeometry(tr); |
|
2642 |
QCOMPARE(tlw.geometry(), tr); |
|
2643 |
tlw.show(); |
|
2644 |
QTest::qWait(50); |
|
2645 |
if (tlw.frameGeometry() != tlw.geometry()) |
|
2646 |
QSKIP("Your window manager is too broken for this test", SkipAll); |
|
2647 |
QCOMPARE(tlw.geometry(), tr); |
|
2648 |
||
2649 |
} |
|
2650 |
||
2651 |
void tst_QWidget::windowOpacity() |
|
2652 |
{ |
|
2653 |
#ifdef Q_OS_WINCE |
|
2654 |
QSKIP( "Windows CE does not support windowOpacity", SkipAll); |
|
2655 |
#endif |
|
2656 |
QWidget widget; |
|
2657 |
QWidget child(&widget); |
|
2658 |
||
2659 |
// Initial value should be 1.0 |
|
2660 |
QCOMPARE(widget.windowOpacity(), 1.0); |
|
2661 |
// children should always return 1.0 |
|
2662 |
QCOMPARE(child.windowOpacity(), 1.0); |
|
2663 |
||
2664 |
widget.setWindowOpacity(0.0); |
|
2665 |
QCOMPARE(widget.windowOpacity(), 0.0); |
|
2666 |
child.setWindowOpacity(0.0); |
|
2667 |
QCOMPARE(child.windowOpacity(), 1.0); |
|
2668 |
||
2669 |
widget.setWindowOpacity(1.0); |
|
2670 |
QCOMPARE(widget.windowOpacity(), 1.0); |
|
2671 |
child.setWindowOpacity(1.0); |
|
2672 |
QCOMPARE(child.windowOpacity(), 1.0); |
|
2673 |
||
2674 |
widget.setWindowOpacity(2.0); |
|
2675 |
QCOMPARE(widget.windowOpacity(), 1.0); |
|
2676 |
child.setWindowOpacity(2.0); |
|
2677 |
QCOMPARE(child.windowOpacity(), 1.0); |
|
2678 |
||
2679 |
widget.setWindowOpacity(-1.0); |
|
2680 |
QCOMPARE(widget.windowOpacity(), 0.0); |
|
2681 |
child.setWindowOpacity(-1.0); |
|
2682 |
QCOMPARE(child.windowOpacity(), 1.0); |
|
2683 |
} |
|
2684 |
||
2685 |
class UpdateWidget : public QWidget |
|
2686 |
{ |
|
2687 |
public: |
|
2688 |
UpdateWidget(QWidget *parent = 0) : QWidget(parent) { |
|
2689 |
reset(); |
|
2690 |
} |
|
2691 |
||
2692 |
void paintEvent(QPaintEvent *e) { |
|
2693 |
paintedRegion += e->region(); |
|
2694 |
++numPaintEvents; |
|
2695 |
if (resizeInPaintEvent) { |
|
2696 |
resizeInPaintEvent = false; |
|
2697 |
resize(size() + QSize(2, 2)); |
|
2698 |
} |
|
2699 |
} |
|
2700 |
||
2701 |
bool event(QEvent *event) |
|
2702 |
{ |
|
2703 |
switch (event->type()) { |
|
2704 |
case QEvent::ZOrderChange: |
|
2705 |
++numZOrderChangeEvents; |
|
2706 |
break; |
|
2707 |
case QEvent::UpdateRequest: |
|
2708 |
++numUpdateRequestEvents; |
|
2709 |
break; |
|
2710 |
case QEvent::ActivationChange: |
|
2711 |
case QEvent::FocusIn: |
|
2712 |
case QEvent::FocusOut: |
|
2713 |
case QEvent::WindowActivate: |
|
2714 |
case QEvent::WindowDeactivate: |
|
2715 |
if (!updateOnActivationChangeAndFocusIn) |
|
2716 |
return true; // Filter out to avoid update() calls in QWidget. |
|
2717 |
break; |
|
2718 |
default: |
|
2719 |
break; |
|
2720 |
} |
|
2721 |
return QWidget::event(event); |
|
2722 |
} |
|
2723 |
||
2724 |
void reset() { |
|
2725 |
numPaintEvents = 0; |
|
2726 |
numZOrderChangeEvents = 0; |
|
2727 |
numUpdateRequestEvents = 0; |
|
2728 |
updateOnActivationChangeAndFocusIn = false; |
|
2729 |
resizeInPaintEvent = false; |
|
2730 |
paintedRegion = QRegion(); |
|
2731 |
} |
|
2732 |
||
2733 |
int numPaintEvents; |
|
2734 |
int numZOrderChangeEvents; |
|
2735 |
int numUpdateRequestEvents; |
|
2736 |
bool updateOnActivationChangeAndFocusIn; |
|
2737 |
bool resizeInPaintEvent; |
|
2738 |
QRegion paintedRegion; |
|
2739 |
}; |
|
2740 |
||
2741 |
void tst_QWidget::lostUpdatesOnHide() |
|
2742 |
{ |
|
2743 |
#ifndef Q_WS_MAC |
|
2744 |
UpdateWidget widget; |
|
2745 |
widget.setAttribute(Qt::WA_DontShowOnScreen); |
|
2746 |
widget.show(); |
|
2747 |
widget.hide(); |
|
2748 |
QTest::qWait(50); |
|
2749 |
widget.show(); |
|
2750 |
QTest::qWait(50); |
|
2751 |
||
2752 |
QCOMPARE(widget.numPaintEvents, 1); |
|
2753 |
#endif |
|
2754 |
} |
|
2755 |
||
2756 |
void tst_QWidget::raise() |
|
2757 |
{ |
|
2758 |
#ifdef QT_MAC_USE_COCOA |
|
2759 |
QSKIP("Cocoa has no Z-Order for views, we hack it, but it results in paint events.", SkipAll); |
|
2760 |
#endif |
|
2761 |
QTest::qWait(10); |
|
2762 |
QWidget *parent = new QWidget(0); |
|
2763 |
QList<UpdateWidget *> allChildren; |
|
2764 |
||
2765 |
UpdateWidget *child1 = new UpdateWidget(parent); |
|
2766 |
child1->setAutoFillBackground(true); |
|
2767 |
allChildren.append(child1); |
|
2768 |
||
2769 |
UpdateWidget *child2 = new UpdateWidget(parent); |
|
2770 |
child2->setAutoFillBackground(true); |
|
2771 |
allChildren.append(child2); |
|
2772 |
||
2773 |
UpdateWidget *child3 = new UpdateWidget(parent); |
|
2774 |
child3->setAutoFillBackground(true); |
|
2775 |
allChildren.append(child3); |
|
2776 |
||
2777 |
UpdateWidget *child4 = new UpdateWidget(parent); |
|
2778 |
child4->setAutoFillBackground(true); |
|
2779 |
allChildren.append(child4); |
|
2780 |
||
2781 |
parent->show(); |
|
2782 |
QTest::qWaitForWindowShown(parent); |
|
2783 |
QTest::qWait(10); |
|
2784 |
||
2785 |
QList<QObject *> list1; |
|
2786 |
list1 << child1 << child2 << child3 << child4; |
|
2787 |
QVERIFY(parent->children() == list1); |
|
2788 |
QCOMPARE(allChildren.count(), list1.count()); |
|
2789 |
||
2790 |
foreach (UpdateWidget *child, allChildren) { |
|
2791 |
int expectedPaintEvents = child == child4 ? 1 : 0; |
|
2792 |
if (expectedPaintEvents == 0) { |
|
2793 |
QVERIFY(child->numPaintEvents == 0); |
|
2794 |
} else { |
|
2795 |
// show() issues multiple paint events on some window managers |
|
2796 |
QTRY_VERIFY(child->numPaintEvents >= expectedPaintEvents); |
|
2797 |
} |
|
2798 |
QCOMPARE(child->numZOrderChangeEvents, 0); |
|
2799 |
child->reset(); |
|
2800 |
} |
|
2801 |
||
2802 |
for (int i = 0; i < 5; ++i) |
|
2803 |
child2->raise(); |
|
2804 |
QTest::qWait(50); |
|
2805 |
||
2806 |
foreach (UpdateWidget *child, allChildren) { |
|
2807 |
int expectedPaintEvents = child == child2 ? 1 : 0; |
|
2808 |
int expectedZOrderChangeEvents = child == child2 ? 1 : 0; |
|
2809 |
QTRY_COMPARE(child->numPaintEvents, expectedPaintEvents); |
|
2810 |
QCOMPARE(child->numZOrderChangeEvents, expectedZOrderChangeEvents); |
|
2811 |
child->reset(); |
|
2812 |
} |
|
2813 |
||
2814 |
QList<QObject *> list2; |
|
2815 |
list2 << child1 << child3 << child4 << child2; |
|
2816 |
QVERIFY(parent->children() == list2); |
|
2817 |
||
2818 |
// Creates a widget on top of all the children and checks that raising one of |
|
2819 |
// the children underneath doesn't trigger a repaint on the covering widget. |
|
2820 |
QWidget topLevel; |
|
2821 |
parent->setParent(&topLevel); |
|
2822 |
topLevel.show(); |
|
2823 |
QTest::qWaitForWindowShown(&topLevel); |
|
2824 |
QTest::qWait(50); |
|
2825 |
||
2826 |
UpdateWidget *onTop = new UpdateWidget(&topLevel); |
|
2827 |
onTop->reset(); |
|
2828 |
onTop->resize(topLevel.size()); |
|
2829 |
onTop->setAutoFillBackground(true); |
|
2830 |
onTop->show(); |
|
2831 |
QTest::qWait(50); |
|
2832 |
QTRY_VERIFY(onTop->numPaintEvents > 0); |
|
2833 |
onTop->reset(); |
|
2834 |
||
2835 |
// Reset all the children. |
|
2836 |
foreach (UpdateWidget *child, allChildren) |
|
2837 |
child->reset(); |
|
2838 |
||
2839 |
for (int i = 0; i < 5; ++i) |
|
2840 |
child3->raise(); |
|
2841 |
QTest::qWait(50); |
|
2842 |
||
2843 |
QCOMPARE(onTop->numPaintEvents, 0); |
|
2844 |
QCOMPARE(onTop->numZOrderChangeEvents, 0); |
|
2845 |
||
2846 |
QList<QObject *> list3; |
|
2847 |
list3 << child1 << child4 << child2 << child3; |
|
2848 |
QVERIFY(parent->children() == list3); |
|
2849 |
||
2850 |
foreach (UpdateWidget *child, allChildren) { |
|
2851 |
int expectedPaintEvents = 0; |
|
2852 |
int expectedZOrderChangeEvents = child == child3 ? 1 : 0; |
|
2853 |
QTRY_COMPARE(child->numPaintEvents, expectedPaintEvents); |
|
2854 |
QCOMPARE(child->numZOrderChangeEvents, expectedZOrderChangeEvents); |
|
2855 |
child->reset(); |
|
2856 |
} |
|
2857 |
} |
|
2858 |
||
2859 |
void tst_QWidget::lower() |
|
2860 |
{ |
|
2861 |
#ifdef QT_MAC_USE_COCOA |
|
2862 |
QSKIP("Cocoa has no Z-Order for views, we hack it, but it results in paint events.", SkipAll); |
|
2863 |
#endif |
|
2864 |
QWidget *parent = new QWidget(0); |
|
2865 |
QList<UpdateWidget *> allChildren; |
|
2866 |
||
2867 |
UpdateWidget *child1 = new UpdateWidget(parent); |
|
2868 |
child1->setAutoFillBackground(true); |
|
2869 |
allChildren.append(child1); |
|
2870 |
||
2871 |
UpdateWidget *child2 = new UpdateWidget(parent); |
|
2872 |
child2->setAutoFillBackground(true); |
|
2873 |
allChildren.append(child2); |
|
2874 |
||
2875 |
UpdateWidget *child3 = new UpdateWidget(parent); |
|
2876 |
child3->setAutoFillBackground(true); |
|
2877 |
allChildren.append(child3); |
|
2878 |
||
2879 |
UpdateWidget *child4 = new UpdateWidget(parent); |
|
2880 |
child4->setAutoFillBackground(true); |
|
2881 |
allChildren.append(child4); |
|
2882 |
||
2883 |
parent->show(); |
|
2884 |
QTest::qWaitForWindowShown(parent); |
|
2885 |
QTest::qWait(100); |
|
2886 |
||
2887 |
QList<QObject *> list1; |
|
2888 |
list1 << child1 << child2 << child3 << child4; |
|
2889 |
QVERIFY(parent->children() == list1); |
|
2890 |
QCOMPARE(allChildren.count(), list1.count()); |
|
2891 |
||
2892 |
foreach (UpdateWidget *child, allChildren) { |
|
2893 |
int expectedPaintEvents = child == child4 ? 1 : 0; |
|
2894 |
if (expectedPaintEvents == 0) { |
|
2895 |
QVERIFY(child->numPaintEvents == 0); |
|
2896 |
} else { |
|
2897 |
// show() issues multiple paint events on some window managers |
|
2898 |
QTRY_VERIFY(child->numPaintEvents >= expectedPaintEvents); |
|
2899 |
} |
|
2900 |
QCOMPARE(child->numZOrderChangeEvents, 0); |
|
2901 |
child->reset(); |
|
2902 |
} |
|
2903 |
||
2904 |
for (int i = 0; i < 5; ++i) |
|
2905 |
child4->lower(); |
|
2906 |
||
2907 |
QTest::qWait(100); |
|
2908 |
||
2909 |
foreach (UpdateWidget *child, allChildren) { |
|
2910 |
int expectedPaintEvents = child == child3 ? 1 : 0; |
|
2911 |
int expectedZOrderChangeEvents = child == child4 ? 1 : 0; |
|
2912 |
QTRY_COMPARE(child->numZOrderChangeEvents, expectedZOrderChangeEvents); |
|
2913 |
QTRY_COMPARE(child->numPaintEvents, expectedPaintEvents); |
|
2914 |
child->reset(); |
|
2915 |
} |
|
2916 |
||
2917 |
QList<QObject *> list2; |
|
2918 |
list2 << child4 << child1 << child2 << child3; |
|
2919 |
QVERIFY(parent->children() == list2); |
|
2920 |
||
2921 |
delete parent; |
|
2922 |
} |
|
2923 |
||
2924 |
void tst_QWidget::stackUnder() |
|
2925 |
{ |
|
2926 |
#ifdef QT_MAC_USE_COCOA |
|
2927 |
QSKIP("Cocoa has no Z-Order for views, we hack it, but it results in paint events.", SkipAll); |
|
2928 |
#endif |
|
2929 |
QTest::qWait(10); |
|
2930 |
QWidget *parent = new QWidget(0); |
|
2931 |
QList<UpdateWidget *> allChildren; |
|
2932 |
||
2933 |
UpdateWidget *child1 = new UpdateWidget(parent); |
|
2934 |
child1->setAutoFillBackground(true); |
|
2935 |
allChildren.append(child1); |
|
2936 |
||
2937 |
UpdateWidget *child2 = new UpdateWidget(parent); |
|
2938 |
child2->setAutoFillBackground(true); |
|
2939 |
allChildren.append(child2); |
|
2940 |
||
2941 |
UpdateWidget *child3 = new UpdateWidget(parent); |
|
2942 |
child3->setAutoFillBackground(true); |
|
2943 |
allChildren.append(child3); |
|
2944 |
||
2945 |
UpdateWidget *child4 = new UpdateWidget(parent); |
|
2946 |
child4->setAutoFillBackground(true); |
|
2947 |
allChildren.append(child4); |
|
2948 |
||
2949 |
parent->show(); |
|
2950 |
QTest::qWaitForWindowShown(parent); |
|
2951 |
QTest::qWait(10); |
|
2952 |
#ifdef Q_WS_QWS |
|
2953 |
QApplication::sendPostedEvents(); //glib workaround |
|
2954 |
#endif |
|
2955 |
||
2956 |
QList<QObject *> list1; |
|
2957 |
list1 << child1 << child2 << child3 << child4; |
|
2958 |
QVERIFY(parent->children() == list1); |
|
2959 |
||
2960 |
foreach (UpdateWidget *child, allChildren) { |
|
2961 |
int expectedPaintEvents = child == child4 ? 1 : 0; |
|
2962 |
#if defined(Q_WS_WIN) || defined(Q_WS_MAC) |
|
2963 |
if (expectedPaintEvents == 1 && child->numPaintEvents == 2) |
|
2964 |
QEXPECT_FAIL(0, "Mac and Windows issues double repaints for Z-Order change", Continue); |
|
2965 |
#endif |
|
2966 |
QTRY_COMPARE(child->numPaintEvents, expectedPaintEvents); |
|
2967 |
QCOMPARE(child->numZOrderChangeEvents, 0); |
|
2968 |
child->reset(); |
|
2969 |
} |
|
2970 |
||
2971 |
for (int i = 0; i < 5; ++i) |
|
2972 |
child4->stackUnder(child2); |
|
2973 |
QTest::qWait(10); |
|
2974 |
||
2975 |
QList<QObject *> list2; |
|
2976 |
list2 << child1 << child4 << child2 << child3; |
|
2977 |
QVERIFY(parent->children() == list2); |
|
2978 |
||
2979 |
foreach (UpdateWidget *child, allChildren) { |
|
2980 |
int expectedPaintEvents = child == child3 ? 1 : 0; |
|
2981 |
int expectedZOrderChangeEvents = child == child4 ? 1 : 0; |
|
2982 |
QTRY_COMPARE(child->numPaintEvents, expectedPaintEvents); |
|
2983 |
QTRY_COMPARE(child->numZOrderChangeEvents, expectedZOrderChangeEvents); |
|
2984 |
child->reset(); |
|
2985 |
} |
|
2986 |
||
2987 |
for (int i = 0; i < 5; ++i) |
|
2988 |
child1->stackUnder(child3); |
|
2989 |
QTest::qWait(10); |
|
2990 |
||
2991 |
QList<QObject *> list3; |
|
2992 |
list3 << child4 << child2 << child1 << child3; |
|
2993 |
QVERIFY(parent->children() == list3); |
|
2994 |
||
2995 |
foreach (UpdateWidget *child, allChildren) { |
|
2996 |
int expectedZOrderChangeEvents = child == child1 ? 1 : 0; |
|
2997 |
if (child == child3) { |
|
2998 |
#ifdef Q_OS_WINCE |
|
2999 |
qApp->processEvents(); |
|
3000 |
#endif |
|
3001 |
#ifndef Q_WS_MAC |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3002 |
QEXPECT_FAIL(0, "See QTBUG-493", Continue); |
0 | 3003 |
#endif |
3004 |
QCOMPARE(child->numPaintEvents, 0); |
|
3005 |
} else { |
|
3006 |
QCOMPARE(child->numPaintEvents, 0); |
|
3007 |
} |
|
3008 |
QTRY_COMPARE(child->numZOrderChangeEvents, expectedZOrderChangeEvents); |
|
3009 |
child->reset(); |
|
3010 |
} |
|
3011 |
||
3012 |
delete parent; |
|
3013 |
} |
|
3014 |
||
3015 |
void drawPolygon(QPaintDevice *dev, int w, int h) |
|
3016 |
{ |
|
3017 |
QPainter p(dev); |
|
3018 |
p.fillRect(0, 0, w, h, Qt::white); |
|
3019 |
||
3020 |
QPolygon a; |
|
3021 |
a << QPoint(0, 0) << QPoint(w/2, h/2) << QPoint(w, 0) |
|
3022 |
<< QPoint(w/2, h) << QPoint(0, 0); |
|
3023 |
||
3024 |
p.setPen(QPen(Qt::black, 1)); |
|
3025 |
p.setBrush(Qt::DiagCrossPattern); |
|
3026 |
p.drawPolygon(a); |
|
3027 |
} |
|
3028 |
||
3029 |
class ContentsPropagationWidget : public QWidget |
|
3030 |
{ |
|
3031 |
Q_OBJECT |
|
3032 |
public: |
|
3033 |
ContentsPropagationWidget(QWidget *parent = 0) : QWidget(parent) |
|
3034 |
{ |
|
3035 |
QWidget *child = this; |
|
3036 |
for (int i=0; i<32; ++i) { |
|
3037 |
child = new QWidget(child); |
|
3038 |
child->setGeometry(i, i, 400 - i*2, 400 - i*2); |
|
3039 |
} |
|
3040 |
} |
|
3041 |
||
3042 |
void setContentsPropagation(bool enable) { |
|
3043 |
foreach (QObject *child, children()) |
|
3044 |
qobject_cast<QWidget *>(child)->setAutoFillBackground(!enable); |
|
3045 |
} |
|
3046 |
||
3047 |
protected: |
|
3048 |
void paintEvent(QPaintEvent *) |
|
3049 |
{ |
|
3050 |
int w = width(), h = height(); |
|
3051 |
drawPolygon(this, w, h); |
|
3052 |
} |
|
3053 |
||
3054 |
QSize sizeHint() const { return QSize(500, 500); } |
|
3055 |
}; |
|
3056 |
||
3057 |
void tst_QWidget::testContentsPropagation() |
|
3058 |
{ |
|
3059 |
#ifdef Q_WS_MAC |
|
3060 |
QSKIP("Pixmap is not antialiased whereas widget is.", SkipAll); |
|
3061 |
#endif |
|
3062 |
ContentsPropagationWidget widget; |
|
3063 |
#ifdef Q_WS_QWS |
|
3064 |
widget.resize(500,500); |
|
3065 |
#else |
|
3066 |
widget.setFixedSize(500, 500); |
|
3067 |
#endif |
|
3068 |
widget.setContentsPropagation(false); |
|
3069 |
QPixmap widgetSnapshot = QPixmap::grabWidget(&widget); |
|
3070 |
||
3071 |
QPixmap correct(500, 500); |
|
3072 |
drawPolygon(&correct, 500, 500); |
|
3073 |
//correct.save("correct.png", "PNG"); |
|
3074 |
||
3075 |
//widgetSnapshot.save("snap1.png", "PNG"); |
|
3076 |
QVERIFY(widgetSnapshot.toImage() != correct.toImage()); |
|
3077 |
||
3078 |
widget.setContentsPropagation(true); |
|
3079 |
widgetSnapshot = QPixmap::grabWidget(&widget); |
|
3080 |
//widgetSnapshot.save("snap2.png", "PNG"); |
|
3081 |
||
3082 |
QCOMPARE(widgetSnapshot, correct); |
|
3083 |
} |
|
3084 |
||
3085 |
/* |
|
3086 |
Test that saving and restoring window geometry with |
|
3087 |
saveGeometry() and restoreGeometry() works. |
|
3088 |
*/ |
|
3089 |
void tst_QWidget::saveRestoreGeometry() |
|
3090 |
{ |
|
3091 |
#ifdef Q_OS_IRIX |
|
3092 |
QSKIP("4DWM issues on IRIX makes this test fail", SkipAll); |
|
3093 |
#endif |
|
3094 |
const QPoint position(100, 100); |
|
3095 |
const QSize size(200, 200); |
|
3096 |
||
3097 |
QByteArray savedGeometry; |
|
3098 |
||
3099 |
{ |
|
3100 |
QWidget widget; |
|
3101 |
widget.move(position); |
|
3102 |
widget.resize(size); |
|
3103 |
widget.show(); |
|
3104 |
QTest::qWaitForWindowShown(&widget); |
|
3105 |
QApplication::processEvents(); |
|
3106 |
||
3107 |
QTRY_COMPARE(widget.pos(), position); |
|
3108 |
QCOMPARE(widget.size(), size); |
|
3109 |
savedGeometry = widget.saveGeometry(); |
|
3110 |
} |
|
3111 |
||
3112 |
{ |
|
3113 |
QWidget widget; |
|
3114 |
||
3115 |
const QByteArray empty; |
|
3116 |
const QByteArray one("a"); |
|
3117 |
const QByteArray two("ab"); |
|
3118 |
const QByteArray three("abc"); |
|
3119 |
const QByteArray four("abca"); |
|
3120 |
const QByteArray garbage("abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"); |
|
3121 |
||
3122 |
QVERIFY(widget.restoreGeometry(empty) == false); |
|
3123 |
QVERIFY(widget.restoreGeometry(one) == false); |
|
3124 |
QVERIFY(widget.restoreGeometry(two) == false); |
|
3125 |
QVERIFY(widget.restoreGeometry(three) == false); |
|
3126 |
QVERIFY(widget.restoreGeometry(four) == false); |
|
3127 |
QVERIFY(widget.restoreGeometry(garbage) == false); |
|
3128 |
||
3129 |
QVERIFY(widget.restoreGeometry(savedGeometry)); |
|
3130 |
widget.show(); |
|
3131 |
QTest::qWaitForWindowShown(&widget); |
|
3132 |
QApplication::processEvents(); |
|
3133 |
||
3134 |
QTRY_COMPARE(widget.pos(), position); |
|
3135 |
QCOMPARE(widget.size(), size); |
|
3136 |
widget.show(); |
|
3137 |
QCOMPARE(widget.pos(), position); |
|
3138 |
QCOMPARE(widget.size(), size); |
|
3139 |
} |
|
3140 |
||
3141 |
{ |
|
3142 |
QWidget widget; |
|
3143 |
widget.move(position); |
|
3144 |
widget.resize(size); |
|
3145 |
widget.show(); |
|
3146 |
QTest::qWaitForWindowShown(&widget); |
|
3147 |
QTest::qWait(500); |
|
3148 |
QTRY_COMPARE(widget.geometry().size(), size); |
|
3149 |
||
3150 |
QRect geom; |
|
3151 |
||
3152 |
//Restore from Full screen |
|
3153 |
savedGeometry = widget.saveGeometry(); |
|
3154 |
geom = widget.geometry(); |
|
3155 |
widget.setWindowState(widget.windowState() | Qt::WindowFullScreen); |
|
3156 |
QTRY_VERIFY((widget.windowState() & Qt::WindowFullScreen)); |
|
3157 |
QTest::qWait(500); |
|
3158 |
QVERIFY(widget.restoreGeometry(savedGeometry)); |
|
3159 |
QTest::qWait(120); |
|
3160 |
QTRY_VERIFY(!(widget.windowState() & Qt::WindowFullScreen)); |
|
3161 |
QTRY_COMPARE(widget.geometry(), geom); |
|
3162 |
||
3163 |
//Restore to full screen |
|
3164 |
widget.setWindowState(widget.windowState() | Qt::WindowFullScreen); |
|
3165 |
QTest::qWait(120); |
|
3166 |
QTRY_VERIFY((widget.windowState() & Qt::WindowFullScreen)); |
|
3167 |
QTest::qWait(500); |
|
3168 |
savedGeometry = widget.saveGeometry(); |
|
3169 |
geom = widget.geometry(); |
|
3170 |
widget.setWindowState(widget.windowState() ^ Qt::WindowFullScreen); |
|
3171 |
QTest::qWait(120); |
|
3172 |
QTRY_VERIFY(!(widget.windowState() & Qt::WindowFullScreen)); |
|
3173 |
QTest::qWait(400); |
|
3174 |
QVERIFY(widget.restoreGeometry(savedGeometry)); |
|
3175 |
QTest::qWait(120); |
|
3176 |
QTRY_VERIFY((widget.windowState() & Qt::WindowFullScreen)); |
|
3177 |
QTRY_COMPARE(widget.geometry(), geom); |
|
3178 |
QVERIFY((widget.windowState() & Qt::WindowFullScreen)); |
|
3179 |
widget.setWindowState(widget.windowState() ^ Qt::WindowFullScreen); |
|
3180 |
QTest::qWait(120); |
|
3181 |
QTRY_VERIFY(!(widget.windowState() & Qt::WindowFullScreen)); |
|
3182 |
QTest::qWait(120); |
|
3183 |
||
3184 |
//Restore from Maximised |
|
3185 |
widget.move(position); |
|
3186 |
widget.resize(size); |
|
3187 |
QTest::qWait(10); |
|
3188 |
QTRY_COMPARE(widget.size(), size); |
|
3189 |
QTest::qWait(500); |
|
3190 |
savedGeometry = widget.saveGeometry(); |
|
3191 |
geom = widget.geometry(); |
|
3192 |
widget.setWindowState(widget.windowState() | Qt::WindowMaximized); |
|
3193 |
QTest::qWait(120); |
|
3194 |
QTRY_VERIFY((widget.windowState() & Qt::WindowMaximized)); |
|
3195 |
QTRY_VERIFY(widget.geometry() != geom); |
|
3196 |
QTest::qWait(500); |
|
3197 |
QVERIFY(widget.restoreGeometry(savedGeometry)); |
|
3198 |
QTest::qWait(120); |
|
3199 |
QTRY_COMPARE(widget.geometry(), geom); |
|
3200 |
||
3201 |
QVERIFY(!(widget.windowState() & Qt::WindowMaximized)); |
|
3202 |
||
3203 |
//Restore to maximised |
|
3204 |
widget.setWindowState(widget.windowState() | Qt::WindowMaximized); |
|
3205 |
QTest::qWait(120); |
|
3206 |
QTRY_VERIFY((widget.windowState() & Qt::WindowMaximized)); |
|
3207 |
QTest::qWait(500); |
|
3208 |
geom = widget.geometry(); |
|
3209 |
savedGeometry = widget.saveGeometry(); |
|
3210 |
widget.setWindowState(widget.windowState() ^ Qt::WindowMaximized); |
|
3211 |
QTest::qWait(120); |
|
3212 |
QTRY_VERIFY(!(widget.windowState() & Qt::WindowMaximized)); |
|
3213 |
QTest::qWait(500); |
|
3214 |
QVERIFY(widget.restoreGeometry(savedGeometry)); |
|
3215 |
QTest::qWait(120); |
|
3216 |
QTRY_VERIFY((widget.windowState() & Qt::WindowMaximized)); |
|
3217 |
QTRY_COMPARE(widget.geometry(), geom); |
|
3218 |
} |
|
3219 |
} |
|
3220 |
||
3221 |
void tst_QWidget::restoreVersion1Geometry_data() |
|
3222 |
{ |
|
3223 |
QTest::addColumn<QString>("fileName"); |
|
3224 |
QTest::addColumn<uint>("expectedWindowState"); |
|
3225 |
QTest::addColumn<QPoint>("expectedPosition"); |
|
3226 |
QTest::addColumn<QSize>("expectedSize"); |
|
3227 |
QTest::addColumn<QRect>("expectedNormalGeometry"); |
|
3228 |
const QPoint position(100, 100); |
|
3229 |
const QSize size(200, 200); |
|
3230 |
const QRect normalGeometry(102, 124, 200, 200); |
|
3231 |
||
3232 |
QTest::newRow("geometry.dat") << ":geometry.dat" << uint(Qt::WindowNoState) << position << size << normalGeometry; |
|
3233 |
QTest::newRow("geometry-maximized.dat") << ":geometry-maximized.dat" << uint(Qt::WindowMaximized) << position << size << normalGeometry; |
|
3234 |
QTest::newRow("geometry-fullscreen.dat") << ":geometry-fullscreen.dat" << uint(Qt::WindowFullScreen) << position << size << normalGeometry; |
|
3235 |
} |
|
3236 |
||
3237 |
/* |
|
3238 |
Test that the current version of restoreGeometry() can restore geometry |
|
3239 |
saved width saveGeometry() version 1.0. |
|
3240 |
*/ |
|
3241 |
void tst_QWidget::restoreVersion1Geometry() |
|
3242 |
{ |
|
3243 |
#ifdef Q_OS_IRIX |
|
3244 |
QSKIP("4DWM issues on IRIX makes this test fail", SkipAll); |
|
3245 |
#endif |
|
3246 |
||
3247 |
QFETCH(QString, fileName); |
|
3248 |
QFETCH(uint, expectedWindowState); |
|
3249 |
QFETCH(QPoint, expectedPosition); |
|
3250 |
QFETCH(QSize, expectedSize); |
|
3251 |
QFETCH(QRect, expectedNormalGeometry); |
|
3252 |
||
3253 |
// WindowActive is uninteresting for this test |
|
3254 |
const uint WindowStateMask = Qt::WindowFullScreen | Qt::WindowMaximized | Qt::WindowMinimized; |
|
3255 |
||
3256 |
QFile f(fileName); |
|
3257 |
QVERIFY(f.exists()); |
|
3258 |
f.open(QIODevice::ReadOnly); |
|
3259 |
const QByteArray savedGeometry = f.readAll(); |
|
3260 |
QCOMPARE(savedGeometry.count(), 46); |
|
3261 |
f.close(); |
|
3262 |
||
3263 |
QWidget widget; |
|
3264 |
||
3265 |
QVERIFY(widget.restoreGeometry(savedGeometry)); |
|
3266 |
||
3267 |
QCOMPARE(uint(widget.windowState() & WindowStateMask), expectedWindowState); |
|
3268 |
if (expectedWindowState == Qt::WindowNoState) { |
|
3269 |
QCOMPARE(widget.pos(), expectedPosition); |
|
3270 |
QCOMPARE(widget.size(), expectedSize); |
|
3271 |
} |
|
3272 |
widget.show(); |
|
3273 |
QTest::qWaitForWindowShown(&widget); |
|
3274 |
QTest::qWait(100); |
|
3275 |
||
3276 |
if (expectedWindowState == Qt::WindowNoState) { |
|
3277 |
QTRY_COMPARE(widget.pos(), expectedPosition); |
|
3278 |
QTRY_COMPARE(widget.size(), expectedSize); |
|
3279 |
} |
|
3280 |
||
3281 |
widget.showNormal(); |
|
3282 |
QTest::qWait(10); |
|
3283 |
||
3284 |
if (expectedWindowState != Qt::WindowNoState) { |
|
3285 |
// restoring from maximized or fullscreen, we can only restore to the normal geometry |
|
3286 |
QTRY_COMPARE(widget.geometry(), expectedNormalGeometry); |
|
3287 |
} else { |
|
3288 |
QTRY_COMPARE(widget.pos(), expectedPosition); |
|
3289 |
QTRY_COMPARE(widget.size(), expectedSize); |
|
3290 |
} |
|
3291 |
||
3292 |
#if 0 |
|
3293 |
// Code for saving a new geometry*.dat files |
|
3294 |
{ |
|
3295 |
QWidget widgetToSave; |
|
3296 |
widgetToSave.move(expectedPosition); |
|
3297 |
widgetToSave.resize(expectedSize); |
|
3298 |
widgetToSave.show(); |
|
3299 |
#ifdef Q_WS_X11 |
|
3300 |
qt_x11_wait_for_window_manager(&widget); |
|
3301 |
#endif |
|
3302 |
QTest::qWait(500); // stabilize |
|
3303 |
widgetToSave.setWindowState(Qt::WindowStates(expectedWindowState)); |
|
3304 |
QTest::qWait(500); // stabilize |
|
3305 |
||
3306 |
QByteArray geometryToSave = widgetToSave.saveGeometry(); |
|
3307 |
||
3308 |
// Code for saving a new geometry.dat file. |
|
3309 |
f.setFileName(fileName.mid(1)); |
|
3310 |
QVERIFY(f.open(QIODevice::WriteOnly)); // did you forget to 'p4 edit *.dat'? :) |
|
3311 |
f.write(geometryToSave); |
|
3312 |
f.close(); |
|
3313 |
} |
|
3314 |
#endif |
|
3315 |
||
3316 |
} |
|
3317 |
||
3318 |
void tst_QWidget::widgetAt() |
|
3319 |
{ |
|
3320 |
Q_CHECK_PAINTEVENTS |
|
3321 |
||
3322 |
QWidget *w1 = new QWidget(0, Qt::X11BypassWindowManagerHint); |
|
3323 |
w1->setGeometry(0,0,150,150); |
|
3324 |
w1->setObjectName("w1"); |
|
3325 |
||
3326 |
QWidget *w2 = new QWidget(0, Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); |
|
3327 |
w2->setGeometry(50,50,100,100); |
|
3328 |
w2->setObjectName("w2"); |
|
3329 |
w1->show(); |
|
3330 |
QTest::qWaitForWindowShown(w1); |
|
3331 |
qApp->processEvents(); |
|
3332 |
QWidget *wr; |
|
3333 |
QTRY_VERIFY((wr = QApplication::widgetAt(100, 100))); |
|
3334 |
QCOMPARE(wr->objectName(), QString("w1")); |
|
3335 |
||
3336 |
w2->show(); |
|
3337 |
QTest::qWaitForWindowShown(w2); |
|
3338 |
qApp->processEvents(); |
|
3339 |
qApp->processEvents(); |
|
3340 |
qApp->processEvents(); |
|
3341 |
QTRY_VERIFY((wr = QApplication::widgetAt(100, 100))); |
|
3342 |
QCOMPARE(wr->objectName(), QString("w2")); |
|
3343 |
||
3344 |
w2->lower(); |
|
3345 |
qApp->processEvents(); |
|
3346 |
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
|
3347 |
const bool match = (wr->objectName() == QString("w1")); |
0 | 3348 |
w2->raise(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3349 |
QVERIFY(match); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3350 |
|
0 | 3351 |
qApp->processEvents(); |
3352 |
QTRY_VERIFY((wr = QApplication::widgetAt(100, 100))); |
|
3353 |
QCOMPARE(wr->objectName(), QString("w2")); |
|
3354 |
||
3355 |
||
3356 |
QWidget *w3 = new QWidget(w2); |
|
3357 |
w3->setGeometry(10,10,50,50); |
|
3358 |
w3->setObjectName("w3"); |
|
3359 |
w3->show(); |
|
3360 |
qApp->processEvents(); |
|
3361 |
QTRY_VERIFY((wr = QApplication::widgetAt(100,100))); |
|
3362 |
QCOMPARE(wr->objectName(), QString("w3")); |
|
3363 |
||
3364 |
w3->setAttribute(Qt::WA_TransparentForMouseEvents); |
|
3365 |
qApp->processEvents(); |
|
3366 |
QTRY_VERIFY((wr = QApplication::widgetAt(100, 100))); |
|
3367 |
QCOMPARE(wr->objectName(), QString("w2")); |
|
3368 |
||
3369 |
QRegion rgn = QRect(QPoint(0,0), w2->size()); |
|
3370 |
QPoint point = w2->mapFromGlobal(QPoint(100,100)); |
|
3371 |
rgn -= QRect(point, QSize(1,1)); |
|
3372 |
w2->setMask(rgn); |
|
3373 |
qApp->processEvents(); |
|
3374 |
QTest::qWait(10); |
|
3375 |
#if defined(Q_OS_WINCE) |
|
3376 |
QEXPECT_FAIL("", "Windows CE does only support rectangular regions", Continue); //See also task 147191 |
|
3377 |
#endif |
|
3378 |
#if defined(Q_OS_SYMBIAN) |
|
3379 |
QEXPECT_FAIL("", "Symbian/S60 does only support rectangular regions", Continue); //See also task 147191 |
|
3380 |
#endif |
|
3381 |
QTRY_COMPARE(QApplication::widgetAt(100,100)->objectName(), w1->objectName()); |
|
3382 |
QTRY_COMPARE(QApplication::widgetAt(101,101)->objectName(), w2->objectName()); |
|
3383 |
||
3384 |
QBitmap bitmap(w2->size()); |
|
3385 |
QPainter p(&bitmap); |
|
3386 |
p.fillRect(bitmap.rect(), Qt::color1); |
|
3387 |
p.setPen(Qt::color0); |
|
3388 |
p.drawPoint(w2->mapFromGlobal(QPoint(100,100))); |
|
3389 |
p.end(); |
|
3390 |
w2->setMask(bitmap); |
|
3391 |
qApp->processEvents(); |
|
3392 |
QTest::qWait(10); |
|
3393 |
#if defined(Q_OS_WINCE) |
|
3394 |
QEXPECT_FAIL("", "Windows CE does only support rectangular regions", Continue); //See also task 147191 |
|
3395 |
#endif |
|
3396 |
#if defined(Q_OS_SYMBIAN) |
|
3397 |
QEXPECT_FAIL("", "Symbian/S60 does only support rectangular regions", Continue); //See also task 147191 |
|
3398 |
#endif |
|
3399 |
QTRY_VERIFY(QApplication::widgetAt(100,100) == w1); |
|
3400 |
QTRY_VERIFY(QApplication::widgetAt(101,101) == w2); |
|
3401 |
||
3402 |
delete w2; |
|
3403 |
delete w1; |
|
3404 |
} |
|
3405 |
||
3406 |
#if defined(Q_WS_X11) |
|
3407 |
bool getProperty(Display *display, Window target, Atom type, Atom property, |
|
3408 |
unsigned char** data, unsigned long* count) |
|
3409 |
{ |
|
3410 |
Atom atom_return; |
|
3411 |
int size; |
|
3412 |
unsigned long nitems, bytes_left; |
|
3413 |
||
3414 |
int ret = XGetWindowProperty(display, target, property, |
|
3415 |
0l, 1l, false, |
|
3416 |
type, &atom_return, &size, |
|
3417 |
&nitems, &bytes_left, data); |
|
3418 |
if (ret != Success || nitems < 1) |
|
3419 |
return false; |
|
3420 |
||
3421 |
if (bytes_left != 0) { |
|
3422 |
XFree(*data); |
|
3423 |
unsigned long remain = ((size / 8) * nitems) + bytes_left; |
|
3424 |
ret = XGetWindowProperty(display, target, |
|
3425 |
property, 0l, remain, false, |
|
3426 |
type, &atom_return, &size, |
|
3427 |
&nitems, &bytes_left, data); |
|
3428 |
if (ret != Success) |
|
3429 |
return false; |
|
3430 |
} |
|
3431 |
||
3432 |
*count = nitems; |
|
3433 |
return true; |
|
3434 |
} |
|
3435 |
||
3436 |
QString textPropertyToString(Display *display, XTextProperty& text_prop) |
|
3437 |
{ |
|
3438 |
QString ret; |
|
3439 |
if (text_prop.value && text_prop.nitems > 0) { |
|
3440 |
if (text_prop.encoding == XA_STRING) { |
|
3441 |
ret = reinterpret_cast<char *>(text_prop.value); |
|
3442 |
} else { |
|
3443 |
text_prop.nitems = strlen(reinterpret_cast<char *>(text_prop.value)); |
|
3444 |
char **list; |
|
3445 |
int num; |
|
3446 |
if (XmbTextPropertyToTextList(display, &text_prop, &list, &num) == Success |
|
3447 |
&& num > 0 && *list) { |
|
3448 |
ret = QString::fromLocal8Bit(*list); |
|
3449 |
XFreeStringList(list); |
|
3450 |
} |
|
3451 |
} |
|
3452 |
} |
|
3453 |
return ret; |
|
3454 |
} |
|
3455 |
||
3456 |
#endif |
|
3457 |
||
3458 |
#if defined(Q_WS_S60) |
|
3459 |
// Returns the application's status pane control, if not present returns NULL. |
|
3460 |
static CCoeControl* GetStatusPaneControl( TInt aPaneId ) |
|
3461 |
{ |
|
3462 |
const TUid paneUid = { aPaneId }; |
|
3463 |
||
3464 |
CEikStatusPane* statusPane = CEikonEnv::Static()->AppUiFactory()->StatusPane(); |
|
3465 |
if (statusPane && statusPane->PaneCapabilities(paneUid).IsPresent()){ |
|
3466 |
CCoeControl* control = NULL; |
|
3467 |
// ControlL shouldn't leave because the pane is present |
|
3468 |
TRAPD(err, control = statusPane->ControlL(paneUid)); |
|
3469 |
return err != KErrNone ? NULL : control; |
|
3470 |
} |
|
3471 |
return NULL; |
|
3472 |
} |
|
3473 |
// Returns the application's title pane, if not present returns NULL. |
|
3474 |
static CAknTitlePane* TitlePane() |
|
3475 |
{ |
|
3476 |
return static_cast<CAknTitlePane*>(GetStatusPaneControl(EEikStatusPaneUidTitle)); |
|
3477 |
} |
|
3478 |
||
3479 |
// Returns the application's title pane, if not present returns NULL. |
|
3480 |
static CAknContextPane* ContextPane() |
|
3481 |
{ |
|
3482 |
return static_cast<CAknContextPane*>(GetStatusPaneControl(EEikStatusPaneUidContext)); |
|
3483 |
} |
|
3484 |
#endif |
|
3485 |
||
3486 |
static QString visibleWindowTitle(QWidget *window, Qt::WindowState state = Qt::WindowNoState) |
|
3487 |
{ |
|
3488 |
QString vTitle; |
|
3489 |
||
3490 |
#ifdef Q_WS_WIN |
|
3491 |
Q_UNUSED(state); |
|
3492 |
const size_t maxTitleLength = 256; |
|
3493 |
wchar_t title[maxTitleLength]; |
|
3494 |
GetWindowText(window->winId(), title, maxTitleLength); |
|
3495 |
vTitle = QString::fromWCharArray(title); |
|
3496 |
#elif defined(Q_WS_X11) |
|
3497 |
/* |
|
3498 |
We can't check what the window manager displays, but we can |
|
3499 |
check what we tell the window manager to display. This will |
|
3500 |
have to do. |
|
3501 |
*/ |
|
3502 |
Atom UTF8_STRING = XInternAtom(window->x11Info().display(), "UTF8_STRING", false); |
|
3503 |
Atom _NET_WM_NAME = XInternAtom(window->x11Info().display(), "_NET_WM_NAME", false); |
|
3504 |
Atom _NET_WM_ICON_NAME = XInternAtom(window->x11Info().display(), "_NET_WM_ICON_NAME", false); |
|
3505 |
uchar *data = 0; |
|
3506 |
ulong length = 0; |
|
3507 |
if (state == Qt::WindowMinimized) { |
|
3508 |
if (getProperty(window->x11Info().display(), window->winId(), |
|
3509 |
UTF8_STRING, _NET_WM_ICON_NAME, &data, &length)) { |
|
3510 |
vTitle = QString::fromUtf8((char *) data, length); |
|
3511 |
XFree(data); |
|
3512 |
} else { |
|
3513 |
XTextProperty text_prop; |
|
3514 |
if (XGetWMIconName(window->x11Info().display(), window->winId(), &text_prop)) { |
|
3515 |
vTitle = textPropertyToString(window->x11Info().display(), text_prop); |
|
3516 |
XFree((char *) text_prop.value); |
|
3517 |
} |
|
3518 |
} |
|
3519 |
} else { |
|
3520 |
if (getProperty(window->x11Info().display(), window->winId(), |
|
3521 |
UTF8_STRING, _NET_WM_NAME, &data, &length)) { |
|
3522 |
vTitle = QString::fromUtf8((char *) data, length); |
|
3523 |
XFree(data); |
|
3524 |
} else { |
|
3525 |
XTextProperty text_prop; |
|
3526 |
if (XGetWMName(window->x11Info().display(), window->winId(), &text_prop)) { |
|
3527 |
vTitle = textPropertyToString(window->x11Info().display(), text_prop); |
|
3528 |
XFree((char *) text_prop.value); |
|
3529 |
} |
|
3530 |
} |
|
3531 |
} |
|
3532 |
#elif defined(Q_WS_MAC) |
|
3533 |
vTitle = nativeWindowTitle(window, state); |
|
3534 |
#elif defined(Q_WS_QWS) |
|
3535 |
if (qwsServer) { |
|
3536 |
const QWSWindow *win = 0; |
|
3537 |
const QList<QWSWindow*> windows = qwsServer->clientWindows(); |
|
3538 |
for (int i = 0; i < windows.count(); ++i) { |
|
3539 |
const QWSWindow* w = windows.at(i); |
|
3540 |
if (w->winId() == window->winId()) { |
|
3541 |
win = w; |
|
3542 |
break; |
|
3543 |
} |
|
3544 |
} |
|
3545 |
if (win) |
|
3546 |
vTitle = win->caption(); |
|
3547 |
} |
|
3548 |
#elif defined (Q_WS_S60) |
|
3549 |
CAknTitlePane* titlePane = TitlePane(); |
|
3550 |
if(titlePane) |
|
3551 |
{ |
|
3552 |
const TDesC* nTitle = titlePane->Text(); |
|
3553 |
vTitle = QString::fromUtf16(nTitle->Ptr(), nTitle->Length()); |
|
3554 |
} |
|
3555 |
#endif |
|
3556 |
||
3557 |
return vTitle; |
|
3558 |
} |
|
3559 |
||
3560 |
void tst_QWidget::windowTitle() |
|
3561 |
{ |
|
3562 |
QWidget widget(0); |
|
3563 |
widget.setWindowTitle("Application Name"); |
|
3564 |
widget.winId(); // Make sure the window is created... |
|
3565 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3566 |
||
3567 |
widget.setWindowTitle("Application Name *"); |
|
3568 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name *")); |
|
3569 |
||
3570 |
widget.setWindowTitle("Application Name[*]"); |
|
3571 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3572 |
||
3573 |
widget.setWindowTitle("Application Name[*][*]"); |
|
3574 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name[*]")); |
|
3575 |
||
3576 |
widget.setWindowTitle("Application Name[*][*][*]"); |
|
3577 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name[*]")); |
|
3578 |
||
3579 |
widget.setWindowTitle("Application Name[*][*][*][*]"); |
|
3580 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name[*][*]")); |
|
3581 |
} |
|
3582 |
||
3583 |
void tst_QWidget::windowIconText() |
|
3584 |
{ |
|
3585 |
#ifdef Q_OS_SYMBIAN |
|
3586 |
QSKIP("Symbian/S60 windows don't have window icon text", SkipAll); |
|
3587 |
#endif |
|
3588 |
QWidget widget(0); |
|
3589 |
||
3590 |
widget.setWindowTitle("Application Name"); |
|
3591 |
widget.setWindowIconText("Application Minimized"); |
|
3592 |
widget.showNormal(); |
|
3593 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3594 |
widget.showMinimized(); |
|
3595 |
#if defined(Q_WS_QWS) || defined(Q_OS_WINCE) |
|
3596 |
QEXPECT_FAIL(0, "Qt/Embedded/WinCE does not implement showMinimized()", Continue); |
|
3597 |
//See task 147193 for WinCE |
|
3598 |
#endif |
|
3599 |
QApplication::instance()->processEvents(); |
|
3600 |
QCOMPARE(visibleWindowTitle(&widget, Qt::WindowMinimized), |
|
3601 |
QString("Application Minimized")); |
|
3602 |
||
3603 |
widget.setWindowTitle("Application Name[*]"); |
|
3604 |
widget.setWindowIconText("Application Minimized[*]"); |
|
3605 |
widget.showNormal(); |
|
3606 |
QApplication::instance()->processEvents(); |
|
3607 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3608 |
widget.showMinimized(); |
|
3609 |
#if defined (Q_WS_QWS) || defined(Q_OS_WINCE) |
|
3610 |
QEXPECT_FAIL(0, "Qt/Embedded/WinCE does not implement showMinimized()", Continue); |
|
3611 |
//See task 147193 for WinCE |
|
3612 |
#endif |
|
3613 |
QApplication::instance()->processEvents(); |
|
3614 |
QCOMPARE(visibleWindowTitle(&widget, Qt::WindowMinimized), |
|
3615 |
QString("Application Minimized")); |
|
3616 |
||
3617 |
widget.setWindowModified(true); |
|
3618 |
widget.showNormal(); |
|
3619 |
QApplication::instance()->processEvents(); |
|
3620 |
if (widget.style()->styleHint(QStyle::SH_TitleBar_ModifyNotification, 0, &widget)) |
|
3621 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name*")); |
|
3622 |
else |
|
3623 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3624 |
widget.showMinimized(); |
|
3625 |
#if defined (Q_WS_QWS) || defined(Q_OS_WINCE) |
|
3626 |
QEXPECT_FAIL(0, "Qt/Embedded/WinCE does not implement showMinimized()", Continue); |
|
3627 |
//See task 147193 for WinCE |
|
3628 |
#endif |
|
3629 |
QApplication::instance()->processEvents(); |
|
3630 |
#ifdef Q_WS_MAC |
|
3631 |
QCOMPARE(visibleWindowTitle(&widget, Qt::WindowMinimized), |
|
3632 |
QString("Application Minimized")); |
|
3633 |
QVERIFY(nativeWindowModified(&widget)); |
|
3634 |
#else |
|
3635 |
QCOMPARE(visibleWindowTitle(&widget, Qt::WindowMinimized), |
|
3636 |
QString("Application Minimized*")); |
|
3637 |
#endif |
|
3638 |
} |
|
3639 |
||
3640 |
void tst_QWidget::windowModified() |
|
3641 |
{ |
|
3642 |
QWidget widget(0); |
|
3643 |
widget.show(); |
|
3644 |
QTest::qWaitForWindowShown(&widget); |
|
3645 |
#ifndef Q_WS_MAC |
|
3646 |
QTest::ignoreMessage(QtWarningMsg, "QWidget::setWindowModified: The window title does not contain a '[*]' placeholder"); |
|
3647 |
#endif |
|
3648 |
widget.setWindowTitle("Application Name"); |
|
3649 |
QTest::qWait(10); |
|
3650 |
QTRY_COMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3651 |
||
3652 |
#ifdef Q_WS_MAC |
|
3653 |
widget.setWindowModified(true); |
|
3654 |
QVERIFY(nativeWindowModified(&widget)); |
|
3655 |
#else |
|
3656 |
widget.setWindowModified(true); |
|
3657 |
QApplication::instance()->processEvents(); |
|
3658 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3659 |
||
3660 |
widget.setWindowModified(false); |
|
3661 |
QApplication::instance()->processEvents(); |
|
3662 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3663 |
||
3664 |
widget.setWindowTitle("Application Name[*]"); |
|
3665 |
||
3666 |
widget.setWindowModified(true); |
|
3667 |
QApplication::instance()->processEvents(); |
|
3668 |
if (widget.style()->styleHint(QStyle::SH_TitleBar_ModifyNotification, 0, &widget)) |
|
3669 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name*")); |
|
3670 |
else |
|
3671 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3672 |
||
3673 |
widget.setWindowModified(false); |
|
3674 |
QApplication::instance()->processEvents(); |
|
3675 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3676 |
||
3677 |
widget.setWindowTitle("Application[*] Name[*]"); |
|
3678 |
||
3679 |
widget.setWindowModified(true); |
|
3680 |
QApplication::instance()->processEvents(); |
|
3681 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application* Name*")); |
|
3682 |
||
3683 |
widget.setWindowModified(false); |
|
3684 |
QApplication::instance()->processEvents(); |
|
3685 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name")); |
|
3686 |
||
3687 |
widget.setWindowTitle("Application Name[*][*]"); |
|
3688 |
||
3689 |
widget.setWindowModified(true); |
|
3690 |
QApplication::instance()->processEvents(); |
|
3691 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name[*]")); |
|
3692 |
||
3693 |
widget.setWindowModified(false); |
|
3694 |
QApplication::instance()->processEvents(); |
|
3695 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name[*]")); |
|
3696 |
||
3697 |
widget.setWindowTitle("Application[*][*] Name[*][*]"); |
|
3698 |
||
3699 |
widget.setWindowModified(true); |
|
3700 |
QApplication::instance()->processEvents(); |
|
3701 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application[*] Name[*]")); |
|
3702 |
||
3703 |
widget.setWindowModified(false); |
|
3704 |
QApplication::instance()->processEvents(); |
|
3705 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application[*] Name[*]")); |
|
3706 |
||
3707 |
widget.setWindowTitle("Application[*] Name[*][*][*]"); |
|
3708 |
||
3709 |
widget.setWindowModified(true); |
|
3710 |
QApplication::instance()->processEvents(); |
|
3711 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application* Name[*]*")); |
|
3712 |
||
3713 |
widget.setWindowModified(false); |
|
3714 |
QApplication::instance()->processEvents(); |
|
3715 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application Name[*]")); |
|
3716 |
||
3717 |
widget.setWindowTitle("Application[*][*][*] Name[*][*][*]"); |
|
3718 |
||
3719 |
widget.setWindowModified(true); |
|
3720 |
QApplication::instance()->processEvents(); |
|
3721 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application[*]* Name[*]*")); |
|
3722 |
||
3723 |
widget.setWindowModified(false); |
|
3724 |
QApplication::instance()->processEvents(); |
|
3725 |
QCOMPARE(visibleWindowTitle(&widget), QString("Application[*] Name[*]")); |
|
3726 |
#endif |
|
3727 |
} |
|
3728 |
||
3729 |
void tst_QWidget::task110173() |
|
3730 |
{ |
|
3731 |
QWidget w; |
|
3732 |
||
3733 |
QPushButton *pb1 = new QPushButton("click", &w); |
|
3734 |
pb1->setFocusPolicy(Qt::ClickFocus); |
|
3735 |
pb1->move(100, 100); |
|
3736 |
||
3737 |
QPushButton *pb2 = new QPushButton("push", &w); |
|
3738 |
pb2->setFocusPolicy(Qt::ClickFocus); |
|
3739 |
pb2->move(300, 300); |
|
3740 |
||
3741 |
QTest::keyClick( &w, Qt::Key_Tab ); |
|
3742 |
w.show(); |
|
3743 |
QTest::qWaitForWindowShown(&w); |
|
3744 |
QTest::qWait(200); |
|
3745 |
} |
|
3746 |
||
3747 |
class Widget : public QWidget |
|
3748 |
{ |
|
3749 |
public: |
|
3750 |
Widget() : deleteThis(false) { setFocusPolicy(Qt::StrongFocus); } |
|
3751 |
void actionEvent(QActionEvent *) { if (deleteThis) delete this; } |
|
3752 |
void changeEvent(QEvent *) { if (deleteThis) delete this; } |
|
3753 |
void closeEvent(QCloseEvent *) { if (deleteThis) delete this; } |
|
3754 |
void hideEvent(QHideEvent *) { if (deleteThis) delete this; } |
|
3755 |
void focusOutEvent(QFocusEvent *) { if (deleteThis) delete this; } |
|
3756 |
void keyPressEvent(QKeyEvent *) { if (deleteThis) delete this; } |
|
3757 |
void keyReleaseEvent(QKeyEvent *) { if (deleteThis) delete this; } |
|
3758 |
void mouseDoubleClickEvent(QMouseEvent *) { if (deleteThis) delete this; } |
|
3759 |
void mousePressEvent(QMouseEvent *) { if (deleteThis) delete this; } |
|
3760 |
void mouseReleaseEvent(QMouseEvent *) { if (deleteThis) delete this; } |
|
3761 |
void mouseMoveEvent(QMouseEvent *) { if (deleteThis) delete this; } |
|
3762 |
||
3763 |
bool deleteThis; |
|
3764 |
}; |
|
3765 |
||
3766 |
void tst_QWidget::testDeletionInEventHandlers() |
|
3767 |
{ |
|
3768 |
// closeEvent |
|
3769 |
QPointer<Widget> w = new Widget; |
|
3770 |
w->deleteThis = true; |
|
3771 |
w->close(); |
|
3772 |
QVERIFY(w == 0); |
|
3773 |
delete w; |
|
3774 |
||
3775 |
// focusOut (crashes) |
|
3776 |
//w = new Widget; |
|
3777 |
//w->show(); |
|
3778 |
//w->setFocus(); |
|
3779 |
//QVERIFY(qApp->focusWidget() == w); |
|
3780 |
//w->deleteThis = true; |
|
3781 |
//w->clearFocus(); |
|
3782 |
//QVERIFY(w == 0); |
|
3783 |
||
3784 |
// key press |
|
3785 |
w = new Widget; |
|
3786 |
w->show(); |
|
3787 |
w->deleteThis = true; |
|
3788 |
QTest::keyPress(w, Qt::Key_A); |
|
3789 |
QVERIFY(w == 0); |
|
3790 |
delete w; |
|
3791 |
||
3792 |
// key release |
|
3793 |
w = new Widget; |
|
3794 |
w->show(); |
|
3795 |
w->deleteThis = true; |
|
3796 |
QTest::keyRelease(w, Qt::Key_A); |
|
3797 |
QVERIFY(w == 0); |
|
3798 |
delete w; |
|
3799 |
||
3800 |
// mouse press |
|
3801 |
w = new Widget; |
|
3802 |
w->show(); |
|
3803 |
w->deleteThis = true; |
|
3804 |
QTest::mousePress(w, Qt::LeftButton); |
|
3805 |
QVERIFY(w == 0); |
|
3806 |
delete w; |
|
3807 |
||
3808 |
// mouse release |
|
3809 |
w = new Widget; |
|
3810 |
w->show(); |
|
3811 |
w->deleteThis = true; |
|
3812 |
QTest::mouseRelease(w, Qt::LeftButton); |
|
3813 |
QVERIFY(w == 0); |
|
3814 |
delete w; |
|
3815 |
||
3816 |
// mouse double click |
|
3817 |
w = new Widget; |
|
3818 |
w->show(); |
|
3819 |
w->deleteThis = true; |
|
3820 |
QTest::mouseDClick(w, Qt::LeftButton); |
|
3821 |
QVERIFY(w == 0); |
|
3822 |
delete w; |
|
3823 |
||
3824 |
// hide event (crashes) |
|
3825 |
//w = new Widget; |
|
3826 |
//w->show(); |
|
3827 |
//w->deleteThis = true; |
|
3828 |
//w->hide(); |
|
3829 |
//QVERIFY(w == 0); |
|
3830 |
||
3831 |
// action event |
|
3832 |
w = new Widget; |
|
3833 |
w->deleteThis = true; |
|
3834 |
w->addAction(new QAction(w)); |
|
3835 |
QVERIFY(w == 0); |
|
3836 |
delete w; |
|
3837 |
||
3838 |
// change event |
|
3839 |
w = new Widget; |
|
3840 |
w->show(); |
|
3841 |
w->deleteThis = true; |
|
3842 |
w->setMouseTracking(true); |
|
3843 |
QVERIFY(w == 0); |
|
3844 |
delete w; |
|
3845 |
||
3846 |
w = new Widget; |
|
3847 |
w->setMouseTracking(true); |
|
3848 |
w->show(); |
|
3849 |
w->deleteThis = true; |
|
3850 |
QMouseEvent me(QEvent::MouseMove, QPoint(0, 0), Qt::NoButton, Qt::NoButton, Qt::NoModifier); |
|
3851 |
QApplication::sendEvent(w, &me); |
|
3852 |
QVERIFY(w == 0); |
|
3853 |
delete w; |
|
3854 |
} |
|
3855 |
||
3856 |
#ifdef Q_WS_MAC |
|
3857 |
||
3858 |
bool testAndRelease(const HIViewRef view) |
|
3859 |
{ |
|
3860 |
// qDebug() << CFGetRetainCount(view); |
|
3861 |
if (CFGetRetainCount(view) != 2) |
|
3862 |
return false; |
|
3863 |
CFRelease(view); |
|
3864 |
CFRelease(view); |
|
3865 |
return true; |
|
3866 |
} |
|
3867 |
||
3868 |
typedef QPair<QWidget *, HIViewRef> WidgetViewPair; |
|
3869 |
||
3870 |
WidgetViewPair createAndRetain(QWidget * const parent = 0) |
|
3871 |
{ |
|
3872 |
QWidget * const widget = new QWidget(parent); |
|
3873 |
const HIViewRef view = (HIViewRef)widget->winId(); |
|
3874 |
// Retain twice so we can safely call CFGetRetaintCount even if the retain count |
|
3875 |
// is off by one because of a double release. |
|
3876 |
CFRetain(view); |
|
3877 |
CFRetain(view); |
|
3878 |
return qMakePair(widget, view); |
|
3879 |
} |
|
3880 |
||
3881 |
/* |
|
3882 |
Test that retaining and releasing the HIView returned by QWidget::winId() |
|
3883 |
works even if the widget itself is deleted. |
|
3884 |
*/ |
|
3885 |
void tst_QWidget::retainHIView() |
|
3886 |
{ |
|
3887 |
// Single window |
|
3888 |
{ |
|
3889 |
const WidgetViewPair window = createAndRetain(); |
|
3890 |
delete window.first; |
|
3891 |
QVERIFY(testAndRelease(window.second)); |
|
3892 |
} |
|
3893 |
||
3894 |
// Child widget |
|
3895 |
{ |
|
3896 |
const WidgetViewPair parent = createAndRetain(); |
|
3897 |
const WidgetViewPair child = createAndRetain(parent.first); |
|
3898 |
||
3899 |
delete parent.first; |
|
3900 |
QVERIFY(testAndRelease(parent.second)); |
|
3901 |
QVERIFY(testAndRelease(child.second)); |
|
3902 |
} |
|
3903 |
||
3904 |
// Multiple children |
|
3905 |
{ |
|
3906 |
const WidgetViewPair parent = createAndRetain(); |
|
3907 |
const WidgetViewPair child1 = createAndRetain(parent.first); |
|
3908 |
const WidgetViewPair child2 = createAndRetain(parent.first); |
|
3909 |
||
3910 |
delete parent.first; |
|
3911 |
QVERIFY(testAndRelease(parent.second)); |
|
3912 |
QVERIFY(testAndRelease(child1.second)); |
|
3913 |
QVERIFY(testAndRelease(child2.second)); |
|
3914 |
} |
|
3915 |
||
3916 |
// Grandchild widget |
|
3917 |
{ |
|
3918 |
const WidgetViewPair parent = createAndRetain(); |
|
3919 |
const WidgetViewPair child = createAndRetain(parent.first); |
|
3920 |
const WidgetViewPair grandchild = createAndRetain(child.first); |
|
3921 |
||
3922 |
delete parent.first; |
|
3923 |
QVERIFY(testAndRelease(parent.second)); |
|
3924 |
QVERIFY(testAndRelease(child.second)); |
|
3925 |
QVERIFY(testAndRelease(grandchild.second)); |
|
3926 |
} |
|
3927 |
||
3928 |
// Reparent child widget |
|
3929 |
{ |
|
3930 |
const WidgetViewPair parent1 = createAndRetain(); |
|
3931 |
const WidgetViewPair parent2 = createAndRetain(); |
|
3932 |
const WidgetViewPair child = createAndRetain(parent1.first); |
|
3933 |
||
3934 |
child.first->setParent(parent2.first); |
|
3935 |
||
3936 |
delete parent1.first; |
|
3937 |
QVERIFY(testAndRelease(parent1.second)); |
|
3938 |
delete parent2.first; |
|
3939 |
QVERIFY(testAndRelease(parent2.second)); |
|
3940 |
QVERIFY(testAndRelease(child.second)); |
|
3941 |
} |
|
3942 |
||
3943 |
// Reparent window |
|
3944 |
{ |
|
3945 |
const WidgetViewPair window1 = createAndRetain(); |
|
3946 |
const WidgetViewPair window2 = createAndRetain(); |
|
3947 |
const WidgetViewPair child1 = createAndRetain(window1.first); |
|
3948 |
const WidgetViewPair child2 = createAndRetain(window2.first); |
|
3949 |
||
3950 |
window2.first->setParent(window1.first); |
|
3951 |
||
3952 |
delete window2.first; |
|
3953 |
QVERIFY(testAndRelease(window2.second)); |
|
3954 |
QVERIFY(testAndRelease(child2.second)); |
|
3955 |
delete window1.first; |
|
3956 |
QVERIFY(testAndRelease(window1.second)); |
|
3957 |
QVERIFY(testAndRelease(child1.second)); |
|
3958 |
} |
|
3959 |
||
3960 |
// Delete child widget |
|
3961 |
{ |
|
3962 |
const WidgetViewPair parent = createAndRetain(); |
|
3963 |
const WidgetViewPair child = createAndRetain(parent.first); |
|
3964 |
||
3965 |
delete child.first; |
|
3966 |
QVERIFY(testAndRelease(child.second)); |
|
3967 |
delete parent.first; |
|
3968 |
QVERIFY(testAndRelease(parent.second)); |
|
3969 |
} |
|
3970 |
} |
|
3971 |
||
3972 |
void tst_QWidget::sheetOpacity() |
|
3973 |
{ |
|
3974 |
QWidget tmpWindow; |
|
3975 |
QWidget sheet(&tmpWindow, Qt::Sheet); |
|
3976 |
tmpWindow.show(); |
|
3977 |
sheet.show(); |
|
3978 |
QCOMPARE(int(sheet.windowOpacity() * 255), 242); // 95% |
|
3979 |
sheet.setParent(0, Qt::Dialog); |
|
3980 |
QCOMPARE(int(sheet.windowOpacity() * 255), 255); |
|
3981 |
} |
|
3982 |
||
3983 |
class MaskedPainter : public QWidget |
|
3984 |
{ |
|
3985 |
public: |
|
3986 |
QRect mask; |
|
3987 |
||
3988 |
MaskedPainter() |
|
3989 |
: mask(20, 20, 50, 50) |
|
3990 |
{ |
|
3991 |
setMask(mask); |
|
3992 |
} |
|
3993 |
||
3994 |
void paintEvent(QPaintEvent *) |
|
3995 |
{ |
|
3996 |
QPainter p(this); |
|
3997 |
p.fillRect(mask, QColor(Qt::red)); |
|
3998 |
} |
|
3999 |
}; |
|
4000 |
||
4001 |
/* |
|
4002 |
Verifies that the entire area inside the mask is painted red. |
|
4003 |
*/ |
|
4004 |
bool verifyWidgetMask(QWidget *widget, QRect mask) |
|
4005 |
{ |
|
4006 |
const QImage image = QPixmap::grabWindow(widget->winId()).toImage(); |
|
4007 |
||
4008 |
const QImage masked = image.copy(mask); |
|
4009 |
QImage red(masked); |
|
4010 |
red.fill(QColor(Qt::red).rgb()); |
|
4011 |
||
4012 |
return (masked == red); |
|
4013 |
} |
|
4014 |
||
4015 |
void tst_QWidget::setMask() |
|
4016 |
{ |
|
4017 |
testWidget->hide(); // get this out of the way. |
|
4018 |
||
4019 |
{ |
|
4020 |
MaskedPainter w; |
|
4021 |
w.resize(200, 200); |
|
4022 |
w.show(); |
|
4023 |
QTest::qWait(100); |
|
4024 |
QVERIFY(verifyWidgetMask(&w, w.mask)); |
|
4025 |
} |
|
4026 |
{ |
|
4027 |
MaskedPainter w; |
|
4028 |
w.resize(200, 200); |
|
4029 |
w.setWindowFlags(w.windowFlags() | Qt::FramelessWindowHint); |
|
4030 |
w.show(); |
|
4031 |
QTest::qWait(100); |
|
4032 |
QRect mask = w.mask; |
|
4033 |
||
4034 |
QVERIFY(verifyWidgetMask(&w, mask)); |
|
4035 |
} |
|
4036 |
} |
|
4037 |
#endif |
|
4038 |
||
4039 |
class StaticWidget : public QWidget |
|
4040 |
{ |
|
4041 |
Q_OBJECT |
|
4042 |
public: |
|
4043 |
bool partial; |
|
4044 |
bool gotPaintEvent; |
|
4045 |
QRegion paintedRegion; |
|
4046 |
||
4047 |
StaticWidget(QWidget *parent = 0) |
|
4048 |
:QWidget(parent) |
|
4049 |
{ |
|
4050 |
setAttribute(Qt::WA_StaticContents); |
|
4051 |
setAttribute(Qt::WA_OpaquePaintEvent); |
|
4052 |
setPalette(Qt::red); // Make sure we have an opaque palette. |
|
4053 |
setAutoFillBackground(true); |
|
4054 |
gotPaintEvent = false; |
|
4055 |
} |
|
4056 |
||
4057 |
void paintEvent(QPaintEvent *e) |
|
4058 |
{ |
|
4059 |
paintedRegion += e->region(); |
|
4060 |
gotPaintEvent = true; |
|
4061 |
// qDebug() << "paint" << e->region(); |
|
4062 |
// Look for a full update, set partial to false if found. |
|
4063 |
foreach(QRect r, e->region().rects()) { |
|
4064 |
partial = (r != rect()); |
|
4065 |
if (partial == false) |
|
4066 |
break; |
|
4067 |
} |
|
4068 |
} |
|
4069 |
}; |
|
4070 |
||
4071 |
/* |
|
4072 |
Test that widget resizes and moves can be done with minimal repaints when WA_StaticContents |
|
4073 |
and WA_OpaquePaintEvent is set. Test is mac-only for now. |
|
4074 |
*/ |
|
4075 |
void tst_QWidget::optimizedResizeMove() |
|
4076 |
{ |
|
4077 |
QWidget parent; |
|
4078 |
parent.resize(400, 400); |
|
4079 |
||
4080 |
StaticWidget staticWidget(&parent); |
|
4081 |
staticWidget.gotPaintEvent = false; |
|
4082 |
staticWidget.move(150, 150); |
|
4083 |
staticWidget.resize(150, 150); |
|
4084 |
parent.show(); |
|
4085 |
QTest::qWaitForWindowShown(&parent); |
|
4086 |
QTest::qWait(20); |
|
4087 |
QTRY_COMPARE(staticWidget.gotPaintEvent, true); |
|
4088 |
||
4089 |
staticWidget.gotPaintEvent = false; |
|
4090 |
staticWidget.move(staticWidget.pos() + QPoint(10, 10)); |
|
4091 |
QTest::qWait(20); |
|
4092 |
QCOMPARE(staticWidget.gotPaintEvent, false); |
|
4093 |
||
4094 |
staticWidget.gotPaintEvent = false; |
|
4095 |
staticWidget.move(staticWidget.pos() + QPoint(-10, -10)); |
|
4096 |
QTest::qWait(20); |
|
4097 |
QCOMPARE(staticWidget.gotPaintEvent, false); |
|
4098 |
||
4099 |
staticWidget.gotPaintEvent = false; |
|
4100 |
staticWidget.move(staticWidget.pos() + QPoint(-10, 10)); |
|
4101 |
QTest::qWait(20); |
|
4102 |
QCOMPARE(staticWidget.gotPaintEvent, false); |
|
4103 |
||
4104 |
staticWidget.gotPaintEvent = false; |
|
4105 |
staticWidget.resize(staticWidget.size() + QSize(10, 10)); |
|
4106 |
QTest::qWait(20); |
|
4107 |
QCOMPARE(staticWidget.gotPaintEvent, true); |
|
4108 |
QCOMPARE(staticWidget.partial, true); |
|
4109 |
||
4110 |
staticWidget.gotPaintEvent = false; |
|
4111 |
staticWidget.resize(staticWidget.size() + QSize(-10, -10)); |
|
4112 |
QTest::qWait(20); |
|
4113 |
QCOMPARE(staticWidget.gotPaintEvent, false); |
|
4114 |
||
4115 |
staticWidget.gotPaintEvent = false; |
|
4116 |
staticWidget.resize(staticWidget.size() + QSize(10, -10)); |
|
4117 |
QTest::qWait(20); |
|
4118 |
QCOMPARE(staticWidget.gotPaintEvent, true); |
|
4119 |
QCOMPARE(staticWidget.partial, true); |
|
4120 |
||
4121 |
staticWidget.gotPaintEvent = false; |
|
4122 |
staticWidget.move(staticWidget.pos() + QPoint(10, 10)); |
|
4123 |
staticWidget.resize(staticWidget.size() + QSize(-10, -10)); |
|
4124 |
QTest::qWait(20); |
|
4125 |
QCOMPARE(staticWidget.gotPaintEvent, false); |
|
4126 |
||
4127 |
staticWidget.gotPaintEvent = false; |
|
4128 |
staticWidget.move(staticWidget.pos() + QPoint(10, 10)); |
|
4129 |
staticWidget.resize(staticWidget.size() + QSize(10, 10)); |
|
4130 |
QTest::qWait(20); |
|
4131 |
QCOMPARE(staticWidget.gotPaintEvent, true); |
|
4132 |
QCOMPARE(staticWidget.partial, true); |
|
4133 |
||
4134 |
staticWidget.gotPaintEvent = false; |
|
4135 |
staticWidget.move(staticWidget.pos() + QPoint(-10, -10)); |
|
4136 |
staticWidget.resize(staticWidget.size() + QSize(-10, -10)); |
|
4137 |
QTest::qWait(20); |
|
4138 |
QCOMPARE(staticWidget.gotPaintEvent, false); |
|
4139 |
||
4140 |
staticWidget.setAttribute(Qt::WA_StaticContents, false); |
|
4141 |
staticWidget.gotPaintEvent = false; |
|
4142 |
staticWidget.move(staticWidget.pos() + QPoint(-10, -10)); |
|
4143 |
staticWidget.resize(staticWidget.size() + QSize(-10, -10)); |
|
4144 |
QTest::qWait(20); |
|
4145 |
QCOMPARE(staticWidget.gotPaintEvent, true); |
|
4146 |
QCOMPARE(staticWidget.partial, false); |
|
4147 |
staticWidget.setAttribute(Qt::WA_StaticContents, true); |
|
4148 |
||
4149 |
staticWidget.setAttribute(Qt::WA_StaticContents, false); |
|
4150 |
staticWidget.gotPaintEvent = false; |
|
4151 |
staticWidget.move(staticWidget.pos() + QPoint(10, 10)); |
|
4152 |
QTest::qWait(20); |
|
4153 |
QCOMPARE(staticWidget.gotPaintEvent, false); |
|
4154 |
staticWidget.setAttribute(Qt::WA_StaticContents, true); |
|
4155 |
} |
|
4156 |
||
4157 |
void tst_QWidget::optimizedResize_topLevel() |
|
4158 |
{ |
|
4159 |
#if defined(Q_WS_MAC) || defined(Q_WS_QWS) |
|
4160 |
QSKIP("We do not yet have static contents support for *top-levels* on this platform", SkipAll); |
|
4161 |
#endif |
|
4162 |
||
4163 |
StaticWidget topLevel; |
|
4164 |
topLevel.gotPaintEvent = false; |
|
4165 |
topLevel.show(); |
|
4166 |
QTest::qWaitForWindowShown(&topLevel); |
|
4167 |
QTest::qWait(10); |
|
4168 |
QTRY_COMPARE(topLevel.gotPaintEvent, true); |
|
4169 |
||
4170 |
topLevel.gotPaintEvent = false; |
|
4171 |
topLevel.partial = false; |
|
4172 |
topLevel.paintedRegion = QRegion(); |
|
4173 |
||
4174 |
#ifndef Q_WS_WIN |
|
4175 |
topLevel.resize(topLevel.size() + QSize(10, 10)); |
|
4176 |
#else |
|
4177 |
// Static contents does not work when programmatically resizing |
|
4178 |
// top-levels with QWidget::resize. We do some funky stuff in |
|
4179 |
// setGeometry_sys. However, resizing it with the mouse or with |
|
4180 |
// a native function call works (it basically has to go through |
|
4181 |
// WM_RESIZE in QApplication). This is a corner case, though. |
|
4182 |
// See task 243708 |
|
4183 |
const QRect frame = topLevel.frameGeometry(); |
|
4184 |
MoveWindow(topLevel.winId(), frame.x(), frame.y(), |
|
4185 |
frame.width() + 10, frame.height() + 10, |
|
4186 |
true); |
|
4187 |
#endif |
|
4188 |
||
4189 |
QTest::qWait(100); |
|
4190 |
||
4191 |
// Expected update region: New rect - old rect. |
|
4192 |
QRegion expectedUpdateRegion(topLevel.rect()); |
|
4193 |
expectedUpdateRegion -= QRect(QPoint(), topLevel.size() - QSize(10, 10)); |
|
4194 |
||
4195 |
QTRY_COMPARE(topLevel.gotPaintEvent, true); |
|
4196 |
QCOMPARE(topLevel.partial, true); |
|
4197 |
QCOMPARE(topLevel.paintedRegion, expectedUpdateRegion); |
|
4198 |
} |
|
4199 |
||
4200 |
class SiblingDeleter : public QWidget |
|
4201 |
{ |
|
4202 |
public: |
|
4203 |
inline SiblingDeleter(QWidget *sibling, QWidget *parent) |
|
4204 |
: QWidget(parent), sibling(sibling) {} |
|
4205 |
inline virtual ~SiblingDeleter() { delete sibling; } |
|
4206 |
||
4207 |
private: |
|
4208 |
QPointer<QWidget> sibling; |
|
4209 |
}; |
|
4210 |
||
4211 |
||
4212 |
void tst_QWidget::childDeletesItsSibling() |
|
4213 |
{ |
|
4214 |
QWidget *commonParent = new QWidget(0); |
|
4215 |
QPointer<QWidget> child = new QWidget(0); |
|
4216 |
QPointer<QWidget> siblingDeleter = new SiblingDeleter(child, commonParent); |
|
4217 |
child->setParent(commonParent); |
|
4218 |
delete commonParent; // don't crash |
|
4219 |
QVERIFY(!child); |
|
4220 |
QVERIFY(!siblingDeleter); |
|
4221 |
||
4222 |
} |
|
4223 |
||
4224 |
#ifdef Q_WS_QWS |
|
4225 |
# define SET_SAFE_SIZE(w) \ |
|
4226 |
do { \ |
|
4227 |
QSize safeSize(qt_screen->width() - 250, qt_screen->height() - 250); \ |
|
4228 |
if (!safeSize.isValid()) \ |
|
4229 |
QSKIP("Screen size too small", SkipAll); \ |
|
4230 |
if (defaultSize.width() > safeSize.width() || defaultSize.height() > safeSize.height()) { \ |
|
4231 |
defaultSize = safeSize; \ |
|
4232 |
w.resize(defaultSize); \ |
|
4233 |
w.setAttribute(Qt::WA_Resized, false); \ |
|
4234 |
} \ |
|
4235 |
} while (false) |
|
4236 |
#else |
|
4237 |
# define SET_SAFE_SIZE(w) |
|
4238 |
#endif |
|
4239 |
||
4240 |
||
4241 |
void tst_QWidget::setMinimumSize() |
|
4242 |
{ |
|
4243 |
QWidget w; |
|
4244 |
QSize defaultSize = w.size(); |
|
4245 |
SET_SAFE_SIZE(w); |
|
4246 |
||
4247 |
w.setMinimumSize(defaultSize + QSize(100, 100)); |
|
4248 |
QCOMPARE(w.size(), defaultSize + QSize(100, 100)); |
|
4249 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
|
4250 |
||
4251 |
w.setMinimumSize(defaultSize + QSize(50, 50)); |
|
4252 |
QCOMPARE(w.size(), defaultSize + QSize(100, 100)); |
|
4253 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
|
4254 |
||
4255 |
w.setMinimumSize(defaultSize + QSize(200, 200)); |
|
4256 |
QCOMPARE(w.size(), defaultSize + QSize(200, 200)); |
|
4257 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
|
4258 |
||
4259 |
#ifdef Q_OS_WINCE |
|
4260 |
QSKIP("Setting a minimum size larger than the desktop does not work", SkipAll); |
|
4261 |
#endif |
|
4262 |
QSize nonDefaultSize = defaultSize + QSize(5,5); |
|
4263 |
w.setMinimumSize(nonDefaultSize); |
|
4264 |
w.show(); |
|
4265 |
QTest::qWait(50); |
|
4266 |
QVERIFY(w.height() >= nonDefaultSize.height()); |
|
4267 |
QVERIFY(w.width() >= nonDefaultSize.width()); |
|
4268 |
} |
|
4269 |
||
4270 |
void tst_QWidget::setMaximumSize() |
|
4271 |
{ |
|
4272 |
QWidget w; |
|
4273 |
QSize defaultSize = w.size(); |
|
4274 |
SET_SAFE_SIZE(w); |
|
4275 |
||
4276 |
w.setMinimumSize(defaultSize + QSize(100, 100)); |
|
4277 |
QCOMPARE(w.size(), defaultSize + QSize(100, 100)); |
|
4278 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
|
4279 |
w.setMinimumSize(defaultSize); |
|
4280 |
||
4281 |
w.setMaximumSize(defaultSize + QSize(200, 200)); |
|
4282 |
QCOMPARE(w.size(), defaultSize + QSize(100, 100)); |
|
4283 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
|
4284 |
||
4285 |
w.setMaximumSize(defaultSize + QSize(50, 50)); |
|
4286 |
QCOMPARE(w.size(), defaultSize + QSize(50, 50)); |
|
4287 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
|
4288 |
||
4289 |
#if 0 |
|
4290 |
//we don't enforce maximum size on show, apparently |
|
4291 |
QSize nonDefaultSize = defaultSize - QSize(5,5); |
|
4292 |
w.setMaximumSize(nonDefaultSize); |
|
4293 |
w.show(); |
|
4294 |
QTest::qWait(50); |
|
4295 |
qDebug() << nonDefaultSize << w.size(); |
|
4296 |
QVERIFY(w.height() <= nonDefaultSize.height()); |
|
4297 |
QVERIFY(w.width() <= nonDefaultSize.width()); |
|
4298 |
#endif |
|
4299 |
} |
|
4300 |
||
4301 |
void tst_QWidget::setFixedSize() |
|
4302 |
{ |
|
4303 |
QWidget w; |
|
4304 |
QSize defaultSize = w.size(); |
|
4305 |
SET_SAFE_SIZE(w); |
|
4306 |
||
4307 |
w.setFixedSize(defaultSize + QSize(100, 100)); |
|
4308 |
QCOMPARE(w.size(), defaultSize + QSize(100, 100)); |
|
4309 |
QVERIFY(w.testAttribute(Qt::WA_Resized)); |
|
4310 |
||
4311 |
w.setFixedSize(defaultSize + QSize(200, 200)); |
|
4312 |
||
4313 |
QCOMPARE(w.minimumSize(), defaultSize + QSize(200,200)); |
|
4314 |
QCOMPARE(w.maximumSize(), defaultSize + QSize(200,200)); |
|
4315 |
QCOMPARE(w.size(), defaultSize + QSize(200, 200)); |
|
4316 |
QVERIFY(w.testAttribute(Qt::WA_Resized)); |
|
4317 |
||
4318 |
w.setFixedSize(defaultSize + QSize(50, 50)); |
|
4319 |
QCOMPARE(w.size(), defaultSize + QSize(50, 50)); |
|
4320 |
QVERIFY(w.testAttribute(Qt::WA_Resized)); |
|
4321 |
||
4322 |
w.setAttribute(Qt::WA_Resized, false); |
|
4323 |
w.setFixedSize(defaultSize + QSize(50, 50)); |
|
4324 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
|
4325 |
||
4326 |
w.setFixedSize(defaultSize + QSize(150, 150)); |
|
4327 |
w.show(); |
|
4328 |
QTest::qWait(50); |
|
4329 |
QVERIFY(w.size() == defaultSize + QSize(150,150)); |
|
4330 |
} |
|
4331 |
||
4332 |
void tst_QWidget::ensureCreated() |
|
4333 |
{ |
|
4334 |
{ |
|
4335 |
QWidget widget; |
|
4336 |
WId widgetWinId = widget.winId(); |
|
4337 |
Q_UNUSED(widgetWinId); |
|
4338 |
QVERIFY(widget.testAttribute(Qt::WA_WState_Created)); |
|
4339 |
} |
|
4340 |
||
4341 |
{ |
|
4342 |
QWidget window; |
|
4343 |
||
4344 |
QDialog dialog(&window); |
|
4345 |
dialog.setWindowModality(Qt::NonModal); |
|
4346 |
||
4347 |
WId dialogWinId = dialog.winId(); |
|
4348 |
Q_UNUSED(dialogWinId); |
|
4349 |
QVERIFY(dialog.testAttribute(Qt::WA_WState_Created)); |
|
4350 |
QVERIFY(window.testAttribute(Qt::WA_WState_Created)); |
|
4351 |
} |
|
4352 |
||
4353 |
{ |
|
4354 |
QWidget window; |
|
4355 |
||
4356 |
QDialog dialog(&window); |
|
4357 |
dialog.setWindowModality(Qt::WindowModal); |
|
4358 |
||
4359 |
WId dialogWinId = dialog.winId(); |
|
4360 |
Q_UNUSED(dialogWinId); |
|
4361 |
QVERIFY(dialog.testAttribute(Qt::WA_WState_Created)); |
|
4362 |
QVERIFY(window.testAttribute(Qt::WA_WState_Created)); |
|
4363 |
} |
|
4364 |
||
4365 |
{ |
|
4366 |
QWidget window; |
|
4367 |
||
4368 |
QDialog dialog(&window); |
|
4369 |
dialog.setWindowModality(Qt::ApplicationModal); |
|
4370 |
||
4371 |
WId dialogWinId = dialog.winId(); |
|
4372 |
Q_UNUSED(dialogWinId); |
|
4373 |
QVERIFY(dialog.testAttribute(Qt::WA_WState_Created)); |
|
4374 |
QVERIFY(window.testAttribute(Qt::WA_WState_Created)); |
|
4375 |
} |
|
4376 |
} |
|
4377 |
||
4378 |
class WinIdChangeWidget : public QWidget { |
|
4379 |
public: |
|
4380 |
WinIdChangeWidget(QWidget *p = 0) |
|
4381 |
: QWidget(p) |
|
4382 |
, m_winIdChangeEventCount(0) |
|
4383 |
{ |
|
4384 |
||
4385 |
} |
|
4386 |
protected: |
|
4387 |
bool event(QEvent *e) |
|
4388 |
{ |
|
4389 |
if (e->type() == QEvent::WinIdChange) { |
|
4390 |
++m_winIdChangeEventCount; |
|
4391 |
return true; |
|
4392 |
} |
|
4393 |
return QWidget::event(e); |
|
4394 |
} |
|
4395 |
public: |
|
4396 |
int m_winIdChangeEventCount; |
|
4397 |
}; |
|
4398 |
||
4399 |
void tst_QWidget::winIdChangeEvent() |
|
4400 |
{ |
|
4401 |
{ |
|
4402 |
// Transforming an alien widget into a native widget |
|
4403 |
WinIdChangeWidget widget; |
|
4404 |
const WId winIdBefore = widget.internalWinId(); |
|
4405 |
const WId winIdAfter = widget.winId(); |
|
4406 |
QVERIFY(winIdBefore != winIdAfter); |
|
4407 |
QCOMPARE(widget.m_winIdChangeEventCount, 1); |
|
4408 |
} |
|
4409 |
||
4410 |
{ |
|
4411 |
// Changing parent of a native widget |
|
4412 |
// Should cause winId of child to change, on all platforms |
|
4413 |
QWidget parent1, parent2; |
|
4414 |
WinIdChangeWidget child(&parent1); |
|
4415 |
const WId winIdBefore = child.winId(); |
|
4416 |
QCOMPARE(child.m_winIdChangeEventCount, 1); |
|
4417 |
child.setParent(&parent2); |
|
4418 |
const WId winIdAfter = child.internalWinId(); |
|
4419 |
QVERIFY(winIdBefore != winIdAfter); |
|
4420 |
QCOMPARE(child.m_winIdChangeEventCount, 2); |
|
4421 |
} |
|
4422 |
||
4423 |
{ |
|
4424 |
// Changing grandparent of a native widget |
|
4425 |
// Should cause winId of grandchild to change only on Symbian |
|
4426 |
QWidget grandparent1, grandparent2; |
|
4427 |
QWidget parent(&grandparent1); |
|
4428 |
WinIdChangeWidget child(&parent); |
|
4429 |
const WId winIdBefore = child.winId(); |
|
4430 |
QCOMPARE(child.m_winIdChangeEventCount, 1); |
|
4431 |
parent.setParent(&grandparent2); |
|
4432 |
const WId winIdAfter = child.internalWinId(); |
|
4433 |
#ifdef Q_OS_SYMBIAN |
|
4434 |
QVERIFY(winIdBefore != winIdAfter); |
|
4435 |
QCOMPARE(child.m_winIdChangeEventCount, 2); |
|
4436 |
#else |
|
4437 |
QCOMPARE(winIdBefore, winIdAfter); |
|
4438 |
QCOMPARE(child.m_winIdChangeEventCount, 1); |
|
4439 |
#endif |
|
4440 |
} |
|
4441 |
||
4442 |
{ |
|
4443 |
// Changing parent of an alien widget |
|
4444 |
QWidget parent1, parent2; |
|
4445 |
WinIdChangeWidget child(&parent1); |
|
4446 |
const WId winIdBefore = child.internalWinId(); |
|
4447 |
child.setParent(&parent2); |
|
4448 |
const WId winIdAfter = child.internalWinId(); |
|
4449 |
QCOMPARE(winIdBefore, winIdAfter); |
|
4450 |
QCOMPARE(child.m_winIdChangeEventCount, 0); |
|
4451 |
} |
|
4452 |
||
4453 |
{ |
|
4454 |
// Making native child widget into a top-level window |
|
4455 |
QWidget parent; |
|
4456 |
WinIdChangeWidget child(&parent); |
|
4457 |
child.winId(); |
|
4458 |
const WId winIdBefore = child.internalWinId(); |
|
4459 |
QCOMPARE(child.m_winIdChangeEventCount, 1); |
|
4460 |
const Qt::WindowFlags flags = child.windowFlags(); |
|
4461 |
child.setWindowFlags(flags | Qt::Window); |
|
4462 |
const WId winIdAfter = child.internalWinId(); |
|
4463 |
QVERIFY(winIdBefore != winIdAfter); |
|
4464 |
QCOMPARE(child.m_winIdChangeEventCount, 2); |
|
4465 |
} |
|
4466 |
} |
|
4467 |
||
4468 |
#ifdef Q_OS_SYMBIAN |
|
4469 |
void tst_QWidget::reparentCausesChildWinIdChange() |
|
4470 |
{ |
|
4471 |
QWidget *parent = new QWidget; |
|
4472 |
QWidget *w1 = new QWidget; |
|
4473 |
QWidget *w2 = new QWidget; |
|
4474 |
QWidget *w3 = new QWidget; |
|
4475 |
w1->setParent(parent); |
|
4476 |
w2->setParent(w1); |
|
4477 |
w3->setParent(w2); |
|
4478 |
||
4479 |
WId winId1 = w1->winId(); |
|
4480 |
WId winId2 = w2->winId(); |
|
4481 |
WId winId3 = w3->winId(); |
|
4482 |
||
4483 |
// reparenting causes winIds of the widget being reparented, and all of its children, to change |
|
4484 |
w1->setParent(0); |
|
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 |
w1->setParent(parent); |
|
4493 |
QVERIFY(w1->winId() != winId1); |
|
4494 |
winId1 = w1->winId(); |
|
4495 |
QVERIFY(w2->winId() != winId2); |
|
4496 |
winId2 = w2->winId(); |
|
4497 |
QVERIFY(w3->winId() != winId3); |
|
4498 |
winId3 = w3->winId(); |
|
4499 |
||
4500 |
w2->setParent(0); |
|
4501 |
QVERIFY(w2->winId() != winId2); |
|
4502 |
winId2 = w2->winId(); |
|
4503 |
QVERIFY(w3->winId() != winId3); |
|
4504 |
winId3 = w3->winId(); |
|
4505 |
||
4506 |
w2->setParent(parent); |
|
4507 |
QVERIFY(w2->winId() != winId2); |
|
4508 |
winId2 = w2->winId(); |
|
4509 |
QVERIFY(w3->winId() != winId3); |
|
4510 |
winId3 = w3->winId(); |
|
4511 |
||
4512 |
w2->setParent(w1); |
|
4513 |
QVERIFY(w2->winId() != winId2); |
|
4514 |
winId2 = w2->winId(); |
|
4515 |
QVERIFY(w3->winId() != winId3); |
|
4516 |
winId3 = w3->winId(); |
|
4517 |
||
4518 |
w3->setParent(0); |
|
4519 |
QVERIFY(w3->winId() != winId3); |
|
4520 |
winId3 = w3->winId(); |
|
4521 |
||
4522 |
w3->setParent(w1); |
|
4523 |
QVERIFY(w3->winId() != winId3); |
|
4524 |
winId3 = w3->winId(); |
|
4525 |
||
4526 |
w3->setParent(w2); |
|
4527 |
QVERIFY(w3->winId() != winId3); |
|
4528 |
winId3 = w3->winId(); |
|
4529 |
||
4530 |
delete parent; |
|
4531 |
} |
|
4532 |
#else |
|
4533 |
void tst_QWidget::persistentWinId() |
|
4534 |
{ |
|
4535 |
QWidget *parent = new QWidget; |
|
4536 |
QWidget *w1 = new QWidget; |
|
4537 |
QWidget *w2 = new QWidget; |
|
4538 |
QWidget *w3 = new QWidget; |
|
4539 |
w1->setParent(parent); |
|
4540 |
w2->setParent(w1); |
|
4541 |
w3->setParent(w2); |
|
4542 |
||
4543 |
WId winId1 = w1->winId(); |
|
4544 |
WId winId2 = w2->winId(); |
|
4545 |
WId winId3 = w3->winId(); |
|
4546 |
||
4547 |
// reparenting should change the winId of the widget being reparented, but not of its children |
|
4548 |
w1->setParent(0); |
|
4549 |
QVERIFY(w1->winId() != winId1); |
|
4550 |
winId1 = w1->winId(); |
|
4551 |
QCOMPARE(w2->winId(), winId2); |
|
4552 |
QCOMPARE(w3->winId(), winId3); |
|
4553 |
||
4554 |
w1->setParent(parent); |
|
4555 |
QVERIFY(w1->winId() != winId1); |
|
4556 |
winId1 = w1->winId(); |
|
4557 |
QCOMPARE(w2->winId(), winId2); |
|
4558 |
QCOMPARE(w3->winId(), winId3); |
|
4559 |
||
4560 |
w2->setParent(0); |
|
4561 |
QVERIFY(w2->winId() != winId2); |
|
4562 |
winId2 = w2->winId(); |
|
4563 |
QCOMPARE(w3->winId(), winId3); |
|
4564 |
||
4565 |
w2->setParent(parent); |
|
4566 |
QVERIFY(w2->winId() != winId2); |
|
4567 |
winId2 = w2->winId(); |
|
4568 |
QCOMPARE(w3->winId(), winId3); |
|
4569 |
||
4570 |
w2->setParent(w1); |
|
4571 |
QVERIFY(w2->winId() != winId2); |
|
4572 |
winId2 = w2->winId(); |
|
4573 |
QCOMPARE(w3->winId(), winId3); |
|
4574 |
||
4575 |
w3->setParent(0); |
|
4576 |
QVERIFY(w3->winId() != winId3); |
|
4577 |
winId3 = w3->winId(); |
|
4578 |
||
4579 |
w3->setParent(w1); |
|
4580 |
QVERIFY(w3->winId() != winId3); |
|
4581 |
winId3 = w3->winId(); |
|
4582 |
||
4583 |
w3->setParent(w2); |
|
4584 |
QVERIFY(w3->winId() != winId3); |
|
4585 |
winId3 = w3->winId(); |
|
4586 |
||
4587 |
delete parent; |
|
4588 |
} |
|
4589 |
#endif // Q_OS_SYMBIAN |
|
4590 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4591 |
void tst_QWidget::showNativeChild() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4592 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4593 |
QWidget topLevel; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4594 |
topLevel.setGeometry(0, 0, 100, 100); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4595 |
QWidget child(&topLevel); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4596 |
child.winId(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4597 |
topLevel.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4598 |
QTest::qWaitForWindowShown(&topLevel); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4599 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4600 |
|
0 | 4601 |
class ShowHideEventWidget : public QWidget |
4602 |
{ |
|
4603 |
public: |
|
4604 |
int numberOfShowEvents, numberOfHideEvents; |
|
4605 |
||
4606 |
ShowHideEventWidget(QWidget *parent = 0) |
|
4607 |
: QWidget(parent), numberOfShowEvents(0), numberOfHideEvents(0) |
|
4608 |
{ } |
|
4609 |
||
4610 |
void create() |
|
4611 |
{ QWidget::create(); } |
|
4612 |
||
4613 |
void showEvent(QShowEvent *) |
|
4614 |
{ ++numberOfShowEvents; } |
|
4615 |
||
4616 |
void hideEvent(QHideEvent *) |
|
4617 |
{ ++numberOfHideEvents; } |
|
4618 |
}; |
|
4619 |
||
4620 |
void tst_QWidget::showHideEvent_data() |
|
4621 |
{ |
|
4622 |
QTest::addColumn<bool>("show"); |
|
4623 |
QTest::addColumn<bool>("hide"); |
|
4624 |
QTest::addColumn<bool>("create"); |
|
4625 |
QTest::addColumn<int>("expectedShowEvents"); |
|
4626 |
QTest::addColumn<int>("expectedHideEvents"); |
|
4627 |
||
4628 |
QTest::newRow("window: only show") |
|
4629 |
<< true |
|
4630 |
<< false |
|
4631 |
<< false |
|
4632 |
<< 1 |
|
4633 |
<< 0; |
|
4634 |
QTest::newRow("window: show/hide") |
|
4635 |
<< true |
|
4636 |
<< true |
|
4637 |
<< false |
|
4638 |
<< 1 |
|
4639 |
<< 1; |
|
4640 |
QTest::newRow("window: show/hide/create") |
|
4641 |
<< true |
|
4642 |
<< true |
|
4643 |
<< true |
|
4644 |
<< 1 |
|
4645 |
<< 1; |
|
4646 |
QTest::newRow("window: hide/create") |
|
4647 |
<< false |
|
4648 |
<< true |
|
4649 |
<< true |
|
4650 |
<< 0 |
|
4651 |
<< 0; |
|
4652 |
QTest::newRow("window: only hide") |
|
4653 |
<< false |
|
4654 |
<< true |
|
4655 |
<< false |
|
4656 |
<< 0 |
|
4657 |
<< 0; |
|
4658 |
QTest::newRow("window: nothing") |
|
4659 |
<< false |
|
4660 |
<< false |
|
4661 |
<< false |
|
4662 |
<< 0 |
|
4663 |
<< 0; |
|
4664 |
} |
|
4665 |
||
4666 |
void tst_QWidget::showHideEvent() |
|
4667 |
{ |
|
4668 |
QFETCH(bool, show); |
|
4669 |
QFETCH(bool, hide); |
|
4670 |
QFETCH(bool, create); |
|
4671 |
QFETCH(int, expectedShowEvents); |
|
4672 |
QFETCH(int, expectedHideEvents); |
|
4673 |
||
4674 |
ShowHideEventWidget widget; |
|
4675 |
if (show) |
|
4676 |
widget.show(); |
|
4677 |
if (hide) |
|
4678 |
widget.hide(); |
|
4679 |
if (create && !widget.testAttribute(Qt::WA_WState_Created)) |
|
4680 |
widget.create(); |
|
4681 |
||
4682 |
QCOMPARE(widget.numberOfShowEvents, expectedShowEvents); |
|
4683 |
QCOMPARE(widget.numberOfHideEvents, expectedHideEvents); |
|
4684 |
} |
|
4685 |
||
4686 |
void tst_QWidget::update() |
|
4687 |
{ |
|
4688 |
QTest::qWait(10); // Wait for the initStuff to do it's stuff. |
|
4689 |
Q_CHECK_PAINTEVENTS |
|
4690 |
||
4691 |
UpdateWidget w; |
|
4692 |
w.setGeometry(50, 50, 100, 100); |
|
4693 |
w.show(); |
|
4694 |
QTest::qWaitForWindowShown(&w); |
|
4695 |
||
4696 |
QApplication::processEvents(); |
|
4697 |
QApplication::processEvents(); |
|
4698 |
||
4699 |
QTRY_COMPARE(w.numPaintEvents, 1); |
|
4700 |
||
4701 |
QCOMPARE(w.visibleRegion(), QRegion(w.rect())); |
|
4702 |
QCOMPARE(w.paintedRegion, w.visibleRegion()); |
|
4703 |
w.reset(); |
|
4704 |
||
4705 |
UpdateWidget child(&w); |
|
4706 |
child.setGeometry(10, 10, 80, 80); |
|
4707 |
child.show(); |
|
4708 |
||
4709 |
QPoint childOffset = child.mapToParent(QPoint()); |
|
4710 |
||
4711 |
// widgets are transparent by default, so both should get repaints |
|
4712 |
{ |
|
4713 |
QApplication::processEvents(); |
|
4714 |
QApplication::processEvents(); |
|
4715 |
QCOMPARE(child.numPaintEvents, 1); |
|
4716 |
QCOMPARE(child.visibleRegion(), QRegion(child.rect())); |
|
4717 |
QCOMPARE(child.paintedRegion, child.visibleRegion()); |
|
4718 |
QCOMPARE(w.numPaintEvents, 1); |
|
4719 |
QCOMPARE(w.visibleRegion(), QRegion(w.rect())); |
|
4720 |
QCOMPARE(w.paintedRegion, child.visibleRegion().translated(childOffset)); |
|
4721 |
||
4722 |
w.reset(); |
|
4723 |
child.reset(); |
|
4724 |
||
4725 |
w.update(); |
|
4726 |
QApplication::processEvents(); |
|
4727 |
QApplication::processEvents(); |
|
4728 |
QCOMPARE(child.numPaintEvents, 1); |
|
4729 |
QCOMPARE(child.visibleRegion(), QRegion(child.rect())); |
|
4730 |
QCOMPARE(child.paintedRegion, child.visibleRegion()); |
|
4731 |
QCOMPARE(w.numPaintEvents, 1); |
|
4732 |
QCOMPARE(w.visibleRegion(), QRegion(w.rect())); |
|
4733 |
QCOMPARE(w.paintedRegion, w.visibleRegion()); |
|
4734 |
} |
|
4735 |
||
4736 |
QPalette opaquePalette = child.palette(); |
|
4737 |
opaquePalette.setColor(child.backgroundRole(), QColor(Qt::red)); |
|
4738 |
||
4739 |
// setting an opaque background on the child should prevent paint-events |
|
4740 |
// for the parent in the child area |
|
4741 |
{ |
|
4742 |
child.setPalette(opaquePalette); |
|
4743 |
child.setAutoFillBackground(true); |
|
4744 |
QApplication::processEvents(); |
|
4745 |
||
4746 |
w.reset(); |
|
4747 |
child.reset(); |
|
4748 |
||
4749 |
w.update(); |
|
4750 |
QApplication::processEvents(); |
|
4751 |
QApplication::processEvents(); |
|
4752 |
||
4753 |
QCOMPARE(w.numPaintEvents, 1); |
|
4754 |
QRegion expectedVisible = QRegion(w.rect()) |
|
4755 |
- child.visibleRegion().translated(childOffset); |
|
4756 |
QCOMPARE(w.visibleRegion(), expectedVisible); |
|
4757 |
#ifdef QT_MAC_USE_COCOA |
|
4758 |
QEXPECT_FAIL(0, "Cocoa compositor paints the content view", Continue); |
|
4759 |
#endif |
|
4760 |
QCOMPARE(w.paintedRegion, expectedVisible); |
|
4761 |
#ifdef QT_MAC_USE_COCOA |
|
4762 |
QEXPECT_FAIL(0, "Cocoa compositor says to paint this.", Continue); |
|
4763 |
#endif |
|
4764 |
QCOMPARE(child.numPaintEvents, 0); |
|
4765 |
||
4766 |
w.reset(); |
|
4767 |
child.reset(); |
|
4768 |
||
4769 |
child.update(); |
|
4770 |
QApplication::processEvents(); |
|
4771 |
QApplication::processEvents(); |
|
4772 |
||
4773 |
QCOMPARE(w.numPaintEvents, 0); |
|
4774 |
QCOMPARE(child.numPaintEvents, 1); |
|
4775 |
QCOMPARE(child.paintedRegion, child.visibleRegion()); |
|
4776 |
||
4777 |
w.reset(); |
|
4778 |
child.reset(); |
|
4779 |
} |
|
4780 |
||
4781 |
// overlapping sibling |
|
4782 |
UpdateWidget sibling(&w); |
|
4783 |
child.setGeometry(10, 10, 20, 20); |
|
4784 |
sibling.setGeometry(15, 15, 20, 20); |
|
4785 |
sibling.show(); |
|
4786 |
||
4787 |
QApplication::processEvents(); |
|
4788 |
w.reset(); |
|
4789 |
child.reset(); |
|
4790 |
sibling.reset(); |
|
4791 |
||
4792 |
const QPoint siblingOffset = sibling.mapToParent(QPoint()); |
|
4793 |
||
4794 |
sibling.update(); |
|
4795 |
QApplication::processEvents(); |
|
4796 |
QApplication::processEvents(); |
|
4797 |
||
4798 |
// child is opaque, sibling transparent |
|
4799 |
{ |
|
4800 |
QCOMPARE(sibling.numPaintEvents, 1); |
|
4801 |
QCOMPARE(sibling.paintedRegion, sibling.visibleRegion()); |
|
4802 |
||
4803 |
QCOMPARE(child.numPaintEvents, 1); |
|
4804 |
QCOMPARE(child.paintedRegion.translated(childOffset), |
|
4805 |
child.visibleRegion().translated(childOffset) |
|
4806 |
& sibling.visibleRegion().translated(siblingOffset)); |
|
4807 |
||
4808 |
QCOMPARE(w.numPaintEvents, 1); |
|
4809 |
#ifdef QT_MAC_USE_COCOA |
|
4810 |
QEXPECT_FAIL(0, "Cocoa compositor paints the content view", Continue); |
|
4811 |
#endif |
|
4812 |
QCOMPARE(w.paintedRegion, |
|
4813 |
w.visibleRegion() & sibling.visibleRegion().translated(siblingOffset)); |
|
4814 |
#ifdef QT_MAC_USE_COCOA |
|
4815 |
QEXPECT_FAIL(0, "Cocoa compositor paints the content view", Continue); |
|
4816 |
#endif |
|
4817 |
QCOMPARE(w.paintedRegion, |
|
4818 |
(w.visibleRegion() - child.visibleRegion().translated(childOffset)) |
|
4819 |
& sibling.visibleRegion().translated(siblingOffset)); |
|
4820 |
||
4821 |
} |
|
4822 |
w.reset(); |
|
4823 |
child.reset(); |
|
4824 |
sibling.reset(); |
|
4825 |
||
4826 |
sibling.setPalette(opaquePalette); |
|
4827 |
sibling.setAutoFillBackground(true); |
|
4828 |
||
4829 |
sibling.update(); |
|
4830 |
QApplication::processEvents(); |
|
4831 |
QApplication::processEvents(); |
|
4832 |
||
4833 |
// child opaque, sibling opaque |
|
4834 |
{ |
|
4835 |
QCOMPARE(sibling.numPaintEvents, 1); |
|
4836 |
QCOMPARE(sibling.paintedRegion, sibling.visibleRegion()); |
|
4837 |
||
4838 |
#ifdef QT_MAC_USE_COCOA |
|
4839 |
QEXPECT_FAIL(0, "Cocoa compositor paints child and sibling", Continue); |
|
4840 |
#endif |
|
4841 |
QCOMPARE(child.numPaintEvents, 0); |
|
4842 |
QCOMPARE(child.visibleRegion(), |
|
4843 |
QRegion(child.rect()) |
|
4844 |
- sibling.visibleRegion().translated(siblingOffset - childOffset)); |
|
4845 |
||
4846 |
QCOMPARE(w.numPaintEvents, 0); |
|
4847 |
QCOMPARE(w.visibleRegion(), |
|
4848 |
QRegion(w.rect()) |
|
4849 |
- child.visibleRegion().translated(childOffset) |
|
4850 |
- sibling.visibleRegion().translated(siblingOffset)); |
|
4851 |
} |
|
4852 |
} |
|
4853 |
||
4854 |
static inline bool isOpaque(QWidget *widget) |
|
4855 |
{ |
|
4856 |
if (!widget) |
|
4857 |
return false; |
|
4858 |
return qt_widget_private(widget)->isOpaque; |
|
4859 |
} |
|
4860 |
||
4861 |
void tst_QWidget::isOpaque() |
|
4862 |
{ |
|
4863 |
#ifndef Q_WS_MAC |
|
4864 |
QWidget w; |
|
4865 |
QVERIFY(::isOpaque(&w)); |
|
4866 |
||
4867 |
QWidget child(&w); |
|
4868 |
QVERIFY(!::isOpaque(&child)); |
|
4869 |
||
4870 |
child.setAutoFillBackground(true); |
|
4871 |
QVERIFY(::isOpaque(&child)); |
|
4872 |
||
4873 |
QPalette palette; |
|
4874 |
||
4875 |
// background color |
|
4876 |
||
4877 |
palette = child.palette(); |
|
4878 |
palette.setColor(child.backgroundRole(), QColor(255, 0, 0, 127)); |
|
4879 |
child.setPalette(palette); |
|
4880 |
QVERIFY(!::isOpaque(&child)); |
|
4881 |
||
4882 |
palette.setColor(child.backgroundRole(), QColor(255, 0, 0, 255)); |
|
4883 |
child.setPalette(palette); |
|
4884 |
QVERIFY(::isOpaque(&child)); |
|
4885 |
||
4886 |
palette.setColor(QPalette::Window, QColor(0, 0, 255, 127)); |
|
4887 |
w.setPalette(palette); |
|
4888 |
||
4889 |
QVERIFY(!::isOpaque(&w)); |
|
4890 |
||
4891 |
child.setAutoFillBackground(false); |
|
4892 |
QVERIFY(!::isOpaque(&child)); |
|
4893 |
||
4894 |
// Qt::WA_OpaquePaintEvent |
|
4895 |
||
4896 |
child.setAttribute(Qt::WA_OpaquePaintEvent); |
|
4897 |
QVERIFY(::isOpaque(&child)); |
|
4898 |
||
4899 |
child.setAttribute(Qt::WA_OpaquePaintEvent, false); |
|
4900 |
QVERIFY(!::isOpaque(&child)); |
|
4901 |
||
4902 |
// Qt::WA_NoSystemBackground |
|
4903 |
||
4904 |
child.setAttribute(Qt::WA_NoSystemBackground); |
|
4905 |
QVERIFY(!::isOpaque(&child)); |
|
4906 |
||
4907 |
child.setAttribute(Qt::WA_NoSystemBackground, false); |
|
4908 |
QVERIFY(!::isOpaque(&child)); |
|
4909 |
||
4910 |
palette.setColor(QPalette::Window, QColor(0, 0, 255, 255)); |
|
4911 |
w.setPalette(palette); |
|
4912 |
QVERIFY(::isOpaque(&w)); |
|
4913 |
||
4914 |
w.setAttribute(Qt::WA_NoSystemBackground); |
|
4915 |
QVERIFY(!::isOpaque(&w)); |
|
4916 |
||
4917 |
w.setAttribute(Qt::WA_NoSystemBackground, false); |
|
4918 |
QVERIFY(::isOpaque(&w)); |
|
4919 |
||
4920 |
{ |
|
4921 |
QPalette palette = QApplication::palette(); |
|
4922 |
QPalette old = palette; |
|
4923 |
palette.setColor(QPalette::Window, Qt::transparent); |
|
4924 |
QApplication::setPalette(palette); |
|
4925 |
||
4926 |
QWidget widget; |
|
4927 |
QVERIFY(!::isOpaque(&widget)); |
|
4928 |
||
4929 |
QApplication::setPalette(old); |
|
4930 |
QCOMPARE(::isOpaque(&widget), old.color(QPalette::Window).alpha() == 255); |
|
4931 |
} |
|
4932 |
#endif |
|
4933 |
} |
|
4934 |
||
4935 |
#ifndef Q_WS_MAC |
|
4936 |
/* |
|
4937 |
Test that scrolling of a widget invalidates the correct regions |
|
4938 |
*/ |
|
4939 |
void tst_QWidget::scroll() |
|
4940 |
{ |
|
4941 |
UpdateWidget updateWidget; |
|
4942 |
updateWidget.resize(500, 500); |
|
4943 |
updateWidget.reset(); |
|
4944 |
updateWidget.show(); |
|
4945 |
QTest::qWaitForWindowShown(&updateWidget); |
|
4946 |
QTest::qWait(50); |
|
4947 |
qApp->processEvents(); |
|
4948 |
QTRY_VERIFY(updateWidget.numPaintEvents > 0); |
|
4949 |
||
4950 |
{ |
|
4951 |
updateWidget.reset(); |
|
4952 |
updateWidget.scroll(10, 10); |
|
4953 |
qApp->processEvents(); |
|
4954 |
QRegion dirty(QRect(0, 0, 500, 10)); |
|
4955 |
dirty += QRegion(QRect(0, 10, 10, 490)); |
|
4956 |
QCOMPARE(updateWidget.paintedRegion, dirty); |
|
4957 |
} |
|
4958 |
||
4959 |
{ |
|
4960 |
updateWidget.reset(); |
|
4961 |
updateWidget.update(0, 0, 10, 10); |
|
4962 |
updateWidget.scroll(0, 10); |
|
4963 |
qApp->processEvents(); |
|
4964 |
QRegion dirty(QRect(0, 0, 500, 10)); |
|
4965 |
dirty += QRegion(QRect(0, 10, 10, 10)); |
|
4966 |
QCOMPARE(updateWidget.paintedRegion, dirty); |
|
4967 |
} |
|
4968 |
||
4969 |
{ |
|
4970 |
updateWidget.reset(); |
|
4971 |
updateWidget.update(0, 0, 100, 100); |
|
4972 |
updateWidget.scroll(10, 10, QRect(50, 50, 100, 100)); |
|
4973 |
qApp->processEvents(); |
|
4974 |
QRegion dirty(QRect(0, 0, 100, 50)); |
|
4975 |
dirty += QRegion(QRect(0, 50, 150, 10)); |
|
4976 |
dirty += QRegion(QRect(0, 60, 110, 40)); |
|
4977 |
dirty += QRegion(QRect(50, 100, 60, 10)); |
|
4978 |
dirty += QRegion(QRect(50, 110, 10, 40)); |
|
4979 |
QCOMPARE(updateWidget.paintedRegion, dirty); |
|
4980 |
} |
|
4981 |
||
4982 |
{ |
|
4983 |
updateWidget.reset(); |
|
4984 |
updateWidget.update(0, 0, 100, 100); |
|
4985 |
updateWidget.scroll(10, 10, QRect(100, 100, 100, 100)); |
|
4986 |
qApp->processEvents(); |
|
4987 |
QRegion dirty(QRect(0, 0, 100, 100)); |
|
4988 |
dirty += QRegion(QRect(100, 100, 100, 10)); |
|
4989 |
dirty += QRegion(QRect(100, 110, 10, 90)); |
|
4990 |
QCOMPARE(updateWidget.paintedRegion, dirty); |
|
4991 |
} |
|
4992 |
} |
|
4993 |
#endif |
|
4994 |
||
4995 |
class DestroyedSlotChecker : public QObject |
|
4996 |
{ |
|
4997 |
Q_OBJECT |
|
4998 |
||
4999 |
public: |
|
5000 |
bool wasQWidget; |
|
5001 |
||
5002 |
DestroyedSlotChecker() |
|
5003 |
: wasQWidget(false) |
|
5004 |
{ |
|
5005 |
} |
|
5006 |
||
5007 |
public slots: |
|
5008 |
void destroyedSlot(QObject *object) |
|
5009 |
{ |
|
5010 |
wasQWidget = (qobject_cast<QWidget *>(object) != 0 || object->isWidgetType()); |
|
5011 |
} |
|
5012 |
}; |
|
5013 |
||
5014 |
/* |
|
5015 |
Test that qobject_cast<QWidget*> returns 0 in a slot |
|
5016 |
connected to QObject::destroyed. |
|
5017 |
*/ |
|
5018 |
void tst_QWidget::qobject_castInDestroyedSlot() |
|
5019 |
{ |
|
5020 |
DestroyedSlotChecker checker; |
|
5021 |
QWidget *widget = new QWidget(); |
|
5022 |
||
5023 |
QObject::connect(widget, SIGNAL(destroyed(QObject *)), &checker, SLOT(destroyedSlot(QObject *))); |
|
5024 |
delete widget; |
|
5025 |
||
5026 |
QVERIFY(checker.wasQWidget == true); |
|
5027 |
} |
|
5028 |
||
5029 |
Q_DECLARE_METATYPE(QList<QRect>) |
|
5030 |
||
5031 |
void tst_QWidget::setWindowGeometry_data() |
|
5032 |
{ |
|
5033 |
QTest::addColumn<QList<QRect> >("rects"); |
|
5034 |
QTest::addColumn<int>("windowFlags"); |
|
5035 |
||
5036 |
QList<QList<QRect> > rects; |
|
5037 |
rects << (QList<QRect>() |
|
5038 |
<< QRect(100, 100, 200, 200) |
|
5039 |
<< QApplication::desktop()->availableGeometry().adjusted(100, 100, -100, -100) |
|
5040 |
<< QRect(130, 100, 0, 200) |
|
5041 |
<< QRect(100, 50, 200, 0) |
|
5042 |
<< QRect(130, 50, 0, 0)) |
|
5043 |
<< (QList<QRect>() |
|
5044 |
<< QApplication::desktop()->availableGeometry().adjusted(100, 100, -100, -100) |
|
5045 |
<< QRect(130, 100, 0, 200) |
|
5046 |
<< QRect(100, 50, 200, 0) |
|
5047 |
<< QRect(130, 50, 0, 0) |
|
5048 |
<< QRect(100, 100, 200, 200)) |
|
5049 |
<< (QList<QRect>() |
|
5050 |
<< QRect(130, 100, 0, 200) |
|
5051 |
<< QRect(100, 50, 200, 0) |
|
5052 |
<< QRect(130, 50, 0, 0) |
|
5053 |
<< QRect(100, 100, 200, 200) |
|
5054 |
<< QApplication::desktop()->availableGeometry().adjusted(100, 100, -100, -100)) |
|
5055 |
<< (QList<QRect>() |
|
5056 |
<< QRect(100, 50, 200, 0) |
|
5057 |
<< QRect(130, 50, 0, 0) |
|
5058 |
<< QRect(100, 100, 200, 200) |
|
5059 |
<< QApplication::desktop()->availableGeometry().adjusted(100, 100, -100, -100) |
|
5060 |
<< QRect(130, 100, 0, 200)) |
|
5061 |
<< (QList<QRect>() |
|
5062 |
<< QRect(130, 50, 0, 0) |
|
5063 |
<< QRect(100, 100, 200, 200) |
|
5064 |
<< QApplication::desktop()->availableGeometry().adjusted(100, 100, -100, -100) |
|
5065 |
<< QRect(130, 100, 0, 200) |
|
5066 |
<< QRect(100, 50, 200, 0)); |
|
5067 |
||
5068 |
QList<int> windowFlags; |
|
5069 |
windowFlags << 0 |
|
5070 |
<< Qt::FramelessWindowHint |
|
5071 |
#ifdef Q_WS_X11 |
|
5072 |
<< Qt::X11BypassWindowManagerHint |
|
5073 |
#endif |
|
5074 |
; |
|
5075 |
||
5076 |
foreach (QList<QRect> l, rects) { |
|
5077 |
QRect rect = l.first(); |
|
5078 |
foreach (int windowFlag, windowFlags) { |
|
5079 |
QTest::newRow(QString("%1,%2 %3x%4, flags %5") |
|
5080 |
.arg(rect.x()) |
|
5081 |
.arg(rect.y()) |
|
5082 |
.arg(rect.width()) |
|
5083 |
.arg(rect.height()) |
|
5084 |
.arg(windowFlag, 0, 16).toAscii()) |
|
5085 |
<< l |
|
5086 |
<< windowFlag; |
|
5087 |
} |
|
5088 |
} |
|
5089 |
} |
|
5090 |
||
5091 |
void tst_QWidget::setWindowGeometry() |
|
5092 |
{ |
|
5093 |
#ifdef Q_WS_X11 |
|
5094 |
//Since WindowManager operation are all assync, and we have no way to know if the window |
|
5095 |
// manager has finished playing with the window geometry, this test can't be reliable. |
|
5096 |
QSKIP("Window Manager behaviour are too random for this test", SkipAll); |
|
5097 |
#endif |
|
5098 |
QFETCH(QList<QRect>, rects); |
|
5099 |
QFETCH(int, windowFlags); |
|
5100 |
QRect rect = rects.takeFirst(); |
|
5101 |
||
5102 |
{ |
|
5103 |
// test setGeometry() without actually showing the window |
|
5104 |
QWidget widget; |
|
5105 |
if (windowFlags != 0) |
|
5106 |
widget.setWindowFlags(Qt::WindowFlags(windowFlags)); |
|
5107 |
||
5108 |
widget.setGeometry(rect); |
|
5109 |
QTest::qWait(100); |
|
5110 |
QCOMPARE(widget.geometry(), rect); |
|
5111 |
||
5112 |
// setGeometry() without showing |
|
5113 |
foreach (QRect r, rects) { |
|
5114 |
widget.setGeometry(r); |
|
5115 |
QTest::qWait(100); |
|
5116 |
QCOMPARE(widget.geometry(), r); |
|
5117 |
} |
|
5118 |
} |
|
5119 |
||
5120 |
{ |
|
5121 |
// setGeometry() first, then show() |
|
5122 |
QWidget widget; |
|
5123 |
if (windowFlags != 0) |
|
5124 |
widget.setWindowFlags(Qt::WindowFlags(windowFlags)); |
|
5125 |
||
5126 |
widget.setGeometry(rect); |
|
5127 |
widget.show(); |
|
5128 |
QTest::qWaitForWindowShown(&widget); |
|
5129 |
QTest::qWait(20); |
|
5130 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5131 |
||
5132 |
// setGeometry() while shown |
|
5133 |
foreach (QRect r, rects) { |
|
5134 |
widget.setGeometry(r); |
|
5135 |
QTest::qWait(10); |
|
5136 |
QTRY_COMPARE(widget.geometry(), r); |
|
5137 |
} |
|
5138 |
widget.setGeometry(rect); |
|
5139 |
QTest::qWait(20); |
|
5140 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5141 |
||
5142 |
// now hide |
|
5143 |
widget.hide(); |
|
5144 |
QTest::qWait(20); |
|
5145 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5146 |
||
5147 |
// setGeometry() after hide() |
|
5148 |
foreach (QRect r, rects) { |
|
5149 |
widget.setGeometry(r); |
|
5150 |
QTest::qWait(10); |
|
5151 |
QTRY_COMPARE(widget.geometry(), r); |
|
5152 |
} |
|
5153 |
widget.setGeometry(rect); |
|
5154 |
QTest::qWait(10); |
|
5155 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5156 |
||
5157 |
// show() again, geometry() should still be the same |
|
5158 |
widget.show(); |
|
5159 |
QTest::qWaitForWindowShown(&widget); |
|
5160 |
QTest::qWait(10); |
|
5161 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5162 |
||
5163 |
// final hide(), again geometry() should be unchanged |
|
5164 |
widget.hide(); |
|
5165 |
QTest::qWait(10); |
|
5166 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5167 |
} |
|
5168 |
||
5169 |
{ |
|
5170 |
// show() first, then setGeometry() |
|
5171 |
QWidget widget; |
|
5172 |
if (windowFlags != 0) |
|
5173 |
widget.setWindowFlags(Qt::WindowFlags(windowFlags)); |
|
5174 |
||
5175 |
widget.show(); |
|
5176 |
QTest::qWaitForWindowShown(&widget); |
|
5177 |
widget.setGeometry(rect); |
|
5178 |
QTest::qWait(10); |
|
5179 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5180 |
||
5181 |
// setGeometry() while shown |
|
5182 |
foreach (QRect r, rects) { |
|
5183 |
widget.setGeometry(r); |
|
5184 |
QTest::qWait(10); |
|
5185 |
QTRY_COMPARE(widget.geometry(), r); |
|
5186 |
} |
|
5187 |
widget.setGeometry(rect); |
|
5188 |
QTest::qWait(10); |
|
5189 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5190 |
||
5191 |
// now hide |
|
5192 |
widget.hide(); |
|
5193 |
QTest::qWait(10); |
|
5194 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5195 |
||
5196 |
// setGeometry() after hide() |
|
5197 |
foreach (QRect r, rects) { |
|
5198 |
widget.setGeometry(r); |
|
5199 |
QTest::qWait(10); |
|
5200 |
QTRY_COMPARE(widget.geometry(), r); |
|
5201 |
} |
|
5202 |
widget.setGeometry(rect); |
|
5203 |
QTest::qWait(10); |
|
5204 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5205 |
||
5206 |
// show() again, geometry() should still be the same |
|
5207 |
widget.show(); |
|
5208 |
QTest::qWaitForWindowShown(&widget); |
|
5209 |
QTest::qWait(10); |
|
5210 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5211 |
||
5212 |
// final hide(), again geometry() should be unchanged |
|
5213 |
widget.hide(); |
|
5214 |
QTest::qWait(10); |
|
5215 |
QTRY_COMPARE(widget.geometry(), rect); |
|
5216 |
} |
|
5217 |
} |
|
5218 |
||
5219 |
#if defined (Q_WS_WIN) && !defined(Q_OS_WINCE) |
|
5220 |
void tst_QWidget::setGeometry_win() |
|
5221 |
{ |
|
5222 |
QWidget widget; |
|
5223 |
widget.setGeometry(0, 600, 100,100); |
|
5224 |
widget.show(); |
|
5225 |
widget.setWindowState(widget.windowState() | Qt::WindowMaximized); |
|
5226 |
QRect geom = widget.normalGeometry(); |
|
5227 |
widget.close(); |
|
5228 |
widget.setGeometry(geom); |
|
5229 |
widget.setWindowState(widget.windowState() | Qt::WindowMaximized); |
|
5230 |
widget.show(); |
|
5231 |
RECT rt; |
|
5232 |
::GetWindowRect(widget.internalWinId(), &rt); |
|
5233 |
QVERIFY(rt.left <= 0); |
|
5234 |
QVERIFY(rt.top <= 0); |
|
5235 |
} |
|
5236 |
#endif |
|
5237 |
||
5238 |
void tst_QWidget::windowMoveResize_data() |
|
5239 |
{ |
|
5240 |
setWindowGeometry_data(); |
|
5241 |
} |
|
5242 |
||
5243 |
void tst_QWidget::windowMoveResize() |
|
5244 |
{ |
|
5245 |
#ifdef Q_WS_X11 |
|
5246 |
//Since WindowManager operation are all assync, and we have no way to know if the window |
|
5247 |
// manager has finished playing with the window geometry, this test can't be reliable. |
|
5248 |
QSKIP("Window Manager behaviour are too random for this test", SkipAll); |
|
5249 |
#endif |
|
5250 |
#ifdef Q_OS_IRIX |
|
5251 |
QSKIP("4DWM issues on IRIX makes this test fail", SkipAll); |
|
5252 |
#endif |
|
5253 |
QFETCH(QList<QRect>, rects); |
|
5254 |
QFETCH(int, windowFlags); |
|
5255 |
||
5256 |
QRect rect = rects.takeFirst(); |
|
5257 |
||
5258 |
{ |
|
5259 |
// test setGeometry() without actually showing the window |
|
5260 |
QWidget widget; |
|
5261 |
if (windowFlags != 0) |
|
5262 |
widget.setWindowFlags(Qt::WindowFlags(windowFlags)); |
|
5263 |
||
5264 |
widget.move(rect.topLeft()); |
|
5265 |
widget.resize(rect.size()); |
|
5266 |
QTest::qWait(10); |
|
5267 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5268 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5269 |
||
5270 |
// move() without showing |
|
5271 |
foreach (QRect r, rects) { |
|
5272 |
widget.move(r.topLeft()); |
|
5273 |
widget.resize(r.size()); |
|
5274 |
QApplication::processEvents(); |
|
5275 |
QTRY_COMPARE(widget.pos(), r.topLeft()); |
|
5276 |
QTRY_COMPARE(widget.size(), r.size()); |
|
5277 |
} |
|
5278 |
} |
|
5279 |
||
5280 |
{ |
|
5281 |
// move() first, then show() |
|
5282 |
QWidget widget; |
|
5283 |
if (windowFlags != 0) |
|
5284 |
widget.setWindowFlags(Qt::WindowFlags(windowFlags)); |
|
5285 |
||
5286 |
widget.move(rect.topLeft()); |
|
5287 |
widget.resize(rect.size()); |
|
5288 |
widget.show(); |
|
5289 |
||
5290 |
QTest::qWait(10); |
|
5291 |
#if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA) |
|
5292 |
QEXPECT_FAIL("130,50 0x0, flags 0", |
|
5293 |
"Showing a window with 0x0 size shifts it up.", |
|
5294 |
Continue); |
|
5295 |
#endif |
|
5296 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5297 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5298 |
||
5299 |
// move() while shown |
|
5300 |
foreach (QRect r, rects) { |
|
5301 |
#ifdef Q_WS_X11 |
|
5302 |
if ((widget.width() == 0 || widget.height() == 0) && r.width() != 0 && r.height() != 0) { |
|
5303 |
QEXPECT_FAIL("130,100 0x200, flags 0", |
|
5304 |
"First resize after show of zero-sized gets wrong win_gravity.", |
|
5305 |
Continue); |
|
5306 |
QEXPECT_FAIL("100,50 200x0, flags 0", |
|
5307 |
"First resize after show of zero-sized gets wrong win_gravity.", |
|
5308 |
Continue); |
|
5309 |
QEXPECT_FAIL("130,50 0x0, flags 0", |
|
5310 |
"First resize after show of zero-sized gets wrong win_gravity.", |
|
5311 |
Continue); |
|
5312 |
} |
|
5313 |
#endif |
|
5314 |
widget.move(r.topLeft()); |
|
5315 |
widget.resize(r.size()); |
|
5316 |
QApplication::processEvents(); |
|
5317 |
QTRY_COMPARE(widget.pos(), r.topLeft()); |
|
5318 |
QTRY_COMPARE(widget.size(), r.size()); |
|
5319 |
} |
|
5320 |
widget.move(rect.topLeft()); |
|
5321 |
widget.resize(rect.size()); |
|
5322 |
QApplication::processEvents(); |
|
5323 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5324 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5325 |
||
5326 |
// now hide |
|
5327 |
widget.hide(); |
|
5328 |
QTest::qWait(10); |
|
5329 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5330 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5331 |
||
5332 |
// move() after hide() |
|
5333 |
foreach (QRect r, rects) { |
|
5334 |
widget.move(r.topLeft()); |
|
5335 |
widget.resize(r.size()); |
|
5336 |
QApplication::processEvents(); |
|
5337 |
#if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA) |
|
5338 |
if (r.width() == 0 && r.height() > 0) { |
|
5339 |
widget.move(r.topLeft()); |
|
5340 |
widget.resize(r.size()); |
|
5341 |
} |
|
5342 |
#endif |
|
5343 |
QTRY_COMPARE(widget.pos(), r.topLeft()); |
|
5344 |
QTRY_COMPARE(widget.size(), r.size()); |
|
5345 |
} |
|
5346 |
widget.move(rect.topLeft()); |
|
5347 |
widget.resize(rect.size()); |
|
5348 |
QTest::qWait(10); |
|
5349 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5350 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5351 |
||
5352 |
// show() again, pos() should be the same |
|
5353 |
widget.show(); |
|
5354 |
QTest::qWaitForWindowShown(&widget); |
|
5355 |
QApplication::processEvents(); |
|
5356 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5357 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5358 |
||
5359 |
// final hide(), again pos() should be unchanged |
|
5360 |
widget.hide(); |
|
5361 |
QApplication::processEvents(); |
|
5362 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5363 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5364 |
} |
|
5365 |
||
5366 |
{ |
|
5367 |
// show() first, then move() |
|
5368 |
QWidget widget; |
|
5369 |
if (windowFlags != 0) |
|
5370 |
widget.setWindowFlags(Qt::WindowFlags(windowFlags)); |
|
5371 |
||
5372 |
widget.show(); |
|
5373 |
QTest::qWaitForWindowShown(&widget); |
|
5374 |
QApplication::processEvents(); |
|
5375 |
widget.move(rect.topLeft()); |
|
5376 |
widget.resize(rect.size()); |
|
5377 |
QApplication::processEvents(); |
|
5378 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5379 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5380 |
||
5381 |
// move() while shown |
|
5382 |
foreach (QRect r, rects) { |
|
5383 |
widget.move(r.topLeft()); |
|
5384 |
widget.resize(r.size()); |
|
5385 |
QApplication::processEvents(); |
|
5386 |
QTRY_COMPARE(widget.pos(), r.topLeft()); |
|
5387 |
QTRY_COMPARE(widget.size(), r.size()); |
|
5388 |
} |
|
5389 |
widget.move(rect.topLeft()); |
|
5390 |
widget.resize(rect.size()); |
|
5391 |
QApplication::processEvents(); |
|
5392 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5393 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5394 |
||
5395 |
// now hide |
|
5396 |
widget.hide(); |
|
5397 |
QApplication::processEvents(); |
|
5398 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5399 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5400 |
||
5401 |
// move() after hide() |
|
5402 |
foreach (QRect r, rects) { |
|
5403 |
widget.move(r.topLeft()); |
|
5404 |
widget.resize(r.size()); |
|
5405 |
QApplication::processEvents(); |
|
5406 |
#if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA) |
|
5407 |
if (r.width() == 0 && r.height() > 0) { |
|
5408 |
widget.move(r.topLeft()); |
|
5409 |
widget.resize(r.size()); |
|
5410 |
} |
|
5411 |
#endif |
|
5412 |
QTRY_COMPARE(widget.pos(), r.topLeft()); |
|
5413 |
QTRY_COMPARE(widget.size(), r.size()); |
|
5414 |
} |
|
5415 |
widget.move(rect.topLeft()); |
|
5416 |
widget.resize(rect.size()); |
|
5417 |
QApplication::processEvents(); |
|
5418 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5419 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5420 |
||
5421 |
// show() again, pos() should be the same |
|
5422 |
widget.show(); |
|
5423 |
QTest::qWaitForWindowShown(&widget); |
|
5424 |
QTest::qWait(10); |
|
5425 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5426 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5427 |
||
5428 |
// final hide(), again pos() should be unchanged |
|
5429 |
widget.hide(); |
|
5430 |
QTest::qWait(10); |
|
5431 |
QTRY_COMPARE(widget.pos(), rect.topLeft()); |
|
5432 |
QTRY_COMPARE(widget.size(), rect.size()); |
|
5433 |
} |
|
5434 |
} |
|
5435 |
||
5436 |
class ColorWidget : public QWidget |
|
5437 |
{ |
|
5438 |
public: |
|
5439 |
ColorWidget(QWidget *parent = 0, const QColor &c = QColor(Qt::red)) |
|
5440 |
: QWidget(parent, Qt::FramelessWindowHint), color(c) |
|
5441 |
{ |
|
5442 |
QPalette opaquePalette = palette(); |
|
5443 |
opaquePalette.setColor(backgroundRole(), color); |
|
5444 |
setPalette(opaquePalette); |
|
5445 |
setAutoFillBackground(true); |
|
5446 |
} |
|
5447 |
||
5448 |
void paintEvent(QPaintEvent *e) { |
|
5449 |
r += e->region(); |
|
5450 |
} |
|
5451 |
||
5452 |
void reset() { |
|
5453 |
r = QRegion(); |
|
5454 |
} |
|
5455 |
||
5456 |
QColor color; |
|
5457 |
QRegion r; |
|
5458 |
}; |
|
5459 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5460 |
#define VERIFY_COLOR(region, color) { \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5461 |
const QRegion r = QRegion(region); \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5462 |
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
|
5463 |
const QRect rect = r.rects().at(i); \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5464 |
for (int t = 0; t < 5; t++) { \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5465 |
const QPixmap pixmap = QPixmap::grabWindow(QDesktopWidget().winId(), \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5466 |
rect.left(), rect.top(), \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5467 |
rect.width(), rect.height()); \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5468 |
QCOMPARE(pixmap.size(), rect.size()); \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5469 |
QPixmap expectedPixmap(pixmap); /* ensure equal formats */ \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5470 |
expectedPixmap.fill(color); \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5471 |
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
|
5472 |
{ QTest::qWait(200); continue; } \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5473 |
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
|
5474 |
QCOMPARE(pixmap, expectedPixmap); \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5475 |
break; \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5476 |
} \ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5477 |
} \ |
0 | 5478 |
} |
5479 |
||
5480 |
void tst_QWidget::moveChild_data() |
|
5481 |
{ |
|
5482 |
QTest::addColumn<QPoint>("offset"); |
|
5483 |
||
5484 |
QTest::newRow("right") << QPoint(20, 0); |
|
5485 |
QTest::newRow("down") << QPoint(0, 20); |
|
5486 |
QTest::newRow("left") << QPoint(-20, 0); |
|
5487 |
QTest::newRow("up") << QPoint(0, -20); |
|
5488 |
} |
|
5489 |
||
5490 |
void tst_QWidget::moveChild() |
|
5491 |
{ |
|
5492 |
QFETCH(QPoint, offset); |
|
5493 |
||
5494 |
ColorWidget parent; |
|
5495 |
// prevent custom styles |
|
5496 |
parent.setStyle(new QWindowsStyle); |
|
5497 |
ColorWidget child(&parent, Qt::blue); |
|
5498 |
||
5499 |
#ifndef Q_OS_WINCE |
|
5500 |
parent.setGeometry(QRect(QPoint(QApplication::desktop()->availableGeometry(&parent).topLeft()), |
|
5501 |
QSize(100, 100))); |
|
5502 |
#else |
|
5503 |
parent.setGeometry(60, 60, 150, 150); |
|
5504 |
#endif |
|
5505 |
child.setGeometry(25, 25, 50, 50); |
|
5506 |
QPoint childOffset = child.mapToGlobal(QPoint()); |
|
5507 |
||
5508 |
parent.show(); |
|
5509 |
QTest::qWaitForWindowShown(&parent); |
|
5510 |
QTest::qWait(30); |
|
5511 |
const QPoint tlwOffset = parent.geometry().topLeft(); |
|
5512 |
||
5513 |
#ifdef QT_MAC_USE_COCOA |
|
5514 |
QEXPECT_FAIL(0, "Cocoa compositor paints the entire content view, even when opaque", Continue); |
|
5515 |
#endif |
|
5516 |
QTRY_COMPARE(parent.r, QRegion(parent.rect()) - child.geometry()); |
|
5517 |
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
|
5518 |
VERIFY_COLOR(child.geometry().translated(tlwOffset), |
0 | 5519 |
child.color); |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5520 |
VERIFY_COLOR(QRegion(parent.geometry()) - child.geometry().translated(tlwOffset), |
0 | 5521 |
parent.color); |
5522 |
parent.reset(); |
|
5523 |
child.reset(); |
|
5524 |
||
5525 |
// move |
|
5526 |
||
5527 |
const QRect oldGeometry = child.geometry(); |
|
5528 |
||
5529 |
QPoint pos = child.pos() + offset; |
|
5530 |
child.move(pos); |
|
5531 |
QTest::qWait(100); |
|
5532 |
QTRY_COMPARE(pos, child.pos()); |
|
5533 |
||
5534 |
QCOMPARE(parent.r, QRegion(oldGeometry) - child.geometry()); |
|
5535 |
#if !defined(Q_WS_MAC) |
|
5536 |
// should be scrolled in backingstore |
|
5537 |
QCOMPARE(child.r, QRegion()); |
|
5538 |
#endif |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5539 |
VERIFY_COLOR(child.geometry().translated(tlwOffset), |
0 | 5540 |
child.color); |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5541 |
VERIFY_COLOR(QRegion(parent.geometry()) - child.geometry().translated(tlwOffset), |
0 | 5542 |
parent.color); |
5543 |
} |
|
5544 |
||
5545 |
void tst_QWidget::showAndMoveChild() |
|
5546 |
{ |
|
5547 |
QWidget parent(0, Qt::FramelessWindowHint); |
|
5548 |
// prevent custom styles |
|
5549 |
parent.setStyle(new QWindowsStyle); |
|
5550 |
||
5551 |
QDesktopWidget desktop; |
|
5552 |
QRect desktopDimensions = desktop.availableGeometry(&parent); |
|
5553 |
||
5554 |
parent.setGeometry(desktopDimensions); |
|
5555 |
parent.setPalette(Qt::red); |
|
5556 |
parent.show(); |
|
5557 |
QTest::qWaitForWindowShown(&parent); |
|
5558 |
QTest::qWait(10); |
|
5559 |
||
5560 |
const QPoint tlwOffset = parent.geometry().topLeft(); |
|
5561 |
QWidget child(&parent); |
|
5562 |
child.resize(desktopDimensions.width()/2, desktopDimensions.height()/2); |
|
5563 |
child.setPalette(Qt::blue); |
|
5564 |
child.setAutoFillBackground(true); |
|
5565 |
||
5566 |
// Ensure that the child is repainted correctly when moved right after show. |
|
5567 |
// NB! Do NOT processEvents() (or qWait()) in between show() and move(). |
|
5568 |
child.show(); |
|
5569 |
child.move(desktopDimensions.width()/2, desktopDimensions.height()/2); |
|
5570 |
qApp->processEvents(); |
|
5571 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
5572 |
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
|
5573 |
VERIFY_COLOR(QRegion(parent.geometry()) - child.geometry().translated(tlwOffset), Qt::red); |
0 | 5574 |
} |
5575 |
||
5576 |
void tst_QWidget::subtractOpaqueSiblings() |
|
5577 |
{ |
|
5578 |
#ifdef QT_MAC_USE_COCOA |
|
5579 |
QSKIP("Cocoa only has rect granularity.", SkipAll); |
|
5580 |
#else |
|
5581 |
QWidget w; |
|
5582 |
w.setGeometry(50, 50, 300, 300); |
|
5583 |
||
5584 |
ColorWidget *large = new ColorWidget(&w, Qt::red); |
|
5585 |
large->setGeometry(50, 50, 200, 200); |
|
5586 |
||
5587 |
ColorWidget *medium = new ColorWidget(large, Qt::gray); |
|
5588 |
medium->setGeometry(50, 50, 100, 100); |
|
5589 |
||
5590 |
ColorWidget *tall = new ColorWidget(&w, Qt::blue); |
|
5591 |
tall->setGeometry(100, 30, 50, 100); |
|
5592 |
||
5593 |
w.show(); |
|
5594 |
QTest::qWaitForWindowShown(&w); |
|
5595 |
QTest::qWait(10); |
|
5596 |
||
5597 |
large->reset(); |
|
5598 |
medium->reset(); |
|
5599 |
tall->reset(); |
|
5600 |
||
5601 |
medium->update(); |
|
5602 |
QTest::qWait(10); |
|
5603 |
||
5604 |
// QWidgetPrivate::subtractOpaqueSiblings() should prevent parts of medium |
|
5605 |
// to be repainted and tall from be repainted at all. |
|
5606 |
||
5607 |
QTRY_COMPARE(large->r, QRegion()); |
|
5608 |
QTRY_COMPARE(tall->r, QRegion()); |
|
5609 |
QTRY_COMPARE(medium->r.translated(medium->mapTo(&w, QPoint())), |
|
5610 |
QRegion(medium->geometry().translated(large->pos())) |
|
5611 |
- tall->geometry()); |
|
5612 |
#endif |
|
5613 |
} |
|
5614 |
||
5615 |
void tst_QWidget::deleteStyle() |
|
5616 |
{ |
|
5617 |
QWidget widget; |
|
5618 |
widget.setStyle(new QWindowsStyle); |
|
5619 |
widget.show(); |
|
5620 |
delete widget.style(); |
|
5621 |
qApp->processEvents(); |
|
5622 |
} |
|
5623 |
||
5624 |
#ifdef Q_WS_WIN |
|
5625 |
void tst_QWidget::getDC() |
|
5626 |
{ |
|
5627 |
QWidget widget; |
|
5628 |
widget.setGeometry(0, 0, 2, 4); |
|
5629 |
||
5630 |
HDC dc = widget.getDC(); |
|
5631 |
QVERIFY(dc != 0); |
|
5632 |
||
5633 |
widget.releaseDC(dc); |
|
5634 |
} |
|
5635 |
#endif |
|
5636 |
||
5637 |
class TopLevelFocusCheck: public QWidget |
|
5638 |
{ |
|
5639 |
Q_OBJECT |
|
5640 |
public: |
|
5641 |
QLineEdit* edit; |
|
5642 |
TopLevelFocusCheck(QWidget* parent = 0) : QWidget(parent) |
|
5643 |
{ |
|
5644 |
edit = new QLineEdit(this); |
|
5645 |
edit->hide(); |
|
5646 |
edit->installEventFilter(this); |
|
5647 |
} |
|
5648 |
||
5649 |
public slots: |
|
5650 |
void mouseDoubleClickEvent ( QMouseEvent * /*event*/ ) |
|
5651 |
{ |
|
5652 |
edit->show(); |
|
5653 |
edit->setFocus(Qt::OtherFocusReason); |
|
5654 |
qApp->processEvents(); |
|
5655 |
} |
|
5656 |
bool eventFilter(QObject *obj, QEvent *event) |
|
5657 |
{ |
|
5658 |
if (obj == edit && event->type()== QEvent::FocusOut) { |
|
5659 |
edit->hide(); |
|
5660 |
return true; |
|
5661 |
} |
|
5662 |
return false; |
|
5663 |
} |
|
5664 |
}; |
|
5665 |
||
5666 |
void tst_QWidget::multipleToplevelFocusCheck() |
|
5667 |
{ |
|
5668 |
TopLevelFocusCheck w1; |
|
5669 |
TopLevelFocusCheck w2; |
|
5670 |
||
5671 |
w1.resize(200, 200); |
|
5672 |
w1.show(); |
|
5673 |
QTest::qWaitForWindowShown(&w1); |
|
5674 |
w2.resize(200,200); |
|
5675 |
w2.show(); |
|
5676 |
QTest::qWaitForWindowShown(&w2); |
|
5677 |
||
5678 |
QTest::qWait(100); |
|
5679 |
||
5680 |
QApplication::setActiveWindow(&w1); |
|
5681 |
w1.activateWindow(); |
|
5682 |
QApplication::processEvents(); |
|
5683 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w1)); |
|
5684 |
QTest::qWait(50); |
|
5685 |
QTest::mouseDClick(&w1, Qt::LeftButton); |
|
5686 |
QTRY_COMPARE(QApplication::focusWidget(), static_cast<QWidget *>(w1.edit)); |
|
5687 |
||
5688 |
w2.activateWindow(); |
|
5689 |
QApplication::setActiveWindow(&w2); |
|
5690 |
QApplication::processEvents(); |
|
5691 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w2)); |
|
5692 |
QTest::mouseClick(&w2, Qt::LeftButton); |
|
5693 |
#ifdef Q_WS_QWS |
|
5694 |
QEXPECT_FAIL("", "embedded toplevels take focus anyway", Continue); |
|
5695 |
#endif |
|
5696 |
QTRY_COMPARE(QApplication::focusWidget(), (QWidget *)0); |
|
5697 |
||
5698 |
QTest::mouseDClick(&w2, Qt::LeftButton); |
|
5699 |
QTRY_COMPARE(QApplication::focusWidget(), static_cast<QWidget *>(w2.edit)); |
|
5700 |
||
5701 |
w1.activateWindow(); |
|
5702 |
QApplication::setActiveWindow(&w1); |
|
5703 |
QApplication::processEvents(); |
|
5704 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w1)); |
|
5705 |
QTest::mouseDClick(&w1, Qt::LeftButton); |
|
5706 |
QTRY_COMPARE(QApplication::focusWidget(), static_cast<QWidget *>(w1.edit)); |
|
5707 |
||
5708 |
w2.activateWindow(); |
|
5709 |
QApplication::setActiveWindow(&w2); |
|
5710 |
QApplication::processEvents(); |
|
5711 |
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w2)); |
|
5712 |
QTest::mouseClick(&w2, Qt::LeftButton); |
|
5713 |
QTRY_COMPARE(QApplication::focusWidget(), (QWidget *)0); |
|
5714 |
} |
|
5715 |
||
5716 |
void tst_QWidget::setFocus() |
|
5717 |
{ |
|
5718 |
{ |
|
5719 |
// move focus to another window |
|
5720 |
testWidget->activateWindow(); |
|
5721 |
QApplication::setActiveWindow(testWidget); |
|
5722 |
if (testWidget->focusWidget()) |
|
5723 |
testWidget->focusWidget()->clearFocus(); |
|
5724 |
else |
|
5725 |
testWidget->clearFocus(); |
|
5726 |
||
5727 |
// window and children never shown, nobody gets focus |
|
5728 |
QWidget window; |
|
5729 |
||
5730 |
QWidget child1(&window); |
|
5731 |
child1.setFocusPolicy(Qt::StrongFocus); |
|
5732 |
||
5733 |
QWidget child2(&window); |
|
5734 |
child2.setFocusPolicy(Qt::StrongFocus); |
|
5735 |
||
5736 |
child1.setFocus(); |
|
5737 |
QVERIFY(!child1.hasFocus()); |
|
5738 |
QCOMPARE(window.focusWidget(), &child1); |
|
5739 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5740 |
||
5741 |
child2.setFocus(); |
|
5742 |
QVERIFY(!child2.hasFocus()); |
|
5743 |
QCOMPARE(window.focusWidget(), &child2); |
|
5744 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5745 |
} |
|
5746 |
||
5747 |
{ |
|
5748 |
// window and children show, but window not active, nobody gets focus |
|
5749 |
QWidget window; |
|
5750 |
||
5751 |
QWidget child1(&window); |
|
5752 |
child1.setFocusPolicy(Qt::StrongFocus); |
|
5753 |
||
5754 |
QWidget child2(&window); |
|
5755 |
child2.setFocusPolicy(Qt::StrongFocus); |
|
5756 |
||
5757 |
window.show(); |
|
5758 |
||
5759 |
// note: window may be active, but we don't want it to be |
|
5760 |
testWidget->activateWindow(); |
|
5761 |
QApplication::setActiveWindow(testWidget); |
|
5762 |
if (testWidget->focusWidget()) |
|
5763 |
testWidget->focusWidget()->clearFocus(); |
|
5764 |
else |
|
5765 |
testWidget->clearFocus(); |
|
5766 |
||
5767 |
child1.setFocus(); |
|
5768 |
QVERIFY(!child1.hasFocus()); |
|
5769 |
QCOMPARE(window.focusWidget(), &child1); |
|
5770 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5771 |
||
5772 |
child2.setFocus(); |
|
5773 |
QVERIFY(!child2.hasFocus()); |
|
5774 |
QCOMPARE(window.focusWidget(), &child2); |
|
5775 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5776 |
} |
|
5777 |
||
5778 |
{ |
|
5779 |
// window and children show, but window *is* active, children get focus |
|
5780 |
QWidget window; |
|
5781 |
||
5782 |
QWidget child1(&window); |
|
5783 |
child1.setFocusPolicy(Qt::StrongFocus); |
|
5784 |
||
5785 |
QWidget child2(&window); |
|
5786 |
child2.setFocusPolicy(Qt::StrongFocus); |
|
5787 |
||
5788 |
window.show(); |
|
5789 |
#ifdef Q_WS_X11 |
|
5790 |
QApplication::setActiveWindow(&window); |
|
5791 |
QTest::qWaitForWindowShown(&window); |
|
5792 |
#else |
|
5793 |
window.activateWindow(); |
|
5794 |
QApplication::processEvents(); |
|
5795 |
#endif |
|
5796 |
||
5797 |
child1.setFocus(); |
|
5798 |
QTRY_VERIFY(child1.hasFocus()); |
|
5799 |
QCOMPARE(window.focusWidget(), &child1); |
|
5800 |
QCOMPARE(QApplication::focusWidget(), &child1); |
|
5801 |
||
5802 |
child2.setFocus(); |
|
5803 |
QVERIFY(child2.hasFocus()); |
|
5804 |
QCOMPARE(window.focusWidget(), &child2); |
|
5805 |
QCOMPARE(QApplication::focusWidget(), &child2); |
|
5806 |
} |
|
5807 |
||
5808 |
{ |
|
5809 |
// window shown and active, children created, don't get focus, but get focus when shown |
|
5810 |
QWidget window; |
|
5811 |
||
5812 |
window.show(); |
|
5813 |
#ifdef Q_WS_X11 |
|
5814 |
QApplication::setActiveWindow(&window); |
|
5815 |
QTest::qWaitForWindowShown(&window); |
|
5816 |
#else |
|
5817 |
window.activateWindow(); |
|
5818 |
#endif |
|
5819 |
||
5820 |
QWidget child1(&window); |
|
5821 |
child1.setFocusPolicy(Qt::StrongFocus); |
|
5822 |
||
5823 |
QWidget child2(&window); |
|
5824 |
child2.setFocusPolicy(Qt::StrongFocus); |
|
5825 |
||
5826 |
child1.setFocus(); |
|
5827 |
QVERIFY(!child1.hasFocus()); |
|
5828 |
QCOMPARE(window.focusWidget(), static_cast<QWidget *>(0)); |
|
5829 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5830 |
||
5831 |
child1.show(); |
|
5832 |
#ifdef Q_WS_X11 |
|
5833 |
QApplication::setActiveWindow(&child1); |
|
5834 |
child1.activateWindow(); |
|
5835 |
#endif |
|
5836 |
QApplication::processEvents(); |
|
5837 |
QTRY_VERIFY(child1.hasFocus()); |
|
5838 |
QCOMPARE(window.focusWidget(), &child1); |
|
5839 |
QCOMPARE(QApplication::focusWidget(), &child1); |
|
5840 |
||
5841 |
child2.setFocus(); |
|
5842 |
QVERIFY(!child2.hasFocus()); |
|
5843 |
QCOMPARE(window.focusWidget(), &child1); |
|
5844 |
QCOMPARE(QApplication::focusWidget(), &child1); |
|
5845 |
||
5846 |
child2.show(); |
|
5847 |
QVERIFY(child2.hasFocus()); |
|
5848 |
QCOMPARE(window.focusWidget(), &child2); |
|
5849 |
QCOMPARE(QApplication::focusWidget(), &child2); |
|
5850 |
} |
|
5851 |
||
5852 |
{ |
|
5853 |
// window shown and active, children created, don't get focus, |
|
5854 |
// even after setFocus(), hide(), then show() |
|
5855 |
QWidget window; |
|
5856 |
||
5857 |
window.show(); |
|
5858 |
#ifdef Q_WS_X11 |
|
5859 |
QApplication::setActiveWindow(&window); |
|
5860 |
QTest::qWaitForWindowShown(&window); |
|
5861 |
#else |
|
5862 |
window.activateWindow(); |
|
5863 |
#endif |
|
5864 |
||
5865 |
QWidget child1(&window); |
|
5866 |
child1.setFocusPolicy(Qt::StrongFocus); |
|
5867 |
||
5868 |
QWidget child2(&window); |
|
5869 |
child2.setFocusPolicy(Qt::StrongFocus); |
|
5870 |
||
5871 |
child1.setFocus(); |
|
5872 |
QVERIFY(!child1.hasFocus()); |
|
5873 |
QCOMPARE(window.focusWidget(), static_cast<QWidget *>(0)); |
|
5874 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5875 |
||
5876 |
child1.hide(); |
|
5877 |
QVERIFY(!child1.hasFocus()); |
|
5878 |
QCOMPARE(window.focusWidget(), static_cast<QWidget *>(0)); |
|
5879 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5880 |
||
5881 |
child1.show(); |
|
5882 |
QVERIFY(!child1.hasFocus()); |
|
5883 |
QCOMPARE(window.focusWidget(), static_cast<QWidget *>(0)); |
|
5884 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5885 |
||
5886 |
child2.setFocus(); |
|
5887 |
QVERIFY(!child2.hasFocus()); |
|
5888 |
QCOMPARE(window.focusWidget(), static_cast<QWidget *>(0)); |
|
5889 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5890 |
||
5891 |
child2.hide(); |
|
5892 |
QVERIFY(!child2.hasFocus()); |
|
5893 |
QCOMPARE(window.focusWidget(), static_cast<QWidget *>(0)); |
|
5894 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5895 |
||
5896 |
child2.show(); |
|
5897 |
QVERIFY(!child2.hasFocus()); |
|
5898 |
QCOMPARE(window.focusWidget(), static_cast<QWidget *>(0)); |
|
5899 |
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0)); |
|
5900 |
} |
|
5901 |
} |
|
5902 |
||
5903 |
class EventSpy : public QObject |
|
5904 |
{ |
|
5905 |
public: |
|
5906 |
EventSpy(QWidget *widget, QEvent::Type event) |
|
5907 |
: m_widget(widget), eventToSpy(event), m_count(0) |
|
5908 |
{ |
|
5909 |
if (m_widget) |
|
5910 |
m_widget->installEventFilter(this); |
|
5911 |
} |
|
5912 |
||
5913 |
QWidget *widget() const { return m_widget; } |
|
5914 |
int count() const { return m_count; } |
|
5915 |
void clear() { m_count = 0; } |
|
5916 |
||
5917 |
protected: |
|
5918 |
bool eventFilter(QObject *object, QEvent *event) |
|
5919 |
{ |
|
5920 |
if (event->type() == eventToSpy) |
|
5921 |
++m_count; |
|
5922 |
return QObject::eventFilter(object, event); |
|
5923 |
} |
|
5924 |
||
5925 |
private: |
|
5926 |
QWidget *m_widget; |
|
5927 |
QEvent::Type eventToSpy; |
|
5928 |
int m_count; |
|
5929 |
}; |
|
5930 |
||
5931 |
void tst_QWidget::setCursor() |
|
5932 |
{ |
|
5933 |
#ifndef QT_NO_CURSOR |
|
5934 |
{ |
|
5935 |
QWidget window; |
|
5936 |
QWidget child(&window); |
|
5937 |
||
5938 |
QVERIFY(!window.testAttribute(Qt::WA_SetCursor)); |
|
5939 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5940 |
||
5941 |
window.setCursor(window.cursor()); |
|
5942 |
QVERIFY(window.testAttribute(Qt::WA_SetCursor)); |
|
5943 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5944 |
QCOMPARE(child.cursor().shape(), window.cursor().shape()); |
|
5945 |
} |
|
5946 |
||
5947 |
// do it again, but with window show()n |
|
5948 |
{ |
|
5949 |
QWidget window; |
|
5950 |
QWidget child(&window); |
|
5951 |
window.show(); |
|
5952 |
||
5953 |
QVERIFY(!window.testAttribute(Qt::WA_SetCursor)); |
|
5954 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5955 |
||
5956 |
window.setCursor(window.cursor()); |
|
5957 |
QVERIFY(window.testAttribute(Qt::WA_SetCursor)); |
|
5958 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5959 |
QCOMPARE(child.cursor().shape(), window.cursor().shape()); |
|
5960 |
} |
|
5961 |
||
5962 |
||
5963 |
{ |
|
5964 |
QWidget window; |
|
5965 |
QWidget child(&window); |
|
5966 |
||
5967 |
window.setCursor(Qt::WaitCursor); |
|
5968 |
QVERIFY(window.testAttribute(Qt::WA_SetCursor)); |
|
5969 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5970 |
QCOMPARE(child.cursor().shape(), window.cursor().shape()); |
|
5971 |
} |
|
5972 |
||
5973 |
// same thing again, just with window show()n |
|
5974 |
{ |
|
5975 |
QWidget window; |
|
5976 |
QWidget child(&window); |
|
5977 |
||
5978 |
window.show(); |
|
5979 |
window.setCursor(Qt::WaitCursor); |
|
5980 |
QVERIFY(window.testAttribute(Qt::WA_SetCursor)); |
|
5981 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5982 |
QCOMPARE(child.cursor().shape(), window.cursor().shape()); |
|
5983 |
} |
|
5984 |
||
5985 |
// reparenting child should not cause the WA_SetCursor to become set |
|
5986 |
{ |
|
5987 |
QWidget window; |
|
5988 |
QWidget window2; |
|
5989 |
QWidget child(&window); |
|
5990 |
||
5991 |
window.setCursor(Qt::WaitCursor); |
|
5992 |
||
5993 |
child.setParent(0); |
|
5994 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5995 |
QCOMPARE(child.cursor().shape(), QCursor().shape()); |
|
5996 |
||
5997 |
child.setParent(&window2); |
|
5998 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
5999 |
QCOMPARE(child.cursor().shape(), window2.cursor().shape()); |
|
6000 |
||
6001 |
window2.setCursor(Qt::WaitCursor); |
|
6002 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
6003 |
QCOMPARE(child.cursor().shape(), window2.cursor().shape()); |
|
6004 |
} |
|
6005 |
||
6006 |
// again, with windows show()n |
|
6007 |
{ |
|
6008 |
QWidget window; |
|
6009 |
QWidget window2; |
|
6010 |
QWidget child(&window); |
|
6011 |
||
6012 |
window.setCursor(Qt::WaitCursor); |
|
6013 |
window.show(); |
|
6014 |
||
6015 |
child.setParent(0); |
|
6016 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
6017 |
QCOMPARE(child.cursor().shape(), QCursor().shape()); |
|
6018 |
||
6019 |
child.setParent(&window2); |
|
6020 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
6021 |
QCOMPARE(child.cursor().shape(), window2.cursor().shape()); |
|
6022 |
||
6023 |
window2.show(); |
|
6024 |
window2.setCursor(Qt::WaitCursor); |
|
6025 |
QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); |
|
6026 |
QCOMPARE(child.cursor().shape(), window2.cursor().shape()); |
|
6027 |
} |
|
6028 |
||
6029 |
// test if CursorChange is sent |
|
6030 |
{ |
|
6031 |
QWidget widget; |
|
6032 |
EventSpy spy(&widget, QEvent::CursorChange); |
|
6033 |
QCOMPARE(spy.count(), 0); |
|
6034 |
widget.setCursor(QCursor(Qt::WaitCursor)); |
|
6035 |
QCOMPARE(spy.count(), 1); |
|
6036 |
widget.unsetCursor(); |
|
6037 |
QCOMPARE(spy.count(), 2); |
|
6038 |
} |
|
6039 |
#endif |
|
6040 |
} |
|
6041 |
||
6042 |
void tst_QWidget::setToolTip() |
|
6043 |
{ |
|
6044 |
QWidget widget; |
|
6045 |
EventSpy spy(&widget, QEvent::ToolTipChange); |
|
6046 |
QCOMPARE(spy.count(), 0); |
|
6047 |
||
6048 |
QCOMPARE(widget.toolTip(), QString()); |
|
6049 |
widget.setToolTip(QString("Hello")); |
|
6050 |
QCOMPARE(widget.toolTip(), QString("Hello")); |
|
6051 |
QCOMPARE(spy.count(), 1); |
|
6052 |
widget.setToolTip(QString()); |
|
6053 |
QCOMPARE(widget.toolTip(), QString()); |
|
6054 |
QCOMPARE(spy.count(), 2); |
|
6055 |
||
6056 |
#ifdef Q_OS_WINCE_WM |
|
6057 |
QSKIP("Mouse over doesn't work on Windows mobile.", SkipAll); |
|
6058 |
#endif |
|
6059 |
||
6060 |
for (int pass = 0; pass < 2; ++pass) { |
|
6061 |
QWidget *popup = new QWidget(0, Qt::Popup); |
|
6062 |
popup->resize(150, 50); |
|
6063 |
QFrame *frame = new QFrame(popup); |
|
6064 |
frame->setGeometry(0, 0, 50, 50); |
|
6065 |
frame->setFrameStyle(QFrame::Box | QFrame::Plain); |
|
6066 |
EventSpy spy1(frame, QEvent::ToolTip); |
|
6067 |
EventSpy spy2(popup, QEvent::ToolTip); |
|
6068 |
frame->setMouseTracking(pass == 0 ? false : true); |
|
6069 |
frame->setToolTip(QLatin1String("TOOLTIP FRAME")); |
|
6070 |
popup->setToolTip(QLatin1String("TOOLTIP POPUP")); |
|
6071 |
popup->show(); |
|
6072 |
QTest::qWaitForWindowShown(popup); |
|
6073 |
QTest::qWait(10); |
|
6074 |
QTest::mouseMove(frame); |
|
6075 |
QTest::qWait(900); // delay is 700 |
|
6076 |
||
6077 |
QCOMPARE(spy1.count(), 1); |
|
6078 |
QCOMPARE(spy2.count(), 0); |
|
6079 |
if (pass == 0) |
|
6080 |
QTest::qWait(2200); // delay is 2000 |
|
6081 |
QTest::mouseMove(popup); |
|
6082 |
delete popup; |
|
6083 |
} |
|
6084 |
} |
|
6085 |
||
6086 |
void tst_QWidget::testWindowIconChangeEventPropagation() |
|
6087 |
{ |
|
6088 |
// Create widget hierarchy. |
|
6089 |
QWidget topLevelWidget; |
|
6090 |
QWidget topLevelChild(&topLevelWidget); |
|
6091 |
||
6092 |
QDialog dialog(&topLevelWidget); |
|
6093 |
QWidget dialogChild(&dialog); |
|
6094 |
||
6095 |
QWidgetList widgets; |
|
6096 |
widgets << &topLevelWidget << &topLevelChild |
|
6097 |
<< &dialog << &dialogChild; |
|
6098 |
QCOMPARE(widgets.count(), 4); |
|
6099 |
||
6100 |
// Create spy lists. |
|
6101 |
QList <EventSpy *> applicationEventSpies; |
|
6102 |
QList <EventSpy *> widgetEventSpies; |
|
6103 |
foreach (QWidget *widget, widgets) { |
|
6104 |
applicationEventSpies.append(new EventSpy(widget, QEvent::ApplicationWindowIconChange)); |
|
6105 |
widgetEventSpies.append(new EventSpy(widget, QEvent::WindowIconChange)); |
|
6106 |
} |
|
6107 |
||
6108 |
// QApplication::setWindowIcon |
|
6109 |
const QIcon windowIcon = qApp->style()->standardIcon(QStyle::SP_TitleBarMenuButton); |
|
6110 |
qApp->setWindowIcon(windowIcon); |
|
6111 |
||
6112 |
for (int i = 0; i < widgets.count(); ++i) { |
|
6113 |
// Check QEvent::ApplicationWindowIconChange |
|
6114 |
EventSpy *spy = applicationEventSpies.at(i); |
|
6115 |
QWidget *widget = spy->widget(); |
|
6116 |
if (widget->isWindow()) { |
|
6117 |
QCOMPARE(spy->count(), 1); |
|
6118 |
QCOMPARE(widget->windowIcon(), windowIcon); |
|
6119 |
} else { |
|
6120 |
QCOMPARE(spy->count(), 0); |
|
6121 |
} |
|
6122 |
spy->clear(); |
|
6123 |
||
6124 |
// Check QEvent::WindowIconChange |
|
6125 |
spy = widgetEventSpies.at(i); |
|
6126 |
QCOMPARE(spy->count(), 1); |
|
6127 |
spy->clear(); |
|
6128 |
} |
|
6129 |
||
6130 |
// Set icon on a top-level widget. |
|
6131 |
topLevelWidget.setWindowIcon(*new QIcon); |
|
6132 |
||
6133 |
for (int i = 0; i < widgets.count(); ++i) { |
|
6134 |
// Check QEvent::ApplicationWindowIconChange |
|
6135 |
EventSpy *spy = applicationEventSpies.at(i); |
|
6136 |
QCOMPARE(spy->count(), 0); |
|
6137 |
spy->clear(); |
|
6138 |
||
6139 |
// Check QEvent::WindowIconChange |
|
6140 |
spy = widgetEventSpies.at(i); |
|
6141 |
QWidget *widget = spy->widget(); |
|
6142 |
if (widget == &topLevelWidget) { |
|
6143 |
QCOMPARE(widget->windowIcon(), QIcon()); |
|
6144 |
QCOMPARE(spy->count(), 1); |
|
6145 |
} else if (topLevelWidget.isAncestorOf(widget)) { |
|
6146 |
QCOMPARE(spy->count(), 1); |
|
6147 |
} else { |
|
6148 |
QCOMPARE(spy->count(), 0); |
|
6149 |
} |
|
6150 |
spy->clear(); |
|
6151 |
} |
|
6152 |
||
6153 |
// Cleanup. |
|
6154 |
for (int i = 0; i < widgets.count(); ++i) { |
|
6155 |
delete applicationEventSpies.at(i); |
|
6156 |
delete widgetEventSpies.at(i); |
|
6157 |
} |
|
6158 |
qApp->setWindowIcon(QIcon()); |
|
6159 |
} |
|
6160 |
||
6161 |
#ifdef Q_WS_X11 |
|
6162 |
void tst_QWidget::minAndMaxSizeWithX11BypassWindowManagerHint() |
|
6163 |
{ |
|
6164 |
// Same size as in QWidget::create_sys(). |
|
6165 |
const QSize desktopSize = QApplication::desktop()->size(); |
|
6166 |
const QSize originalSize(desktopSize.width() / 2, desktopSize.height() * 4 / 10); |
|
6167 |
||
6168 |
{ // Maximum size. |
|
6169 |
QWidget widget(0, Qt::X11BypassWindowManagerHint); |
|
6170 |
||
6171 |
const QSize newMaximumSize = widget.size().boundedTo(originalSize) - QSize(10, 10); |
|
6172 |
widget.setMaximumSize(newMaximumSize); |
|
6173 |
QCOMPARE(widget.size(), newMaximumSize); |
|
6174 |
||
6175 |
widget.show(); |
|
6176 |
qt_x11_wait_for_window_manager(&widget); |
|
6177 |
QCOMPARE(widget.size(), newMaximumSize); |
|
6178 |
} |
|
6179 |
||
6180 |
{ // Minimum size. |
|
6181 |
QWidget widget(0, Qt::X11BypassWindowManagerHint); |
|
6182 |
||
6183 |
const QSize newMinimumSize = widget.size().expandedTo(originalSize) + QSize(10, 10); |
|
6184 |
widget.setMinimumSize(newMinimumSize); |
|
6185 |
QCOMPARE(widget.size(), newMinimumSize); |
|
6186 |
||
6187 |
widget.show(); |
|
6188 |
qt_x11_wait_for_window_manager(&widget); |
|
6189 |
QCOMPARE(widget.size(), newMinimumSize); |
|
6190 |
} |
|
6191 |
} |
|
6192 |
||
6193 |
class ShowHideShowWidget : public QWidget |
|
6194 |
{ |
|
6195 |
Q_OBJECT |
|
6196 |
||
6197 |
int state; |
|
6198 |
public: |
|
6199 |
bool gotExpectedMapNotify; |
|
6200 |
||
6201 |
ShowHideShowWidget() |
|
6202 |
: state(0), gotExpectedMapNotify(false) |
|
6203 |
{ |
|
6204 |
startTimer(1000); |
|
6205 |
} |
|
6206 |
||
6207 |
void timerEvent(QTimerEvent *) |
|
6208 |
{ |
|
6209 |
switch (state++) { |
|
6210 |
case 0: |
|
6211 |
show(); |
|
6212 |
break; |
|
6213 |
case 1: |
|
6214 |
emit done(); |
|
6215 |
break; |
|
6216 |
} |
|
6217 |
} |
|
6218 |
||
6219 |
bool x11Event(XEvent *event) |
|
6220 |
{ |
|
6221 |
if (state == 1 && event->type == MapNotify) |
|
6222 |
gotExpectedMapNotify = true; |
|
6223 |
return false; |
|
6224 |
} |
|
6225 |
||
6226 |
signals: |
|
6227 |
void done(); |
|
6228 |
}; |
|
6229 |
||
6230 |
void tst_QWidget::showHideShow() |
|
6231 |
{ |
|
6232 |
ShowHideShowWidget w; |
|
6233 |
w.show(); |
|
6234 |
w.hide(); |
|
6235 |
||
6236 |
QEventLoop eventLoop; |
|
6237 |
connect(&w, SIGNAL(done()), &eventLoop, SLOT(quit())); |
|
6238 |
eventLoop.exec(); |
|
6239 |
||
6240 |
QVERIFY(w.gotExpectedMapNotify); |
|
6241 |
} |
|
6242 |
||
6243 |
void tst_QWidget::clean_qt_x11_enforce_cursor() |
|
6244 |
{ |
|
6245 |
{ |
|
6246 |
QWidget window; |
|
6247 |
QWidget *w = new QWidget(&window); |
|
6248 |
QWidget *child = new QWidget(w); |
|
6249 |
child->setAttribute(Qt::WA_SetCursor, true); |
|
6250 |
||
6251 |
window.show(); |
|
6252 |
QApplication::setActiveWindow(&window); |
|
6253 |
QTest::qWaitForWindowShown(&window); |
|
6254 |
QTest::qWait(100); |
|
6255 |
QCursor::setPos(window.geometry().center()); |
|
6256 |
QTest::qWait(100); |
|
6257 |
||
6258 |
child->setFocus(); |
|
6259 |
QApplication::processEvents(); |
|
6260 |
QTest::qWait(100); |
|
6261 |
||
6262 |
delete w; |
|
6263 |
} |
|
6264 |
||
6265 |
QGraphicsScene scene; |
|
6266 |
QLineEdit *edit = new QLineEdit; |
|
6267 |
scene.addWidget(edit); |
|
6268 |
||
6269 |
// If the test didn't crash, then it passed. |
|
6270 |
} |
|
6271 |
#endif |
|
6272 |
||
6273 |
class EventRecorder : public QObject |
|
6274 |
{ |
|
6275 |
Q_OBJECT |
|
6276 |
||
6277 |
public: |
|
6278 |
typedef QList<QPair<QWidget *, QEvent::Type> > EventList; |
|
6279 |
||
6280 |
EventRecorder(QObject *parent = 0) |
|
6281 |
: QObject(parent) |
|
6282 |
{ } |
|
6283 |
||
6284 |
EventList eventList() |
|
6285 |
{ |
|
6286 |
return events; |
|
6287 |
} |
|
6288 |
||
6289 |
void clear() |
|
6290 |
{ |
|
6291 |
events.clear(); |
|
6292 |
} |
|
6293 |
||
6294 |
bool eventFilter(QObject *object, QEvent *event) |
|
6295 |
{ |
|
6296 |
QWidget *widget = qobject_cast<QWidget *>(object); |
|
6297 |
if (widget && !event->spontaneous()) |
|
6298 |
events.append(qMakePair(widget, event->type())); |
|
6299 |
return false; |
|
6300 |
} |
|
6301 |
||
6302 |
private: |
|
6303 |
EventList events; |
|
6304 |
}; |
|
6305 |
||
6306 |
void tst_QWidget::compatibilityChildInsertedEvents() |
|
6307 |
{ |
|
6308 |
EventRecorder::EventList expected; |
|
6309 |
bool accessibilityEnabled = false; |
|
6310 |
#if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA) |
|
6311 |
accessibilityEnabled = AXAPIEnabled(); |
|
6312 |
#endif |
|
6313 |
||
6314 |
// Move away the cursor; otherwise it might result in an enter event if it's |
|
6315 |
// inside the widget when the widget is shown. |
|
6316 |
QCursor::setPos(qApp->desktop()->availableGeometry().bottomRight()); |
|
6317 |
QTest::qWait(100); |
|
6318 |
||
6319 |
{ |
|
6320 |
// no children created, not 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 |
QCoreApplication::sendPostedEvents(); |
|
6328 |
||
6329 |
expected = |
|
6330 |
EventRecorder::EventList() |
|
6331 |
<< qMakePair(&widget, QEvent::PolishRequest) |
|
6332 |
<< qMakePair(&widget, QEvent::Polish) |
|
6333 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1)); |
|
6334 |
QCOMPARE(spy.eventList(), expected); |
|
6335 |
} |
|
6336 |
||
6337 |
{ |
|
6338 |
// no children, shown |
|
6339 |
QWidget widget; |
|
6340 |
EventRecorder spy; |
|
6341 |
widget.installEventFilter(&spy); |
|
6342 |
||
6343 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 1))); |
|
6344 |
||
6345 |
widget.show(); |
|
6346 |
expected = |
|
6347 |
EventRecorder::EventList() |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6348 |
<< qMakePair(&widget, QEvent::WinIdChange) |
0 | 6349 |
<< qMakePair(&widget, QEvent::Polish) |
6350 |
<< qMakePair(&widget, QEvent::Move) |
|
6351 |
<< qMakePair(&widget, QEvent::Resize) |
|
6352 |
<< qMakePair(&widget, QEvent::Show); |
|
6353 |
||
6354 |
if (accessibilityEnabled) |
|
6355 |
expected << qMakePair(&widget, QEvent::AccessibilityPrepare); |
|
6356 |
expected << qMakePair(&widget, QEvent::ShowToParent); |
|
6357 |
QCOMPARE(spy.eventList(), expected); |
|
6358 |
spy.clear(); |
|
6359 |
||
6360 |
QCoreApplication::sendPostedEvents(); |
|
6361 |
expected = |
|
6362 |
EventRecorder::EventList() |
|
6363 |
<< qMakePair(&widget, QEvent::PolishRequest) |
|
6364 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1)) |
|
6365 |
#if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_QWS) || defined(Q_WS_S60) |
|
6366 |
<< qMakePair(&widget, QEvent::UpdateRequest) |
|
6367 |
#endif |
|
6368 |
; |
|
6369 |
QCOMPARE(spy.eventList(), expected); |
|
6370 |
} |
|
6371 |
||
6372 |
{ |
|
6373 |
// 2 children, not shown |
|
6374 |
QWidget widget; |
|
6375 |
EventRecorder spy; |
|
6376 |
widget.installEventFilter(&spy); |
|
6377 |
||
6378 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 1))); |
|
6379 |
||
6380 |
QWidget child1(&widget); |
|
6381 |
QWidget child2; |
|
6382 |
child2.setParent(&widget); |
|
6383 |
||
6384 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 2))); |
|
6385 |
||
6386 |
expected = |
|
6387 |
EventRecorder::EventList() |
|
6388 |
<< qMakePair(&widget, QEvent::ChildAdded) |
|
6389 |
<< qMakePair(&widget, QEvent::ChildAdded); |
|
6390 |
QCOMPARE(spy.eventList(), expected); |
|
6391 |
spy.clear(); |
|
6392 |
||
6393 |
QCoreApplication::sendPostedEvents(); |
|
6394 |
expected = |
|
6395 |
EventRecorder::EventList() |
|
6396 |
#ifdef QT_HAS_QT3SUPPORT |
|
6397 |
<< qMakePair(&widget, QEvent::ChildInsertedRequest) |
|
6398 |
<< qMakePair(&widget, QEvent::ChildInserted) |
|
6399 |
<< qMakePair(&widget, QEvent::ChildInserted) |
|
6400 |
#endif |
|
6401 |
<< qMakePair(&widget, QEvent::PolishRequest) |
|
6402 |
<< qMakePair(&widget, QEvent::Polish) |
|
6403 |
<< qMakePair(&widget, QEvent::ChildPolished) |
|
6404 |
<< qMakePair(&widget, QEvent::ChildPolished) |
|
6405 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1)) |
|
6406 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 2)); |
|
6407 |
QCOMPARE(spy.eventList(), expected); |
|
6408 |
} |
|
6409 |
||
6410 |
{ |
|
6411 |
// 2 children, widget shown |
|
6412 |
QWidget widget; |
|
6413 |
EventRecorder spy; |
|
6414 |
widget.installEventFilter(&spy); |
|
6415 |
||
6416 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 1))); |
|
6417 |
||
6418 |
QWidget child1(&widget); |
|
6419 |
QWidget child2; |
|
6420 |
child2.setParent(&widget); |
|
6421 |
||
6422 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 2))); |
|
6423 |
||
6424 |
expected = |
|
6425 |
EventRecorder::EventList() |
|
6426 |
<< qMakePair(&widget, QEvent::ChildAdded) |
|
6427 |
<< qMakePair(&widget, QEvent::ChildAdded); |
|
6428 |
QCOMPARE(spy.eventList(), expected); |
|
6429 |
spy.clear(); |
|
6430 |
||
6431 |
widget.show(); |
|
6432 |
expected = |
|
6433 |
EventRecorder::EventList() |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6434 |
<< qMakePair(&widget, QEvent::WinIdChange) |
0 | 6435 |
<< qMakePair(&widget, QEvent::Polish) |
6436 |
#ifdef QT_HAS_QT3SUPPORT |
|
6437 |
<< qMakePair(&widget, QEvent::ChildInserted) |
|
6438 |
<< qMakePair(&widget, QEvent::ChildInserted) |
|
6439 |
#endif |
|
6440 |
<< qMakePair(&widget, QEvent::ChildPolished) |
|
6441 |
<< qMakePair(&widget, QEvent::ChildPolished) |
|
6442 |
<< qMakePair(&widget, QEvent::Move) |
|
6443 |
<< qMakePair(&widget, QEvent::Resize) |
|
6444 |
<< qMakePair(&widget, QEvent::Show); |
|
6445 |
||
6446 |
if (accessibilityEnabled) |
|
6447 |
expected << qMakePair(&widget, QEvent::AccessibilityPrepare); |
|
6448 |
expected << qMakePair(&widget, QEvent::ShowToParent); |
|
6449 |
QCOMPARE(spy.eventList(), expected); |
|
6450 |
spy.clear(); |
|
6451 |
||
6452 |
QCoreApplication::sendPostedEvents(); |
|
6453 |
expected = |
|
6454 |
EventRecorder::EventList() |
|
6455 |
#ifdef QT_HAS_QT3SUPPORT |
|
6456 |
<< qMakePair(&widget, QEvent::ChildInsertedRequest) |
|
6457 |
#endif |
|
6458 |
<< qMakePair(&widget, QEvent::PolishRequest) |
|
6459 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1)) |
|
6460 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 2)) |
|
6461 |
#if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_QWS) || defined(Q_WS_S60) |
|
6462 |
<< qMakePair(&widget, QEvent::UpdateRequest) |
|
6463 |
#endif |
|
6464 |
; |
|
6465 |
QCOMPARE(spy.eventList(), expected); |
|
6466 |
} |
|
6467 |
||
6468 |
{ |
|
6469 |
// 2 children, but one is reparented away, not shown |
|
6470 |
QWidget widget; |
|
6471 |
EventRecorder spy; |
|
6472 |
widget.installEventFilter(&spy); |
|
6473 |
||
6474 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 1))); |
|
6475 |
||
6476 |
QWidget child1(&widget); |
|
6477 |
QWidget child2; |
|
6478 |
child2.setParent(&widget); |
|
6479 |
child2.setParent(0); |
|
6480 |
||
6481 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 2))); |
|
6482 |
||
6483 |
expected = |
|
6484 |
EventRecorder::EventList() |
|
6485 |
<< qMakePair(&widget, QEvent::ChildAdded) |
|
6486 |
<< qMakePair(&widget, QEvent::ChildAdded) |
|
6487 |
<< qMakePair(&widget, QEvent::ChildRemoved); |
|
6488 |
QCOMPARE(spy.eventList(), expected); |
|
6489 |
spy.clear(); |
|
6490 |
||
6491 |
QCoreApplication::sendPostedEvents(); |
|
6492 |
expected = |
|
6493 |
EventRecorder::EventList() |
|
6494 |
#ifdef QT_HAS_QT3SUPPORT |
|
6495 |
<< qMakePair(&widget, QEvent::ChildInsertedRequest) |
|
6496 |
<< qMakePair(&widget, QEvent::ChildInserted) |
|
6497 |
#endif |
|
6498 |
<< qMakePair(&widget, QEvent::PolishRequest) |
|
6499 |
<< qMakePair(&widget, QEvent::Polish) |
|
6500 |
<< qMakePair(&widget, QEvent::ChildPolished) |
|
6501 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1)) |
|
6502 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 2)); |
|
6503 |
QCOMPARE(spy.eventList(), expected); |
|
6504 |
} |
|
6505 |
||
6506 |
{ |
|
6507 |
// 2 children, but one is reparented away, then widget is shown |
|
6508 |
QWidget widget; |
|
6509 |
EventRecorder spy; |
|
6510 |
widget.installEventFilter(&spy); |
|
6511 |
||
6512 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 1))); |
|
6513 |
||
6514 |
QWidget child1(&widget); |
|
6515 |
QWidget child2; |
|
6516 |
child2.setParent(&widget); |
|
6517 |
child2.setParent(0); |
|
6518 |
||
6519 |
QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 2))); |
|
6520 |
||
6521 |
expected = |
|
6522 |
EventRecorder::EventList() |
|
6523 |
<< qMakePair(&widget, QEvent::ChildAdded) |
|
6524 |
<< qMakePair(&widget, QEvent::ChildAdded) |
|
6525 |
<< qMakePair(&widget, QEvent::ChildRemoved); |
|
6526 |
QCOMPARE(spy.eventList(), expected); |
|
6527 |
spy.clear(); |
|
6528 |
||
6529 |
widget.show(); |
|
6530 |
expected = |
|
6531 |
EventRecorder::EventList() |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6532 |
<< qMakePair(&widget, QEvent::WinIdChange) |
0 | 6533 |
<< qMakePair(&widget, QEvent::Polish) |
6534 |
#ifdef QT_HAS_QT3SUPPORT |
|
6535 |
<< qMakePair(&widget, QEvent::ChildInserted) |
|
6536 |
#endif |
|
6537 |
<< qMakePair(&widget, QEvent::ChildPolished) |
|
6538 |
<< qMakePair(&widget, QEvent::Move) |
|
6539 |
<< qMakePair(&widget, QEvent::Resize) |
|
6540 |
<< qMakePair(&widget, QEvent::Show); |
|
6541 |
||
6542 |
if (accessibilityEnabled) |
|
6543 |
expected << qMakePair(&widget, QEvent::AccessibilityPrepare); |
|
6544 |
expected << qMakePair(&widget, QEvent::ShowToParent); |
|
6545 |
QCOMPARE(spy.eventList(), expected); |
|
6546 |
spy.clear(); |
|
6547 |
||
6548 |
QCoreApplication::sendPostedEvents(); |
|
6549 |
expected = |
|
6550 |
EventRecorder::EventList() |
|
6551 |
#ifdef QT_HAS_QT3SUPPORT |
|
6552 |
<< qMakePair(&widget, QEvent::ChildInsertedRequest) |
|
6553 |
#endif |
|
6554 |
<< qMakePair(&widget, QEvent::PolishRequest) |
|
6555 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1)) |
|
6556 |
<< qMakePair(&widget, QEvent::Type(QEvent::User + 2)) |
|
6557 |
#if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_QWS) || defined(Q_WS_S60) |
|
6558 |
<< qMakePair(&widget, QEvent::UpdateRequest) |
|
6559 |
#endif |
|
6560 |
; |
|
6561 |
QCOMPARE(spy.eventList(), expected); |
|
6562 |
} |
|
6563 |
} |
|
6564 |
||
6565 |
class RenderWidget : public QWidget |
|
6566 |
{ |
|
6567 |
public: |
|
6568 |
RenderWidget(QWidget *source) |
|
6569 |
: source(source), ellipse(false) {} |
|
6570 |
||
6571 |
void setEllipseEnabled(bool enable = true) |
|
6572 |
{ |
|
6573 |
ellipse = enable; |
|
6574 |
update(); |
|
6575 |
} |
|
6576 |
||
6577 |
protected: |
|
6578 |
void paintEvent(QPaintEvent *) |
|
6579 |
{ |
|
6580 |
if (ellipse) { |
|
6581 |
QPainter painter(this); |
|
6582 |
painter.fillRect(rect(), Qt::red); |
|
6583 |
painter.end(); |
|
6584 |
QRegion regionToRender = QRegion(0, 0, source->width(), source->height() / 2, |
|
6585 |
QRegion::Ellipse); |
|
6586 |
source->render(this, QPoint(0, 30), regionToRender); |
|
6587 |
} else { |
|
6588 |
source->render(this); |
|
6589 |
} |
|
6590 |
} |
|
6591 |
||
6592 |
private: |
|
6593 |
QWidget *source; |
|
6594 |
bool ellipse; |
|
6595 |
}; |
|
6596 |
||
6597 |
void tst_QWidget::render() |
|
6598 |
{ |
|
6599 |
return; |
|
6600 |
QCalendarWidget source; |
|
6601 |
// disable anti-aliasing to eliminate potential differences when subpixel antialiasing |
|
6602 |
// is enabled on the screen |
|
6603 |
QFont f; |
|
6604 |
f.setStyleStrategy(QFont::NoAntialias); |
|
6605 |
source.setFont(f); |
|
6606 |
source.show(); |
|
6607 |
QTest::qWaitForWindowShown(&source); |
|
6608 |
||
6609 |
// Render the entire source into target. |
|
6610 |
RenderWidget target(&source); |
|
6611 |
target.resize(source.size()); |
|
6612 |
target.show(); |
|
6613 |
||
6614 |
qApp->processEvents(); |
|
6615 |
qApp->sendPostedEvents(); |
|
6616 |
QTest::qWait(250); |
|
6617 |
||
6618 |
QImage sourceImage = QPixmap::grabWidget(&source).toImage(); |
|
6619 |
qApp->processEvents(); |
|
6620 |
QImage targetImage = QPixmap::grabWidget(&target).toImage(); |
|
6621 |
qApp->processEvents(); |
|
6622 |
QCOMPARE(sourceImage, targetImage); |
|
6623 |
||
6624 |
// Fill target.rect() will Qt::red and render |
|
6625 |
// QRegion(0, 0, source->width(), source->height() / 2, QRegion::Ellipse) |
|
6626 |
// of source into target with offset (0, 30). |
|
6627 |
target.setEllipseEnabled(); |
|
6628 |
qApp->processEvents(); |
|
6629 |
qApp->sendPostedEvents(); |
|
6630 |
||
6631 |
targetImage = QPixmap::grabWidget(&target).toImage(); |
|
6632 |
QVERIFY(sourceImage != targetImage); |
|
6633 |
||
6634 |
QCOMPARE(targetImage.pixel(target.width() / 2, 29), QColor(Qt::red).rgb()); |
|
6635 |
QCOMPARE(targetImage.pixel(target.width() / 2, 30), sourceImage.pixel(source.width() / 2, 0)); |
|
6636 |
||
6637 |
// Test that a child widget properly fills its background |
|
6638 |
{ |
|
6639 |
QWidget window; |
|
6640 |
window.resize(100, 100); |
|
6641 |
// prevent custom styles |
|
6642 |
window.setStyle(new QWindowsStyle); |
|
6643 |
window.show(); |
|
6644 |
QTest::qWaitForWindowShown(&window); |
|
6645 |
QWidget child(&window); |
|
6646 |
child.resize(window.size()); |
|
6647 |
child.show(); |
|
6648 |
||
6649 |
qApp->processEvents(); |
|
6650 |
QCOMPARE(QPixmap::grabWidget(&child), QPixmap::grabWidget(&window)); |
|
6651 |
} |
|
6652 |
||
6653 |
{ // Check that the target offset is correct. |
|
6654 |
QWidget widget; |
|
6655 |
widget.resize(200, 200); |
|
6656 |
widget.setAutoFillBackground(true); |
|
6657 |
widget.setPalette(Qt::red); |
|
6658 |
// prevent custom styles |
|
6659 |
widget.setStyle(new QWindowsStyle); |
|
6660 |
widget.show(); |
|
6661 |
QTest::qWaitForWindowShown(&widget); |
|
6662 |
QImage image(widget.size(), QImage::Format_RGB32); |
|
6663 |
image.fill(QColor(Qt::blue).rgb()); |
|
6664 |
||
6665 |
// Target offset (0, 0) |
|
6666 |
widget.render(&image, QPoint(), QRect(20, 20, 100, 100)); |
|
6667 |
QCOMPARE(image.pixel(0, 0), QColor(Qt::red).rgb()); |
|
6668 |
QCOMPARE(image.pixel(99, 99), QColor(Qt::red).rgb()); |
|
6669 |
QCOMPARE(image.pixel(100, 100), QColor(Qt::blue).rgb()); |
|
6670 |
||
6671 |
// Target offset (20, 20). |
|
6672 |
image.fill(QColor(Qt::blue).rgb()); |
|
6673 |
widget.render(&image, QPoint(20, 20), QRect(20, 20, 100, 100)); |
|
6674 |
QCOMPARE(image.pixel(0, 0), QColor(Qt::blue).rgb()); |
|
6675 |
QCOMPARE(image.pixel(19, 19), QColor(Qt::blue).rgb()); |
|
6676 |
QCOMPARE(image.pixel(20, 20), QColor(Qt::red).rgb()); |
|
6677 |
QCOMPARE(image.pixel(119, 119), QColor(Qt::red).rgb()); |
|
6678 |
QCOMPARE(image.pixel(120, 120), QColor(Qt::blue).rgb()); |
|
6679 |
} |
|
6680 |
} |
|
6681 |
||
6682 |
// On Windows the active palette is used instead of the inactive palette even |
|
6683 |
// though the widget is invisible. This is probably related to task 178507/168682, |
|
6684 |
// but for the renderInvisible test it doesn't matter, we're mostly interested |
|
6685 |
// in testing the geometry so just workaround the palette issue for now. |
|
6686 |
static void workaroundPaletteIssue(QWidget *widget) |
|
6687 |
{ |
|
6688 |
#ifndef Q_WS_WIN |
|
6689 |
return; |
|
6690 |
#endif |
|
6691 |
if (!widget) |
|
6692 |
return; |
|
6693 |
||
6694 |
QWidget *navigationBar = qFindChild<QWidget *>(widget, QLatin1String("qt_calendar_navigationbar")); |
|
6695 |
QVERIFY(navigationBar); |
|
6696 |
||
6697 |
QPalette palette = navigationBar->palette(); |
|
6698 |
const QColor background = palette.color(QPalette::Inactive, navigationBar->backgroundRole()); |
|
6699 |
const QColor highlightedText = palette.color(QPalette::Inactive, QPalette::HighlightedText); |
|
6700 |
palette.setColor(QPalette::Active, navigationBar->backgroundRole(), background); |
|
6701 |
palette.setColor(QPalette::Active, QPalette::HighlightedText, highlightedText); |
|
6702 |
navigationBar->setPalette(palette); |
|
6703 |
} |
|
6704 |
||
6705 |
//#define RENDER_DEBUG |
|
6706 |
void tst_QWidget::renderInvisible() |
|
6707 |
{ |
|
6708 |
QCalendarWidget *calendar = new QCalendarWidget; |
|
6709 |
// disable anti-aliasing to eliminate potential differences when subpixel antialiasing |
|
6710 |
// is enabled on the screen |
|
6711 |
QFont f; |
|
6712 |
f.setStyleStrategy(QFont::NoAntialias); |
|
6713 |
calendar->setFont(f); |
|
6714 |
calendar->show(); |
|
6715 |
QTest::qWaitForWindowShown(calendar); |
|
6716 |
||
6717 |
// Create a dummy focus widget to get rid of focus rect in reference image. |
|
6718 |
QLineEdit dummyFocusWidget; |
|
6719 |
dummyFocusWidget.show(); |
|
6720 |
QTest::qWaitForWindowShown(&dummyFocusWidget); |
|
6721 |
qApp->processEvents(); |
|
6722 |
QTest::qWait(120); |
|
6723 |
||
6724 |
// Create normal reference image. |
|
6725 |
const QSize calendarSize = calendar->size(); |
|
6726 |
QImage referenceImage(calendarSize, QImage::Format_ARGB32); |
|
6727 |
calendar->render(&referenceImage); |
|
6728 |
#ifdef RENDER_DEBUG |
|
6729 |
referenceImage.save("referenceImage.png"); |
|
6730 |
#endif |
|
6731 |
QVERIFY(!referenceImage.isNull()); |
|
6732 |
||
6733 |
// Create resized reference image. |
|
6734 |
const QSize calendarSizeResized = calendar->size() + QSize(50, 50); |
|
6735 |
calendar->resize(calendarSizeResized); |
|
6736 |
qApp->processEvents(); |
|
6737 |
QTest::qWait(30); |
|
6738 |
QImage referenceImageResized(calendarSizeResized, QImage::Format_ARGB32); |
|
6739 |
calendar->render(&referenceImageResized); |
|
6740 |
#ifdef RENDER_DEBUG |
|
6741 |
referenceImageResized.save("referenceImageResized.png"); |
|
6742 |
#endif |
|
6743 |
QVERIFY(!referenceImageResized.isNull()); |
|
6744 |
||
6745 |
// Explicitly hide the calendar. |
|
6746 |
calendar->hide(); |
|
6747 |
qApp->processEvents(); |
|
6748 |
QTest::qWait(30); |
|
6749 |
workaroundPaletteIssue(calendar); |
|
6750 |
||
6751 |
{ // Make sure we get the same image when the calendar is explicitly hidden. |
|
6752 |
QImage testImage(calendarSizeResized, QImage::Format_ARGB32); |
|
6753 |
calendar->render(&testImage); |
|
6754 |
#ifdef RENDER_DEBUG |
|
6755 |
testImage.save("explicitlyHiddenCalendarResized.png"); |
|
6756 |
#endif |
|
6757 |
QCOMPARE(testImage, referenceImageResized); |
|
6758 |
} |
|
6759 |
||
6760 |
// Now that we have reference images we can delete the source and re-create |
|
6761 |
// the calendar and check that we get the same images from a calendar which has never |
|
6762 |
// been visible, laid out or created (Qt::WA_WState_Created). |
|
6763 |
delete calendar; |
|
6764 |
calendar = new QCalendarWidget; |
|
6765 |
calendar->setFont(f); |
|
6766 |
workaroundPaletteIssue(calendar); |
|
6767 |
||
6768 |
{ // Never been visible, created or laid out. |
|
6769 |
QImage testImage(calendarSize, QImage::Format_ARGB32); |
|
6770 |
calendar->render(&testImage); |
|
6771 |
#ifdef RENDER_DEBUG |
|
6772 |
testImage.save("neverBeenVisibleCreatedOrLaidOut.png"); |
|
6773 |
#endif |
|
6774 |
QCOMPARE(testImage, referenceImage); |
|
6775 |
} |
|
6776 |
||
6777 |
calendar->hide(); |
|
6778 |
qApp->processEvents(); |
|
6779 |
QTest::qWait(30); |
|
6780 |
||
6781 |
{ // Calendar explicitly hidden. |
|
6782 |
QImage testImage(calendarSize, QImage::Format_ARGB32); |
|
6783 |
calendar->render(&testImage); |
|
6784 |
#ifdef RENDER_DEBUG |
|
6785 |
testImage.save("explicitlyHiddenCalendar.png"); |
|
6786 |
#endif |
|
6787 |
QCOMPARE(testImage, referenceImage); |
|
6788 |
} |
|
6789 |
||
6790 |
// Get navigation bar and explicitly hide it. |
|
6791 |
QWidget *navigationBar = qFindChild<QWidget *>(calendar, QLatin1String("qt_calendar_navigationbar")); |
|
6792 |
QVERIFY(navigationBar); |
|
6793 |
navigationBar->hide(); |
|
6794 |
||
6795 |
{ // Check that the navigation bar isn't drawn when rendering the entire calendar. |
|
6796 |
QImage testImage(calendarSize, QImage::Format_ARGB32); |
|
6797 |
calendar->render(&testImage); |
|
6798 |
#ifdef RENDER_DEBUG |
|
6799 |
testImage.save("calendarWithoutNavigationBar.png"); |
|
6800 |
#endif |
|
6801 |
QVERIFY(testImage != referenceImage); |
|
6802 |
} |
|
6803 |
||
6804 |
{ // Make sure the navigation bar renders correctly even though it's hidden. |
|
6805 |
QImage testImage(navigationBar->size(), QImage::Format_ARGB32); |
|
6806 |
navigationBar->render(&testImage); |
|
6807 |
#ifdef RENDER_DEBUG |
|
6808 |
testImage.save("explicitlyHiddenNavigationBar.png"); |
|
6809 |
#endif |
|
6810 |
QCOMPARE(testImage, referenceImage.copy(navigationBar->rect())); |
|
6811 |
} |
|
6812 |
||
6813 |
// Get next month button. |
|
6814 |
QWidget *nextMonthButton = qFindChild<QWidget *>(navigationBar, QLatin1String("qt_calendar_nextmonth")); |
|
6815 |
QVERIFY(nextMonthButton); |
|
6816 |
||
6817 |
{ // Render next month button. |
|
6818 |
// Fill test image with correct background color. |
|
6819 |
QImage testImage(nextMonthButton->size(), QImage::Format_ARGB32); |
|
6820 |
navigationBar->render(&testImage, QPoint(), QRegion(), QWidget::RenderFlags()); |
|
6821 |
#ifdef RENDER_DEBUG |
|
6822 |
testImage.save("nextMonthButtonBackground.png"); |
|
6823 |
#endif |
|
6824 |
||
6825 |
// Set the button's background color to Qt::transparent; otherwise it will fill the |
|
6826 |
// background with QPalette::Window. |
|
6827 |
const QPalette originalPalette = nextMonthButton->palette(); |
|
6828 |
QPalette palette = originalPalette; |
|
6829 |
palette.setColor(QPalette::Window, Qt::transparent); |
|
6830 |
nextMonthButton->setPalette(palette); |
|
6831 |
||
6832 |
// Render the button on top of the background. |
|
6833 |
nextMonthButton->render(&testImage); |
|
6834 |
#ifdef RENDER_DEBUG |
|
6835 |
testImage.save("nextMonthButton.png"); |
|
6836 |
#endif |
|
6837 |
const QRect buttonRect(nextMonthButton->mapTo(calendar, QPoint()), nextMonthButton->size()); |
|
6838 |
QCOMPARE(testImage, referenceImage.copy(buttonRect)); |
|
6839 |
||
6840 |
// Restore palette. |
|
6841 |
nextMonthButton->setPalette(originalPalette); |
|
6842 |
} |
|
6843 |
||
6844 |
// Navigation bar isn't explicitly hidden anymore. |
|
6845 |
navigationBar->show(); |
|
6846 |
qApp->processEvents(); |
|
6847 |
QTest::qWait(30); |
|
6848 |
QVERIFY(!calendar->isVisible()); |
|
6849 |
||
6850 |
// Now, completely mess up the layout. This will trigger an update on the layout |
|
6851 |
// when the calendar is visible or shown, but it's not. QWidget::render must therefore |
|
6852 |
// make sure the layout is activated before rendering. |
|
6853 |
QVERIFY(!calendar->isVisible()); |
|
6854 |
calendar->resize(calendarSizeResized); |
|
6855 |
qApp->processEvents(); |
|
6856 |
||
6857 |
{ // Make sure we get an image equal to the resized reference image. |
|
6858 |
QImage testImage(calendarSizeResized, QImage::Format_ARGB32); |
|
6859 |
calendar->render(&testImage); |
|
6860 |
#ifdef RENDER_DEBUG |
|
6861 |
testImage.save("calendarResized.png"); |
|
6862 |
#endif |
|
6863 |
QCOMPARE(testImage, referenceImageResized); |
|
6864 |
} |
|
6865 |
||
6866 |
{ // Make sure we lay out the widget correctly the first time it's rendered. |
|
6867 |
QCalendarWidget calendar; |
|
6868 |
const QSize calendarSize = calendar.sizeHint(); |
|
6869 |
||
6870 |
QImage image(2 * calendarSize, QImage::Format_ARGB32); |
|
6871 |
image.fill(QColor(Qt::red).rgb()); |
|
6872 |
calendar.render(&image); |
|
6873 |
||
6874 |
for (int i = calendarSize.height(); i < 2 * calendarSize.height(); ++i) |
|
6875 |
for (int j = calendarSize.width(); j < 2 * calendarSize.width(); ++j) |
|
6876 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
6877 |
} |
|
6878 |
||
6879 |
{ // Ensure that we don't call adjustSize() on invisible top-levels if render() is called |
|
6880 |
// right after widgets have been added/removed to/from its layout. |
|
6881 |
QWidget topLevel; |
|
6882 |
topLevel.setLayout(new QVBoxLayout); |
|
6883 |
||
6884 |
QWidget *widget = new QLineEdit; |
|
6885 |
topLevel.layout()->addWidget(widget); |
|
6886 |
||
6887 |
const QSize initialSize = topLevel.size(); |
|
6888 |
QPixmap pixmap(topLevel.sizeHint()); |
|
6889 |
topLevel.render(&pixmap); // triggers adjustSize() |
|
6890 |
const QSize finalSize = topLevel.size(); |
|
6891 |
QVERIFY(finalSize != initialSize); |
|
6892 |
||
6893 |
topLevel.layout()->removeWidget(widget); |
|
6894 |
QCOMPARE(topLevel.size(), finalSize); |
|
6895 |
topLevel.render(&pixmap); |
|
6896 |
QCOMPARE(topLevel.size(), finalSize); |
|
6897 |
||
6898 |
topLevel.layout()->addWidget(widget); |
|
6899 |
QCOMPARE(topLevel.size(), finalSize); |
|
6900 |
topLevel.render(&pixmap); |
|
6901 |
QCOMPARE(topLevel.size(), finalSize); |
|
6902 |
} |
|
6903 |
} |
|
6904 |
||
6905 |
void tst_QWidget::renderWithPainter() |
|
6906 |
{ |
|
6907 |
QWidget widget; |
|
6908 |
// prevent custom styles |
|
6909 |
widget.setStyle(new QWindowsStyle); |
|
6910 |
widget.show(); |
|
6911 |
widget.resize(70, 50); |
|
6912 |
widget.setAutoFillBackground(true); |
|
6913 |
widget.setPalette(Qt::black); |
|
6914 |
||
6915 |
// Render the entire widget onto the image. |
|
6916 |
QImage image(QSize(70, 50), QImage::Format_ARGB32); |
|
6917 |
image.fill(QColor(Qt::red).rgb()); |
|
6918 |
QPainter painter(&image); |
|
6919 |
widget.render(&painter); |
|
6920 |
||
6921 |
for (int i = 0; i < image.height(); ++i) { |
|
6922 |
for (int j = 0; j < image.width(); ++j) |
|
6923 |
QCOMPARE(image.pixel(j, i), QColor(Qt::black).rgb()); |
|
6924 |
} |
|
6925 |
||
6926 |
// Translate painter (10, 10). |
|
6927 |
painter.save(); |
|
6928 |
image.fill(QColor(Qt::red).rgb()); |
|
6929 |
painter.translate(10, 10); |
|
6930 |
widget.render(&painter); |
|
6931 |
painter.restore(); |
|
6932 |
||
6933 |
for (int i = 0; i < image.height(); ++i) { |
|
6934 |
for (int j = 0; j < image.width(); ++j) { |
|
6935 |
if (i < 10 || j < 10) |
|
6936 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
6937 |
else |
|
6938 |
QCOMPARE(image.pixel(j, i), QColor(Qt::black).rgb()); |
|
6939 |
} |
|
6940 |
} |
|
6941 |
||
6942 |
// Pass target offset (10, 10) (the same as QPainter::translate). |
|
6943 |
image.fill(QColor(Qt::red).rgb()); |
|
6944 |
widget.render(&painter, QPoint(10, 10)); |
|
6945 |
||
6946 |
for (int i = 0; i < image.height(); ++i) { |
|
6947 |
for (int j = 0; j < image.width(); ++j) { |
|
6948 |
if (i < 10 || j < 10) |
|
6949 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
6950 |
else |
|
6951 |
QCOMPARE(image.pixel(j, i), QColor(Qt::black).rgb()); |
|
6952 |
} |
|
6953 |
} |
|
6954 |
||
6955 |
// Translate (10, 10) and pass target offset (10, 10). |
|
6956 |
painter.save(); |
|
6957 |
image.fill(QColor(Qt::red).rgb()); |
|
6958 |
painter.translate(10, 10); |
|
6959 |
widget.render(&painter, QPoint(10, 10)); |
|
6960 |
painter.restore(); |
|
6961 |
||
6962 |
for (int i = 0; i < image.height(); ++i) { |
|
6963 |
for (int j = 0; j < image.width(); ++j) { |
|
6964 |
if (i < 20 || j < 20) |
|
6965 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
6966 |
else |
|
6967 |
QCOMPARE(image.pixel(j, i), QColor(Qt::black).rgb()); |
|
6968 |
} |
|
6969 |
} |
|
6970 |
||
6971 |
// Rotate painter 90 degrees. |
|
6972 |
painter.save(); |
|
6973 |
image.fill(QColor(Qt::red).rgb()); |
|
6974 |
painter.rotate(90); |
|
6975 |
widget.render(&painter); |
|
6976 |
painter.restore(); |
|
6977 |
||
6978 |
for (int i = 0; i < image.height(); ++i) { |
|
6979 |
for (int j = 0; j < image.width(); ++j) |
|
6980 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
6981 |
} |
|
6982 |
||
6983 |
// Translate and rotate. |
|
6984 |
image.fill(QColor(Qt::red).rgb()); |
|
6985 |
widget.resize(40, 10); |
|
6986 |
painter.translate(10, 10); |
|
6987 |
painter.rotate(90); |
|
6988 |
widget.render(&painter); |
|
6989 |
||
6990 |
for (int i = 0; i < image.height(); ++i) { |
|
6991 |
for (int j = 0; j < image.width(); ++j) { |
|
6992 |
if (i >= 10 && j >= 0 && j < 10) |
|
6993 |
QCOMPARE(image.pixel(j, i), QColor(Qt::black).rgb()); |
|
6994 |
else |
|
6995 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
6996 |
} |
|
6997 |
} |
|
6998 |
||
6999 |
// Make sure QWidget::render does not modify the render hints set on the painter. |
|
7000 |
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform |
|
7001 |
| QPainter::NonCosmeticDefaultPen | QPainter::TextAntialiasing); |
|
7002 |
QPainter::RenderHints oldRenderHints = painter.renderHints(); |
|
7003 |
widget.render(&painter); |
|
7004 |
QCOMPARE(painter.renderHints(), oldRenderHints); |
|
7005 |
} |
|
7006 |
||
7007 |
void tst_QWidget::render_task188133() |
|
7008 |
{ |
|
7009 |
QMainWindow mainWindow; |
|
7010 |
#if defined(QT3_SUPPORT) |
|
7011 |
mainWindow.setCentralWidget(new Q3TextEdit); |
|
7012 |
#endif |
|
7013 |
// Make sure QWidget::render does not trigger QWidget::repaint/update |
|
7014 |
// and asserts for Qt::WA_WState_Created. |
|
7015 |
QPixmap pixmap = QPixmap::grabWidget(&mainWindow); |
|
7016 |
} |
|
7017 |
||
7018 |
void tst_QWidget::render_task211796() |
|
7019 |
{ |
|
7020 |
class MyWidget : public QWidget |
|
7021 |
{ |
|
7022 |
void resizeEvent(QResizeEvent *) |
|
7023 |
{ |
|
7024 |
QPixmap pixmap(size()); |
|
7025 |
render(&pixmap); |
|
7026 |
} |
|
7027 |
}; |
|
7028 |
||
7029 |
{ // Please don't die in a resize recursion. |
|
7030 |
MyWidget widget; |
|
7031 |
widget.resize(200, 200); |
|
7032 |
widget.show(); |
|
7033 |
} |
|
7034 |
||
7035 |
{ // Same check with a deeper hierarchy. |
|
7036 |
QWidget widget; |
|
7037 |
widget.show(); |
|
7038 |
QWidget child(&widget); |
|
7039 |
MyWidget grandChild; |
|
7040 |
grandChild.setParent(&child); |
|
7041 |
grandChild.resize(100, 100); |
|
7042 |
child.show(); |
|
7043 |
} |
|
7044 |
} |
|
7045 |
||
7046 |
void tst_QWidget::render_task217815() |
|
7047 |
{ |
|
7048 |
// Make sure we don't change the size of the widget when calling |
|
7049 |
// render() and the widget has an explicit size set. |
|
7050 |
// This was a problem on Windows because we called createWinId(), |
|
7051 |
// which in turn enforced the size to be bigger than the smallest |
|
7052 |
// possible native window size (which is (115,something) on WinXP). |
|
7053 |
QWidget widget; |
|
7054 |
const QSize explicitSize(80, 20); |
|
7055 |
widget.resize(explicitSize); |
|
7056 |
QCOMPARE(widget.size(), explicitSize); |
|
7057 |
||
7058 |
QPixmap pixmap(explicitSize); |
|
7059 |
widget.render(&pixmap); |
|
7060 |
||
7061 |
QCOMPARE(widget.size(), explicitSize); |
|
7062 |
} |
|
7063 |
||
7064 |
void tst_QWidget::render_windowOpacity() |
|
7065 |
{ |
|
7066 |
#ifdef Q_OS_WINCE |
|
7067 |
QSKIP("Window Opacity is not supported on Windows CE", SkipAll); |
|
7068 |
#endif |
|
7069 |
||
7070 |
const qreal opacity = 0.5; |
|
7071 |
||
7072 |
{ // Check that the painter opacity effects the widget drawing. |
|
7073 |
QWidget topLevel; |
|
7074 |
QWidget child(&topLevel); |
|
7075 |
child.resize(50, 50); |
|
7076 |
child.setPalette(Qt::red); |
|
7077 |
child.setAutoFillBackground(true); |
|
7078 |
||
7079 |
QPixmap expected(child.size()); |
|
7080 |
#ifdef Q_WS_X11 |
|
7081 |
if (expected.depth() < 24) { |
|
7082 |
QSKIP("This test won't give correct results with dithered pixmaps", SkipAll); |
|
7083 |
} |
|
7084 |
#endif |
|
7085 |
expected.fill(Qt::green); |
|
7086 |
QPainter painter(&expected); |
|
7087 |
painter.setOpacity(opacity); |
|
7088 |
painter.fillRect(QRect(QPoint(0, 0), child.size()), Qt::red); |
|
7089 |
painter.end(); |
|
7090 |
||
7091 |
QPixmap result(child.size()); |
|
7092 |
result.fill(Qt::green); |
|
7093 |
painter.begin(&result); |
|
7094 |
painter.setOpacity(opacity); |
|
7095 |
child.render(&painter); |
|
7096 |
painter.end(); |
|
7097 |
QCOMPARE(result, expected); |
|
7098 |
} |
|
7099 |
||
7100 |
{ // Combine the opacity set on the painter with the widget opacity. |
|
7101 |
class MyWidget : public QWidget |
|
7102 |
{ |
|
7103 |
public: |
|
7104 |
void paintEvent(QPaintEvent *) |
|
7105 |
{ |
|
7106 |
QPainter painter(this); |
|
7107 |
painter.setOpacity(opacity); |
|
7108 |
QCOMPARE(painter.opacity(), opacity); |
|
7109 |
painter.fillRect(rect(), Qt::red); |
|
7110 |
} |
|
7111 |
qreal opacity; |
|
7112 |
}; |
|
7113 |
||
7114 |
MyWidget widget; |
|
7115 |
widget.resize(50, 50); |
|
7116 |
widget.opacity = opacity; |
|
7117 |
widget.setPalette(Qt::blue); |
|
7118 |
widget.setAutoFillBackground(true); |
|
7119 |
||
7120 |
QPixmap expected(widget.size()); |
|
7121 |
expected.fill(Qt::green); |
|
7122 |
QPainter painter(&expected); |
|
7123 |
painter.setOpacity(opacity); |
|
7124 |
QPixmap pixmap(widget.size()); |
|
7125 |
pixmap.fill(Qt::blue); |
|
7126 |
QPainter pixmapPainter(&pixmap); |
|
7127 |
pixmapPainter.setOpacity(opacity); |
|
7128 |
pixmapPainter.fillRect(QRect(QPoint(), widget.size()), Qt::red); |
|
7129 |
painter.drawPixmap(QPoint(), pixmap); |
|
7130 |
painter.end(); |
|
7131 |
||
7132 |
QPixmap result(widget.size()); |
|
7133 |
result.fill(Qt::green); |
|
7134 |
painter.begin(&result); |
|
7135 |
painter.setOpacity(opacity); |
|
7136 |
widget.render(&painter); |
|
7137 |
painter.end(); |
|
7138 |
QCOMPARE(result, expected); |
|
7139 |
} |
|
7140 |
} |
|
7141 |
||
7142 |
void tst_QWidget::render_systemClip() |
|
7143 |
{ |
|
7144 |
QWidget widget; |
|
7145 |
widget.setPalette(Qt::blue); |
|
7146 |
widget.resize(100, 100); |
|
7147 |
||
7148 |
QImage image(widget.size(), QImage::Format_RGB32); |
|
7149 |
image.fill(QColor(Qt::red).rgb()); |
|
7150 |
||
7151 |
QPaintEngine *paintEngine = image.paintEngine(); |
|
7152 |
QVERIFY(paintEngine); |
|
7153 |
paintEngine->setSystemClip(QRegion(0, 0, 50, 50)); |
|
7154 |
||
7155 |
QPainter painter(&image); |
|
7156 |
// Make sure we're using the same paint engine and has the right clip set. |
|
7157 |
QCOMPARE(painter.paintEngine(), paintEngine); |
|
7158 |
QCOMPARE(paintEngine->systemClip(), QRegion(0, 0, 50, 50)); |
|
7159 |
||
7160 |
// Translate painter outside system clip. |
|
7161 |
painter.translate(50, 0); |
|
7162 |
widget.render(&painter); |
|
7163 |
||
7164 |
#ifdef RENDER_DEBUG |
|
7165 |
image.save("outside_systemclip.png"); |
|
7166 |
#endif |
|
7167 |
||
7168 |
// All pixels should be red. |
|
7169 |
for (int i = 0; i < image.height(); ++i) { |
|
7170 |
for (int j = 0; j < image.width(); ++j) |
|
7171 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
7172 |
} |
|
7173 |
||
7174 |
// Restore painter and refill image with red. |
|
7175 |
image.fill(QColor(Qt::red).rgb()); |
|
7176 |
painter.translate(-50, 0); |
|
7177 |
||
7178 |
// Set transform on the painter. |
|
7179 |
QTransform transform; |
|
7180 |
transform.shear(0, 1); |
|
7181 |
painter.setTransform(transform); |
|
7182 |
widget.render(&painter); |
|
7183 |
||
7184 |
#ifdef RENDER_DEBUG |
|
7185 |
image.save("blue_triangle.png"); |
|
7186 |
#endif |
|
7187 |
||
7188 |
// We should now have a blue triangle starting at scan line 1, and the rest should be red. |
|
7189 |
// rrrrrrrrrr |
|
7190 |
// brrrrrrrrr |
|
7191 |
// bbrrrrrrrr |
|
7192 |
// bbbrrrrrrr |
|
7193 |
// bbbbrrrrrr |
|
7194 |
// rrrrrrrrrr |
|
7195 |
// ... |
|
7196 |
||
7197 |
#ifndef Q_WS_MAC |
|
7198 |
for (int i = 0; i < image.height(); ++i) { |
|
7199 |
for (int j = 0; j < image.width(); ++j) { |
|
7200 |
if (i < 50 && j < i) |
|
7201 |
QCOMPARE(image.pixel(j, i), QColor(Qt::blue).rgb()); |
|
7202 |
else |
|
7203 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
7204 |
} |
|
7205 |
} |
|
7206 |
#else |
|
7207 |
// We don't paint directly on the image on the Mac, so we cannot do the pixel comparison |
|
7208 |
// as above due to QPainter::SmoothPixmapTransform. We therefore need to generate an |
|
7209 |
// expected image by first painting on a pixmap, and then draw the pixmap onto |
|
7210 |
// the image using QPainter::SmoothPixmapTransform. Then we can compare pixels :) |
|
7211 |
// The check is basically the same, except that it takes the smoothening into account. |
|
7212 |
QPixmap pixmap(50, 50); |
|
7213 |
const QRegion sysClip(0, 0, 50, 50); |
|
7214 |
widget.render(&pixmap, QPoint(), sysClip); |
|
7215 |
||
7216 |
QImage expectedImage(widget.size(), QImage::Format_RGB32); |
|
7217 |
expectedImage.fill(QColor(Qt::red).rgb()); |
|
7218 |
expectedImage.paintEngine()->setSystemClip(sysClip); |
|
7219 |
||
7220 |
QPainter expectedImagePainter(&expectedImage); |
|
7221 |
expectedImagePainter.setTransform(QTransform().shear(0, 1)); |
|
7222 |
// NB! This is the important part (SmoothPixmapTransform). |
|
7223 |
expectedImagePainter.setRenderHints(QPainter::SmoothPixmapTransform); |
|
7224 |
expectedImagePainter.drawPixmap(QPoint(0, 0), pixmap); |
|
7225 |
expectedImagePainter.end(); |
|
7226 |
||
7227 |
QCOMPARE(image, expectedImage); |
|
7228 |
#endif |
|
7229 |
} |
|
7230 |
||
7231 |
void tst_QWidget::render_systemClip2_data() |
|
7232 |
{ |
|
7233 |
QTest::addColumn<bool>("autoFillBackground"); |
|
7234 |
QTest::addColumn<bool>("usePaintEvent"); |
|
7235 |
QTest::addColumn<QColor>("expectedColor"); |
|
7236 |
||
7237 |
QTest::newRow("Only auto-fill background") << true << false << QColor(Qt::blue); |
|
7238 |
QTest::newRow("Only draw in paintEvent") << false << true << QColor(Qt::green); |
|
7239 |
QTest::newRow("Auto-fill background and draw in paintEvent") << true << true << QColor(Qt::green); |
|
7240 |
} |
|
7241 |
||
7242 |
void tst_QWidget::render_systemClip2() |
|
7243 |
{ |
|
7244 |
QFETCH(bool, autoFillBackground); |
|
7245 |
QFETCH(bool, usePaintEvent); |
|
7246 |
QFETCH(QColor, expectedColor); |
|
7247 |
||
7248 |
Q_ASSERT_X(expectedColor != QColor(Qt::red), Q_FUNC_INFO, |
|
7249 |
"Qt::red is the reference color for the image, pick another color"); |
|
7250 |
||
7251 |
class MyWidget : public QWidget |
|
7252 |
{ |
|
7253 |
public: |
|
7254 |
bool usePaintEvent; |
|
7255 |
void paintEvent(QPaintEvent *) |
|
7256 |
{ |
|
7257 |
if (usePaintEvent) |
|
7258 |
QPainter(this).fillRect(rect(), Qt::green); |
|
7259 |
} |
|
7260 |
}; |
|
7261 |
||
7262 |
MyWidget widget; |
|
7263 |
widget.usePaintEvent = usePaintEvent; |
|
7264 |
widget.setPalette(Qt::blue); |
|
7265 |
// NB! widget.setAutoFillBackground(autoFillBackground) won't do the |
|
7266 |
// trick here since the widget is a top-level. The background is filled |
|
7267 |
// regardless, unless Qt::WA_OpaquePaintEvent or Qt::WA_NoSystemBackground |
|
7268 |
// is set. We therefore use the opaque attribute to turn off auto-fill. |
|
7269 |
if (!autoFillBackground) |
|
7270 |
widget.setAttribute(Qt::WA_OpaquePaintEvent); |
|
7271 |
widget.resize(100, 100); |
|
7272 |
||
7273 |
QImage image(widget.size(), QImage::Format_RGB32); |
|
7274 |
image.fill(QColor(Qt::red).rgb()); |
|
7275 |
||
7276 |
QPaintEngine *paintEngine = image.paintEngine(); |
|
7277 |
QVERIFY(paintEngine); |
|
7278 |
||
7279 |
QRegion systemClip(QRegion(50, 0, 50, 10)); |
|
7280 |
systemClip += QRegion(90, 10, 10, 40); |
|
7281 |
paintEngine->setSystemClip(systemClip); |
|
7282 |
||
7283 |
// Render entire widget directly onto device. |
|
7284 |
widget.render(&image); |
|
7285 |
||
7286 |
#ifdef RENDER_DEBUG |
|
7287 |
image.save("systemclip_with_device.png"); |
|
7288 |
#endif |
|
7289 |
// All pixels within the system clip should now be |
|
7290 |
// the expectedColor, and the rest should be red. |
|
7291 |
for (int i = 0; i < image.height(); ++i) { |
|
7292 |
for (int j = 0; j < image.width(); ++j) { |
|
7293 |
if (systemClip.contains(QPoint(j, i))) |
|
7294 |
QCOMPARE(image.pixel(j, i), expectedColor.rgb()); |
|
7295 |
else |
|
7296 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
7297 |
} |
|
7298 |
} |
|
7299 |
||
7300 |
// Refill image with red. |
|
7301 |
image.fill(QColor(Qt::red).rgb()); |
|
7302 |
paintEngine->setSystemClip(systemClip); |
|
7303 |
||
7304 |
// Do the same with an untransformed painter. |
|
7305 |
QPainter painter(&image); |
|
7306 |
//Make sure we're using the same paint engine and has the right clip set. |
|
7307 |
QCOMPARE(painter.paintEngine(), paintEngine); |
|
7308 |
QCOMPARE(paintEngine->systemClip(), systemClip); |
|
7309 |
||
7310 |
widget.render(&painter); |
|
7311 |
||
7312 |
#ifdef RENDER_DEBUG |
|
7313 |
image.save("systemclip_with_untransformed_painter.png"); |
|
7314 |
#endif |
|
7315 |
// All pixels within the system clip should now be |
|
7316 |
// the expectedColor, and the rest should be red. |
|
7317 |
for (int i = 0; i < image.height(); ++i) { |
|
7318 |
for (int j = 0; j < image.width(); ++j) { |
|
7319 |
if (systemClip.contains(QPoint(j, i))) |
|
7320 |
QCOMPARE(image.pixel(j, i), expectedColor.rgb()); |
|
7321 |
else |
|
7322 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
7323 |
} |
|
7324 |
} |
|
7325 |
} |
|
7326 |
||
7327 |
void tst_QWidget::render_systemClip3_data() |
|
7328 |
{ |
|
7329 |
QTest::addColumn<QSize>("size"); |
|
7330 |
QTest::addColumn<bool>("useSystemClip"); |
|
7331 |
||
7332 |
// Reference: http://en.wikipedia.org/wiki/Flag_of_Norway |
|
7333 |
QTest::newRow("Norwegian Civil Flag") << QSize(220, 160) << false; |
|
7334 |
QTest::newRow("Norwegian War Flag") << QSize(270, 160) << true; |
|
7335 |
} |
|
7336 |
||
7337 |
// This test ensures that the current engine clip (systemClip + painter clip) |
|
7338 |
// is preserved after QPainter::setClipRegion(..., Qt::ReplaceClip); |
|
7339 |
void tst_QWidget::render_systemClip3() |
|
7340 |
{ |
|
7341 |
QFETCH(QSize, size); |
|
7342 |
QFETCH(bool, useSystemClip); |
|
7343 |
||
7344 |
// Calculate the inner/outer cross of the flag. |
|
7345 |
QRegion outerCross(0, 0, size.width(), size.height()); |
|
7346 |
outerCross -= QRect(0, 0, 60, 60); |
|
7347 |
outerCross -= QRect(100, 0, size.width() - 100, 60); |
|
7348 |
outerCross -= QRect(0, 100, 60, 60); |
|
7349 |
outerCross -= QRect(100, 100, size.width() - 100, 60); |
|
7350 |
||
7351 |
QRegion innerCross(0, 0, size.width(), size.height()); |
|
7352 |
innerCross -= QRect(0, 0, 70, 70); |
|
7353 |
innerCross -= QRect(90, 0, size.width() - 90, 70); |
|
7354 |
innerCross -= QRect(0, 90, 70, 70); |
|
7355 |
innerCross -= QRect(90, 90, size.width() - 90, 70); |
|
7356 |
||
7357 |
const QRegion redArea(QRegion(0, 0, size.width(), size.height()) - outerCross); |
|
7358 |
const QRegion whiteArea(outerCross - innerCross); |
|
7359 |
const QRegion blueArea(innerCross); |
|
7360 |
QRegion systemClip; |
|
7361 |
||
7362 |
// Okay, here's the image that should look like a Norwegian civil/war flag in the end. |
|
7363 |
QImage flag(size, QImage::Format_ARGB32); |
|
7364 |
flag.fill(QColor(Qt::transparent).rgba()); |
|
7365 |
||
7366 |
if (useSystemClip) { |
|
7367 |
QPainterPath warClip(QPoint(size.width(), 0)); |
|
7368 |
warClip.lineTo(size.width() - 110, 60); |
|
7369 |
warClip.lineTo(size.width(), 80); |
|
7370 |
warClip.lineTo(size.width() - 110, 100); |
|
7371 |
warClip.lineTo(size.width(), 160); |
|
7372 |
warClip.closeSubpath(); |
|
7373 |
systemClip = QRegion(0, 0, size.width(), size.height()) - QRegion(warClip.toFillPolygon().toPolygon()); |
|
7374 |
flag.paintEngine()->setSystemClip(systemClip); |
|
7375 |
} |
|
7376 |
||
7377 |
QPainter painter(&flag); |
|
7378 |
painter.fillRect(QRect(QPoint(), size), Qt::red); // Fill image background with red. |
|
7379 |
painter.setClipRegion(outerCross); // Limit widget painting to inside the outer cross. |
|
7380 |
||
7381 |
// Here's the widget that's supposed to draw the inner/outer cross of the flag. |
|
7382 |
// The outer cross (white) should be drawn when the background is auto-filled, and |
|
7383 |
// the inner cross (blue) should be drawn in the paintEvent. |
|
7384 |
class MyWidget : public QWidget |
|
7385 |
{ public: |
|
7386 |
void paintEvent(QPaintEvent *) |
|
7387 |
{ |
|
7388 |
QPainter painter(this); |
|
7389 |
// Be evil and try to paint outside the outer cross. This should not be |
|
7390 |
// possible since the shared painter is clipped to the outer cross. |
|
7391 |
painter.setClipRect(0, 0, 60, 60, Qt::ReplaceClip); |
|
7392 |
painter.fillRect(rect(), Qt::green); |
|
7393 |
painter.setClipRegion(clip, Qt::ReplaceClip); |
|
7394 |
painter.fillRect(rect(), Qt::blue); |
|
7395 |
} |
|
7396 |
QRegion clip; |
|
7397 |
}; |
|
7398 |
||
7399 |
MyWidget widget; |
|
7400 |
widget.clip = innerCross; |
|
7401 |
widget.setFixedSize(size); |
|
7402 |
widget.setPalette(Qt::white); |
|
7403 |
widget.setAutoFillBackground(true); |
|
7404 |
widget.render(&painter); |
|
7405 |
||
7406 |
#ifdef RENDER_DEBUG |
|
7407 |
flag.save("flag.png"); |
|
7408 |
#endif |
|
7409 |
||
7410 |
// Let's make sure we got a Norwegian flag. |
|
7411 |
for (int i = 0; i < flag.height(); ++i) { |
|
7412 |
for (int j = 0; j < flag.width(); ++j) { |
|
7413 |
const QPoint pixel(j, i); |
|
7414 |
const QRgb pixelValue = flag.pixel(pixel); |
|
7415 |
if (useSystemClip && !systemClip.contains(pixel)) |
|
7416 |
QCOMPARE(pixelValue, QColor(Qt::transparent).rgba()); |
|
7417 |
else if (redArea.contains(pixel)) |
|
7418 |
QCOMPARE(pixelValue, QColor(Qt::red).rgba()); |
|
7419 |
else if (whiteArea.contains(pixel)) |
|
7420 |
QCOMPARE(pixelValue, QColor(Qt::white).rgba()); |
|
7421 |
else |
|
7422 |
QCOMPARE(pixelValue, QColor(Qt::blue).rgba()); |
|
7423 |
} |
|
7424 |
} |
|
7425 |
} |
|
7426 |
||
7427 |
void tst_QWidget::render_task252837() |
|
7428 |
{ |
|
7429 |
QWidget widget; |
|
7430 |
widget.resize(200, 200); |
|
7431 |
||
7432 |
QPixmap pixmap(widget.size()); |
|
7433 |
QPainter painter(&pixmap); |
|
7434 |
// Please do not crash. |
|
7435 |
widget.render(&painter); |
|
7436 |
} |
|
7437 |
||
7438 |
void tst_QWidget::render_worldTransform() |
|
7439 |
{ |
|
7440 |
class MyWidget : public QWidget |
|
7441 |
{ public: |
|
7442 |
void paintEvent(QPaintEvent *) |
|
7443 |
{ |
|
7444 |
QPainter painter(this); |
|
7445 |
// Make sure world transform is identity. |
|
7446 |
QCOMPARE(painter.worldTransform(), QTransform()); |
|
7447 |
||
7448 |
// Make sure device transform is correct. |
|
7449 |
const QPoint widgetOffset = geometry().topLeft(); |
|
7450 |
QTransform expectedDeviceTransform = QTransform::fromTranslate(105, 5); |
|
7451 |
expectedDeviceTransform.rotate(90); |
|
7452 |
expectedDeviceTransform.translate(widgetOffset.x(), widgetOffset.y()); |
|
7453 |
QCOMPARE(painter.deviceTransform(), expectedDeviceTransform); |
|
7454 |
||
7455 |
// Set new world transform. |
|
7456 |
QTransform newWorldTransform = QTransform::fromTranslate(10, 10); |
|
7457 |
newWorldTransform.rotate(90); |
|
7458 |
painter.setWorldTransform(newWorldTransform); |
|
7459 |
QCOMPARE(painter.worldTransform(), newWorldTransform); |
|
7460 |
||
7461 |
// Again, check device transform. |
|
7462 |
expectedDeviceTransform.translate(10, 10); |
|
7463 |
expectedDeviceTransform.rotate(90); |
|
7464 |
QCOMPARE(painter.deviceTransform(), expectedDeviceTransform); |
|
7465 |
||
7466 |
painter.fillRect(QRect(0, 0, 20, 10), Qt::green); |
|
7467 |
} |
|
7468 |
}; |
|
7469 |
||
7470 |
MyWidget widget; |
|
7471 |
widget.setFixedSize(100, 100); |
|
7472 |
widget.setPalette(Qt::red); |
|
7473 |
widget.setAutoFillBackground(true); |
|
7474 |
||
7475 |
MyWidget child; |
|
7476 |
child.setParent(&widget); |
|
7477 |
child.move(50, 50); |
|
7478 |
child.setFixedSize(50, 50); |
|
7479 |
child.setPalette(Qt::blue); |
|
7480 |
child.setAutoFillBackground(true); |
|
7481 |
||
7482 |
QImage image(QSize(110, 110), QImage::Format_RGB32); |
|
7483 |
image.fill(QColor(Qt::black).rgb()); |
|
7484 |
||
7485 |
QPainter painter(&image); |
|
7486 |
painter.translate(105, 5); |
|
7487 |
painter.rotate(90); |
|
7488 |
||
7489 |
const QTransform worldTransform = painter.worldTransform(); |
|
7490 |
const QTransform deviceTransform = painter.deviceTransform(); |
|
7491 |
||
7492 |
// Render widgets onto image. |
|
7493 |
widget.render(&painter); |
|
7494 |
#ifdef RENDER_DEBUG |
|
7495 |
image.save("render_worldTransform_image.png"); |
|
7496 |
#endif |
|
7497 |
||
7498 |
// Ensure the transforms are unchanged after render. |
|
7499 |
QCOMPARE(painter.worldTransform(), painter.worldTransform()); |
|
7500 |
QCOMPARE(painter.deviceTransform(), painter.deviceTransform()); |
|
7501 |
painter.end(); |
|
7502 |
||
7503 |
// Paint expected image. |
|
7504 |
QImage expected(QSize(110, 110), QImage::Format_RGB32); |
|
7505 |
expected.fill(QColor(Qt::black).rgb()); |
|
7506 |
||
7507 |
QPainter expectedPainter(&expected); |
|
7508 |
expectedPainter.translate(105, 5); |
|
7509 |
expectedPainter.rotate(90); |
|
7510 |
expectedPainter.save(); |
|
7511 |
expectedPainter.fillRect(widget.rect(),Qt::red); |
|
7512 |
expectedPainter.translate(10, 10); |
|
7513 |
expectedPainter.rotate(90); |
|
7514 |
expectedPainter.fillRect(QRect(0, 0, 20, 10), Qt::green); |
|
7515 |
expectedPainter.restore(); |
|
7516 |
expectedPainter.translate(50, 50); |
|
7517 |
expectedPainter.fillRect(child.rect(),Qt::blue); |
|
7518 |
expectedPainter.translate(10, 10); |
|
7519 |
expectedPainter.rotate(90); |
|
7520 |
expectedPainter.fillRect(QRect(0, 0, 20, 10), Qt::green); |
|
7521 |
expectedPainter.end(); |
|
7522 |
||
7523 |
#ifdef RENDER_DEBUG |
|
7524 |
expected.save("render_worldTransform_expected.png"); |
|
7525 |
#endif |
|
7526 |
||
7527 |
QCOMPARE(image, expected); |
|
7528 |
} |
|
7529 |
||
7530 |
void tst_QWidget::setContentsMargins() |
|
7531 |
{ |
|
7532 |
QLabel label("why does it always rain on me?"); |
|
7533 |
QSize oldSize = label.sizeHint(); |
|
7534 |
label.setFrameStyle(QFrame::Sunken | QFrame::Box); |
|
7535 |
QSize newSize = label.sizeHint(); |
|
7536 |
QVERIFY(oldSize != newSize); |
|
7537 |
||
7538 |
QLabel label2("why does it always rain on me?"); |
|
7539 |
label2.show(); |
|
7540 |
label2.setFrameStyle(QFrame::Sunken | QFrame::Box); |
|
7541 |
QCOMPARE(newSize, label2.sizeHint()); |
|
7542 |
||
7543 |
QLabel label3("why does it always rain on me?"); |
|
7544 |
label3.setFrameStyle(QFrame::Sunken | QFrame::Box); |
|
7545 |
QCOMPARE(newSize, label3.sizeHint()); |
|
7546 |
} |
|
7547 |
||
7548 |
void tst_QWidget::moveWindowInShowEvent_data() |
|
7549 |
{ |
|
7550 |
QTest::addColumn<QPoint>("initial"); |
|
7551 |
QTest::addColumn<QPoint>("position"); |
|
7552 |
||
7553 |
QPoint p = QApplication::desktop()->availableGeometry().topLeft(); |
|
7554 |
||
7555 |
QTest::newRow("1") << p << (p + QPoint(10, 10)); |
|
7556 |
QTest::newRow("2") << (p + QPoint(10,10)) << p; |
|
7557 |
} |
|
7558 |
||
7559 |
void tst_QWidget::moveWindowInShowEvent() |
|
7560 |
{ |
|
7561 |
#ifdef Q_OS_IRIX |
|
7562 |
QSKIP("4DWM issues on IRIX makes this test fail", SkipAll); |
|
7563 |
#endif |
|
7564 |
QFETCH(QPoint, initial); |
|
7565 |
QFETCH(QPoint, position); |
|
7566 |
||
7567 |
class MoveWindowInShowEventWidget : public QWidget |
|
7568 |
{ |
|
7569 |
public: |
|
7570 |
QPoint position; |
|
7571 |
void showEvent(QShowEvent *) |
|
7572 |
{ |
|
7573 |
move(position); |
|
7574 |
} |
|
7575 |
}; |
|
7576 |
||
7577 |
MoveWindowInShowEventWidget widget; |
|
7578 |
widget.resize(QSize(qApp->desktop()->availableGeometry().size() / 3).expandedTo(QSize(1, 1))); |
|
7579 |
// move to this position in showEvent() |
|
7580 |
widget.position = position; |
|
7581 |
||
7582 |
// put the widget in it's starting position |
|
7583 |
widget.move(initial); |
|
7584 |
QCOMPARE(widget.pos(), initial); |
|
7585 |
||
7586 |
// show it |
|
7587 |
widget.show(); |
|
7588 |
#ifdef Q_WS_X11 |
|
7589 |
qt_x11_wait_for_window_manager(&widget); |
|
7590 |
#endif |
|
7591 |
QTest::qWait(100); |
|
7592 |
// it should have moved |
|
7593 |
QCOMPARE(widget.pos(), position); |
|
7594 |
} |
|
7595 |
||
7596 |
void tst_QWidget::repaintWhenChildDeleted() |
|
7597 |
{ |
|
7598 |
#ifdef Q_WS_WIN |
|
7599 |
if (QSysInfo::WindowsVersion & QSysInfo::WV_VISTA) { |
|
7600 |
QTest::qWait(1000); |
|
7601 |
} |
|
7602 |
#endif |
|
7603 |
ColorWidget w(0, Qt::red); |
|
7604 |
#if !defined(Q_OS_WINCE) && !defined(Q_WS_S60) |
|
7605 |
QPoint startPoint = QApplication::desktop()->availableGeometry(&w).topLeft(); |
|
7606 |
startPoint.rx() += 50; |
|
7607 |
startPoint.ry() += 50; |
|
7608 |
w.setGeometry(QRect(startPoint, QSize(100, 100))); |
|
7609 |
#else |
|
7610 |
w.setGeometry(60, 60, 110, 110); |
|
7611 |
#endif |
|
7612 |
w.show(); |
|
7613 |
QTest::qWaitForWindowShown(&w); |
|
7614 |
QTest::qWait(10); |
|
7615 |
QTRY_COMPARE(w.r, QRegion(w.rect())); |
|
7616 |
w.r = QRegion(); |
|
7617 |
||
7618 |
{ |
|
7619 |
const QPoint tlwOffset = w.geometry().topLeft(); |
|
7620 |
ColorWidget child(&w, Qt::blue); |
|
7621 |
child.setGeometry(10, 10, 10, 10); |
|
7622 |
child.show(); |
|
7623 |
QTest::qWait(10); |
|
7624 |
QTRY_COMPARE(child.r, QRegion(child.rect())); |
|
7625 |
w.r = QRegion(); |
|
7626 |
} |
|
7627 |
||
7628 |
QTest::qWait(10); |
|
7629 |
QTRY_COMPARE(w.r, QRegion(10, 10, 10, 10)); |
|
7630 |
} |
|
7631 |
||
7632 |
// task 175114 |
|
7633 |
void tst_QWidget::hideOpaqueChildWhileHidden() |
|
7634 |
{ |
|
7635 |
ColorWidget w(0, Qt::red); |
|
7636 |
#if !defined(Q_OS_WINCE) && !defined(Q_WS_S60) |
|
7637 |
QPoint startPoint = QApplication::desktop()->availableGeometry(&w).topLeft(); |
|
7638 |
startPoint.rx() += 50; |
|
7639 |
startPoint.ry() += 50; |
|
7640 |
w.setGeometry(QRect(startPoint, QSize(100, 100))); |
|
7641 |
#else |
|
7642 |
w.setGeometry(60, 60, 110, 110); |
|
7643 |
#endif |
|
7644 |
||
7645 |
ColorWidget child(&w, Qt::blue); |
|
7646 |
child.setGeometry(10, 10, 80, 80); |
|
7647 |
||
7648 |
ColorWidget child2(&child, Qt::white); |
|
7649 |
child2.setGeometry(10, 10, 60, 60); |
|
7650 |
||
7651 |
w.show(); |
|
7652 |
QTest::qWaitForWindowShown(&w); |
|
7653 |
QTest::qWait(10); |
|
7654 |
QTRY_COMPARE(child2.r, QRegion(child2.rect())); |
|
7655 |
child.r = QRegion(); |
|
7656 |
child2.r = QRegion(); |
|
7657 |
w.r = QRegion(); |
|
7658 |
||
7659 |
child.hide(); |
|
7660 |
child2.hide(); |
|
7661 |
QTest::qWait(100); |
|
7662 |
||
7663 |
QCOMPARE(w.r, QRegion(child.geometry())); |
|
7664 |
||
7665 |
child.show(); |
|
7666 |
QTest::qWait(100); |
|
7667 |
QCOMPARE(child.r, QRegion(child.rect())); |
|
7668 |
QCOMPARE(child2.r, QRegion()); |
|
7669 |
} |
|
7670 |
||
7671 |
void tst_QWidget::updateWhileMinimized() |
|
7672 |
{ |
|
7673 |
#if defined(Q_OS_WINCE) || defined(Q_WS_QWS) |
|
7674 |
QSKIP("This test doesn't make sense without support for showMinimized()", SkipAll); |
|
7675 |
#endif |
|
7676 |
||
7677 |
UpdateWidget widget; |
|
7678 |
// Filter out activation change and focus events to avoid update() calls in QWidget. |
|
7679 |
widget.updateOnActivationChangeAndFocusIn = false; |
|
7680 |
widget.reset(); |
|
7681 |
widget.show(); |
|
7682 |
QTest::qWaitForWindowShown(&widget); |
|
7683 |
QApplication::processEvents(); |
|
7684 |
QTRY_VERIFY(widget.numPaintEvents > 0); |
|
7685 |
QTest::qWait(150); |
|
7686 |
||
7687 |
// Minimize window. |
|
7688 |
widget.showMinimized(); |
|
7689 |
QTest::qWait(110); |
|
7690 |
||
7691 |
widget.reset(); |
|
7692 |
||
7693 |
// The widget is not visible on the screen (but isVisible() still returns true). |
|
7694 |
// Make sure update requests are discarded until the widget is shown again. |
|
7695 |
widget.update(0, 0, 50, 50); |
|
7696 |
QTest::qWait(10); |
|
7697 |
QCOMPARE(widget.numPaintEvents, 0); |
|
7698 |
||
7699 |
// Restore window. |
|
7700 |
widget.showNormal(); |
|
7701 |
QTest::qWait(30); |
|
7702 |
QTRY_COMPARE(widget.numPaintEvents, 1); |
|
7703 |
QCOMPARE(widget.paintedRegion, QRegion(0, 0, 50, 50)); |
|
7704 |
} |
|
7705 |
||
7706 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) |
|
7707 |
class PaintOnScreenWidget: public QWidget |
|
7708 |
{ |
|
7709 |
public: |
|
7710 |
PaintOnScreenWidget(QWidget *parent = 0, Qt::WindowFlags f = 0) |
|
7711 |
:QWidget(parent, f) |
|
7712 |
{ |
|
7713 |
} |
|
7714 |
#if defined(Q_WS_WIN) |
|
7715 |
// This is the only way to enable PaintOnScreen on Windows. |
|
7716 |
QPaintEngine * paintEngine () const {return 0;} |
|
7717 |
#endif |
|
7718 |
}; |
|
7719 |
||
7720 |
void tst_QWidget::alienWidgets() |
|
7721 |
{ |
|
7722 |
qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); |
|
7723 |
QWidget parent; |
|
7724 |
QWidget child(&parent); |
|
7725 |
QWidget grandChild(&child); |
|
7726 |
QWidget greatGrandChild(&grandChild); |
|
7727 |
parent.show(); |
|
7728 |
||
7729 |
#ifdef Q_WS_X11 |
|
7730 |
qt_x11_wait_for_window_manager(&parent); |
|
7731 |
#endif |
|
7732 |
||
7733 |
// Verify that the WA_WState_Created attribute is set |
|
7734 |
// and the top-level is the only native window. |
|
7735 |
QVERIFY(parent.testAttribute(Qt::WA_WState_Created)); |
|
7736 |
QVERIFY(parent.internalWinId()); |
|
7737 |
||
7738 |
QVERIFY(child.testAttribute(Qt::WA_WState_Created)); |
|
7739 |
QVERIFY(!child.internalWinId()); |
|
7740 |
||
7741 |
QVERIFY(grandChild.testAttribute(Qt::WA_WState_Created)); |
|
7742 |
QVERIFY(!grandChild.internalWinId()); |
|
7743 |
||
7744 |
QVERIFY(greatGrandChild.testAttribute(Qt::WA_WState_Created)); |
|
7745 |
QVERIFY(!greatGrandChild.internalWinId()); |
|
7746 |
||
7747 |
// Enforce native windows all the way up in the parent hierarchy |
|
7748 |
// if not WA_DontCreateNativeAncestors is set. |
|
7749 |
grandChild.setAttribute(Qt::WA_DontCreateNativeAncestors); |
|
7750 |
greatGrandChild.setAttribute(Qt::WA_NativeWindow); |
|
7751 |
QVERIFY(greatGrandChild.internalWinId()); |
|
7752 |
QVERIFY(grandChild.internalWinId()); |
|
7753 |
QVERIFY(!child.internalWinId()); |
|
7754 |
||
7755 |
{ |
|
7756 |
// Ensure that hide() on an ancestor of a widget with |
|
7757 |
// Qt::WA_DontCreateNativeAncestors still gets unmapped |
|
7758 |
QWidget window; |
|
7759 |
QWidget widget(&window); |
|
7760 |
QWidget child(&widget); |
|
7761 |
child.setAttribute(Qt::WA_NativeWindow); |
|
7762 |
child.setAttribute(Qt::WA_DontCreateNativeAncestors); |
|
7763 |
window.show(); |
|
7764 |
QVERIFY(child.testAttribute(Qt::WA_Mapped)); |
|
7765 |
widget.hide(); |
|
7766 |
QVERIFY(!child.testAttribute(Qt::WA_Mapped)); |
|
7767 |
} |
|
7768 |
||
7769 |
// Enforce a native window when calling QWidget::winId. |
|
7770 |
QVERIFY(child.winId()); |
|
7771 |
QVERIFY(child.internalWinId()); |
|
7772 |
||
7773 |
// Check that paint on screen widgets (incl. children) are native. |
|
7774 |
PaintOnScreenWidget paintOnScreen(&parent); |
|
7775 |
QWidget paintOnScreenChild(&paintOnScreen); |
|
7776 |
paintOnScreen.show(); |
|
7777 |
QVERIFY(paintOnScreen.testAttribute(Qt::WA_WState_Created)); |
|
7778 |
QVERIFY(!paintOnScreen.testAttribute(Qt::WA_NativeWindow)); |
|
7779 |
QVERIFY(!paintOnScreen.internalWinId()); |
|
7780 |
QVERIFY(!paintOnScreenChild.testAttribute(Qt::WA_NativeWindow)); |
|
7781 |
QVERIFY(!paintOnScreenChild.internalWinId()); |
|
7782 |
||
7783 |
paintOnScreen.setAttribute(Qt::WA_PaintOnScreen); |
|
7784 |
QVERIFY(paintOnScreen.testAttribute(Qt::WA_NativeWindow)); |
|
7785 |
QVERIFY(paintOnScreen.internalWinId()); |
|
7786 |
QVERIFY(paintOnScreenChild.testAttribute(Qt::WA_NativeWindow)); |
|
7787 |
QVERIFY(paintOnScreenChild.internalWinId()); |
|
7788 |
||
7789 |
// Check that widgets with the Qt::MSWindowsOwnDC attribute set |
|
7790 |
// are native. |
|
7791 |
QWidget msWindowsOwnDC(&parent, Qt::MSWindowsOwnDC); |
|
7792 |
msWindowsOwnDC.show(); |
|
7793 |
QVERIFY(msWindowsOwnDC.testAttribute(Qt::WA_WState_Created)); |
|
7794 |
QVERIFY(msWindowsOwnDC.testAttribute(Qt::WA_NativeWindow)); |
|
7795 |
QVERIFY(msWindowsOwnDC.internalWinId()); |
|
7796 |
||
7797 |
{ // Enforce a native window when calling QWidget::handle() (on X11) or QWidget::getDC() (on Windows). |
|
7798 |
QWidget widget(&parent); |
|
7799 |
widget.show(); |
|
7800 |
QVERIFY(widget.testAttribute(Qt::WA_WState_Created)); |
|
7801 |
QVERIFY(!widget.internalWinId()); |
|
7802 |
#ifdef Q_WS_X11 |
|
7803 |
widget.handle(); |
|
7804 |
#else |
|
7805 |
widget.getDC(); |
|
7806 |
#endif |
|
7807 |
QVERIFY(widget.internalWinId()); |
|
7808 |
} |
|
7809 |
||
7810 |
#ifdef Q_WS_X11 |
|
7811 |
#ifndef QT_NO_XRENDER |
|
7812 |
{ // Enforce a native window when calling QWidget::x11PictureHandle(). |
|
7813 |
QWidget widget(&parent); |
|
7814 |
widget.show(); |
|
7815 |
QVERIFY(widget.testAttribute(Qt::WA_WState_Created)); |
|
7816 |
QVERIFY(!widget.internalWinId()); |
|
7817 |
widget.x11PictureHandle(); |
|
7818 |
QVERIFY(widget.internalWinId()); |
|
7819 |
} |
|
7820 |
#endif |
|
7821 |
||
7822 |
{ // Make sure we don't create native windows when setting Qt::WA_X11NetWmWindowType attributes |
|
7823 |
// on alien widgets (see task 194231). |
|
7824 |
QWidget dummy; |
|
7825 |
QVERIFY(dummy.winId()); |
|
7826 |
QWidget widget(&dummy); |
|
7827 |
widget.setAttribute(Qt::WA_X11NetWmWindowTypeToolBar); |
|
7828 |
QVERIFY(!widget.internalWinId()); |
|
7829 |
} |
|
7830 |
#endif |
|
7831 |
||
7832 |
||
7833 |
{ // Make sure we create native ancestors when setting Qt::WA_PaintOnScreen before show(). |
|
7834 |
QWidget topLevel; |
|
7835 |
QWidget child(&topLevel); |
|
7836 |
QWidget grandChild(&child); |
|
7837 |
PaintOnScreenWidget greatGrandChild(&grandChild); |
|
7838 |
||
7839 |
greatGrandChild.setAttribute(Qt::WA_PaintOnScreen); |
|
7840 |
QVERIFY(!child.internalWinId()); |
|
7841 |
QVERIFY(!grandChild.internalWinId()); |
|
7842 |
QVERIFY(!greatGrandChild.internalWinId()); |
|
7843 |
||
7844 |
topLevel.show(); |
|
7845 |
QVERIFY(child.internalWinId()); |
|
7846 |
QVERIFY(grandChild.internalWinId()); |
|
7847 |
QVERIFY(greatGrandChild.internalWinId()); |
|
7848 |
} |
|
7849 |
||
7850 |
{ // Ensure that widgets reparented into Qt::WA_PaintOnScreen widgets become native. |
|
7851 |
QWidget topLevel; |
|
7852 |
QWidget *widget = new PaintOnScreenWidget(&topLevel); |
|
7853 |
widget->setAttribute(Qt::WA_PaintOnScreen); |
|
7854 |
QWidget *child = new QWidget; |
|
7855 |
QWidget *dummy = new QWidget(child); |
|
7856 |
QWidget *grandChild = new QWidget(child); |
|
7857 |
QWidget *dummy2 = new QWidget(grandChild); |
|
7858 |
||
7859 |
child->setParent(widget); |
|
7860 |
||
7861 |
QVERIFY(!topLevel.internalWinId()); |
|
7862 |
QVERIFY(!child->internalWinId()); |
|
7863 |
QVERIFY(!dummy->internalWinId()); |
|
7864 |
QVERIFY(!grandChild->internalWinId()); |
|
7865 |
QVERIFY(!dummy2->internalWinId()); |
|
7866 |
||
7867 |
topLevel.show(); |
|
7868 |
QVERIFY(topLevel.internalWinId()); |
|
7869 |
QVERIFY(widget->testAttribute(Qt::WA_NativeWindow)); |
|
7870 |
QVERIFY(child->internalWinId()); |
|
7871 |
QVERIFY(child->testAttribute(Qt::WA_NativeWindow)); |
|
7872 |
QVERIFY(!child->testAttribute(Qt::WA_PaintOnScreen)); |
|
7873 |
QVERIFY(!dummy->internalWinId()); |
|
7874 |
QVERIFY(!dummy->testAttribute(Qt::WA_NativeWindow)); |
|
7875 |
QVERIFY(!grandChild->internalWinId()); |
|
7876 |
QVERIFY(!grandChild->testAttribute(Qt::WA_NativeWindow)); |
|
7877 |
QVERIFY(!dummy2->internalWinId()); |
|
7878 |
QVERIFY(!dummy2->testAttribute(Qt::WA_NativeWindow)); |
|
7879 |
} |
|
7880 |
||
7881 |
{ // Ensure that ancestors of a Qt::WA_PaintOnScreen widget stay native |
|
7882 |
// if they are re-created (typically in QWidgetPrivate::setParent_sys) (task 210822). |
|
7883 |
QWidget window; |
|
7884 |
QWidget child(&window); |
|
7885 |
||
7886 |
QWidget grandChild; |
|
7887 |
grandChild.setWindowTitle("This causes the widget to be created"); |
|
7888 |
||
7889 |
PaintOnScreenWidget paintOnScreenWidget; |
|
7890 |
paintOnScreenWidget.setAttribute(Qt::WA_PaintOnScreen); |
|
7891 |
paintOnScreenWidget.setParent(&grandChild); |
|
7892 |
||
7893 |
grandChild.setParent(&child); |
|
7894 |
||
7895 |
window.show(); |
|
7896 |
||
7897 |
QVERIFY(window.internalWinId()); |
|
7898 |
QVERIFY(child.internalWinId()); |
|
7899 |
QVERIFY(child.testAttribute(Qt::WA_NativeWindow)); |
|
7900 |
QVERIFY(grandChild.internalWinId()); |
|
7901 |
QVERIFY(grandChild.testAttribute(Qt::WA_NativeWindow)); |
|
7902 |
QVERIFY(paintOnScreenWidget.internalWinId()); |
|
7903 |
QVERIFY(paintOnScreenWidget.testAttribute(Qt::WA_NativeWindow)); |
|
7904 |
} |
|
7905 |
||
7906 |
{ // Ensure that all siblings are native unless Qt::AA_DontCreateNativeWidgetSiblings is set. |
|
7907 |
qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, false); |
|
7908 |
QWidget mainWindow; |
|
7909 |
QWidget *toolBar = new QWidget(&mainWindow); |
|
7910 |
QWidget *dockWidget = new QWidget(&mainWindow); |
|
7911 |
QWidget *centralWidget = new QWidget(&mainWindow); |
|
7912 |
||
7913 |
QWidget *button = new QWidget(centralWidget); |
|
7914 |
QWidget *mdiArea = new QWidget(centralWidget); |
|
7915 |
||
7916 |
QWidget *horizontalScroll = new QWidget(mdiArea); |
|
7917 |
QWidget *verticalScroll = new QWidget(mdiArea); |
|
7918 |
QWidget *viewport = new QWidget(mdiArea); |
|
7919 |
||
7920 |
viewport->setAttribute(Qt::WA_NativeWindow); |
|
7921 |
mainWindow.show(); |
|
7922 |
||
7923 |
// Ensure that the viewport and its siblings are native: |
|
7924 |
QVERIFY(verticalScroll->testAttribute(Qt::WA_NativeWindow)); |
|
7925 |
QVERIFY(verticalScroll->testAttribute(Qt::WA_NativeWindow)); |
|
7926 |
QVERIFY(horizontalScroll->testAttribute(Qt::WA_NativeWindow)); |
|
7927 |
||
7928 |
// Ensure that the mdi area and its siblings are native: |
|
7929 |
QVERIFY(mdiArea->testAttribute(Qt::WA_NativeWindow)); |
|
7930 |
QVERIFY(button->testAttribute(Qt::WA_NativeWindow)); |
|
7931 |
||
7932 |
// Ensure that the central widget and its siblings are native: |
|
7933 |
QVERIFY(centralWidget->testAttribute(Qt::WA_NativeWindow)); |
|
7934 |
QVERIFY(dockWidget->testAttribute(Qt::WA_NativeWindow)); |
|
7935 |
QVERIFY(toolBar->testAttribute(Qt::WA_NativeWindow)); |
|
7936 |
} |
|
7937 |
} |
|
7938 |
#endif // Q_WS_WIN / Q_WS_X11 |
|
7939 |
||
7940 |
class ASWidget : public QWidget |
|
7941 |
{ |
|
7942 |
public: |
|
7943 |
ASWidget(QSize sizeHint, QSizePolicy sizePolicy, bool layout, bool hfwLayout, QWidget *parent = 0) |
|
7944 |
: QWidget(parent), mySizeHint(sizeHint) |
|
7945 |
{ |
|
7946 |
setSizePolicy(sizePolicy); |
|
7947 |
if (layout) { |
|
7948 |
QSizePolicy sp = QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
|
7949 |
sp.setHeightForWidth(hfwLayout); |
|
7950 |
||
7951 |
QVBoxLayout *vbox = new QVBoxLayout; |
|
7952 |
vbox->setMargin(0); |
|
7953 |
vbox->addWidget(new ASWidget(sizeHint + QSize(30, 20), sp, false, false)); |
|
7954 |
setLayout(vbox); |
|
7955 |
} |
|
7956 |
} |
|
7957 |
||
7958 |
QSize sizeHint() const { |
|
7959 |
if (layout()) |
|
7960 |
return layout()->totalSizeHint(); |
|
7961 |
return mySizeHint; |
|
7962 |
} |
|
7963 |
int heightForWidth(int width) const { |
|
7964 |
if (sizePolicy().hasHeightForWidth()) { |
|
7965 |
return width * 2; |
|
7966 |
} else { |
|
7967 |
return -1; |
|
7968 |
} |
|
7969 |
} |
|
7970 |
||
7971 |
QSize mySizeHint; |
|
7972 |
}; |
|
7973 |
||
7974 |
void tst_QWidget::adjustSize_data() |
|
7975 |
{ |
|
7976 |
const int MagicW = 200; |
|
7977 |
const int MagicH = 100; |
|
7978 |
||
7979 |
QTest::addColumn<QSize>("sizeHint"); |
|
7980 |
QTest::addColumn<int>("hPolicy"); |
|
7981 |
QTest::addColumn<int>("vPolicy"); |
|
7982 |
QTest::addColumn<bool>("hfwSP"); |
|
7983 |
QTest::addColumn<bool>("layout"); |
|
7984 |
QTest::addColumn<bool>("hfwLayout"); |
|
7985 |
QTest::addColumn<bool>("haveParent"); |
|
7986 |
QTest::addColumn<QSize>("expectedSize"); |
|
7987 |
||
7988 |
QTest::newRow("1") << QSize(5, 6) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7989 |
<< false << false << false << false << QSize(5, qMax(6, MagicH)); |
|
7990 |
QTest::newRow("2") << QSize(5, 6) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7991 |
<< true << false << false << false << QSize(5, qMax(10, MagicH)); |
|
7992 |
QTest::newRow("3") << QSize(5, 6) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7993 |
<< false << true << false << false << QSize(35, 26); |
|
7994 |
QTest::newRow("4") << QSize(5, 6) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7995 |
<< false << true << true << false << QSize(35, 70); |
|
7996 |
QTest::newRow("5") << QSize(40001, 30001) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7997 |
<< false << false << false << false << QSize(100000, 100000); |
|
7998 |
QTest::newRow("6") << QSize(40001, 30001) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
7999 |
<< true << false << false << false << QSize(100000, 100000); |
|
8000 |
QTest::newRow("7") << QSize(40001, 30001) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
8001 |
<< false << true << false << false << QSize(100000, 100000); |
|
8002 |
QTest::newRow("8") << QSize(40001, 30001) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
8003 |
<< false << true << true << false << QSize(100000, 100000); |
|
8004 |
QTest::newRow("9") << QSize(5, 6) << int(QSizePolicy::Expanding) << int(QSizePolicy::Minimum) |
|
8005 |
<< true << false << false << false << QSize(qMax(5, MagicW), 10); |
|
8006 |
||
8007 |
QTest::newRow("1c") << QSize(5, 6) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
8008 |
<< false << false << false << true << QSize(5, 6); |
|
8009 |
QTest::newRow("2c") << QSize(5, 6) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
8010 |
<< true << false << false << true << QSize(5, 6 /* or 10 would be OK too, since hfw contradicts sizeHint() */); |
|
8011 |
QTest::newRow("3c") << QSize(5, 6) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
8012 |
<< false << true << false << true << QSize(35, 26); |
|
8013 |
QTest::newRow("4c") << QSize(5, 6) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
8014 |
<< false << true << true << true << QSize(35, 70); |
|
8015 |
QTest::newRow("5c") << QSize(40001, 30001) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
8016 |
<< false << false << false << true << QSize(40001, 30001); |
|
8017 |
QTest::newRow("6c") << QSize(40001, 30001) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
8018 |
<< true << false << false << true << QSize(40001, 30001 /* or 80002 would be OK too, since hfw contradicts sizeHint() */); |
|
8019 |
QTest::newRow("7c") << QSize(40001, 30001) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
8020 |
<< false << true << false << true << QSize(40001 + 30, 30001 + 20); |
|
8021 |
QTest::newRow("8c") << QSize(40001, 30001) << int(QSizePolicy::Minimum) << int(QSizePolicy::Expanding) |
|
8022 |
<< false << true << true << true << QSize(40001 + 30, 80002 + 60); |
|
8023 |
QTest::newRow("9c") << QSize(5, 6) << int(QSizePolicy::Expanding) << int(QSizePolicy::Minimum) |
|
8024 |
<< true << false << false << true << QSize(5, 6); |
|
8025 |
} |
|
8026 |
||
8027 |
void tst_QWidget::adjustSize() |
|
8028 |
{ |
|
8029 |
QFETCH(QSize, sizeHint); |
|
8030 |
QFETCH(int, hPolicy); |
|
8031 |
QFETCH(int, vPolicy); |
|
8032 |
QFETCH(bool, hfwSP); |
|
8033 |
QFETCH(bool, layout); |
|
8034 |
QFETCH(bool, hfwLayout); |
|
8035 |
QFETCH(bool, haveParent); |
|
8036 |
QFETCH(QSize, expectedSize); |
|
8037 |
||
8038 |
QWidget *parent = new QWidget; |
|
8039 |
||
8040 |
QSizePolicy sp = QSizePolicy(QSizePolicy::Policy(hPolicy), QSizePolicy::Policy(vPolicy)); |
|
8041 |
sp.setHeightForWidth(hfwSP); |
|
8042 |
||
8043 |
QWidget *child = new ASWidget(sizeHint, sp, layout, hfwLayout, haveParent ? parent : 0); |
|
8044 |
child->resize(123, 456); |
|
8045 |
child->adjustSize(); |
|
8046 |
if (expectedSize == QSize(100000, 100000)) { |
|
8047 |
QVERIFY(child->size().width() < sizeHint.width()); |
|
8048 |
QVERIFY(child->size().height() < sizeHint.height()); |
|
8049 |
} else { |
|
8050 |
#if defined (Q_OS_WINCE) |
|
8051 |
if (!haveParent) { |
|
8052 |
const QRect& desktopRect = qApp->desktop()->availableGeometry(); |
|
8053 |
expectedSize.setWidth(qMin(expectedSize.width(), desktopRect.width())); |
|
8054 |
expectedSize.setHeight(qMin(expectedSize.height(), desktopRect.height())); |
|
8055 |
} |
|
8056 |
#endif |
|
8057 |
QCOMPARE(child->size(), expectedSize); |
|
8058 |
} |
|
8059 |
||
8060 |
delete parent; |
|
8061 |
} |
|
8062 |
||
8063 |
class TestLayout : public QVBoxLayout |
|
8064 |
{ |
|
8065 |
Q_OBJECT |
|
8066 |
public: |
|
8067 |
TestLayout(QWidget *w = 0) : QVBoxLayout(w) |
|
8068 |
{ |
|
8069 |
invalidated = false; |
|
8070 |
} |
|
8071 |
||
8072 |
void invalidate() |
|
8073 |
{ |
|
8074 |
invalidated = true; |
|
8075 |
} |
|
8076 |
||
8077 |
bool invalidated; |
|
8078 |
}; |
|
8079 |
||
8080 |
void tst_QWidget::updateGeometry_data() |
|
8081 |
{ |
|
8082 |
QTest::addColumn<QSize>("minSize"); |
|
8083 |
QTest::addColumn<bool>("shouldInvalidate"); |
|
8084 |
QTest::addColumn<QSize>("maxSize"); |
|
8085 |
QTest::addColumn<bool>("shouldInvalidate2"); |
|
8086 |
QTest::addColumn<int>("verticalSizePolicy"); |
|
8087 |
QTest::addColumn<bool>("shouldInvalidate3"); |
|
8088 |
QTest::addColumn<bool>("setVisible"); |
|
8089 |
QTest::addColumn<bool>("shouldInvalidate4"); |
|
8090 |
||
8091 |
QTest::newRow("setMinimumSize") |
|
8092 |
<< QSize(100, 100) << true |
|
8093 |
<< QSize() << false |
|
8094 |
<< int(QSizePolicy::Preferred) << false |
|
8095 |
<< true << false; |
|
8096 |
QTest::newRow("setMaximumSize") |
|
8097 |
<< QSize() << false |
|
8098 |
<< QSize(100, 100) << true |
|
8099 |
<< int(QSizePolicy::Preferred) << false |
|
8100 |
<< true << false; |
|
8101 |
QTest::newRow("setMinimumSize, then maximumSize to a different size") |
|
8102 |
<< QSize(100, 100) << true |
|
8103 |
<< QSize(300, 300) << true |
|
8104 |
<< int(QSizePolicy::Preferred) << false |
|
8105 |
<< true << false; |
|
8106 |
QTest::newRow("setMinimumSize, then maximumSize to the same size") |
|
8107 |
<< QSize(100, 100) << true |
|
8108 |
<< QSize(100, 100) << true |
|
8109 |
<< int(QSizePolicy::Preferred) << false |
|
8110 |
<< true << false; |
|
8111 |
QTest::newRow("setMinimumSize, then maximumSize to the same size and then hide it") |
|
8112 |
<< QSize(100, 100) << true |
|
8113 |
<< QSize(100, 100) << true |
|
8114 |
<< int(QSizePolicy::Preferred) << false |
|
8115 |
<< false << true; |
|
8116 |
QTest::newRow("Change sizePolicy") |
|
8117 |
<< QSize() << false |
|
8118 |
<< QSize() << false |
|
8119 |
<< int(QSizePolicy::Minimum) << true |
|
8120 |
<< true << false; |
|
8121 |
||
8122 |
} |
|
8123 |
||
8124 |
void tst_QWidget::updateGeometry() |
|
8125 |
{ |
|
8126 |
QFETCH(QSize, minSize); |
|
8127 |
QFETCH(bool, shouldInvalidate); |
|
8128 |
QFETCH(QSize, maxSize); |
|
8129 |
QFETCH(bool, shouldInvalidate2); |
|
8130 |
QFETCH(int, verticalSizePolicy); |
|
8131 |
QFETCH(bool, shouldInvalidate3); |
|
8132 |
QFETCH(bool, setVisible); |
|
8133 |
QFETCH(bool, shouldInvalidate4); |
|
8134 |
QWidget parent; |
|
8135 |
parent.resize(200, 200); |
|
8136 |
TestLayout *lout = new TestLayout(); |
|
8137 |
parent.setLayout(lout); |
|
8138 |
QWidget *child = new QWidget(&parent); |
|
8139 |
lout->addWidget(child); |
|
8140 |
parent.show(); |
|
8141 |
QApplication::processEvents(); |
|
8142 |
||
8143 |
lout->invalidated = false; |
|
8144 |
if (minSize.isValid()) |
|
8145 |
child->setMinimumSize(minSize); |
|
8146 |
QCOMPARE(lout->invalidated, shouldInvalidate); |
|
8147 |
||
8148 |
lout->invalidated = false; |
|
8149 |
if (maxSize.isValid()) |
|
8150 |
child->setMaximumSize(maxSize); |
|
8151 |
QCOMPARE(lout->invalidated, shouldInvalidate2); |
|
8152 |
||
8153 |
lout->invalidated = false; |
|
8154 |
child->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, (QSizePolicy::Policy)verticalSizePolicy)); |
|
8155 |
if (shouldInvalidate3) |
|
8156 |
QCOMPARE(lout->invalidated, true); |
|
8157 |
||
8158 |
lout->invalidated = false; |
|
8159 |
if (!setVisible) |
|
8160 |
child->setVisible(false); |
|
8161 |
QCOMPARE(lout->invalidated, shouldInvalidate4); |
|
8162 |
} |
|
8163 |
||
8164 |
void tst_QWidget::sendUpdateRequestImmediately() |
|
8165 |
{ |
|
8166 |
#ifdef Q_WS_MAC |
|
8167 |
if (!QApplicationPrivate::graphicsSystem()) |
|
8168 |
QSKIP("We only send update requests on the Mac when passing -graphicssystem", SkipAll); |
|
8169 |
#endif |
|
8170 |
||
8171 |
UpdateWidget updateWidget; |
|
8172 |
updateWidget.show(); |
|
8173 |
#ifdef Q_WS_X11 |
|
8174 |
qt_x11_wait_for_window_manager(&updateWidget); |
|
8175 |
#endif |
|
8176 |
||
8177 |
qApp->processEvents(); |
|
8178 |
#ifdef Q_WS_QWS |
|
8179 |
QApplication::sendPostedEvents(); //glib workaround |
|
8180 |
#endif |
|
8181 |
updateWidget.reset(); |
|
8182 |
||
8183 |
QCOMPARE(updateWidget.numUpdateRequestEvents, 0); |
|
8184 |
updateWidget.repaint(); |
|
8185 |
QCOMPARE(updateWidget.numUpdateRequestEvents, 1); |
|
8186 |
} |
|
8187 |
||
8188 |
class RedirectedWidget : public QWidget |
|
8189 |
{ |
|
8190 |
protected: |
|
8191 |
void paintEvent(QPaintEvent *) |
|
8192 |
{ |
|
8193 |
// Verify that the widget has a redirection set. The widget is redirected to |
|
8194 |
// the backing store on all platforms using it; otherwise to itself if the wrect |
|
8195 |
// does not start in (0, 0) or it has a mask set. |
|
8196 |
QPaintDevice *oldRedirection = QPainter::redirected(this); |
|
8197 |
#ifndef Q_WS_MAC |
|
8198 |
QVERIFY(oldRedirection); |
|
8199 |
#endif |
|
8200 |
||
8201 |
QImage image(size(), QImage::Format_RGB32); |
|
8202 |
image.fill(Qt::blue); |
|
8203 |
||
8204 |
{ |
|
8205 |
QPainter painter(this); |
|
8206 |
QCOMPARE(painter.device(), static_cast<QPaintDevice *>(this)); |
|
8207 |
} |
|
8208 |
||
8209 |
QPainter::setRedirected(this, &image); |
|
8210 |
QCOMPARE(QPainter::redirected(this), static_cast<QPaintDevice *>(&image)); |
|
8211 |
||
8212 |
QPainter painter(this); |
|
8213 |
painter.fillRect(rect(), Qt::red); |
|
8214 |
||
8215 |
QPainter::restoreRedirected(this); |
|
8216 |
QCOMPARE(QPainter::redirected(this), oldRedirection); |
|
8217 |
||
8218 |
for (int i = 0; i < image.height(); ++i) |
|
8219 |
for (int j = 0; j < image.width(); ++j) |
|
8220 |
QCOMPARE(image.pixel(j, i), QColor(Qt::red).rgb()); |
|
8221 |
} |
|
8222 |
||
8223 |
}; |
|
8224 |
||
8225 |
// Test to make sure we're compatible in the particular case where QPainter::setRedirected |
|
8226 |
// actually works. It has been broken for all other cases since Qt 4.1.4 (backing store). |
|
8227 |
// QWidget::render is the modern and more powerful way of doing the same. |
|
8228 |
void tst_QWidget::painterRedirection() |
|
8229 |
{ |
|
8230 |
RedirectedWidget widget; |
|
8231 |
// Set FramelessWindowHint and mask to trigger internal painter redirection on the Mac. |
|
8232 |
widget.setWindowFlags(widget.windowFlags() | Qt::FramelessWindowHint); |
|
8233 |
widget.setMask(QRect(10, 10, 50, 50)); |
|
8234 |
widget.setFixedSize(100, 200); |
|
8235 |
widget.show(); |
|
8236 |
#ifdef Q_WS_X11 |
|
8237 |
qt_x11_wait_for_window_manager(&widget); |
|
8238 |
#endif |
|
8239 |
QPixmap pixmap(widget.size()); |
|
8240 |
QPainter::setRedirected(&widget, &pixmap, QPoint()); |
|
8241 |
widget.repaint(); |
|
8242 |
QCOMPARE(QPainter::redirected(&widget), static_cast<QPaintDevice *>(&pixmap)); |
|
8243 |
} |
|
8244 |
||
8245 |
||
8246 |
void tst_QWidget::doubleRepaint() |
|
8247 |
{ |
|
8248 |
#ifdef Q_OS_IRIX |
|
8249 |
QSKIP("4DWM issues on IRIX makes this test fail", SkipAll); |
|
8250 |
#elif defined(Q_WS_MAC) |
|
8251 |
if (!macHasAccessToWindowsServer()) |
|
8252 |
QSKIP("Not having window server access causes the wrong number of repaints to be issues", SkipAll); |
|
8253 |
#endif |
|
8254 |
UpdateWidget widget; |
|
8255 |
widget.setFocusPolicy(Qt::StrongFocus); |
|
8256 |
// Filter out activation change and focus events to avoid update() calls in QWidget. |
|
8257 |
widget.updateOnActivationChangeAndFocusIn = false; |
|
8258 |
||
8259 |
// Show: 1 repaint |
|
8260 |
int expectedRepaints = 1; |
|
8261 |
widget.show(); |
|
8262 |
QTest::qWaitForWindowShown(&widget); |
|
8263 |
QTest::qWait(10); |
|
8264 |
QTRY_COMPARE(widget.numPaintEvents, expectedRepaints); |
|
8265 |
widget.numPaintEvents = 0; |
|
8266 |
||
8267 |
// Minmize: Should not trigger a repaint. |
|
8268 |
widget.showMinimized(); |
|
8269 |
QTest::qWait(10); |
|
8270 |
QCOMPARE(widget.numPaintEvents, 0); |
|
8271 |
widget.numPaintEvents = 0; |
|
8272 |
||
8273 |
// Restore: Should not trigger a repaint. |
|
8274 |
widget.showNormal(); |
|
8275 |
QTest::qWaitForWindowShown(&widget); |
|
8276 |
QTest::qWait(10); |
|
8277 |
QCOMPARE(widget.numPaintEvents, 0); |
|
8278 |
} |
|
8279 |
||
8280 |
#ifndef Q_WS_MAC |
|
8281 |
// This test only makes sense on the Mac when passing -graphicssystem. |
|
8282 |
void tst_QWidget::resizeInPaintEvent() |
|
8283 |
{ |
|
8284 |
QWidget window; |
|
8285 |
UpdateWidget widget(&window); |
|
8286 |
window.show(); |
|
8287 |
QTest::qWaitForWindowShown(&window); |
|
8288 |
QTRY_VERIFY(widget.numPaintEvents > 0); |
|
8289 |
||
8290 |
widget.reset(); |
|
8291 |
QCOMPARE(widget.numPaintEvents, 0); |
|
8292 |
||
8293 |
widget.resizeInPaintEvent = true; |
|
8294 |
// This will call resize in the paintEvent, which in turn will call |
|
8295 |
// invalidateBuffer() and a new update request should be posted. |
|
8296 |
widget.repaint(); |
|
8297 |
QCOMPARE(widget.numPaintEvents, 1); |
|
8298 |
widget.numPaintEvents = 0; |
|
8299 |
||
8300 |
QTest::qWait(10); |
|
8301 |
// Make sure the resize triggers another update. |
|
8302 |
QTRY_COMPARE(widget.numPaintEvents, 1); |
|
8303 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8304 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8305 |
void tst_QWidget::opaqueChildren() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8306 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8307 |
QWidget widget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8308 |
widget.resize(200, 200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8309 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8310 |
QWidget child(&widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8311 |
child.setGeometry(-700, -700, 200, 200); |
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 |
QWidget grandChild(&child); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8314 |
grandChild.resize(200, 200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8315 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8316 |
QWidget greatGrandChild(&grandChild); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8317 |
greatGrandChild.setGeometry(50, 50, 200, 200); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8318 |
greatGrandChild.setPalette(Qt::red); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8319 |
greatGrandChild.setAutoFillBackground(true); // Opaque child widget. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8320 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8321 |
widget.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8322 |
#ifdef Q_WS_X11 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8323 |
qt_x11_wait_for_window_manager(&widget); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8324 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8325 |
QTest::qWait(100); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8326 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8327 |
// 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
|
8328 |
QRegion expectedOpaqueRegion(50, 50, 150, 150); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8329 |
QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), expectedOpaqueRegion); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8330 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8331 |
// 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
|
8332 |
child.setGeometry(50, 50, 150, 150); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8333 |
QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), expectedOpaqueRegion); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8334 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8335 |
// Set mask on greatGrandChild. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8336 |
const QRegion mask(10, 10, 50, 50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8337 |
greatGrandChild.setMask(mask); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8338 |
expectedOpaqueRegion &= mask.translated(50, 50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8339 |
QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), expectedOpaqueRegion); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8340 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8341 |
// Make greatGrandChild "transparent". |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8342 |
greatGrandChild.setAutoFillBackground(false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8343 |
QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), QRegion()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
8344 |
} |
0 | 8345 |
#endif |
8346 |
||
8347 |
||
8348 |
class MaskSetWidget : public QWidget |
|
8349 |
{ |
|
8350 |
Q_OBJECT |
|
8351 |
public: |
|
8352 |
MaskSetWidget(QWidget* p =0) |
|
8353 |
: QWidget(p) {} |
|
8354 |
||
8355 |
void paintEvent(QPaintEvent* event) { |
|
8356 |
QPainter p(this); |
|
8357 |
||
8358 |
paintedRegion += event->region(); |
|
8359 |
foreach(QRect r, event->region().rects()) |
|
8360 |
p.fillRect(r, Qt::red); |
|
8361 |
} |
|
8362 |
||
8363 |
void resizeEvent(QResizeEvent*) { |
|
8364 |
setMask(QRegion(QRect(0, 0, width(), 10).normalized())); |
|
8365 |
} |
|
8366 |
||
8367 |
QRegion paintedRegion; |
|
8368 |
||
8369 |
public slots: |
|
8370 |
void resizeDown() { |
|
8371 |
setGeometry(QRect(0, 50, 50, 50)); |
|
8372 |
} |
|
8373 |
||
8374 |
void resizeUp() { |
|
8375 |
setGeometry(QRect(0, 50, 150, 50)); |
|
8376 |
} |
|
8377 |
||
8378 |
}; |
|
8379 |
||
8380 |
void tst_QWidget::setMaskInResizeEvent() |
|
8381 |
{ |
|
8382 |
UpdateWidget w; |
|
8383 |
w.reset(); |
|
8384 |
w.resize(200, 200); |
|
8385 |
w.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); |
|
8386 |
w.raise(); |
|
8387 |
||
8388 |
MaskSetWidget testWidget(&w); |
|
8389 |
testWidget.setGeometry(0, 0, 100, 100); |
|
8390 |
testWidget.setMask(QRegion(QRect(0,0,100,10))); |
|
8391 |
testWidget.show(); |
|
8392 |
w.show(); |
|
8393 |
QTest::qWaitForWindowShown(&w); |
|
8394 |
QTest::qWait(30); |
|
8395 |
QTRY_VERIFY(w.numPaintEvents > 0); |
|
8396 |
||
8397 |
w.reset(); |
|
8398 |
testWidget.paintedRegion = QRegion(); |
|
8399 |
QTimer::singleShot(0, &testWidget, SLOT(resizeDown())); |
|
8400 |
QTest::qWait(100); |
|
8401 |
||
8402 |
QRegion expectedParentUpdate(0, 0, 100, 10); // Old testWidget area. |
|
8403 |
expectedParentUpdate += testWidget.geometry(); // New testWidget area. |
|
8404 |
QCOMPARE(w.paintedRegion, expectedParentUpdate); |
|
8405 |
QCOMPARE(testWidget.paintedRegion, testWidget.mask()); |
|
8406 |
||
8407 |
testWidget.paintedRegion = QRegion(); |
|
8408 |
// Now resize the widget again, but in the oposite direction |
|
8409 |
QTimer::singleShot(0, &testWidget, SLOT(resizeUp())); |
|
8410 |
QTest::qWait(100); |
|
8411 |
||
8412 |
QTRY_COMPARE(testWidget.paintedRegion, testWidget.mask()); |
|
8413 |
} |
|
8414 |
||
8415 |
class MoveInResizeWidget : public QWidget |
|
8416 |
{ |
|
8417 |
Q_OBJECT |
|
8418 |
public: |
|
8419 |
MoveInResizeWidget(QWidget* p = 0) |
|
8420 |
: QWidget(p) |
|
8421 |
{ |
|
8422 |
setWindowFlags(Qt::FramelessWindowHint); |
|
8423 |
} |
|
8424 |
||
8425 |
void resizeEvent(QResizeEvent*) { |
|
8426 |
||
8427 |
move(QPoint(100,100)); |
|
8428 |
||
8429 |
static bool firstTime = true; |
|
8430 |
if (firstTime) |
|
8431 |
QTimer::singleShot(250, this, SLOT(resizeMe())); |
|
8432 |
||
8433 |
firstTime = false; |
|
8434 |
} |
|
8435 |
||
8436 |
public slots: |
|
8437 |
void resizeMe() { |
|
8438 |
resize(100, 100); |
|
8439 |
} |
|
8440 |
}; |
|
8441 |
||
8442 |
void tst_QWidget::moveInResizeEvent() |
|
8443 |
{ |
|
8444 |
MoveInResizeWidget testWidget; |
|
8445 |
testWidget.setGeometry(50, 50, 200, 200); |
|
8446 |
testWidget.show(); |
|
8447 |
QTest::qWaitForWindowShown(&testWidget); |
|
8448 |
QTest::qWait(300); |
|
8449 |
||
8450 |
QRect expectedGeometry(100,100, 100, 100); |
|
8451 |
QTRY_COMPARE(testWidget.geometry(), expectedGeometry); |
|
8452 |
} |
|
8453 |
||
8454 |
||
8455 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) |
|
8456 |
void tst_QWidget::immediateRepaintAfterShow() |
|
8457 |
{ |
|
8458 |
UpdateWidget widget; |
|
8459 |
widget.show(); |
|
8460 |
qApp->processEvents(); |
|
8461 |
// On X11 in particular, we are now waiting for a MapNotify event before |
|
8462 |
// syncing the backing store. However, if someone request a repaint() |
|
8463 |
// we must repaint immediately regardless of the current state. |
|
8464 |
widget.numPaintEvents = 0; |
|
8465 |
widget.repaint(); |
|
8466 |
QCOMPARE(widget.numPaintEvents, 1); |
|
8467 |
} |
|
8468 |
||
8469 |
void tst_QWidget::immediateRepaintAfterInvalidateBuffer() |
|
8470 |
{ |
|
8471 |
QWidget *widget = new UpdateWidget; |
|
8472 |
widget->show(); |
|
8473 |
#ifdef Q_WS_X11 |
|
8474 |
qt_x11_wait_for_window_manager(widget); |
|
8475 |
#endif |
|
8476 |
QTest::qWait(200); |
|
8477 |
||
8478 |
static_cast<UpdateWidget *>(widget)->numPaintEvents = 0; |
|
8479 |
||
8480 |
// Marks the area covered by the widget as dirty in the backing store and |
|
8481 |
// posts an UpdateRequest event. |
|
8482 |
qt_widget_private(widget)->invalidateBuffer(widget->rect()); |
|
8483 |
QCOMPARE(static_cast<UpdateWidget *>(widget)->numPaintEvents, 0); |
|
8484 |
||
8485 |
// The entire widget is already dirty, but this time we want to update immediately |
|
8486 |
// by calling repaint(), and thus we have to repaint the widget and not wait for |
|
8487 |
// the UpdateRequest to be sent when we get back to the event loop. |
|
8488 |
widget->repaint(); |
|
8489 |
QCOMPARE(static_cast<UpdateWidget *>(widget)->numPaintEvents, 1); |
|
8490 |
||
8491 |
delete widget; |
|
8492 |
} |
|
8493 |
#endif |
|
8494 |
||
8495 |
void tst_QWidget::effectiveWinId() |
|
8496 |
{ |
|
8497 |
QWidget parent; |
|
8498 |
QWidget child(&parent); |
|
8499 |
||
8500 |
// Shouldn't crash. |
|
8501 |
QVERIFY(!parent.effectiveWinId()); |
|
8502 |
QVERIFY(!child.effectiveWinId()); |
|
8503 |
||
8504 |
parent.show(); |
|
8505 |
||
8506 |
QVERIFY(parent.effectiveWinId()); |
|
8507 |
QVERIFY(child.effectiveWinId()); |
|
8508 |
} |
|
8509 |
||
8510 |
class CustomWidget : public QWidget |
|
8511 |
{ |
|
8512 |
public: |
|
8513 |
mutable int metricCallCount; |
|
8514 |
||
8515 |
CustomWidget(QWidget *parent = 0) : QWidget(parent), metricCallCount(0) {} |
|
8516 |
||
8517 |
virtual int metric(PaintDeviceMetric metric) const { |
|
8518 |
++metricCallCount; |
|
8519 |
return QWidget::metric(metric); |
|
8520 |
} |
|
8521 |
}; |
|
8522 |
||
8523 |
void tst_QWidget::customDpi() |
|
8524 |
{ |
|
8525 |
QWidget *topLevel = new QWidget; |
|
8526 |
CustomWidget *custom = new CustomWidget(topLevel); |
|
8527 |
QWidget *child = new QWidget(custom); |
|
8528 |
||
8529 |
custom->metricCallCount = 0; |
|
8530 |
topLevel->logicalDpiX(); |
|
8531 |
QCOMPARE(custom->metricCallCount, 0); |
|
8532 |
custom->logicalDpiX(); |
|
8533 |
QCOMPARE(custom->metricCallCount, 1); |
|
8534 |
child->logicalDpiX(); |
|
8535 |
#ifdef Q_WS_S60 |
|
8536 |
// QWidget::metric is not recursive on Symbian |
|
8537 |
QCOMPARE(custom->metricCallCount, 1); |
|
8538 |
#else |
|
8539 |
QCOMPARE(custom->metricCallCount, 2); |
|
8540 |
#endif |
|
8541 |
||
8542 |
delete topLevel; |
|
8543 |
} |
|
8544 |
||
8545 |
void tst_QWidget::customDpiProperty() |
|
8546 |
{ |
|
8547 |
QWidget *topLevel = new QWidget; |
|
8548 |
QWidget *middle = new CustomWidget(topLevel); |
|
8549 |
QWidget *child = new QWidget(middle); |
|
8550 |
||
8551 |
const int initialDpiX = topLevel->logicalDpiX(); |
|
8552 |
const int initialDpiY = topLevel->logicalDpiY(); |
|
8553 |
||
8554 |
middle->setProperty("_q_customDpiX", 300); |
|
8555 |
middle->setProperty("_q_customDpiY", 400); |
|
8556 |
||
8557 |
QCOMPARE(topLevel->logicalDpiX(), initialDpiX); |
|
8558 |
QCOMPARE(topLevel->logicalDpiY(), initialDpiY); |
|
8559 |
||
8560 |
QCOMPARE(middle->logicalDpiX(), 300); |
|
8561 |
QCOMPARE(middle->logicalDpiY(), 400); |
|
8562 |
||
8563 |
QCOMPARE(child->logicalDpiX(), 300); |
|
8564 |
QCOMPARE(child->logicalDpiY(), 400); |
|
8565 |
||
8566 |
middle->setProperty("_q_customDpiX", QVariant()); |
|
8567 |
middle->setProperty("_q_customDpiY", QVariant()); |
|
8568 |
||
8569 |
QCOMPARE(topLevel->logicalDpiX(), initialDpiX); |
|
8570 |
QCOMPARE(topLevel->logicalDpiY(), initialDpiY); |
|
8571 |
||
8572 |
QCOMPARE(middle->logicalDpiX(), initialDpiX); |
|
8573 |
QCOMPARE(middle->logicalDpiY(), initialDpiY); |
|
8574 |
||
8575 |
QCOMPARE(child->logicalDpiX(), initialDpiX); |
|
8576 |
QCOMPARE(child->logicalDpiY(), initialDpiY); |
|
8577 |
||
8578 |
delete topLevel; |
|
8579 |
} |
|
8580 |
||
8581 |
void tst_QWidget::quitOnCloseAttribute() |
|
8582 |
{ |
|
8583 |
QWidget w; |
|
8584 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), true); |
|
8585 |
w.setAttribute(Qt::WA_QuitOnClose, false); |
|
8586 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), false); |
|
8587 |
||
8588 |
w.setAttribute(Qt::WA_QuitOnClose); |
|
8589 |
w.setWindowFlags(Qt::Tool); |
|
8590 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), false); |
|
8591 |
||
8592 |
w.setAttribute(Qt::WA_QuitOnClose); |
|
8593 |
w.setWindowFlags(Qt::Popup); |
|
8594 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), false); |
|
8595 |
||
8596 |
w.setAttribute(Qt::WA_QuitOnClose); |
|
8597 |
w.setWindowFlags(Qt::ToolTip); |
|
8598 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), false); |
|
8599 |
||
8600 |
w.setAttribute(Qt::WA_QuitOnClose); |
|
8601 |
w.setWindowFlags(Qt::SplashScreen); |
|
8602 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), false); |
|
8603 |
||
8604 |
w.setAttribute(Qt::WA_QuitOnClose); |
|
8605 |
w.setWindowFlags(Qt::SubWindow); |
|
8606 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), false); |
|
8607 |
||
8608 |
w.setAttribute(Qt::WA_QuitOnClose); |
|
8609 |
w.setWindowFlags(Qt::Dialog); |
|
8610 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), true); |
|
8611 |
w.show(); |
|
8612 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), true); |
|
8613 |
w.setWindowFlags(Qt::Tool); |
|
8614 |
QCOMPARE(w.testAttribute(Qt::WA_QuitOnClose), false); |
|
8615 |
} |
|
8616 |
||
8617 |
void tst_QWidget::moveRect() |
|
8618 |
{ |
|
8619 |
QWidget widget; |
|
8620 |
widget.setUpdatesEnabled(false); |
|
8621 |
QWidget child(&widget); |
|
8622 |
child.setUpdatesEnabled(false); |
|
8623 |
child.setAttribute(Qt::WA_OpaquePaintEvent); |
|
8624 |
widget.show(); |
|
8625 |
QTest::qWait(200); |
|
8626 |
child.move(10, 10); // Don't crash. |
|
8627 |
} |
|
8628 |
||
8629 |
#ifdef Q_WS_WIN |
|
8630 |
class GDIWidget : public QDialog |
|
8631 |
{ |
|
8632 |
public: |
|
8633 |
GDIWidget() { setAttribute(Qt::WA_PaintOnScreen); } |
|
8634 |
QPaintEngine *paintEngine() const { return 0; } |
|
8635 |
||
8636 |
||
8637 |
void paintEvent(QPaintEvent *) { |
|
8638 |
HDC hdc = getDC(); |
|
8639 |
SelectObject(hdc, CreateSolidBrush(RGB(255, 0, 0))); |
|
8640 |
Rectangle(hdc, 0, 0, 10, 10); |
|
8641 |
||
8642 |
releaseDC(hdc); |
|
8643 |
||
8644 |
QImage im = QPixmap::grabWindow(winId(), 0, 0, width(), height()).toImage(); |
|
8645 |
color = im.pixel(1, 1); |
|
8646 |
||
8647 |
accept(); |
|
8648 |
} |
|
8649 |
||
8650 |
QSize sizeHint() const { |
|
8651 |
return QSize(400, 300); |
|
8652 |
} |
|
8653 |
||
8654 |
QColor color; |
|
8655 |
}; |
|
8656 |
||
8657 |
void tst_QWidget::gdiPainting() |
|
8658 |
{ |
|
8659 |
GDIWidget w; |
|
8660 |
w.exec(); |
|
8661 |
||
8662 |
QCOMPARE(w.color, QColor(255, 0, 0)); |
|
8663 |
||
8664 |
} |
|
8665 |
||
8666 |
void tst_QWidget::paintOnScreenPossible() |
|
8667 |
{ |
|
8668 |
QWidget w1; |
|
8669 |
w1.setAttribute(Qt::WA_PaintOnScreen); |
|
8670 |
QVERIFY(!w1.testAttribute(Qt::WA_PaintOnScreen)); |
|
8671 |
||
8672 |
GDIWidget w2; |
|
8673 |
w2.setAttribute(Qt::WA_PaintOnScreen); |
|
8674 |
QVERIFY(w2.testAttribute(Qt::WA_PaintOnScreen)); |
|
8675 |
} |
|
8676 |
#endif |
|
8677 |
||
8678 |
void tst_QWidget::reparentStaticWidget() |
|
8679 |
{ |
|
8680 |
QWidget window1; |
|
8681 |
||
8682 |
QWidget *child = new QWidget(&window1); |
|
8683 |
child->setPalette(Qt::red); |
|
8684 |
child->setAutoFillBackground(true); |
|
8685 |
child->setAttribute(Qt::WA_StaticContents); |
|
8686 |
child->resize(100, 100); |
|
8687 |
||
8688 |
QWidget *grandChild = new QWidget(child); |
|
8689 |
grandChild->setPalette(Qt::blue); |
|
8690 |
grandChild->setAutoFillBackground(true); |
|
8691 |
grandChild->resize(50, 50); |
|
8692 |
grandChild->setAttribute(Qt::WA_StaticContents); |
|
8693 |
window1.show(); |
|
8694 |
QTest::qWaitForWindowShown(&window1); |
|
8695 |
||
8696 |
QWidget window2; |
|
8697 |
window2.show(); |
|
8698 |
QTest::qWaitForWindowShown(&window2); |
|
8699 |
QTest::qWait(20); |
|
8700 |
||
8701 |
// Reparent into another top-level. |
|
8702 |
child->setParent(&window2); |
|
8703 |
child->show(); |
|
8704 |
||
8705 |
// Please don't crash. |
|
8706 |
window1.resize(window1.size() + QSize(2, 2)); |
|
8707 |
QTest::qWait(20); |
|
8708 |
||
8709 |
// Make sure we move all static children even though |
|
8710 |
// the reparented widget itself is non-static. |
|
8711 |
child->setAttribute(Qt::WA_StaticContents, false); |
|
8712 |
child->setParent(&window1); |
|
8713 |
child->show(); |
|
8714 |
||
8715 |
// Please don't crash. |
|
8716 |
window2.resize(window2.size() + QSize(2, 2)); |
|
8717 |
QTest::qWait(20); |
|
8718 |
||
8719 |
child->setParent(0); |
|
8720 |
child->show(); |
|
8721 |
QTest::qWait(20); |
|
8722 |
||
8723 |
// Please don't crash. |
|
8724 |
child->resize(child->size() + QSize(2, 2)); |
|
8725 |
window2.resize(window2.size() + QSize(2, 2)); |
|
8726 |
QTest::qWait(20); |
|
8727 |
||
8728 |
QWidget *siblingOfGrandChild = new QWidget(child); |
|
8729 |
siblingOfGrandChild->show(); |
|
8730 |
QTest::qWait(20); |
|
8731 |
||
8732 |
// Nothing should happen when reparenting within the same top-level. |
|
8733 |
grandChild->setParent(siblingOfGrandChild); |
|
8734 |
grandChild->show(); |
|
8735 |
QTest::qWait(20); |
|
8736 |
||
8737 |
QWidget paintOnScreen; |
|
8738 |
paintOnScreen.setAttribute(Qt::WA_PaintOnScreen); |
|
8739 |
paintOnScreen.show(); |
|
8740 |
QTest::qWaitForWindowShown(&paintOnScreen); |
|
8741 |
QTest::qWait(20); |
|
8742 |
||
8743 |
child->setParent(&paintOnScreen); |
|
8744 |
child->show(); |
|
8745 |
QTest::qWait(20); |
|
8746 |
||
8747 |
// Please don't crash. |
|
8748 |
paintOnScreen.resize(paintOnScreen.size() + QSize(2, 2)); |
|
8749 |
QTest::qWait(20); |
|
4
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 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8752 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8753 |
void tst_QWidget::QTBUG6883_reparentStaticWidget2() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8754 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8755 |
QMainWindow mw; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8756 |
QDockWidget *one = new QDockWidget("one", &mw); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8757 |
mw.addDockWidget(Qt::LeftDockWidgetArea, one , Qt::Vertical); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8758 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8759 |
QWidget *child = new QWidget(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8760 |
child->setPalette(Qt::red); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8761 |
child->setAutoFillBackground(true); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8762 |
child->setAttribute(Qt::WA_StaticContents); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8763 |
child->resize(100, 100); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8764 |
one->setWidget(child); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8765 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8766 |
QToolBar *mainTools = mw.addToolBar("Main Tools"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8767 |
mainTools->addWidget(new QLineEdit); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8768 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8769 |
mw.show(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8770 |
QTest::qWaitForWindowShown(&mw); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8771 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8772 |
one->setFloating(true); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8773 |
QTest::qWait(20); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
8774 |
//do not crash |
0 | 8775 |
} |
8776 |
||
8777 |
#ifdef Q_WS_QWS |
|
8778 |
void tst_QWidget::updateOutsideSurfaceClip() |
|
8779 |
{ |
|
8780 |
UpdateWidget widget; |
|
8781 |
widget.setWindowFlags(Qt::FramelessWindowHint); |
|
8782 |
widget.resize(100, 100); |
|
8783 |
widget.raise(); |
|
8784 |
widget.show(); |
|
8785 |
QTest::qWait(200); |
|
8786 |
widget.reset(); |
|
8787 |
||
8788 |
// Move widget partially outside buffer and change the surface clip. |
|
8789 |
widget.move(-50, 0); |
|
8790 |
QTest::qWait(100); |
|
8791 |
||
8792 |
// Update region is outside the surface clip and should not trigger a repaint. |
|
8793 |
widget.update(0, 0, 20, 20); |
|
8794 |
QTest::qWait(100); |
|
8795 |
QCOMPARE(widget.numPaintEvents, 0); |
|
8796 |
||
8797 |
// Now, move the widget back so that the update region is inside the clip |
|
8798 |
// and make sure we get a repaint of the dirty area. |
|
8799 |
widget.move(0, 0); |
|
8800 |
QTest::qWait(100); |
|
8801 |
QCOMPARE(widget.numPaintEvents, 1); |
|
8802 |
QCOMPARE(widget.paintedRegion, QRegion(0, 0, 20, 20)); |
|
8803 |
} |
|
8804 |
#endif |
|
8805 |
class ColorRedWidget : public QWidget |
|
8806 |
{ |
|
8807 |
public: |
|
8808 |
ColorRedWidget(QWidget *parent = 0) |
|
8809 |
: QWidget(parent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::ToolTip) |
|
8810 |
{ |
|
8811 |
} |
|
8812 |
||
8813 |
void paintEvent(QPaintEvent *) { |
|
8814 |
QPainter p(this); |
|
8815 |
p.fillRect(rect(),Qt::red); |
|
8816 |
} |
|
8817 |
}; |
|
8818 |
||
8819 |
void tst_QWidget::translucentWidget() |
|
8820 |
{ |
|
8821 |
QPixmap pm(16,16); |
|
8822 |
pm.fill(Qt::red); |
|
8823 |
ColorRedWidget label; |
|
8824 |
label.setFixedSize(16,16); |
|
8825 |
label.setAttribute(Qt::WA_TranslucentBackground); |
|
8826 |
label.move(qApp->desktop()->availableGeometry().topLeft()); |
|
8827 |
label.show(); |
|
8828 |
#ifdef Q_WS_X11 |
|
8829 |
qt_x11_wait_for_window_manager(&label); |
|
8830 |
#endif |
|
8831 |
QTest::qWait(200); |
|
8832 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
8833 |
QPixmap widgetSnapshot; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
8834 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
8835 |
#ifdef Q_WS_WIN |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
8836 |
QWidget *desktopWidget = QApplication::desktop()->screen(0); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
8837 |
if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
8838 |
widgetSnapshot = QPixmap::grabWindow(desktopWidget->winId(), 0,0, label.width(), label.height()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
8839 |
else |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
8840 |
#endif |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
8841 |
widgetSnapshot = QPixmap::grabWindow(label.winId()); |
0 | 8842 |
QImage actual = widgetSnapshot.toImage().convertToFormat(QImage::Format_RGB32); |
8843 |
QImage expected = pm.toImage().convertToFormat(QImage::Format_RGB32); |
|
8844 |
QCOMPARE(actual.size(),expected.size()); |
|
8845 |
QCOMPARE(actual,expected); |
|
8846 |
} |
|
8847 |
||
8848 |
class MaskResizeTestWidget : public QWidget |
|
8849 |
{ |
|
8850 |
Q_OBJECT |
|
8851 |
public: |
|
8852 |
MaskResizeTestWidget(QWidget* p =0) |
|
8853 |
: QWidget(p) { |
|
8854 |
setMask(QRegion(QRect(0, 0, 100, 100).normalized())); |
|
8855 |
} |
|
8856 |
||
8857 |
void paintEvent(QPaintEvent* event) { |
|
8858 |
QPainter p(this); |
|
8859 |
||
8860 |
paintedRegion += event->region(); |
|
8861 |
foreach(QRect r, event->region().rects()) |
|
8862 |
p.fillRect(r, Qt::red); |
|
8863 |
} |
|
8864 |
||
8865 |
QRegion paintedRegion; |
|
8866 |
||
8867 |
public slots: |
|
8868 |
void enlargeMask() { |
|
8869 |
QRegion newMask(QRect(0, 0, 150, 150).normalized()); |
|
8870 |
setMask(newMask); |
|
8871 |
} |
|
8872 |
||
8873 |
void shrinkMask() { |
|
8874 |
QRegion newMask(QRect(0, 0, 50, 50).normalized()); |
|
8875 |
setMask(newMask); |
|
8876 |
} |
|
8877 |
||
8878 |
}; |
|
8879 |
||
8880 |
void tst_QWidget::setClearAndResizeMask() |
|
8881 |
{ |
|
8882 |
UpdateWidget topLevel; |
|
8883 |
topLevel.resize(150, 150); |
|
8884 |
topLevel.show(); |
|
8885 |
QTest::qWaitForWindowShown(&topLevel); |
|
8886 |
QTRY_VERIFY(topLevel.numPaintEvents > 0); |
|
8887 |
topLevel.reset(); |
|
8888 |
||
8889 |
// Mask top-level widget |
|
8890 |
const QRegion topLevelMask(0, 0, 100, 100, QRegion::Ellipse); |
|
8891 |
topLevel.setMask(topLevelMask); |
|
8892 |
QCOMPARE(topLevel.mask(), topLevelMask); |
|
8893 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) // We don't control what's happening on other platforms. |
|
8894 |
// and ensure that the top-level doesn't get any update. |
|
8895 |
QCOMPARE(topLevel.numPaintEvents, 0); |
|
8896 |
#endif |
|
8897 |
||
8898 |
topLevel.reset(); |
|
8899 |
||
8900 |
// Clear top-level mask |
|
8901 |
topLevel.clearMask(); |
|
8902 |
QCOMPARE(topLevel.mask(), QRegion()); |
|
8903 |
QTest::qWait(10); |
|
8904 |
QRegion outsideOldMask(topLevel.rect()); |
|
8905 |
outsideOldMask -= topLevelMask; |
|
8906 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) // We don't control what's happening on other platforms. |
|
8907 |
// and ensure that the top-level gets an update for the area outside the old mask. |
|
8908 |
QTRY_VERIFY(topLevel.numPaintEvents > 0); |
|
8909 |
QTRY_COMPARE(topLevel.paintedRegion, outsideOldMask); |
|
8910 |
#endif |
|
8911 |
||
8912 |
UpdateWidget child(&topLevel); |
|
8913 |
child.setAutoFillBackground(true); // NB! Opaque child. |
|
8914 |
child.resize(100, 100); |
|
8915 |
child.show(); |
|
8916 |
QTest::qWait(10); |
|
8917 |
||
8918 |
child.reset(); |
|
8919 |
topLevel.reset(); |
|
8920 |
||
8921 |
// Mask child widget with a mask that is smaller than the rect |
|
8922 |
const QRegion childMask(0, 0, 50, 50); |
|
8923 |
child.setMask(childMask); |
|
8924 |
QTRY_COMPARE(child.mask(), childMask); |
|
8925 |
QTest::qWait(50); |
|
8926 |
// and ensure that the child widget doesn't get any update. |
|
8927 |
#ifdef Q_WS_MAC |
|
8928 |
// Mac always issues a full update when calling setMask, and we cannot force it to not do so. |
|
8929 |
QCOMPARE(child.numPaintEvents, 1); |
|
8930 |
#else |
|
8931 |
QCOMPARE(child.numPaintEvents, 0); |
|
8932 |
#endif |
|
8933 |
// and the parent widget gets an update for the newly exposed area. |
|
8934 |
QTRY_COMPARE(topLevel.numPaintEvents, 1); |
|
8935 |
QRegion expectedParentExpose(child.rect()); |
|
8936 |
expectedParentExpose -= childMask; |
|
8937 |
QCOMPARE(topLevel.paintedRegion, expectedParentExpose); |
|
8938 |
||
8939 |
child.reset(); |
|
8940 |
topLevel.reset(); |
|
8941 |
||
8942 |
// Clear child widget mask |
|
8943 |
child.clearMask(); |
|
8944 |
QTRY_COMPARE(child.mask(), QRegion()); |
|
8945 |
QTest::qWait(10); |
|
8946 |
// and ensure that that the child widget gets an update for the area outside the old mask. |
|
8947 |
QTRY_COMPARE(child.numPaintEvents, 1); |
|
8948 |
outsideOldMask = child.rect(); |
|
8949 |
#ifndef Q_WS_MAC |
|
8950 |
// Mac always issues a full update when calling setMask, and we cannot force it to not do so. |
|
8951 |
outsideOldMask -= childMask; |
|
8952 |
#endif |
|
8953 |
QCOMPARE(child.paintedRegion, outsideOldMask); |
|
8954 |
// and the parent widget doesn't get any update. |
|
8955 |
QCOMPARE(topLevel.numPaintEvents, 0); |
|
8956 |
||
8957 |
child.reset(); |
|
8958 |
topLevel.reset(); |
|
8959 |
||
8960 |
// Mask child widget with a mask that is bigger than the rect |
|
8961 |
child.setMask(QRegion(0, 0, 1000, 1000)); |
|
8962 |
QTest::qWait(100); |
|
8963 |
#ifdef Q_WS_MAC |
|
8964 |
// Mac always issues a full update when calling setMask, and we cannot force it to not do so. |
|
8965 |
QTRY_COMPARE(child.numPaintEvents, 1); |
|
8966 |
#else |
|
8967 |
// and ensure that we don't get any updates at all. |
|
8968 |
QTRY_COMPARE(child.numPaintEvents, 0); |
|
8969 |
#endif |
|
8970 |
QCOMPARE(topLevel.numPaintEvents, 0); |
|
8971 |
||
8972 |
// ...and the same applies when clearing the mask. |
|
8973 |
child.clearMask(); |
|
8974 |
QTest::qWait(100); |
|
8975 |
#ifdef Q_WS_MAC |
|
8976 |
// Mac always issues a full update when calling setMask, and we cannot force it to not do so. |
|
8977 |
QTRY_VERIFY(child.numPaintEvents > 0); |
|
8978 |
#else |
|
8979 |
QCOMPARE(child.numPaintEvents, 0); |
|
8980 |
#endif |
|
8981 |
QCOMPARE(topLevel.numPaintEvents, 0); |
|
8982 |
||
8983 |
QWidget resizeParent; |
|
8984 |
MaskResizeTestWidget resizeChild(&resizeParent); |
|
8985 |
||
8986 |
resizeParent.resize(300,300); |
|
8987 |
resizeParent.raise(); |
|
8988 |
resizeParent.setWindowFlags(Qt::WindowStaysOnTopHint); |
|
8989 |
resizeChild.setGeometry(50,50,200,200); |
|
8990 |
QPalette pal = resizeParent.palette(); |
|
8991 |
pal.setColor(QPalette::Window, QColor(Qt::white)); |
|
8992 |
resizeParent.setPalette(pal); |
|
8993 |
||
8994 |
resizeParent.show(); |
|
8995 |
QTest::qWaitForWindowShown(&resizeParent); |
|
8996 |
// Disable the size grip on the Mac; otherwise it'll be included when grabbing the window. |
|
8997 |
resizeParent.setFixedSize(resizeParent.size()); |
|
8998 |
resizeChild.show(); |
|
8999 |
QTest::qWait(100); |
|
9000 |
resizeChild.paintedRegion = QRegion(); |
|
9001 |
||
9002 |
QTimer::singleShot(100, &resizeChild, SLOT(shrinkMask())); |
|
9003 |
QTest::qWait(200); |
|
9004 |
#ifdef Q_WS_MAC |
|
9005 |
// Mac always issues a full update when calling setMask, and we cannot force it to not do so. |
|
9006 |
QTRY_COMPARE(resizeChild.paintedRegion, resizeChild.mask()); |
|
9007 |
#else |
|
9008 |
QTRY_COMPARE(resizeChild.paintedRegion, QRegion()); |
|
9009 |
#endif |
|
9010 |
||
9011 |
resizeChild.paintedRegion = QRegion(); |
|
9012 |
const QRegion oldMask = resizeChild.mask(); |
|
9013 |
QTimer::singleShot(0, &resizeChild, SLOT(enlargeMask())); |
|
9014 |
QTest::qWait(100); |
|
9015 |
#ifdef Q_WS_MAC |
|
9016 |
// Mac always issues a full update when calling setMask, and we cannot force it to not do so. |
|
9017 |
QTRY_COMPARE(resizeChild.paintedRegion, resizeChild.mask()); |
|
9018 |
#else |
|
9019 |
QTRY_COMPARE(resizeChild.paintedRegion, resizeChild.mask() - oldMask); |
|
9020 |
#endif |
|
9021 |
} |
|
9022 |
||
9023 |
void tst_QWidget::maskedUpdate() |
|
9024 |
{ |
|
9025 |
UpdateWidget topLevel; |
|
9026 |
topLevel.resize(200, 200); |
|
9027 |
const QRegion topLevelMask(50, 50, 70, 70); |
|
9028 |
topLevel.setMask(topLevelMask); |
|
9029 |
||
9030 |
UpdateWidget child(&topLevel); |
|
9031 |
child.setGeometry(20, 20, 180, 180); |
|
9032 |
const QRegion childMask(60, 60, 30, 30); |
|
9033 |
child.setMask(childMask); |
|
9034 |
||
9035 |
UpdateWidget grandChild(&child); |
|
9036 |
grandChild.setGeometry(50, 50, 100, 100); |
|
9037 |
const QRegion grandChildMask(20, 20, 10, 10); |
|
9038 |
grandChild.setMask(grandChildMask); |
|
9039 |
||
9040 |
topLevel.show(); |
|
9041 |
QTest::qWaitForWindowShown(&topLevel); |
|
9042 |
QTRY_VERIFY(topLevel.numPaintEvents > 0); |
|
9043 |
||
9044 |
||
9045 |
#define RESET_WIDGETS \ |
|
9046 |
topLevel.reset(); \ |
|
9047 |
child.reset(); \ |
|
9048 |
grandChild.reset(); |
|
9049 |
||
9050 |
#define CLEAR_MASK(widget) \ |
|
9051 |
widget.clearMask(); \ |
|
9052 |
QTest::qWait(100); \ |
|
9053 |
RESET_WIDGETS; |
|
9054 |
||
9055 |
// All widgets are transparent at this point, so any call to update() will result |
|
9056 |
// in composition, i.e. the update propagates to ancestors and children. |
|
9057 |
||
9058 |
// TopLevel update. |
|
9059 |
RESET_WIDGETS; |
|
9060 |
topLevel.update(); |
|
9061 |
QTest::qWait(10); |
|
9062 |
||
9063 |
QTRY_COMPARE(topLevel.paintedRegion, topLevelMask); |
|
9064 |
QTRY_COMPARE(child.paintedRegion, childMask); |
|
9065 |
QTRY_COMPARE(grandChild.paintedRegion, grandChildMask); |
|
9066 |
||
9067 |
// Child update. |
|
9068 |
RESET_WIDGETS; |
|
9069 |
child.update(); |
|
9070 |
QTest::qWait(10); |
|
9071 |
||
9072 |
QTRY_COMPARE(topLevel.paintedRegion, childMask.translated(child.pos())); |
|
9073 |
QTRY_COMPARE(child.paintedRegion, childMask); |
|
9074 |
QTRY_COMPARE(grandChild.paintedRegion, grandChildMask); |
|
9075 |
||
9076 |
// GrandChild update. |
|
9077 |
RESET_WIDGETS; |
|
9078 |
grandChild.update(); |
|
9079 |
QTest::qWait(10); |
|
9080 |
||
9081 |
QTRY_COMPARE(topLevel.paintedRegion, grandChildMask.translated(grandChild.mapTo(&topLevel, QPoint()))); |
|
9082 |
QTRY_COMPARE(child.paintedRegion, grandChildMask.translated(grandChild.pos())); |
|
9083 |
QTRY_COMPARE(grandChild.paintedRegion, grandChildMask); |
|
9084 |
||
9085 |
topLevel.setAttribute(Qt::WA_OpaquePaintEvent); |
|
9086 |
child.setAttribute(Qt::WA_OpaquePaintEvent); |
|
9087 |
grandChild.setAttribute(Qt::WA_OpaquePaintEvent); |
|
9088 |
||
9089 |
// All widgets are now opaque, which means no composition, i.e. |
|
9090 |
// the update does not propate to ancestors and children. |
|
9091 |
||
9092 |
// TopLevel update. |
|
9093 |
RESET_WIDGETS; |
|
9094 |
topLevel.update(); |
|
9095 |
QTest::qWait(10); |
|
9096 |
||
9097 |
QRegion expectedTopLevelUpdate = topLevelMask; |
|
9098 |
expectedTopLevelUpdate -= childMask.translated(child.pos()); // Subtract opaque children. |
|
9099 |
QTRY_COMPARE(topLevel.paintedRegion, expectedTopLevelUpdate); |
|
9100 |
QTRY_COMPARE(child.paintedRegion, QRegion()); |
|
9101 |
QTRY_COMPARE(grandChild.paintedRegion, QRegion()); |
|
9102 |
||
9103 |
// Child update. |
|
9104 |
RESET_WIDGETS; |
|
9105 |
child.update(); |
|
9106 |
QTest::qWait(10); |
|
9107 |
||
9108 |
QTRY_COMPARE(topLevel.paintedRegion, QRegion()); |
|
9109 |
QRegion expectedChildUpdate = childMask; |
|
9110 |
expectedChildUpdate -= grandChildMask.translated(grandChild.pos()); // Subtract oapque children. |
|
9111 |
QTRY_COMPARE(child.paintedRegion, expectedChildUpdate); |
|
9112 |
QTRY_COMPARE(grandChild.paintedRegion, QRegion()); |
|
9113 |
||
9114 |
// GrandChild update. |
|
9115 |
RESET_WIDGETS; |
|
9116 |
grandChild.update(); |
|
9117 |
QTest::qWait(10); |
|
9118 |
||
9119 |
QTRY_COMPARE(topLevel.paintedRegion, QRegion()); |
|
9120 |
QTRY_COMPARE(child.paintedRegion, QRegion()); |
|
9121 |
QTRY_COMPARE(grandChild.paintedRegion, grandChildMask); |
|
9122 |
||
9123 |
// GrandChild update. |
|
9124 |
CLEAR_MASK(grandChild); |
|
9125 |
grandChild.update(); |
|
9126 |
QTest::qWait(10); |
|
9127 |
||
9128 |
QTRY_COMPARE(topLevel.paintedRegion, QRegion()); |
|
9129 |
QTRY_COMPARE(child.paintedRegion, QRegion()); |
|
9130 |
QRegion expectedGrandChildUpdate = grandChild.rect(); |
|
9131 |
// Clip with parent's mask. |
|
9132 |
expectedGrandChildUpdate &= childMask.translated(-grandChild.pos()); |
|
9133 |
QCOMPARE(grandChild.paintedRegion, expectedGrandChildUpdate); |
|
9134 |
||
9135 |
// GrandChild update. |
|
9136 |
CLEAR_MASK(child); |
|
9137 |
grandChild.update(); |
|
9138 |
QTest::qWait(10); |
|
9139 |
||
9140 |
QTRY_COMPARE(topLevel.paintedRegion, QRegion()); |
|
9141 |
QTRY_COMPARE(child.paintedRegion, QRegion()); |
|
9142 |
expectedGrandChildUpdate = grandChild.rect(); |
|
9143 |
// Clip with parent's mask. |
|
9144 |
expectedGrandChildUpdate &= topLevelMask.translated(-grandChild.mapTo(&topLevel, QPoint())); |
|
9145 |
QTRY_COMPARE(grandChild.paintedRegion, expectedGrandChildUpdate); |
|
9146 |
||
9147 |
// Child update. |
|
9148 |
RESET_WIDGETS; |
|
9149 |
child.update(); |
|
9150 |
QTest::qWait(10); |
|
9151 |
||
9152 |
QTRY_COMPARE(topLevel.paintedRegion, QRegion()); |
|
9153 |
expectedChildUpdate = child.rect(); |
|
9154 |
// Clip with parent's mask. |
|
9155 |
expectedChildUpdate &= topLevelMask.translated(-child.pos()); |
|
9156 |
expectedChildUpdate -= grandChild.geometry(); // Subtract opaque children. |
|
9157 |
QTRY_COMPARE(child.paintedRegion, expectedChildUpdate); |
|
9158 |
QTRY_COMPARE(grandChild.paintedRegion, QRegion()); |
|
9159 |
||
9160 |
// GrandChild update. |
|
9161 |
CLEAR_MASK(topLevel); |
|
9162 |
grandChild.update(); |
|
9163 |
QTest::qWait(10); |
|
9164 |
||
9165 |
QTRY_COMPARE(topLevel.paintedRegion, QRegion()); |
|
9166 |
QTRY_COMPARE(child.paintedRegion, QRegion()); |
|
9167 |
QTRY_COMPARE(grandChild.paintedRegion, QRegion(grandChild.rect())); // Full update. |
|
9168 |
} |
|
9169 |
||
9170 |
#if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_QWS) |
|
9171 |
void tst_QWidget::syntheticEnterLeave() |
|
9172 |
{ |
|
9173 |
class MyWidget : public QWidget |
|
9174 |
{ |
|
9175 |
public: |
|
9176 |
MyWidget(QWidget *parent = 0) : QWidget(parent), numEnterEvents(0), numLeaveEvents(0) {} |
|
9177 |
void enterEvent(QEvent *) { ++numEnterEvents; } |
|
9178 |
void leaveEvent(QEvent *) { ++numLeaveEvents; } |
|
9179 |
int numEnterEvents; |
|
9180 |
int numLeaveEvents; |
|
9181 |
}; |
|
9182 |
||
9183 |
QCursor::setPos(QPoint(0,0)); |
|
9184 |
||
9185 |
MyWidget window; |
|
9186 |
window.setWindowFlags(Qt::WindowStaysOnTopHint); |
|
9187 |
window.resize(200, 200); |
|
9188 |
||
9189 |
MyWidget *child1 = new MyWidget(&window); |
|
9190 |
child1->setPalette(Qt::blue); |
|
9191 |
child1->setAutoFillBackground(true); |
|
9192 |
child1->resize(200, 200); |
|
9193 |
child1->setCursor(Qt::OpenHandCursor); |
|
9194 |
||
9195 |
MyWidget *child2 = new MyWidget(&window); |
|
9196 |
child2->resize(200, 200); |
|
9197 |
||
9198 |
MyWidget *grandChild = new MyWidget(child2); |
|
9199 |
grandChild->setPalette(Qt::red); |
|
9200 |
grandChild->setAutoFillBackground(true); |
|
9201 |
grandChild->resize(200, 200); |
|
9202 |
grandChild->setCursor(Qt::WaitCursor); |
|
9203 |
||
9204 |
window.show(); |
|
9205 |
window.raise(); |
|
9206 |
#ifdef Q_WS_X11 |
|
9207 |
qt_x11_wait_for_window_manager(&window); |
|
9208 |
#endif |
|
9209 |
QTest::qWait(300); |
|
9210 |
||
9211 |
#define RESET_EVENT_COUNTS \ |
|
9212 |
window.numEnterEvents = 0; \ |
|
9213 |
window.numLeaveEvents = 0; \ |
|
9214 |
child1->numEnterEvents = 0; \ |
|
9215 |
child1->numLeaveEvents = 0; \ |
|
9216 |
child2->numEnterEvents = 0; \ |
|
9217 |
child2->numLeaveEvents = 0; \ |
|
9218 |
grandChild->numEnterEvents = 0; \ |
|
9219 |
grandChild->numLeaveEvents = 0; |
|
9220 |
||
9221 |
// Position the cursor in the middle of the window. |
|
9222 |
const QPoint globalPos = window.mapToGlobal(QPoint(100, 100)); |
|
9223 |
QCursor::setPos(globalPos); // Enter child2 and grandChild. |
|
9224 |
QTest::qWait(300); |
|
9225 |
||
9226 |
#ifdef Q_OS_WINCE_WM |
|
9227 |
QSKIP("Windows Mobile has no proper cursor support", SkipAll); |
|
9228 |
#endif |
|
9229 |
||
9230 |
QCOMPARE(window.numLeaveEvents, 0); |
|
9231 |
QCOMPARE(child2->numLeaveEvents, 0); |
|
9232 |
QCOMPARE(grandChild->numLeaveEvents, 0); |
|
9233 |
QCOMPARE(child1->numLeaveEvents, 0); |
|
9234 |
||
9235 |
QCOMPARE(window.numEnterEvents, 1); |
|
9236 |
QCOMPARE(child2->numEnterEvents, 1); |
|
9237 |
QCOMPARE(grandChild->numEnterEvents, 1); |
|
9238 |
QCOMPARE(child1->numEnterEvents, 0); |
|
9239 |
||
9240 |
RESET_EVENT_COUNTS; |
|
9241 |
child2->hide(); // Leave child2 and grandChild, enter child1. |
|
9242 |
||
9243 |
QCOMPARE(window.numLeaveEvents, 0); |
|
9244 |
QCOMPARE(child2->numLeaveEvents, 1); |
|
9245 |
QCOMPARE(grandChild->numLeaveEvents, 1); |
|
9246 |
QCOMPARE(child1->numLeaveEvents, 0); |
|
9247 |
||
9248 |
QCOMPARE(window.numEnterEvents, 0); |
|
9249 |
QCOMPARE(child2->numEnterEvents, 0); |
|
9250 |
QCOMPARE(grandChild->numEnterEvents, 0); |
|
9251 |
QCOMPARE(child1->numEnterEvents, 1); |
|
9252 |
||
9253 |
RESET_EVENT_COUNTS; |
|
9254 |
child2->show(); // Leave child1, enter child2 and grandChild. |
|
9255 |
||
9256 |
QCOMPARE(window.numLeaveEvents, 0); |
|
9257 |
QCOMPARE(child2->numLeaveEvents, 0); |
|
9258 |
QCOMPARE(grandChild->numLeaveEvents, 0); |
|
9259 |
QCOMPARE(child1->numLeaveEvents, 1); |
|
9260 |
||
9261 |
QCOMPARE(window.numEnterEvents, 0); |
|
9262 |
QCOMPARE(child2->numEnterEvents, 1); |
|
9263 |
QCOMPARE(grandChild->numEnterEvents, 1); |
|
9264 |
QCOMPARE(child1->numEnterEvents, 0); |
|
9265 |
||
9266 |
RESET_EVENT_COUNTS; |
|
9267 |
delete child2; // Enter child1 (and do not send leave events to child2 and grandChild). |
|
9268 |
||
9269 |
QCOMPARE(window.numLeaveEvents, 0); |
|
9270 |
QCOMPARE(child1->numLeaveEvents, 0); |
|
9271 |
||
9272 |
QCOMPARE(window.numEnterEvents, 0); |
|
9273 |
QCOMPARE(child1->numEnterEvents, 1); |
|
9274 |
} |
|
9275 |
||
9276 |
void tst_QWidget::taskQTBUG_4055_sendSyntheticEnterLeave() |
|
9277 |
{ |
|
9278 |
#ifdef Q_OS_WINCE_WM |
|
9279 |
QSKIP("Windows Mobile has no proper cursor support", SkipAll); |
|
9280 |
#endif |
|
9281 |
class SELParent : public QWidget |
|
9282 |
{ |
|
9283 |
public: |
|
9284 |
SELParent(QWidget *parent = 0): QWidget(parent) { } |
|
9285 |
||
9286 |
void mousePressEvent(QMouseEvent *) { child->show(); } |
|
9287 |
QWidget *child; |
|
9288 |
}; |
|
9289 |
||
9290 |
class SELChild : public QWidget |
|
9291 |
{ |
|
9292 |
public: |
|
9293 |
SELChild(QWidget *parent = 0) : QWidget(parent), numEnterEvents(0), numMouseMoveEvents(0) {} |
|
9294 |
void enterEvent(QEvent *) { ++numEnterEvents; } |
|
9295 |
void mouseMoveEvent(QMouseEvent *event) |
|
9296 |
{ |
|
9297 |
QCOMPARE(event->button(), Qt::NoButton); |
|
9298 |
QCOMPARE(event->buttons(), Qt::MouseButtons(Qt::NoButton)); |
|
9299 |
++numMouseMoveEvents; |
|
9300 |
} |
|
9301 |
void reset() { numEnterEvents = numMouseMoveEvents = 0; } |
|
9302 |
int numEnterEvents, numMouseMoveEvents; |
|
9303 |
}; |
|
9304 |
||
9305 |
QCursor::setPos(QPoint(0,0)); |
|
9306 |
||
9307 |
SELParent parent; |
|
9308 |
parent.resize(200, 200); |
|
9309 |
SELChild child(&parent); |
|
9310 |
child.resize(200, 200); |
|
9311 |
parent.show(); |
|
9312 |
#ifdef Q_WS_X11 |
|
9313 |
qt_x11_wait_for_window_manager(&parent); |
|
9314 |
#endif |
|
9315 |
QTest::qWait(150); |
|
9316 |
||
9317 |
QCursor::setPos(child.mapToGlobal(QPoint(100, 100))); |
|
9318 |
// Make sure the cursor has entered the child. |
|
9319 |
QTRY_VERIFY(child.numEnterEvents > 0); |
|
9320 |
||
9321 |
child.hide(); |
|
9322 |
child.reset(); |
|
9323 |
child.show(); |
|
9324 |
||
9325 |
// Make sure the child gets enter event and no mouse move event. |
|
9326 |
QCOMPARE(child.numEnterEvents, 1); |
|
9327 |
QCOMPARE(child.numMouseMoveEvents, 0); |
|
9328 |
||
9329 |
child.hide(); |
|
9330 |
child.reset(); |
|
9331 |
child.setMouseTracking(true); |
|
9332 |
child.show(); |
|
9333 |
||
9334 |
// Make sure the child gets enter event and mouse move event. |
|
9335 |
// Note that we verify event->button() and event->buttons() |
|
9336 |
// in SELChild::mouseMoveEvent(). |
|
9337 |
QCOMPARE(child.numEnterEvents, 1); |
|
9338 |
QCOMPARE(child.numMouseMoveEvents, 1); |
|
9339 |
||
9340 |
// Sending synthetic enter/leave trough the parent's mousePressEvent handler. |
|
9341 |
parent.child = &child; |
|
9342 |
||
9343 |
child.hide(); |
|
9344 |
child.reset(); |
|
9345 |
QTest::mouseClick(&parent, Qt::LeftButton); |
|
9346 |
||
9347 |
// Make sure the child gets enter event and one mouse move event. |
|
9348 |
QCOMPARE(child.numEnterEvents, 1); |
|
9349 |
QCOMPARE(child.numMouseMoveEvents, 1); |
|
9350 |
||
9351 |
child.hide(); |
|
9352 |
child.reset(); |
|
9353 |
child.setMouseTracking(false); |
|
9354 |
QTest::mouseClick(&parent, Qt::LeftButton); |
|
9355 |
||
9356 |
// Make sure the child gets enter event and no mouse move event. |
|
9357 |
QCOMPARE(child.numEnterEvents, 1); |
|
9358 |
QCOMPARE(child.numMouseMoveEvents, 0); |
|
9359 |
} |
|
9360 |
#endif |
|
9361 |
||
9362 |
void tst_QWidget::windowFlags() |
|
9363 |
{ |
|
9364 |
QWidget w; |
|
9365 |
w.setWindowFlags(w.windowFlags() | Qt::FramelessWindowHint); |
|
9366 |
QVERIFY(w.windowFlags() & Qt::FramelessWindowHint); |
|
9367 |
} |
|
9368 |
||
9369 |
void tst_QWidget::initialPosForDontShowOnScreenWidgets() |
|
9370 |
{ |
|
9371 |
{ // Check default position. |
|
9372 |
const QPoint expectedPos(0, 0); |
|
9373 |
QWidget widget; |
|
9374 |
widget.setAttribute(Qt::WA_DontShowOnScreen); |
|
9375 |
widget.winId(); // Make sure create_sys is called. |
|
9376 |
QCOMPARE(widget.pos(), expectedPos); |
|
9377 |
QCOMPARE(widget.geometry().topLeft(), expectedPos); |
|
9378 |
} |
|
9379 |
||
9380 |
{ // Explicitly move to a position. |
|
9381 |
const QPoint expectedPos(100, 100); |
|
9382 |
QWidget widget; |
|
9383 |
widget.setAttribute(Qt::WA_DontShowOnScreen); |
|
9384 |
widget.move(expectedPos); |
|
9385 |
widget.winId(); // Make sure create_sys is called. |
|
9386 |
QCOMPARE(widget.pos(), expectedPos); |
|
9387 |
QCOMPARE(widget.geometry().topLeft(), expectedPos); |
|
9388 |
} |
|
9389 |
} |
|
9390 |
||
9391 |
#ifdef Q_WS_X11 |
|
9392 |
void tst_QWidget::paintOutsidePaintEvent() |
|
9393 |
{ |
|
9394 |
QWidget widget; |
|
9395 |
widget.resize(200, 200); |
|
9396 |
||
9397 |
QWidget child1(&widget); |
|
9398 |
child1.resize(100, 100); |
|
9399 |
child1.setPalette(Qt::red); |
|
9400 |
child1.setAutoFillBackground(true); |
|
9401 |
||
9402 |
QWidget child2(&widget); |
|
9403 |
child2.setGeometry(50, 50, 100, 100); |
|
9404 |
child2.setPalette(Qt::blue); |
|
9405 |
child2.setAutoFillBackground(true); |
|
9406 |
||
9407 |
widget.show(); |
|
9408 |
QTest::qWaitForWindowShown(&widget); |
|
9409 |
QTest::qWait(60); |
|
9410 |
||
9411 |
const QPixmap before = QPixmap::grabWindow(widget.winId()); |
|
9412 |
||
9413 |
// Child 1 should be clipped by child 2, so nothing should change. |
|
9414 |
child1.setAttribute(Qt::WA_PaintOutsidePaintEvent); |
|
9415 |
QPainter painter(&child1); |
|
9416 |
painter.fillRect(child1.rect(), Qt::red); |
|
9417 |
painter.end(); |
|
9418 |
XSync(QX11Info::display(), false); // Flush output buffer. |
|
9419 |
QTest::qWait(60); |
|
9420 |
||
9421 |
const QPixmap after = QPixmap::grabWindow(widget.winId()); |
|
9422 |
||
9423 |
QCOMPARE(before, after); |
|
9424 |
} |
|
9425 |
#endif |
|
9426 |
||
9427 |
class MyEvilObject : public QObject |
|
9428 |
{ |
|
9429 |
Q_OBJECT |
|
9430 |
public: |
|
9431 |
MyEvilObject(QWidget *widgetToCrash) : QObject(), widget(widgetToCrash) |
|
9432 |
{ |
|
9433 |
connect(widget, SIGNAL(destroyed(QObject *)), this, SLOT(beEvil(QObject *))); |
|
9434 |
delete widget; |
|
9435 |
} |
|
9436 |
QWidget *widget; |
|
9437 |
||
9438 |
private slots: |
|
9439 |
void beEvil(QObject *) { widget->update(0, 0, 150, 150); } |
|
9440 |
}; |
|
9441 |
||
9442 |
void tst_QWidget::updateOnDestroyedSignal() |
|
9443 |
{ |
|
9444 |
QWidget widget; |
|
9445 |
||
9446 |
QWidget *child = new QWidget(&widget); |
|
9447 |
child->resize(100, 100); |
|
9448 |
child->setAutoFillBackground(true); |
|
9449 |
child->setPalette(Qt::red); |
|
9450 |
||
9451 |
widget.show(); |
|
9452 |
#ifdef Q_WS_X11 |
|
9453 |
qt_x11_wait_for_window_manager(&widget); |
|
9454 |
#endif |
|
9455 |
QTest::qWait(200); |
|
9456 |
||
9457 |
// Please do not crash. |
|
9458 |
MyEvilObject evil(child); |
|
9459 |
QTest::qWait(200); |
|
9460 |
} |
|
9461 |
||
9462 |
void tst_QWidget::toplevelLineEditFocus() |
|
9463 |
{ |
|
9464 |
testWidget->hide(); |
|
9465 |
||
9466 |
QLineEdit w; |
|
9467 |
w.show(); |
|
9468 |
QTest::qWaitForWindowShown(&w); |
|
9469 |
QTest::qWait(20); |
|
9470 |
||
9471 |
QTRY_COMPARE(QApplication::activeWindow(), (QWidget*)&w); |
|
9472 |
QTRY_COMPARE(QApplication::focusWidget(), (QWidget*)&w); |
|
9473 |
} |
|
9474 |
||
9475 |
void tst_QWidget::focusWidget_task254563() |
|
9476 |
{ |
|
9477 |
//having different visibility for widget is important |
|
9478 |
QWidget top; |
|
9479 |
top.show(); |
|
9480 |
QWidget container(&top); |
|
9481 |
QWidget *widget = new QWidget(&container); |
|
9482 |
widget->show(); |
|
9483 |
||
9484 |
widget->setFocus(); //set focus (will set the focus widget up to the toplevel to be 'widget') |
|
9485 |
container.setFocus(); |
|
9486 |
delete widget; // will call clearFocus but that doesn't help |
|
9487 |
QVERIFY(top.focusWidget() != widget); //dangling pointer |
|
9488 |
} |
|
9489 |
||
9490 |
void tst_QWidget::destroyBackingStore() |
|
9491 |
{ |
|
9492 |
#ifdef QT_BUILD_INTERNAL |
|
9493 |
UpdateWidget w; |
|
9494 |
w.reset(); |
|
9495 |
w.show(); |
|
9496 |
||
9497 |
QTest::qWaitForWindowShown(&w); |
|
9498 |
QApplication::processEvents(); |
|
9499 |
QTRY_VERIFY(w.numPaintEvents > 0); |
|
9500 |
w.reset(); |
|
9501 |
w.update(); |
|
9502 |
delete qt_widget_private(&w)->topData()->backingStore; |
|
9503 |
qt_widget_private(&w)->topData()->backingStore = 0; |
|
9504 |
qt_widget_private(&w)->topData()->backingStore = new QWidgetBackingStore(&w); |
|
9505 |
||
9506 |
w.update(); |
|
9507 |
QApplication::processEvents(); |
|
9508 |
#ifdef Q_WS_QWS |
|
9509 |
QApplication::processEvents(); |
|
9510 |
#endif |
|
9511 |
QCOMPARE(w.numPaintEvents, 1); |
|
9512 |
||
9513 |
// Check one more time, because the second time around does more caching. |
|
9514 |
w.update(); |
|
9515 |
QApplication::processEvents(); |
|
9516 |
QCOMPARE(w.numPaintEvents, 2); |
|
9517 |
#endif |
|
9518 |
} |
|
9519 |
||
9520 |
void tst_QWidget::rectOutsideCoordinatesLimit_task144779() |
|
9521 |
{ |
|
9522 |
#ifdef Q_OS_WINCE_WM |
|
9523 |
QSKIP( "Tables of 5000 elements do not make sense on Windows Mobile.", SkipAll); |
|
9524 |
#endif |
|
9525 |
QApplication::setOverrideCursor(Qt::BlankCursor); //keep the cursor out of screen grabs |
|
9526 |
QWidget main(0,Qt::FramelessWindowHint); //don't get confused by the size of the window frame |
|
9527 |
QPalette palette; |
|
9528 |
palette.setColor(QPalette::Window, Qt::red); |
|
9529 |
main.setPalette(palette); |
|
9530 |
||
9531 |
QDesktopWidget desktop; |
|
9532 |
QRect desktopDimensions = desktop.availableGeometry(&main); |
|
9533 |
QSize mainSize(400, 400); |
|
9534 |
mainSize = mainSize.boundedTo(desktopDimensions.size()); |
|
9535 |
main.resize(mainSize); |
|
9536 |
||
9537 |
QWidget *offsetWidget = new QWidget(&main); |
|
9538 |
offsetWidget->setGeometry(0, -(15000 - mainSize.height()), mainSize.width(), 15000); |
|
9539 |
||
9540 |
// big widget is too big for the coordinates, it must be limited by wrect |
|
9541 |
// if wrect is not at the right position because of offsetWidget, bigwidget |
|
9542 |
// is not painted correctly |
|
9543 |
QWidget *bigWidget = new QWidget(offsetWidget); |
|
9544 |
bigWidget->setGeometry(0, 0, mainSize.width(), 50000); |
|
9545 |
palette.setColor(QPalette::Window, Qt::green); |
|
9546 |
bigWidget->setPalette(palette); |
|
9547 |
bigWidget->setAutoFillBackground(true); |
|
9548 |
||
9549 |
main.show(); |
|
9550 |
QTest::qWaitForWindowShown(&main); |
|
9551 |
||
9552 |
QPixmap correct(main.size()); |
|
9553 |
correct.fill(Qt::green); |
|
9554 |
||
9555 |
QTRY_COMPARE(QPixmap::grabWindow(main.winId()).toImage().convertToFormat(QImage::Format_RGB32), |
|
9556 |
correct.toImage().convertToFormat(QImage::Format_RGB32)); |
|
9557 |
QApplication::restoreOverrideCursor(); |
|
9558 |
} |
|
9559 |
||
9560 |
void tst_QWidget::inputFocus_task257832() |
|
9561 |
{ |
|
9562 |
QLineEdit *widget = new QLineEdit; |
|
9563 |
QInputContext *context = widget->inputContext(); |
|
9564 |
if (!context) |
|
9565 |
QSKIP("No input context", SkipSingle); |
|
9566 |
widget->setFocus(); |
|
9567 |
widget->winId(); // make sure, widget has been created |
|
9568 |
context->setFocusWidget(widget); |
|
9569 |
QCOMPARE(context->focusWidget(), static_cast<QWidget*>(widget)); |
|
9570 |
widget->setReadOnly(true); |
|
9571 |
QVERIFY(!context->focusWidget()); |
|
9572 |
delete widget; |
|
9573 |
} |
|
9574 |
||
9575 |
void tst_QWidget::setGraphicsEffect() |
|
9576 |
{ |
|
9577 |
// Check that we don't have any effect by default. |
|
9578 |
QWidget *widget = new QWidget; |
|
9579 |
QVERIFY(!widget->graphicsEffect()); |
|
9580 |
||
9581 |
// SetGet check. |
|
9582 |
QPointer<QGraphicsEffect> blurEffect = new QGraphicsBlurEffect; |
|
9583 |
widget->setGraphicsEffect(blurEffect); |
|
9584 |
QCOMPARE(widget->graphicsEffect(), static_cast<QGraphicsEffect *>(blurEffect)); |
|
9585 |
||
9586 |
// Ensure the existing effect is deleted when setting a new one. |
|
9587 |
QPointer<QGraphicsEffect> shadowEffect = new QGraphicsDropShadowEffect; |
|
9588 |
widget->setGraphicsEffect(shadowEffect); |
|
9589 |
QVERIFY(!blurEffect); |
|
9590 |
QCOMPARE(widget->graphicsEffect(), static_cast<QGraphicsEffect *>(shadowEffect)); |
|
9591 |
blurEffect = new QGraphicsBlurEffect; |
|
9592 |
||
9593 |
// Ensure the effect is uninstalled when setting it on a new target. |
|
9594 |
QWidget *anotherWidget = new QWidget; |
|
9595 |
anotherWidget->setGraphicsEffect(blurEffect); |
|
9596 |
widget->setGraphicsEffect(blurEffect); |
|
9597 |
QVERIFY(!anotherWidget->graphicsEffect()); |
|
9598 |
QVERIFY(!shadowEffect); |
|
9599 |
||
9600 |
// Ensure the existing effect is deleted when deleting the widget. |
|
9601 |
delete widget; |
|
9602 |
QVERIFY(!blurEffect); |
|
9603 |
delete anotherWidget; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9604 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9605 |
// 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
|
9606 |
widget = new QWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9607 |
blurEffect = new QGraphicsBlurEffect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9608 |
widget->setGraphicsEffect(blurEffect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9609 |
delete blurEffect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9610 |
QVERIFY(!widget->graphicsEffect()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9611 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9612 |
// 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
|
9613 |
blurEffect = new QGraphicsBlurEffect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9614 |
widget->setGraphicsEffect(blurEffect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9615 |
widget->setGraphicsEffect(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9616 |
QVERIFY(!widget->graphicsEffect()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9617 |
QVERIFY(!blurEffect); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9618 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9619 |
delete widget; |
0 | 9620 |
} |
9621 |
||
9622 |
void tst_QWidget::activateWindow() |
|
9623 |
{ |
|
9624 |
// Test case for task 260685 |
|
9625 |
||
9626 |
// Create first mainwindow and set it active |
|
9627 |
QMainWindow* mainwindow = new QMainWindow(); |
|
9628 |
QLabel* label = new QLabel(mainwindow); |
|
9629 |
mainwindow->setCentralWidget(label); |
|
9630 |
mainwindow->setVisible(true); |
|
9631 |
mainwindow->activateWindow(); |
|
9632 |
QTest::qWaitForWindowShown(mainwindow); |
|
9633 |
qApp->processEvents(); |
|
9634 |
||
9635 |
QTRY_VERIFY(mainwindow->isActiveWindow()); |
|
9636 |
||
9637 |
// Create second mainwindow and set it active |
|
9638 |
QMainWindow* mainwindow2 = new QMainWindow(); |
|
9639 |
QLabel* label2 = new QLabel(mainwindow2); |
|
9640 |
mainwindow2->setCentralWidget(label2); |
|
9641 |
mainwindow2->setVisible(true); |
|
9642 |
mainwindow2->activateWindow(); |
|
9643 |
qApp->processEvents(); |
|
9644 |
||
9645 |
QTRY_VERIFY(!mainwindow->isActiveWindow()); |
|
9646 |
QTRY_VERIFY(mainwindow2->isActiveWindow()); |
|
9647 |
||
9648 |
// Revert first mainwindow back to visible active |
|
9649 |
mainwindow->setVisible(true); |
|
9650 |
mainwindow->activateWindow(); |
|
9651 |
qApp->processEvents(); |
|
9652 |
||
9653 |
QTRY_VERIFY(mainwindow->isActiveWindow()); |
|
9654 |
QTRY_VERIFY(!mainwindow2->isActiveWindow()); |
|
9655 |
} |
|
9656 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9657 |
void tst_QWidget::openModal_taskQTBUG_5804() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9658 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9659 |
class Widget : public QWidget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9660 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9661 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9662 |
Widget(QWidget *parent) : QWidget(parent) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9663 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9664 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9665 |
~Widget() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9666 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9667 |
QMessageBox msgbox; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9668 |
QTimer::singleShot(10, &msgbox, SLOT(accept())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9669 |
msgbox.exec(); //open a modal dialog |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9670 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9671 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9672 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9673 |
QWidget *win = new QWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9674 |
new Widget(win); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9675 |
win->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9676 |
QTest::qWaitForWindowShown(win); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9677 |
delete win; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9678 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9679 |
|
0 | 9680 |
#ifdef Q_OS_SYMBIAN |
9681 |
void tst_QWidget::cbaVisibility() |
|
9682 |
{ |
|
9683 |
// Test case for task 261048 |
|
9684 |
||
9685 |
// Create first mainwindow in fullsreen and activate it |
|
9686 |
QMainWindow* mainwindow = new QMainWindow(); |
|
9687 |
QLabel* label = new QLabel(mainwindow); |
|
9688 |
mainwindow->setCentralWidget(label); |
|
9689 |
mainwindow->setWindowState(Qt::WindowFullScreen); |
|
9690 |
mainwindow->setVisible(true); |
|
9691 |
mainwindow->activateWindow(); |
|
9692 |
qApp->processEvents(); |
|
9693 |
||
9694 |
QVERIFY(mainwindow->isActiveWindow()); |
|
9695 |
QVERIFY(QDesktopWidget().availableGeometry().size() == mainwindow->size()); |
|
9696 |
||
9697 |
// Create second mainwindow in maximized and activate it |
|
9698 |
QMainWindow* mainwindow2 = new QMainWindow(); |
|
9699 |
QLabel* label2 = new QLabel(mainwindow2); |
|
9700 |
mainwindow2->setCentralWidget(label2); |
|
9701 |
mainwindow2->setWindowState(Qt::WindowMaximized); |
|
9702 |
mainwindow2->setVisible(true); |
|
9703 |
mainwindow2->activateWindow(); |
|
9704 |
qApp->processEvents(); |
|
9705 |
||
9706 |
QVERIFY(!mainwindow->isActiveWindow()); |
|
9707 |
QVERIFY(mainwindow2->isActiveWindow()); |
|
9708 |
QVERIFY(QDesktopWidget().availableGeometry().size() == mainwindow2->size()); |
|
9709 |
||
9710 |
// Verify window decorations i.e. status pane and CBA are visible. |
|
9711 |
CEikStatusPane* statusPane = CEikonEnv::Static()->AppUiFactory()->StatusPane(); |
|
9712 |
QVERIFY(statusPane->IsVisible()); |
|
9713 |
CEikButtonGroupContainer* buttonGroup = CEikonEnv::Static()->AppUiFactory()->Cba(); |
|
9714 |
QVERIFY(buttonGroup->IsVisible()); |
|
9715 |
} |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9716 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9717 |
void tst_QWidget::fullScreenWindowModeTransitions() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9718 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9719 |
QWidget widget; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9720 |
QVBoxLayout *layout = new QVBoxLayout; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9721 |
QPushButton *button = new QPushButton("test Button"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9722 |
layout->addWidget(button); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9723 |
widget.setLayout(layout); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9724 |
widget.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9725 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9726 |
const QRect normalGeometry = widget.normalGeometry(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9727 |
const QRect fullScreenGeometry = qApp->desktop()->screenGeometry(&widget); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9728 |
const QRect maximumScreenGeometry = qApp->desktop()->availableGeometry(&widget); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9729 |
CEikStatusPane *statusPane = CEikonEnv::Static()->AppUiFactory()->StatusPane(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9730 |
CEikButtonGroupContainer *buttonGroup = CEikonEnv::Static()->AppUiFactory()->Cba(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9731 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9732 |
//Enter |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9733 |
widget.showNormal(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9734 |
widget.showFullScreen(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9735 |
QCOMPARE(widget.geometry(), fullScreenGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9736 |
QVERIFY(!buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9737 |
QVERIFY(!statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9738 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9739 |
widget.showMaximized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9740 |
widget.showFullScreen(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9741 |
QCOMPARE(widget.geometry(), fullScreenGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9742 |
QVERIFY(!buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9743 |
QVERIFY(!statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9744 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9745 |
widget.showMinimized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9746 |
widget.showFullScreen(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9747 |
QCOMPARE(widget.geometry(), fullScreenGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9748 |
QVERIFY(!buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9749 |
QVERIFY(!statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9750 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9751 |
//Exit |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9752 |
widget.showFullScreen(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9753 |
widget.showNormal(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9754 |
QCOMPARE(widget.geometry(), normalGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9755 |
QVERIFY(buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9756 |
QVERIFY(statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9757 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9758 |
widget.showFullScreen(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9759 |
widget.showMaximized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9760 |
QCOMPARE(widget.geometry(), maximumScreenGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9761 |
QVERIFY(buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9762 |
QVERIFY(statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9763 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9764 |
widget.showFullScreen(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9765 |
widget.showMinimized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9766 |
QCOMPARE(widget.geometry(), fullScreenGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9767 |
QVERIFY(!buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9768 |
QVERIFY(!statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9769 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9770 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9771 |
void tst_QWidget::maximizedWindowModeTransitions() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9772 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9773 |
QWidget widget; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9774 |
QVBoxLayout *layout = new QVBoxLayout; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9775 |
QPushButton *button = new QPushButton("test Button"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9776 |
layout->addWidget(button); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9777 |
widget.setLayout(layout); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9778 |
widget.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9779 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9780 |
const QRect normalGeometry = widget.normalGeometry(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9781 |
const QRect fullScreenGeometry = qApp->desktop()->screenGeometry(&widget); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9782 |
const QRect maximumScreenGeometry = qApp->desktop()->availableGeometry(&widget); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9783 |
CEikStatusPane *statusPane = CEikonEnv::Static()->AppUiFactory()->StatusPane(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9784 |
CEikButtonGroupContainer *buttonGroup = CEikonEnv::Static()->AppUiFactory()->Cba(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9785 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9786 |
//Enter |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9787 |
widget.showNormal(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9788 |
widget.showMaximized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9789 |
QCOMPARE(widget.geometry(), maximumScreenGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9790 |
QVERIFY(buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9791 |
QVERIFY(statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9792 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9793 |
widget.showFullScreen(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9794 |
widget.showMaximized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9795 |
QCOMPARE(widget.geometry(), maximumScreenGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9796 |
QVERIFY(buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9797 |
QVERIFY(statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9798 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9799 |
widget.showMinimized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9800 |
widget.showMaximized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9801 |
QCOMPARE(widget.geometry(), maximumScreenGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9802 |
QVERIFY(buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9803 |
QVERIFY(statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9804 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9805 |
//Exit |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9806 |
widget.showMaximized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9807 |
widget.showNormal(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9808 |
QCOMPARE(widget.geometry(), normalGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9809 |
QVERIFY(buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9810 |
QVERIFY(statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9811 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9812 |
widget.showMaximized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9813 |
widget.showFullScreen(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9814 |
QCOMPARE(widget.geometry(), fullScreenGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9815 |
QVERIFY(!buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9816 |
QVERIFY(!statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9817 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9818 |
widget.showMaximized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9819 |
widget.showMinimized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9820 |
// Since showMinimized hides window decoration availableGeometry gives different value |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9821 |
// than with decoration visible. Altual size does not really matter since widget is invisible. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9822 |
QCOMPARE(widget.geometry(), qApp->desktop()->availableGeometry(&widget)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9823 |
QVERIFY(!buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9824 |
QVERIFY(!statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9825 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9826 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9827 |
void tst_QWidget::minimizedWindowModeTransitions() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9828 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9829 |
QWidget widget; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9830 |
QVBoxLayout *layout = new QVBoxLayout; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9831 |
QPushButton *button = new QPushButton("test Button"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9832 |
layout->addWidget(button); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9833 |
widget.setLayout(layout); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9834 |
widget.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9835 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9836 |
const QRect normalGeometry = widget.normalGeometry(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9837 |
const QRect fullScreenGeometry = qApp->desktop()->screenGeometry(&widget); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9838 |
const QRect maximumScreenGeometry = qApp->desktop()->availableGeometry(&widget); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9839 |
CEikStatusPane *statusPane = CEikonEnv::Static()->AppUiFactory()->StatusPane(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9840 |
CEikButtonGroupContainer *buttonGroup = CEikonEnv::Static()->AppUiFactory()->Cba(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9841 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9842 |
//Enter |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9843 |
widget.showNormal(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9844 |
widget.showMinimized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9845 |
QCOMPARE(widget.geometry(), normalGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9846 |
QVERIFY(!buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9847 |
QVERIFY(!statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9848 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9849 |
widget.showFullScreen(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9850 |
widget.showMinimized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9851 |
QCOMPARE(widget.geometry(), fullScreenGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9852 |
QVERIFY(!buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9853 |
QVERIFY(!statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9854 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9855 |
widget.showMaximized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9856 |
widget.showMinimized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9857 |
// Since showMinimized hides window decoration availableGeometry gives different value |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9858 |
// than with decoration visible. Altual size does not really matter since widget is invisible. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9859 |
QCOMPARE(widget.geometry(), qApp->desktop()->availableGeometry(&widget)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9860 |
QVERIFY(!buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9861 |
QVERIFY(!statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9862 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9863 |
//Exit |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9864 |
widget.showMinimized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9865 |
widget.showNormal(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9866 |
QCOMPARE(widget.geometry(), normalGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9867 |
QVERIFY(buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9868 |
QVERIFY(statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9869 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9870 |
widget.showMinimized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9871 |
widget.showFullScreen(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9872 |
QCOMPARE(widget.geometry(), fullScreenGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9873 |
QVERIFY(!buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9874 |
QVERIFY(!statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9875 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9876 |
widget.showMinimized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9877 |
widget.showMaximized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9878 |
QCOMPARE(widget.geometry(), maximumScreenGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9879 |
QVERIFY(buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9880 |
QVERIFY(statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9881 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9882 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9883 |
void tst_QWidget::normalWindowModeTransitions() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9884 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9885 |
QWidget widget; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9886 |
QVBoxLayout *layout = new QVBoxLayout; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9887 |
QPushButton *button = new QPushButton("test Button"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9888 |
layout->addWidget(button); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9889 |
widget.setLayout(layout); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9890 |
widget.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9891 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9892 |
const QRect normalGeometry = widget.normalGeometry(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9893 |
const QRect fullScreenGeometry = qApp->desktop()->screenGeometry(&widget); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9894 |
const QRect maximumScreenGeometry = qApp->desktop()->availableGeometry(&widget); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9895 |
CEikStatusPane *statusPane = CEikonEnv::Static()->AppUiFactory()->StatusPane(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9896 |
CEikButtonGroupContainer *buttonGroup = CEikonEnv::Static()->AppUiFactory()->Cba(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9897 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9898 |
//Enter |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9899 |
widget.showMaximized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9900 |
widget.showNormal(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9901 |
QCOMPARE(widget.geometry(), normalGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9902 |
QVERIFY(buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9903 |
QVERIFY(statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9904 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9905 |
widget.showFullScreen(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9906 |
widget.showNormal(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9907 |
QCOMPARE(widget.geometry(), normalGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9908 |
QVERIFY(buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9909 |
QVERIFY(statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9910 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9911 |
widget.showMinimized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9912 |
widget.showNormal(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9913 |
QCOMPARE(widget.geometry(), normalGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9914 |
QVERIFY(buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9915 |
QVERIFY(statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9916 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9917 |
//Exit |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9918 |
widget.showNormal(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9919 |
widget.showMaximized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9920 |
QCOMPARE(widget.geometry(), maximumScreenGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9921 |
QVERIFY(buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9922 |
QVERIFY(statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9923 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9924 |
widget.showNormal(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9925 |
widget.showFullScreen(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9926 |
QCOMPARE(widget.geometry(), fullScreenGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9927 |
QVERIFY(!buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9928 |
QVERIFY(!statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9929 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9930 |
widget.showNormal(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9931 |
widget.showMinimized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9932 |
QCOMPARE(widget.geometry(), normalGeometry); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9933 |
QVERIFY(!buttonGroup->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9934 |
QVERIFY(!statusPane->IsVisible()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
9935 |
} |
0 | 9936 |
#endif |
9937 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9938 |
class InputContextTester : public QInputContext |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9939 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9940 |
Q_OBJECT |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9941 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9942 |
QString identifierName() { return QString(); } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9943 |
bool isComposing() const { return false; } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9944 |
QString language() { return QString(); } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9945 |
void reset() { ++resets; } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9946 |
int resets; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9947 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9948 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9949 |
void tst_QWidget::focusProxyAndInputMethods() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9950 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9951 |
InputContextTester *inputContext = new InputContextTester; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9952 |
QWidget *toplevel = new QWidget(0, Qt::X11BypassWindowManagerHint); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9953 |
toplevel->setAttribute(Qt::WA_InputMethodEnabled, true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9954 |
toplevel->setInputContext(inputContext); // ownership is transferred |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9955 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9956 |
QWidget *child = new QWidget(toplevel); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9957 |
child->setFocusProxy(toplevel); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9958 |
child->setAttribute(Qt::WA_InputMethodEnabled, true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9959 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9960 |
toplevel->setFocusPolicy(Qt::WheelFocus); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9961 |
child->setFocusPolicy(Qt::WheelFocus); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9962 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9963 |
QVERIFY(!child->hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9964 |
QVERIFY(!toplevel->hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9965 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9966 |
toplevel->show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9967 |
QTest::qWaitForWindowShown(toplevel); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9968 |
QApplication::setActiveWindow(toplevel); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9969 |
QVERIFY(toplevel->hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9970 |
QVERIFY(child->hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9971 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9972 |
// 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
|
9973 |
// 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
|
9974 |
// 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
|
9975 |
// 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
|
9976 |
// 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
|
9977 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9978 |
QCOMPARE(inputContext->focusWidget(), toplevel); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9979 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9980 |
child->setAttribute(Qt::WA_InputMethodEnabled, false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9981 |
QVERIFY(!inputContext->focusWidget()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9982 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9983 |
child->setAttribute(Qt::WA_InputMethodEnabled, true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9984 |
QCOMPARE(inputContext->focusWidget(), toplevel); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9985 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9986 |
child->setEnabled(false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9987 |
QVERIFY(!inputContext->focusWidget()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9988 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9989 |
child->setEnabled(true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9990 |
QCOMPARE(inputContext->focusWidget(), toplevel); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9991 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9992 |
delete toplevel; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9993 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9994 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9995 |
class scrollWidgetWBS : public QWidget |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9996 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9997 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9998 |
void deleteBackingStore() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9999 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10000 |
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
|
10001 |
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
|
10002 |
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
|
10003 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10004 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10005 |
void enableBackingStore() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10006 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10007 |
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
|
10008 |
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
|
10009 |
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
|
10010 |
repaint(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10011 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10012 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10013 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10014 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10015 |
void tst_QWidget::scrollWithoutBackingStore() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10016 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10017 |
scrollWidgetWBS scrollable; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10018 |
scrollable.resize(100,100); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10019 |
QLabel child(QString("@"),&scrollable); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10020 |
child.resize(50,50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10021 |
scrollable.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10022 |
QTest::qWaitForWindowShown(&scrollable); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10023 |
scrollable.scroll(50,50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10024 |
QCOMPARE(child.pos(),QPoint(50,50)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10025 |
scrollable.deleteBackingStore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10026 |
scrollable.scroll(-25,-25); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10027 |
QCOMPARE(child.pos(),QPoint(25,25)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10028 |
scrollable.enableBackingStore(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10029 |
QCOMPARE(child.pos(),QPoint(25,25)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10030 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
10031 |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10032 |
void tst_QWidget::taskQTBUG_7532_tabOrderWithFocusProxy() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10033 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10034 |
QWidget w; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10035 |
w.setFocusPolicy(Qt::TabFocus); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10036 |
QWidget *fp = new QWidget(&w); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10037 |
fp->setFocusPolicy(Qt::TabFocus); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10038 |
w.setFocusProxy(fp); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10039 |
QWidget::setTabOrder(&w, fp); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10040 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10041 |
// No Q_ASSERT, then it's allright. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10042 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10043 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10044 |
void tst_QWidget::movedAndResizedAttributes() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10045 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10046 |
#if defined (Q_OS_MAC) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10047 |
QEXPECT_FAIL("", "FixMe, QTBUG-8941 and QTBUG-8977", Abort); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10048 |
QVERIFY(false); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10049 |
#else |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10050 |
QWidget w; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10051 |
w.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10052 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10053 |
QVERIFY(!w.testAttribute(Qt::WA_Moved)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10054 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10055 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10056 |
w.setWindowState(Qt::WindowFullScreen); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10057 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10058 |
QVERIFY(!w.testAttribute(Qt::WA_Moved)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10059 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10060 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10061 |
w.setWindowState(Qt::WindowMaximized); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10062 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10063 |
QVERIFY(!w.testAttribute(Qt::WA_Moved)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10064 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10065 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10066 |
w.setWindowState(Qt::WindowMinimized); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10067 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10068 |
QVERIFY(!w.testAttribute(Qt::WA_Moved)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10069 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10070 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10071 |
w.showNormal(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10072 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10073 |
QVERIFY(!w.testAttribute(Qt::WA_Moved)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10074 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10075 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10076 |
w.showMaximized(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10077 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10078 |
QVERIFY(!w.testAttribute(Qt::WA_Moved)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10079 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10080 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10081 |
w.showFullScreen(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10082 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10083 |
QVERIFY(!w.testAttribute(Qt::WA_Moved)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10084 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10085 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10086 |
w.showNormal(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10087 |
w.move(10,10); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10088 |
QVERIFY(w.testAttribute(Qt::WA_Moved)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10089 |
#if defined(Q_OS_WIN) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10090 |
QEXPECT_FAIL("", "FixMe, QTBUG-8911", Abort); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10091 |
#endif |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10092 |
QVERIFY(!w.testAttribute(Qt::WA_Resized)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10093 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10094 |
w.resize(100, 100); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10095 |
QVERIFY(w.testAttribute(Qt::WA_Moved)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10096 |
QVERIFY(w.testAttribute(Qt::WA_Resized)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10097 |
#endif |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10098 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
10099 |
|
0 | 10100 |
QTEST_MAIN(tst_QWidget) |
10101 |
#include "tst_qwidget.moc" |