# HG changeset patch # User Chris Cannam # Date 1407938719 -3600 # Node ID 71b21d6e66bedec420c916f049e0e97dd02afed2 # Parent ff43500426da7ff6420edbb4ae10335b5301f15d Try descending through menu hierarchy from the top rather than just looking for any objects that are children of menus diff -r ff43500426da -r 71b21d6e66be framework/MainWindowBase.cpp --- 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 menus = mb->findChildren(); + + QList menus = mb->findChildren + (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(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(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 } diff -r ff43500426da -r 71b21d6e66be framework/MainWindowBase.h --- 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 m_appShortcuts;