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 <QPushButton> |
|
46 |
#include <QMainWindow> |
|
47 |
#include <QMenuBar> |
|
48 |
#include <QToolBar> |
|
49 |
#include <QToolButton> |
|
50 |
#include <QStatusBar> |
|
51 |
#include <QListWidget> |
|
52 |
#include <QWidgetAction> |
|
53 |
#include <QDesktopWidget> |
|
54 |
||
55 |
#include <qmenu.h> |
|
56 |
#include <qstyle.h> |
|
57 |
#include <qdebug.h> |
|
58 |
||
59 |
#include "../../shared/util.h" |
|
60 |
||
61 |
//TESTED_CLASS= |
|
62 |
//TESTED_FILES= |
|
63 |
||
64 |
class tst_QMenu : public QObject |
|
65 |
{ |
|
66 |
Q_OBJECT |
|
67 |
||
68 |
public: |
|
69 |
tst_QMenu(); |
|
70 |
virtual ~tst_QMenu(); |
|
71 |
||
72 |
||
73 |
public slots: |
|
74 |
void initTestCase(); |
|
75 |
void cleanupTestCase(); |
|
76 |
void init(); |
|
77 |
void cleanup(); |
|
78 |
private slots: |
|
79 |
void getSetCheck(); |
|
80 |
void addActionsAndClear(); |
|
81 |
||
82 |
void keyboardNavigation_data(); |
|
83 |
void keyboardNavigation(); |
|
84 |
void focus(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
void overrideMenuAction(); |
0 | 86 |
void statusTip(); |
87 |
void widgetActionFocus(); |
|
88 |
void mouseActivation(); |
|
89 |
void tearOff(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
void layoutDirection(); |
0 | 91 |
|
92 |
#if defined(QT3_SUPPORT) |
|
93 |
void indexBasedInsertion_data(); |
|
94 |
void indexBasedInsertion(); |
|
95 |
#endif |
|
96 |
void task208001_stylesheet(); |
|
97 |
void activeSubMenuPosition(); |
|
98 |
void task242454_sizeHint(); |
|
99 |
void task176201_clear(); |
|
100 |
void task250673_activeMultiColumnSubMenuPosition(); |
|
101 |
void task256918_setFont(); |
|
102 |
void menuSizeHint(); |
|
103 |
void task258920_mouseBorder(); |
|
104 |
void setFixedWidth(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
105 |
void deleteActionInTriggered(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
106 |
void pushButtonPopulateOnAboutToShow(); |
0 | 107 |
protected slots: |
108 |
void onActivated(QAction*); |
|
109 |
void onHighlighted(QAction*); |
|
110 |
void onStatusMessageChanged(const QString &); |
|
111 |
void onStatusTipTimer(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
112 |
void deleteAction(QAction *a) { delete a; } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
113 |
void populateMenu(); |
0 | 114 |
private: |
115 |
void createActions(); |
|
116 |
QMenu *menus[2], *lastMenu; |
|
117 |
enum { num_builtins = 10 }; |
|
118 |
QAction *activated, *highlighted, *builtins[num_builtins]; |
|
119 |
QString statustip; |
|
120 |
}; |
|
121 |
||
122 |
// Testing get/set functions |
|
123 |
void tst_QMenu::getSetCheck() |
|
124 |
{ |
|
125 |
QMenu obj1; |
|
126 |
// QAction * QMenu::defaultAction() |
|
127 |
// void QMenu::setDefaultAction(QAction *) |
|
128 |
QAction *var1 = new QAction(0); |
|
129 |
obj1.setDefaultAction(var1); |
|
130 |
QCOMPARE(var1, obj1.defaultAction()); |
|
131 |
obj1.setDefaultAction((QAction *)0); |
|
132 |
QCOMPARE((QAction *)0, obj1.defaultAction()); |
|
133 |
delete var1; |
|
134 |
||
135 |
// QAction * QMenu::activeAction() |
|
136 |
// void QMenu::setActiveAction(QAction *) |
|
137 |
QAction *var2 = new QAction(0); |
|
138 |
obj1.setActiveAction(var2); |
|
139 |
QCOMPARE(var2, obj1.activeAction()); |
|
140 |
obj1.setActiveAction((QAction *)0); |
|
141 |
QCOMPARE((QAction *)0, obj1.activeAction()); |
|
142 |
delete var2; |
|
143 |
} |
|
144 |
||
145 |
tst_QMenu::tst_QMenu() |
|
146 |
{ |
|
147 |
QApplication::setEffectEnabled(Qt::UI_AnimateMenu, false); |
|
148 |
} |
|
149 |
||
150 |
tst_QMenu::~tst_QMenu() |
|
151 |
{ |
|
152 |
||
153 |
} |
|
154 |
||
155 |
void |
|
156 |
tst_QMenu::initTestCase() |
|
157 |
{ |
|
158 |
for(int i = 0; i < num_builtins; i++) |
|
159 |
builtins[i] = 0; |
|
160 |
for(int i = 0; i < 2; i++) { |
|
161 |
menus[i] = new QMenu; |
|
162 |
QObject::connect(menus[i], SIGNAL(triggered(QAction*)), this, SLOT(onActivated(QAction*))); |
|
163 |
QObject::connect(menus[i], SIGNAL(hovered(QAction*)), this, SLOT(onHighlighted(QAction*))); |
|
164 |
} |
|
165 |
} |
|
166 |
||
167 |
void |
|
168 |
tst_QMenu::cleanupTestCase() |
|
169 |
{ |
|
170 |
for(int i = 0; i < 2; i++) |
|
171 |
menus[i]->clear(); |
|
172 |
for(int i = 0; i < num_builtins; i++) { |
|
173 |
bool menuAction = false; |
|
174 |
for (int j = 0; j < 2; ++j) |
|
175 |
if (menus[j]->menuAction() == builtins[i]) |
|
176 |
menuAction = true; |
|
177 |
if (!menuAction) |
|
178 |
delete builtins[i]; |
|
179 |
} |
|
180 |
delete menus[0]; |
|
181 |
delete menus[1]; |
|
182 |
} |
|
183 |
||
184 |
void |
|
185 |
tst_QMenu::init() |
|
186 |
{ |
|
187 |
activated = highlighted = 0; |
|
188 |
lastMenu = 0; |
|
189 |
} |
|
190 |
||
191 |
void |
|
192 |
tst_QMenu::cleanup() |
|
193 |
{ |
|
194 |
} |
|
195 |
||
196 |
void |
|
197 |
tst_QMenu::createActions() |
|
198 |
{ |
|
199 |
if(!builtins[0]) |
|
200 |
builtins[0] = new QAction("New", 0); |
|
201 |
menus[0]->addAction(builtins[0]); |
|
202 |
||
203 |
if(!builtins[1]) { |
|
204 |
builtins[1] = new QAction(0); |
|
205 |
builtins[1]->setSeparator(true); |
|
206 |
} |
|
207 |
menus[0]->addAction(builtins[1]); |
|
208 |
||
209 |
if(!builtins[2]) { |
|
210 |
builtins[2] = menus[1]->menuAction(); |
|
211 |
builtins[2]->setText("&Open.."); |
|
212 |
builtins[8] = new QAction("Close", 0); |
|
213 |
menus[1]->addAction(builtins[8]); |
|
214 |
builtins[9] = new QAction("Quit", 0); |
|
215 |
menus[1]->addAction(builtins[9]); |
|
216 |
} |
|
217 |
menus[0]->addAction(builtins[2]); |
|
218 |
||
219 |
if(!builtins[3]) |
|
220 |
builtins[3] = new QAction("Open &as..", 0); |
|
221 |
menus[0]->addAction(builtins[3]); |
|
222 |
||
223 |
if(!builtins[4]) { |
|
224 |
builtins[4] = new QAction("Save", 0); |
|
225 |
builtins[4]->setEnabled(false); |
|
226 |
} |
|
227 |
menus[0]->addAction(builtins[4]); |
|
228 |
||
229 |
if(!builtins[5]) |
|
230 |
builtins[5] = new QAction("Sa&ve as..", 0); |
|
231 |
menus[0]->addAction(builtins[5]); |
|
232 |
||
233 |
if(!builtins[6]) { |
|
234 |
builtins[6] = new QAction(0); |
|
235 |
builtins[6]->setSeparator(true); |
|
236 |
} |
|
237 |
menus[0]->addAction(builtins[6]); |
|
238 |
||
239 |
if(!builtins[7]) |
|
240 |
builtins[7] = new QAction("Prin&t", 0); |
|
241 |
menus[0]->addAction(builtins[7]); |
|
242 |
} |
|
243 |
||
244 |
void |
|
245 |
tst_QMenu::onHighlighted(QAction *action) |
|
246 |
{ |
|
247 |
highlighted = action; |
|
248 |
lastMenu = qobject_cast<QMenu*>(sender()); |
|
249 |
} |
|
250 |
||
251 |
void |
|
252 |
tst_QMenu::onActivated(QAction *action) |
|
253 |
{ |
|
254 |
activated = action; |
|
255 |
lastMenu = qobject_cast<QMenu*>(sender()); |
|
256 |
} |
|
257 |
||
258 |
void tst_QMenu::onStatusMessageChanged(const QString &s) |
|
259 |
{ |
|
260 |
statustip=s; |
|
261 |
} |
|
262 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
263 |
void tst_QMenu::populateMenu(){ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
264 |
//just adds 3 dummy actions and a separator. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
265 |
lastMenu->addAction("Foo"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
266 |
lastMenu->addAction("Bar"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
267 |
lastMenu->addAction("FooBar"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
lastMenu->addSeparator(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
269 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
270 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
271 |
|
0 | 272 |
|
273 |
//actual tests |
|
274 |
void |
|
275 |
tst_QMenu::addActionsAndClear() |
|
276 |
{ |
|
277 |
#ifdef QT_SOFTKEYS_ENABLED |
|
278 |
// Softkeys add extra "Select" and "Back" actions to menu by default. |
|
279 |
// Two first actions will be Select and Back when softkeys are enabled |
|
280 |
int numSoftkeyActions = 2; |
|
281 |
#else |
|
282 |
int numSoftkeyActions = 0; |
|
283 |
#endif |
|
284 |
||
285 |
QCOMPARE(menus[0]->actions().count(), 0 + numSoftkeyActions); |
|
286 |
createActions(); |
|
287 |
QCOMPARE(menus[0]->actions().count(), 8 + numSoftkeyActions); |
|
288 |
menus[0]->clear(); |
|
289 |
QCOMPARE(menus[0]->actions().count(), 0); |
|
290 |
} |
|
291 |
||
292 |
void tst_QMenu::mouseActivation() |
|
293 |
{ |
|
294 |
#ifdef Q_OS_WINCE_WM |
|
295 |
QSKIP("We have a separate mouseActivation test for Windows mobile.", SkipAll); |
|
296 |
#endif |
|
297 |
QMenu menu; |
|
298 |
menu.addAction("Menu Action"); |
|
299 |
menu.show(); |
|
300 |
QTest::mouseClick(&menu, Qt::LeftButton, 0, QPoint(5, 5), 300); |
|
301 |
QVERIFY(!menu.isVisible()); |
|
302 |
||
303 |
//context menus can allways be accessed with right click except on windows |
|
304 |
menu.show(); |
|
305 |
QTest::mouseClick(&menu, Qt::RightButton, 0, QPoint(5, 5), 300); |
|
306 |
QVERIFY(!menu.isVisible()); |
|
307 |
||
308 |
#ifdef Q_OS_WIN |
|
309 |
//on windows normal mainwindow menus Can only be accessed with left mouse button |
|
310 |
QMenuBar menubar; |
|
311 |
QMenu submenu("Menu"); |
|
312 |
submenu.addAction("action"); |
|
313 |
QAction *action = menubar.addMenu(&submenu); |
|
314 |
menubar.show(); |
|
315 |
||
316 |
QTest::mouseClick(&menubar, Qt::LeftButton, 0, menubar.actionGeometry(action).center(), 300); |
|
317 |
QVERIFY(submenu.isVisible()); |
|
318 |
QTest::mouseClick(&submenu, Qt::LeftButton, 0, QPoint(5, 5), 300); |
|
319 |
QVERIFY(!submenu.isVisible()); |
|
320 |
||
321 |
QTest::mouseClick(&menubar, Qt::LeftButton, 0, menubar.actionGeometry(action).center(), 300); |
|
322 |
QVERIFY(submenu.isVisible()); |
|
323 |
QTest::mouseClick(&submenu, Qt::RightButton, 0, QPoint(5, 5), 300); |
|
324 |
QVERIFY(submenu.isVisible()); |
|
325 |
#endif |
|
326 |
} |
|
327 |
||
328 |
||
329 |
void |
|
330 |
tst_QMenu::keyboardNavigation_data() |
|
331 |
{ |
|
332 |
QTest::addColumn<int>("key"); |
|
333 |
QTest::addColumn<int>("expected_action"); |
|
334 |
QTest::addColumn<int>("expected_menu"); |
|
335 |
QTest::addColumn<bool>("init"); |
|
336 |
QTest::addColumn<bool>("expected_activated"); |
|
337 |
QTest::addColumn<bool>("expected_highlighted"); |
|
338 |
||
339 |
//test up and down (order is important here) |
|
340 |
QTest::newRow("data0") << int(Qt::Key_Down) << 0 << 0 << true << false << true; |
|
341 |
QTest::newRow("data1") << int(Qt::Key_Down) << 2 << 0 << false << false << true; //skips the separator |
|
342 |
QTest::newRow("data2") << int(Qt::Key_Down) << 3 << 0 << false << false << true; |
|
343 |
||
344 |
if (QApplication::style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled)) |
|
345 |
QTest::newRow("data3_noMac") << int(Qt::Key_Down) << 4 << 0 << false << false << true; |
|
346 |
else |
|
347 |
QTest::newRow("data3_Mac") << int(Qt::Key_Down) << 5 << 0 << false << false << true; |
|
348 |
QTest::newRow("data4") << int(Qt::Key_Up) << 3 << 0 << false << false << true; |
|
349 |
QTest::newRow("data5") << int(Qt::Key_Up) << 2 << 0 << false << false << true; |
|
350 |
QTest::newRow("data6") << int(Qt::Key_Right) << 8 << 1 << false << false << true; |
|
351 |
QTest::newRow("data7") << int(Qt::Key_Down) << 9 << 1 << false << false << true; |
|
352 |
QTest::newRow("data8") << int(Qt::Key_Escape) << 2 << 0 << false << false << false; |
|
353 |
QTest::newRow("data9") << int(Qt::Key_Down) << 3 << 0 << false << false<< true; |
|
354 |
QTest::newRow("data10") << int(Qt::Key_Return) << 3 << 0 << false << true << false; |
|
355 |
||
356 |
//test shortcuts |
|
357 |
#if 0 |
|
358 |
QTest::newRow("shortcut0") << (Qt::ALT | Qt::Key_A) << 2 << 0 << true << true << false; |
|
359 |
#endif |
|
360 |
} |
|
361 |
||
362 |
void |
|
363 |
tst_QMenu::keyboardNavigation() |
|
364 |
{ |
|
365 |
DEPENDS_ON( "addActionsAndClear" ); //if add/clear fails... |
|
366 |
QFETCH(int, key); |
|
367 |
QFETCH(int, expected_action); |
|
368 |
QFETCH(int, expected_menu); |
|
369 |
QFETCH(bool, init); |
|
370 |
QFETCH(bool, expected_activated); |
|
371 |
QFETCH(bool, expected_highlighted); |
|
372 |
||
373 |
if(init) { |
|
374 |
lastMenu = menus[0]; |
|
375 |
lastMenu->clear(); |
|
376 |
createActions(); |
|
377 |
lastMenu->popup(QPoint(0, 0)); |
|
378 |
} |
|
379 |
||
380 |
QTest::keyClick(lastMenu, (Qt::Key)key); |
|
381 |
if(expected_activated) { |
|
382 |
QCOMPARE(activated, builtins[expected_action]); |
|
383 |
QCOMPARE(menus[expected_menu]->activeAction(), (QAction *)0); |
|
384 |
} else { |
|
385 |
QCOMPARE(menus[expected_menu]->activeAction(), builtins[expected_action]); |
|
386 |
if(expected_highlighted) |
|
387 |
QCOMPARE(menus[expected_menu]->activeAction(), highlighted); |
|
388 |
} |
|
389 |
} |
|
390 |
||
391 |
||
392 |
#ifdef Q_WS_MAC |
|
393 |
QT_BEGIN_NAMESPACE |
|
394 |
extern bool qt_tab_all_widgets; // qapplication_mac.cpp |
|
395 |
QT_END_NAMESPACE |
|
396 |
#endif |
|
397 |
||
398 |
void tst_QMenu::focus() |
|
399 |
{ |
|
400 |
QMenu menu; |
|
401 |
menu.addAction("One"); |
|
402 |
menu.addAction("Two"); |
|
403 |
menu.addAction("Three"); |
|
404 |
bool fullKeyboardControl = true; |
|
405 |
||
406 |
#ifdef Q_WS_MAC |
|
407 |
fullKeyboardControl = qt_tab_all_widgets; |
|
408 |
#endif |
|
409 |
||
410 |
if (!fullKeyboardControl) |
|
411 |
QSKIP("Computer is currently set up to NOT tab to all widgets," |
|
412 |
" this test assumes you can tab to all widgets", SkipAll); |
|
413 |
||
414 |
QWidget window; |
|
415 |
QPushButton button("Push me", &window); |
|
416 |
window.show(); |
|
417 |
qApp->setActiveWindow(&window); |
|
418 |
||
419 |
QVERIFY(button.hasFocus()); |
|
420 |
QCOMPARE(QApplication::focusWidget(), (QWidget *)&button); |
|
421 |
QCOMPARE(QApplication::activeWindow(), &window); |
|
422 |
menu.show(); |
|
423 |
#if 0 |
|
424 |
QVERIFY(!button.hasFocus()); |
|
425 |
QCOMPARE(QApplication::focusWidget(), &menu); |
|
426 |
QCOMPARE(QApplication::activeWindow(), &window); |
|
427 |
#else |
|
428 |
QVERIFY(button.hasFocus()); |
|
429 |
QCOMPARE(QApplication::focusWidget(), (QWidget *)&button); |
|
430 |
QCOMPARE(QApplication::activeWindow(), &window); |
|
431 |
#endif |
|
432 |
menu.hide(); |
|
433 |
QVERIFY(button.hasFocus()); |
|
434 |
QCOMPARE(QApplication::focusWidget(), (QWidget *)&button); |
|
435 |
QCOMPARE(QApplication::activeWindow(), &window); |
|
436 |
} |
|
437 |
||
438 |
void tst_QMenu::overrideMenuAction() |
|
439 |
{ |
|
440 |
//test the override menu action by first creating an action to which we set its menu |
|
441 |
QMainWindow w; |
|
442 |
||
443 |
QAction *aFileMenu = new QAction("&File", &w); |
|
444 |
w.menuBar()->addAction(aFileMenu); |
|
445 |
||
446 |
QMenu *m = new QMenu(&w); |
|
447 |
QAction *menuaction = m->menuAction(); |
|
448 |
connect(m, SIGNAL(triggered(QAction*)), SLOT(onActivated(QAction*))); |
|
449 |
aFileMenu->setMenu(m); //this sets the override menu action for the QMenu |
|
450 |
QCOMPARE(m->menuAction(), aFileMenu); |
|
451 |
||
452 |
#ifdef Q_WS_MAC |
|
453 |
QSKIP("On Mac, we need to create native key events to test menu action activation", SkipAll); |
|
454 |
#elif defined(Q_OS_WINCE) |
|
455 |
QSKIP("On Windows CE, we need to create native key events to test menu action activation", SkipAll); |
|
456 |
#elif defined(Q_OS_SYMBIAN) |
|
457 |
QSKIP("On Symbian OS, we need to create native key events to test menu action activation", SkipAll); |
|
458 |
#endif |
|
459 |
||
460 |
QAction *aQuit = new QAction("Quit", &w); |
|
461 |
aQuit->setShortcut(QKeySequence("Ctrl+X")); |
|
462 |
m->addAction(aQuit); |
|
463 |
||
464 |
w.show(); |
|
465 |
QApplication::setActiveWindow(&w); |
|
466 |
w.setFocus(); |
|
467 |
QTest::qWaitForWindowShown(&w); |
|
468 |
QTRY_VERIFY(w.hasFocus()); |
|
469 |
||
470 |
//test of the action inside the menu |
|
471 |
QTest::keyClick(&w, Qt::Key_X, Qt::ControlModifier); |
|
472 |
QTRY_COMPARE(activated, aQuit); |
|
473 |
||
474 |
//test if the menu still pops out |
|
475 |
QTest::keyClick(&w, Qt::Key_F, Qt::AltModifier); |
|
476 |
QTRY_VERIFY(m->isVisible()); |
|
477 |
||
478 |
delete aFileMenu; |
|
479 |
||
480 |
//after the deletion of the override menu action, |
|
481 |
//the menu should have its default menu action back |
|
482 |
QCOMPARE(m->menuAction(), menuaction); |
|
483 |
||
484 |
} |
|
485 |
||
486 |
void tst_QMenu::statusTip() |
|
487 |
{ |
|
488 |
//check that the statustip of actions inserted into the menu are displayed |
|
489 |
QMainWindow w; |
|
490 |
connect(w.statusBar(), SIGNAL(messageChanged(const QString &)), SLOT(onStatusMessageChanged(const QString &)));; //creates the status bar |
|
491 |
QToolBar tb; |
|
492 |
QAction a("main action", &tb); |
|
493 |
a.setStatusTip("main action"); |
|
494 |
QMenu m(&tb); |
|
495 |
QAction subact("sub action", &m); |
|
496 |
subact.setStatusTip("sub action"); |
|
497 |
m.addAction(&subact); |
|
498 |
a.setMenu(&m); |
|
499 |
tb.addAction(&a); |
|
500 |
||
501 |
w.addToolBar(&tb); |
|
502 |
w.show(); |
|
503 |
||
504 |
QRect rect1 = tb.actionGeometry(&a); |
|
505 |
QToolButton *btn = qobject_cast<QToolButton*>(tb.childAt(rect1.center())); |
|
506 |
||
507 |
QVERIFY(btn != NULL); |
|
508 |
||
509 |
//because showMenu calls QMenu::exec, we need to use a singleshot |
|
510 |
//to continue the test |
|
511 |
QTimer::singleShot(200,this, SLOT(onStatusTipTimer())); |
|
512 |
btn->showMenu(); |
|
513 |
QVERIFY(statustip.isEmpty()); |
|
514 |
} |
|
515 |
||
516 |
//2nd part of the test |
|
517 |
void tst_QMenu::onStatusTipTimer() |
|
518 |
{ |
|
519 |
QMenu *menu = qobject_cast<QMenu*>(QApplication::activePopupWidget()); |
|
520 |
QVERIFY(menu != 0); |
|
521 |
QVERIFY(menu->isVisible()); |
|
522 |
QTest::keyClick(menu, Qt::Key_Down); |
|
523 |
||
524 |
//we store the statustip to press escape in any case |
|
525 |
//otherwise, if the test fails it blocks (never gets out of QMenu::exec |
|
526 |
const QString st=statustip; |
|
527 |
||
528 |
menu->close(); //goes out of the menu |
|
529 |
||
530 |
QCOMPARE(st, QString("sub action")); |
|
531 |
QVERIFY(menu->isVisible() == false); |
|
532 |
} |
|
533 |
||
534 |
void tst_QMenu::widgetActionFocus() |
|
535 |
{ |
|
536 |
//test if the focus is correctly handled with a QWidgetAction |
|
537 |
QMenu m; |
|
538 |
QListWidget *l = new QListWidget(&m); |
|
539 |
for(int i = 1; i<3 ; i++) |
|
540 |
l->addItem(QString("item%1").arg(i)); |
|
541 |
QWidgetAction *wa = new QWidgetAction(&m); |
|
542 |
wa->setDefaultWidget(l); |
|
543 |
m.addAction(wa); |
|
544 |
m.setActiveAction(wa); |
|
545 |
l->setFocus(); //to ensure it has primarily the focus |
|
546 |
QAction *menuitem1=m.addAction("menuitem1"); |
|
547 |
QAction *menuitem2=m.addAction("menuitem2"); |
|
548 |
||
549 |
m.popup(QPoint()); |
|
550 |
||
551 |
QVERIFY(m.isVisible()); |
|
552 |
QVERIFY(l->hasFocus()); |
|
553 |
QVERIFY(l->currentItem()); |
|
554 |
QCOMPARE(l->currentItem()->text(), QString("item1")); |
|
555 |
||
556 |
QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down); |
|
557 |
QVERIFY(l->currentItem()); |
|
558 |
QCOMPARE(l->currentItem()->text(), QString("item2")); |
|
559 |
||
560 |
QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down); |
|
561 |
QVERIFY(m.hasFocus()); |
|
562 |
QCOMPARE(m.activeAction(), menuitem1); |
|
563 |
||
564 |
QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down); |
|
565 |
QVERIFY(m.hasFocus()); |
|
566 |
QCOMPARE(m.activeAction(), menuitem2); |
|
567 |
||
568 |
QTest::keyClick(QApplication::focusWidget(), Qt::Key_Up); |
|
569 |
QVERIFY(m.hasFocus()); |
|
570 |
QCOMPARE(m.activeAction(), menuitem1); |
|
571 |
||
572 |
QTest::keyClick(QApplication::focusWidget(), Qt::Key_Up); |
|
573 |
QVERIFY(l->hasFocus()); |
|
574 |
QCOMPARE(m.activeAction(), (QAction *)wa); |
|
575 |
} |
|
576 |
||
577 |
void tst_QMenu::tearOff() |
|
578 |
{ |
|
579 |
QWidget widget; |
|
580 |
QMenu *menu = new QMenu(&widget); |
|
581 |
QVERIFY(!menu->isTearOffEnabled()); //default value |
|
582 |
menu->setTearOffEnabled(true); |
|
583 |
menu->addAction("aaa"); |
|
584 |
menu->addAction("bbb"); |
|
585 |
QVERIFY(menu->isTearOffEnabled()); |
|
586 |
||
587 |
widget.show(); |
|
588 |
menu->popup(QPoint(0,0)); |
|
589 |
QTest::qWait(50); |
|
590 |
QVERIFY(!menu->isTearOffMenuVisible()); |
|
591 |
||
592 |
QTest::mouseClick(menu, Qt::LeftButton, 0, QPoint(3, 3), 10); |
|
593 |
QTest::qWait(100); |
|
594 |
||
595 |
QVERIFY(menu->isTearOffMenuVisible()); |
|
596 |
QPointer<QMenu> torn = 0; |
|
597 |
foreach (QWidget *w, QApplication::allWidgets()) { |
|
598 |
if (w->inherits("QTornOffMenu")) { |
|
599 |
torn = static_cast<QMenu *>(w); |
|
600 |
break; |
|
601 |
} |
|
602 |
} |
|
603 |
QVERIFY(torn); |
|
604 |
QVERIFY(torn->isVisible()); |
|
605 |
||
606 |
menu->hideTearOffMenu(); |
|
607 |
QVERIFY(!menu->isTearOffMenuVisible()); |
|
608 |
QVERIFY(!torn->isVisible()); |
|
609 |
} |
|
610 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
611 |
void tst_QMenu::layoutDirection() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
612 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
613 |
QMainWindow win; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
614 |
win.setLayoutDirection(Qt::RightToLeft); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
615 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
616 |
QMenu menu(&win); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
617 |
menu.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
618 |
QTest::qWaitForWindowShown(&menu); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
619 |
QCOMPARE(menu.layoutDirection(), Qt::RightToLeft); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
620 |
menu.close(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
621 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
622 |
menu.setParent(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
623 |
menu.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
624 |
QTest::qWaitForWindowShown(&menu); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
625 |
QCOMPARE(menu.layoutDirection(), QApplication::layoutDirection()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
626 |
menu.close(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
627 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
628 |
//now the menubar |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
629 |
QAction *action = win.menuBar()->addMenu(&menu); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
630 |
win.menuBar()->setActiveAction(action); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
631 |
QTest::qWaitForWindowShown(&menu); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
632 |
QCOMPARE(menu.layoutDirection(), Qt::RightToLeft); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
633 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
634 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
635 |
|
0 | 636 |
|
637 |
#if defined(QT3_SUPPORT) |
|
638 |
void tst_QMenu::indexBasedInsertion_data() |
|
639 |
{ |
|
640 |
QTest::addColumn<int>("indexForInsertion"); |
|
641 |
QTest::addColumn<int>("expectedIndex"); |
|
642 |
||
643 |
QTest::newRow("negative-index-appends") << -1 << 1; |
|
644 |
QTest::newRow("prepend") << 0 << 0; |
|
645 |
QTest::newRow("append") << 1 << 1; |
|
646 |
} |
|
647 |
||
648 |
void tst_QMenu::indexBasedInsertion() |
|
649 |
{ |
|
650 |
// test the compat'ed index based insertion |
|
651 |
||
652 |
QFETCH(int, indexForInsertion); |
|
653 |
QFETCH(int, expectedIndex); |
|
654 |
||
655 |
{ |
|
656 |
QMenu menu; |
|
657 |
menu.addAction("Regular Item"); |
|
658 |
||
659 |
menu.insertItem("New Item", -1 /*id*/, indexForInsertion); |
|
660 |
||
661 |
QAction *act = menu.actions().value(expectedIndex); |
|
662 |
QVERIFY(act); |
|
663 |
QCOMPARE(act->text(), QString("New Item")); |
|
664 |
} |
|
665 |
{ |
|
666 |
QMenu menu; |
|
667 |
menu.addAction("Regular Item"); |
|
668 |
||
669 |
menu.insertSeparator(indexForInsertion); |
|
670 |
||
671 |
QAction *act = menu.actions().value(expectedIndex); |
|
672 |
QVERIFY(act); |
|
673 |
QVERIFY(act->isSeparator()); |
|
674 |
} |
|
675 |
} |
|
676 |
#endif |
|
677 |
||
678 |
void tst_QMenu::task208001_stylesheet() |
|
679 |
{ |
|
680 |
//test if it crash |
|
681 |
QMainWindow main; |
|
682 |
main.setStyleSheet("QMenu [title =\"File\"] { color: red;}"); |
|
683 |
main.menuBar()->addMenu("File"); |
|
684 |
} |
|
685 |
||
686 |
void tst_QMenu::activeSubMenuPosition() |
|
687 |
{ |
|
688 |
QPushButton lab("subMenuPosition test"); |
|
689 |
||
690 |
QMenu *sub = new QMenu("Submenu", &lab); |
|
691 |
sub->addAction("Sub-Item1"); |
|
692 |
QAction *subAction = sub->addAction("Sub-Item2"); |
|
693 |
||
694 |
QMenu *main = new QMenu("Menu-Title", &lab); |
|
695 |
(void)main->addAction("Item 1"); |
|
696 |
QAction *menuAction = main->addMenu(sub); |
|
697 |
(void)main->addAction("Item 3"); |
|
698 |
(void)main->addAction("Item 4"); |
|
699 |
||
700 |
main->setActiveAction(menuAction); |
|
701 |
sub->setActiveAction(subAction); |
|
702 |
#ifdef Q_OS_SYMBIAN |
|
703 |
main->popup(QPoint(50,200)); |
|
704 |
#else |
|
705 |
main->popup(QPoint(200,200)); |
|
706 |
#endif |
|
707 |
||
708 |
QVERIFY(main->isVisible()); |
|
709 |
QCOMPARE(main->activeAction(), menuAction); |
|
710 |
QVERIFY(sub->isVisible()); |
|
711 |
QVERIFY(sub->pos() != QPoint(0,0)); |
|
712 |
// well, it's enough to check the pos is not (0,0) but it's more safe |
|
713 |
// to check that submenu is to the right of the main menu too. |
|
714 |
#ifdef Q_OS_WINCE_WM |
|
715 |
QSKIP("Not true for Windows Mobile Soft Keys", SkipSingle); |
|
716 |
#endif |
|
717 |
||
718 |
#ifdef Q_OS_SYMBIAN |
|
719 |
// On Symbian, QS60Style::pixelMetric(QStyle::PM_SubMenuOverlap) is different with other styles. |
|
720 |
QVERIFY(sub->pos().x() < main->pos().x()); |
|
721 |
#else |
|
722 |
QVERIFY(sub->pos().x() > main->pos().x()); |
|
723 |
#endif |
|
724 |
QCOMPARE(sub->activeAction(), subAction); |
|
725 |
} |
|
726 |
||
727 |
void tst_QMenu::task242454_sizeHint() |
|
728 |
{ |
|
729 |
QMenu menu; |
|
730 |
QString s = QLatin1String("foo\nfoo\nfoo\nfoo"); |
|
731 |
menu.addAction(s); |
|
732 |
QVERIFY(menu.sizeHint().width() > menu.fontMetrics().boundingRect(QRect(), Qt::TextSingleLine, s).width()); |
|
733 |
} |
|
734 |
||
735 |
||
736 |
class Menu : public QMenu |
|
737 |
{ |
|
738 |
Q_OBJECT |
|
739 |
public slots: |
|
740 |
void clear() |
|
741 |
{ |
|
742 |
QMenu::clear(); |
|
743 |
} |
|
744 |
}; |
|
745 |
||
746 |
void tst_QMenu::task176201_clear() |
|
747 |
{ |
|
748 |
//this test used to crash |
|
749 |
Menu menu; |
|
750 |
QAction *action = menu.addAction("test"); |
|
751 |
menu.connect(action, SIGNAL(triggered()), SLOT(clear())); |
|
752 |
menu.popup(QPoint()); |
|
753 |
QTest::mouseClick(&menu, Qt::LeftButton, 0, menu.rect().center()); |
|
754 |
} |
|
755 |
||
756 |
void tst_QMenu::task250673_activeMultiColumnSubMenuPosition() |
|
757 |
{ |
|
758 |
class MyMenu : public QMenu |
|
759 |
{ |
|
760 |
public: |
|
761 |
int columnCount() const { return QMenu::columnCount(); } |
|
762 |
}; |
|
763 |
||
764 |
QMenu sub; |
|
765 |
||
766 |
if (sub.style()->styleHint(QStyle::SH_Menu_Scrollable, 0, &sub)) { |
|
767 |
//the style prevents the menus from getting columns |
|
768 |
QSKIP("the style doesn't support multiple columns, it makes the menu scrollable", SkipSingle); |
|
769 |
} |
|
770 |
||
771 |
sub.addAction("Sub-Item1"); |
|
772 |
QAction *subAction = sub.addAction("Sub-Item2"); |
|
773 |
||
774 |
MyMenu main; |
|
775 |
main.addAction("Item 1"); |
|
776 |
QAction *menuAction = main.addMenu(&sub); |
|
777 |
main.popup(QPoint(200,200)); |
|
778 |
||
779 |
uint i = 2; |
|
780 |
while (main.columnCount() < 2) { |
|
781 |
main.addAction(QString("Item %1").arg(i)); |
|
782 |
++i; |
|
783 |
Q_ASSERT(i<1000); |
|
784 |
} |
|
785 |
main.setActiveAction(menuAction); |
|
786 |
sub.setActiveAction(subAction); |
|
787 |
||
788 |
QVERIFY(main.isVisible()); |
|
789 |
QCOMPARE(main.activeAction(), menuAction); |
|
790 |
QVERIFY(sub.isVisible()); |
|
791 |
QVERIFY(sub.pos().x() > main.pos().x()); |
|
792 |
||
793 |
const int subMenuOffset = main.style()->pixelMetric(QStyle::PM_SubMenuOverlap, 0, &main); |
|
794 |
QVERIFY((sub.geometry().left() - subMenuOffset + 5) < main.geometry().right()); |
|
795 |
} |
|
796 |
||
797 |
||
798 |
void tst_QMenu::task256918_setFont() |
|
799 |
{ |
|
800 |
QMenu menu; |
|
801 |
QAction *action = menu.addAction("foo"); |
|
802 |
QFont f; |
|
803 |
f.setPointSize(30); |
|
804 |
action->setFont(f); |
|
805 |
menu.show(); //ensures that the actiongeometry are calculated |
|
806 |
QVERIFY(menu.actionGeometry(action).height() > f.pointSize()); |
|
807 |
} |
|
808 |
||
809 |
void tst_QMenu::menuSizeHint() |
|
810 |
{ |
|
811 |
QMenu menu; |
|
812 |
//this is a list of arbitrary strings so that we check the geometry |
|
813 |
QStringList list = QStringList() << "trer" << "ezrfgtgvqd" << "sdgzgzerzerzer" << "eerzertz" << "er"; |
|
814 |
foreach(QString str, list) |
|
815 |
menu.addAction(str); |
|
816 |
||
817 |
int left, top, right, bottom; |
|
818 |
menu.getContentsMargins(&left, &top, &right, &bottom); |
|
819 |
const int panelWidth = menu.style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, &menu); |
|
820 |
const int hmargin = menu.style()->pixelMetric(QStyle::PM_MenuHMargin, 0, &menu), |
|
821 |
vmargin = menu.style()->pixelMetric(QStyle::PM_MenuVMargin, 0, &menu); |
|
822 |
||
823 |
int maxWidth =0; |
|
824 |
QRect result; |
|
825 |
foreach(QAction *action, menu.actions()) { |
|
826 |
#ifdef QT_SOFTKEYS_ENABLED |
|
827 |
// Softkey actions are not widgets and have no geometry. |
|
828 |
if (menu.actionGeometry(action).topLeft() == QPoint(0,0)) |
|
829 |
continue; |
|
830 |
#endif |
|
831 |
maxWidth = qMax(maxWidth, menu.actionGeometry(action).width()); |
|
832 |
result |= menu.actionGeometry(action); |
|
833 |
QCOMPARE(result.x(), left + hmargin + panelWidth); |
|
834 |
QCOMPARE(result.y(), top + vmargin + panelWidth); |
|
835 |
} |
|
836 |
||
837 |
QStyleOption opt(0); |
|
838 |
opt.rect = menu.rect(); |
|
839 |
opt.state = QStyle::State_None; |
|
840 |
||
841 |
QSize resSize = QSize(result.x(), result.y()) + result.size() + QSize(hmargin + right + panelWidth, vmargin + top + panelWidth); |
|
842 |
||
843 |
resSize = menu.style()->sizeFromContents(QStyle::CT_Menu, &opt, |
|
844 |
resSize.expandedTo(QApplication::globalStrut()), &menu); |
|
845 |
||
846 |
QCOMPARE(resSize, menu.sizeHint()); |
|
847 |
} |
|
848 |
||
849 |
class Menu258920 : public QMenu |
|
850 |
{ |
|
851 |
Q_OBJECT |
|
852 |
public slots: |
|
853 |
void paintEvent(QPaintEvent *e) |
|
854 |
{ |
|
855 |
QMenu::paintEvent(e); |
|
856 |
painted = true; |
|
857 |
} |
|
858 |
||
859 |
public: |
|
860 |
bool painted; |
|
861 |
}; |
|
862 |
||
863 |
void tst_QMenu::task258920_mouseBorder() |
|
864 |
{ |
|
865 |
#ifdef Q_OS_WINCE_WM |
|
866 |
QSKIP("Mouse move related signals for Windows Mobile unavailable", SkipAll); |
|
867 |
#endif |
|
868 |
Menu258920 menu; |
|
869 |
// On Symbian, styleHint(QStyle::SH_Menu_MouseTracking) in QS60Style is false. |
|
870 |
// For other styles which inherit from QWindowsStyle, the value is true. |
|
871 |
menu.setMouseTracking(true); |
|
872 |
QAction *action = menu.addAction("test"); |
|
873 |
||
874 |
menu.popup(QApplication::desktop()->availableGeometry().center()); |
|
875 |
QTest::qWaitForWindowShown(&menu); |
|
876 |
QTest::qWait(100); |
|
877 |
QRect actionRect = menu.actionGeometry(action); |
|
878 |
QTest::mouseMove(&menu, actionRect.center()); |
|
879 |
QTest::qWait(30); |
|
880 |
QTest::mouseMove(&menu, actionRect.center() + QPoint(10, 0)); |
|
881 |
QTest::qWait(30); |
|
882 |
QCOMPARE(action, menu.activeAction()); |
|
883 |
menu.painted = false; |
|
884 |
QTest::mouseMove(&menu, QPoint(actionRect.center().x(), actionRect.bottom() + 1)); |
|
885 |
QTest::qWait(30); |
|
886 |
QCOMPARE(static_cast<QAction*>(0), menu.activeAction()); |
|
887 |
QVERIFY(menu.painted); |
|
888 |
} |
|
889 |
||
890 |
void tst_QMenu::setFixedWidth() |
|
891 |
{ |
|
892 |
QMenu menu; |
|
893 |
menu.addAction("action"); |
|
894 |
menu.setFixedWidth(300); |
|
895 |
//the sizehint should reflect the minimumwidth because the action will try to |
|
896 |
//get as much space as possible |
|
897 |
QCOMPARE(menu.sizeHint().width(), menu.minimumWidth()); |
|
898 |
} |
|
899 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
900 |
void tst_QMenu::deleteActionInTriggered() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
901 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
902 |
// should not crash |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
903 |
QMenu m; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
904 |
QObject::connect(&m, SIGNAL(triggered(QAction*)), this, SLOT(deleteAction(QAction*))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
905 |
QWeakPointer<QAction> a = m.addAction("action"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
906 |
a.data()->trigger(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
907 |
QVERIFY(!a); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
908 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
909 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
910 |
void tst_QMenu::pushButtonPopulateOnAboutToShow() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
911 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
912 |
QPushButton b("Test PushButton"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
913 |
b.setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
914 |
lastMenu = new QMenu; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
915 |
b.setMenu(lastMenu); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
916 |
const int scrNumber = QApplication::desktop()->screenNumber(&b); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
917 |
connect(lastMenu, SIGNAL(aboutToShow()), this, SLOT(populateMenu())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
918 |
b.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
919 |
const QRect screen = QApplication::desktop()->screenGeometry(scrNumber); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
920 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
921 |
b.move(10, screen.bottom()-b.height()-5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
922 |
QTest::qWaitForWindowShown(&b); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
923 |
QTimer::singleShot(300,lastMenu, SLOT(hide())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
924 |
QTest::mouseClick(&b, Qt::LeftButton, Qt::NoModifier, b.rect().center()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
925 |
QVERIFY(!lastMenu->geometry().intersects(b.geometry())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
926 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
927 |
b.move(10, screen.bottom()-lastMenu->height()-5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
928 |
QTimer::singleShot(300,lastMenu, SLOT(hide())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
929 |
QTest::mouseClick(&b, Qt::LeftButton, Qt::NoModifier, b.rect().center()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
930 |
QVERIFY(!lastMenu->geometry().intersects(b.geometry())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
931 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
932 |
} |
0 | 933 |
|
934 |
||
935 |
QTEST_MAIN(tst_QMenu) |
|
936 |
#include "tst_qmenu.moc" |