diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-06-29 13:38:06 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-06-29 13:38:45 (GMT) |
commit | 82c48b13249fbcd96d8287f3cd1fdfd61802523c (patch) | |
tree | 5713b0936f049492990db70acdd6da2c53e63781 /tests | |
parent | a9c225e6b464337d253e6b9aa5eaac82d01b3301 (diff) | |
download | Qt-82c48b13249fbcd96d8287f3cd1fdfd61802523c.zip Qt-82c48b13249fbcd96d8287f3cd1fdfd61802523c.tar.gz Qt-82c48b13249fbcd96d8287f3cd1fdfd61802523c.tar.bz2 |
QMenuBar: adding autotest and simplify/fix geometry calculation
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qmenubar/tst_qmenubar.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/auto/qmenubar/tst_qmenubar.cpp b/tests/auto/qmenubar/tst_qmenubar.cpp index 8a38782..f6f5873 100644 --- a/tests/auto/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/qmenubar/tst_qmenubar.cpp @@ -50,6 +50,7 @@ #include <qstyle.h> #include <qdesktopwidget.h> #include <qaction.h> +#include <qstyleoption.h> #ifdef Q_WS_WIN #include <windows.h> @@ -150,6 +151,7 @@ private slots: void check_menuPosition(); void task223138_triggered(); void task256322_highlight(); + void menubarSizeHint(); #if defined(QT3_SUPPORT) void indexBasedInsertion_data(); @@ -1556,6 +1558,47 @@ void tst_QMenuBar::task256322_highlight() QVERIFY(!win.menuBar()->activeAction()); } +void tst_QMenuBar::menubarSizeHint() +{ + QMenuBar mb; + //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) + mb.addAction(str); + + int left, top, right, bottom; + mb.getContentsMargins(&left, &top, &right, &bottom); + const int panelWidth = mb.style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, &mb); + + mb.show(); + QRect result; + foreach(QAction *action, mb.actions()) { + result |= mb.actionGeometry(action); + QCOMPARE(result.x(), left + panelWidth); + QCOMPARE(result.y(), top + panelWidth); + } + + //this code is copied from QMenuBar + //there is no public member that allows to initialize a styleoption instance + QStyleOptionMenuItem opt; + opt.rect = mb.rect(); + opt.menuRect = mb.rect(); + opt.state = QStyle::State_None; + opt.menuItemType = QStyleOptionMenuItem::Normal; + opt.checkType = QStyleOptionMenuItem::NotCheckable; + opt.palette = mb.palette(); + + QSize resSize = QSize(result.x(), result.y()) + result.size() + + QSize(right + panelWidth, top + panelWidth); + + + resSize = mb.style()->sizeFromContents(QStyle::CT_MenuBar, &opt, + resSize.expandedTo(QApplication::globalStrut()), + &mb); + + QCOMPARE(resSize, mb.sizeHint()); +} + #if defined(QT3_SUPPORT) void tst_QMenuBar::indexBasedInsertion_data() |