author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <qapplication.h> |
|
45 |
#include <qmainwindow.h> |
|
46 |
#include <qmenubar.h> |
|
47 |
#include <qworkspace.h> |
|
48 |
#if defined(QT3_SUPPORT) |
|
49 |
#include <q3popupmenu.h> |
|
50 |
#include <q3accel.h> |
|
51 |
#endif |
|
52 |
||
53 |
//TESTED_CLASS= |
|
54 |
//TESTED_FILES= |
|
55 |
||
56 |
class tst_QWorkspace : public QObject |
|
57 |
{ |
|
58 |
Q_OBJECT |
|
59 |
||
60 |
public: |
|
61 |
tst_QWorkspace(); |
|
62 |
virtual ~tst_QWorkspace(); |
|
63 |
||
64 |
||
65 |
protected slots: |
|
66 |
void activeChanged( QWidget *w ); |
|
67 |
void accelActivated(); |
|
68 |
||
69 |
public slots: |
|
70 |
void initTestCase(); |
|
71 |
void cleanupTestCase(); |
|
72 |
void init(); |
|
73 |
void cleanup(); |
|
74 |
private slots: |
|
75 |
void getSetCheck(); |
|
76 |
void windowActivated_data(); |
|
77 |
void windowActivated(); |
|
78 |
void accelPropagation(); |
|
79 |
void windowActivatedWithMinimize(); |
|
80 |
void showWindows(); |
|
81 |
void changeWindowTitle(); |
|
82 |
void changeModified(); |
|
83 |
void childSize(); |
|
84 |
void fixedSize(); |
|
85 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) |
|
86 |
void nativeSubWindows(); |
|
87 |
#endif |
|
88 |
void task206368(); |
|
89 |
||
90 |
private: |
|
91 |
QWidget *activeWidget; |
|
92 |
bool accelPressed; |
|
93 |
}; |
|
94 |
||
95 |
// Testing get/set functions |
|
96 |
void tst_QWorkspace::getSetCheck() |
|
97 |
{ |
|
98 |
QWorkspace obj1; |
|
99 |
// bool QWorkspace::scrollBarsEnabled() |
|
100 |
// void QWorkspace::setScrollBarsEnabled(bool) |
|
101 |
obj1.setScrollBarsEnabled(false); |
|
102 |
QCOMPARE(false, obj1.scrollBarsEnabled()); |
|
103 |
obj1.setScrollBarsEnabled(true); |
|
104 |
QCOMPARE(true, obj1.scrollBarsEnabled()); |
|
105 |
} |
|
106 |
||
107 |
tst_QWorkspace::tst_QWorkspace() |
|
108 |
: activeWidget( 0 ) |
|
109 |
{ |
|
110 |
} |
|
111 |
||
112 |
tst_QWorkspace::~tst_QWorkspace() |
|
113 |
{ |
|
114 |
||
115 |
} |
|
116 |
||
117 |
// initTestCase will be executed once before the first testfunction is executed. |
|
118 |
void tst_QWorkspace::initTestCase() |
|
119 |
{ |
|
120 |
||
121 |
} |
|
122 |
||
123 |
// cleanupTestCase will be executed once after the last testfunction is executed. |
|
124 |
void tst_QWorkspace::cleanupTestCase() |
|
125 |
{ |
|
126 |
} |
|
127 |
||
128 |
// init() will be executed immediately before each testfunction is run. |
|
129 |
void tst_QWorkspace::init() |
|
130 |
{ |
|
131 |
// TODO: Add testfunction specific initialization code here. |
|
132 |
} |
|
133 |
||
134 |
// cleanup() will be executed immediately after each testfunction is run. |
|
135 |
void tst_QWorkspace::cleanup() |
|
136 |
{ |
|
137 |
// TODO: Add testfunction specific cleanup code here. |
|
138 |
} |
|
139 |
||
140 |
void tst_QWorkspace::activeChanged( QWidget *w ) |
|
141 |
{ |
|
142 |
activeWidget = w; |
|
143 |
} |
|
144 |
||
145 |
void tst_QWorkspace::windowActivated_data() |
|
146 |
{ |
|
147 |
// define the test elements we're going to use |
|
148 |
QTest::addColumn<int>("count"); |
|
149 |
||
150 |
// create a first testdata instance and fill it with data |
|
151 |
QTest::newRow( "data0" ) << 0; |
|
152 |
QTest::newRow( "data1" ) << 1; |
|
153 |
QTest::newRow( "data2" ) << 2; |
|
154 |
} |
|
155 |
||
156 |
void tst_QWorkspace::windowActivated() |
|
157 |
{ |
|
158 |
QMainWindow mw(0, Qt::X11BypassWindowManagerHint); |
|
159 |
mw.menuBar(); |
|
160 |
QWorkspace *workspace = new QWorkspace(&mw); |
|
161 |
workspace->setObjectName("testWidget"); |
|
162 |
mw.setCentralWidget(workspace); |
|
163 |
QSignalSpy spy(workspace, SIGNAL(windowActivated(QWidget*))); |
|
164 |
connect( workspace, SIGNAL(windowActivated(QWidget*)), this, SLOT(activeChanged(QWidget*)) ); |
|
165 |
mw.show(); |
|
166 |
qApp->setActiveWindow(&mw); |
|
167 |
||
168 |
QFETCH( int, count ); |
|
169 |
int i; |
|
170 |
||
171 |
for ( i = 0; i < count; ++i ) { |
|
172 |
QWidget *widget = new QWidget(workspace, 0); |
|
173 |
widget->setAttribute(Qt::WA_DeleteOnClose); |
|
174 |
workspace->addWindow(widget); |
|
175 |
widget->show(); |
|
176 |
qApp->processEvents(); |
|
177 |
QVERIFY( activeWidget == workspace->activeWindow() ); |
|
178 |
QCOMPARE(spy.count(), 1); |
|
179 |
spy.clear(); |
|
180 |
} |
|
181 |
||
182 |
QWidgetList windows = workspace->windowList(); |
|
183 |
QCOMPARE( (int)windows.count(), count ); |
|
184 |
||
185 |
for ( i = 0; i < count; ++i ) { |
|
186 |
QWidget *window = windows.at(i); |
|
187 |
window->showMinimized(); |
|
188 |
qApp->processEvents(); |
|
189 |
QVERIFY( activeWidget == workspace->activeWindow() ); |
|
190 |
if ( i == 1 ) |
|
191 |
QVERIFY( activeWidget == window ); |
|
192 |
} |
|
193 |
||
194 |
for ( i = 0; i < count; ++i ) { |
|
195 |
QWidget *window = windows.at(i); |
|
196 |
window->showNormal(); |
|
197 |
qApp->processEvents(); |
|
198 |
QVERIFY( window == activeWidget ); |
|
199 |
QVERIFY( activeWidget == workspace->activeWindow() ); |
|
200 |
} |
|
201 |
spy.clear(); |
|
202 |
||
203 |
while ( workspace->activeWindow() ) { |
|
204 |
workspace->activeWindow()->close(); |
|
205 |
qApp->processEvents(); |
|
206 |
QVERIFY( activeWidget == workspace->activeWindow() ); |
|
207 |
QCOMPARE(spy.count(), 1); |
|
208 |
spy.clear(); |
|
209 |
} |
|
210 |
QVERIFY(activeWidget == 0); |
|
211 |
QVERIFY(workspace->activeWindow() == 0); |
|
212 |
QVERIFY(workspace->windowList().count() == 0); |
|
213 |
||
214 |
{ |
|
215 |
workspace->hide(); |
|
216 |
QWidget *widget = new QWidget(workspace); |
|
217 |
widget->setObjectName("normal"); |
|
218 |
widget->setAttribute(Qt::WA_DeleteOnClose); |
|
219 |
workspace->addWindow(widget); |
|
220 |
widget->show(); |
|
221 |
QCOMPARE(spy.count(), 0); |
|
222 |
workspace->show(); |
|
223 |
QCOMPARE(spy.count(), 1); |
|
224 |
spy.clear(); |
|
225 |
QVERIFY( activeWidget == widget ); |
|
226 |
widget->close(); |
|
227 |
qApp->processEvents(); |
|
228 |
QCOMPARE(spy.count(), 1); |
|
229 |
spy.clear(); |
|
230 |
QVERIFY( activeWidget == 0 ); |
|
231 |
} |
|
232 |
||
233 |
{ |
|
234 |
workspace->hide(); |
|
235 |
QWidget *widget = new QWidget(workspace); |
|
236 |
widget->setObjectName("maximized"); |
|
237 |
widget->setAttribute(Qt::WA_DeleteOnClose); |
|
238 |
workspace->addWindow(widget); |
|
239 |
widget->showMaximized(); |
|
240 |
qApp->sendPostedEvents(); |
|
241 |
#ifdef Q_WS_MAC |
|
242 |
QEXPECT_FAIL("", "This test has never passed on Mac. QWorkspace is obsoleted -> won't fix", Abort); |
|
243 |
#endif |
|
244 |
QCOMPARE(spy.count(), 0); |
|
245 |
spy.clear(); |
|
246 |
workspace->show(); |
|
247 |
QCOMPARE(spy.count(), 1); |
|
248 |
spy.clear(); |
|
249 |
QVERIFY( activeWidget == widget ); |
|
250 |
widget->close(); |
|
251 |
qApp->processEvents(); |
|
252 |
QCOMPARE(spy.count(), 1); |
|
253 |
spy.clear(); |
|
254 |
QVERIFY( activeWidget == 0 ); |
|
255 |
} |
|
256 |
||
257 |
{ |
|
258 |
QWidget *widget = new QWidget(workspace); |
|
259 |
widget->setObjectName("minimized"); |
|
260 |
widget->setAttribute(Qt::WA_DeleteOnClose); |
|
261 |
workspace->addWindow(widget); |
|
262 |
widget->showMinimized(); |
|
263 |
QCOMPARE(spy.count(), 1); |
|
264 |
spy.clear(); |
|
265 |
QVERIFY( activeWidget == widget ); |
|
266 |
QVERIFY(workspace->activeWindow() == widget); |
|
267 |
widget->close(); |
|
268 |
qApp->processEvents(); |
|
269 |
QCOMPARE(spy.count(), 1); |
|
270 |
spy.clear(); |
|
271 |
QVERIFY(workspace->activeWindow() == 0); |
|
272 |
QVERIFY( activeWidget == 0 ); |
|
273 |
} |
|
274 |
} |
|
275 |
void tst_QWorkspace::windowActivatedWithMinimize() |
|
276 |
{ |
|
277 |
QMainWindow mw(0, Qt::X11BypassWindowManagerHint) ; |
|
278 |
mw.menuBar(); |
|
279 |
QWorkspace *workspace = new QWorkspace(&mw); |
|
280 |
workspace->setObjectName("testWidget"); |
|
281 |
mw.setCentralWidget(workspace); |
|
282 |
QSignalSpy spy(workspace, SIGNAL(windowActivated(QWidget*))); |
|
283 |
connect( workspace, SIGNAL(windowActivated(QWidget*)), this, SLOT(activeChanged(QWidget*)) ); |
|
284 |
mw.show(); |
|
285 |
qApp->setActiveWindow(&mw); |
|
286 |
QWidget *widget = new QWidget(workspace); |
|
287 |
widget->setObjectName("minimized1"); |
|
288 |
widget->setAttribute(Qt::WA_DeleteOnClose); |
|
289 |
workspace->addWindow(widget); |
|
290 |
QWidget *widget2 = new QWidget(workspace); |
|
291 |
widget2->setObjectName("minimized2"); |
|
292 |
widget2->setAttribute(Qt::WA_DeleteOnClose); |
|
293 |
workspace->addWindow(widget2); |
|
294 |
||
295 |
widget->showMinimized(); |
|
296 |
QVERIFY( activeWidget == widget ); |
|
297 |
widget2->showMinimized(); |
|
298 |
QVERIFY( activeWidget == widget2 ); |
|
299 |
||
300 |
widget2->close(); |
|
301 |
qApp->processEvents(); |
|
302 |
QVERIFY( activeWidget == widget ); |
|
303 |
||
304 |
widget->close(); |
|
305 |
qApp->processEvents(); |
|
306 |
QVERIFY(workspace->activeWindow() == 0); |
|
307 |
QVERIFY( activeWidget == 0 ); |
|
308 |
||
309 |
QVERIFY( workspace->windowList().count() == 0 ); |
|
310 |
} |
|
311 |
||
312 |
void tst_QWorkspace::accelActivated() |
|
313 |
{ |
|
314 |
accelPressed = TRUE; |
|
315 |
} |
|
316 |
||
317 |
void tst_QWorkspace::accelPropagation() |
|
318 |
{ |
|
319 |
#if defined (QT3_SUPPORT) |
|
320 |
QSKIP( "Until QTest::keyPress() sends the events via the OS, this will skip", SkipAll); |
|
321 |
// See #13987 for details of bug report related to this |
|
322 |
||
323 |
QMainWindow mw(0, Qt::X11BypassWindowManagerHint) ; |
|
324 |
mw.menuBar(); |
|
325 |
QWorkspace *workspace = new QWorkspace(&mw); |
|
326 |
workspace->setObjectName("testWidget"); |
|
327 |
mw.setCentralWidget(workspace); |
|
328 |
connect( workspace, SIGNAL(windowActivated(QWidget*)), this, SLOT(activeChanged(QWidget*)) ); |
|
329 |
mw.show(); |
|
330 |
qApp->setActiveWindow(&mw); |
|
331 |
||
332 |
QMainWindow* mainWindow = new QMainWindow( workspace ); |
|
333 |
||
334 |
// The popup menu has to have no parent, this is vital in the |
|
335 |
// original case of reproducing the bug |
|
336 |
||
337 |
Q3PopupMenu* popup = new Q3PopupMenu; |
|
338 |
popup->insertItem("First"); |
|
339 |
mainWindow->menuBar()->insertItem("Menu", popup); |
|
340 |
||
341 |
Q3Accel* accel = new Q3Accel(mainWindow); |
|
342 |
accel->connectItem(accel->insertItem(Qt::Key_Escape), this, SLOT(accelActivated()) ); |
|
343 |
||
344 |
mainWindow->show(); |
|
345 |
||
346 |
QTest::keyPress( mainWindow, Qt::Key_Escape ); |
|
347 |
QVERIFY( accelPressed ); |
|
348 |
accelPressed = FALSE; |
|
349 |
||
350 |
QTest::mousePress( mainWindow->menuBar(), Qt::LeftButton, 0, QPoint( 5, 5 ) ); |
|
351 |
||
352 |
// Check the popup menu did appear to be sure |
|
353 |
QVERIFY( qApp->activePopupWidget() == popup ); |
|
354 |
||
355 |
QTest::mouseClick( popup, Qt::LeftButton, 0, QPoint( 5, 25 ) ); |
|
356 |
||
357 |
// Check we did actually cause the popup menu to be closed |
|
358 |
QVERIFY( !popup->isVisible() ); |
|
359 |
||
360 |
// Now we check that the accelarator still works |
|
361 |
QTest::keyPress( mainWindow, Qt::Key_Escape ); |
|
362 |
QVERIFY( accelPressed ); |
|
363 |
delete popup; |
|
364 |
#else |
|
365 |
QSKIP( "No Qt3Support. Skipping.", SkipAll); |
|
366 |
#endif |
|
367 |
||
368 |
} |
|
369 |
||
370 |
void tst_QWorkspace::showWindows() |
|
371 |
{ |
|
372 |
QWorkspace *ws = new QWorkspace( 0 ); |
|
373 |
||
374 |
QWidget *widget = 0; |
|
375 |
ws->show(); |
|
376 |
||
377 |
widget = new QWidget(ws); |
|
378 |
widget->setObjectName("plain1"); |
|
379 |
widget->show(); |
|
380 |
QVERIFY( widget->isVisible() ); |
|
381 |
||
382 |
widget = new QWidget(ws); |
|
383 |
widget->setObjectName("maximized1"); |
|
384 |
widget->showMaximized(); |
|
385 |
QVERIFY( widget->isMaximized() ); |
|
386 |
widget->showNormal(); |
|
387 |
QVERIFY( !widget->isMaximized() ); |
|
388 |
||
389 |
widget = new QWidget(ws); |
|
390 |
widget->setObjectName("minimized1"); |
|
391 |
widget->showMinimized(); |
|
392 |
QVERIFY( widget->isMinimized() ); |
|
393 |
widget->showNormal(); |
|
394 |
QVERIFY( !widget->isMinimized() ); |
|
395 |
||
396 |
ws->hide(); |
|
397 |
||
398 |
widget = new QWidget(ws); |
|
399 |
widget->setObjectName("plain2"); |
|
400 |
ws->show(); |
|
401 |
QVERIFY( widget->isVisible() ); |
|
402 |
||
403 |
ws->hide(); |
|
404 |
||
405 |
widget = new QWidget(ws); |
|
406 |
widget->setObjectName("maximized2"); |
|
407 |
widget->showMaximized(); |
|
408 |
QVERIFY( widget->isMaximized() ); |
|
409 |
ws->show(); |
|
410 |
QVERIFY( widget->isVisible() ); |
|
411 |
QVERIFY( widget->isMaximized() ); |
|
412 |
ws->hide(); |
|
413 |
||
414 |
widget = new QWidget(ws); |
|
415 |
widget->setObjectName("minimized2"); |
|
416 |
widget->showMinimized(); |
|
417 |
ws->show(); |
|
418 |
QVERIFY( widget->isMinimized() ); |
|
419 |
ws->hide(); |
|
420 |
||
421 |
delete ws; |
|
422 |
} |
|
423 |
||
424 |
||
425 |
//#define USE_SHOW |
|
426 |
||
427 |
void tst_QWorkspace::changeWindowTitle() |
|
428 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
429 |
#ifdef Q_OS_WINCE |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
430 |
QSKIP( "Test fails on Windows CE due to QWorkspace state handling", SkipAll); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
431 |
#endif |
0 | 432 |
const QString mwc( "MainWindow's Caption" ); |
433 |
const QString mwc2( "MainWindow's New Caption" ); |
|
434 |
const QString wc( "Widget's Caption" ); |
|
435 |
const QString wc2( "Widget's New Caption" ); |
|
436 |
||
437 |
QMainWindow *mw = new QMainWindow(0, Qt::X11BypassWindowManagerHint); |
|
438 |
mw->setWindowTitle( mwc ); |
|
439 |
QWorkspace *ws = new QWorkspace( mw ); |
|
440 |
mw->setCentralWidget( ws ); |
|
441 |
||
442 |
||
443 |
QWidget *widget = new QWidget( ws ); |
|
444 |
widget->setWindowTitle( wc ); |
|
445 |
ws->addWindow(widget); |
|
446 |
||
447 |
QCOMPARE( mw->windowTitle(), mwc ); |
|
448 |
||
449 |
||
450 |
#ifdef USE_SHOW |
|
451 |
widget->showMaximized(); |
|
452 |
#else |
|
453 |
widget->setWindowState(Qt::WindowMaximized); |
|
454 |
#endif |
|
455 |
QCOMPARE( mw->windowTitle(), QString("%1 - [%2]").arg(mwc).arg(wc) ); |
|
456 |
||
457 |
#ifdef USE_SHOW |
|
458 |
widget->showNormal(); |
|
459 |
#else |
|
460 |
widget->setWindowState(Qt::WindowNoState); |
|
461 |
#endif |
|
462 |
qApp->processEvents(); |
|
463 |
QCOMPARE( mw->windowTitle(), mwc ); |
|
464 |
||
465 |
#ifdef USE_SHOW |
|
466 |
widget->showMaximized(); |
|
467 |
#else |
|
468 |
widget->setWindowState(Qt::WindowMaximized); |
|
469 |
#endif |
|
470 |
qApp->processEvents(); |
|
471 |
QCOMPARE( mw->windowTitle(), QString("%1 - [%2]").arg(mwc).arg(wc) ); |
|
472 |
widget->setWindowTitle( wc2 ); |
|
473 |
QCOMPARE( mw->windowTitle(), QString("%1 - [%2]").arg(mwc).arg(wc2) ); |
|
474 |
mw->setWindowTitle( mwc2 ); |
|
475 |
QCOMPARE( mw->windowTitle(), QString("%1 - [%2]").arg(mwc2).arg(wc2) ); |
|
476 |
||
477 |
mw->show(); |
|
478 |
qApp->setActiveWindow(mw); |
|
479 |
||
480 |
#ifdef USE_SHOW |
|
481 |
mw->showFullScreen(); |
|
482 |
#else |
|
483 |
mw->setWindowState(Qt::WindowFullScreen); |
|
484 |
#endif |
|
485 |
||
486 |
qApp->processEvents(); |
|
487 |
QCOMPARE( mw->windowTitle(), QString("%1 - [%2]").arg(mwc2).arg(wc2) ); |
|
488 |
#ifdef USE_SHOW |
|
489 |
widget->showNormal(); |
|
490 |
#else |
|
491 |
widget->setWindowState(Qt::WindowNoState); |
|
492 |
#endif |
|
493 |
qApp->processEvents(); |
|
494 |
QCOMPARE( mw->windowTitle(), mwc2 ); |
|
495 |
#ifdef USE_SHOW |
|
496 |
widget->showMaximized(); |
|
497 |
#else |
|
498 |
widget->setWindowState(Qt::WindowMaximized); |
|
499 |
#endif |
|
500 |
qApp->processEvents(); |
|
501 |
QCOMPARE( mw->windowTitle(), QString("%1 - [%2]").arg(mwc2).arg(wc2) ); |
|
502 |
||
503 |
#ifdef USE_SHOW |
|
504 |
mw->showNormal(); |
|
505 |
#else |
|
506 |
mw->setWindowState(Qt::WindowNoState); |
|
507 |
#endif |
|
508 |
qApp->processEvents(); |
|
509 |
QCOMPARE( mw->windowTitle(), QString("%1 - [%2]").arg(mwc2).arg(wc2) ); |
|
510 |
#ifdef USE_SHOW |
|
511 |
widget->showNormal(); |
|
512 |
#else |
|
513 |
widget->setWindowState(Qt::WindowNoState); |
|
514 |
#endif |
|
515 |
QCOMPARE( mw->windowTitle(), mwc2 ); |
|
516 |
||
517 |
delete mw; |
|
518 |
} |
|
519 |
||
520 |
void tst_QWorkspace::changeModified() |
|
521 |
{ |
|
522 |
const QString mwc( "MainWindow's Caption" ); |
|
523 |
const QString wc( "Widget's Caption[*]" ); |
|
524 |
||
525 |
QMainWindow *mw = new QMainWindow(0, Qt::X11BypassWindowManagerHint); |
|
526 |
mw->setWindowTitle( mwc ); |
|
527 |
QWorkspace *ws = new QWorkspace( mw ); |
|
528 |
mw->setCentralWidget( ws ); |
|
529 |
||
530 |
QWidget *widget = new QWidget( ws ); |
|
531 |
widget->setWindowTitle( wc ); |
|
532 |
ws->addWindow(widget); |
|
533 |
||
534 |
QCOMPARE( mw->isWindowModified(), false); |
|
535 |
QCOMPARE( widget->isWindowModified(), false); |
|
536 |
widget->setWindowState(Qt::WindowMaximized); |
|
537 |
QCOMPARE( mw->isWindowModified(), false); |
|
538 |
QCOMPARE( widget->isWindowModified(), false); |
|
539 |
||
540 |
widget->setWindowState(Qt::WindowNoState); |
|
541 |
QCOMPARE( mw->isWindowModified(), false); |
|
542 |
QCOMPARE( widget->isWindowModified(), false); |
|
543 |
||
544 |
widget->setWindowModified(true); |
|
545 |
QCOMPARE( mw->isWindowModified(), false); |
|
546 |
QCOMPARE( widget->isWindowModified(), true); |
|
547 |
widget->setWindowState(Qt::WindowMaximized); |
|
548 |
QCOMPARE( mw->isWindowModified(), true); |
|
549 |
QCOMPARE( widget->isWindowModified(), true); |
|
550 |
||
551 |
widget->setWindowState(Qt::WindowNoState); |
|
552 |
QCOMPARE( mw->isWindowModified(), false); |
|
553 |
QCOMPARE( widget->isWindowModified(), true); |
|
554 |
||
555 |
widget->setWindowState(Qt::WindowMaximized); |
|
556 |
QCOMPARE( mw->isWindowModified(), true); |
|
557 |
QCOMPARE( widget->isWindowModified(), true); |
|
558 |
||
559 |
widget->setWindowModified(false); |
|
560 |
QCOMPARE( mw->isWindowModified(), false); |
|
561 |
QCOMPARE( widget->isWindowModified(), false); |
|
562 |
||
563 |
widget->setWindowModified(true); |
|
564 |
QCOMPARE( mw->isWindowModified(), true); |
|
565 |
QCOMPARE( widget->isWindowModified(), true); |
|
566 |
||
567 |
widget->setWindowState(Qt::WindowNoState); |
|
568 |
QCOMPARE( mw->isWindowModified(), false); |
|
569 |
QCOMPARE( widget->isWindowModified(), true); |
|
570 |
||
571 |
delete mw; |
|
572 |
} |
|
573 |
||
574 |
class MyChild : public QWidget |
|
575 |
{ |
|
576 |
public: |
|
577 |
MyChild(QWidget *parent = 0, Qt::WFlags f = 0) |
|
578 |
: QWidget(parent, f) |
|
579 |
{ |
|
580 |
} |
|
581 |
||
582 |
QSize sizeHint() const |
|
583 |
{ |
|
584 |
return QSize(234, 123); |
|
585 |
} |
|
586 |
}; |
|
587 |
||
588 |
void tst_QWorkspace::childSize() |
|
589 |
{ |
|
590 |
QWorkspace ws; |
|
591 |
||
592 |
MyChild *child = new MyChild(&ws); |
|
593 |
child->show(); |
|
594 |
QCOMPARE(child->size(), child->sizeHint()); |
|
595 |
delete child; |
|
596 |
||
597 |
child = new MyChild(&ws); |
|
598 |
child->setFixedSize(200, 200); |
|
599 |
child->show(); |
|
600 |
QCOMPARE(child->size(), child->minimumSize()); |
|
601 |
delete child; |
|
602 |
||
603 |
child = new MyChild(&ws); |
|
604 |
child->resize(150, 150); |
|
605 |
child->show(); |
|
606 |
QCOMPARE(child->size(), QSize(150,150)); |
|
607 |
delete child; |
|
608 |
} |
|
609 |
||
610 |
void tst_QWorkspace::fixedSize() |
|
611 |
{ |
|
612 |
QWorkspace *ws = new QWorkspace; |
|
613 |
int i; |
|
614 |
||
615 |
ws->resize(500, 500); |
|
616 |
// ws->show(); |
|
617 |
||
618 |
QSize fixed(300, 300); |
|
619 |
for (i = 0; i < 4; ++i) { |
|
620 |
QWidget *child = new QWidget(ws); |
|
621 |
child->setFixedSize(fixed); |
|
622 |
child->show(); |
|
623 |
} |
|
624 |
||
625 |
QWidgetList windows = ws->windowList(); |
|
626 |
for (i = 0; i < (int)windows.count(); ++i) { |
|
627 |
QWidget *child = windows.at(i); |
|
628 |
QCOMPARE(child->size(), fixed); |
|
629 |
QCOMPARE(child->visibleRegion().boundingRect().size(), fixed); |
|
630 |
} |
|
631 |
||
632 |
ws->cascade(); |
|
633 |
ws->resize(800, 800); |
|
634 |
for (i = 0; i < (int)windows.count(); ++i) { |
|
635 |
QWidget *child = windows.at(i); |
|
636 |
QCOMPARE(child->size(), fixed); |
|
637 |
QCOMPARE(child->visibleRegion().boundingRect().size(), fixed); |
|
638 |
} |
|
639 |
ws->resize(500, 500); |
|
640 |
||
641 |
ws->tile(); |
|
642 |
ws->resize(800, 800); |
|
643 |
for (i = 0; i < (int)windows.count(); ++i) { |
|
644 |
QWidget *child = windows.at(i); |
|
645 |
QCOMPARE(child->size(), fixed); |
|
646 |
QCOMPARE(child->visibleRegion().boundingRect().size(), fixed); |
|
647 |
} |
|
648 |
ws->resize(500, 500); |
|
649 |
||
650 |
for (i = 0; i < (int)windows.count(); ++i) { |
|
651 |
QWidget *child = windows.at(i); |
|
652 |
delete child; |
|
653 |
} |
|
654 |
||
655 |
delete ws; |
|
656 |
} |
|
657 |
||
658 |
#if defined(Q_WS_WIN) || defined(Q_WS_X11) |
|
659 |
void tst_QWorkspace::nativeSubWindows() |
|
660 |
{ |
|
661 |
{ // Add native widgets after show. |
|
662 |
QWorkspace workspace; |
|
663 |
workspace.addWindow(new QWidget); |
|
664 |
workspace.addWindow(new QWidget); |
|
665 |
workspace.show(); |
|
666 |
#ifdef Q_WS_X11 |
|
667 |
qt_x11_wait_for_window_manager(&workspace); |
|
668 |
#endif |
|
669 |
||
670 |
// No native widgets. |
|
671 |
foreach (QWidget *subWindow, workspace.windowList()) |
|
672 |
QVERIFY(!subWindow->parentWidget()->internalWinId()); |
|
673 |
||
674 |
QWidget *nativeWidget = new QWidget; |
|
675 |
QVERIFY(nativeWidget->winId()); // enforce native window. |
|
676 |
workspace.addWindow(nativeWidget); |
|
677 |
||
678 |
// All the sub-windows must be native. |
|
679 |
foreach (QWidget *subWindow, workspace.windowList()) |
|
680 |
QVERIFY(subWindow->parentWidget()->internalWinId()); |
|
681 |
||
682 |
// Add a non-native widget. This should become native. |
|
683 |
QWidget *subWindow = workspace.addWindow(new QWidget); |
|
684 |
QVERIFY(subWindow->parentWidget()->internalWinId()); |
|
685 |
} |
|
686 |
||
687 |
{ // Add native widgets before show. |
|
688 |
QWorkspace workspace; |
|
689 |
workspace.addWindow(new QWidget); |
|
690 |
QWidget *nativeWidget = new QWidget; |
|
691 |
(void)nativeWidget->winId(); |
|
692 |
workspace.addWindow(nativeWidget); |
|
693 |
workspace.show(); |
|
694 |
#ifdef Q_WS_X11 |
|
695 |
qt_x11_wait_for_window_manager(&workspace); |
|
696 |
#endif |
|
697 |
||
698 |
// All the sub-windows must be native. |
|
699 |
foreach (QWidget *subWindow, workspace.windowList()) |
|
700 |
QVERIFY(subWindow->parentWidget()->internalWinId()); |
|
701 |
} |
|
702 |
||
703 |
{ // Make a sub-window native *after* it's added to the area. |
|
704 |
QWorkspace workspace; |
|
705 |
workspace.addWindow(new QWidget); |
|
706 |
workspace.addWindow(new QWidget); |
|
707 |
workspace.show(); |
|
708 |
#ifdef Q_WS_X11 |
|
709 |
qt_x11_wait_for_window_manager(&workspace); |
|
710 |
#endif |
|
711 |
||
712 |
QWidget *nativeSubWindow = workspace.windowList().last()->parentWidget(); |
|
713 |
QVERIFY(!nativeSubWindow->internalWinId()); |
|
714 |
(void)nativeSubWindow->winId(); |
|
715 |
||
716 |
// All the sub-windows should be native at this point. |
|
717 |
foreach (QWidget *subWindow, workspace.windowList()) |
|
718 |
QVERIFY(subWindow->parentWidget()->internalWinId()); |
|
719 |
} |
|
720 |
} |
|
721 |
#endif |
|
722 |
||
723 |
void tst_QWorkspace::task206368() |
|
724 |
{ |
|
725 |
// Make sure the internal list of iconified windows doesn't contain dangling pointers. |
|
726 |
QWorkspace workspace; |
|
727 |
QWidget *child = new QWidget; |
|
728 |
QWidget *window = workspace.addWindow(child); |
|
729 |
workspace.show(); |
|
730 |
child->showMinimized(); |
|
731 |
delete window; |
|
732 |
// This shouldn't crash. |
|
733 |
workspace.arrangeIcons(); |
|
734 |
} |
|
735 |
||
736 |
QTEST_MAIN(tst_QWorkspace) |
|
737 |
#include "tst_qworkspace.moc" |