author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 10:37:55 +0300 | |
changeset 33 | 3e2da88830cd |
parent 18 | 2f34d5167611 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <qapplication.h> |
|
45 |
#include <qmainwindow.h> |
|
46 |
#include <qmenubar.h> |
|
47 |
#ifdef QT3_SUPPORT |
|
48 |
#include <q3popupmenu.h> |
|
49 |
#endif |
|
50 |
#include <qstyle.h> |
|
51 |
#include <qwindowsstyle.h> |
|
52 |
#include <qdesktopwidget.h> |
|
53 |
#include <qaction.h> |
|
54 |
#include <qstyleoption.h> |
|
55 |
||
56 |
#ifdef Q_WS_WIN |
|
57 |
#include <windows.h> |
|
58 |
#endif |
|
59 |
||
60 |
#include <qobject.h> |
|
61 |
||
62 |
#include "../../shared/util.h" |
|
63 |
||
64 |
QT_FORWARD_DECLARE_CLASS(QMainWindow) |
|
65 |
||
66 |
#include <qmenubar.h> |
|
67 |
||
68 |
//TESTED_CLASS= |
|
69 |
//TESTED_FILES= |
|
70 |
||
71 |
class QtTestSlot : public QObject |
|
72 |
{ |
|
73 |
Q_OBJECT |
|
74 |
||
75 |
public: |
|
76 |
QtTestSlot( QObject* parent = 0 ): QObject( parent ) { clear(); }; |
|
77 |
virtual ~QtTestSlot() {}; |
|
78 |
||
79 |
void clear() { sel_count = 0; }; |
|
80 |
uint selCount() { return sel_count; }; |
|
81 |
||
82 |
public slots: |
|
83 |
void selected() { sel_count++; }; |
|
84 |
||
85 |
private: |
|
86 |
uint sel_count; |
|
87 |
}; |
|
88 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
class Menu : public QMenu |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
Q_OBJECT |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
92 |
public slots: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
93 |
void addActions() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
94 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
95 |
//this will change the geometry of the menu |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
96 |
addAction("action1"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
addAction("action2"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
98 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
99 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
|
0 | 101 |
class tst_QMenuBar : public QObject |
102 |
{ |
|
103 |
Q_OBJECT |
|
104 |
public: |
|
105 |
tst_QMenuBar(); |
|
106 |
virtual ~tst_QMenuBar(); |
|
107 |
||
108 |
#ifdef QT3_SUPPORT |
|
109 |
void initSimpleMenubar(); |
|
110 |
#endif |
|
111 |
void initSimpleMenubar_noQt3(); |
|
112 |
||
113 |
#ifdef QT3_SUPPORT |
|
114 |
void initComplexMenubar(); |
|
115 |
#endif |
|
116 |
void initComplexMenubar_noQt3(); |
|
117 |
||
118 |
public slots: |
|
119 |
void initTestCase(); |
|
120 |
void cleanupTestCase(); |
|
121 |
void init(); |
|
122 |
private slots: |
|
123 |
void getSetCheck(); |
|
124 |
||
125 |
void clear_noQt3(); |
|
126 |
void removeItemAt_noQt3(); |
|
127 |
void removeItemAt_noQt3_data(); |
|
128 |
void removeItem_noQt3_data(); |
|
129 |
void removeItem_noQt3(); |
|
130 |
void count_noQt3(); |
|
131 |
void insertItem_QString_QObject_noQt3(); |
|
132 |
void accel_noQt3(); |
|
133 |
void activatedCount_noQt3(); |
|
134 |
void allowActiveAndDisabled(); |
|
135 |
#ifdef QT3_SUPPORT |
|
136 |
void clear(); |
|
137 |
void removeItemAt_data(); |
|
138 |
void removeItemAt(); |
|
139 |
void removeItem_data(); |
|
140 |
void removeItem(); |
|
141 |
void count(); |
|
142 |
void insertItem_QString_QObject(); |
|
143 |
void accel(); |
|
144 |
void activatedCount(); |
|
145 |
#endif |
|
146 |
||
147 |
void check_accelKeys(); |
|
148 |
void check_cursorKeys1(); |
|
149 |
void check_cursorKeys2(); |
|
150 |
void check_cursorKeys3(); |
|
151 |
||
152 |
void check_homeKey(); |
|
153 |
void check_endKey(); |
|
154 |
#ifdef QT3_SUPPORT |
|
155 |
void check_escKey(); |
|
156 |
#endif |
|
157 |
void check_escKey_noQt3(); |
|
158 |
||
159 |
// void check_mouse1_data(); |
|
160 |
// void check_mouse1(); |
|
161 |
// void check_mouse2_data(); |
|
162 |
// void check_mouse2(); |
|
163 |
||
164 |
void check_altPress(); |
|
165 |
void check_shortcutPress(); |
|
166 |
void check_menuPosition(); |
|
167 |
void task223138_triggered(); |
|
168 |
void task256322_highlight(); |
|
169 |
void menubarSizeHint(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
170 |
void taskQTBUG4965_escapeEaten(); |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
171 |
void taskQTBUG11823_crashwithInvisibleActions(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
172 |
|
0 | 173 |
#if defined(QT3_SUPPORT) |
174 |
void indexBasedInsertion_data(); |
|
175 |
void indexBasedInsertion(); |
|
176 |
#endif |
|
177 |
||
178 |
protected slots: |
|
179 |
#ifdef QT3_SUPPORT |
|
180 |
void onActivated( int ); |
|
181 |
#endif |
|
182 |
void onActivated_noQt3( QAction*); |
|
183 |
||
184 |
private: |
|
185 |
||
186 |
void initTestCase_noQt3(); |
|
187 |
||
188 |
QtTestSlot *menu1; |
|
189 |
QtTestSlot *menu2; |
|
190 |
QtTestSlot *menu3; |
|
191 |
QtTestSlot *menu4; |
|
192 |
||
193 |
QtTestSlot *item1_A; |
|
194 |
QtTestSlot *item1_B; |
|
195 |
QtTestSlot *item2_C; |
|
196 |
QtTestSlot *item2_D; |
|
197 |
QtTestSlot *item2_E; |
|
198 |
QtTestSlot *item2_F; |
|
199 |
QtTestSlot *item2_G; |
|
200 |
QtTestSlot *item2_H; |
|
201 |
||
202 |
void resetSlots(); |
|
203 |
void resetCount(); |
|
204 |
||
205 |
void reset() { resetSlots(); resetCount(); }; |
|
206 |
||
207 |
#ifdef QT3_SUPPORT |
|
208 |
int last_accel_id; |
|
209 |
#endif |
|
210 |
QAction* last_accel_id_Qt4; |
|
211 |
int activated_count; |
|
212 |
||
213 |
#ifdef QT3_SUPPORT |
|
214 |
int idAccel; |
|
215 |
int idAccel1; |
|
216 |
#endif |
|
217 |
QAction *action; |
|
218 |
QAction *action1; |
|
219 |
QMainWindow *mw; |
|
220 |
QMenuBar *mb; |
|
221 |
#ifdef QT3_SUPPORT |
|
222 |
Q3PopupMenu *pm1; |
|
223 |
Q3PopupMenu *pm2; |
|
224 |
#endif |
|
225 |
QMenu *pm1_Qt4; |
|
226 |
QMenu *pm2_Qt4; |
|
227 |
}; |
|
228 |
||
229 |
// Testing get/set functions |
|
230 |
void tst_QMenuBar::getSetCheck() |
|
231 |
{ |
|
232 |
QMenuBar obj1; |
|
233 |
// QAction * QMenuBar::activeAction() |
|
234 |
// void QMenuBar::setActiveAction(QAction *) |
|
235 |
QAction *var1 = new QAction(0); |
|
236 |
obj1.setActiveAction(var1); |
|
237 |
QCOMPARE(var1, obj1.activeAction()); |
|
238 |
obj1.setActiveAction((QAction *)0); |
|
239 |
QCOMPARE((QAction *)0, obj1.activeAction()); |
|
240 |
delete var1; |
|
241 |
} |
|
242 |
||
243 |
//// |
|
244 |
||
245 |
||
246 |
||
247 |
#include <qcursor.h> |
|
248 |
||
249 |
const int RESET = 0; |
|
250 |
||
251 |
/*! |
|
252 |
Test plan: |
|
253 |
insertItem (all flavours and combinations) |
|
254 |
removing menu items |
|
255 |
clearing the menu |
|
256 |
||
257 |
check the common behaviour + emitted signals for: |
|
258 |
accelerator keys |
|
259 |
navigating tru the menu and then pressing ENTER |
|
260 |
mouse clicks |
|
261 |
mouse drags |
|
262 |
combinations of key + mouse (if possible) |
|
263 |
checked / unckecked state of menu options |
|
264 |
active / inactive state |
|
265 |
||
266 |
Can't test these without pixmap comparison... |
|
267 |
show and hide |
|
268 |
icons in a menu |
|
269 |
pixmaps in a menu |
|
270 |
||
271 |
*/ |
|
272 |
||
273 |
tst_QMenuBar::tst_QMenuBar() |
|
274 |
||
275 |
{ |
|
276 |
QApplication::setEffectEnabled(Qt::UI_AnimateMenu, false); |
|
277 |
||
278 |
||
279 |
activated_count = 0; |
|
280 |
mb = 0; |
|
281 |
#ifdef QT3_SUPPORT |
|
282 |
pm1 = 0; |
|
283 |
pm2 = 0; |
|
284 |
last_accel_id = RESET; |
|
285 |
#endif |
|
286 |
pm1_Qt4 = 0; |
|
287 |
pm2_Qt4 = 0; |
|
288 |
last_accel_id_Qt4 = 0; |
|
289 |
} |
|
290 |
||
291 |
tst_QMenuBar::~tst_QMenuBar() |
|
292 |
{ |
|
293 |
//delete mw; //#### cannot do that AFTER qapplication was destroyed! |
|
294 |
mw = 0; |
|
295 |
} |
|
296 |
||
297 |
void tst_QMenuBar::initTestCase() |
|
298 |
{ |
|
299 |
#ifdef QT3_SUPPORT |
|
300 |
// create a default mainwindow |
|
301 |
// If you run a widget test, this will be replaced in the testcase by the |
|
302 |
// widget under test |
|
303 |
mw = new QMainWindow(0, Qt::X11BypassWindowManagerHint); |
|
304 |
mb = new QMenuBar( mw, "menubar" ); |
|
305 |
connect( mb, SIGNAL(activated(int)), this, SLOT(onActivated(int)) ); |
|
306 |
||
307 |
initSimpleMenubar(); |
|
308 |
||
309 |
qApp->setMainWidget( mw ); |
|
310 |
mw->show(); |
|
311 |
qApp->setActiveWindow(mw); |
|
312 |
||
313 |
menu1 = new QtTestSlot( mw ); |
|
314 |
menu2 = new QtTestSlot( mw ); |
|
315 |
menu3 = new QtTestSlot( mw ); |
|
316 |
menu4 = new QtTestSlot( mw ); |
|
317 |
item1_A = new QtTestSlot( mw ); |
|
318 |
item1_B = new QtTestSlot( mw ); |
|
319 |
item2_C = new QtTestSlot( mw ); |
|
320 |
item2_D = new QtTestSlot( mw ); |
|
321 |
item2_E = new QtTestSlot( mw ); |
|
322 |
item2_F = new QtTestSlot( mw ); |
|
323 |
item2_G = new QtTestSlot( mw ); |
|
324 |
item2_H = new QtTestSlot( mw ); |
|
325 |
#else |
|
326 |
initTestCase_noQt3(); |
|
327 |
#endif |
|
328 |
} |
|
329 |
||
330 |
void tst_QMenuBar::initTestCase_noQt3() |
|
331 |
{ |
|
332 |
// create a default mainwindow |
|
333 |
// If you run a widget test, this will be replaced in the testcase by the |
|
334 |
// widget under test |
|
335 |
mw = new QMainWindow(0, Qt::X11BypassWindowManagerHint); |
|
336 |
mb = new QMenuBar( mw ); |
|
337 |
connect( mb, SIGNAL(triggered(QAction *)), this, SLOT(onActivated_noQt3(QAction *)) ); |
|
338 |
||
339 |
initSimpleMenubar_noQt3(); |
|
340 |
mw->show(); |
|
341 |
||
342 |
menu1 = new QtTestSlot( mw ); |
|
343 |
menu2 = new QtTestSlot( mw ); |
|
344 |
menu3 = new QtTestSlot( mw ); |
|
345 |
menu4 = new QtTestSlot( mw ); |
|
346 |
item1_A = new QtTestSlot( mw ); |
|
347 |
item1_B = new QtTestSlot( mw ); |
|
348 |
item2_C = new QtTestSlot( mw ); |
|
349 |
item2_D = new QtTestSlot( mw ); |
|
350 |
item2_E = new QtTestSlot( mw ); |
|
351 |
item2_F = new QtTestSlot( mw ); |
|
352 |
item2_G = new QtTestSlot( mw ); |
|
353 |
item2_H = new QtTestSlot( mw ); |
|
354 |
} |
|
355 |
||
356 |
||
357 |
void tst_QMenuBar::cleanupTestCase() |
|
358 |
{ |
|
359 |
delete mw; |
|
360 |
} |
|
361 |
||
362 |
#if defined(QT3_SUPPORT) |
|
363 |
void tst_QMenuBar::initSimpleMenubar() |
|
364 |
{ |
|
365 |
mb->hide(); |
|
366 |
mb->clear(); |
|
367 |
||
368 |
delete pm1; |
|
369 |
pm1 = new Q3PopupMenu( mb ); |
|
370 |
idAccel = pm1->insertItem( "menu1", 123 ); |
|
371 |
// pm->setAccel( ALT + Key_A, idAccel ); |
|
372 |
pm1->setAccel( Qt::CTRL + Qt::Key_A, idAccel ); |
|
373 |
mb->insertItem( "&accel", pm1 ); |
|
374 |
connect( pm1, SIGNAL(activated(int)), this, SLOT(onActivated(int))); |
|
375 |
||
376 |
delete pm2; |
|
377 |
pm2 = new Q3PopupMenu( mb ); |
|
378 |
// idAccel1 = pm2->insertItem( "&Open...", this, SLOT(onActivated(int)), Qt::Key_O, 456 ); |
|
379 |
idAccel1 = pm2->insertItem( "&Open...", 0, 0, Qt::Key_O, 456 ); |
|
380 |
connect(pm2, SIGNAL(activated(int)), this, SLOT(onActivated(int))); |
|
381 |
mb->insertItem( "accel1", pm2 ); |
|
382 |
||
383 |
mb->show(); |
|
384 |
qApp->syncX(); |
|
385 |
qApp->processEvents(); |
|
386 |
} |
|
387 |
#endif |
|
388 |
||
389 |
void tst_QMenuBar::initSimpleMenubar_noQt3() |
|
390 |
{ |
|
391 |
mb->hide(); |
|
392 |
mb->clear(); |
|
393 |
||
394 |
delete pm1_Qt4; |
|
395 |
pm1_Qt4 = mb->addMenu("&accel"); |
|
396 |
action = pm1_Qt4->addAction( "menu1" ); |
|
397 |
action->setShortcut(QKeySequence("ALT+A")); |
|
398 |
action->setShortcut(QKeySequence("CTRL+A")); |
|
399 |
||
400 |
||
401 |
connect( pm1_Qt4, SIGNAL(triggered(QAction*)), this, SLOT(onActivated_noQt3(QAction*))); |
|
402 |
||
403 |
delete pm2_Qt4; |
|
404 |
pm2_Qt4 = mb->addMenu("accel1"); |
|
405 |
||
406 |
action1 = pm2_Qt4->addAction( "&Open..." ); |
|
407 |
action1->setShortcut(Qt::Key_O); |
|
408 |
connect(pm2_Qt4, SIGNAL(triggered(QAction*)), this, SLOT(onActivated_noQt3(QAction*))); |
|
409 |
||
410 |
mb->show(); |
|
411 |
qApp->syncX(); |
|
412 |
qApp->processEvents(); |
|
413 |
} |
|
414 |
||
415 |
void tst_QMenuBar::init() |
|
416 |
{ |
|
417 |
resetSlots(); |
|
418 |
resetCount(); |
|
419 |
} |
|
420 |
||
421 |
void tst_QMenuBar::resetSlots() |
|
422 |
{ |
|
423 |
menu1->clear(); |
|
424 |
menu2->clear(); |
|
425 |
menu3->clear(); |
|
426 |
menu4->clear(); |
|
427 |
item1_A->clear(); |
|
428 |
item1_B->clear(); |
|
429 |
item2_C->clear(); |
|
430 |
item2_D->clear(); |
|
431 |
item2_E->clear(); |
|
432 |
item2_F->clear(); |
|
433 |
item2_G->clear(); |
|
434 |
item2_H->clear(); |
|
435 |
} |
|
436 |
||
437 |
void tst_QMenuBar::resetCount() |
|
438 |
{ |
|
439 |
#ifdef QT3_SUPPORT |
|
440 |
last_accel_id = RESET; |
|
441 |
#endif |
|
442 |
last_accel_id_Qt4 = 0; |
|
443 |
activated_count = 0; |
|
444 |
} |
|
445 |
||
446 |
#ifdef QT3_SUPPORT |
|
447 |
void tst_QMenuBar::onActivated( int i ) |
|
448 |
{ |
|
449 |
last_accel_id = i; |
|
450 |
activated_count++; |
|
451 |
// printf( QString("acceleratorId: %1, count: %1\n").arg( i ).arg(activated_count) ); |
|
452 |
} |
|
453 |
#endif |
|
454 |
||
455 |
void tst_QMenuBar::onActivated_noQt3( QAction* action ) |
|
456 |
{ |
|
457 |
last_accel_id_Qt4 = action; |
|
458 |
activated_count++; |
|
459 |
// printf( QString("acceleratorId: %1, count: %1\n").arg( i ).arg(activated_count) ); |
|
460 |
} |
|
461 |
||
462 |
#ifdef QT3_SUPPORT |
|
463 |
void tst_QMenuBar::accel() |
|
464 |
{ |
|
465 |
#ifdef Q_WS_MAC |
|
466 |
QSKIP("On Mac, native key events are needed to test menu action activation", SkipAll); |
|
467 |
#endif |
|
468 |
// create a popup menu with menu items set the accelerators later... |
|
469 |
initSimpleMenubar(); |
|
470 |
// QTest::keyClick( 0, Qt::Key_A, AltKey ); |
|
471 |
QTest::keyClick( 0, Qt::Key_A, Qt::ControlModifier ); |
|
472 |
QTest::qWait(300); |
|
473 |
||
474 |
QCOMPARE( last_accel_id, idAccel ); |
|
475 |
} |
|
476 |
#endif //QT3_SUPPORT |
|
477 |
||
478 |
void tst_QMenuBar::accel_noQt3() |
|
479 |
{ |
|
480 |
#if defined(Q_WS_MAC) || defined(Q_OS_WINCE_WM) |
|
481 |
QSKIP("On Mac/WinCE, native key events are needed to test menu action activation", SkipAll); |
|
482 |
#endif |
|
483 |
#ifdef Q_OS_SYMBIAN |
|
484 |
QSKIP("On Symbian OS, native key events are needed to test menu action activation", SkipAll); |
|
485 |
#endif |
|
486 |
||
487 |
// create a popup menu with menu items set the accelerators later... |
|
488 |
initSimpleMenubar_noQt3(); |
|
489 |
// QTest::keyClick( 0, Qt::Key_A, AltKey ); |
|
490 |
QTest::keyClick( 0, Qt::Key_A, Qt::ControlModifier ); |
|
491 |
QTest::qWait(300); |
|
492 |
||
493 |
QCOMPARE( last_accel_id_Qt4, action ); |
|
494 |
} |
|
495 |
||
496 |
#ifdef QT3_SUPPORT |
|
497 |
void tst_QMenuBar::activatedCount() |
|
498 |
{ |
|
499 |
#ifdef Q_WS_MAC |
|
500 |
QSKIP("On Mac, native key events are needed to test menu action activation", SkipAll); |
|
501 |
#endif |
|
502 |
// create a popup menu with menu items set the accelerators later... |
|
503 |
initSimpleMenubar(); |
|
504 |
||
505 |
QTest::keyClick( 0, Qt::Key_A, Qt::ControlModifier ); |
|
506 |
//wait(5000); |
|
507 |
QCOMPARE( activated_count, 2 ); //1 from the popupmenu and 1 from the menubar |
|
508 |
} |
|
509 |
#endif //QT3_SUPPORT |
|
510 |
||
511 |
void tst_QMenuBar::activatedCount_noQt3() |
|
512 |
{ |
|
513 |
#if defined(Q_WS_MAC) || defined(Q_OS_WINCE_WM) |
|
514 |
QSKIP("On Mac/WinCE, native key events are needed to test menu action activation", SkipAll); |
|
515 |
#endif |
|
516 |
// create a popup menu with menu items set the accelerators later... |
|
517 |
initSimpleMenubar_noQt3(); |
|
518 |
||
519 |
QTest::keyClick( 0, Qt::Key_A, Qt::ControlModifier ); |
|
520 |
//wait(5000); |
|
521 |
QCOMPARE( activated_count, 2 ); //1 from the popupmenu and 1 from the menubar |
|
522 |
} |
|
523 |
||
524 |
void tst_QMenuBar::clear_noQt3() |
|
525 |
{ |
|
526 |
mb->clear(); |
|
527 |
QVERIFY( (uint) mb->actions().size() == 0 ); |
|
528 |
||
529 |
mb->clear(); |
|
530 |
for (uint i=0; i<10; i++) { |
|
531 |
QMenu *menu = mb->addMenu( QString("Menu %1")); |
|
532 |
for (uint k=0; k<i; k++) |
|
533 |
menu->addAction( QString("Item %1")); |
|
534 |
QCOMPARE( (uint) mb->actions().size(), (uint)i+1 ); |
|
535 |
} |
|
536 |
QCOMPARE( (uint) mb->actions().size(), 10u ); |
|
537 |
||
538 |
mb->clear(); |
|
539 |
QVERIFY( (uint) mb->actions().size() == 0 ); |
|
540 |
} |
|
541 |
||
542 |
void tst_QMenuBar::count_noQt3() |
|
543 |
{ |
|
544 |
mb->clear(); |
|
545 |
QVERIFY( mb->actions().size() == 0 ); |
|
546 |
||
547 |
for (uint i=0; i<10; i++) { |
|
548 |
mb->addAction( QString("Menu %1")); |
|
549 |
QCOMPARE( (uint) mb->actions().size(), (uint) i+1 ); |
|
550 |
} |
|
551 |
} |
|
552 |
||
553 |
void tst_QMenuBar::removeItem_noQt3_data() |
|
554 |
{ |
|
555 |
QTest::addColumn<int>("removeIndex"); |
|
556 |
QTest::newRow( "first" ) << 0; |
|
557 |
QTest::newRow( "middle" ) << 1; |
|
558 |
QTest::newRow( "last" ) << 2; |
|
559 |
} |
|
560 |
||
561 |
// Basically the same test as removeItemAt, except that we remember and remove id's. |
|
562 |
void tst_QMenuBar::removeItem_noQt3() |
|
563 |
{ |
|
564 |
mb->clear(); |
|
565 |
||
566 |
QMenu *pm; |
|
567 |
pm = new QMenu( "stuff", mb ); |
|
568 |
pm->setTitle("Menu 1"); |
|
569 |
pm->addAction( QString("Item 10") ); |
|
570 |
QAction* action1 = mb->addMenu( pm ); |
|
571 |
||
572 |
pm = new QMenu( mb ); |
|
573 |
pm->setTitle("Menu 2"); |
|
574 |
pm->addAction( QString("Item 20") ); |
|
575 |
pm->addAction( QString("Item 21") ); |
|
576 |
QAction *action2 = mb->addMenu( pm ); |
|
577 |
||
578 |
pm = new QMenu( "Menu 3", mb ); |
|
579 |
pm->addAction( QString("Item 30") ); |
|
580 |
pm->addAction( QString("Item 31") ); |
|
581 |
pm->addAction( QString("Item 32") ); |
|
582 |
QAction *action3 = mb->addMenu( pm ); |
|
583 |
||
584 |
QList<QAction *> menuBarActions = mb->actions(); |
|
585 |
||
586 |
QCOMPARE( action1->text(), QString("Menu 1") ); |
|
587 |
QCOMPARE( action2->text(), QString("Menu 2") ); |
|
588 |
QCOMPARE( action3->text(), QString("Menu 3") ); |
|
589 |
||
590 |
QVERIFY( menuBarActions.at(0) == action1 ); |
|
591 |
QVERIFY( menuBarActions.at(1) == action2 ); |
|
592 |
QVERIFY( menuBarActions.at(2) == action3 ); |
|
593 |
||
594 |
// Ok, now that we know we have created the menu we expect, lets remove an item... |
|
595 |
QFETCH( int, removeIndex ); |
|
596 |
switch (removeIndex ) |
|
597 |
{ |
|
598 |
case 0: { |
|
599 |
mb->removeAction(action1); |
|
600 |
QList<QAction *> menuBarActions2 = mb->actions(); |
|
601 |
QCOMPARE( menuBarActions2.at(0)->text(), QString("Menu 2") ); |
|
602 |
QCOMPARE( menuBarActions2.at(1)->text(), QString("Menu 3") ); |
|
603 |
} |
|
604 |
break; |
|
605 |
case 1: { |
|
606 |
mb->removeAction(action2); |
|
607 |
QList<QAction *> menuBarActions2 = mb->actions(); |
|
608 |
QCOMPARE( menuBarActions2.at(0)->text(), QString("Menu 1") ); |
|
609 |
QCOMPARE( menuBarActions2.at(1)->text(), QString("Menu 3") ); |
|
610 |
} |
|
611 |
break; |
|
612 |
case 2: { |
|
613 |
mb->removeAction(action3); |
|
614 |
QList<QAction *> menuBarActions2 = mb->actions(); |
|
615 |
QCOMPARE( menuBarActions2.at(0)->text(), QString("Menu 1") ); |
|
616 |
QCOMPARE( menuBarActions2.at(1)->text(), QString("Menu 2") ); |
|
617 |
} |
|
618 |
break; |
|
619 |
} |
|
620 |
QList<QAction *> menuBarActions2 = mb->actions(); |
|
621 |
QVERIFY( menuBarActions2.size() == 2 ); |
|
622 |
} |
|
623 |
||
624 |
void tst_QMenuBar::removeItemAt_noQt3_data() |
|
625 |
{ |
|
626 |
QTest::addColumn<int>("removeIndex"); |
|
627 |
QTest::newRow( "first" ) << 0; |
|
628 |
QTest::newRow( "middle" ) << 1; |
|
629 |
QTest::newRow( "last" ) << 2; |
|
630 |
} |
|
631 |
||
632 |
void tst_QMenuBar::removeItemAt_noQt3() |
|
633 |
{ |
|
634 |
mb->clear(); |
|
635 |
||
636 |
QMenu *pm; |
|
637 |
pm = new QMenu("Menu 1", mb); |
|
638 |
pm->addAction( QString("Item 10") ); |
|
639 |
mb->addMenu( pm ); |
|
640 |
||
641 |
pm = new QMenu( "Menu 2", mb ); |
|
642 |
pm->addAction( QString("Item 20") ); |
|
643 |
pm->addAction( QString("Item 21") ); |
|
644 |
mb->addMenu( pm ); |
|
645 |
||
646 |
pm = new QMenu( "Menu 3", mb ); |
|
647 |
pm->addAction( QString("Item 30") ); |
|
648 |
pm->addAction( QString("Item 31") ); |
|
649 |
pm->addAction( QString("Item 32") ); |
|
650 |
mb->addMenu( pm ); |
|
651 |
||
652 |
QList<QAction *> menuBarActions = mb->actions(); |
|
653 |
||
654 |
QCOMPARE( menuBarActions.at(0)->text(), QString("Menu 1") ); |
|
655 |
QCOMPARE( menuBarActions.at(1)->text(), QString("Menu 2") ); |
|
656 |
QCOMPARE( menuBarActions.at(2)->text(), QString("Menu 3") ); |
|
657 |
||
658 |
// Ok, now that we know we have created the menu we expect, lets remove an item... |
|
659 |
QFETCH( int, removeIndex ); |
|
660 |
mb->removeAction(menuBarActions.at(removeIndex)); |
|
661 |
QList<QAction *> menuBarActions2 = mb->actions(); |
|
662 |
switch (removeIndex ) |
|
663 |
{ |
|
664 |
case 0: |
|
665 |
QCOMPARE( menuBarActions2.at(0)->text(), QString("Menu 2") ); |
|
666 |
QCOMPARE( menuBarActions2.at(1)->text(), QString("Menu 3") ); |
|
667 |
break; |
|
668 |
case 1: |
|
669 |
QCOMPARE( menuBarActions2.at(0)->text(), QString("Menu 1") ); |
|
670 |
QCOMPARE( menuBarActions2.at(1)->text(), QString("Menu 3") ); |
|
671 |
break; |
|
672 |
case 2: |
|
673 |
QCOMPARE( menuBarActions2.at(0)->text(), QString("Menu 1") ); |
|
674 |
QCOMPARE( menuBarActions2.at(1)->text(), QString("Menu 2") ); |
|
675 |
break; |
|
676 |
} |
|
677 |
||
678 |
QVERIFY( menuBarActions2.size() == 2 ); |
|
679 |
} |
|
680 |
||
681 |
#ifdef QT3_SUPPORT |
|
682 |
void tst_QMenuBar::clear() |
|
683 |
{ |
|
684 |
mb->clear(); |
|
685 |
QVERIFY( mb->count() == 0 ); |
|
686 |
||
687 |
mb->clear(); |
|
688 |
for (uint i=0; i<10; i++) { |
|
689 |
Q3PopupMenu *pm = new Q3PopupMenu( mb ); |
|
690 |
for (uint k=0; k<i; k++) |
|
691 |
pm->insertItem( QString("Item %1").arg(i*10 + k) ); |
|
692 |
mb->insertItem( QString("Menu %1").arg(i), pm ); |
|
693 |
QCOMPARE( mb->count(), (uint)i+1 ); |
|
694 |
} |
|
695 |
QCOMPARE( mb->count(), 10u ); |
|
696 |
||
697 |
mb->clear(); |
|
698 |
QVERIFY( mb->count() == 0 ); |
|
699 |
} |
|
700 |
||
701 |
void tst_QMenuBar::count() |
|
702 |
{ |
|
703 |
mb->clear(); |
|
704 |
QVERIFY( mb->count() == 0 ); |
|
705 |
||
706 |
for (uint i=0; i<10; i++) { |
|
707 |
Q3PopupMenu *pm = new Q3PopupMenu( mb ); |
|
708 |
mb->insertItem( QString("Menu %1").arg(i), pm ); |
|
709 |
QCOMPARE( mb->count(), i+1 ); |
|
710 |
} |
|
711 |
} |
|
712 |
||
713 |
void tst_QMenuBar::removeItemAt_data() |
|
714 |
{ |
|
715 |
QTest::addColumn<int>("removeIndex"); |
|
716 |
QTest::newRow( "first" ) << 0; |
|
717 |
QTest::newRow( "middle" ) << 1; |
|
718 |
QTest::newRow( "last" ) << 2; |
|
719 |
} |
|
720 |
||
721 |
void tst_QMenuBar::removeItemAt() |
|
722 |
{ |
|
723 |
mb->clear(); |
|
724 |
||
725 |
Q3PopupMenu *pm; |
|
726 |
pm = new Q3PopupMenu( mb ); |
|
727 |
pm->insertItem( QString("Item 10") ); |
|
728 |
mb->insertItem( QString("Menu 1"), pm ); |
|
729 |
||
730 |
pm = new Q3PopupMenu( mb ); |
|
731 |
pm->insertItem( QString("Item 20") ); |
|
732 |
pm->insertItem( QString("Item 21") ); |
|
733 |
mb->insertItem( QString("Menu 2"), pm ); |
|
734 |
||
735 |
pm = new Q3PopupMenu( mb ); |
|
736 |
pm->insertItem( QString("Item 30") ); |
|
737 |
pm->insertItem( QString("Item 31") ); |
|
738 |
pm->insertItem( QString("Item 32") ); |
|
739 |
mb->insertItem( QString("Menu 3"), pm ); |
|
740 |
||
741 |
QCOMPARE( mb->text( mb->idAt(0) ), QString("Menu 1") ); |
|
742 |
QCOMPARE( mb->text( mb->idAt(1) ), QString("Menu 2") ); |
|
743 |
QCOMPARE( mb->text( mb->idAt(2) ), QString("Menu 3") ); |
|
744 |
||
745 |
// Ok, now that we know we have created the menu we expect, lets remove an item... |
|
746 |
QFETCH( int, removeIndex ); |
|
747 |
mb->removeItemAt( removeIndex ); |
|
748 |
switch (removeIndex ) |
|
749 |
{ |
|
750 |
case 0: |
|
751 |
QCOMPARE( mb->text( mb->idAt(0) ), QString("Menu 2") ); |
|
752 |
QCOMPARE( mb->text( mb->idAt(1) ), QString("Menu 3") ); |
|
753 |
break; |
|
754 |
case 1: |
|
755 |
QCOMPARE( mb->text( mb->idAt(0) ), QString("Menu 1") ); |
|
756 |
QCOMPARE( mb->text( mb->idAt(1) ), QString("Menu 3") ); |
|
757 |
break; |
|
758 |
case 2: |
|
759 |
QCOMPARE( mb->text( mb->idAt(0) ), QString("Menu 1") ); |
|
760 |
QCOMPARE( mb->text( mb->idAt(1) ), QString("Menu 2") ); |
|
761 |
break; |
|
762 |
} |
|
763 |
||
764 |
QVERIFY( mb->count() == 2 ); |
|
765 |
} |
|
766 |
||
767 |
void tst_QMenuBar::removeItem_data() |
|
768 |
{ |
|
769 |
QTest::addColumn<int>("removeIndex"); |
|
770 |
QTest::newRow( "first" ) << 0; |
|
771 |
QTest::newRow( "middle" ) << 1; |
|
772 |
QTest::newRow( "last" ) << 2; |
|
773 |
} |
|
774 |
||
775 |
// Basically the same test as removeItemAt, except that we remember and remove id's. |
|
776 |
void tst_QMenuBar::removeItem() |
|
777 |
{ |
|
778 |
mb->clear(); |
|
779 |
||
780 |
Q3PopupMenu *pm; |
|
781 |
pm = new Q3PopupMenu( mb ); |
|
782 |
pm->insertItem( QString("Item 10") ); |
|
783 |
int id1 = mb->insertItem( QString("Menu 1"), pm ); |
|
784 |
||
785 |
pm = new Q3PopupMenu( mb ); |
|
786 |
pm->insertItem( QString("Item 20") ); |
|
787 |
pm->insertItem( QString("Item 21") ); |
|
788 |
int id2 = mb->insertItem( QString("Menu 2"), pm ); |
|
789 |
||
790 |
pm = new Q3PopupMenu( mb ); |
|
791 |
pm->insertItem( QString("Item 30") ); |
|
792 |
pm->insertItem( QString("Item 31") ); |
|
793 |
pm->insertItem( QString("Item 32") ); |
|
794 |
int id3 = mb->insertItem( QString("Menu 3"), pm ); |
|
795 |
||
796 |
QCOMPARE( mb->text( id1 ), QString("Menu 1") ); |
|
797 |
QCOMPARE( mb->text( id2 ), QString("Menu 2") ); |
|
798 |
QCOMPARE( mb->text( id3 ), QString("Menu 3") ); |
|
799 |
||
800 |
QVERIFY( mb->idAt(0) == id1 ); |
|
801 |
QVERIFY( mb->idAt(1) == id2 ); |
|
802 |
QVERIFY( mb->idAt(2) == id3 ); |
|
803 |
||
804 |
// Ok, now that we know we have created the menu we expect, lets remove an item... |
|
805 |
QFETCH( int, removeIndex ); |
|
806 |
switch (removeIndex ) |
|
807 |
{ |
|
808 |
case 0: |
|
809 |
mb->removeItem( id1 ); |
|
810 |
QCOMPARE( mb->text( mb->idAt(0) ), QString("Menu 2") ); |
|
811 |
QCOMPARE( mb->text( mb->idAt(1) ), QString("Menu 3") ); |
|
812 |
break; |
|
813 |
case 1: |
|
814 |
mb->removeItem( id2 ); |
|
815 |
QCOMPARE( mb->text( mb->idAt(0) ), QString("Menu 1") ); |
|
816 |
QCOMPARE( mb->text( mb->idAt(1) ), QString("Menu 3") ); |
|
817 |
break; |
|
818 |
case 2: |
|
819 |
mb->removeItem( id3 ); |
|
820 |
QCOMPARE( mb->text( mb->idAt(0) ), QString("Menu 1") ); |
|
821 |
QCOMPARE( mb->text( mb->idAt(1) ), QString("Menu 2") ); |
|
822 |
break; |
|
823 |
} |
|
824 |
||
825 |
QVERIFY( mb->count() == 2 ); |
|
826 |
} |
|
827 |
||
828 |
void tst_QMenuBar::initComplexMenubar() // well, complex.... |
|
829 |
{ |
|
830 |
mb->hide(); |
|
831 |
mb->clear(); |
|
832 |
||
833 |
delete pm1; |
|
834 |
pm1 = new Q3PopupMenu( mb, "popup1" ); |
|
835 |
pm1->insertItem( QString("Item A"), item1_A, SLOT(selected()), Qt::CTRL+Qt::Key_A ); |
|
836 |
pm1->insertItem( QString("Item B"), item1_B, SLOT(selected()), Qt::CTRL+Qt::Key_B ); |
|
837 |
// use the form insertItem( QString, Q3PopupMenu ) |
|
838 |
mb->insertItem( "Menu &1", pm1 ); |
|
839 |
||
840 |
delete pm2; |
|
841 |
pm2 = new Q3PopupMenu( mb, "popup2" ); |
|
842 |
pm2->insertItem( QString("Item C"), item2_C, SLOT(selected()), Qt::CTRL+Qt::Key_C ); |
|
843 |
pm2->insertItem( QString("Item D"), item2_D, SLOT(selected()), Qt::CTRL+Qt::Key_D ); |
|
844 |
pm2->insertItem( QString("Item E"), item2_E, SLOT(selected()), Qt::CTRL+Qt::Key_E ); |
|
845 |
pm2->insertItem( QString("Item F"), item2_F, SLOT(selected()), Qt::CTRL+Qt::Key_F ); |
|
846 |
pm2->insertSeparator(); |
|
847 |
pm2->insertItem( QString("Item G"), item2_G, SLOT(selected()), Qt::CTRL+Qt::Key_G ); |
|
848 |
pm2->insertItem( QString("Item H"), item2_H, SLOT(selected()), Qt::CTRL+Qt::Key_H ); |
|
849 |
// use the form insertItem( QString, Q3PopupMenu ) |
|
850 |
mb->insertItem( "Menu &2", pm2 ); |
|
851 |
||
852 |
// use the form insertItem( QString, QObject, slot, keysequence ) |
|
853 |
mb->insertItem( QString("M&enu 3"), menu3, SLOT(selected()), Qt::ALT+Qt::Key_J ); |
|
854 |
mb->show(); |
|
855 |
} |
|
856 |
#endif |
|
857 |
||
858 |
void tst_QMenuBar::initComplexMenubar_noQt3() // well, complex.... |
|
859 |
{ |
|
860 |
mb->hide(); |
|
861 |
mb->clear(); |
|
862 |
||
863 |
delete pm1_Qt4; |
|
864 |
pm1_Qt4 = mb->addMenu("Menu &1"); |
|
865 |
pm1_Qt4->addAction( QString("Item A"), item1_A, SLOT(selected()), Qt::CTRL+Qt::Key_A ); |
|
866 |
pm1_Qt4->addAction( QString("Item B"), item1_B, SLOT(selected()), Qt::CTRL+Qt::Key_B ); |
|
867 |
||
868 |
delete pm2_Qt4; |
|
869 |
pm2_Qt4 = mb->addMenu("Menu &2"); |
|
870 |
pm2_Qt4->addAction( QString("Item C"), item2_C, SLOT(selected()), Qt::CTRL+Qt::Key_C ); |
|
871 |
pm2_Qt4->addAction( QString("Item D"), item2_D, SLOT(selected()), Qt::CTRL+Qt::Key_D ); |
|
872 |
pm2_Qt4->addAction( QString("Item E"), item2_E, SLOT(selected()), Qt::CTRL+Qt::Key_E ); |
|
873 |
pm2_Qt4->addAction( QString("Item F"), item2_F, SLOT(selected()), Qt::CTRL+Qt::Key_F ); |
|
874 |
pm2_Qt4->addSeparator(); |
|
875 |
pm2_Qt4->addAction( QString("Item G"), item2_G, SLOT(selected()), Qt::CTRL+Qt::Key_G ); |
|
876 |
pm2_Qt4->addAction( QString("Item H"), item2_H, SLOT(selected()), Qt::CTRL+Qt::Key_H ); |
|
877 |
||
878 |
QAction *ac = mb->addAction( QString("M&enu 3"), menu3, SLOT(selected())); |
|
879 |
ac->setShortcut(Qt::ALT+Qt::Key_J); |
|
880 |
mb->show(); |
|
881 |
} |
|
882 |
||
883 |
||
884 |
/* |
|
885 |
Check the insert functions that create menu items. |
|
886 |
For the moment i only check the strings and pixmaps. The rest are special cases which are |
|
887 |
used less frequently. |
|
888 |
*/ |
|
889 |
||
890 |
#ifdef QT3_SUPPORT |
|
891 |
void tst_QMenuBar::insertItem_QString_QObject() |
|
892 |
{ |
|
893 |
initComplexMenubar(); |
|
894 |
QCOMPARE( mb->text( mb->idAt( 0 ) ), QString("Menu &1") ); |
|
895 |
QCOMPARE( mb->text( mb->idAt( 1 ) ), QString("Menu &2") ); |
|
896 |
QCOMPARE( mb->text( mb->idAt( 2 ) ), QString("M&enu 3") ); |
|
897 |
QCOMPARE( mb->text( mb->idAt( 3 ) ), QString() ); // there is no menu 4! |
|
898 |
} |
|
899 |
#endif |
|
900 |
||
901 |
void tst_QMenuBar::insertItem_QString_QObject_noQt3() |
|
902 |
{ |
|
903 |
initComplexMenubar_noQt3(); |
|
904 |
||
905 |
QList<QAction *> actions = mb->actions(); |
|
906 |
||
907 |
QCOMPARE(actions.at(0)->text(), QString("Menu &1") ); |
|
908 |
QCOMPARE(actions.at(1)->text(), QString("Menu &2") ); |
|
909 |
QCOMPARE(actions.at(2)->text(), QString("M&enu 3") ); |
|
910 |
QVERIFY(actions.size() < 4); // there is no menu 4! |
|
911 |
} |
|
912 |
||
913 |
void tst_QMenuBar::check_accelKeys() |
|
914 |
{ |
|
915 |
#if defined(Q_WS_MAC) || defined(Q_OS_WINCE_WM) |
|
916 |
QSKIP("On Mac/WinCE, native key events are needed to test menu action activation", SkipAll); |
|
917 |
#endif |
|
918 |
#ifdef QT3_SUPPORT |
|
919 |
initComplexMenubar(); |
|
920 |
#else |
|
921 |
initComplexMenubar_noQt3(); |
|
922 |
#endif |
|
923 |
||
924 |
// start with a bogus key that shouldn't trigger anything |
|
925 |
QTest::keyClick(0, Qt::Key_I, Qt::ControlModifier); |
|
926 |
QCOMPARE(menu1->selCount(), 0u); |
|
927 |
QCOMPARE(menu2->selCount(), 0u); |
|
928 |
QCOMPARE(menu3->selCount(), 0u); |
|
929 |
QCOMPARE(menu4->selCount(), 0u); |
|
930 |
QCOMPARE(item1_A->selCount(), 0u); |
|
931 |
QCOMPARE(item1_B->selCount(), 0u); |
|
932 |
QCOMPARE(item2_C->selCount(), 0u); |
|
933 |
QCOMPARE(item2_D->selCount(), 0u); |
|
934 |
||
935 |
QTest::keyClick(0, Qt::Key_A, Qt::ControlModifier); |
|
936 |
QCOMPARE(menu1->selCount(), 0u); |
|
937 |
QCOMPARE(menu2->selCount(), 0u); |
|
938 |
QCOMPARE(menu3->selCount(), 0u); |
|
939 |
QCOMPARE(menu4->selCount(), 0u); |
|
940 |
QCOMPARE(item1_A->selCount(), 1u); |
|
941 |
QCOMPARE(item1_B->selCount(), 0u); |
|
942 |
QCOMPARE(item2_C->selCount(), 0u); |
|
943 |
QCOMPARE(item2_D->selCount(), 0u); |
|
944 |
||
945 |
QTest::keyClick(0, Qt::Key_C, Qt::ControlModifier); |
|
946 |
QCOMPARE(menu1->selCount(), 0u); |
|
947 |
QCOMPARE(menu2->selCount(), 0u); |
|
948 |
QCOMPARE(menu3->selCount(), 0u); |
|
949 |
QCOMPARE(menu4->selCount(), 0u); |
|
950 |
QCOMPARE(item1_A->selCount(), 1u); |
|
951 |
QCOMPARE(item1_B->selCount(), 0u); |
|
952 |
QCOMPARE(item2_C->selCount(), 1u); |
|
953 |
QCOMPARE(item2_D->selCount(), 0u); |
|
954 |
||
955 |
QTest::keyClick(0, Qt::Key_B, Qt::ControlModifier); |
|
956 |
QCOMPARE(menu1->selCount(), 0u); |
|
957 |
QCOMPARE(menu2->selCount(), 0u); |
|
958 |
QCOMPARE(menu3->selCount(), 0u); |
|
959 |
QCOMPARE(menu4->selCount(), 0u); |
|
960 |
QCOMPARE(item1_A->selCount(), 1u); |
|
961 |
QCOMPARE(item1_B->selCount(), 1u); |
|
962 |
QCOMPARE(item2_C->selCount(), 1u); |
|
963 |
QCOMPARE(item2_D->selCount(), 0u); |
|
964 |
||
965 |
QTest::keyClick(0, Qt::Key_D, Qt::ControlModifier); |
|
966 |
QCOMPARE(menu1->selCount(), 0u); |
|
967 |
QCOMPARE(menu2->selCount(), 0u); |
|
968 |
QCOMPARE(menu3->selCount(), 0u); |
|
969 |
QCOMPARE(menu4->selCount(), 0u); |
|
970 |
QCOMPARE(item1_A->selCount(), 1u); |
|
971 |
QCOMPARE(item1_B->selCount(), 1u); |
|
972 |
QCOMPARE(item2_C->selCount(), 1u); |
|
973 |
QCOMPARE(item2_D->selCount(), 1u); |
|
974 |
||
975 |
QTest::keyClick(0, Qt::Key_J, Qt::AltModifier); |
|
976 |
QCOMPARE(menu1->selCount(), 0u); |
|
977 |
QCOMPARE(menu2->selCount(), 0u); |
|
978 |
QCOMPARE(menu3->selCount(), 1u); |
|
979 |
QCOMPARE(menu4->selCount(), 0u); |
|
980 |
QCOMPARE(item1_A->selCount(), 1u); |
|
981 |
QCOMPARE(item1_B->selCount(), 1u); |
|
982 |
QCOMPARE(item2_C->selCount(), 1u); |
|
983 |
QCOMPARE(item2_D->selCount(), 1u); |
|
984 |
} |
|
985 |
||
986 |
void tst_QMenuBar::check_cursorKeys1() |
|
987 |
{ |
|
988 |
#if defined(Q_WS_MAC) || defined(Q_OS_WINCE_WM) |
|
989 |
QSKIP("Qt/Mac,WinCE does not use the native popups/menubar", SkipAll); |
|
990 |
#endif |
|
991 |
||
992 |
#ifdef QT3_SUPPORT |
|
993 |
initComplexMenubar(); |
|
994 |
#else |
|
995 |
initComplexMenubar_noQt3(); |
|
996 |
#endif |
|
997 |
||
998 |
// start with a ALT + 1 that activates the first popupmenu |
|
999 |
QTest::keyClick( 0, Qt::Key_1, Qt::AltModifier ); |
|
1000 |
// the Popupmenu should be visible now |
|
1001 |
QCOMPARE(menu3->selCount(), 0u); |
|
1002 |
QCOMPARE(menu4->selCount(), 0u); |
|
1003 |
QCOMPARE(item1_A->selCount(), 0u); |
|
1004 |
QCOMPARE(item1_B->selCount(), 0u); |
|
1005 |
QCOMPARE(item2_C->selCount(), 0u); |
|
1006 |
QCOMPARE(item2_D->selCount(), 0u); |
|
1007 |
||
1008 |
// Simulate a cursor key down click |
|
1009 |
QTest::keyClick( 0, Qt::Key_Down ); |
|
1010 |
// and an Enter key |
|
1011 |
QTest::keyClick( 0, Qt::Key_Enter ); |
|
1012 |
// Let's see if the correct slot is called... |
|
1013 |
QCOMPARE(menu3->selCount(), 0u); |
|
1014 |
QCOMPARE(menu4->selCount(), 0u); |
|
1015 |
QCOMPARE(item1_A->selCount(), 0u); // this shouldn't have been called |
|
1016 |
QCOMPARE(item1_B->selCount(), 1u); // and this should have been called by a signal now |
|
1017 |
QCOMPARE(item2_C->selCount(), 0u); |
|
1018 |
QCOMPARE(item2_D->selCount(), 0u); |
|
1019 |
} |
|
1020 |
||
1021 |
void tst_QMenuBar::check_cursorKeys2() |
|
1022 |
{ |
|
1023 |
#if defined(Q_WS_MAC) || defined(Q_OS_WINCE_WM) |
|
1024 |
QSKIP("Qt/Mac,WinCE does not use the native popups/menubar", SkipAll); |
|
1025 |
#endif |
|
1026 |
||
1027 |
#ifdef QT3_SUPPORT |
|
1028 |
initComplexMenubar(); |
|
1029 |
#else |
|
1030 |
initComplexMenubar_noQt3(); |
|
1031 |
#endif |
|
1032 |
||
1033 |
// select popupmenu2 |
|
1034 |
QTest::keyClick( 0, Qt::Key_2, Qt::AltModifier ); |
|
1035 |
||
1036 |
// Simulate some cursor keys |
|
1037 |
QTest::keyClick( 0, Qt::Key_Left ); |
|
1038 |
QTest::keyClick( 0, Qt::Key_Down ); |
|
1039 |
QTest::keyClick( 0, Qt::Key_Right ); |
|
1040 |
QTest::keyClick( 0, Qt::Key_Down ); |
|
1041 |
// and an Enter key |
|
1042 |
QTest::keyClick( 0, Qt::Key_Enter ); |
|
1043 |
// Let's see if the correct slot is called... |
|
1044 |
QCOMPARE(menu3->selCount(), 0u); |
|
1045 |
QCOMPARE(menu4->selCount(), 0u); |
|
1046 |
QCOMPARE(item1_A->selCount(), 0u); // this shouldn't have been caled |
|
1047 |
QCOMPARE(item1_B->selCount(), 0u); // and this should have been called by a signal ow |
|
1048 |
QCOMPARE(item2_C->selCount(), 0u); |
|
1049 |
QCOMPARE(item2_D->selCount(), 1u); |
|
1050 |
} |
|
1051 |
||
1052 |
/*! |
|
1053 |
If a popupmenu is active you can use Left to move to the menu to the left of it. |
|
1054 |
*/ |
|
1055 |
void tst_QMenuBar::check_cursorKeys3() |
|
1056 |
{ |
|
1057 |
#if defined(Q_WS_MAC) || defined(Q_OS_WINCE_WM) |
|
1058 |
QSKIP("Qt/Mac,WinCE does not use the native popups/menubar", SkipAll); |
|
1059 |
#endif |
|
1060 |
||
1061 |
#ifdef QT3_SUPPORT |
|
1062 |
initComplexMenubar(); |
|
1063 |
#else |
|
1064 |
initComplexMenubar_noQt3(); |
|
1065 |
#endif |
|
1066 |
||
1067 |
// select Popupmenu 2 |
|
1068 |
QTest::keyClick( 0, Qt::Key_2, Qt::AltModifier ); |
|
1069 |
||
1070 |
// Simulate some keys |
|
1071 |
QTest::keyClick( 0, Qt::Key_Left ); |
|
1072 |
QTest::keyClick( 0, Qt::Key_Down ); |
|
1073 |
// and press ENTER |
|
1074 |
QTest::keyClick( 0, Qt::Key_Enter ); |
|
1075 |
// Let's see if the correct slot is called... |
|
1076 |
QCOMPARE(menu3->selCount(), 0u); |
|
1077 |
QCOMPARE(menu4->selCount(), 0u); |
|
1078 |
QCOMPARE(item1_A->selCount(), 0u); // this shouldn't have been called |
|
1079 |
QCOMPARE(item1_B->selCount(), 1u); // and this should have been called by a signal now |
|
1080 |
QCOMPARE(item2_C->selCount(), 0u); |
|
1081 |
QCOMPARE(item2_D->selCount(), 0u); |
|
1082 |
} |
|
1083 |
||
1084 |
/*! |
|
1085 |
If a popupmenu is active you can use home to go quickly to the first item in the menu. |
|
1086 |
*/ |
|
1087 |
void tst_QMenuBar::check_homeKey() |
|
1088 |
{ |
|
1089 |
// I'm temporarily shutting up this testcase. |
|
1090 |
// Seems like the behaviour i'm expecting isn't ok. |
|
1091 |
QVERIFY( TRUE ); |
|
1092 |
return; |
|
1093 |
||
1094 |
QEXPECT_FAIL( "0", "Popupmenu should respond to a Home key", Abort ); |
|
1095 |
||
1096 |
#ifdef QT3_SUPPORT |
|
1097 |
initComplexMenubar(); |
|
1098 |
#else |
|
1099 |
initComplexMenubar_noQt3(); |
|
1100 |
#endif |
|
1101 |
||
1102 |
// select Popupmenu 2 |
|
1103 |
QTest::keyClick( 0, Qt::Key_2, Qt::AltModifier ); |
|
1104 |
||
1105 |
// Simulate some keys |
|
1106 |
QTest::keyClick( 0, Qt::Key_Down ); |
|
1107 |
QTest::keyClick( 0, Qt::Key_Down ); |
|
1108 |
QTest::keyClick( 0, Qt::Key_Down ); |
|
1109 |
QTest::keyClick( 0, Qt::Key_Home ); |
|
1110 |
// and press ENTER |
|
1111 |
QTest::keyClick( 0, Qt::Key_Enter ); |
|
1112 |
// Let's see if the correct slot is called... |
|
1113 |
// QVERIFY2( item2_C->selCount() == 1, "Popupmenu should respond to a Home key" ); |
|
1114 |
QCOMPARE(item2_C->selCount(), 1u); |
|
1115 |
QCOMPARE(menu3->selCount(), 0u); |
|
1116 |
QCOMPARE(menu4->selCount(), 0u); |
|
1117 |
QCOMPARE(item1_A->selCount(), 0u); |
|
1118 |
QCOMPARE(item1_B->selCount(), 0u); |
|
1119 |
QCOMPARE(item2_D->selCount(), 0u); |
|
1120 |
QCOMPARE(item2_E->selCount(), 0u); |
|
1121 |
QCOMPARE(item2_F->selCount(), 0u); |
|
1122 |
QCOMPARE(item2_G->selCount(), 0u); |
|
1123 |
QCOMPARE(item2_H->selCount(), 0u); |
|
1124 |
} |
|
1125 |
||
1126 |
/*! |
|
1127 |
If a popupmenu is active you can use end to go quickly to the last item in the menu. |
|
1128 |
*/ |
|
1129 |
void tst_QMenuBar::check_endKey() |
|
1130 |
{ |
|
1131 |
// I'm temporarily silenting this testcase. |
|
1132 |
// Seems like the behaviour i'm expecting isn't ok. |
|
1133 |
QVERIFY( TRUE ); |
|
1134 |
return; |
|
1135 |
||
1136 |
QEXPECT_FAIL( "0", "Popupmenu should respond to an End key", Abort ); |
|
1137 |
||
1138 |
#ifdef QT3_SUPPORT |
|
1139 |
initComplexMenubar(); |
|
1140 |
#else |
|
1141 |
initComplexMenubar_noQt3(); |
|
1142 |
#endif |
|
1143 |
||
1144 |
// select Popupmenu 2 |
|
1145 |
QTest::keyClick( 0, Qt::Key_2, Qt::AltModifier ); |
|
1146 |
||
1147 |
// Simulate some keys |
|
1148 |
QTest::keyClick( 0, Qt::Key_End ); |
|
1149 |
// and press ENTER |
|
1150 |
QTest::keyClick( 0, Qt::Key_Enter ); |
|
1151 |
// Let's see if the correct slot is called... |
|
1152 |
// QVERIFY2( item2_H->selCount() == 1, "Popupmenu should respond to an End key" ); |
|
1153 |
QCOMPARE(item2_H->selCount(), 1u);//, "Popupmenu should respond to an End key"); |
|
1154 |
QCOMPARE(menu3->selCount(), 0u); |
|
1155 |
QCOMPARE(menu4->selCount(), 0u); |
|
1156 |
QCOMPARE(item1_A->selCount(), 0u); |
|
1157 |
QCOMPARE(item1_B->selCount(), 0u); |
|
1158 |
QCOMPARE(item2_C->selCount(), 0u); |
|
1159 |
QCOMPARE(item2_D->selCount(), 0u); |
|
1160 |
QCOMPARE(item2_E->selCount(), 0u); |
|
1161 |
QCOMPARE(item2_F->selCount(), 0u); |
|
1162 |
QCOMPARE(item2_G->selCount(), 0u); |
|
1163 |
} |
|
1164 |
||
1165 |
/*! |
|
1166 |
If a popupmenu is active you can use esc to hide the menu and then the |
|
1167 |
menubar should become active. |
|
1168 |
If Down is pressed next the popup is activated again. |
|
1169 |
*/ |
|
1170 |
||
1171 |
#ifdef QT3_SUPPORT |
|
1172 |
void tst_QMenuBar::check_escKey() |
|
1173 |
{ |
|
1174 |
#ifdef Q_WS_MAC |
|
1175 |
QSKIP("Qt/Mac does not use the native popups/menubar", SkipAll); |
|
1176 |
#endif |
|
1177 |
||
1178 |
initComplexMenubar(); |
|
1179 |
||
1180 |
QVERIFY( !pm1->isActiveWindow() ); |
|
1181 |
QVERIFY( !pm2->isActiveWindow() ); |
|
1182 |
||
1183 |
// select Popupmenu 2 |
|
1184 |
QTest::keyClick( 0, Qt::Key_2, Qt::AltModifier ); |
|
1185 |
QVERIFY( !pm1->isActiveWindow() ); |
|
1186 |
QVERIFY( pm2->isActiveWindow() ); |
|
1187 |
||
1188 |
// If we press ESC, the popup should disappear |
|
1189 |
QTest::keyClick( 0, Qt::Key_Escape ); |
|
1190 |
QVERIFY( !pm1->isActiveWindow() ); |
|
1191 |
QVERIFY( !pm2->isActiveWindow() ); |
|
1192 |
||
1193 |
if (!QApplication::style()->inherits("QWindowsStyle")) |
|
1194 |
return; |
|
1195 |
||
1196 |
// but the menubar item should stay selected |
|
1197 |
QVERIFY( mb->isItemActive(mb->idAt(1)) ); |
|
1198 |
||
1199 |
// If we press Down the popupmenu should be active again |
|
1200 |
QTest::keyClick( 0, Qt::Key_Down ); |
|
1201 |
QVERIFY( !pm1->isActiveWindow() ); |
|
1202 |
QVERIFY( pm2->isActiveWindow() ); |
|
1203 |
||
1204 |
// and press ENTER |
|
1205 |
QTest::keyClick( pm2, Qt::Key_Enter ); |
|
1206 |
// Let's see if the correct slot is called... |
|
1207 |
QVERIFY2( item2_C->selCount() == 1, "Expected item 2C to be selected" ); |
|
1208 |
} |
|
1209 |
#endif |
|
1210 |
||
1211 |
void tst_QMenuBar::check_escKey_noQt3() |
|
1212 |
{ |
|
1213 |
#if defined(Q_WS_MAC) || defined(Q_OS_WINCE_WM) |
|
1214 |
QSKIP("Qt/Mac,WinCE does not use the native popups/menubar", SkipAll); |
|
1215 |
#endif |
|
1216 |
||
1217 |
initComplexMenubar_noQt3(); |
|
1218 |
||
1219 |
QVERIFY( !pm1_Qt4->isActiveWindow() ); |
|
1220 |
QVERIFY( !pm2_Qt4->isActiveWindow() ); |
|
1221 |
||
1222 |
// select Popupmenu 2 |
|
1223 |
QTest::keyClick( 0, Qt::Key_2, Qt::AltModifier ); |
|
1224 |
QVERIFY( !pm1_Qt4->isActiveWindow() ); |
|
1225 |
QVERIFY( pm2_Qt4->isActiveWindow() ); |
|
1226 |
||
1227 |
// If we press ESC, the popup should disappear |
|
1228 |
QTest::keyClick( 0, Qt::Key_Escape ); |
|
1229 |
QVERIFY( !pm1_Qt4->isActiveWindow() ); |
|
1230 |
QVERIFY( !pm2_Qt4->isActiveWindow() ); |
|
1231 |
||
1232 |
if (!QApplication::style()->inherits("QWindowsStyle")) |
|
1233 |
return; |
|
1234 |
||
1235 |
// If we press Down the popupmenu should be active again |
|
1236 |
QTest::keyClick( 0, Qt::Key_Down ); |
|
1237 |
QVERIFY( !pm1_Qt4->isActiveWindow() ); |
|
1238 |
QVERIFY( pm2_Qt4->isActiveWindow() ); |
|
1239 |
||
1240 |
// and press ENTER |
|
1241 |
QTest::keyClick( pm2_Qt4, Qt::Key_Enter ); |
|
1242 |
// Let's see if the correct slot is called... |
|
1243 |
QVERIFY2( item2_C->selCount() == 1, "Expected item 2C to be selected" ); |
|
1244 |
} |
|
1245 |
||
1246 |
||
1247 |
// void tst_QMenuBar::check_mouse1_data() |
|
1248 |
// { |
|
1249 |
// QTest::addColumn<QString>("popup_item"); |
|
1250 |
// QTest::addColumn<int>("itemA_count"); |
|
1251 |
// QTest::addColumn<int>("itemB_count"); |
|
1252 |
||
1253 |
// QTest::newRow( "A" ) << QString( "Item A Ctrl+A" ) << 1 << 0; |
|
1254 |
// QTest::newRow( "B" ) << QString( "Item B Ctrl+B" ) << 0 << 1; |
|
1255 |
// } |
|
1256 |
||
1257 |
// /*! |
|
1258 |
// Check if the correct signals are emitted if we select a popupmenu. |
|
1259 |
// */ |
|
1260 |
// void tst_QMenuBar::check_mouse1() |
|
1261 |
// { |
|
1262 |
// if (QSystem::curStyle() == "Motif") |
|
1263 |
// QSKIP("This fails in Motif due to a bug in the testing framework", SkipAll); |
|
1264 |
// QFETCH( QString, popup_item ); |
|
1265 |
// QFETCH( int, itemA_count ); |
|
1266 |
// QFETCH( int, itemB_count ); |
|
1267 |
||
1268 |
// initComplexMenubar(); |
|
1269 |
// QVERIFY( !pm1->isActiveWindow() ); |
|
1270 |
// QVERIFY( !pm2->isActiveWindow() ); |
|
1271 |
||
1272 |
// QTest::qWait(1000); |
|
1273 |
// QtTestMouse mouse; |
|
1274 |
// mouse.mouseEvent( QtTestMouse::MouseClick, mb, "Menu &1", Qt::LeftButton ); |
|
1275 |
||
1276 |
// QVERIFY( pm1->isActiveWindow() ); |
|
1277 |
// QVERIFY( !pm2->isActiveWindow() ); |
|
1278 |
||
1279 |
// QTest::qWait(1000); |
|
1280 |
// mouse.mouseEvent( QtTestMouse::MouseClick, pm1, popup_item, Qt::LeftButton ); |
|
1281 |
||
1282 |
// QCOMPARE(menu3->selCount(), 0u); |
|
1283 |
// QCOMPARE(menu4->selCount(), 0u); |
|
1284 |
// QCOMPARE(item1_A->selCount(), (uint)itemA_count); // this option should have fired |
|
1285 |
// QCOMPARE(item1_B->selCount(), (uint)itemB_count); |
|
1286 |
// QCOMPARE(item2_C->selCount(), 0u); |
|
1287 |
// QCOMPARE(item2_D->selCount(), 0u); |
|
1288 |
// QCOMPARE(item2_E->selCount(), 0u); |
|
1289 |
// QCOMPARE(item2_F->selCount(), 0u); |
|
1290 |
// QCOMPARE(item2_G->selCount(), 0u); |
|
1291 |
// } |
|
1292 |
||
1293 |
// void tst_QMenuBar::check_mouse2_data() |
|
1294 |
// { |
|
1295 |
// QTest::addColumn<QString>("label"); |
|
1296 |
// QTest::addColumn<int>("itemA_count"); |
|
1297 |
// QTest::addColumn<int>("itemB_count"); |
|
1298 |
// QTest::addColumn<int>("itemC_count"); |
|
1299 |
// QTest::addColumn<int>("itemD_count"); |
|
1300 |
// QTest::addColumn<int>("itemE_count"); |
|
1301 |
// QTest::addColumn<int>("itemF_count"); |
|
1302 |
// QTest::addColumn<int>("itemG_count"); |
|
1303 |
// QTest::addColumn<int>("itemH_count"); |
|
1304 |
// QTest::addColumn<int>("menu3_count"); |
|
1305 |
||
1306 |
// QTest::newRow( "A" ) << QString( "Menu &1/Item A Ctrl+A" ) << 1 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; |
|
1307 |
// QTest::newRow( "B" ) << QString( "Menu &1/Item B Ctrl+B" ) << 0 << 1 << 0 << 0 << 0 << 0 << 0 << 0 << 0; |
|
1308 |
// QTest::newRow( "C" ) << QString( "Menu &2/Item C Ctrl+C" ) << 0 << 0 << 1 << 0 << 0 << 0 << 0 << 0 << 0; |
|
1309 |
// QTest::newRow( "D" ) << QString( "Menu &2/Item D Ctrl+D" ) << 0 << 0 << 0 << 1 << 0 << 0 << 0 << 0 << 0; |
|
1310 |
// QTest::newRow( "E" ) << QString( "Menu &2/Item E Ctrl+E" ) << 0 << 0 << 0 << 0 << 1 << 0 << 0 << 0 << 0; |
|
1311 |
// QTest::newRow( "F" ) << QString( "Menu &2/Item F Ctrl+F" ) << 0 << 0 << 0 << 0 << 0 << 1 << 0 << 0 << 0; |
|
1312 |
// QTest::newRow( "G" ) << QString( "Menu &2/Item G Ctrl+G" ) << 0 << 0 << 0 << 0 << 0 << 0 << 1 << 0 << 0; |
|
1313 |
// QTest::newRow( "H" ) << QString( "Menu &2/Item H Ctrl+H" ) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 1 << 0; |
|
1314 |
// QTest::newRow( "menu 3" ) << QString( "M&enu 3" ) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 1; |
|
1315 |
// } |
|
1316 |
||
1317 |
// /*! |
|
1318 |
// Check if the correct signals are emitted if we select a popupmenu. |
|
1319 |
// This time, we use a little bit more magic from the testframework. |
|
1320 |
// */ |
|
1321 |
// void tst_QMenuBar::check_mouse2() |
|
1322 |
// { |
|
1323 |
// if (QSystem::curStyle() == "Motif") |
|
1324 |
// QSKIP("This fails in Motif due to a bug in the testing framework", SkipAll); |
|
1325 |
// QFETCH( QString, label ); |
|
1326 |
// QFETCH( int, itemA_count ); |
|
1327 |
// QFETCH( int, itemB_count ); |
|
1328 |
// QFETCH( int, itemC_count ); |
|
1329 |
// QFETCH( int, itemD_count ); |
|
1330 |
// QFETCH( int, itemE_count ); |
|
1331 |
// QFETCH( int, itemF_count ); |
|
1332 |
// QFETCH( int, itemG_count ); |
|
1333 |
// QFETCH( int, itemH_count ); |
|
1334 |
// QFETCH( int, menu3_count ); |
|
1335 |
||
1336 |
// initComplexMenubar(); |
|
1337 |
// QtTestMouse mouse; |
|
1338 |
// mouse.click( QtTestMouse::Menu, label, Qt::LeftButton ); |
|
1339 |
||
1340 |
// // check if the correct signals have fired |
|
1341 |
// QCOMPARE(menu3->selCount(), (uint)menu3_count); |
|
1342 |
// QCOMPARE(menu4->selCount(), 0u); |
|
1343 |
// QCOMPARE(item1_A->selCount(), (uint)itemA_count); |
|
1344 |
// QCOMPARE(item1_B->selCount(), (uint)itemB_count); |
|
1345 |
// QCOMPARE(item2_C->selCount(), (uint)itemC_count); |
|
1346 |
// QCOMPARE(item2_D->selCount(), (uint)itemD_count); |
|
1347 |
// QCOMPARE(item2_E->selCount(), (uint)itemE_count); |
|
1348 |
// QCOMPARE(item2_F->selCount(), (uint)itemF_count); |
|
1349 |
// QCOMPARE(item2_G->selCount(), (uint)itemG_count); |
|
1350 |
// QCOMPARE(item2_H->selCount(), (uint)itemH_count); |
|
1351 |
// } |
|
1352 |
||
1353 |
void |
|
1354 |
tst_QMenuBar::allowActiveAndDisabled() |
|
1355 |
{ |
|
1356 |
#if !defined(Q_WS_MAC) && !defined(Q_OS_WINCE_WM) |
|
1357 |
mb->hide(); |
|
1358 |
mb->clear(); |
|
1359 |
||
1360 |
// Task 241043 : check that second menu is activated if only |
|
1361 |
// disabled menu items are added |
|
1362 |
||
1363 |
QMenu fileMenu("&File"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1364 |
// Task 241043 : check that second menu is activated |
0 | 1365 |
// if all items are disabled |
1366 |
QAction *act = fileMenu.addAction("Disabled"); |
|
1367 |
act->setEnabled(false); |
|
1368 |
||
1369 |
mb->addMenu(&fileMenu); |
|
1370 |
QMenu disabledMenu("Disabled"); |
|
1371 |
disabledMenu.setEnabled(false); |
|
1372 |
QMenu activeMenu("Active"); |
|
1373 |
mb->addMenu(&disabledMenu); |
|
1374 |
mb->addMenu(&activeMenu); |
|
1375 |
mb->show(); |
|
1376 |
||
1377 |
||
1378 |
// Here we verify that AllowActiveAndDisabled correctly skips |
|
1379 |
// the disabled menu entry |
|
1380 |
QTest::keyClick(mb, Qt::Key_F, Qt::AltModifier ); |
|
1381 |
QTest::keyClick(&fileMenu, (Qt::Key_Right)); |
|
1382 |
if (qApp->style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled)) |
|
1383 |
QCOMPARE(mb->activeAction()->text(), disabledMenu.title()); |
|
1384 |
else |
|
1385 |
QCOMPARE(mb->activeAction()->text(), activeMenu.title()); |
|
1386 |
||
1387 |
QTest::keyClick(mb, (Qt::Key_Left)); |
|
1388 |
if (qApp->style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled)) |
|
1389 |
QCOMPARE(mb->activeAction()->text(), fileMenu.title()); |
|
1390 |
else |
|
1391 |
QCOMPARE(mb->activeAction()->text(), fileMenu.title()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1392 |
|
0 | 1393 |
mb->hide(); |
1394 |
#endif //Q_WS_MAC |
|
1395 |
} |
|
1396 |
||
1397 |
void tst_QMenuBar::check_altPress() |
|
1398 |
{ |
|
1399 |
if ( !qApp->style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation) ) { |
|
1400 |
QSKIP( QString( "this is not supposed to work in the %1 style. Skipping." ). |
|
1401 |
arg( qApp->style()->objectName() ).toAscii(), SkipAll ); |
|
1402 |
} |
|
1403 |
||
1404 |
#ifdef QT3_SUPPORT |
|
1405 |
initSimpleMenubar(); |
|
1406 |
#else |
|
1407 |
initSimpleMenubar_noQt3(); |
|
1408 |
#endif |
|
1409 |
||
1410 |
qApp->setActiveWindow(mw); |
|
1411 |
mw->setFocus(); |
|
1412 |
||
1413 |
QTest::keyClick( mw, Qt::Key_Alt ); |
|
1414 |
||
1415 |
QVERIFY( ::qobject_cast<QMenuBar *>(qApp->focusWidget()) ); |
|
1416 |
} |
|
1417 |
||
1418 |
void tst_QMenuBar::check_shortcutPress() |
|
1419 |
{ |
|
1420 |
#if defined(Q_WS_MAC) || defined(Q_OS_WINCE_WM) |
|
1421 |
QSKIP("Qt/Mac,WinCE does not use the native popups/menubar", SkipAll); |
|
1422 |
#endif |
|
1423 |
||
1424 |
#ifdef QT3_SUPPORT |
|
1425 |
initComplexMenubar(); |
|
1426 |
#else |
|
1427 |
initComplexMenubar_noQt3(); |
|
1428 |
#endif |
|
1429 |
||
1430 |
qApp->setActiveWindow(mw); |
|
1431 |
QCOMPARE(menu3->selCount(), 0u); |
|
1432 |
QTest::keyClick(mw, Qt::Key_E, Qt::AltModifier); |
|
1433 |
QTest::qWait(200); |
|
1434 |
QCOMPARE(menu3->selCount(), 1u); |
|
1435 |
QVERIFY(!mb->activeAction()); |
|
1436 |
||
1437 |
QTest::keyClick(mw, Qt::Key_1, Qt::AltModifier ); |
|
1438 |
#ifdef QT3_SUPPORT |
|
1439 |
QVERIFY(pm1->isActiveWindow()); |
|
1440 |
#else |
|
1441 |
QVERIFY(pm1_Qt4->isActiveWindow()); |
|
1442 |
#endif |
|
1443 |
QTest::keyClick(mb, Qt::Key_2); |
|
1444 |
#ifdef QT3_SUPPORT |
|
1445 |
QVERIFY(pm1->isActiveWindow()); // Should still be the active window |
|
1446 |
#else |
|
1447 |
QVERIFY(pm1_Qt4->isActiveWindow()); |
|
1448 |
#endif |
|
1449 |
} |
|
1450 |
||
1451 |
void tst_QMenuBar::check_menuPosition() |
|
1452 |
{ |
|
1453 |
#ifdef Q_WS_MAC |
|
1454 |
QSKIP("Qt/Mac does not use the native popups/menubar", SkipAll); |
|
1455 |
#endif |
|
1456 |
#ifdef Q_OS_WINCE_WM |
|
1457 |
QSKIP("Qt/CE uses native menubar", SkipAll); |
|
1458 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1459 |
Menu menu; |
0 | 1460 |
#ifdef QT3_SUPPORT |
1461 |
initComplexMenubar(); |
|
1462 |
#else |
|
1463 |
initComplexMenubar_noQt3(); |
|
1464 |
#endif |
|
1465 |
menu.setTitle("&menu"); |
|
1466 |
QRect availRect = QApplication::desktop()->availableGeometry(mw); |
|
1467 |
QRect screenRect = QApplication::desktop()->screenGeometry(mw); |
|
1468 |
||
1469 |
while(menu.sizeHint().height() < (screenRect.height()*2/3)) { |
|
1470 |
menu.addAction("item"); |
|
1471 |
} |
|
1472 |
||
1473 |
QAction *menu_action = mw->menuBar()->addMenu(&menu); |
|
1474 |
||
1475 |
qApp->setActiveWindow(mw); |
|
1476 |
qApp->processEvents(); |
|
1477 |
||
1478 |
//the menu should be below the menubar item |
|
1479 |
{ |
|
1480 |
mw->move(availRect.topLeft()); |
|
1481 |
QRect mbItemRect = mw->menuBar()->actionGeometry(menu_action); |
|
1482 |
mbItemRect.moveTo(mw->menuBar()->mapToGlobal(mbItemRect.topLeft())); |
|
1483 |
QTest::keyClick(mw, Qt::Key_M, Qt::AltModifier ); |
|
1484 |
QVERIFY(menu.isActiveWindow()); |
|
1485 |
QCOMPARE(menu.pos(), QPoint(mbItemRect.x(), mbItemRect.bottom() + 1)); |
|
1486 |
menu.close(); |
|
1487 |
} |
|
1488 |
||
1489 |
//the menu should be above the menubar item |
|
1490 |
{ |
|
1491 |
mw->move(0,screenRect.bottom() - screenRect.height()/4); //just leave some place for the menubar |
|
1492 |
QRect mbItemRect = mw->menuBar()->actionGeometry(menu_action); |
|
1493 |
mbItemRect.moveTo(mw->menuBar()->mapToGlobal(mbItemRect.topLeft())); |
|
1494 |
QTest::keyClick(mw, Qt::Key_M, Qt::AltModifier ); |
|
1495 |
QVERIFY(menu.isActiveWindow()); |
|
1496 |
QCOMPARE(menu.pos(), QPoint(mbItemRect.x(), mbItemRect.top() - menu.height())); |
|
1497 |
menu.close(); |
|
1498 |
} |
|
1499 |
||
1500 |
//the menu should be on the side of the menubar item and should be "stuck" to the bottom of the screen |
|
1501 |
{ |
|
1502 |
mw->move(0,screenRect.y() + screenRect.height()/2); //put it in the middle |
|
1503 |
QRect mbItemRect = mw->menuBar()->actionGeometry(menu_action); |
|
1504 |
mbItemRect.moveTo(mw->menuBar()->mapToGlobal(mbItemRect.topLeft())); |
|
1505 |
QTest::keyClick(mw, Qt::Key_M, Qt::AltModifier ); |
|
1506 |
QVERIFY(menu.isActiveWindow()); |
|
1507 |
QPoint firstPoint = QPoint(mbItemRect.right()+1, screenRect.bottom() - menu.height() + 1); |
|
1508 |
QPoint secondPoint = QPoint(mbItemRect.right()+1, availRect.bottom() - menu.height() + 1); |
|
1509 |
QVERIFY(menu.pos() == firstPoint || menu.pos() == secondPoint); |
|
1510 |
menu.close(); |
|
1511 |
} |
|
1512 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1513 |
//in RTL, the menu should be stuck at the right of the action geometry |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1514 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1515 |
Qt::LayoutDirection dir = qApp->layoutDirection(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1516 |
qApp->setLayoutDirection(Qt::RightToLeft); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1517 |
menu.clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1518 |
QObject::connect(&menu, SIGNAL(aboutToShow()), &menu, SLOT(addActions())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1519 |
QRect mbItemRect = mw->menuBar()->actionGeometry(menu_action); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1520 |
mbItemRect.moveTo(mw->menuBar()->mapToGlobal(mbItemRect.topLeft())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1521 |
QTest::keyClick(mw, Qt::Key_M, Qt::AltModifier ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1522 |
QVERIFY(menu.isActiveWindow()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1523 |
QCOMPARE(menu.geometry().right(), mbItemRect.right()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1524 |
menu.close(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1525 |
qApp->setLayoutDirection(dir); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1526 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1527 |
|
0 | 1528 |
} |
1529 |
||
1530 |
void tst_QMenuBar::task223138_triggered() |
|
1531 |
{ |
|
1532 |
qRegisterMetaType<QAction *>("QAction *"); |
|
1533 |
//we create a window with submenus and we check that both menubar and menus get the triggered signal |
|
1534 |
QMainWindow win; |
|
1535 |
QMenu *menu = win.menuBar()->addMenu("test"); |
|
1536 |
QAction *top = menu->addAction("toplevelaction"); |
|
1537 |
QMenu *submenu = menu->addMenu("nested menu"); |
|
1538 |
QAction *action = submenu->addAction("nested action"); |
|
1539 |
||
1540 |
QSignalSpy menubarSpy(win.menuBar(), SIGNAL(triggered(QAction*))); |
|
1541 |
QSignalSpy menuSpy(menu, SIGNAL(triggered(QAction*))); |
|
1542 |
QSignalSpy submenuSpy(submenu, SIGNAL(triggered(QAction*))); |
|
1543 |
||
1544 |
//let's trigger the first action |
|
1545 |
top->trigger(); |
|
1546 |
||
1547 |
QCOMPARE(menubarSpy.count(), 1); |
|
1548 |
QCOMPARE(menuSpy.count(), 1); |
|
1549 |
QCOMPARE(submenuSpy.count(), 0); |
|
1550 |
||
1551 |
menubarSpy.clear(); |
|
1552 |
menuSpy.clear(); |
|
1553 |
submenuSpy.clear(); |
|
1554 |
||
1555 |
//let's trigger the sub action |
|
1556 |
action->trigger(); |
|
1557 |
QCOMPARE(menubarSpy.count(), 1); |
|
1558 |
QCOMPARE(menuSpy.count(), 1); |
|
1559 |
QCOMPARE(submenuSpy.count(), 1); |
|
1560 |
} |
|
1561 |
||
1562 |
void tst_QMenuBar::task256322_highlight() |
|
1563 |
{ |
|
1564 |
QMainWindow win; |
|
1565 |
win.menuBar()->setNativeMenuBar(false); //we can't check the geometry of native menubars |
|
1566 |
QMenu menu; |
|
1567 |
QAction *file = win.menuBar()->addMenu(&menu); |
|
1568 |
file->setText("file"); |
|
1569 |
QMenu menu2; |
|
1570 |
QAction *file2 = win.menuBar()->addMenu(&menu2); |
|
1571 |
file2->setText("file2"); |
|
1572 |
QAction *nothing = win.menuBar()->addAction("nothing"); |
|
1573 |
||
1574 |
win.show(); |
|
1575 |
QTest::qWait(200); |
|
1576 |
||
1577 |
QTest::mousePress(win.menuBar(), Qt::LeftButton, 0, win.menuBar()->actionGeometry(file).center()); |
|
1578 |
QTest::mouseMove(win.menuBar(), win.menuBar()->actionGeometry(file).center()); |
|
1579 |
QTest::mouseRelease(win.menuBar(), Qt::LeftButton, 0, win.menuBar()->actionGeometry(file).center()); |
|
1580 |
QTRY_VERIFY(menu.isVisible()); |
|
1581 |
QVERIFY(!menu2.isVisible()); |
|
1582 |
QCOMPARE(win.menuBar()->activeAction(), file); |
|
1583 |
||
1584 |
QTest::mousePress(win.menuBar(), Qt::LeftButton, 0, win.menuBar()->actionGeometry(file2).center()); |
|
1585 |
QTest::mouseMove(win.menuBar(), win.menuBar()->actionGeometry(file2).center()); |
|
1586 |
QTRY_VERIFY(!menu.isVisible()); |
|
1587 |
QVERIFY(menu2.isVisible()); |
|
1588 |
QCOMPARE(win.menuBar()->activeAction(), file2); |
|
1589 |
QTest::mouseRelease(win.menuBar(), Qt::LeftButton, 0, win.menuBar()->actionGeometry(file2).center()); |
|
1590 |
||
1591 |
QPoint nothingCenter = win.menuBar()->actionGeometry(nothing).center(); |
|
1592 |
QTest::mousePress(win.menuBar(), Qt::LeftButton, 0, nothingCenter); |
|
1593 |
QTest::mouseMove(win.menuBar(), nothingCenter); |
|
1594 |
QTRY_VERIFY(!menu2.isVisible()); |
|
1595 |
QVERIFY(!menu.isVisible()); |
|
1596 |
QCOMPARE(win.menuBar()->activeAction(), nothing); |
|
1597 |
QTest::mouseRelease(win.menuBar(), Qt::LeftButton, 0, nothingCenter); |
|
1598 |
} |
|
1599 |
||
1600 |
void tst_QMenuBar::menubarSizeHint() |
|
1601 |
{ |
|
1602 |
struct MyStyle : public QWindowsStyle |
|
1603 |
{ |
|
1604 |
virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const |
|
1605 |
{ |
|
1606 |
// I chose strange values (prime numbers to be more sure that the size of the menubar is correct) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1607 |
switch (metric) |
0 | 1608 |
{ |
1609 |
case QStyle::PM_MenuBarItemSpacing: |
|
1610 |
return 7; |
|
1611 |
case PM_MenuBarHMargin: |
|
1612 |
return 13; |
|
1613 |
case PM_MenuBarVMargin: |
|
1614 |
return 11; |
|
1615 |
case PM_MenuBarPanelWidth: |
|
1616 |
return 1; |
|
1617 |
default: |
|
1618 |
return QWindowsStyle::pixelMetric(metric, option, widget); |
|
1619 |
} |
|
1620 |
} |
|
1621 |
} style; |
|
1622 |
||
1623 |
QMenuBar mb; |
|
1624 |
mb.setNativeMenuBar(false); //we can't check the geometry of native menubars |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1625 |
|
0 | 1626 |
mb.setStyle(&style); |
1627 |
//this is a list of arbitrary strings so that we check the geometry |
|
1628 |
QStringList list = QStringList() << "trer" << "ezrfgtgvqd" << "sdgzgzerzerzer" << "eerzertz" << "er"; |
|
1629 |
foreach(QString str, list) |
|
1630 |
mb.addAction(str); |
|
1631 |
||
1632 |
const int panelWidth = style.pixelMetric(QStyle::PM_MenuBarPanelWidth); |
|
1633 |
const int hmargin = style.pixelMetric(QStyle::PM_MenuBarHMargin); |
|
1634 |
const int vmargin = style.pixelMetric(QStyle::PM_MenuBarVMargin); |
|
1635 |
const int spacing = style.pixelMetric(QStyle::PM_MenuBarItemSpacing); |
|
1636 |
||
1637 |
mb.show(); |
|
1638 |
QRect result; |
|
1639 |
foreach(QAction *action, mb.actions()) { |
|
1640 |
const QRect actionRect = mb.actionGeometry(action); |
|
1641 |
if (!result.isNull()) //this is the first item |
|
1642 |
QCOMPARE(actionRect.left() - result.right() - 1, spacing); |
|
1643 |
result |= actionRect; |
|
1644 |
QCOMPARE(result.x(), panelWidth + hmargin + spacing); |
|
1645 |
QCOMPARE(result.y(), panelWidth + vmargin); |
|
1646 |
} |
|
1647 |
||
1648 |
//this code is copied from QMenuBar |
|
1649 |
//there is no public member that allows to initialize a styleoption instance |
|
1650 |
QStyleOptionMenuItem opt; |
|
1651 |
opt.rect = mb.rect(); |
|
1652 |
opt.menuRect = mb.rect(); |
|
1653 |
opt.state = QStyle::State_None; |
|
1654 |
opt.menuItemType = QStyleOptionMenuItem::Normal; |
|
1655 |
opt.checkType = QStyleOptionMenuItem::NotCheckable; |
|
1656 |
opt.palette = mb.palette(); |
|
1657 |
||
1658 |
QSize resSize = QSize(result.x(), result.y()) + result.size() |
|
1659 |
+ QSize(panelWidth + hmargin, panelWidth + vmargin); |
|
1660 |
||
1661 |
||
1662 |
resSize = style.sizeFromContents(QStyle::CT_MenuBar, &opt, |
|
1663 |
resSize.expandedTo(QApplication::globalStrut()), |
|
1664 |
&mb); |
|
1665 |
||
1666 |
QCOMPARE(resSize, mb.sizeHint()); |
|
1667 |
} |
|
1668 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1669 |
void tst_QMenuBar::taskQTBUG4965_escapeEaten() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1670 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1671 |
#ifdef Q_WS_MAC |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1672 |
QSKIP("On Mac, do not test the menubar with escape key", SkipAll); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1673 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1674 |
QMenuBar menubar; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1675 |
QMenu menu("menu1"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1676 |
QAction *first = menubar.addMenu(&menu); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1677 |
menu.addAction("quit", &menubar, SLOT(close()), QKeySequence("ESC")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1678 |
menubar.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1679 |
QApplication::setActiveWindow(&menubar); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1680 |
QTest::qWaitForWindowShown(&menubar); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1681 |
menubar.setActiveAction(first); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1682 |
QTRY_VERIFY(menu.isVisible()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1683 |
QCOMPARE(menubar.activeAction(), first); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1684 |
QTest::keyClick(0, Qt::Key_Escape); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1685 |
QVERIFY(!menu.isVisible()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1686 |
QTRY_VERIFY(menubar.hasFocus()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1687 |
QCOMPARE(menubar.activeAction(), first); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1688 |
QTest::keyClick(0, Qt::Key_Escape); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1689 |
QVERIFY(!menubar.activeAction()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1690 |
QTest::keyClick(0, Qt::Key_Escape); //now the action should be triggered |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1691 |
QTRY_VERIFY(!menubar.isVisible()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1692 |
} |
0 | 1693 |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1694 |
void tst_QMenuBar::taskQTBUG11823_crashwithInvisibleActions() |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1695 |
{ |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1696 |
QMenuBar menubar; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1697 |
menubar.setNativeMenuBar(false); //we can't check the geometry of native menubars |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1698 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1699 |
QAction * m = menubar.addAction( "&m" ); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1700 |
QAction * a = menubar.addAction( "&a" ); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1701 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1702 |
menubar.show(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1703 |
QApplication::setActiveWindow(&menubar); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1704 |
QTest::qWaitForWindowShown(&menubar); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1705 |
menubar.setActiveAction(m); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1706 |
QCOMPARE(menubar.activeAction(), m); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1707 |
QTest::keyClick(0, Qt::Key_Right); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1708 |
QCOMPARE(menubar.activeAction(), a); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1709 |
QTest::keyClick(0, Qt::Key_Right); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1710 |
QCOMPARE(menubar.activeAction(), m); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1711 |
a->setVisible(false); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1712 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1713 |
menubar.setActiveAction(m); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1714 |
QCOMPARE(menubar.activeAction(), m); //the active action shouldn't have changed |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1715 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1716 |
//it used to crash here because the action is invisible |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1717 |
QTest::keyClick(0, Qt::Key_Right); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1718 |
QCOMPARE(menubar.activeAction(), m); //the active action shouldn't have changed |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1719 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1720 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1721 |
|
0 | 1722 |
#if defined(QT3_SUPPORT) |
1723 |
void tst_QMenuBar::indexBasedInsertion_data() |
|
1724 |
{ |
|
1725 |
QTest::addColumn<int>("indexForInsertion"); |
|
1726 |
QTest::addColumn<int>("expectedIndex"); |
|
1727 |
||
1728 |
QTest::newRow("negative-index-appends") << -1 << 1; |
|
1729 |
QTest::newRow("prepend") << 0 << 0; |
|
1730 |
QTest::newRow("append") << 1 << 1; |
|
1731 |
} |
|
1732 |
||
1733 |
void tst_QMenuBar::indexBasedInsertion() |
|
1734 |
{ |
|
1735 |
// test the compat'ed index based insertion |
|
1736 |
||
1737 |
QFETCH(int, indexForInsertion); |
|
1738 |
QFETCH(int, expectedIndex); |
|
1739 |
||
1740 |
{ |
|
1741 |
QMenuBar menu; |
|
1742 |
menu.addAction("Regular Item"); |
|
1743 |
||
1744 |
menu.insertItem("New Item", -1 /*id*/, indexForInsertion); |
|
1745 |
||
1746 |
QAction *act = menu.actions().value(expectedIndex); |
|
1747 |
QVERIFY(act); |
|
1748 |
QCOMPARE(act->text(), QString("New Item")); |
|
1749 |
} |
|
1750 |
{ |
|
1751 |
QMenuBar menu; |
|
1752 |
menu.addAction("Regular Item"); |
|
1753 |
||
1754 |
menu.insertSeparator(indexForInsertion); |
|
1755 |
||
1756 |
QAction *act = menu.actions().value(expectedIndex); |
|
1757 |
QVERIFY(act); |
|
1758 |
QVERIFY(act->isSeparator()); |
|
1759 |
} |
|
1760 |
} |
|
1761 |
#endif |
|
1762 |
||
1763 |
QTEST_MAIN(tst_QMenuBar) |
|
1764 |
#include "tst_qmenubar.moc" |