0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
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 <qdialog.h>
|
|
46 |
#include <qapplication.h>
|
|
47 |
#include <qlineedit.h>
|
|
48 |
#include <qpushbutton.h>
|
|
49 |
#include <qstyle.h>
|
|
50 |
#include <QVBoxLayout>
|
|
51 |
#include <QSizeGrip>
|
|
52 |
|
|
53 |
#include "../../shared/util.h"
|
|
54 |
|
|
55 |
Q_DECLARE_METATYPE(QSize)
|
|
56 |
|
|
57 |
|
|
58 |
QT_FORWARD_DECLARE_CLASS(QDialog)
|
|
59 |
|
|
60 |
//TESTED_CLASS=
|
|
61 |
//TESTED_FILES=
|
|
62 |
|
|
63 |
class tst_QDialog : public QObject
|
|
64 |
{
|
|
65 |
Q_OBJECT
|
|
66 |
public:
|
|
67 |
tst_QDialog();
|
|
68 |
|
|
69 |
public slots:
|
|
70 |
void initTestCase();
|
|
71 |
void cleanupTestCase();
|
|
72 |
private slots:
|
|
73 |
void getSetCheck();
|
|
74 |
void showExtension_data();
|
|
75 |
void showExtension();
|
|
76 |
void defaultButtons();
|
|
77 |
void showMaximized();
|
|
78 |
void showMinimized();
|
|
79 |
void showFullScreen();
|
|
80 |
void showAsTool();
|
|
81 |
void toolDialogPosition();
|
|
82 |
void deleteMainDefault();
|
|
83 |
void deleteInExec();
|
|
84 |
void throwInExec();
|
|
85 |
void showSizeGrip();
|
|
86 |
void setVisible();
|
|
87 |
void reject();
|
|
88 |
|
|
89 |
private:
|
|
90 |
QDialog *testWidget;
|
|
91 |
};
|
|
92 |
|
|
93 |
// Testing get/set functions
|
|
94 |
void tst_QDialog::getSetCheck()
|
|
95 |
{
|
|
96 |
QDialog obj1;
|
|
97 |
// QWidget* QDialog::extension()
|
|
98 |
// void QDialog::setExtension(QWidget*)
|
|
99 |
QWidget *var1 = new QWidget;
|
|
100 |
obj1.setExtension(var1);
|
|
101 |
QCOMPARE(var1, obj1.extension());
|
|
102 |
obj1.setExtension((QWidget *)0);
|
|
103 |
QCOMPARE((QWidget *)0, obj1.extension());
|
|
104 |
// No delete var1, since setExtension takes ownership
|
|
105 |
|
|
106 |
// int QDialog::result()
|
|
107 |
// void QDialog::setResult(int)
|
|
108 |
obj1.setResult(0);
|
|
109 |
QCOMPARE(0, obj1.result());
|
|
110 |
obj1.setResult(INT_MIN);
|
|
111 |
QCOMPARE(INT_MIN, obj1.result());
|
|
112 |
obj1.setResult(INT_MAX);
|
|
113 |
QCOMPARE(INT_MAX, obj1.result());
|
|
114 |
}
|
|
115 |
|
|
116 |
// work around function being protected
|
|
117 |
class DummyDialog : public QDialog {
|
|
118 |
public:
|
|
119 |
DummyDialog(): QDialog(0) {}
|
|
120 |
void showExtension( bool b ) { QDialog::showExtension( b ); }
|
|
121 |
};
|
|
122 |
|
|
123 |
class ToolDialog : public QDialog
|
|
124 |
{
|
|
125 |
public:
|
|
126 |
ToolDialog(QWidget *parent = 0) : QDialog(parent, Qt::Tool), mWasActive(false), tId(-1) {
|
|
127 |
}
|
|
128 |
bool wasActive() const { return mWasActive; }
|
|
129 |
|
|
130 |
int exec() {
|
|
131 |
tId = startTimer(300);
|
|
132 |
return QDialog::exec();
|
|
133 |
}
|
|
134 |
protected:
|
|
135 |
void timerEvent(QTimerEvent *event) {
|
|
136 |
if (tId == event->timerId()) {
|
|
137 |
killTimer(tId);
|
|
138 |
mWasActive = isActiveWindow();
|
|
139 |
reject();
|
|
140 |
}
|
|
141 |
}
|
|
142 |
|
|
143 |
private:
|
|
144 |
int mWasActive;
|
|
145 |
int tId;
|
|
146 |
};
|
|
147 |
|
|
148 |
tst_QDialog::tst_QDialog()
|
|
149 |
|
|
150 |
{
|
|
151 |
}
|
|
152 |
|
|
153 |
void tst_QDialog::initTestCase()
|
|
154 |
{
|
|
155 |
// Create the test class
|
|
156 |
testWidget = new QDialog(0, Qt::X11BypassWindowManagerHint);
|
|
157 |
testWidget->resize(200,200);
|
|
158 |
testWidget->show();
|
|
159 |
qApp->setActiveWindow(testWidget);
|
|
160 |
}
|
|
161 |
|
|
162 |
void tst_QDialog::cleanupTestCase()
|
|
163 |
{
|
|
164 |
if (testWidget) {
|
|
165 |
delete testWidget;
|
|
166 |
testWidget = 0;
|
|
167 |
}
|
|
168 |
}
|
|
169 |
|
|
170 |
void tst_QDialog::showExtension_data()
|
|
171 |
{
|
|
172 |
QTest::addColumn<QSize>("dlgSize");
|
|
173 |
QTest::addColumn<QSize>("extSize");
|
|
174 |
QTest::addColumn<bool>("horizontal");
|
|
175 |
QTest::addColumn<QSize>("result");
|
|
176 |
|
|
177 |
//next we fill it with data
|
|
178 |
QTest::newRow( "data0" ) << QSize(100,100) << QSize(50,50) << (bool)FALSE << QSize(100,150);
|
|
179 |
QTest::newRow( "data1" ) << QSize(100,100) << QSize(120,50) << (bool)FALSE << QSize(120,150);
|
|
180 |
QTest::newRow( "data2" ) << QSize(100,100) << QSize(50,50) << (bool)TRUE << QSize(150,100);
|
|
181 |
QTest::newRow( "data3" ) << QSize(100,100) << QSize(50,120) << (bool)TRUE << QSize(150,120);
|
|
182 |
}
|
|
183 |
|
|
184 |
void tst_QDialog::showExtension()
|
|
185 |
{
|
|
186 |
QFETCH( QSize, dlgSize );
|
|
187 |
QFETCH( QSize, extSize );
|
|
188 |
QFETCH( bool, horizontal );
|
|
189 |
|
|
190 |
// set geometry of main dialog and extension widget
|
|
191 |
testWidget->setFixedSize( dlgSize );
|
|
192 |
QWidget *ext = new QWidget( testWidget );
|
|
193 |
ext->setFixedSize( extSize );
|
|
194 |
testWidget->setExtension( ext );
|
|
195 |
testWidget->setOrientation( horizontal ? Qt::Horizontal : Qt::Vertical );
|
|
196 |
|
|
197 |
QCOMPARE( testWidget->size(), dlgSize );
|
|
198 |
QPoint oldPosition = testWidget->pos();
|
|
199 |
|
|
200 |
#ifdef Q_WS_S60
|
|
201 |
const int htDiff = ext->size().height() - testWidget->size().height();
|
|
202 |
#endif
|
|
203 |
// show
|
|
204 |
((DummyDialog*)testWidget)->showExtension( TRUE );
|
|
205 |
// while ( testWidget->size() == dlgSize )
|
|
206 |
// qApp->processEvents();
|
|
207 |
|
|
208 |
#ifdef Q_WS_S60
|
|
209 |
QPoint expectedPosition;
|
|
210 |
if (!horizontal) {
|
|
211 |
expectedPosition = QPoint(0, oldPosition.y() - extSize.height());
|
|
212 |
} else {
|
|
213 |
if (htDiff>0)
|
|
214 |
expectedPosition = QPoint(0, oldPosition.y() - htDiff);
|
|
215 |
else
|
|
216 |
expectedPosition = oldPosition;
|
|
217 |
}
|
|
218 |
#endif
|
|
219 |
|
|
220 |
QTEST( testWidget->size(), "result" );
|
|
221 |
|
|
222 |
#ifdef Q_WS_S60
|
|
223 |
QCOMPARE(testWidget->pos(), expectedPosition);
|
|
224 |
#else
|
|
225 |
QCOMPARE(testWidget->pos(), oldPosition);
|
|
226 |
#endif
|
|
227 |
|
|
228 |
// hide extension. back to old size ?
|
|
229 |
((DummyDialog*)testWidget)->showExtension( FALSE );
|
|
230 |
QCOMPARE( testWidget->size(), dlgSize );
|
|
231 |
|
|
232 |
testWidget->setExtension( 0 );
|
|
233 |
}
|
|
234 |
|
|
235 |
void tst_QDialog::defaultButtons()
|
|
236 |
{
|
|
237 |
QLineEdit *lineEdit = new QLineEdit(testWidget);
|
|
238 |
QPushButton *push = new QPushButton("Button 1", testWidget);
|
|
239 |
QPushButton *pushTwo = new QPushButton("Button 2", testWidget);
|
|
240 |
QPushButton *pushThree = new QPushButton("Button 3", testWidget);
|
|
241 |
pushThree->setAutoDefault(FALSE);
|
|
242 |
|
|
243 |
//we need to show the buttons. Otherwise they won't get the focus
|
|
244 |
push->show();
|
|
245 |
pushTwo->show();
|
|
246 |
pushThree->show();
|
|
247 |
|
|
248 |
push->setDefault(TRUE);
|
|
249 |
QVERIFY(push->isDefault());
|
|
250 |
|
|
251 |
pushTwo->setFocus();
|
|
252 |
QVERIFY(pushTwo->isDefault());
|
|
253 |
pushThree->setFocus();
|
|
254 |
QVERIFY(push->isDefault());
|
|
255 |
lineEdit->setFocus();
|
|
256 |
QVERIFY(push->isDefault());
|
|
257 |
|
|
258 |
pushTwo->setDefault(TRUE);
|
|
259 |
QVERIFY(pushTwo->isDefault());
|
|
260 |
|
|
261 |
pushTwo->setFocus();
|
|
262 |
QVERIFY(pushTwo->isDefault());
|
|
263 |
lineEdit->setFocus();
|
|
264 |
QVERIFY(pushTwo->isDefault());
|
|
265 |
}
|
|
266 |
|
|
267 |
void tst_QDialog::showMaximized()
|
|
268 |
{
|
|
269 |
QDialog dialog(0);
|
|
270 |
dialog.setSizeGripEnabled(true);
|
|
271 |
QSizeGrip *sizeGrip = qFindChild<QSizeGrip *>(&dialog);
|
|
272 |
QVERIFY(sizeGrip);
|
|
273 |
|
|
274 |
dialog.showMaximized();
|
|
275 |
QVERIFY(dialog.isMaximized());
|
|
276 |
QVERIFY(dialog.isVisible());
|
|
277 |
#if !defined(Q_WS_MAC) && !defined(Q_OS_IRIX) && !defined(Q_OS_HPUX)
|
|
278 |
QVERIFY(!sizeGrip->isVisible());
|
|
279 |
#endif
|
|
280 |
|
|
281 |
dialog.showNormal();
|
|
282 |
QVERIFY(!dialog.isMaximized());
|
|
283 |
QVERIFY(dialog.isVisible());
|
|
284 |
QVERIFY(sizeGrip->isVisible());
|
|
285 |
|
|
286 |
dialog.showMaximized();
|
|
287 |
QVERIFY(dialog.isMaximized());
|
|
288 |
QVERIFY(dialog.isVisible());
|
|
289 |
|
|
290 |
dialog.hide();
|
|
291 |
QVERIFY(dialog.isMaximized());
|
|
292 |
QVERIFY(!dialog.isVisible());
|
|
293 |
|
|
294 |
dialog.show();
|
|
295 |
QVERIFY(dialog.isMaximized());
|
|
296 |
QVERIFY(dialog.isVisible());
|
|
297 |
|
|
298 |
dialog.hide();
|
|
299 |
QVERIFY(dialog.isMaximized());
|
|
300 |
QVERIFY(!dialog.isVisible());
|
|
301 |
|
|
302 |
dialog.showMaximized();
|
|
303 |
QVERIFY(dialog.isMaximized());
|
|
304 |
QVERIFY(dialog.isVisible());
|
|
305 |
}
|
|
306 |
|
|
307 |
void tst_QDialog::showMinimized()
|
|
308 |
{
|
|
309 |
QDialog dialog(0);
|
|
310 |
|
|
311 |
dialog.showMinimized();
|
|
312 |
QVERIFY(dialog.isMinimized());
|
|
313 |
QVERIFY(dialog.isVisible());
|
|
314 |
|
|
315 |
dialog.showNormal();
|
|
316 |
QVERIFY(!dialog.isMinimized());
|
|
317 |
QVERIFY(dialog.isVisible());
|
|
318 |
|
|
319 |
dialog.showMinimized();
|
|
320 |
QVERIFY(dialog.isMinimized());
|
|
321 |
QVERIFY(dialog.isVisible());
|
|
322 |
|
|
323 |
dialog.hide();
|
|
324 |
QVERIFY(dialog.isMinimized());
|
|
325 |
QVERIFY(!dialog.isVisible());
|
|
326 |
|
|
327 |
dialog.show();
|
|
328 |
QVERIFY(dialog.isMinimized());
|
|
329 |
QVERIFY(dialog.isVisible());
|
|
330 |
|
|
331 |
dialog.hide();
|
|
332 |
QVERIFY(dialog.isMinimized());
|
|
333 |
QVERIFY(!dialog.isVisible());
|
|
334 |
|
|
335 |
dialog.showMinimized();
|
|
336 |
QVERIFY(dialog.isMinimized());
|
|
337 |
QVERIFY(dialog.isVisible());
|
|
338 |
}
|
|
339 |
|
|
340 |
void tst_QDialog::showFullScreen()
|
|
341 |
{
|
|
342 |
QDialog dialog(0, Qt::X11BypassWindowManagerHint);
|
|
343 |
dialog.setSizeGripEnabled(true);
|
|
344 |
QSizeGrip *sizeGrip = qFindChild<QSizeGrip *>(&dialog);
|
|
345 |
QVERIFY(sizeGrip);
|
|
346 |
|
|
347 |
qApp->syncX();
|
|
348 |
dialog.showFullScreen();
|
|
349 |
QVERIFY(dialog.isFullScreen());
|
|
350 |
QVERIFY(dialog.isVisible());
|
|
351 |
QVERIFY(!sizeGrip->isVisible());
|
|
352 |
|
|
353 |
qApp->syncX();
|
|
354 |
dialog.showNormal();
|
|
355 |
QVERIFY(!dialog.isFullScreen());
|
|
356 |
QVERIFY(dialog.isVisible());
|
|
357 |
QVERIFY(sizeGrip->isVisible());
|
|
358 |
|
|
359 |
qApp->syncX();
|
|
360 |
dialog.showFullScreen();
|
|
361 |
QVERIFY(dialog.isFullScreen());
|
|
362 |
QVERIFY(dialog.isVisible());
|
|
363 |
|
|
364 |
qApp->syncX();
|
|
365 |
dialog.hide();
|
|
366 |
QVERIFY(dialog.isFullScreen());
|
|
367 |
QVERIFY(!dialog.isVisible());
|
|
368 |
|
|
369 |
qApp->syncX();
|
|
370 |
dialog.show();
|
|
371 |
QVERIFY(dialog.isFullScreen());
|
|
372 |
QVERIFY(dialog.isVisible());
|
|
373 |
|
|
374 |
qApp->syncX();
|
|
375 |
dialog.hide();
|
|
376 |
QVERIFY(dialog.isFullScreen());
|
|
377 |
QVERIFY(!dialog.isVisible());
|
|
378 |
|
|
379 |
qApp->syncX();
|
|
380 |
dialog.showFullScreen();
|
|
381 |
QVERIFY(dialog.isFullScreen());
|
|
382 |
QVERIFY(dialog.isVisible());
|
|
383 |
|
|
384 |
qApp->syncX();
|
|
385 |
dialog.hide();
|
|
386 |
QVERIFY(dialog.isFullScreen());
|
|
387 |
QVERIFY(!dialog.isVisible());
|
|
388 |
}
|
|
389 |
|
|
390 |
void tst_QDialog::showAsTool()
|
|
391 |
{
|
|
392 |
#if defined(Q_WS_X11)
|
|
393 |
QSKIP("Qt/X11: Skipped since activeWindow() is not respected by all window managers", SkipAll);
|
|
394 |
#elif defined(Q_OS_WINCE)
|
|
395 |
QSKIP("No real support for Qt::Tool on WinCE", SkipAll);
|
|
396 |
#endif
|
|
397 |
ToolDialog dialog(testWidget);
|
|
398 |
testWidget->activateWindow();
|
|
399 |
dialog.exec();
|
|
400 |
QTest::qWait(100);
|
|
401 |
if (testWidget->style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, testWidget)) {
|
|
402 |
QCOMPARE(dialog.wasActive(), true);
|
|
403 |
} else {
|
|
404 |
QCOMPARE(dialog.wasActive(), false);
|
|
405 |
}
|
|
406 |
}
|
|
407 |
|
|
408 |
// Verify that pos() returns the same before and after show()
|
|
409 |
// for a dialog with the Tool window type.
|
|
410 |
void tst_QDialog::toolDialogPosition()
|
|
411 |
{
|
|
412 |
#if defined(Q_OS_WINCE)
|
|
413 |
QSKIP("No real support for Qt::Tool on WinCE", SkipAll);
|
|
414 |
#endif
|
|
415 |
QDialog dialog(0, Qt::Tool);
|
|
416 |
dialog.move(QPoint(100,100));
|
|
417 |
const QPoint beforeShowPosition = dialog.pos();
|
|
418 |
dialog.show();
|
|
419 |
const QPoint afterShowPosition = dialog.pos();
|
|
420 |
QCOMPARE(afterShowPosition, beforeShowPosition);
|
|
421 |
}
|
|
422 |
|
|
423 |
class Dialog : public QDialog
|
|
424 |
{
|
|
425 |
public:
|
|
426 |
Dialog(QPushButton *&button)
|
|
427 |
{
|
|
428 |
button = new QPushButton(this);
|
|
429 |
}
|
|
430 |
};
|
|
431 |
|
|
432 |
void tst_QDialog::deleteMainDefault()
|
|
433 |
{
|
|
434 |
QPushButton *button;
|
|
435 |
Dialog dialog(button);
|
|
436 |
button->setDefault(true);
|
|
437 |
delete button;
|
|
438 |
dialog.show();
|
|
439 |
QTestEventLoop::instance().enterLoop(2);
|
|
440 |
}
|
|
441 |
|
|
442 |
void tst_QDialog::deleteInExec()
|
|
443 |
{
|
|
444 |
QDialog *dialog = new QDialog(0);
|
|
445 |
QMetaObject::invokeMethod(dialog, "deleteLater", Qt::QueuedConnection);
|
|
446 |
QCOMPARE(dialog->exec(), int(QDialog::Rejected));
|
|
447 |
}
|
|
448 |
|
|
449 |
#ifndef QT_NO_EXCEPTIONS
|
|
450 |
class QDialogTestException { };
|
|
451 |
|
|
452 |
class ExceptionDialog : public QDialog
|
|
453 |
{
|
|
454 |
Q_OBJECT
|
|
455 |
public:
|
|
456 |
ExceptionDialog() : QDialog(0) { }
|
|
457 |
public slots:
|
|
458 |
void throwException()
|
|
459 |
{
|
|
460 |
QDialogTestException e;
|
|
461 |
throw e;
|
|
462 |
}
|
|
463 |
};
|
|
464 |
|
|
465 |
void tst_QDialog::throwInExec()
|
|
466 |
{
|
|
467 |
#ifdef Q_WS_MAC
|
|
468 |
QSKIP("Qt/Mac: Throwing exceptions in exec() is not supported.", SkipAll);
|
|
469 |
#endif
|
|
470 |
int caughtExceptions = 0;
|
|
471 |
try {
|
|
472 |
ExceptionDialog dialog;
|
|
473 |
QMetaObject::invokeMethod(&dialog, "throwException", Qt::QueuedConnection);
|
|
474 |
(void) dialog.exec();
|
|
475 |
} catch(...) {
|
|
476 |
++caughtExceptions;
|
|
477 |
}
|
|
478 |
QCOMPARE(caughtExceptions, 1);
|
|
479 |
}
|
|
480 |
#else
|
|
481 |
void tst_QDialog::throwInExec()
|
|
482 |
{
|
|
483 |
QSKIP("Exceptions are disabled", SkipAll);
|
|
484 |
}
|
|
485 |
#endif //QT_NO_EXCEPTIONS
|
|
486 |
|
|
487 |
// From Task 124269
|
|
488 |
void tst_QDialog::showSizeGrip()
|
|
489 |
{
|
|
490 |
#ifndef QT_NO_SIZEGRIP
|
|
491 |
QDialog dialog(0);
|
|
492 |
dialog.show();
|
|
493 |
QWidget *ext = new QWidget(&dialog);
|
|
494 |
QVERIFY(!dialog.extension());
|
|
495 |
QVERIFY(!dialog.isSizeGripEnabled());
|
|
496 |
|
|
497 |
dialog.setSizeGripEnabled(true);
|
|
498 |
QPointer<QSizeGrip> sizeGrip = qFindChild<QSizeGrip *>(&dialog);
|
|
499 |
QVERIFY(sizeGrip);
|
|
500 |
QVERIFY(sizeGrip->isVisible());
|
|
501 |
QVERIFY(dialog.isSizeGripEnabled());
|
|
502 |
|
|
503 |
dialog.setExtension(ext);
|
|
504 |
QVERIFY(dialog.extension() && !dialog.extension()->isVisible());
|
|
505 |
QVERIFY(dialog.isSizeGripEnabled());
|
|
506 |
|
|
507 |
// normal show/hide sequence
|
|
508 |
dialog.showExtension(true);
|
|
509 |
QVERIFY(dialog.extension() && dialog.extension()->isVisible());
|
|
510 |
QVERIFY(!dialog.isSizeGripEnabled());
|
|
511 |
QVERIFY(!sizeGrip);
|
|
512 |
|
|
513 |
dialog.showExtension(false);
|
|
514 |
QVERIFY(dialog.extension() && !dialog.extension()->isVisible());
|
|
515 |
QVERIFY(dialog.isSizeGripEnabled());
|
|
516 |
sizeGrip = qFindChild<QSizeGrip *>(&dialog);
|
|
517 |
QVERIFY(sizeGrip);
|
|
518 |
QVERIFY(sizeGrip->isVisible());
|
|
519 |
|
|
520 |
// show/hide sequence with interleaved size grip update
|
|
521 |
dialog.showExtension(true);
|
|
522 |
QVERIFY(dialog.extension() && dialog.extension()->isVisible());
|
|
523 |
QVERIFY(!dialog.isSizeGripEnabled());
|
|
524 |
QVERIFY(!sizeGrip);
|
|
525 |
|
|
526 |
dialog.setSizeGripEnabled(false);
|
|
527 |
QVERIFY(!dialog.isSizeGripEnabled());
|
|
528 |
|
|
529 |
dialog.showExtension(false);
|
|
530 |
QVERIFY(dialog.extension() && !dialog.extension()->isVisible());
|
|
531 |
QVERIFY(!dialog.isSizeGripEnabled());
|
|
532 |
|
|
533 |
dialog.setSizeGripEnabled(true);
|
|
534 |
sizeGrip = qFindChild<QSizeGrip *>(&dialog);
|
|
535 |
QVERIFY(sizeGrip);
|
|
536 |
QVERIFY(sizeGrip->isVisible());
|
|
537 |
sizeGrip->hide();
|
|
538 |
dialog.hide();
|
|
539 |
dialog.show();
|
|
540 |
QVERIFY(!sizeGrip->isVisible());
|
|
541 |
#endif
|
|
542 |
}
|
|
543 |
|
|
544 |
void tst_QDialog::setVisible()
|
|
545 |
{
|
|
546 |
QWidget topLevel;
|
|
547 |
topLevel.show();
|
|
548 |
|
|
549 |
QDialog *dialog = new QDialog;
|
|
550 |
dialog->setLayout(new QVBoxLayout);
|
|
551 |
dialog->layout()->addWidget(new QPushButton("dialog button"));
|
|
552 |
|
|
553 |
QWidget *widget = new QWidget(&topLevel);
|
|
554 |
widget->setLayout(new QVBoxLayout);
|
|
555 |
widget->layout()->addWidget(dialog);
|
|
556 |
|
|
557 |
QVERIFY(!dialog->isVisible());
|
|
558 |
QVERIFY(!dialog->isHidden());
|
|
559 |
|
|
560 |
widget->show();
|
|
561 |
QVERIFY(dialog->isVisible());
|
|
562 |
QVERIFY(!dialog->isHidden());
|
|
563 |
|
|
564 |
widget->hide();
|
|
565 |
dialog->hide();
|
|
566 |
widget->show();
|
|
567 |
QVERIFY(!dialog->isVisible());
|
|
568 |
QVERIFY(dialog->isHidden());
|
|
569 |
}
|
|
570 |
|
|
571 |
class TestRejectDialog : public QDialog
|
|
572 |
{
|
|
573 |
public:
|
|
574 |
TestRejectDialog() : cancelReject(false), called(0) {}
|
|
575 |
void reject()
|
|
576 |
{
|
|
577 |
called++;
|
|
578 |
if (!cancelReject)
|
|
579 |
QDialog::reject();
|
|
580 |
}
|
|
581 |
bool cancelReject;
|
|
582 |
int called;
|
|
583 |
};
|
|
584 |
|
|
585 |
void tst_QDialog::reject()
|
|
586 |
{
|
|
587 |
TestRejectDialog dialog;
|
|
588 |
dialog.show();
|
|
589 |
QTest::qWaitForWindowShown(&dialog);
|
|
590 |
QTRY_VERIFY(dialog.isVisible());
|
|
591 |
dialog.reject();
|
|
592 |
QTRY_VERIFY(!dialog.isVisible());
|
|
593 |
QCOMPARE(dialog.called, 1);
|
|
594 |
|
|
595 |
dialog.show();
|
|
596 |
QTest::qWaitForWindowShown(&dialog);
|
|
597 |
QTRY_VERIFY(dialog.isVisible());
|
|
598 |
QVERIFY(dialog.close());
|
|
599 |
QTRY_VERIFY(!dialog.isVisible());
|
|
600 |
QCOMPARE(dialog.called, 2);
|
|
601 |
|
|
602 |
dialog.cancelReject = true;
|
|
603 |
dialog.show();
|
|
604 |
QTest::qWaitForWindowShown(&dialog);
|
|
605 |
QTRY_VERIFY(dialog.isVisible());
|
|
606 |
dialog.reject();
|
|
607 |
QTRY_VERIFY(dialog.isVisible());
|
|
608 |
QCOMPARE(dialog.called, 3);
|
|
609 |
QVERIFY(!dialog.close());
|
|
610 |
QTRY_VERIFY(dialog.isVisible());
|
|
611 |
QCOMPARE(dialog.called, 4);
|
|
612 |
}
|
|
613 |
|
|
614 |
|
|
615 |
QTEST_MAIN(tst_QDialog)
|
|
616 |
#include "tst_qdialog.moc"
|