80 void addActionsAndClear(); |
80 void addActionsAndClear(); |
81 |
81 |
82 void keyboardNavigation_data(); |
82 void keyboardNavigation_data(); |
83 void keyboardNavigation(); |
83 void keyboardNavigation(); |
84 void focus(); |
84 void focus(); |
85 void overrideMenuAction(); |
85 void overrideMenuAction(); |
86 void statusTip(); |
86 void statusTip(); |
87 void widgetActionFocus(); |
87 void widgetActionFocus(); |
88 void mouseActivation(); |
88 void mouseActivation(); |
89 void tearOff(); |
89 void tearOff(); |
|
90 void layoutDirection(); |
90 |
91 |
91 #if defined(QT3_SUPPORT) |
92 #if defined(QT3_SUPPORT) |
92 void indexBasedInsertion_data(); |
93 void indexBasedInsertion_data(); |
93 void indexBasedInsertion(); |
94 void indexBasedInsertion(); |
94 #endif |
95 #endif |
99 void task250673_activeMultiColumnSubMenuPosition(); |
100 void task250673_activeMultiColumnSubMenuPosition(); |
100 void task256918_setFont(); |
101 void task256918_setFont(); |
101 void menuSizeHint(); |
102 void menuSizeHint(); |
102 void task258920_mouseBorder(); |
103 void task258920_mouseBorder(); |
103 void setFixedWidth(); |
104 void setFixedWidth(); |
|
105 void deleteActionInTriggered(); |
|
106 void pushButtonPopulateOnAboutToShow(); |
104 protected slots: |
107 protected slots: |
105 void onActivated(QAction*); |
108 void onActivated(QAction*); |
106 void onHighlighted(QAction*); |
109 void onHighlighted(QAction*); |
107 void onStatusMessageChanged(const QString &); |
110 void onStatusMessageChanged(const QString &); |
108 void onStatusTipTimer(); |
111 void onStatusTipTimer(); |
|
112 void deleteAction(QAction *a) { delete a; } |
|
113 void populateMenu(); |
109 private: |
114 private: |
110 void createActions(); |
115 void createActions(); |
111 QMenu *menus[2], *lastMenu; |
116 QMenu *menus[2], *lastMenu; |
112 enum { num_builtins = 10 }; |
117 enum { num_builtins = 10 }; |
113 QAction *activated, *highlighted, *builtins[num_builtins]; |
118 QAction *activated, *highlighted, *builtins[num_builtins]; |
591 |
605 |
592 menu->hideTearOffMenu(); |
606 menu->hideTearOffMenu(); |
593 QVERIFY(!menu->isTearOffMenuVisible()); |
607 QVERIFY(!menu->isTearOffMenuVisible()); |
594 QVERIFY(!torn->isVisible()); |
608 QVERIFY(!torn->isVisible()); |
595 } |
609 } |
|
610 |
|
611 void tst_QMenu::layoutDirection() |
|
612 { |
|
613 QMainWindow win; |
|
614 win.setLayoutDirection(Qt::RightToLeft); |
|
615 |
|
616 QMenu menu(&win); |
|
617 menu.show(); |
|
618 QTest::qWaitForWindowShown(&menu); |
|
619 QCOMPARE(menu.layoutDirection(), Qt::RightToLeft); |
|
620 menu.close(); |
|
621 |
|
622 menu.setParent(0); |
|
623 menu.show(); |
|
624 QTest::qWaitForWindowShown(&menu); |
|
625 QCOMPARE(menu.layoutDirection(), QApplication::layoutDirection()); |
|
626 menu.close(); |
|
627 |
|
628 //now the menubar |
|
629 QAction *action = win.menuBar()->addMenu(&menu); |
|
630 win.menuBar()->setActiveAction(action); |
|
631 QTest::qWaitForWindowShown(&menu); |
|
632 QCOMPARE(menu.layoutDirection(), Qt::RightToLeft); |
|
633 } |
|
634 |
596 |
635 |
597 |
636 |
598 #if defined(QT3_SUPPORT) |
637 #if defined(QT3_SUPPORT) |
599 void tst_QMenu::indexBasedInsertion_data() |
638 void tst_QMenu::indexBasedInsertion_data() |
600 { |
639 { |
856 //the sizehint should reflect the minimumwidth because the action will try to |
895 //the sizehint should reflect the minimumwidth because the action will try to |
857 //get as much space as possible |
896 //get as much space as possible |
858 QCOMPARE(menu.sizeHint().width(), menu.minimumWidth()); |
897 QCOMPARE(menu.sizeHint().width(), menu.minimumWidth()); |
859 } |
898 } |
860 |
899 |
|
900 void tst_QMenu::deleteActionInTriggered() |
|
901 { |
|
902 // should not crash |
|
903 QMenu m; |
|
904 QObject::connect(&m, SIGNAL(triggered(QAction*)), this, SLOT(deleteAction(QAction*))); |
|
905 QWeakPointer<QAction> a = m.addAction("action"); |
|
906 a.data()->trigger(); |
|
907 QVERIFY(!a); |
|
908 } |
|
909 |
|
910 void tst_QMenu::pushButtonPopulateOnAboutToShow() |
|
911 { |
|
912 QPushButton b("Test PushButton"); |
|
913 b.setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); |
|
914 lastMenu = new QMenu; |
|
915 b.setMenu(lastMenu); |
|
916 const int scrNumber = QApplication::desktop()->screenNumber(&b); |
|
917 connect(lastMenu, SIGNAL(aboutToShow()), this, SLOT(populateMenu())); |
|
918 b.show(); |
|
919 const QRect screen = QApplication::desktop()->screenGeometry(scrNumber); |
|
920 |
|
921 b.move(10, screen.bottom()-b.height()-5); |
|
922 QTest::qWaitForWindowShown(&b); |
|
923 QTimer::singleShot(300,lastMenu, SLOT(hide())); |
|
924 QTest::mouseClick(&b, Qt::LeftButton, Qt::NoModifier, b.rect().center()); |
|
925 QVERIFY(!lastMenu->geometry().intersects(b.geometry())); |
|
926 |
|
927 b.move(10, screen.bottom()-lastMenu->height()-5); |
|
928 QTimer::singleShot(300,lastMenu, SLOT(hide())); |
|
929 QTest::mouseClick(&b, Qt::LeftButton, Qt::NoModifier, b.rect().center()); |
|
930 QVERIFY(!lastMenu->geometry().intersects(b.geometry())); |
|
931 |
|
932 } |
861 |
933 |
862 |
934 |
863 QTEST_MAIN(tst_QMenu) |
935 QTEST_MAIN(tst_QMenu) |
864 #include "tst_qmenu.moc" |
936 #include "tst_qmenu.moc" |