153 void check_shortcutPress(); |
165 void check_shortcutPress(); |
154 void check_menuPosition(); |
166 void check_menuPosition(); |
155 void task223138_triggered(); |
167 void task223138_triggered(); |
156 void task256322_highlight(); |
168 void task256322_highlight(); |
157 void menubarSizeHint(); |
169 void menubarSizeHint(); |
158 |
170 void taskQTBUG4965_escapeEaten(); |
|
171 |
159 #if defined(QT3_SUPPORT) |
172 #if defined(QT3_SUPPORT) |
160 void indexBasedInsertion_data(); |
173 void indexBasedInsertion_data(); |
161 void indexBasedInsertion(); |
174 void indexBasedInsertion(); |
162 #endif |
175 #endif |
163 |
176 |
1345 |
1358 |
1346 // Task 241043 : check that second menu is activated if only |
1359 // Task 241043 : check that second menu is activated if only |
1347 // disabled menu items are added |
1360 // disabled menu items are added |
1348 |
1361 |
1349 QMenu fileMenu("&File"); |
1362 QMenu fileMenu("&File"); |
1350 // Task 241043 : check that second menu is activated |
1363 // Task 241043 : check that second menu is activated |
1351 // if all items are disabled |
1364 // if all items are disabled |
1352 QAction *act = fileMenu.addAction("Disabled"); |
1365 QAction *act = fileMenu.addAction("Disabled"); |
1353 act->setEnabled(false); |
1366 act->setEnabled(false); |
1354 |
1367 |
1355 mb->addMenu(&fileMenu); |
1368 mb->addMenu(&fileMenu); |
1373 QTest::keyClick(mb, (Qt::Key_Left)); |
1386 QTest::keyClick(mb, (Qt::Key_Left)); |
1374 if (qApp->style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled)) |
1387 if (qApp->style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled)) |
1375 QCOMPARE(mb->activeAction()->text(), fileMenu.title()); |
1388 QCOMPARE(mb->activeAction()->text(), fileMenu.title()); |
1376 else |
1389 else |
1377 QCOMPARE(mb->activeAction()->text(), fileMenu.title()); |
1390 QCOMPARE(mb->activeAction()->text(), fileMenu.title()); |
1378 |
1391 |
1379 mb->hide(); |
1392 mb->hide(); |
1380 #endif //Q_WS_MAC |
1393 #endif //Q_WS_MAC |
1381 } |
1394 } |
1382 |
1395 |
1383 void tst_QMenuBar::check_altPress() |
1396 void tst_QMenuBar::check_altPress() |
1440 QSKIP("Qt/Mac does not use the native popups/menubar", SkipAll); |
1453 QSKIP("Qt/Mac does not use the native popups/menubar", SkipAll); |
1441 #endif |
1454 #endif |
1442 #ifdef Q_OS_WINCE_WM |
1455 #ifdef Q_OS_WINCE_WM |
1443 QSKIP("Qt/CE uses native menubar", SkipAll); |
1456 QSKIP("Qt/CE uses native menubar", SkipAll); |
1444 #endif |
1457 #endif |
1445 QMenu menu; |
1458 Menu menu; |
1446 #ifdef QT3_SUPPORT |
1459 #ifdef QT3_SUPPORT |
1447 initComplexMenubar(); |
1460 initComplexMenubar(); |
1448 #else |
1461 #else |
1449 initComplexMenubar_noQt3(); |
1462 initComplexMenubar_noQt3(); |
1450 #endif |
1463 #endif |
1494 QPoint secondPoint = QPoint(mbItemRect.right()+1, availRect.bottom() - menu.height() + 1); |
1507 QPoint secondPoint = QPoint(mbItemRect.right()+1, availRect.bottom() - menu.height() + 1); |
1495 QVERIFY(menu.pos() == firstPoint || menu.pos() == secondPoint); |
1508 QVERIFY(menu.pos() == firstPoint || menu.pos() == secondPoint); |
1496 menu.close(); |
1509 menu.close(); |
1497 } |
1510 } |
1498 |
1511 |
|
1512 //in RTL, the menu should be stuck at the right of the action geometry |
|
1513 { |
|
1514 Qt::LayoutDirection dir = qApp->layoutDirection(); |
|
1515 qApp->setLayoutDirection(Qt::RightToLeft); |
|
1516 menu.clear(); |
|
1517 QObject::connect(&menu, SIGNAL(aboutToShow()), &menu, SLOT(addActions())); |
|
1518 QRect mbItemRect = mw->menuBar()->actionGeometry(menu_action); |
|
1519 mbItemRect.moveTo(mw->menuBar()->mapToGlobal(mbItemRect.topLeft())); |
|
1520 QTest::keyClick(mw, Qt::Key_M, Qt::AltModifier ); |
|
1521 QVERIFY(menu.isActiveWindow()); |
|
1522 QCOMPARE(menu.geometry().right(), mbItemRect.right()); |
|
1523 menu.close(); |
|
1524 qApp->setLayoutDirection(dir); |
|
1525 } |
|
1526 |
1499 } |
1527 } |
1500 |
1528 |
1501 void tst_QMenuBar::task223138_triggered() |
1529 void tst_QMenuBar::task223138_triggered() |
1502 { |
1530 { |
1503 qRegisterMetaType<QAction *>("QAction *"); |
1531 qRegisterMetaType<QAction *>("QAction *"); |
1573 struct MyStyle : public QWindowsStyle |
1601 struct MyStyle : public QWindowsStyle |
1574 { |
1602 { |
1575 virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const |
1603 virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const |
1576 { |
1604 { |
1577 // I chose strange values (prime numbers to be more sure that the size of the menubar is correct) |
1605 // I chose strange values (prime numbers to be more sure that the size of the menubar is correct) |
1578 switch (metric) |
1606 switch (metric) |
1579 { |
1607 { |
1580 case QStyle::PM_MenuBarItemSpacing: |
1608 case QStyle::PM_MenuBarItemSpacing: |
1581 return 7; |
1609 return 7; |
1582 case PM_MenuBarHMargin: |
1610 case PM_MenuBarHMargin: |
1583 return 13; |
1611 return 13; |
1591 } |
1619 } |
1592 } style; |
1620 } style; |
1593 |
1621 |
1594 QMenuBar mb; |
1622 QMenuBar mb; |
1595 mb.setNativeMenuBar(false); //we can't check the geometry of native menubars |
1623 mb.setNativeMenuBar(false); //we can't check the geometry of native menubars |
1596 |
1624 |
1597 mb.setStyle(&style); |
1625 mb.setStyle(&style); |
1598 //this is a list of arbitrary strings so that we check the geometry |
1626 //this is a list of arbitrary strings so that we check the geometry |
1599 QStringList list = QStringList() << "trer" << "ezrfgtgvqd" << "sdgzgzerzerzer" << "eerzertz" << "er"; |
1627 QStringList list = QStringList() << "trer" << "ezrfgtgvqd" << "sdgzgzerzerzer" << "eerzertz" << "er"; |
1600 foreach(QString str, list) |
1628 foreach(QString str, list) |
1601 mb.addAction(str); |
1629 mb.addAction(str); |
1635 &mb); |
1663 &mb); |
1636 |
1664 |
1637 QCOMPARE(resSize, mb.sizeHint()); |
1665 QCOMPARE(resSize, mb.sizeHint()); |
1638 } |
1666 } |
1639 |
1667 |
|
1668 void tst_QMenuBar::taskQTBUG4965_escapeEaten() |
|
1669 { |
|
1670 #ifdef Q_WS_MAC |
|
1671 QSKIP("On Mac, do not test the menubar with escape key", SkipAll); |
|
1672 #endif |
|
1673 QMenuBar menubar; |
|
1674 QMenu menu("menu1"); |
|
1675 QAction *first = menubar.addMenu(&menu); |
|
1676 menu.addAction("quit", &menubar, SLOT(close()), QKeySequence("ESC")); |
|
1677 menubar.show(); |
|
1678 QApplication::setActiveWindow(&menubar); |
|
1679 QTest::qWaitForWindowShown(&menubar); |
|
1680 menubar.setActiveAction(first); |
|
1681 QTRY_VERIFY(menu.isVisible()); |
|
1682 QCOMPARE(menubar.activeAction(), first); |
|
1683 QTest::keyClick(0, Qt::Key_Escape); |
|
1684 QVERIFY(!menu.isVisible()); |
|
1685 QTRY_VERIFY(menubar.hasFocus()); |
|
1686 QCOMPARE(menubar.activeAction(), first); |
|
1687 QTest::keyClick(0, Qt::Key_Escape); |
|
1688 QVERIFY(!menubar.activeAction()); |
|
1689 QTest::keyClick(0, Qt::Key_Escape); //now the action should be triggered |
|
1690 QTRY_VERIFY(!menubar.isVisible()); |
|
1691 } |
1640 |
1692 |
1641 #if defined(QT3_SUPPORT) |
1693 #if defined(QT3_SUPPORT) |
1642 void tst_QMenuBar::indexBasedInsertion_data() |
1694 void tst_QMenuBar::indexBasedInsertion_data() |
1643 { |
1695 { |
1644 QTest::addColumn<int>("indexForInsertion"); |
1696 QTest::addColumn<int>("indexForInsertion"); |