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 |
|
|
46 |
#include "qpushbutton.h"
|
|
47 |
#include <qapplication.h>
|
|
48 |
|
|
49 |
#include <qpushbutton.h>
|
|
50 |
#include <qmenu.h>
|
|
51 |
#include <qtimer.h>
|
|
52 |
#include <QDialog>
|
|
53 |
#include <QGridLayout>
|
|
54 |
#include <QStyleFactory>
|
|
55 |
#include <QTabWidget>
|
|
56 |
|
|
57 |
#include "../../shared/util.h"
|
|
58 |
|
|
59 |
Q_DECLARE_METATYPE(QPushButton*)
|
|
60 |
|
|
61 |
//TESTED_CLASS=
|
|
62 |
//TESTED_FILES=
|
|
63 |
|
|
64 |
class tst_QPushButton : public QObject
|
|
65 |
{
|
|
66 |
Q_OBJECT
|
|
67 |
public:
|
|
68 |
tst_QPushButton();
|
|
69 |
virtual ~tst_QPushButton();
|
|
70 |
|
|
71 |
|
|
72 |
public slots:
|
|
73 |
void initTestCase();
|
|
74 |
void cleanupTestCase();
|
|
75 |
void init();
|
|
76 |
void cleanup();
|
|
77 |
private slots:
|
|
78 |
void getSetCheck();
|
|
79 |
void setAutoRepeat();
|
|
80 |
void pressed();
|
|
81 |
void released();
|
|
82 |
void text();
|
|
83 |
void accel();
|
|
84 |
void setAccel();
|
|
85 |
void isCheckable();
|
|
86 |
void isDown();
|
|
87 |
void setDown();
|
|
88 |
void popupCrash();
|
|
89 |
void isChecked();
|
|
90 |
void autoRepeat();
|
|
91 |
void animateClick();
|
|
92 |
void toggle();
|
|
93 |
void clicked();
|
|
94 |
void toggled();
|
|
95 |
void isEnabled();
|
|
96 |
void defaultAndAutoDefault();
|
|
97 |
void sizeHint_data();
|
|
98 |
void sizeHint();
|
|
99 |
/*
|
|
100 |
void state();
|
|
101 |
void group();
|
|
102 |
void stateChanged();
|
|
103 |
*/
|
|
104 |
|
|
105 |
protected slots:
|
|
106 |
void resetCounters();
|
|
107 |
void onClicked();
|
|
108 |
void onToggled( bool on );
|
|
109 |
void onPressed();
|
|
110 |
void onReleased();
|
|
111 |
void helperSlotDelete();
|
|
112 |
|
|
113 |
private:
|
|
114 |
uint click_count;
|
|
115 |
uint toggle_count;
|
|
116 |
uint press_count;
|
|
117 |
uint release_count;
|
|
118 |
|
|
119 |
QPushButton *testWidget;
|
|
120 |
};
|
|
121 |
|
|
122 |
// Testing get/set functions
|
|
123 |
void tst_QPushButton::getSetCheck()
|
|
124 |
{
|
|
125 |
QPushButton obj1;
|
|
126 |
// QMenu* QPushButton::menu()
|
|
127 |
// void QPushButton::setMenu(QMenu*)
|
|
128 |
QMenu *var1 = new QMenu;
|
|
129 |
obj1.setMenu(var1);
|
|
130 |
QCOMPARE(var1, obj1.menu());
|
|
131 |
obj1.setMenu((QMenu *)0);
|
|
132 |
QCOMPARE((QMenu *)0, obj1.menu());
|
|
133 |
delete var1;
|
|
134 |
}
|
|
135 |
|
|
136 |
tst_QPushButton::tst_QPushButton()
|
|
137 |
{
|
|
138 |
}
|
|
139 |
|
|
140 |
tst_QPushButton::~tst_QPushButton()
|
|
141 |
{
|
|
142 |
}
|
|
143 |
|
|
144 |
void tst_QPushButton::initTestCase()
|
|
145 |
{
|
|
146 |
// Create the test class
|
|
147 |
testWidget = new QPushButton( "&Start", 0 );
|
|
148 |
testWidget->setObjectName("testWidget");
|
|
149 |
testWidget->resize( 200, 200 );
|
|
150 |
testWidget->show();
|
|
151 |
|
|
152 |
connect( testWidget, SIGNAL(clicked()), this, SLOT(onClicked()) );
|
|
153 |
connect( testWidget, SIGNAL(pressed()), this, SLOT(onPressed()) );
|
|
154 |
connect( testWidget, SIGNAL(released()), this, SLOT(onReleased()) );
|
|
155 |
connect( testWidget, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool)) );
|
|
156 |
}
|
|
157 |
|
|
158 |
void tst_QPushButton::cleanupTestCase()
|
|
159 |
{
|
|
160 |
delete testWidget;
|
|
161 |
testWidget = 0;
|
|
162 |
}
|
|
163 |
|
|
164 |
void tst_QPushButton::init()
|
|
165 |
{
|
|
166 |
testWidget->setAutoRepeat( FALSE );
|
|
167 |
testWidget->setDown( FALSE );
|
|
168 |
testWidget->setText("Test");
|
|
169 |
testWidget->setEnabled( TRUE );
|
|
170 |
QKeySequence seq;
|
|
171 |
testWidget->setShortcut( seq );
|
|
172 |
|
|
173 |
resetCounters();
|
|
174 |
}
|
|
175 |
|
|
176 |
void tst_QPushButton::cleanup()
|
|
177 |
{
|
|
178 |
}
|
|
179 |
|
|
180 |
|
|
181 |
void tst_QPushButton::resetCounters()
|
|
182 |
{
|
|
183 |
toggle_count = 0;
|
|
184 |
press_count = 0;
|
|
185 |
release_count = 0;
|
|
186 |
click_count = 0;
|
|
187 |
}
|
|
188 |
|
|
189 |
void tst_QPushButton::onClicked()
|
|
190 |
{
|
|
191 |
click_count++;
|
|
192 |
}
|
|
193 |
|
|
194 |
void tst_QPushButton::onToggled( bool /*on*/ )
|
|
195 |
{
|
|
196 |
toggle_count++;
|
|
197 |
}
|
|
198 |
|
|
199 |
void tst_QPushButton::onPressed()
|
|
200 |
{
|
|
201 |
press_count++;
|
|
202 |
}
|
|
203 |
|
|
204 |
void tst_QPushButton::onReleased()
|
|
205 |
{
|
|
206 |
release_count++;
|
|
207 |
}
|
|
208 |
|
|
209 |
void tst_QPushButton::setAutoRepeat()
|
|
210 |
{
|
|
211 |
// If this changes, this test must be completely revised.
|
|
212 |
QVERIFY( !testWidget->isCheckable() );
|
|
213 |
|
|
214 |
// verify autorepeat is off by default.
|
|
215 |
QPushButton tmp( 0 );
|
|
216 |
tmp.setObjectName("tmp");
|
|
217 |
QVERIFY( !tmp.autoRepeat() );
|
|
218 |
|
|
219 |
// check if we can toggle the mode
|
|
220 |
testWidget->setAutoRepeat( TRUE );
|
|
221 |
QVERIFY( testWidget->autoRepeat() );
|
|
222 |
|
|
223 |
testWidget->setAutoRepeat( FALSE );
|
|
224 |
QVERIFY( !testWidget->autoRepeat() );
|
|
225 |
|
|
226 |
resetCounters();
|
|
227 |
|
|
228 |
// check that the button is down if we press space and not in autorepeat
|
|
229 |
testWidget->setDown( FALSE );
|
|
230 |
testWidget->setAutoRepeat( FALSE );
|
|
231 |
QTest::keyPress( testWidget, Qt::Key_Space );
|
|
232 |
|
|
233 |
QTest::qWait( 300 );
|
|
234 |
|
|
235 |
QVERIFY( testWidget->isDown() );
|
|
236 |
QVERIFY( toggle_count == 0 );
|
|
237 |
QVERIFY( press_count == 1 );
|
|
238 |
QVERIFY( release_count == 0 );
|
|
239 |
QVERIFY( click_count == 0 );
|
|
240 |
|
|
241 |
QTest::keyRelease( testWidget, Qt::Key_Space );
|
|
242 |
resetCounters();
|
|
243 |
|
|
244 |
// check that the button is down if we press space while in autorepeat
|
|
245 |
// we can't actually confirm how many times it is fired, more than 1 is enough.
|
|
246 |
|
|
247 |
testWidget->setDown( FALSE );
|
|
248 |
testWidget->setAutoRepeat( TRUE );
|
|
249 |
QTest::keyPress( testWidget, Qt::Key_Space );
|
|
250 |
QTest::qWait(900);
|
|
251 |
QVERIFY( testWidget->isDown() );
|
|
252 |
QVERIFY( toggle_count == 0 );
|
|
253 |
QTest::keyRelease( testWidget, Qt::Key_Space );
|
|
254 |
QVERIFY(press_count == release_count);
|
|
255 |
QVERIFY(release_count == click_count);
|
|
256 |
QVERIFY(press_count > 1);
|
|
257 |
|
|
258 |
// #### shouldn't I check here to see if multiple signals have been fired???
|
|
259 |
|
|
260 |
// check that pressing ENTER has no effect
|
|
261 |
resetCounters();
|
|
262 |
testWidget->setDown( FALSE );
|
|
263 |
testWidget->setAutoRepeat( FALSE );
|
|
264 |
QTest::keyPress( testWidget, Qt::Key_Enter );
|
|
265 |
|
|
266 |
QTest::qWait( 300 );
|
|
267 |
|
|
268 |
QVERIFY( !testWidget->isDown() );
|
|
269 |
QVERIFY( toggle_count == 0 );
|
|
270 |
QVERIFY( press_count == 0 );
|
|
271 |
QVERIFY( release_count == 0 );
|
|
272 |
QVERIFY( click_count == 0 );
|
|
273 |
QTest::keyRelease( testWidget, Qt::Key_Enter );
|
|
274 |
|
|
275 |
// check that pressing ENTER has no effect
|
|
276 |
resetCounters();
|
|
277 |
testWidget->setDown( FALSE );
|
|
278 |
testWidget->setAutoRepeat( TRUE );
|
|
279 |
QTest::keyClick( testWidget, Qt::Key_Enter );
|
|
280 |
QTest::qWait( 300 );
|
|
281 |
QVERIFY( !testWidget->isDown() );
|
|
282 |
QVERIFY( toggle_count == 0 );
|
|
283 |
QVERIFY( press_count == 0 );
|
|
284 |
QVERIFY( release_count == 0 );
|
|
285 |
QVERIFY( click_count == 0 );
|
|
286 |
}
|
|
287 |
|
|
288 |
void tst_QPushButton::autoRepeat()
|
|
289 |
{
|
|
290 |
DEPENDS_ON(" setAutoRepeat" );
|
|
291 |
}
|
|
292 |
|
|
293 |
void tst_QPushButton::pressed()
|
|
294 |
{
|
|
295 |
QTest::keyPress( testWidget, ' ' );
|
|
296 |
// QTest::qWait( 300 );
|
|
297 |
QCOMPARE( press_count, (uint)1 );
|
|
298 |
QCOMPARE( release_count, (uint)0 );
|
|
299 |
|
|
300 |
QTest::keyRelease( testWidget, ' ' );
|
|
301 |
// QTest::qWait( 300 );
|
|
302 |
QCOMPARE( press_count, (uint)1 );
|
|
303 |
QCOMPARE( release_count, (uint)1 );
|
|
304 |
|
|
305 |
QTest::keyPress( testWidget,Qt::Key_Enter );
|
|
306 |
// QTest::qWait( 300 );
|
|
307 |
QCOMPARE( press_count, (uint)1 );
|
|
308 |
QCOMPARE( release_count, (uint)1 );
|
|
309 |
|
|
310 |
testWidget->setAutoDefault(true);
|
|
311 |
QTest::keyPress( testWidget,Qt::Key_Enter );
|
|
312 |
// QTest::qWait( 300 );
|
|
313 |
QCOMPARE( press_count, (uint)2 );
|
|
314 |
QCOMPARE( release_count, (uint)2 );
|
|
315 |
testWidget->setAutoDefault(false);
|
|
316 |
|
|
317 |
}
|
|
318 |
|
|
319 |
void tst_QPushButton::released()
|
|
320 |
{
|
|
321 |
DEPENDS_ON( "pressed" );
|
|
322 |
}
|
|
323 |
|
|
324 |
void tst_QPushButton::text()
|
|
325 |
{
|
|
326 |
DEPENDS_ON( "setText" );
|
|
327 |
}
|
|
328 |
|
|
329 |
void tst_QPushButton::isEnabled()
|
|
330 |
{
|
|
331 |
DEPENDS_ON( "setEnabled" );
|
|
332 |
}
|
|
333 |
|
|
334 |
void tst_QPushButton::isCheckable()
|
|
335 |
{
|
|
336 |
QVERIFY( !testWidget->isCheckable() );
|
|
337 |
}
|
|
338 |
|
|
339 |
void tst_QPushButton::isDown()
|
|
340 |
{
|
|
341 |
DEPENDS_ON( "setDown" );
|
|
342 |
}
|
|
343 |
|
|
344 |
void tst_QPushButton::setDown()
|
|
345 |
{
|
|
346 |
testWidget->setDown( FALSE );
|
|
347 |
QVERIFY( !testWidget->isDown() );
|
|
348 |
|
|
349 |
testWidget->setDown( TRUE );
|
|
350 |
QVERIFY( testWidget->isDown() );
|
|
351 |
|
|
352 |
testWidget->setDown( TRUE );
|
|
353 |
QTest::keyClick( testWidget, Qt::Key_Escape );
|
|
354 |
QVERIFY( !testWidget->isDown() );
|
|
355 |
}
|
|
356 |
|
|
357 |
void tst_QPushButton::isChecked()
|
|
358 |
{
|
|
359 |
testWidget->setDown( FALSE );
|
|
360 |
QVERIFY( !testWidget->isChecked() );
|
|
361 |
|
|
362 |
testWidget->setDown( TRUE );
|
|
363 |
QVERIFY( !testWidget->isChecked() );
|
|
364 |
|
|
365 |
testWidget->setDown( FALSE );
|
|
366 |
testWidget->toggle();
|
|
367 |
QVERIFY( testWidget->isChecked() == testWidget->isCheckable() );
|
|
368 |
}
|
|
369 |
|
|
370 |
void tst_QPushButton::toggle()
|
|
371 |
{
|
|
372 |
// the pushbutton shouldn't toggle the button.
|
|
373 |
testWidget->toggle();
|
|
374 |
QVERIFY( testWidget->isChecked() == FALSE );
|
|
375 |
}
|
|
376 |
|
|
377 |
void tst_QPushButton::toggled()
|
|
378 |
{
|
|
379 |
// the pushbutton shouldn't send a toggled signal when we call the toggle slot.
|
|
380 |
QVERIFY( !testWidget->isCheckable() );
|
|
381 |
|
|
382 |
testWidget->toggle();
|
|
383 |
QVERIFY( toggle_count == 0 );
|
|
384 |
|
|
385 |
// do it again, just to be shure
|
|
386 |
resetCounters();
|
|
387 |
testWidget->toggle();
|
|
388 |
QVERIFY( toggle_count == 0 );
|
|
389 |
|
|
390 |
// finally check that we can toggle using the mouse
|
|
391 |
resetCounters();
|
|
392 |
QTest::mousePress( testWidget, Qt::LeftButton );
|
|
393 |
QVERIFY( toggle_count == 0 );
|
|
394 |
QVERIFY( click_count == 0 );
|
|
395 |
|
|
396 |
QTest::mouseRelease( testWidget, Qt::LeftButton );
|
|
397 |
QVERIFY( click_count == 1 );
|
|
398 |
}
|
|
399 |
|
|
400 |
void tst_QPushButton::accel()
|
|
401 |
{
|
|
402 |
DEPENDS_ON( "setAccel" );
|
|
403 |
}
|
|
404 |
|
|
405 |
/*
|
|
406 |
If we press an accelerator key we ONLY get a pressed signal and
|
|
407 |
NOT a released or clicked signal.
|
|
408 |
*/
|
|
409 |
|
|
410 |
void tst_QPushButton::setAccel()
|
|
411 |
{
|
|
412 |
testWidget->setText("&AccelTest");
|
|
413 |
QKeySequence seq( Qt::ALT + Qt::Key_A );
|
|
414 |
testWidget->setShortcut( seq );
|
|
415 |
|
|
416 |
// The shortcut will not be activated unless the button is in a active
|
|
417 |
// window and has focus
|
|
418 |
QApplication::setActiveWindow(testWidget);
|
|
419 |
testWidget->setFocus();
|
|
420 |
for (int i = 0; !testWidget->isActiveWindow() && i < 1000; ++i) {
|
|
421 |
testWidget->activateWindow();
|
|
422 |
QApplication::instance()->processEvents();
|
|
423 |
QTest::qWait(100);
|
|
424 |
}
|
|
425 |
QVERIFY(testWidget->isActiveWindow());
|
|
426 |
QTest::keyClick( testWidget, 'A', Qt::AltModifier );
|
|
427 |
QTest::qWait( 50 );
|
|
428 |
QTRY_VERIFY( click_count == 1 );
|
|
429 |
QVERIFY( press_count == 1 );
|
|
430 |
QVERIFY( release_count == 1 );
|
|
431 |
QVERIFY( toggle_count == 0 );
|
|
432 |
|
|
433 |
// wait 200 ms because setAccel uses animateClick.
|
|
434 |
// if we don't wait this may screw up a next test.
|
|
435 |
QTest::qWait(200);
|
|
436 |
QTRY_VERIFY( !testWidget->isDown() );
|
|
437 |
}
|
|
438 |
|
|
439 |
void tst_QPushButton::animateClick()
|
|
440 |
{
|
|
441 |
QVERIFY( !testWidget->isDown() );
|
|
442 |
testWidget->animateClick();
|
|
443 |
QVERIFY( testWidget->isDown() );
|
|
444 |
QTest::qWait( 200 );
|
|
445 |
QVERIFY( !testWidget->isDown() );
|
|
446 |
|
|
447 |
QVERIFY( click_count == 1 );
|
|
448 |
QVERIFY( press_count == 1 );
|
|
449 |
QVERIFY( release_count == 1 );
|
|
450 |
QVERIFY( toggle_count == 0 );
|
|
451 |
}
|
|
452 |
|
|
453 |
void tst_QPushButton::clicked()
|
|
454 |
{
|
|
455 |
QTest::mousePress( testWidget, Qt::LeftButton );
|
|
456 |
QVERIFY( press_count == 1 );
|
|
457 |
QVERIFY( release_count == 0 );
|
|
458 |
|
|
459 |
QTest::mouseRelease( testWidget, Qt::LeftButton );
|
|
460 |
QCOMPARE( press_count, (uint)1 );
|
|
461 |
QCOMPARE( release_count, (uint)1 );
|
|
462 |
|
|
463 |
press_count = 0;
|
|
464 |
release_count = 0;
|
|
465 |
testWidget->setDown(FALSE);
|
|
466 |
for (uint i=0; i<10; i++)
|
|
467 |
QTest::mouseClick( testWidget, Qt::LeftButton );
|
|
468 |
QCOMPARE( press_count, (uint)10 );
|
|
469 |
QCOMPARE( release_count, (uint)10 );
|
|
470 |
}
|
|
471 |
|
|
472 |
/*
|
|
473 |
void tst_QPushButton::group()
|
|
474 |
{
|
|
475 |
}
|
|
476 |
|
|
477 |
void tst_QPushButton::state()
|
|
478 |
{
|
|
479 |
}
|
|
480 |
|
|
481 |
void tst_QPushButton::stateChanged()
|
|
482 |
{
|
|
483 |
}
|
|
484 |
*/
|
|
485 |
QPushButton *pb = 0;
|
|
486 |
void tst_QPushButton::helperSlotDelete()
|
|
487 |
{
|
|
488 |
delete pb;
|
|
489 |
pb = 0;
|
|
490 |
}
|
|
491 |
|
|
492 |
void tst_QPushButton::popupCrash()
|
|
493 |
{
|
|
494 |
pb = new QPushButton("foo");
|
|
495 |
QMenu *menu = new QMenu("bar", pb);
|
|
496 |
pb->setMenu(menu);
|
|
497 |
QTimer::singleShot(1000, this, SLOT(helperSlotDelete()));
|
|
498 |
pb->show();
|
|
499 |
pb->click();
|
|
500 |
}
|
|
501 |
|
|
502 |
void tst_QPushButton::defaultAndAutoDefault()
|
|
503 |
{
|
|
504 |
{
|
|
505 |
// Adding buttons directly to QDialog
|
|
506 |
QDialog dialog;
|
|
507 |
|
|
508 |
QPushButton button1(&dialog);
|
|
509 |
QVERIFY(button1.autoDefault());
|
|
510 |
QVERIFY(!button1.isDefault());
|
|
511 |
|
|
512 |
QPushButton button2(&dialog);
|
|
513 |
QVERIFY(button2.autoDefault());
|
|
514 |
QVERIFY(!button2.isDefault());
|
|
515 |
|
|
516 |
button1.setDefault(true);
|
|
517 |
QVERIFY(button1.autoDefault());
|
|
518 |
QVERIFY(button1.isDefault());
|
|
519 |
QVERIFY(button2.autoDefault());
|
|
520 |
QVERIFY(!button2.isDefault());
|
|
521 |
|
|
522 |
dialog.show();
|
|
523 |
QVERIFY(dialog.isVisible());
|
|
524 |
|
|
525 |
QObject::connect(&button1, SIGNAL(clicked()), &dialog, SLOT(hide()));
|
|
526 |
QKeyEvent event(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier);
|
|
527 |
QApplication::sendEvent(&dialog, &event);
|
|
528 |
QVERIFY(!dialog.isVisible());
|
|
529 |
}
|
|
530 |
|
|
531 |
{
|
|
532 |
// Adding buttons to QDialog through a layout
|
|
533 |
QDialog dialog;
|
|
534 |
|
|
535 |
QPushButton button3;
|
|
536 |
button3.setAutoDefault(false);
|
|
537 |
|
|
538 |
QPushButton button1;
|
|
539 |
QVERIFY(!button1.autoDefault());
|
|
540 |
QVERIFY(!button1.isDefault());
|
|
541 |
|
|
542 |
QPushButton button2;
|
|
543 |
QVERIFY(!button2.autoDefault());
|
|
544 |
QVERIFY(!button2.isDefault());
|
|
545 |
|
|
546 |
button1.setDefault(true);
|
|
547 |
QVERIFY(!button1.autoDefault());
|
|
548 |
QVERIFY(button1.isDefault());
|
|
549 |
QVERIFY(!button2.autoDefault());
|
|
550 |
QVERIFY(!button2.isDefault());
|
|
551 |
|
|
552 |
QGridLayout layout;
|
|
553 |
layout.addWidget(&button3, 0, 3);
|
|
554 |
layout.addWidget(&button2, 0, 2);
|
|
555 |
layout.addWidget(&button1, 0, 1);
|
|
556 |
dialog.setLayout(&layout);
|
|
557 |
button3.setFocus();
|
|
558 |
QVERIFY(button1.autoDefault());
|
|
559 |
QVERIFY(button1.isDefault());
|
|
560 |
QVERIFY(button2.autoDefault());
|
|
561 |
QVERIFY(!button2.isDefault());
|
|
562 |
|
|
563 |
dialog.show();
|
|
564 |
QVERIFY(dialog.isVisible());
|
|
565 |
|
|
566 |
QObject::connect(&button1, SIGNAL(clicked()), &dialog, SLOT(hide()));
|
|
567 |
QKeyEvent event(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier);
|
|
568 |
QApplication::sendEvent(&dialog, &event);
|
|
569 |
QVERIFY(!dialog.isVisible());
|
|
570 |
}
|
|
571 |
|
|
572 |
{
|
|
573 |
// autoDefault behavior.
|
|
574 |
QDialog dialog;
|
|
575 |
QPushButton button2(&dialog);
|
|
576 |
QPushButton button1(&dialog);
|
|
577 |
dialog.show();
|
|
578 |
QVERIFY(dialog.isVisible());
|
|
579 |
|
|
580 |
// No default button is set, and button2 is the first autoDefault button
|
|
581 |
// that is next in the tab order
|
|
582 |
QObject::connect(&button2, SIGNAL(clicked()), &dialog, SLOT(hide()));
|
|
583 |
QKeyEvent event(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier);
|
|
584 |
QApplication::sendEvent(&dialog, &event);
|
|
585 |
QVERIFY(!dialog.isVisible());
|
|
586 |
|
|
587 |
// Reparenting
|
|
588 |
QVERIFY(button2.autoDefault());
|
|
589 |
button2.setParent(0);
|
|
590 |
QVERIFY(!button2.autoDefault());
|
|
591 |
button2.setAutoDefault(false);
|
|
592 |
button2.setParent(&dialog);
|
|
593 |
QVERIFY(!button2.autoDefault());
|
|
594 |
|
|
595 |
button1.setAutoDefault(true);
|
|
596 |
button1.setParent(0);
|
|
597 |
QVERIFY(button1.autoDefault());
|
|
598 |
}
|
|
599 |
}
|
|
600 |
|
|
601 |
void tst_QPushButton::sizeHint_data()
|
|
602 |
{
|
|
603 |
QTest::addColumn<QString>("stylename");
|
|
604 |
QTest::newRow("motif") << QString::fromAscii("motif");
|
|
605 |
QTest::newRow("cde") << QString::fromAscii("cde");
|
|
606 |
QTest::newRow("windows") << QString::fromAscii("windows");
|
|
607 |
QTest::newRow("cleanlooks") << QString::fromAscii("cleanlooks");
|
|
608 |
QTest::newRow("gtk") << QString::fromAscii("gtk");
|
|
609 |
QTest::newRow("mac") << QString::fromAscii("mac");
|
|
610 |
QTest::newRow("plastique") << QString::fromAscii("plastique");
|
|
611 |
QTest::newRow("windowsxp") << QString::fromAscii("windowsxp");
|
|
612 |
QTest::newRow("windowsvista") << QString::fromAscii("windowsvista");
|
|
613 |
}
|
|
614 |
|
|
615 |
void tst_QPushButton::sizeHint()
|
|
616 |
{
|
|
617 |
QFETCH(QString, stylename);
|
|
618 |
|
|
619 |
QStyle *style = QStyleFactory::create(stylename);
|
|
620 |
if (!style)
|
|
621 |
QSKIP(qPrintable(QString::fromLatin1("Qt has been compiled without style: %1")
|
|
622 |
.arg(stylename)), SkipSingle);
|
|
623 |
QApplication::setStyle(style);
|
|
624 |
|
|
625 |
// Test 1
|
|
626 |
{
|
|
627 |
QPushButton *button = new QPushButton("123");
|
|
628 |
QSize initSizeHint = button->sizeHint();
|
|
629 |
|
|
630 |
QDialog *dialog = new QDialog;
|
|
631 |
QWidget *widget = new QWidget(dialog);
|
|
632 |
button->setParent(widget);
|
|
633 |
button->sizeHint();
|
|
634 |
|
|
635 |
widget->setParent(0);
|
|
636 |
delete dialog;
|
|
637 |
button->setDefault(false);
|
|
638 |
QCOMPARE(button->sizeHint(), initSizeHint);
|
|
639 |
delete button;
|
|
640 |
}
|
|
641 |
|
|
642 |
// Test 2
|
|
643 |
{
|
|
644 |
QWidget *tab1 = new QWidget;
|
|
645 |
QHBoxLayout *layout1 = new QHBoxLayout(tab1);
|
|
646 |
QPushButton *button1_1 = new QPushButton("123");
|
|
647 |
QPushButton *button1_2 = new QPushButton("123");
|
|
648 |
layout1->addWidget(button1_1);
|
|
649 |
layout1->addWidget(button1_2);
|
|
650 |
|
|
651 |
QWidget *tab2 = new QWidget;
|
|
652 |
QHBoxLayout *layout2 = new QHBoxLayout(tab2);
|
|
653 |
QPushButton *button2_1 = new QPushButton("123");
|
|
654 |
QPushButton *button2_2 = new QPushButton("123");
|
|
655 |
layout2->addWidget(button2_1);
|
|
656 |
layout2->addWidget(button2_2);
|
|
657 |
|
|
658 |
QDialog *dialog = new QDialog;
|
|
659 |
QTabWidget *tabWidget = new QTabWidget;
|
|
660 |
tabWidget->addTab(tab1, "1");
|
|
661 |
tabWidget->addTab(tab2, "2");
|
|
662 |
QVBoxLayout *mainLayout = new QVBoxLayout(dialog);
|
|
663 |
mainLayout->addWidget(tabWidget);
|
|
664 |
dialog->show();
|
|
665 |
tabWidget->setCurrentWidget(tab2);
|
|
666 |
tabWidget->setCurrentWidget(tab1);
|
|
667 |
QTest::qWait(100);
|
|
668 |
QApplication::processEvents();
|
|
669 |
|
|
670 |
QCOMPARE(button1_2->size(), button2_2->size());
|
|
671 |
}
|
|
672 |
}
|
|
673 |
|
|
674 |
QTEST_MAIN(tst_QPushButton)
|
|
675 |
#include "tst_qpushbutton.moc"
|