changeset 394:71b21d6e66be

Try descending through menu hierarchy from the top rather than just looking for any objects that are children of menus
author Chris Cannam
date Wed, 13 Aug 2014 15:05:19 +0100
parents ff43500426da
children ad168a6510f0
files framework/MainWindowBase.cpp framework/MainWindowBase.h
diffstat 2 files changed, 33 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/framework/MainWindowBase.cpp	Wed Aug 13 11:49:45 2014 +0100
+++ b/framework/MainWindowBase.cpp	Wed Aug 13 15:05:19 2014 +0100
@@ -288,7 +288,10 @@
     m_appShortcuts.clear();
 
     QMenuBar *mb = menuBar();
-    QList<QMenu *> menus = mb->findChildren<QMenu *>();
+
+    QList<QMenu *> menus = mb->findChildren<QMenu *>
+        (QString(), Qt::FindDirectChildrenOnly);
+
     foreach (QMenu *menu, menus) {
         if (menu) finaliseMenu(menu);
     }
@@ -347,25 +350,36 @@
     }
 
     foreach (QAction *a, menu->actions()) {
-        QWidgetList ww = a->associatedWidgets();
-        bool hasButton = false;
-        foreach (QWidget *w, ww) {
-            if (qobject_cast<QAbstractButton *>(w)) {
-                hasButton = true;
-                break;
+
+        if (a->isSeparator()) {
+            continue;
+        } else if (a->menu()) {
+            cerr << "recursing to menu: " << a->menu()->title() << endl;
+            finaliseMenu(a->menu());
+        } else {
+
+            QWidgetList ww = a->associatedWidgets();
+            bool hasButton = false;
+            foreach (QWidget *w, ww) {
+                if (qobject_cast<QAbstractButton *>(w)) {
+                    hasButton = true;
+                    break;
+                }
+            }
+            if (hasButton) continue;
+            QKeySequence sc = a->shortcut();
+            if (sc.count() == 1 && !(sc[0] & Qt::KeyboardModifierMask)) {
+                QShortcut *newSc = new QShortcut(sc, a->parentWidget());
+                QObject::connect(newSc, SIGNAL(activated()),
+                                 m_menuShortcutMapper, SLOT(map()));
+                cerr << "setting mapping for action " << a << ", name " << a->text() << " on mapper " << m_menuShortcutMapper << " through shortcut " << newSc << " with key " << newSc->key().toString() << endl;
+                m_menuShortcutMapper->setMapping(newSc, a);
+                m_appShortcuts.push_back(newSc);
             }
         }
-        if (hasButton) continue;
-        QKeySequence sc = a->shortcut();
-        if (sc.count() == 1 && !(sc[0] & Qt::KeyboardModifierMask)) {
-            QShortcut *newSc = new QShortcut(sc, a->parentWidget());
-            QObject::connect(newSc, SIGNAL(activated()),
-                             m_menuShortcutMapper, SLOT(map()));
-            cerr << "setting mapping for action " << a << ", name " << a->text() << " on mapper " << m_menuShortcutMapper << " through shortcut " << newSc << " with key " << newSc->key().toString() << endl;
-            m_menuShortcutMapper->setMapping(newSc, a);
-            m_appShortcuts.push_back(newSc);
-        }
     }
+
+    cerr << "finished with menu " << menu << endl;
 #endif
 }
 
--- a/framework/MainWindowBase.h	Wed Aug 13 11:49:45 2014 +0100
+++ b/framework/MainWindowBase.h	Wed Aug 13 15:05:19 2014 +0100
@@ -429,6 +429,8 @@
     // shortcuts on OS/X
     virtual void finaliseMenus();
     virtual void finaliseMenu(QMenu *);
+
+    // Only used on OS/X to work around a Qt/Cocoa bug, see finaliseMenus
     QSignalMapper *m_menuShortcutMapper;
     QList<QShortcut *> m_appShortcuts;