summaryrefslogtreecommitdiffstats
path: root/tests/auto/qmenu
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-06-29 13:15:26 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-06-29 13:38:44 (GMT)
commita9c225e6b464337d253e6b9aa5eaac82d01b3301 (patch)
treef93a6c05df4eeae6a078ad06a7c6527a2a545c6a /tests/auto/qmenu
parent5f027e8e5e430abf54eea4a020ead8ed95e3a211 (diff)
downloadQt-a9c225e6b464337d253e6b9aa5eaac82d01b3301.zip
Qt-a9c225e6b464337d253e6b9aa5eaac82d01b3301.tar.gz
Qt-a9c225e6b464337d253e6b9aa5eaac82d01b3301.tar.bz2
QMenu: adding autotest for the geometry calculations
I also fixed an off-by-1 pixel bug
Diffstat (limited to 'tests/auto/qmenu')
-rw-r--r--tests/auto/qmenu/tst_qmenu.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/qmenu/tst_qmenu.cpp b/tests/auto/qmenu/tst_qmenu.cpp
index 01e29f8..1d19ffa 100644
--- a/tests/auto/qmenu/tst_qmenu.cpp
+++ b/tests/auto/qmenu/tst_qmenu.cpp
@@ -94,6 +94,7 @@ private slots:
void task176201_clear();
void task250673_activeMultiColumnSubMenuPosition();
void task256918_setFont();
+ void menuSizeHint();
protected slots:
void onActivated(QAction*);
void onHighlighted(QAction*);
@@ -727,6 +728,40 @@ void tst_QMenu::task256918_setFont()
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());
+}
QTEST_MAIN(tst_QMenu)
#include "tst_qmenu.moc"