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