summaryrefslogtreecommitdiffstats
path: root/tests/auto/qmenubar/tst_qmenubar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qmenubar/tst_qmenubar.cpp')
-rw-r--r--tests/auto/qmenubar/tst_qmenubar.cpp109
1 files changed, 107 insertions, 2 deletions
diff --git a/tests/auto/qmenubar/tst_qmenubar.cpp b/tests/auto/qmenubar/tst_qmenubar.cpp
index 2b3e5e3..197d6f0 100644
--- a/tests/auto/qmenubar/tst_qmenubar.cpp
+++ b/tests/auto/qmenubar/tst_qmenubar.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
+** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the test suite of the Qt Toolkit.
**
@@ -34,7 +34,7 @@
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
+** contact the sales department at http://www.qtsoftware.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -48,8 +48,10 @@
#include <q3popupmenu.h>
#endif
#include <qstyle.h>
+#include <qwindowsstyle.h>
#include <qdesktopwidget.h>
#include <qaction.h>
+#include <qstyleoption.h>
#ifdef Q_WS_WIN
#include <windows.h>
@@ -149,6 +151,8 @@ private slots:
void check_shortcutPress();
void check_menuPosition();
void task223138_triggered();
+ void task256322_highlight();
+ void menubarSizeHint();
#if defined(QT3_SUPPORT)
void indexBasedInsertion_data();
@@ -1524,6 +1528,107 @@ void tst_QMenuBar::task223138_triggered()
QCOMPARE(submenuSpy.count(), 1);
}
+void tst_QMenuBar::task256322_highlight()
+{
+ QMainWindow win;
+ QMenu menu;
+ QAction *file = win.menuBar()->addMenu(&menu);
+ file->setText("file");
+ QMenu menu2;
+ QAction *file2 = win.menuBar()->addMenu(&menu2);
+ file2->setText("file2");
+ QAction *nothing = win.menuBar()->addAction("nothing");
+
+ win.show();
+
+ QTest::mouseClick(win.menuBar(), Qt::LeftButton, 0, win.menuBar()->actionGeometry(file).center());
+ QVERIFY(menu.isVisible());
+ QVERIFY(!menu2.isVisible());
+ QCOMPARE(win.menuBar()->activeAction(), file);
+
+ QTest::mouseMove(win.menuBar(), win.menuBar()->actionGeometry(file2).center());
+ QVERIFY(!menu.isVisible());
+ QVERIFY(menu2.isVisible());
+ QCOMPARE(win.menuBar()->activeAction(), file2);
+
+ QTest::mouseMove(win.menuBar(), win.menuBar()->actionGeometry(nothing).center());
+ QVERIFY(!menu.isVisible());
+ QVERIFY(!menu2.isVisible());
+ QCOMPARE(win.menuBar()->activeAction(), nothing);
+
+ QTest::mouseMove(&win, win.menuBar()->geometry().bottomLeft() + QPoint(1,1));
+
+ QVERIFY(!menu.isVisible());
+ QVERIFY(!menu2.isVisible());
+ QVERIFY(!win.menuBar()->activeAction());
+}
+
+void tst_QMenuBar::menubarSizeHint()
+{
+ struct MyStyle : public QWindowsStyle
+ {
+ virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const
+ {
+ // I chose strange values (prime numbers to be more sure that the size of the menubar is correct)
+ switch (metric)
+ {
+ case QStyle::PM_MenuBarItemSpacing:
+ return 7;
+ case PM_MenuBarHMargin:
+ return 13;
+ case PM_MenuBarVMargin:
+ return 11;
+ case PM_MenuBarPanelWidth:
+ return 1;
+ }
+ return QWindowsStyle::pixelMetric(metric, option, widget);
+ }
+ } style;
+
+ QMenuBar mb;
+ mb.setStyle(&style);
+ //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);
+
+ const int panelWidth = style.pixelMetric(QStyle::PM_MenuBarPanelWidth);
+ const int hmargin = style.pixelMetric(QStyle::PM_MenuBarHMargin);
+ const int vmargin = style.pixelMetric(QStyle::PM_MenuBarVMargin);
+ const int spacing = style.pixelMetric(QStyle::PM_MenuBarItemSpacing);
+
+ mb.show();
+ QRect result;
+ foreach(QAction *action, mb.actions()) {
+ const QRect actionRect = mb.actionGeometry(action);
+ if (!result.isNull()) //this is the first item
+ QCOMPARE(actionRect.left() - result.right() - 1, spacing);
+ result |= actionRect;
+ QCOMPARE(result.x(), panelWidth + hmargin + spacing);
+ QCOMPARE(result.y(), panelWidth + vmargin);
+ }
+
+ //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(panelWidth + hmargin, panelWidth + vmargin);
+
+
+ resSize = style.sizeFromContents(QStyle::CT_MenuBar, &opt,
+ resSize.expandedTo(QApplication::globalStrut()),
+ &mb);
+
+ QCOMPARE(resSize, mb.sizeHint());
+}
+
#if defined(QT3_SUPPORT)
void tst_QMenuBar::indexBasedInsertion_data()