author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
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 |
||
45 |
#include "qmdisubwindow.h" |
|
46 |
#include "qmdiarea.h" |
|
47 |
||
48 |
#include <QLayout> |
|
49 |
#include <QLineEdit> |
|
50 |
#include <QMainWindow> |
|
51 |
#include <QMenuBar> |
|
52 |
#include <QMenu> |
|
53 |
#include <QGroupBox> |
|
54 |
#include <QTextEdit> |
|
55 |
#include <QLayout> |
|
56 |
#include <QHBoxLayout> |
|
57 |
#include <QByteArray> |
|
58 |
#include <QStyle> |
|
59 |
#include <QStyleOptionTitleBar> |
|
60 |
#include <QPushButton> |
|
61 |
#include <QSizeGrip> |
|
62 |
#if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) |
|
63 |
#include <QMacStyle> |
|
64 |
#endif |
|
65 |
||
66 |
#include "../../shared/util.h" |
|
67 |
||
68 |
||
69 |
QT_BEGIN_NAMESPACE |
|
70 |
#if defined(Q_WS_X11) |
|
71 |
extern void qt_x11_wait_for_window_manager(QWidget *w); |
|
72 |
#endif |
|
73 |
#if !defined(Q_WS_WIN) |
|
74 |
extern bool qt_tab_all_widgets; |
|
75 |
#endif |
|
76 |
QT_END_NAMESPACE |
|
77 |
||
78 |
static inline bool tabAllWidgets() |
|
79 |
{ |
|
80 |
#if !defined(Q_WS_WIN) |
|
81 |
if (qApp->style()->inherits("QMacStyle")) |
|
82 |
return qt_tab_all_widgets; |
|
83 |
#endif |
|
84 |
return true; |
|
85 |
} |
|
86 |
||
87 |
static inline void triggerSignal(QMdiSubWindow *window, QMdiArea *workspace, |
|
88 |
const QByteArray &signal) |
|
89 |
{ |
|
90 |
if (signal == SIGNAL(windowMaximized())) { |
|
91 |
window->showMaximized(); |
|
92 |
qApp->processEvents(); |
|
93 |
if (window->parent()) |
|
94 |
QVERIFY(window->isMaximized()); |
|
95 |
} else if (signal == SIGNAL(windowMinimized())) { |
|
96 |
window->showMinimized(); |
|
97 |
qApp->processEvents(); |
|
98 |
if (window->parent()) |
|
99 |
QVERIFY(window->isMinimized()); |
|
100 |
} else if (signal == SIGNAL(windowRestored())) { |
|
101 |
window->showMaximized(); |
|
102 |
qApp->processEvents(); |
|
103 |
window->showNormal(); |
|
104 |
qApp->processEvents(); |
|
105 |
QVERIFY(!window->isMinimized()); |
|
106 |
QVERIFY(!window->isMaximized()); |
|
107 |
QVERIFY(!window->isShaded()); |
|
108 |
} else if (signal == SIGNAL(aboutToActivate())) { |
|
109 |
if (window->parent()) { |
|
110 |
workspace->setActiveSubWindow(window); |
|
111 |
qApp->processEvents(); |
|
112 |
} |
|
113 |
} else if (signal == SIGNAL(windowActivated())) { |
|
114 |
if (window->parent()) { |
|
115 |
workspace->setActiveSubWindow(window); |
|
116 |
qApp->processEvents(); |
|
117 |
} |
|
118 |
} else if (signal == SIGNAL(windowDeactivated())) { |
|
119 |
if (!window->parent()) |
|
120 |
return; |
|
121 |
workspace->setActiveSubWindow(window); |
|
122 |
qApp->processEvents(); |
|
123 |
workspace->setActiveSubWindow(0); |
|
124 |
qApp->processEvents(); |
|
125 |
} |
|
126 |
} |
|
127 |
||
128 |
// --- from tst_qgraphicsview.cpp --- |
|
129 |
static void sendMousePress(QWidget *widget, const QPoint &point, Qt::MouseButton button = Qt::LeftButton) |
|
130 |
{ |
|
131 |
QMouseEvent event(QEvent::MouseButtonPress, point, widget->mapToGlobal(point), button, 0, 0); |
|
132 |
QApplication::sendEvent(widget, &event); |
|
133 |
} |
|
134 |
||
135 |
static void sendMouseMove(QWidget *widget, const QPoint &point, Qt::MouseButton button = Qt::LeftButton) |
|
136 |
{ |
|
137 |
QMouseEvent event(QEvent::MouseMove, point, widget->mapToGlobal(point), button, button, 0); |
|
138 |
QApplication::sendEvent(widget, &event); |
|
139 |
} |
|
140 |
||
141 |
static void sendMouseRelease(QWidget *widget, const QPoint &point, Qt::MouseButton button = Qt::LeftButton) |
|
142 |
{ |
|
143 |
QMouseEvent event(QEvent::MouseButtonRelease, point, widget->mapToGlobal(point), button, 0, 0); |
|
144 |
QApplication::sendEvent(widget, &event); |
|
145 |
} |
|
146 |
// --- |
|
147 |
||
148 |
static void sendMouseDoubleClick(QWidget *widget, const QPoint &point, Qt::MouseButton button = Qt::LeftButton) |
|
149 |
{ |
|
150 |
sendMousePress(widget, point, button); |
|
151 |
sendMouseRelease(widget, point, button); |
|
152 |
QMouseEvent event(QEvent::MouseButtonDblClick, point, widget->mapToGlobal(point), button, 0, 0); |
|
153 |
QApplication::sendEvent(widget, &event); |
|
154 |
} |
|
155 |
||
156 |
static const Qt::WindowFlags StandardWindowFlags |
|
157 |
= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint; |
|
158 |
static const Qt::WindowFlags DialogWindowFlags |
|
159 |
= Qt::WindowTitleHint | Qt::WindowSystemMenuHint; |
|
160 |
||
161 |
Q_DECLARE_METATYPE(Qt::WindowState); |
|
162 |
Q_DECLARE_METATYPE(Qt::WindowStates); |
|
163 |
Q_DECLARE_METATYPE(Qt::WindowType); |
|
164 |
Q_DECLARE_METATYPE(Qt::WindowFlags); |
|
165 |
||
166 |
//TESTED_CLASS= |
|
167 |
//TESTED_FILES= |
|
168 |
||
169 |
class tst_QMdiSubWindow : public QObject |
|
170 |
{ |
|
171 |
Q_OBJECT |
|
172 |
private slots: |
|
173 |
void initTestCase(); |
|
174 |
void sizeHint(); |
|
175 |
void minimumSizeHint(); |
|
176 |
void minimumSize(); |
|
177 |
void setWidget(); |
|
178 |
void setWindowState_data(); |
|
179 |
void setWindowState(); |
|
180 |
void mainWindowSupport(); |
|
181 |
void emittingOfSignals_data(); |
|
182 |
void emittingOfSignals(); |
|
183 |
void showShaded(); |
|
184 |
void showNormal_data(); |
|
185 |
void showNormal(); |
|
186 |
void setOpaqueResizeAndMove_data(); |
|
187 |
void setOpaqueResizeAndMove(); |
|
188 |
void setWindowFlags_data(); |
|
189 |
void setWindowFlags(); |
|
190 |
void mouseDoubleClick(); |
|
191 |
void setSystemMenu(); |
|
192 |
void restoreFocus(); |
|
193 |
void changeFocusWithTab(); |
|
194 |
void closeEvent(); |
|
195 |
void setWindowTitle(); |
|
196 |
void resizeEvents_data(); |
|
197 |
void resizeEvents(); |
|
198 |
#if defined(Q_WS_MAC) |
|
199 |
void defaultSizeGrip(); |
|
200 |
#endif |
|
201 |
void hideAndShow(); |
|
202 |
void keepWindowMaximizedState(); |
|
203 |
void explicitlyHiddenWidget(); |
|
204 |
void resizeTimer(); |
|
205 |
void fixedMinMaxSize(); |
|
206 |
#if !defined (Q_WS_MAC) && !defined (Q_OS_WINCE) |
|
207 |
void replaceMenuBarWhileMaximized(); |
|
208 |
void closeOnDoubleClick(); |
|
209 |
#endif |
|
210 |
void setFont(); |
|
211 |
void task_188849(); |
|
212 |
void mdiArea(); |
|
213 |
void task_182852(); |
|
214 |
void task_233197(); |
|
215 |
void task_226929(); |
|
216 |
}; |
|
217 |
||
218 |
void tst_QMdiSubWindow::initTestCase() |
|
219 |
{ |
|
220 |
qRegisterMetaType<Qt::WindowStates>("Qt::WindowStates"); |
|
221 |
} |
|
222 |
||
223 |
void tst_QMdiSubWindow::sizeHint() |
|
224 |
{ |
|
225 |
QMdiSubWindow *window = new QMdiSubWindow; |
|
226 |
QCOMPARE(window->sizeHint(), window->minimumSizeHint()); |
|
227 |
window->show(); |
|
228 |
QCOMPARE(window->sizeHint(), window->minimumSizeHint()); |
|
229 |
QMdiArea workspace; |
|
230 |
workspace.addSubWindow(window); |
|
231 |
QCOMPARE(window->sizeHint(), window->minimumSizeHint()); |
|
232 |
} |
|
233 |
||
234 |
void tst_QMdiSubWindow::minimumSizeHint() |
|
235 |
{ |
|
236 |
QMdiSubWindow window; |
|
237 |
window.show(); |
|
238 |
||
239 |
QCOMPARE(window.minimumSizeHint(), qApp->globalStrut()); |
|
240 |
||
241 |
window.setWidget(new QWidget); |
|
242 |
QCOMPARE(window.minimumSizeHint(), window.layout()->minimumSize() |
|
243 |
.expandedTo(qApp->globalStrut())); |
|
244 |
||
245 |
delete window.widget(); |
|
246 |
delete window.layout(); |
|
247 |
window.setWidget(new QWidget); |
|
248 |
QCOMPARE(window.minimumSizeHint(), qApp->globalStrut()); |
|
249 |
||
250 |
window.widget()->show(); |
|
251 |
QCOMPARE(window.minimumSizeHint(), window.widget()->minimumSizeHint() |
|
252 |
.expandedTo(qApp->globalStrut())); |
|
253 |
} |
|
254 |
||
255 |
void tst_QMdiSubWindow::minimumSize() |
|
256 |
{ |
|
257 |
QMdiArea mdiArea; |
|
258 |
mdiArea.resize(200, 200); |
|
259 |
||
260 |
// Check that we respect the minimum size set on the sub-window itself. |
|
261 |
QMdiSubWindow *subWindow1 = mdiArea.addSubWindow(new QWidget); |
|
262 |
subWindow1->setMinimumSize(1000, 1000); |
|
263 |
mdiArea.show(); |
|
264 |
#if defined(Q_WS_X11) |
|
265 |
qt_x11_wait_for_window_manager(&mdiArea); |
|
266 |
#endif |
|
267 |
QCOMPARE(subWindow1->size(), QSize(1000, 1000)); |
|
268 |
||
269 |
// Check that we respect the minimum size set on the internal widget. |
|
270 |
QWidget *widget = new QWidget; |
|
271 |
widget->setMinimumSize(1000, 1000); |
|
272 |
QMdiSubWindow *subWindow2 = mdiArea.addSubWindow(widget); |
|
273 |
QVERIFY(subWindow2->size() != mdiArea.viewport()->size()); |
|
274 |
QCOMPARE(subWindow2->size(), subWindow2->minimumSizeHint()); |
|
275 |
} |
|
276 |
||
277 |
void tst_QMdiSubWindow::setWidget() |
|
278 |
{ |
|
279 |
QMdiSubWindow window; |
|
280 |
window.show(); |
|
281 |
QVERIFY(window.layout()); |
|
282 |
QVERIFY(!window.widget()); |
|
283 |
||
284 |
// QPointer so we can check if the widget is deleted |
|
285 |
QPointer<QWidget> widget = new QWidget; |
|
286 |
widget->setWindowTitle(QString::fromLatin1("DummyTitle")); |
|
287 |
QCOMPARE(widget->windowTitle(), QString::fromLatin1("DummyTitle")); |
|
288 |
window.setWidget(widget); |
|
289 |
QCOMPARE(window.windowTitle(), window.widget()->windowTitle()); |
|
290 |
QCOMPARE(widget->parentWidget(), static_cast<QWidget *>(&window)); |
|
291 |
QVERIFY(!widget->isVisible()); |
|
292 |
QCOMPARE(window.layout()->count(), 1); |
|
293 |
||
294 |
QTest::ignoreMessage(QtWarningMsg,"QMdiSubWindow::setWidget: widget is already set"); |
|
295 |
window.setWidget(widget); |
|
296 |
QCOMPARE(window.widget(), static_cast<QWidget *>(widget)); |
|
297 |
QCOMPARE(widget->parentWidget(), static_cast<QWidget *>(&window)); |
|
298 |
||
299 |
window.setWidget(0); |
|
300 |
QVERIFY(widget); |
|
301 |
QVERIFY(!widget->parent()); |
|
302 |
QVERIFY(!window.widget()); |
|
303 |
QCOMPARE(window.layout()->count(), 0); |
|
304 |
||
305 |
window.setWidget(widget); |
|
306 |
delete window.layout(); |
|
307 |
QVERIFY(!window.layout()); |
|
308 |
QVERIFY(window.widget()); |
|
309 |
QCOMPARE(window.widget()->parentWidget(), static_cast<QWidget *>(&window)); |
|
310 |
||
311 |
delete window.widget(); |
|
312 |
QVERIFY(!widget); |
|
313 |
QVERIFY(!window.widget()); |
|
314 |
} |
|
315 |
||
316 |
void tst_QMdiSubWindow::setWindowState_data() |
|
317 |
{ |
|
318 |
QTest::addColumn<Qt::WindowState>("windowState"); |
|
319 |
||
320 |
QTest::newRow("maximized") << Qt::WindowMaximized; |
|
321 |
QTest::newRow("minimized") << Qt::WindowMinimized; |
|
322 |
QTest::newRow("normalized") << Qt::WindowNoState; |
|
323 |
} |
|
324 |
||
325 |
void tst_QMdiSubWindow::setWindowState() |
|
326 |
{ |
|
327 |
QFETCH(Qt::WindowState, windowState); |
|
328 |
QMdiArea workspace; |
|
329 |
QMdiSubWindow *window = qobject_cast<QMdiSubWindow *>(workspace.addSubWindow(new QLineEdit)); |
|
330 |
window->show(); |
|
331 |
workspace.show(); |
|
332 |
#if defined(Q_WS_X11) |
|
333 |
qt_x11_wait_for_window_manager(&workspace); |
|
334 |
#endif |
|
335 |
||
336 |
QWidget *testWidget = 0; |
|
337 |
for (int iteration = 0; iteration < 2; ++iteration) { |
|
338 |
if (iteration == 0) |
|
339 |
testWidget = window; |
|
340 |
else |
|
341 |
testWidget = window->widget(); |
|
342 |
||
343 |
testWidget->setWindowState(windowState); |
|
344 |
||
345 |
Qt::WindowStates windowStateWindow = window->windowState(); |
|
346 |
windowStateWindow &= ~Qt::WindowActive; |
|
347 |
Qt::WindowStates windowStateWidget = window->widget()->windowState(); |
|
348 |
windowStateWidget &= ~Qt::WindowActive; |
|
349 |
QCOMPARE(windowStateWindow, windowStateWidget); |
|
350 |
||
351 |
switch (windowState) { |
|
352 |
case Qt::WindowNoState: |
|
353 |
QVERIFY(!window->widget()->isMinimized()); |
|
354 |
QVERIFY(!window->widget()->isMaximized()); |
|
355 |
QVERIFY(!window->isMinimized()); |
|
356 |
QVERIFY(!window->isMaximized()); |
|
357 |
break; |
|
358 |
case Qt::WindowMinimized: |
|
359 |
QVERIFY(window->widget()->isMinimized()); |
|
360 |
QVERIFY(window->isMinimized()); |
|
361 |
break; |
|
362 |
case Qt::WindowMaximized: |
|
363 |
QVERIFY(window->widget()->isMaximized()); |
|
364 |
QVERIFY(window->isMaximized()); |
|
365 |
break; |
|
366 |
default: |
|
367 |
break; |
|
368 |
} |
|
369 |
} |
|
370 |
} |
|
371 |
||
372 |
void tst_QMdiSubWindow::mainWindowSupport() |
|
373 |
{ |
|
374 |
QList<QMdiSubWindow *> windows; |
|
375 |
QMdiArea *workspace = new QMdiArea; |
|
376 |
QMainWindow mainWindow; |
|
377 |
mainWindow.setCentralWidget(workspace); |
|
378 |
mainWindow.show(); |
|
379 |
mainWindow.menuBar()->setVisible(true); |
|
380 |
qApp->setActiveWindow(&mainWindow); |
|
381 |
||
382 |
// QMainWindow's window title is empty |
|
383 |
#if !defined(Q_WS_MAC) && !defined(Q_OS_WINCE) |
|
384 |
{ |
|
385 |
QCOMPARE(mainWindow.windowTitle(), QString()); |
|
386 |
QMdiSubWindow *window = workspace->addSubWindow(new QPushButton(QLatin1String("Test"))); |
|
387 |
QString expectedTitle = QLatin1String("MainWindow's title is empty"); |
|
388 |
window->setWindowTitle(expectedTitle); |
|
389 |
QCOMPARE(window->windowTitle(), expectedTitle); |
|
390 |
window->showMaximized(); |
|
391 |
QVERIFY(window->isMaximized()); |
|
392 |
QCOMPARE(window->windowTitle(), expectedTitle); |
|
393 |
QCOMPARE(mainWindow.windowTitle(), expectedTitle); |
|
394 |
window->showNormal(); |
|
395 |
QCOMPARE(window->windowTitle(), expectedTitle); |
|
396 |
QCOMPARE(mainWindow.windowTitle(), QString()); |
|
397 |
window->close(); |
|
398 |
} |
|
399 |
#endif |
|
400 |
||
401 |
QString originalWindowTitle = QString::fromLatin1("MainWindow"); |
|
402 |
mainWindow.setWindowTitle(originalWindowTitle); |
|
403 |
||
404 |
for (int i = 0; i < 5; ++i) { |
|
405 |
mainWindow.menuBar()->setVisible(false); |
|
406 |
||
407 |
QMdiSubWindow *window = new QMdiSubWindow; |
|
408 |
windows.append(window); |
|
409 |
QVERIFY(!window->maximizedButtonsWidget()); |
|
410 |
QVERIFY(!window->maximizedSystemMenuIconWidget()); |
|
411 |
||
412 |
QMdiArea *nestedWorkspace = new QMdiArea; // :-) |
|
413 |
window->setWidget(nestedWorkspace); |
|
414 |
window->widget()->setWindowTitle(QString::fromLatin1("Window %1").arg(i)); |
|
415 |
||
416 |
workspace->addSubWindow(window); |
|
417 |
QVERIFY(!window->maximizedButtonsWidget()); |
|
418 |
QVERIFY(!window->maximizedSystemMenuIconWidget()); |
|
419 |
window->show(); |
|
420 |
||
421 |
// mainWindow.menuBar() is not visible |
|
422 |
window->showMaximized(); |
|
423 |
qApp->processEvents(); |
|
424 |
QVERIFY(window->isMaximized()); |
|
425 |
QVERIFY(!window->maximizedButtonsWidget()); |
|
426 |
QVERIFY(!window->maximizedSystemMenuIconWidget()); |
|
427 |
window->showNormal(); |
|
428 |
||
429 |
// Now it is |
|
430 |
mainWindow.menuBar()->setVisible(true); |
|
431 |
||
432 |
window->showMaximized(); |
|
433 |
qApp->processEvents(); |
|
434 |
QVERIFY(window->isMaximized()); |
|
435 |
#if !defined(Q_WS_MAC) && !defined(Q_OS_WINCE) |
|
436 |
QVERIFY(window->maximizedButtonsWidget()); |
|
437 |
QCOMPARE(window->maximizedButtonsWidget(), mainWindow.menuBar()->cornerWidget(Qt::TopRightCorner)); |
|
438 |
QVERIFY(window->maximizedSystemMenuIconWidget()); |
|
439 |
QCOMPARE(window->maximizedSystemMenuIconWidget(), qobject_cast<QWidget *>(mainWindow.menuBar() |
|
440 |
->cornerWidget(Qt::TopLeftCorner))); |
|
441 |
QCOMPARE(mainWindow.windowTitle(), QString::fromLatin1("%1 - [%2]") |
|
442 |
.arg(originalWindowTitle, window->widget()->windowTitle())); |
|
443 |
#endif |
|
444 |
||
445 |
// Check that nested child windows don't set window title |
|
446 |
nestedWorkspace->show(); |
|
447 |
QMdiSubWindow *nestedWindow = new QMdiSubWindow; |
|
448 |
nestedWindow->setWidget(new QWidget); |
|
449 |
nestedWorkspace->addSubWindow(nestedWindow); |
|
450 |
nestedWindow->widget()->setWindowTitle(QString::fromLatin1("NestedWindow %1").arg(i)); |
|
451 |
nestedWindow->showMaximized(); |
|
452 |
qApp->processEvents(); |
|
453 |
QVERIFY(nestedWindow->isMaximized()); |
|
454 |
QVERIFY(!nestedWindow->maximizedButtonsWidget()); |
|
455 |
QVERIFY(!nestedWindow->maximizedSystemMenuIconWidget()); |
|
456 |
||
457 |
#if !defined(Q_WS_MAC) && !defined(Q_OS_WINCE) |
|
458 |
QCOMPARE(mainWindow.windowTitle(), QString::fromLatin1("%1 - [%2]") |
|
459 |
.arg(originalWindowTitle, window->widget()->windowTitle())); |
|
460 |
#endif |
|
461 |
} |
|
462 |
||
463 |
#if defined(Q_WS_MAC) || defined(Q_OS_WINCE) |
|
464 |
return; |
|
465 |
#endif |
|
466 |
||
467 |
workspace->activateNextSubWindow(); |
|
468 |
qApp->processEvents(); |
|
469 |
foreach (QMdiSubWindow *window, windows) { |
|
470 |
QCOMPARE(workspace->activeSubWindow(), window); |
|
471 |
QVERIFY(window->isMaximized()); |
|
472 |
QVERIFY(window->maximizedButtonsWidget()); |
|
473 |
QCOMPARE(window->maximizedButtonsWidget(), mainWindow.menuBar()->cornerWidget(Qt::TopRightCorner)); |
|
474 |
QVERIFY(window->maximizedSystemMenuIconWidget()); |
|
475 |
QCOMPARE(window->maximizedSystemMenuIconWidget(), qobject_cast<QWidget *>(mainWindow.menuBar() |
|
476 |
->cornerWidget(Qt::TopLeftCorner))); |
|
477 |
QCOMPARE(mainWindow.windowTitle(), QString::fromLatin1("%1 - [%2]") |
|
478 |
.arg(originalWindowTitle, window->widget()->windowTitle())); |
|
479 |
workspace->activateNextSubWindow(); |
|
480 |
qApp->processEvents(); |
|
481 |
} |
|
482 |
} |
|
483 |
||
484 |
// This test was written when QMdiSubWindow emitted separate signals |
|
485 |
void tst_QMdiSubWindow::emittingOfSignals_data() |
|
486 |
{ |
|
487 |
QTest::addColumn<QByteArray>("signal"); |
|
488 |
QTest::addColumn<Qt::WindowState>("watchedState"); |
|
489 |
||
490 |
QTest::newRow("windowMaximized") << QByteArray(SIGNAL(windowMaximized())) << Qt::WindowMaximized; |
|
491 |
QTest::newRow("windowMinimized") << QByteArray(SIGNAL(windowMinimized())) << Qt::WindowMinimized; |
|
492 |
QTest::newRow("windowRestored") << QByteArray(SIGNAL(windowRestored())) << Qt::WindowNoState; |
|
493 |
QTest::newRow("aboutToActivate") << QByteArray(SIGNAL(aboutToActivate())) << Qt::WindowNoState; |
|
494 |
QTest::newRow("windowActivated") << QByteArray(SIGNAL(windowActivated())) << Qt::WindowActive; |
|
495 |
QTest::newRow("windowDeactivated") << QByteArray(SIGNAL(windowDeactivated())) << Qt::WindowActive; |
|
496 |
} |
|
497 |
||
498 |
void tst_QMdiSubWindow::emittingOfSignals() |
|
499 |
{ |
|
500 |
QFETCH(QByteArray, signal); |
|
501 |
QFETCH(Qt::WindowState, watchedState); |
|
502 |
QMdiArea workspace; |
|
503 |
workspace.show(); |
|
504 |
qApp->processEvents(); |
|
505 |
qApp->setActiveWindow(&workspace); |
|
506 |
QMdiSubWindow *window = qobject_cast<QMdiSubWindow *>(workspace.addSubWindow(new QWidget)); |
|
507 |
qApp->processEvents(); |
|
508 |
window->show(); |
|
509 |
if (signal != SIGNAL(windowRestored())) |
|
510 |
workspace.setActiveSubWindow(0); |
|
511 |
qApp->processEvents(); |
|
512 |
||
513 |
QSignalSpy spy(window, signal == SIGNAL(aboutToActivate()) |
|
514 |
? signal.data() |
|
515 |
: SIGNAL(windowStateChanged(Qt::WindowStates, Qt::WindowStates))); |
|
516 |
QVERIFY(spy.isEmpty()); |
|
517 |
triggerSignal(window, &workspace, signal); |
|
518 |
// Unless the signal is windowRestored or windowDeactivated, |
|
519 |
// we're already in correct state and nothing should happen. |
|
520 |
if (signal != SIGNAL(windowRestored()) && signal != SIGNAL(windowDeactivated())) |
|
521 |
triggerSignal(window, &workspace, signal); |
|
522 |
||
523 |
int count = 0; |
|
524 |
if (signal == SIGNAL(aboutToActivate())) { |
|
525 |
count += spy.count(); |
|
526 |
} else { |
|
527 |
for (int i = 0; i < spy.count(); ++i) { |
|
528 |
Qt::WindowStates oldState = qvariant_cast<Qt::WindowStates>(spy.at(i).at(0)); |
|
529 |
Qt::WindowStates newState = qvariant_cast<Qt::WindowStates>(spy.at(i).at(1)); |
|
530 |
if (watchedState != Qt::WindowNoState) { |
|
531 |
if (!(oldState & watchedState) && (newState & watchedState)) |
|
532 |
++count; |
|
533 |
} else { |
|
534 |
if ((oldState & (Qt::WindowMinimized | Qt::WindowMaximized)) |
|
535 |
&& (newState & (watchedState | Qt::WindowActive))) { |
|
536 |
++count; |
|
537 |
} |
|
538 |
} |
|
539 |
} |
|
540 |
} |
|
541 |
QCOMPARE(count, 1); |
|
542 |
||
543 |
window->setParent(0); |
|
544 |
window->showNormal(); |
|
545 |
#if defined(Q_WS_X11) |
|
546 |
qt_x11_wait_for_window_manager(window); |
|
547 |
#endif |
|
548 |
qApp->processEvents(); |
|
549 |
||
550 |
spy.clear(); |
|
551 |
triggerSignal(window, &workspace, signal); |
|
552 |
QCOMPARE(spy.count(), 0); |
|
553 |
||
554 |
delete window; |
|
555 |
window = 0; |
|
556 |
} |
|
557 |
||
558 |
void tst_QMdiSubWindow::showShaded() |
|
559 |
{ |
|
560 |
QMdiArea workspace; |
|
561 |
QMdiSubWindow *window = workspace.addSubWindow(new QLineEdit); |
|
562 |
window->resize(300, 300); |
|
563 |
qApp->processEvents(); |
|
564 |
workspace.show(); |
|
565 |
#ifdef Q_WS_X11 |
|
566 |
qt_x11_wait_for_window_manager(&workspace); |
|
567 |
#endif |
|
568 |
||
569 |
QVERIFY(!window->isShaded()); |
|
570 |
QVERIFY(!window->isMaximized()); |
|
571 |
||
572 |
QCOMPARE(window->size(), QSize(300, 300)); |
|
573 |
QRect restoreGeometry = window->geometry(); |
|
574 |
window->showShaded(); |
|
575 |
QVERIFY(window->isShaded()); |
|
576 |
QVERIFY(window->isMinimized()); |
|
577 |
||
578 |
window->showNormal(); |
|
579 |
QVERIFY(!window->isShaded()); |
|
580 |
QVERIFY(!window->isMinimized()); |
|
581 |
QCOMPARE(window->geometry(), restoreGeometry); |
|
582 |
window->showShaded(); |
|
583 |
||
584 |
window->showNormal(); |
|
585 |
QVERIFY(!window->isShaded()); |
|
586 |
QVERIFY(!window->isMinimized()); |
|
587 |
QCOMPARE(window->geometry(), restoreGeometry); |
|
588 |
window->showMinimized(); |
|
589 |
window->showMaximized(); |
|
590 |
window->showShaded(); |
|
591 |
QCOMPARE(window->width(), workspace.contentsRect().width()); |
|
592 |
window->showNormal(); |
|
593 |
QCOMPARE(window->geometry(), workspace.contentsRect()); |
|
594 |
||
595 |
window->resize(300, 300); |
|
596 |
QCOMPARE(window->size(), QSize(300, 300)); |
|
597 |
window->showShaded(); |
|
598 |
window->showNormal(); |
|
599 |
QTest::qWait(250); |
|
600 |
||
601 |
#ifdef Q_OS_WINCE |
|
602 |
QSKIP("Until we have a QEvent::WindowFlagsChange event, this will skip", SkipAll); |
|
603 |
#endif |
|
604 |
||
605 |
const QSize minimumSizeHint = window->minimumSizeHint(); |
|
606 |
QVERIFY(minimumSizeHint.height() < 300); |
|
607 |
const int maxHeightDiff = 300 - minimumSizeHint.height(); |
|
608 |
||
609 |
// Calculate mouse position for bottom right corner and simulate a |
|
610 |
// vertical resize with the mouse. |
|
611 |
int offset = window->style()->pixelMetric(QStyle::PM_MDIFrameWidth) / 2; |
|
612 |
QPoint mousePosition(window->width() - qMax(offset, 2), window->height() - qMax(offset, 2)); |
|
613 |
QWidget *mouseReceiver = 0; |
|
614 |
#ifdef Q_WS_MAC |
|
615 |
if (qobject_cast<QMacStyle*>(window->style())) |
|
616 |
mouseReceiver = qFindChild<QSizeGrip *>(window); |
|
617 |
else |
|
618 |
#endif |
|
619 |
mouseReceiver = window; |
|
620 |
QVERIFY(mouseReceiver); |
|
621 |
sendMouseMove(mouseReceiver, mousePosition, Qt::NoButton); |
|
622 |
sendMousePress(mouseReceiver, mousePosition); |
|
623 |
||
624 |
for (int i = 0; i < maxHeightDiff + 20; ++i) { |
|
625 |
--mousePosition.ry(); |
|
626 |
sendMouseMove(mouseReceiver, mousePosition); |
|
627 |
} |
|
628 |
||
629 |
sendMouseRelease(mouseReceiver, mousePosition); |
|
630 |
// Make sure we respect the minimumSizeHint! |
|
631 |
QCOMPARE(window->height(), minimumSizeHint.height()); |
|
632 |
||
633 |
window->showShaded(); |
|
634 |
window->setParent(0); |
|
635 |
window->show(); |
|
636 |
QVERIFY(!window->isShaded()); |
|
637 |
||
638 |
delete window; |
|
639 |
} |
|
640 |
||
641 |
void tst_QMdiSubWindow::showNormal_data() |
|
642 |
{ |
|
643 |
QTest::addColumn<QByteArray>("slot"); |
|
644 |
||
645 |
QTest::newRow("showMinimized") << QByteArray("showMinimized"); |
|
646 |
QTest::newRow("showMaximized") << QByteArray("showMaximized"); |
|
647 |
QTest::newRow("showShaded") << QByteArray("showShaded"); |
|
648 |
} |
|
649 |
||
650 |
void tst_QMdiSubWindow::showNormal() |
|
651 |
{ |
|
652 |
QFETCH(QByteArray, slot); |
|
653 |
||
654 |
QMdiArea workspace; |
|
655 |
QWidget *window = workspace.addSubWindow(new QWidget); |
|
656 |
qApp->processEvents(); |
|
657 |
workspace.show(); |
|
658 |
window->show(); |
|
659 |
#if defined(Q_WS_X11) |
|
660 |
qt_x11_wait_for_window_manager(&workspace); |
|
661 |
#endif |
|
662 |
||
663 |
QRect originalGeometry = window->geometry(); |
|
664 |
QVERIFY(QMetaObject::invokeMethod(window, slot.data())); |
|
665 |
qApp->processEvents(); |
|
666 |
window->showNormal(); |
|
667 |
qApp->processEvents(); |
|
668 |
QCOMPARE(window->geometry(), originalGeometry); |
|
669 |
} |
|
670 |
||
671 |
class EventSpy : public QObject |
|
672 |
{ |
|
673 |
public: |
|
674 |
EventSpy(QObject *object, QEvent::Type event) |
|
675 |
: eventToSpy(event), _count(0) |
|
676 |
{ |
|
677 |
if (object) |
|
678 |
object->installEventFilter(this); |
|
679 |
} |
|
680 |
||
681 |
int count() const { return _count; } |
|
682 |
void clear() { _count = 0; } |
|
683 |
||
684 |
protected: |
|
685 |
bool eventFilter(QObject *object, QEvent *event) |
|
686 |
{ |
|
687 |
if (event->type() == eventToSpy) |
|
688 |
++_count; |
|
689 |
return QObject::eventFilter(object, event); |
|
690 |
} |
|
691 |
||
692 |
private: |
|
693 |
QEvent::Type eventToSpy; |
|
694 |
int _count; |
|
695 |
}; |
|
696 |
||
697 |
void tst_QMdiSubWindow::setOpaqueResizeAndMove_data() |
|
698 |
{ |
|
699 |
QTest::addColumn<bool>("opaqueMode"); |
|
700 |
QTest::addColumn<int>("geometryCount"); |
|
701 |
QTest::addColumn<int>("expectedGeometryCount"); |
|
702 |
QTest::addColumn<QSize>("workspaceSize"); |
|
703 |
QTest::addColumn<QSize>("windowSize"); |
|
704 |
||
705 |
QTest::newRow("normal mode") << true<< 20 << 20 << QSize(400, 400) << QSize(200, 200); |
|
706 |
QTest::newRow("rubberband mode") << false << 20 << 1 << QSize(400, 400) << QSize(200, 200); |
|
707 |
} |
|
708 |
||
709 |
void tst_QMdiSubWindow::setOpaqueResizeAndMove() |
|
710 |
{ |
|
711 |
#if defined (QT_NO_CURSOR) || defined (Q_OS_WINCE_WM) //For Windows CE we will set QT_NO_CURSOR if there is no cursor support |
|
712 |
QSKIP("No cursor available", SkipAll); |
|
713 |
#endif |
|
714 |
QFETCH(bool, opaqueMode); |
|
715 |
QFETCH(int, geometryCount); |
|
716 |
QFETCH(int, expectedGeometryCount); |
|
717 |
QFETCH(QSize, workspaceSize); |
|
718 |
QFETCH(QSize, windowSize); |
|
719 |
||
720 |
QMdiArea workspace; |
|
721 |
QMdiSubWindow *window = qobject_cast<QMdiSubWindow *>(workspace.addSubWindow(new QWidget)); |
|
722 |
qApp->processEvents(); |
|
723 |
workspace.resize(workspaceSize); |
|
724 |
workspace.show(); |
|
725 |
#ifdef Q_WS_X11 |
|
726 |
qt_x11_wait_for_window_manager(&workspace); |
|
727 |
#endif |
|
728 |
||
729 |
QWidget *mouseReceiver = 0; |
|
730 |
if (window->style()->inherits("QMacStyle")) |
|
731 |
mouseReceiver = qFindChild<QSizeGrip *>(window); |
|
732 |
else |
|
733 |
mouseReceiver = window; |
|
734 |
QVERIFY(mouseReceiver); |
|
735 |
||
736 |
// ----------------------------- resize ----------------------------- |
|
737 |
{ |
|
738 |
// setOpaqueResize |
|
739 |
window->setOption(QMdiSubWindow::RubberBandResize, !opaqueMode); |
|
740 |
QCOMPARE(window->testOption(QMdiSubWindow::RubberBandResize), !opaqueMode); |
|
741 |
||
742 |
// Check that the event spy actually works |
|
743 |
EventSpy resizeSpy(window, QEvent::Resize); |
|
744 |
QCOMPARE(resizeSpy.count(), 0); |
|
745 |
window->resize(windowSize); |
|
746 |
QCOMPARE(window->size(), windowSize); |
|
747 |
QCOMPARE(resizeSpy.count(), 1); |
|
748 |
resizeSpy.clear(); |
|
749 |
QCOMPARE(resizeSpy.count(), 0); |
|
750 |
||
751 |
QTest::qWait(250); // delayed update of dirty regions |
|
752 |
||
753 |
// Enter resize mode. |
|
754 |
int offset = window->style()->pixelMetric(QStyle::PM_MDIFrameWidth) / 2; |
|
755 |
QPoint mousePosition(mouseReceiver->width() - qMax(offset, 2), mouseReceiver->height() - qMax(offset, 2)); |
|
756 |
sendMouseMove(mouseReceiver, mousePosition, Qt::NoButton); |
|
757 |
sendMousePress(mouseReceiver, mousePosition); |
|
758 |
||
759 |
// The window itself is the grabber in rubberband mode |
|
760 |
if (!opaqueMode) { |
|
761 |
mouseReceiver = window; |
|
762 |
mousePosition = QPoint(window->width() - qMax(offset, 2), window->height() - qMax(offset, 2)); |
|
763 |
} |
|
764 |
||
765 |
// Trigger resize events |
|
766 |
for (int i = 0; i < geometryCount; ++i) { |
|
767 |
if (mouseReceiver == window) { |
|
768 |
++mousePosition.rx(); |
|
769 |
++mousePosition.ry(); |
|
770 |
sendMouseMove(mouseReceiver, mousePosition); |
|
771 |
} else { |
|
772 |
sendMouseMove(mouseReceiver, mousePosition + QPoint(1, 1)); |
|
773 |
} |
|
774 |
} |
|
775 |
||
776 |
// Leave resize mode |
|
777 |
sendMouseRelease(mouseReceiver, mousePosition); |
|
778 |
QCOMPARE(resizeSpy.count(), expectedGeometryCount); |
|
779 |
QCOMPARE(window->size(), windowSize + QSize(geometryCount, geometryCount)); |
|
780 |
} |
|
781 |
||
782 |
// ------------------------------ move ------------------------------ |
|
783 |
{ |
|
784 |
// setOpaqueMove |
|
785 |
window->setOption(QMdiSubWindow::RubberBandMove, !opaqueMode); |
|
786 |
QCOMPARE(window->testOption(QMdiSubWindow::RubberBandMove), !opaqueMode); |
|
787 |
||
788 |
EventSpy moveSpy(window, QEvent::Move); |
|
789 |
QCOMPARE(moveSpy.count(), 0); |
|
790 |
window->move(30, 30); |
|
791 |
QCOMPARE(moveSpy.count(), 1); |
|
792 |
moveSpy.clear(); |
|
793 |
||
794 |
// Enter move mode |
|
795 |
QStyleOptionTitleBar options; |
|
796 |
options.initFrom(window); |
|
797 |
int height = window->style()->pixelMetric(QStyle::PM_TitleBarHeight, &options); |
|
798 |
#if defined(Q_WS_MAC) |
|
799 |
// ### Remove this after mac style has been fixed |
|
800 |
height -= 4; |
|
801 |
#endif |
|
802 |
QPoint mousePosition(window->width() / 2, height - 1); |
|
803 |
sendMouseMove(window, mousePosition, Qt::NoButton); |
|
804 |
sendMousePress(window, mousePosition); |
|
805 |
||
806 |
// Trigger move events |
|
807 |
for (int i = 0; i < geometryCount; ++i) { |
|
808 |
++mousePosition.rx(); |
|
809 |
++mousePosition.ry(); |
|
810 |
sendMouseMove(window, mousePosition); |
|
811 |
} |
|
812 |
||
813 |
// Leave move mode |
|
814 |
sendMouseRelease(window, mousePosition); |
|
815 |
QCOMPARE(moveSpy.count(), expectedGeometryCount); |
|
816 |
QCOMPARE(window->size(), windowSize + QSize(geometryCount, geometryCount)); |
|
817 |
} |
|
818 |
} |
|
819 |
||
820 |
void tst_QMdiSubWindow::setWindowFlags_data() |
|
821 |
{ |
|
822 |
QTest::addColumn<Qt::WindowType>("windowType"); |
|
823 |
QTest::addColumn<Qt::WindowType>("expectedWindowType"); |
|
824 |
QTest::addColumn<Qt::WindowFlags>("customFlags"); |
|
825 |
QTest::addColumn<Qt::WindowFlags>("expectedCustomFlags"); |
|
826 |
||
827 |
// NB! If 'expectedCustomFlags' is set to 'Qt::WindowFlags(0)' |
|
828 |
// and nothing else, it means we're expecting the same as customFlags. |
|
829 |
||
830 |
// Standard window types with no custom flags set. |
|
831 |
QTest::newRow("Qt::Widget") << Qt::Widget << Qt::SubWindow |
|
832 |
<< Qt::WindowFlags(0) << StandardWindowFlags; |
|
833 |
QTest::newRow("Qt::Window") << Qt::Window << Qt::SubWindow |
|
834 |
<< Qt::WindowFlags(0) << StandardWindowFlags; |
|
835 |
QTest::newRow("Qt::Dialog") << Qt::Dialog << Qt::SubWindow |
|
836 |
<< Qt::WindowFlags(0) << DialogWindowFlags; |
|
837 |
QTest::newRow("Qt::Sheet") << Qt::Sheet << Qt::SubWindow |
|
838 |
<< Qt::WindowFlags(0) << StandardWindowFlags; |
|
839 |
QTest::newRow("Qt::Drawer") << Qt::Drawer << Qt::SubWindow |
|
840 |
<< Qt::WindowFlags(0) << StandardWindowFlags; |
|
841 |
QTest::newRow("Qt::Popup") << Qt::Popup << Qt::SubWindow |
|
842 |
<< Qt::WindowFlags(0) << StandardWindowFlags; |
|
843 |
QTest::newRow("Qt::Tool") << Qt::Tool << Qt::SubWindow |
|
844 |
<< Qt::WindowFlags(0) << StandardWindowFlags; |
|
845 |
QTest::newRow("Qt::ToolTip") << Qt::ToolTip << Qt::SubWindow |
|
846 |
<< Qt::WindowFlags(0) << StandardWindowFlags; |
|
847 |
QTest::newRow("Qt::SplashScreen") << Qt::SplashScreen << Qt::SubWindow |
|
848 |
<< Qt::WindowFlags(0) << StandardWindowFlags; |
|
849 |
QTest::newRow("Qt::Desktop") << Qt::Desktop << Qt::SubWindow |
|
850 |
<< Qt::WindowFlags(0) << StandardWindowFlags; |
|
851 |
QTest::newRow("Qt::SubWindow") << Qt::SubWindow << Qt::SubWindow |
|
852 |
<< Qt::WindowFlags(0) << StandardWindowFlags; |
|
853 |
||
854 |
// Custom flags |
|
855 |
QTest::newRow("Title") << Qt::SubWindow << Qt::SubWindow |
|
856 |
<< (Qt::WindowTitleHint | Qt::WindowFlags(0)) |
|
857 |
<< Qt::WindowFlags(0); |
|
858 |
QTest::newRow("TitleAndMin") << Qt::SubWindow << Qt::SubWindow |
|
859 |
<< (Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint) |
|
860 |
<< Qt::WindowFlags(0); |
|
861 |
QTest::newRow("TitleAndMax") << Qt::SubWindow << Qt::SubWindow |
|
862 |
<< (Qt::WindowTitleHint | Qt::WindowMaximizeButtonHint) |
|
863 |
<< Qt::WindowFlags(0); |
|
864 |
QTest::newRow("TitleAndMinMax") << Qt::SubWindow << Qt::SubWindow |
|
865 |
<< (Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint) |
|
866 |
<< Qt::WindowFlags(0); |
|
867 |
QTest::newRow("Standard") << Qt::SubWindow << Qt::SubWindow |
|
868 |
<< StandardWindowFlags |
|
869 |
<< Qt::WindowFlags(0); |
|
870 |
QTest::newRow("StandardAndShade") << Qt::SubWindow << Qt::SubWindow |
|
871 |
<< (StandardWindowFlags | Qt::WindowShadeButtonHint) |
|
872 |
<< Qt::WindowFlags(0); |
|
873 |
QTest::newRow("StandardAndContext") << Qt::SubWindow << Qt::SubWindow |
|
874 |
<< (StandardWindowFlags | Qt::WindowContextHelpButtonHint) |
|
875 |
<< Qt::WindowFlags(0); |
|
876 |
QTest::newRow("StandardAndStaysOnTop") << Qt::SubWindow << Qt::SubWindow |
|
877 |
<< (StandardWindowFlags | Qt::WindowStaysOnTopHint) |
|
878 |
<< Qt::WindowFlags(0); |
|
879 |
QTest::newRow("StandardAndFrameless") << Qt::SubWindow << Qt::SubWindow |
|
880 |
<< (StandardWindowFlags | Qt::FramelessWindowHint) |
|
881 |
<< (Qt::FramelessWindowHint | Qt::WindowFlags(0)); |
|
882 |
QTest::newRow("StandardAndFramelessAndStaysOnTop") << Qt::SubWindow << Qt::SubWindow |
|
883 |
<< (StandardWindowFlags | Qt::FramelessWindowHint |
|
884 |
| Qt::WindowStaysOnTopHint) |
|
885 |
<< (Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); |
|
886 |
QTest::newRow("Shade") << Qt::SubWindow << Qt::SubWindow |
|
887 |
<< (Qt::WindowShadeButtonHint | Qt::WindowFlags(0)) |
|
888 |
<< (StandardWindowFlags | Qt::WindowShadeButtonHint); |
|
889 |
QTest::newRow("ShadeAndCustomize") << Qt::SubWindow << Qt::SubWindow |
|
890 |
<< (Qt::WindowShadeButtonHint | Qt::CustomizeWindowHint) |
|
891 |
<< Qt::WindowFlags(0); |
|
892 |
QTest::newRow("Context") << Qt::SubWindow << Qt::SubWindow |
|
893 |
<< (Qt::WindowContextHelpButtonHint | Qt::WindowFlags(0)) |
|
894 |
<< (StandardWindowFlags | Qt::WindowContextHelpButtonHint); |
|
895 |
QTest::newRow("ContextAndCustomize") << Qt::SubWindow << Qt::SubWindow |
|
896 |
<< (Qt::WindowContextHelpButtonHint | Qt::CustomizeWindowHint) |
|
897 |
<< Qt::WindowFlags(0); |
|
898 |
QTest::newRow("ShadeAndContext") << Qt::SubWindow << Qt::SubWindow |
|
899 |
<< (Qt::WindowShadeButtonHint | Qt::WindowContextHelpButtonHint) |
|
900 |
<< (StandardWindowFlags | Qt::WindowShadeButtonHint | Qt::WindowContextHelpButtonHint); |
|
901 |
QTest::newRow("ShadeAndContextAndCustomize") << Qt::SubWindow << Qt::SubWindow |
|
902 |
<< (Qt::WindowShadeButtonHint | Qt::WindowContextHelpButtonHint | Qt::CustomizeWindowHint) |
|
903 |
<< Qt::WindowFlags(0); |
|
904 |
QTest::newRow("OnlyCustomize") << Qt::SubWindow << Qt::SubWindow |
|
905 |
<< (Qt::CustomizeWindowHint | Qt::WindowFlags(0)) |
|
906 |
<< Qt::WindowFlags(0); |
|
907 |
} |
|
908 |
||
909 |
void tst_QMdiSubWindow::setWindowFlags() |
|
910 |
{ |
|
911 |
QSKIP("Until we have a QEvent::WindowFlagsChange event, this will skip", SkipAll); |
|
912 |
QFETCH(Qt::WindowType, windowType); |
|
913 |
QFETCH(Qt::WindowType, expectedWindowType); |
|
914 |
QFETCH(Qt::WindowFlags, customFlags); |
|
915 |
QFETCH(Qt::WindowFlags, expectedCustomFlags); |
|
916 |
||
917 |
QMdiArea workspace; |
|
918 |
QMdiSubWindow *window = qobject_cast<QMdiSubWindow *>(workspace.addSubWindow(new QWidget)); |
|
919 |
qApp->processEvents(); |
|
920 |
workspace.show(); |
|
921 |
window->show(); |
|
922 |
#if defined(Q_WS_X11) |
|
923 |
qt_x11_wait_for_window_manager(&workspace); |
|
924 |
#endif |
|
925 |
||
926 |
window->setWindowFlags(windowType | customFlags); |
|
927 |
QCOMPARE(window->windowType(), expectedWindowType); |
|
928 |
if (!expectedCustomFlags) // We expect the same as 'customFlags' |
|
929 |
QCOMPARE(window->windowFlags() & ~expectedWindowType, customFlags); |
|
930 |
else |
|
931 |
QCOMPARE(window->windowFlags() & ~expectedWindowType, expectedCustomFlags); |
|
932 |
||
933 |
} |
|
934 |
||
935 |
void tst_QMdiSubWindow::mouseDoubleClick() |
|
936 |
{ |
|
937 |
QMdiArea workspace; |
|
938 |
QMdiSubWindow *window = qobject_cast<QMdiSubWindow *>(workspace.addSubWindow(new QWidget)); |
|
939 |
qApp->processEvents(); |
|
940 |
workspace.show(); |
|
941 |
window->show(); |
|
942 |
||
943 |
QVERIFY(!window->isMaximized()); |
|
944 |
QVERIFY(!window->isShaded()); |
|
945 |
||
946 |
QRect originalGeometry = window->geometry(); |
|
947 |
||
948 |
// Calculate mouse position |
|
949 |
QStyleOptionTitleBar options; |
|
950 |
options.initFrom(window); |
|
951 |
int height = window->style()->pixelMetric(QStyle::PM_TitleBarHeight, &options); |
|
952 |
// ### Remove this after mac style has been fixed |
|
953 |
if (window->style()->inherits("QMacStyle")) |
|
954 |
height -= 4; |
|
955 |
// has border |
|
956 |
if (!window->style()->styleHint(QStyle::SH_TitleBar_NoBorder, &options, window)) |
|
957 |
height += window->isMinimized() ? 8 : 4; |
|
958 |
QPoint mousePosition(window->width() / 2, height - 1); |
|
959 |
sendMouseMove(window, mousePosition, Qt::NoButton); |
|
960 |
||
961 |
// Without Qt::WindowShadeButtonHint flag set |
|
962 |
sendMouseDoubleClick(window, mousePosition); |
|
963 |
qApp->processEvents(); |
|
964 |
QVERIFY(window->isMaximized()); |
|
965 |
||
966 |
sendMouseDoubleClick(window, mousePosition); |
|
967 |
qApp->processEvents(); |
|
968 |
QVERIFY(!window->isMaximized()); |
|
969 |
QCOMPARE(window->geometry(), originalGeometry); |
|
970 |
||
971 |
// With Qt::WindowShadeButtonHint flag set |
|
972 |
QSKIP("Until we have a QEvent::WindowFlagsChange event, this will skip", SkipAll); |
|
973 |
window->setWindowFlags(window->windowFlags() | Qt::WindowShadeButtonHint); |
|
974 |
QVERIFY(window->windowFlags() & Qt::WindowShadeButtonHint); |
|
975 |
originalGeometry = window->geometry(); |
|
976 |
sendMouseDoubleClick(window, mousePosition); |
|
977 |
qApp->processEvents(); |
|
978 |
QVERIFY(window->isShaded()); |
|
979 |
||
980 |
sendMouseDoubleClick(window, mousePosition); |
|
981 |
qApp->processEvents(); |
|
982 |
QVERIFY(!window->isShaded()); |
|
983 |
QCOMPARE(window->geometry(), originalGeometry); |
|
984 |
||
985 |
window->showMinimized(); |
|
986 |
QVERIFY(window->isMinimized()); |
|
987 |
sendMouseDoubleClick(window, mousePosition); |
|
988 |
QVERIFY(!window->isMinimized()); |
|
989 |
QCOMPARE(window->geometry(), originalGeometry); |
|
990 |
} |
|
991 |
||
992 |
void tst_QMdiSubWindow::setSystemMenu() |
|
993 |
{ |
|
994 |
QMdiSubWindow *subWindow = new QMdiSubWindow; |
|
995 |
subWindow->resize(200, 50); |
|
996 |
QPointer<QMenu>systemMenu = subWindow->systemMenu(); |
|
997 |
QVERIFY(systemMenu); |
|
998 |
QCOMPARE(subWindow->actions(), systemMenu->actions()); |
|
999 |
||
1000 |
QMainWindow mainWindow; |
|
1001 |
QMdiArea *mdiArea = new QMdiArea; |
|
1002 |
mdiArea->addSubWindow(subWindow); |
|
1003 |
mainWindow.setCentralWidget(mdiArea); |
|
1004 |
mainWindow.menuBar(); |
|
1005 |
mainWindow.show(); |
|
1006 |
QTest::qWaitForWindowShown(&mainWindow); |
|
1007 |
QTest::qWait(60); |
|
1008 |
||
1009 |
||
1010 |
QTRY_VERIFY(subWindow->isVisible()); |
|
1011 |
QPoint globalPopupPos; |
|
1012 |
||
1013 |
// Show system menu |
|
1014 |
QVERIFY(!qApp->activePopupWidget()); |
|
1015 |
subWindow->showSystemMenu(); |
|
1016 |
QTest::qWait(25); |
|
1017 |
QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); |
|
1018 |
QTRY_COMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), |
|
1019 |
(globalPopupPos = subWindow->mapToGlobal(subWindow->contentsRect().topLeft())) ); |
|
1020 |
||
1021 |
systemMenu->hide(); |
|
1022 |
QVERIFY(!qApp->activePopupWidget()); |
|
1023 |
||
1024 |
QTest::ignoreMessage(QtWarningMsg, "QMdiSubWindow::setSystemMenu: system menu is already set"); |
|
1025 |
subWindow->setSystemMenu(systemMenu); |
|
1026 |
||
1027 |
subWindow->setSystemMenu(0); |
|
1028 |
QVERIFY(!systemMenu); // systemMenu is QPointer |
|
1029 |
||
1030 |
systemMenu = new QMenu(subWindow); |
|
1031 |
systemMenu->addAction(QIcon(subWindow->style()->standardIcon(QStyle::SP_TitleBarCloseButton)), |
|
1032 |
QObject::tr("&Close"), subWindow, SLOT(close())); |
|
1033 |
subWindow->setSystemMenu(systemMenu); |
|
1034 |
QCOMPARE(subWindow->systemMenu(), qobject_cast<QMenu *>(systemMenu)); |
|
1035 |
QCOMPARE(subWindow->systemMenu()->parentWidget(), static_cast<QWidget *>(subWindow)); |
|
1036 |
QCOMPARE(subWindow->systemMenu()->actions().count(), 1); |
|
1037 |
||
1038 |
// Show the new system menu |
|
1039 |
QVERIFY(!qApp->activePopupWidget()); |
|
1040 |
subWindow->showSystemMenu(); |
|
1041 |
QTest::qWait(25); |
|
1042 |
QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); |
|
1043 |
QTRY_COMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); |
|
1044 |
||
1045 |
systemMenu->hide(); |
|
1046 |
QVERIFY(!qApp->activePopupWidget()); |
|
1047 |
||
1048 |
#if !defined (Q_WS_MAC) && !defined (Q_OS_WINCE) |
|
1049 |
// System menu in menu bar. |
|
1050 |
subWindow->showMaximized(); |
|
1051 |
QVERIFY(subWindow->isMaximized()); |
|
1052 |
QWidget *menuLabel = subWindow->maximizedSystemMenuIconWidget(); |
|
1053 |
QVERIFY(menuLabel); |
|
1054 |
subWindow->showSystemMenu(); |
|
1055 |
QTest::qWait(25); |
|
1056 |
QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); |
|
1057 |
QCOMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), |
|
1058 |
(globalPopupPos = menuLabel->mapToGlobal(QPoint(0, menuLabel->y() + menuLabel->height())))); |
|
1059 |
systemMenu->hide(); |
|
1060 |
QTRY_VERIFY(!qApp->activePopupWidget()); |
|
1061 |
subWindow->showNormal(); |
|
1062 |
#endif |
|
1063 |
||
1064 |
// Reverse |
|
1065 |
qApp->setLayoutDirection(Qt::RightToLeft); |
|
1066 |
qApp->processEvents(); |
|
1067 |
mainWindow.updateGeometry(); |
|
1068 |
QTest::qWait(150); |
|
1069 |
||
1070 |
subWindow->showSystemMenu(); |
|
1071 |
QTest::qWait(250); |
|
1072 |
QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); |
|
1073 |
// + QPoint(1, 0) because topRight() == QPoint(left() + width() -1, top()) |
|
1074 |
globalPopupPos = subWindow->mapToGlobal(subWindow->contentsRect().topRight()) + QPoint(1, 0); |
|
1075 |
globalPopupPos -= QPoint(systemMenu->sizeHint().width(), 0); |
|
1076 |
QTRY_COMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); |
|
1077 |
||
1078 |
systemMenu->hide(); |
|
1079 |
QVERIFY(!qApp->activePopupWidget()); |
|
1080 |
||
1081 |
#if !defined (Q_WS_MAC) && !defined (Q_OS_WINCE) |
|
1082 |
// System menu in menu bar in reverse mode. |
|
1083 |
subWindow->showMaximized(); |
|
1084 |
QVERIFY(subWindow->isMaximized()); |
|
1085 |
menuLabel = subWindow->maximizedSystemMenuIconWidget(); |
|
1086 |
QVERIFY(menuLabel); |
|
1087 |
subWindow->showSystemMenu(); |
|
1088 |
QTest::qWait(250); |
|
1089 |
QTRY_COMPARE(qApp->activePopupWidget(), qobject_cast<QWidget *>(systemMenu)); |
|
1090 |
globalPopupPos = menuLabel->mapToGlobal(QPoint(menuLabel->width(), menuLabel->y() + menuLabel->height())); |
|
1091 |
globalPopupPos -= QPoint(systemMenu->sizeHint().width(), 0); |
|
1092 |
QTRY_COMPARE(systemMenu->mapToGlobal(QPoint(0, 0)), globalPopupPos); |
|
1093 |
#endif |
|
1094 |
||
1095 |
delete systemMenu; |
|
1096 |
QVERIFY(!qApp->activePopupWidget()); |
|
1097 |
QVERIFY(!subWindow->systemMenu()); |
|
1098 |
||
1099 |
// Restore layout direction. |
|
1100 |
qApp->setLayoutDirection(Qt::LeftToRight); |
|
1101 |
} |
|
1102 |
||
1103 |
void tst_QMdiSubWindow::restoreFocus() |
|
1104 |
{ |
|
1105 |
// Create complex layout. |
|
1106 |
QGroupBox *box = new QGroupBox(tr("GroupBox")); |
|
1107 |
box->setCheckable(true); |
|
1108 |
||
1109 |
QGroupBox *box1 = new QGroupBox(tr("&TopLeft")); |
|
1110 |
box1->setLayout(new QHBoxLayout); |
|
1111 |
box1->layout()->addWidget(new QTextEdit); |
|
1112 |
||
1113 |
QGroupBox *box2 = new QGroupBox(tr("&TopRight")); |
|
1114 |
box2->setLayout(new QHBoxLayout); |
|
1115 |
box2->layout()->addWidget(new QTextEdit); |
|
1116 |
||
1117 |
QGroupBox *box3 = new QGroupBox(tr("&BottomLeft")); |
|
1118 |
box3->setLayout(new QHBoxLayout); |
|
1119 |
box3->layout()->addWidget(new QTextEdit); |
|
1120 |
||
1121 |
QGroupBox *box4 = new QGroupBox(tr("&BottomRight")); |
|
1122 |
box4->setLayout(new QHBoxLayout); |
|
1123 |
QMdiArea *nestedWorkspace = new QMdiArea; |
|
1124 |
for (int i = 0; i < 4; ++i) |
|
1125 |
nestedWorkspace->addSubWindow(new QTextEdit)->show(); |
|
1126 |
qApp->processEvents(); |
|
1127 |
nestedWorkspace->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); |
|
1128 |
nestedWorkspace->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); |
|
1129 |
box4->layout()->addWidget(nestedWorkspace); |
|
1130 |
||
1131 |
QGridLayout *layout = new QGridLayout; |
|
1132 |
layout->addWidget(box1, 0, 0); |
|
1133 |
layout->addWidget(box2, 0, 1); |
|
1134 |
layout->addWidget(box3, 1, 0); |
|
1135 |
layout->addWidget(box4, 1, 1); |
|
1136 |
||
1137 |
box->setLayout(layout); |
|
1138 |
||
1139 |
// Add complex widget to workspace. |
|
1140 |
QMdiArea topArea; |
|
1141 |
QMdiSubWindow *complexWindow = topArea.addSubWindow(box); |
|
1142 |
topArea.show(); |
|
1143 |
box->show(); |
|
1144 |
||
1145 |
qApp->setActiveWindow(&topArea); |
|
1146 |
QMdiSubWindow *expectedFocusWindow = nestedWorkspace->subWindowList().last(); |
|
1147 |
QVERIFY(expectedFocusWindow); |
|
1148 |
QVERIFY(expectedFocusWindow->widget()); |
|
1149 |
QCOMPARE(qApp->focusWidget(), expectedFocusWindow->widget()); |
|
1150 |
||
1151 |
// Normal -> minimized |
|
1152 |
expectedFocusWindow->showMinimized(); |
|
1153 |
qApp->processEvents(); |
|
1154 |
QVERIFY(expectedFocusWindow->isMinimized()); |
|
1155 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(expectedFocusWindow)); |
|
1156 |
||
1157 |
// Minimized -> normal |
|
1158 |
expectedFocusWindow->showNormal(); |
|
1159 |
qApp->processEvents(); |
|
1160 |
QVERIFY(!expectedFocusWindow->isMinimized()); |
|
1161 |
QCOMPARE(qApp->focusWidget(), expectedFocusWindow->widget()); |
|
1162 |
||
1163 |
// Normal -> maximized |
|
1164 |
expectedFocusWindow->showMaximized(); |
|
1165 |
qApp->processEvents(); |
|
1166 |
QVERIFY(expectedFocusWindow->isMaximized()); |
|
1167 |
QCOMPARE(qApp->focusWidget(), expectedFocusWindow->widget()); |
|
1168 |
||
1169 |
// Maximized -> normal |
|
1170 |
expectedFocusWindow->showNormal(); |
|
1171 |
qApp->processEvents(); |
|
1172 |
QVERIFY(!expectedFocusWindow->isMaximized()); |
|
1173 |
QCOMPARE(qApp->focusWidget(), expectedFocusWindow->widget()); |
|
1174 |
||
1175 |
// Minimized -> maximized |
|
1176 |
expectedFocusWindow->showMinimized(); |
|
1177 |
qApp->processEvents(); |
|
1178 |
QVERIFY(expectedFocusWindow->isMinimized()); |
|
1179 |
expectedFocusWindow->showMaximized(); |
|
1180 |
qApp->processEvents(); |
|
1181 |
QVERIFY(expectedFocusWindow->isMaximized()); |
|
1182 |
QCOMPARE(qApp->focusWidget(), expectedFocusWindow->widget()); |
|
1183 |
||
1184 |
// Maximized -> minimized |
|
1185 |
expectedFocusWindow->showNormal(); |
|
1186 |
qApp->processEvents(); |
|
1187 |
QVERIFY(!expectedFocusWindow->isMaximized()); |
|
1188 |
expectedFocusWindow->showMaximized(); |
|
1189 |
qApp->processEvents(); |
|
1190 |
QVERIFY(expectedFocusWindow->isMaximized()); |
|
1191 |
expectedFocusWindow->showMinimized(); |
|
1192 |
qApp->processEvents(); |
|
1193 |
QVERIFY(expectedFocusWindow->isMinimized()); |
|
1194 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(expectedFocusWindow)); |
|
1195 |
||
1196 |
complexWindow->showMinimized(); |
|
1197 |
qApp->processEvents(); |
|
1198 |
QVERIFY(complexWindow->isMinimized()); |
|
1199 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(complexWindow)); |
|
1200 |
||
1201 |
complexWindow->showNormal(); |
|
1202 |
qApp->processEvents(); |
|
1203 |
QVERIFY(!complexWindow->isMinimized()); |
|
1204 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(expectedFocusWindow)); |
|
1205 |
} |
|
1206 |
||
1207 |
void tst_QMdiSubWindow::changeFocusWithTab() |
|
1208 |
{ |
|
1209 |
QWidget *widget = new QWidget; |
|
1210 |
widget->setLayout(new QVBoxLayout); |
|
1211 |
||
1212 |
QLineEdit *firstLineEdit = new QLineEdit; |
|
1213 |
widget->layout()->addWidget(firstLineEdit); |
|
1214 |
QLineEdit *secondLineEdit = new QLineEdit; |
|
1215 |
widget->layout()->addWidget(secondLineEdit); |
|
1216 |
QLineEdit *thirdLineEdit = new QLineEdit; |
|
1217 |
widget->layout()->addWidget(thirdLineEdit); |
|
1218 |
||
1219 |
QMdiArea mdiArea; |
|
1220 |
mdiArea.addSubWindow(widget); |
|
1221 |
mdiArea.show(); |
|
1222 |
QCOMPARE(mdiArea.subWindowList().count(), 1); |
|
1223 |
||
1224 |
qApp->setActiveWindow(&mdiArea); |
|
1225 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(firstLineEdit)); |
|
1226 |
||
1227 |
// Next |
|
1228 |
QTest::keyPress(widget, Qt::Key_Tab); |
|
1229 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(secondLineEdit)); |
|
1230 |
||
1231 |
// Next |
|
1232 |
QTest::keyPress(widget, Qt::Key_Tab); |
|
1233 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(thirdLineEdit)); |
|
1234 |
||
1235 |
// Previous |
|
1236 |
QTest::keyPress(widget, Qt::Key_Backtab); |
|
1237 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(secondLineEdit)); |
|
1238 |
||
1239 |
// Previous |
|
1240 |
QTest::keyPress(widget, Qt::Key_Backtab); |
|
1241 |
QCOMPARE(qApp->focusWidget(), static_cast<QWidget *>(firstLineEdit)); |
|
1242 |
||
1243 |
QMdiSubWindow *window = mdiArea.addSubWindow(new QPushButton); |
|
1244 |
window->show(); |
|
1245 |
QCOMPARE(mdiArea.activeSubWindow(), window); |
|
1246 |
||
1247 |
// Check that we don't give away focus to another window by |
|
1248 |
// just hitting tab if the child widget does not accept |
|
1249 |
// focus (which is the case for a QPushButton). |
|
1250 |
QTest::keyPress(window, Qt::Key_Tab); |
|
1251 |
QCOMPARE(mdiArea.activeSubWindow(), window); |
|
1252 |
QCOMPARE(qApp->focusWidget(), tabAllWidgets() ? window->widget() : window); |
|
1253 |
QTest::keyPress(window, Qt::Key_Tab); |
|
1254 |
QCOMPARE(mdiArea.activeSubWindow(), window); |
|
1255 |
QCOMPARE(qApp->focusWidget(), tabAllWidgets() ? window->widget() : window); |
|
1256 |
} |
|
1257 |
||
1258 |
class MyTextEdit : public QTextEdit |
|
1259 |
{ |
|
1260 |
public: |
|
1261 |
MyTextEdit(QWidget *parent = 0) : QTextEdit(parent), acceptClose(false) {} |
|
1262 |
void setAcceptClose(bool enable = true) { acceptClose = enable; } |
|
1263 |
protected: |
|
1264 |
void closeEvent(QCloseEvent *closeEvent) |
|
1265 |
{ |
|
1266 |
if (!acceptClose) |
|
1267 |
closeEvent->ignore(); |
|
1268 |
} |
|
1269 |
||
1270 |
private: |
|
1271 |
bool acceptClose; |
|
1272 |
}; |
|
1273 |
||
1274 |
void tst_QMdiSubWindow::closeEvent() |
|
1275 |
{ |
|
1276 |
QMdiArea mdiArea; |
|
1277 |
mdiArea.show(); |
|
1278 |
||
1279 |
MyTextEdit *textEdit = new MyTextEdit; |
|
1280 |
textEdit->setAcceptClose(false); |
|
1281 |
QMdiSubWindow *window = mdiArea.addSubWindow(textEdit); |
|
1282 |
EventSpy closeSpy(window->widget(), QEvent::Close); |
|
1283 |
window->show(); |
|
1284 |
||
1285 |
QCOMPARE(closeSpy.count(), 0); |
|
1286 |
QVERIFY(window->isVisible()); |
|
1287 |
QVERIFY(textEdit->isVisible()); |
|
1288 |
||
1289 |
QVERIFY(!window->close()); |
|
1290 |
QCOMPARE(closeSpy.count(), 1); |
|
1291 |
QVERIFY(window->isVisible()); |
|
1292 |
QVERIFY(textEdit->isVisible()); |
|
1293 |
||
1294 |
QVERIFY(!textEdit->close()); |
|
1295 |
QCOMPARE(closeSpy.count(), 2); |
|
1296 |
QVERIFY(window->isVisible()); |
|
1297 |
QVERIFY(textEdit->isVisible()); |
|
1298 |
||
1299 |
textEdit->setAcceptClose(true); |
|
1300 |
||
1301 |
QVERIFY(window->close()); |
|
1302 |
QCOMPARE(closeSpy.count(), 3); |
|
1303 |
QCOMPARE(mdiArea.subWindowList().count(), 0); |
|
1304 |
} |
|
1305 |
||
1306 |
// There exists more tests in QMdiArea which covers window title support |
|
1307 |
// related to QMainWindow. This test is specific for QMdiSubWindow and its |
|
1308 |
// widget. |
|
1309 |
void tst_QMdiSubWindow::setWindowTitle() |
|
1310 |
{ |
|
1311 |
QString expectedWindowTitle = QLatin1String("This is teh shit[*]"); |
|
1312 |
QTextEdit *textEdit = new QTextEdit; |
|
1313 |
textEdit->setWindowTitle(expectedWindowTitle); |
|
1314 |
QCOMPARE(textEdit->windowTitle(), expectedWindowTitle); |
|
1315 |
textEdit->setWindowModified(true); |
|
1316 |
QCOMPARE(textEdit->isWindowModified(), true); |
|
1317 |
||
1318 |
QMdiArea mdiArea; |
|
1319 |
QMdiSubWindow *window = new QMdiSubWindow; |
|
1320 |
mdiArea.addSubWindow(window); |
|
1321 |
QCOMPARE(window->windowTitle(), QString()); |
|
1322 |
QVERIFY(!window->isWindowModified()); |
|
1323 |
||
1324 |
window->setWidget(textEdit); |
|
1325 |
QVERIFY(window->isWindowModified()); |
|
1326 |
QCOMPARE(textEdit->windowTitle(), expectedWindowTitle); |
|
1327 |
QCOMPARE(window->windowTitle(), window->widget()->windowTitle()); |
|
1328 |
||
1329 |
textEdit->setWindowModified(false); |
|
1330 |
QVERIFY(!textEdit->isWindowModified()); |
|
1331 |
QVERIFY(!window->isWindowModified()); |
|
1332 |
// This will return the title including the astrix, but the |
|
1333 |
// actual window title does not contain the astrix. This behavior |
|
1334 |
// seems a bit odd, but is equal to e.g. QTextEdit (and probably all |
|
1335 |
// other widgets which are not real top-level widgets). |
|
1336 |
QCOMPARE(window->windowTitle(), expectedWindowTitle); |
|
1337 |
||
1338 |
textEdit->setWindowModified(true);; |
|
1339 |
expectedWindowTitle = QLatin1String("Override child title"); |
|
1340 |
window->setWindowTitle(expectedWindowTitle); |
|
1341 |
QVERIFY(window->isWindowModified()); |
|
1342 |
QCOMPARE(window->windowTitle(), expectedWindowTitle); |
|
1343 |
||
1344 |
textEdit->setWindowTitle(QLatin1String("My parent overrides me")); |
|
1345 |
QCOMPARE(window->windowTitle(), expectedWindowTitle); |
|
1346 |
||
1347 |
textEdit->setWindowModified(false); |
|
1348 |
QVERIFY(window->isWindowModified()); |
|
1349 |
QCOMPARE(window->windowTitle(), expectedWindowTitle); |
|
1350 |
||
1351 |
window->setWindowModified(false); |
|
1352 |
QVERIFY(!window->isWindowModified()); |
|
1353 |
window->setWindowTitle(QString()); |
|
1354 |
QCOMPARE(window->windowTitle(), QString()); |
|
1355 |
||
1356 |
expectedWindowTitle = QLatin1String("My parent doesn't have any title so now I can set one[*]"); |
|
1357 |
textEdit->setWindowTitle(expectedWindowTitle); |
|
1358 |
QCOMPARE(window->windowTitle(), expectedWindowTitle); |
|
1359 |
textEdit->setWindowModified(true); |
|
1360 |
QVERIFY(window->isWindowModified()); |
|
1361 |
||
1362 |
window->setWidget(0); |
|
1363 |
QCOMPARE(window->windowTitle(), QString()); |
|
1364 |
QVERIFY(!window->isWindowModified()); |
|
1365 |
delete textEdit; |
|
1366 |
} |
|
1367 |
||
1368 |
void tst_QMdiSubWindow::resizeEvents_data() |
|
1369 |
{ |
|
1370 |
QTest::addColumn<Qt::WindowState>("windowState"); |
|
1371 |
QTest::addColumn<int>("expectedWindowResizeEvents"); |
|
1372 |
QTest::addColumn<int>("expectedWidgetResizeEvents"); |
|
1373 |
QTest::addColumn<bool>("isShadeMode"); |
|
1374 |
||
1375 |
QTest::newRow("minimized") << Qt::WindowMinimized << 1 << 0 << false; |
|
1376 |
QTest::newRow("maximized") << Qt::WindowMaximized << 1 << 1 << false; |
|
1377 |
QTest::newRow("shaded") << Qt::WindowMinimized << 1 << 0 << true; |
|
1378 |
} |
|
1379 |
||
1380 |
void tst_QMdiSubWindow::resizeEvents() |
|
1381 |
{ |
|
1382 |
QFETCH(Qt::WindowState, windowState); |
|
1383 |
QFETCH(int, expectedWindowResizeEvents); |
|
1384 |
QFETCH(int, expectedWidgetResizeEvents); |
|
1385 |
QFETCH(bool, isShadeMode); |
|
1386 |
||
1387 |
QMainWindow mainWindow; |
|
1388 |
QMdiArea *mdiArea = new QMdiArea; |
|
1389 |
mainWindow.setCentralWidget(mdiArea); |
|
1390 |
mainWindow.show(); |
|
1391 |
#if defined(Q_WS_X11) |
|
1392 |
qt_x11_wait_for_window_manager(&mainWindow); |
|
1393 |
#endif |
|
1394 |
||
1395 |
QMdiSubWindow *window = mdiArea->addSubWindow(new QTextEdit); |
|
1396 |
window->show(); |
|
1397 |
||
1398 |
EventSpy windowResizeEventSpy(window, QEvent::Resize); |
|
1399 |
QCOMPARE(windowResizeEventSpy.count(), 0); |
|
1400 |
EventSpy widgetResizeEventSpy(window->widget(), QEvent::Resize); |
|
1401 |
QCOMPARE(widgetResizeEventSpy.count(), 0); |
|
1402 |
||
1403 |
// Set the window state. |
|
1404 |
if (!isShadeMode) |
|
1405 |
window->setWindowState(windowState); |
|
1406 |
else |
|
1407 |
window->showShaded(); |
|
1408 |
||
1409 |
// Check that the window state is correct. |
|
1410 |
QCOMPARE(window->windowState(), windowState | Qt::WindowActive); |
|
1411 |
QCOMPARE(window->widget()->windowState(), windowState); |
|
1412 |
||
1413 |
// Make sure we got as many resize events as expected. |
|
1414 |
QCOMPARE(windowResizeEventSpy.count(), expectedWindowResizeEvents); |
|
1415 |
QCOMPARE(widgetResizeEventSpy.count(), expectedWidgetResizeEvents); |
|
1416 |
windowResizeEventSpy.clear(); |
|
1417 |
widgetResizeEventSpy.clear(); |
|
1418 |
||
1419 |
// Normalize. |
|
1420 |
window->showNormal(); |
|
1421 |
||
1422 |
// Check that the window state is correct. |
|
1423 |
QCOMPARE(window->windowState(), Qt::WindowNoState | Qt::WindowActive); |
|
1424 |
QCOMPARE(window->widget()->windowState(), Qt::WindowNoState); |
|
1425 |
||
1426 |
// Make sure we got as many resize events as expected. |
|
1427 |
QCOMPARE(windowResizeEventSpy.count(), expectedWindowResizeEvents); |
|
1428 |
QCOMPARE(widgetResizeEventSpy.count(), expectedWidgetResizeEvents); |
|
1429 |
} |
|
1430 |
||
1431 |
#if defined(Q_WS_MAC) |
|
1432 |
void tst_QMdiSubWindow::defaultSizeGrip() |
|
1433 |
{ |
|
1434 |
if (!qApp->style()->inherits("QMacStyle")) |
|
1435 |
return; |
|
1436 |
QMdiArea mdiArea; |
|
1437 |
mdiArea.show(); |
|
1438 |
||
1439 |
// QSizeGrip on windows with decoration. |
|
1440 |
QMdiSubWindow *windowWithDecoration = mdiArea.addSubWindow(new QWidget); |
|
1441 |
windowWithDecoration->show(); |
|
1442 |
QVERIFY(qFindChild<QSizeGrip *>(windowWithDecoration)); |
|
1443 |
||
1444 |
// ...but not on windows without decoration (Qt::FramelessWindowHint). |
|
1445 |
QMdiSubWindow *windowWithoutDecoration = mdiArea.addSubWindow(new QWidget, Qt::FramelessWindowHint); |
|
1446 |
windowWithoutDecoration->show(); |
|
1447 |
QVERIFY(!qFindChild<QSizeGrip *>(windowWithoutDecoration)); |
|
1448 |
} |
|
1449 |
#endif |
|
1450 |
||
1451 |
void tst_QMdiSubWindow::hideAndShow() |
|
1452 |
{ |
|
1453 |
// Create a QTabWidget with two tabs; QMdiArea and QTextEdit. |
|
1454 |
QTabWidget *tabWidget = new QTabWidget; |
|
1455 |
QMdiArea *mdiArea = new QMdiArea; |
|
1456 |
tabWidget->addTab(mdiArea, QLatin1String("QMdiArea")); |
|
1457 |
tabWidget->addTab(new QTextEdit, QLatin1String("Dummy")); |
|
1458 |
||
1459 |
// Set the tab widget as the central widget in QMainWindow. |
|
1460 |
QMainWindow mainWindow; |
|
1461 |
mainWindow.setGeometry(0, 0, 640, 480); |
|
1462 |
QMenuBar *menuBar = mainWindow.menuBar(); |
|
1463 |
mainWindow.setCentralWidget(tabWidget); |
|
1464 |
mainWindow.show(); |
|
1465 |
#ifdef Q_WS_X11 |
|
1466 |
qt_x11_wait_for_window_manager(&mainWindow); |
|
1467 |
#endif |
|
1468 |
||
1469 |
QVERIFY(!menuBar->cornerWidget(Qt::TopRightCorner)); |
|
1470 |
QMdiSubWindow *subWindow = mdiArea->addSubWindow(new QTextEdit); |
|
1471 |
subWindow->showMaximized(); |
|
1472 |
#if !defined (Q_WS_MAC) && !defined (Q_OS_WINCE) |
|
1473 |
QVERIFY(menuBar->cornerWidget(Qt::TopRightCorner)); |
|
1474 |
QCOMPARE(menuBar->cornerWidget(Qt::TopRightCorner), subWindow->maximizedButtonsWidget()); |
|
1475 |
#endif |
|
1476 |
||
1477 |
// Hide QMdiArea. |
|
1478 |
tabWidget->setCurrentIndex(1); |
|
1479 |
||
1480 |
QVERIFY(!menuBar->cornerWidget(Qt::TopRightCorner)); |
|
1481 |
QVERIFY(!subWindow->maximizedButtonsWidget()); |
|
1482 |
QVERIFY(!subWindow->maximizedSystemMenuIconWidget()); |
|
1483 |
||
1484 |
// Show QMdiArea. |
|
1485 |
tabWidget->setCurrentIndex(0); |
|
1486 |
||
1487 |
#if !defined (Q_WS_MAC) && !defined (Q_OS_WINCE) |
|
1488 |
QVERIFY(menuBar->cornerWidget(Qt::TopRightCorner)); |
|
1489 |
QVERIFY(subWindow->maximizedButtonsWidget()); |
|
1490 |
QVERIFY(subWindow->maximizedSystemMenuIconWidget()); |
|
1491 |
QCOMPARE(menuBar->cornerWidget(Qt::TopRightCorner), subWindow->maximizedButtonsWidget()); |
|
1492 |
#endif |
|
1493 |
||
1494 |
// Hide QMdiArea. |
|
1495 |
tabWidget->setCurrentIndex(1); |
|
1496 |
||
1497 |
// Add few more windows. |
|
1498 |
for (int i = 0; i < 5; ++i) |
|
1499 |
mdiArea->addSubWindow(new QTextEdit); |
|
1500 |
||
1501 |
// Show QMdiArea. |
|
1502 |
tabWidget->setCurrentIndex(0); |
|
1503 |
qApp->processEvents(); |
|
1504 |
||
1505 |
subWindow = mdiArea->subWindowList().back(); |
|
1506 |
QVERIFY(subWindow); |
|
1507 |
QCOMPARE(mdiArea->activeSubWindow(), subWindow); |
|
1508 |
||
1509 |
#if !defined (Q_WS_MAC) && !defined (Q_OS_WINCE) |
|
1510 |
QVERIFY(menuBar->cornerWidget(Qt::TopRightCorner)); |
|
1511 |
QVERIFY(subWindow->maximizedButtonsWidget()); |
|
1512 |
QVERIFY(subWindow->maximizedSystemMenuIconWidget()); |
|
1513 |
QCOMPARE(menuBar->cornerWidget(Qt::TopRightCorner), subWindow->maximizedButtonsWidget()); |
|
1514 |
#endif |
|
1515 |
||
1516 |
subWindow->showNormal(); |
|
1517 |
QVERIFY(!menuBar->cornerWidget(Qt::TopRightCorner)); |
|
1518 |
||
1519 |
// Check that newly added windows got right sizes. |
|
1520 |
foreach (QMdiSubWindow *window, mdiArea->subWindowList()) |
|
1521 |
QCOMPARE(window->size(), window->sizeHint()); |
|
1522 |
||
1523 |
subWindow->showMaximized(); |
|
1524 |
#ifndef Q_WS_MAC |
|
1525 |
QCOMPARE(menuBar->cornerWidget(Qt::TopRightCorner), subWindow->maximizedButtonsWidget()); |
|
1526 |
#endif |
|
1527 |
||
1528 |
subWindow->hide(); |
|
1529 |
QVERIFY(!subWindow->maximizedButtonsWidget()); |
|
1530 |
QVERIFY(!subWindow->maximizedSystemMenuIconWidget()); |
|
1531 |
QVERIFY(!menuBar->cornerWidget(Qt::TopRightCorner)); |
|
1532 |
||
1533 |
subWindow->show(); |
|
1534 |
#if !defined (Q_WS_MAC) && !defined (Q_OS_WINCE) |
|
1535 |
QVERIFY(subWindow->maximizedButtonsWidget()); |
|
1536 |
QVERIFY(subWindow->maximizedSystemMenuIconWidget()); |
|
1537 |
QCOMPARE(menuBar->cornerWidget(Qt::TopRightCorner), subWindow->maximizedButtonsWidget()); |
|
1538 |
#endif |
|
1539 |
||
1540 |
// Hide QMainWindow. |
|
1541 |
mainWindow.hide(); |
|
1542 |
QVERIFY(!subWindow->maximizedButtonsWidget()); |
|
1543 |
QVERIFY(!subWindow->maximizedSystemMenuIconWidget()); |
|
1544 |
QVERIFY(!menuBar->cornerWidget(Qt::TopRightCorner)); |
|
1545 |
||
1546 |
// Show QMainWindow. |
|
1547 |
mainWindow.show(); |
|
1548 |
#if !defined (Q_WS_MAC) && !defined (Q_OS_WINCE) |
|
1549 |
QVERIFY(subWindow->maximizedButtonsWidget()); |
|
1550 |
QVERIFY(subWindow->maximizedSystemMenuIconWidget()); |
|
1551 |
QCOMPARE(menuBar->cornerWidget(Qt::TopRightCorner), subWindow->maximizedButtonsWidget()); |
|
1552 |
#endif |
|
1553 |
} |
|
1554 |
||
1555 |
void tst_QMdiSubWindow::keepWindowMaximizedState() |
|
1556 |
{ |
|
1557 |
QMdiArea mdiArea; |
|
1558 |
QMdiSubWindow *subWindow = mdiArea.addSubWindow(new QTextEdit); |
|
1559 |
mdiArea.show(); |
|
1560 |
#ifdef Q_WS_X11 |
|
1561 |
qt_x11_wait_for_window_manager(&mdiArea); |
|
1562 |
#endif |
|
1563 |
||
1564 |
subWindow->showMaximized(); |
|
1565 |
QVERIFY(subWindow->isMaximized()); |
|
1566 |
||
1567 |
// move |
|
1568 |
const QPoint newPosition = subWindow->pos() + QPoint(10, 10); |
|
1569 |
subWindow->move(newPosition); |
|
1570 |
QCOMPARE(subWindow->pos(), newPosition); |
|
1571 |
QVERIFY(subWindow->isMaximized()); |
|
1572 |
||
1573 |
// resize |
|
1574 |
const QSize newSize = subWindow->size() - QSize(10, 10); |
|
1575 |
subWindow->resize(newSize); |
|
1576 |
QCOMPARE(subWindow->size(), newSize); |
|
1577 |
QVERIFY(subWindow->isMaximized()); |
|
1578 |
||
1579 |
// setGeometry |
|
1580 |
const QRect newGeometry = QRect(newPosition - QPoint(10, 10), newSize + QSize(10, 10)); |
|
1581 |
subWindow->setGeometry(newGeometry); |
|
1582 |
QCOMPARE(subWindow->geometry(), newGeometry); |
|
1583 |
QVERIFY(subWindow->isMaximized()); |
|
1584 |
||
1585 |
subWindow->showNormal(); |
|
1586 |
||
1587 |
// Verify that we don't force Qt::WindowMaximized. |
|
1588 |
QVERIFY(!subWindow->isMaximized()); |
|
1589 |
subWindow->setGeometry(QRect(newPosition, newSize)); |
|
1590 |
QCOMPARE(subWindow->geometry(), QRect(newPosition, newSize)); |
|
1591 |
QVERIFY(!subWindow->isMaximized()); |
|
1592 |
} |
|
1593 |
||
1594 |
void tst_QMdiSubWindow::explicitlyHiddenWidget() |
|
1595 |
{ |
|
1596 |
QMdiArea mdiArea; |
|
1597 |
QTextEdit *textEdit = new QTextEdit; |
|
1598 |
textEdit->hide(); |
|
1599 |
QMdiSubWindow *subWindow = mdiArea.addSubWindow(textEdit); |
|
1600 |
mdiArea.show(); |
|
1601 |
#ifdef Q_WS_X11 |
|
1602 |
qt_x11_wait_for_window_manager(&mdiArea); |
|
1603 |
#endif |
|
1604 |
||
1605 |
QVERIFY(subWindow->isVisible()); |
|
1606 |
QVERIFY(!textEdit->isVisible()); |
|
1607 |
||
1608 |
textEdit->show(); |
|
1609 |
QVERIFY(textEdit->isVisible()); |
|
1610 |
||
1611 |
// normal -> minimized |
|
1612 |
subWindow->showMinimized(); |
|
1613 |
QVERIFY(subWindow->isVisible()); |
|
1614 |
QVERIFY(!textEdit->isVisible()); |
|
1615 |
||
1616 |
// minimized -> normal |
|
1617 |
subWindow->showNormal(); |
|
1618 |
QVERIFY(subWindow->isVisible()); |
|
1619 |
QVERIFY(textEdit->isVisible()); |
|
1620 |
||
1621 |
// minimized -> maximized |
|
1622 |
subWindow->showMinimized(); |
|
1623 |
subWindow->showMaximized(); |
|
1624 |
QVERIFY(subWindow->isVisible()); |
|
1625 |
QVERIFY(textEdit->isVisible()); |
|
1626 |
||
1627 |
textEdit->hide(); |
|
1628 |
||
1629 |
// maximized -> normal |
|
1630 |
subWindow->showNormal(); |
|
1631 |
QVERIFY(subWindow->isVisible()); |
|
1632 |
QVERIFY(!textEdit->isVisible()); |
|
1633 |
||
1634 |
textEdit->show(); |
|
1635 |
||
1636 |
subWindow->showMinimized(); |
|
1637 |
subWindow->setWidget(0); |
|
1638 |
delete textEdit; |
|
1639 |
textEdit = new QTextEdit; |
|
1640 |
textEdit->hide(); |
|
1641 |
subWindow->setWidget(textEdit); |
|
1642 |
subWindow->showNormal(); |
|
1643 |
QVERIFY(subWindow->isVisible()); |
|
1644 |
QVERIFY(!textEdit->isVisible()); |
|
1645 |
} |
|
1646 |
||
1647 |
void tst_QMdiSubWindow::resizeTimer() |
|
1648 |
{ |
|
1649 |
QMdiArea mdiArea; |
|
1650 |
QMdiSubWindow *subWindow = mdiArea.addSubWindow(new QWidget); |
|
1651 |
mdiArea.show(); |
|
1652 |
QTest::qWaitForWindowShown(&mdiArea); |
|
1653 |
QTest::qWait(300); |
|
1654 |
||
1655 |
||
1656 |
EventSpy timerEventSpy(subWindow, QEvent::Timer); |
|
1657 |
QCOMPARE(timerEventSpy.count(), 0); |
|
1658 |
||
1659 |
for (int i = 0; i < 20; ++i) { |
|
1660 |
subWindow->resize(subWindow->size() + QSize(2, 2)); |
|
1661 |
qApp->processEvents(); |
|
1662 |
} |
|
1663 |
||
1664 |
QTest::qWait(500); // Wait for timer events to occur. |
|
1665 |
||
1666 |
QTRY_VERIFY(timerEventSpy.count() > 0); |
|
1667 |
} |
|
1668 |
||
1669 |
void tst_QMdiSubWindow::fixedMinMaxSize() |
|
1670 |
{ |
|
1671 |
QMdiArea mdiArea; |
|
1672 |
mdiArea.setGeometry(0, 0, 640, 480); |
|
1673 |
mdiArea.show(); |
|
1674 |
#ifdef Q_WS_X11 |
|
1675 |
qt_x11_wait_for_window_manager(&mdiArea); |
|
1676 |
#endif |
|
1677 |
||
1678 |
const QSize minimumSize = QSize(250, 150); |
|
1679 |
const QSize maximumSize = QSize(300, 200); |
|
1680 |
||
1681 |
// Add the sub window to QMdiArea and set min/max size. |
|
1682 |
QMdiSubWindow *subWindow = new QMdiSubWindow; |
|
1683 |
subWindow->setMinimumSize(minimumSize); |
|
1684 |
QCOMPARE(subWindow->minimumSize(), minimumSize); |
|
1685 |
subWindow->setMaximumSize(maximumSize); |
|
1686 |
QCOMPARE(subWindow->maximumSize(), maximumSize); |
|
1687 |
mdiArea.addSubWindow(subWindow); |
|
1688 |
subWindow->show(); |
|
1689 |
QCOMPARE(subWindow->size(), minimumSize); |
|
1690 |
||
1691 |
// Calculate the size of a minimized sub window. |
|
1692 |
QStyleOptionTitleBar options; |
|
1693 |
options.initFrom(subWindow); |
|
1694 |
int minimizedHeight = subWindow->style()->pixelMetric(QStyle::PM_TitleBarHeight, &options); |
|
1695 |
#if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) |
|
1696 |
// ### Remove this after mac style has been fixed |
|
1697 |
if (qobject_cast<QMacStyle *>(subWindow->style())) |
|
1698 |
minimizedHeight -= 4; |
|
1699 |
#endif |
|
1700 |
if (!subWindow->style()->styleHint(QStyle::SH_TitleBar_NoBorder, &options, subWindow)) |
|
1701 |
minimizedHeight += 8; |
|
1702 |
int minimizedWidth = subWindow->style()->pixelMetric(QStyle::PM_MDIMinimizedWidth, &options); |
|
1703 |
const QSize minimizedSize = QSize(minimizedWidth, minimizedHeight); |
|
1704 |
||
1705 |
// Even though the sub window has a minimum size set, it should be possible |
|
1706 |
// to minimize the window. |
|
1707 |
subWindow->showMinimized(); |
|
1708 |
QVERIFY(subWindow->isMinimized()); |
|
1709 |
QCOMPARE(subWindow->size(), minimizedSize); |
|
1710 |
QCOMPARE(subWindow->minimumSize(), minimizedSize); |
|
1711 |
||
1712 |
// Restore minimum size. |
|
1713 |
subWindow->showNormal(); |
|
1714 |
QVERIFY(!subWindow->isMinimized()); |
|
1715 |
QCOMPARE(subWindow->size(), minimumSize); |
|
1716 |
QCOMPARE(subWindow->minimumSize(), minimumSize); |
|
1717 |
||
1718 |
// Well, the logic here is of course broken (calling showMaximized on a window with |
|
1719 |
// maximum size set), but we should handle it :) |
|
1720 |
subWindow->showMaximized(); |
|
1721 |
QVERIFY(subWindow->isMaximized()); |
|
1722 |
QCOMPARE(subWindow->size(), maximumSize); |
|
1723 |
||
1724 |
subWindow->showNormal(); |
|
1725 |
QVERIFY(!subWindow->isMaximized()); |
|
1726 |
QCOMPARE(subWindow->size(), minimumSize); |
|
1727 |
} |
|
1728 |
||
1729 |
#if !defined( Q_WS_MAC) && !defined( Q_OS_WINCE) |
|
1730 |
void tst_QMdiSubWindow::replaceMenuBarWhileMaximized() |
|
1731 |
{ |
|
1732 |
||
1733 |
QMainWindow mainWindow; |
|
1734 |
||
1735 |
QMdiArea *mdiArea = new QMdiArea; |
|
1736 |
QMdiSubWindow *subWindow = mdiArea->addSubWindow(new QTextEdit); |
|
1737 |
subWindow->showMaximized(); |
|
1738 |
||
1739 |
mainWindow.setCentralWidget(mdiArea); |
|
1740 |
QMenuBar *menuBar = mainWindow.menuBar(); |
|
1741 |
mainWindow.show(); |
|
1742 |
#ifdef Q_WS_X11 |
|
1743 |
qt_x11_wait_for_window_manager(&mainWindow); |
|
1744 |
#endif |
|
1745 |
||
1746 |
qApp->processEvents(); |
|
1747 |
||
1748 |
QVERIFY(subWindow->maximizedButtonsWidget()); |
|
1749 |
QVERIFY(subWindow->maximizedSystemMenuIconWidget()); |
|
1750 |
QCOMPARE(menuBar->cornerWidget(Qt::TopLeftCorner), subWindow->maximizedSystemMenuIconWidget()); |
|
1751 |
QCOMPARE(menuBar->cornerWidget(Qt::TopRightCorner), subWindow->maximizedButtonsWidget()); |
|
1752 |
||
1753 |
// Replace. |
|
1754 |
mainWindow.setMenuBar(new QMenuBar); |
|
1755 |
menuBar = mainWindow.menuBar(); |
|
1756 |
qApp->processEvents(); |
|
1757 |
||
1758 |
QVERIFY(subWindow->maximizedButtonsWidget()); |
|
1759 |
QVERIFY(subWindow->maximizedSystemMenuIconWidget()); |
|
1760 |
QCOMPARE(menuBar->cornerWidget(Qt::TopLeftCorner), subWindow->maximizedSystemMenuIconWidget()); |
|
1761 |
QCOMPARE(menuBar->cornerWidget(Qt::TopRightCorner), subWindow->maximizedButtonsWidget()); |
|
1762 |
||
1763 |
subWindow->showNormal(); |
|
1764 |
QVERIFY(!subWindow->maximizedButtonsWidget()); |
|
1765 |
QVERIFY(!subWindow->maximizedSystemMenuIconWidget()); |
|
1766 |
QVERIFY(!menuBar->cornerWidget(Qt::TopLeftCorner)); |
|
1767 |
QVERIFY(!menuBar->cornerWidget(Qt::TopRightCorner)); |
|
1768 |
||
1769 |
// Delete and replace. |
|
1770 |
subWindow->showMaximized(); |
|
1771 |
delete menuBar; |
|
1772 |
mainWindow.setMenuBar(new QMenuBar); |
|
1773 |
qApp->processEvents(); |
|
1774 |
||
1775 |
QVERIFY(!subWindow->maximizedButtonsWidget()); |
|
1776 |
QVERIFY(!subWindow->maximizedSystemMenuIconWidget()); |
|
1777 |
||
1778 |
subWindow->showNormal(); |
|
1779 |
QVERIFY(!subWindow->maximizedButtonsWidget()); |
|
1780 |
QVERIFY(!subWindow->maximizedSystemMenuIconWidget()); |
|
1781 |
||
1782 |
// Delete. |
|
1783 |
subWindow->showMaximized(); |
|
1784 |
mainWindow.setMenuBar(0); |
|
1785 |
qApp->processEvents(); |
|
1786 |
QVERIFY(!mainWindow.menuWidget()); |
|
1787 |
||
1788 |
QVERIFY(!subWindow->maximizedButtonsWidget()); |
|
1789 |
QVERIFY(!subWindow->maximizedSystemMenuIconWidget()); |
|
1790 |
||
1791 |
subWindow->showNormal(); |
|
1792 |
QVERIFY(!subWindow->maximizedButtonsWidget()); |
|
1793 |
QVERIFY(!subWindow->maximizedSystemMenuIconWidget()); |
|
1794 |
} |
|
1795 |
||
1796 |
void tst_QMdiSubWindow::closeOnDoubleClick() |
|
1797 |
{ |
|
1798 |
QMdiArea mdiArea; |
|
1799 |
QPointer<QMdiSubWindow> subWindow = mdiArea.addSubWindow(new QWidget); |
|
1800 |
mdiArea.show(); |
|
1801 |
#ifdef Q_WS_X11 |
|
1802 |
qt_x11_wait_for_window_manager(&mdiArea); |
|
1803 |
#endif |
|
1804 |
||
1805 |
subWindow->showSystemMenu(); |
|
1806 |
QTest::qWait(200); |
|
1807 |
||
1808 |
QPointer<QMenu> systemMenu = subWindow->systemMenu(); |
|
1809 |
QVERIFY(systemMenu); |
|
1810 |
QVERIFY(systemMenu->isVisible()); |
|
1811 |
||
1812 |
sendMouseDoubleClick(systemMenu, QPoint(10, 10)); |
|
1813 |
if (qApp->activePopupWidget() == static_cast<QWidget *>(systemMenu)) |
|
1814 |
systemMenu->hide(); |
|
1815 |
qApp->processEvents(); |
|
1816 |
QVERIFY(!subWindow || !subWindow->isVisible()); |
|
1817 |
QVERIFY(!systemMenu || !systemMenu->isVisible()); |
|
1818 |
} |
|
1819 |
#endif |
|
1820 |
||
1821 |
void tst_QMdiSubWindow::setFont() |
|
1822 |
{ |
|
1823 |
QMdiArea mdiArea; |
|
1824 |
QMdiSubWindow *subWindow = mdiArea.addSubWindow(new QPushButton(QLatin1String("test"))); |
|
1825 |
subWindow->resize(300, 100); |
|
1826 |
subWindow->setWindowTitle(QLatin1String("Window title")); |
|
1827 |
mdiArea.show(); |
|
1828 |
#ifdef Q_WS_X11 |
|
1829 |
qt_x11_wait_for_window_manager(&mdiArea); |
|
1830 |
#endif |
|
1831 |
||
1832 |
const QFont originalFont = QApplication::font("QWorkspaceTitleBar"); |
|
1833 |
QStyleOptionTitleBar opt; |
|
1834 |
opt.initFrom(subWindow); |
|
1835 |
const int titleBarHeight = subWindow->style()->pixelMetric(QStyle::PM_TitleBarHeight, &opt); |
|
1836 |
const QRect titleBarRect = QRect(0, 0, subWindow->width(), titleBarHeight); |
|
1837 |
const QImage originalTitleBar = QPixmap::grabWidget(subWindow, titleBarRect).toImage(); |
|
1838 |
||
1839 |
QFont newFont(QLatin1String("Helvetica"), 16); |
|
1840 |
newFont.setBold(true); |
|
1841 |
subWindow->setFont(newFont); |
|
1842 |
qApp->processEvents(); |
|
1843 |
const QFont &swFont = subWindow->font(); |
|
1844 |
QCOMPARE(swFont.family(), newFont.family()); |
|
1845 |
QCOMPARE(swFont.pointSize(), newFont.pointSize()); |
|
1846 |
QCOMPARE(swFont.weight(), newFont.weight()); |
|
1847 |
QImage newTitleBar = QPixmap::grabWidget(subWindow, titleBarRect).toImage(); |
|
1848 |
QVERIFY(newTitleBar != originalTitleBar); |
|
1849 |
||
1850 |
subWindow->setFont(originalFont); |
|
1851 |
qApp->processEvents(); |
|
1852 |
QCOMPARE(subWindow->font(), originalFont); |
|
1853 |
newTitleBar = QPixmap::grabWidget(subWindow, titleBarRect).toImage(); |
|
1854 |
QCOMPARE(newTitleBar, originalTitleBar); |
|
1855 |
} |
|
1856 |
||
1857 |
void tst_QMdiSubWindow::task_188849() |
|
1858 |
{ |
|
1859 |
QMainWindow mainWindow; |
|
1860 |
// Sets a regular QWidget (and NOT a QMenuBar) as the menu bar. |
|
1861 |
mainWindow.setMenuWidget(new QWidget); |
|
1862 |
||
1863 |
QMdiArea *mdiArea = new QMdiArea; |
|
1864 |
QMdiSubWindow *subWindow = mdiArea->addSubWindow(new QWidget); |
|
1865 |
mainWindow.setCentralWidget(mdiArea); |
|
1866 |
mainWindow.show(); |
|
1867 |
#if defined(Q_WS_X11) |
|
1868 |
qt_x11_wait_for_window_manager(&mainWindow); |
|
1869 |
#endif |
|
1870 |
||
1871 |
// QMdiSubWindow will now try to show its buttons in the menu bar. |
|
1872 |
// Without checking that the menu bar is actually a QMenuBar |
|
1873 |
// and not a regular QWidget, this will crash. |
|
1874 |
subWindow->showMaximized(); |
|
1875 |
} |
|
1876 |
||
1877 |
void tst_QMdiSubWindow::mdiArea() |
|
1878 |
{ |
|
1879 |
QMdiArea mdiArea; |
|
1880 |
QMdiSubWindow *subWindow = mdiArea.addSubWindow(new QWidget); |
|
1881 |
QCOMPARE(subWindow->mdiArea(), &mdiArea); |
|
1882 |
||
1883 |
subWindow->setParent(0); |
|
1884 |
QVERIFY(!subWindow->mdiArea()); |
|
1885 |
||
1886 |
// Child of the area's corner widget. |
|
1887 |
mdiArea.setCornerWidget(new QWidget); |
|
1888 |
subWindow->setParent(mdiArea.cornerWidget()); |
|
1889 |
QVERIFY(!subWindow->mdiArea()); |
|
1890 |
||
1891 |
// Nested mdi area. |
|
1892 |
QMdiArea *nestedArea = new QMdiArea; |
|
1893 |
mdiArea.addSubWindow(nestedArea); |
|
1894 |
nestedArea->addSubWindow(subWindow); |
|
1895 |
QCOMPARE(subWindow->mdiArea(), nestedArea); |
|
1896 |
nestedArea->setViewport(new QWidget); |
|
1897 |
QCOMPARE(subWindow->mdiArea(), nestedArea); |
|
1898 |
} |
|
1899 |
||
1900 |
void tst_QMdiSubWindow::task_182852() |
|
1901 |
{ |
|
1902 |
#if !defined(Q_WS_MAC) && !defined(Q_OS_WINCE) |
|
1903 |
||
1904 |
QMdiArea *workspace = new QMdiArea; |
|
1905 |
QMainWindow mainWindow; |
|
1906 |
mainWindow.setCentralWidget(workspace); |
|
1907 |
mainWindow.show(); |
|
1908 |
mainWindow.menuBar()->setVisible(true); |
|
1909 |
qApp->setActiveWindow(&mainWindow); |
|
1910 |
||
1911 |
QString originalWindowTitle = QString::fromLatin1("MainWindow - [foo]"); |
|
1912 |
mainWindow.setWindowTitle(originalWindowTitle); |
|
1913 |
||
1914 |
QMdiSubWindow *window = new QMdiSubWindow; |
|
1915 |
||
1916 |
QMdiArea *nestedWorkspace = new QMdiArea; // :-) |
|
1917 |
window->setWidget(nestedWorkspace); |
|
1918 |
window->widget()->setWindowTitle(QString::fromLatin1("Window")); |
|
1919 |
||
1920 |
workspace->addSubWindow(window); |
|
1921 |
||
1922 |
window->showMaximized(); |
|
1923 |
qApp->processEvents(); |
|
1924 |
QVERIFY(window->isMaximized()); |
|
1925 |
||
1926 |
QCOMPARE(mainWindow.windowTitle(), QString::fromLatin1("%1 - [%2]") |
|
1927 |
.arg(originalWindowTitle, window->widget()->windowTitle())); |
|
1928 |
||
1929 |
window->showNormal(); |
|
1930 |
QCOMPARE(mainWindow.windowTitle(), originalWindowTitle); |
|
1931 |
||
1932 |
window->widget()->setWindowTitle(QString::fromLatin1("foo")); |
|
1933 |
window->showMaximized(); |
|
1934 |
||
1935 |
QCOMPARE(mainWindow.windowTitle(), originalWindowTitle); |
|
1936 |
||
1937 |
window->showNormal(); |
|
1938 |
QCOMPARE(mainWindow.windowTitle(), originalWindowTitle); |
|
1939 |
||
1940 |
window->widget()->setWindowTitle(QString::fromLatin1("bar")); |
|
1941 |
window->showMaximized(); |
|
1942 |
||
1943 |
QCOMPARE(mainWindow.windowTitle(), QString::fromLatin1("%1 - [%2]") |
|
1944 |
.arg(originalWindowTitle, window->widget()->windowTitle())); |
|
1945 |
||
1946 |
||
1947 |
#endif |
|
1948 |
} |
|
1949 |
||
1950 |
void tst_QMdiSubWindow::task_233197() |
|
1951 |
{ |
|
1952 |
QMainWindow *mainWindow = new QMainWindow; |
|
1953 |
mainWindow->setAttribute(Qt::WA_DeleteOnClose); |
|
1954 |
mainWindow->resize(500, 200); |
|
1955 |
mainWindow->show(); |
|
1956 |
||
1957 |
QMdiArea *mdiArea = new QMdiArea(mainWindow); |
|
1958 |
mdiArea->setOption(QMdiArea::DontMaximizeSubWindowOnActivation, true); |
|
1959 |
mainWindow->setCentralWidget(mdiArea); |
|
1960 |
||
1961 |
QMdiSubWindow *subWindow1 = new QMdiSubWindow(); |
|
1962 |
mdiArea->addSubWindow(subWindow1); |
|
1963 |
subWindow1->showMaximized(); |
|
1964 |
||
1965 |
QMdiSubWindow *subWindow2 = new QMdiSubWindow(); |
|
1966 |
mdiArea->addSubWindow(subWindow2); |
|
1967 |
subWindow2->showMaximized(); |
|
1968 |
||
1969 |
QMdiSubWindow *subWindow3 = new QMdiSubWindow(); |
|
1970 |
mdiArea->addSubWindow(subWindow3); |
|
1971 |
subWindow3->showMaximized(); |
|
1972 |
||
1973 |
QMenuBar *menuBar = mainWindow->menuBar(); // force creation of a menubar |
|
1974 |
Q_UNUSED(menuBar); |
|
1975 |
||
1976 |
QPushButton *focus1 = new QPushButton(QLatin1String("Focus 1"), mainWindow); |
|
1977 |
QObject::connect(focus1, SIGNAL(clicked()), subWindow1, SLOT(setFocus())); |
|
1978 |
focus1->move(5, 30); |
|
1979 |
focus1->show(); |
|
1980 |
||
1981 |
QPushButton *focus2 = new QPushButton(QLatin1String("Focus 2"), mainWindow); |
|
1982 |
QObject::connect(focus2, SIGNAL(clicked()), subWindow2, SLOT(setFocus())); |
|
1983 |
focus2->move(5, 60); |
|
1984 |
focus2->show(); |
|
1985 |
||
1986 |
QPushButton *close = new QPushButton(QLatin1String("Close"), mainWindow); |
|
1987 |
QObject::connect(close, SIGNAL(clicked()), mainWindow, SLOT(close())); |
|
1988 |
close->move(5, 90); |
|
1989 |
close->show(); |
|
1990 |
||
1991 |
QTest::qWait(200); |
|
1992 |
||
1993 |
sendMousePress(focus2, QPoint()); |
|
1994 |
sendMouseRelease(focus2, QPoint()); |
|
1995 |
||
1996 |
sendMousePress(focus1, QPoint()); |
|
1997 |
sendMouseRelease(focus1, QPoint()); |
|
1998 |
||
1999 |
sendMousePress(focus2, QPoint()); |
|
2000 |
sendMouseRelease(focus2, QPoint()); |
|
2001 |
||
2002 |
sendMousePress(close, QPoint()); |
|
2003 |
sendMouseRelease(close, QPoint()); |
|
2004 |
||
2005 |
QTest::qWait(200); |
|
2006 |
} |
|
2007 |
||
2008 |
void tst_QMdiSubWindow::task_226929() |
|
2009 |
{ |
|
2010 |
QMdiArea mdiArea; |
|
2011 |
mdiArea.show(); |
|
2012 |
#ifdef Q_WS_X11 |
|
2013 |
qt_x11_wait_for_window_manager(&mdiArea); |
|
2014 |
#endif |
|
2015 |
||
2016 |
QMdiSubWindow *sub1 = mdiArea.addSubWindow(new QTextEdit); |
|
2017 |
sub1->showMinimized(); |
|
2018 |
||
2019 |
QMdiSubWindow *sub2 = mdiArea.addSubWindow(new QTextEdit); |
|
2020 |
sub2->showMaximized(); |
|
2021 |
||
2022 |
QTest::qWait(100); |
|
2023 |
||
2024 |
// Do not assert. |
|
2025 |
// This window will now be activated and automatically maximized |
|
2026 |
// (if not QMdiArea::DontMaximizeSubWindowOnActionvation is set). |
|
2027 |
sub1->showNormal(); |
|
2028 |
QVERIFY(sub1->isMaximized()); |
|
2029 |
} |
|
2030 |
||
2031 |
QTEST_MAIN(tst_QMdiSubWindow) |
|
2032 |
#include "tst_qmdisubwindow.moc" |
|
2033 |