summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shaw <qt-info@nokia.com>2009-09-21 12:40:53 (GMT)
committerAndy Shaw <qt-info@nokia.com>2009-09-21 12:40:53 (GMT)
commit3bc60c59bf967425afb9b2ef891b5c701a4f1f86 (patch)
tree9f2ea8e4fa6991482652a73b144b28f31346b3da
parente39d9914491c4a21f7c44140a26fc9bdff682b9d (diff)
downloadQt-3bc60c59bf967425afb9b2ef891b5c701a4f1f86.zip
Qt-3bc60c59bf967425afb9b2ef891b5c701a4f1f86.tar.gz
Qt-3bc60c59bf967425afb9b2ef891b5c701a4f1f86.tar.bz2
Ensure that the menu only shows when clicking on the menu button
In Qt 3 clicking on the toolbutton would not popup the menu, only when clicking on the arrow for the menu popup would this appear if the toolbutton had MenuPopup mode set. When a Q3ActionGroup is used and added to a toolbar then it will give a toolbutton with such a button. This patch fixes the behaviour so that only clicking on the arrow button will cause the menu to appear in this mode. Reviewed-by: Thierry
-rw-r--r--src/gui/widgets/qtoolbutton.cpp4
-rw-r--r--tests/auto/q3toolbar/tst_q3toolbar.cpp54
2 files changed, 57 insertions, 1 deletions
diff --git a/src/gui/widgets/qtoolbutton.cpp b/src/gui/widgets/qtoolbutton.cpp
index 828cd77..91f366f 100644
--- a/src/gui/widgets/qtoolbutton.cpp
+++ b/src/gui/widgets/qtoolbutton.cpp
@@ -871,7 +871,9 @@ void QToolButtonPrivate::_q_buttonPressed()
Q_Q(QToolButton);
if (!hasMenu())
return; // no menu to show
- if (delay > 0 && !popupTimer.isActive() && popupMode == QToolButton::DelayedPopup)
+ if (popupMode == QToolButton::MenuButtonPopup)
+ return;
+ else if (delay > 0 && !popupTimer.isActive() && popupMode == QToolButton::DelayedPopup)
popupTimer.start(delay, q);
else if (delay == 0 || popupMode == QToolButton::InstantPopup)
q->showMenu();
diff --git a/tests/auto/q3toolbar/tst_q3toolbar.cpp b/tests/auto/q3toolbar/tst_q3toolbar.cpp
index 56b24f0..a291f3c 100644
--- a/tests/auto/q3toolbar/tst_q3toolbar.cpp
+++ b/tests/auto/q3toolbar/tst_q3toolbar.cpp
@@ -46,6 +46,8 @@
#include <qaction.h>
#include <qapplication.h>
#include <QToolButton>
+#include <q3action.h>
+#include <qmenu.h>
//TESTED_CLASS=
//TESTED_FILES=
@@ -70,6 +72,7 @@ public slots:
private slots:
void toggled();
+ void actionGroupPopup();
// task-specific tests below me
void task182657();
@@ -134,6 +137,57 @@ void tst_Q3ToolBar::toggled()
}
+class MenuEventFilter : public QObject
+{
+public:
+ MenuEventFilter(QObject *parent = 0) : QObject(parent), menuShown(false) {}
+ bool wasMenuShown() const { return menuShown; }
+ void setMenuShown(bool b) { menuShown = b; }
+protected:
+ bool eventFilter(QObject *o, QEvent *e)
+ {
+ if (e->type() == QEvent::Show) {
+ menuShown = true;
+ QTimer::singleShot(0, o, SLOT(hide()));
+ }
+ return false;
+ }
+private:
+ bool menuShown;
+};
+
+void tst_Q3ToolBar::actionGroupPopup()
+{
+ Q3ActionGroup* ag = new Q3ActionGroup(testWidget);
+ ag->setText("Group");
+ ag->setUsesDropDown(true);
+ ag->setExclusive(false);
+ Q3Action *a = new Q3Action(QIcon(), "ActionA", QKeySequence(), ag);
+ a->setToggleAction(true);
+ Q3Action *b = new Q3Action(QIcon(), "ActionB", QKeySequence(), ag);
+ b->setToggleAction(true);
+ ag->addTo(testWidget);
+ QTest::qWait(100);
+#ifndef NOFINDCHILDRENMETHOD
+ QList<QToolButton *> list = testWidget->findChildren<QToolButton *>();
+#else
+ QList<QToolButton *> list = qFindChildren<QToolButton *>(testWidget, QString());
+#endif
+ QToolButton *tb = 0;
+ for (int i=0;i<list.size();i++) {
+ if (list.at(i)->menu()) {
+ tb = list.at(i);
+ break;
+ }
+ }
+ MenuEventFilter mef;
+ tb->menu()->installEventFilter(&mef);
+ QTest::mouseClick(tb, Qt::LeftButton, 0, QPoint(5,5));
+ QVERIFY(!mef.wasMenuShown());
+ QTest::mouseClick(tb, Qt::LeftButton, 0, QPoint(tb->rect().right() - 5, tb->rect().bottom() - 5));
+ QVERIFY(mef.wasMenuShown());
+}
+
class Q3MainWindow_task182657 : public Q3MainWindow
{
Q3ToolBar *toolbar;