summaryrefslogtreecommitdiffstats
path: root/tests/auto/qmenu
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qmenu')
-rw-r--r--tests/auto/qmenu/tst_qmenu.cpp130
1 files changed, 121 insertions, 9 deletions
diff --git a/tests/auto/qmenu/tst_qmenu.cpp b/tests/auto/qmenu/tst_qmenu.cpp
index 8049935..ab8dd48 100644
--- a/tests/auto/qmenu/tst_qmenu.cpp
+++ b/tests/auto/qmenu/tst_qmenu.cpp
@@ -50,6 +50,7 @@
#include <QStatusBar>
#include <QListWidget>
#include <QWidgetAction>
+#include <QDesktopWidget>
#include <qmenu.h>
#include <qstyle.h>
@@ -92,7 +93,11 @@ private slots:
void activeSubMenuPosition();
void task242454_sizeHint();
void task176201_clear();
- void task250673_activeMutliColumnSubMenuPosition();
+ void task250673_activeMultiColumnSubMenuPosition();
+ void task256918_setFont();
+ void menuSizeHint();
+ void task258920_mouseBorder();
+ void setFixedWidth();
protected slots:
void onActivated(QAction*);
void onHighlighted(QAction*);
@@ -423,8 +428,11 @@ void tst_QMenu::overrideMenuAction()
QSKIP("On Mac, we need to create native key events to test menu action activation", SkipAll);
#elif defined(Q_OS_WINCE)
QSKIP("On Windows CE, we need to create native key events to test menu action activation", SkipAll);
+#elif defined(Q_OS_SYMBIAN)
+ QSKIP("On Symbian OS, we need to create native key events to test menu action activation", SkipAll);
#endif
- QAction *aQuit = new QAction("Quit", &w);
+
+ QAction *aQuit = new QAction("Quit", &w);
aQuit->setShortcut(QKeySequence("Ctrl+X"));
m->addAction(aQuit);
@@ -441,7 +449,7 @@ void tst_QMenu::overrideMenuAction()
delete aFileMenu;
- //after the deletion of the override menu action,
+ //after the deletion of the override menu action,
//the menu should have its default menu action back
QCOMPARE(m->menuAction(), menuaction);
@@ -470,7 +478,7 @@ void tst_QMenu::statusTip()
QVERIFY(btn != NULL);
- //because showMenu calls QMenu::exec, we need to use a singleshot
+ //because showMenu calls QMenu::exec, we need to use a singleshot
//to continue the test
QTimer::singleShot(200,this, SLOT(onStatusTipTimer()));
btn->showMenu();
@@ -484,10 +492,10 @@ void tst_QMenu::onStatusTipTimer()
QVERIFY(menu != 0);
QVERIFY(menu->isVisible());
QTest::keyClick(menu, Qt::Key_Down);
-
+
//we store the statustip to press escape in any case
//otherwise, if the test fails it blocks (never gets out of QMenu::exec
- const QString st=statustip;
+ const QString st=statustip;
menu->close(); //goes out of the menu
@@ -552,10 +560,10 @@ void tst_QMenu::tearOff()
menu->popup(QPoint(0,0));
QTest::qWait(50);
QVERIFY(!menu->isTearOffMenuVisible());
-
+
QTest::mouseClick(menu, Qt::LeftButton, 0, QPoint(3, 3), 10);
QTest::qWait(100);
-
+
QVERIFY(menu->isTearOffMenuVisible());
QPointer<QMenu> torn = 0;
foreach (QWidget *w, QApplication::allWidgets()) {
@@ -638,7 +646,11 @@ void tst_QMenu::activeSubMenuPosition()
main->setActiveAction(menuAction);
sub->setActiveAction(subAction);
+#ifdef Q_OS_SYMBIAN
+ main->popup(QPoint(50,200));
+#else
main->popup(QPoint(200,200));
+#endif
QVERIFY(main->isVisible());
QCOMPARE(main->activeAction(), menuAction);
@@ -682,7 +694,7 @@ void tst_QMenu::task176201_clear()
QTest::mouseClick(&menu, Qt::LeftButton, 0, menu.rect().center());
}
-void tst_QMenu::task250673_activeMutliColumnSubMenuPosition()
+void tst_QMenu::task250673_activeMultiColumnSubMenuPosition()
{
class MyMenu : public QMenu
{
@@ -691,6 +703,12 @@ void tst_QMenu::task250673_activeMutliColumnSubMenuPosition()
};
QMenu sub;
+
+ if (sub.style()->styleHint(QStyle::SH_Menu_Scrollable, 0, &sub)) {
+ //the style prevents the menus from getting columns
+ QSKIP("the style doesn't support multiple columns, it makes the menu scrollable", SkipSingle);
+ }
+
sub.addAction("Sub-Item1");
QAction *subAction = sub.addAction("Sub-Item2");
@@ -716,5 +734,99 @@ void tst_QMenu::task250673_activeMutliColumnSubMenuPosition()
const int subMenuOffset = main.style()->pixelMetric(QStyle::PM_SubMenuOverlap, 0, &main);
QVERIFY((sub.geometry().left() - subMenuOffset + 5) < main.geometry().right());
}
+
+
+void tst_QMenu::task256918_setFont()
+{
+ QMenu menu;
+ QAction *action = menu.addAction("foo");
+ QFont f;
+ f.setPointSize(30);
+ action->setFont(f);
+ menu.show(); //ensures that the actiongeometry are calculated
+ QVERIFY(menu.actionGeometry(action).height() > f.pointSize());
+}
+
+void tst_QMenu::menuSizeHint()
+{
+ QMenu menu;
+ //this is a list of arbitrary strings so that we check the geometry
+ QStringList list = QStringList() << "trer" << "ezrfgtgvqd" << "sdgzgzerzerzer" << "eerzertz" << "er";
+ foreach(QString str, list)
+ menu.addAction(str);
+
+ int left, top, right, bottom;
+ menu.getContentsMargins(&left, &top, &right, &bottom);
+ const int panelWidth = menu.style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, &menu);
+ const int hmargin = menu.style()->pixelMetric(QStyle::PM_MenuHMargin, 0, &menu),
+ vmargin = menu.style()->pixelMetric(QStyle::PM_MenuVMargin, 0, &menu);
+
+ int maxWidth =0;
+ QRect result;
+ foreach(QAction *action, menu.actions()) {
+ maxWidth = qMax(maxWidth, menu.actionGeometry(action).width());
+ result |= menu.actionGeometry(action);
+ QCOMPARE(result.x(), left + hmargin + panelWidth);
+ QCOMPARE(result.y(), top + vmargin + panelWidth);
+ }
+
+ QStyleOption opt(0);
+ opt.rect = menu.rect();
+ opt.state = QStyle::State_None;
+
+ QSize resSize = QSize(result.x(), result.y()) + result.size() + QSize(hmargin + right + panelWidth, vmargin + top + panelWidth);
+
+ resSize = menu.style()->sizeFromContents(QStyle::CT_Menu, &opt,
+ resSize.expandedTo(QApplication::globalStrut()), &menu);
+
+ QCOMPARE(resSize, menu.sizeHint());
+}
+
+class Menu258920 : public QMenu
+{
+ Q_OBJECT
+public slots:
+ void paintEvent(QPaintEvent *e)
+ {
+ QMenu::paintEvent(e);
+ painted = true;
+ }
+
+public:
+ bool painted;
+};
+
+void tst_QMenu::task258920_mouseBorder()
+{
+ Menu258920 menu;
+ QAction *action = menu.addAction("test");
+
+ menu.popup(QApplication::desktop()->availableGeometry().center());
+ QTest::qWait(100);
+ QRect actionRect = menu.actionGeometry(action);
+ QTest::mouseMove(&menu, actionRect.center());
+ QTest::qWait(30);
+ QTest::mouseMove(&menu, actionRect.center() + QPoint(10, 0));
+ QTest::qWait(30);
+ QCOMPARE(action, menu.activeAction());
+ menu.painted = false;
+ QTest::mouseMove(&menu, QPoint(actionRect.center().x(), actionRect.bottom() + 1));
+ QTest::qWait(30);
+ QCOMPARE(static_cast<QAction*>(0), menu.activeAction());
+ QVERIFY(menu.painted);
+}
+
+void tst_QMenu::setFixedWidth()
+{
+ QMenu menu;
+ menu.addAction("action");
+ menu.setFixedWidth(300);
+ //the sizehint should reflect the minimumwidth because the action will try to
+ //get as much space as possible
+ QCOMPARE(menu.sizeHint().width(), menu.minimumWidth());
+}
+
+
+
QTEST_MAIN(tst_QMenu)
#include "tst_qmenu.moc"