comparison framework/MainWindowBase.cpp @ 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 2f54917f1599
comparison
equal deleted inserted replaced
393:ff43500426da 394:71b21d6e66be
286 delete sc; 286 delete sc;
287 } 287 }
288 m_appShortcuts.clear(); 288 m_appShortcuts.clear();
289 289
290 QMenuBar *mb = menuBar(); 290 QMenuBar *mb = menuBar();
291 QList<QMenu *> menus = mb->findChildren<QMenu *>(); 291
292 QList<QMenu *> menus = mb->findChildren<QMenu *>
293 (QString(), Qt::FindDirectChildrenOnly);
294
292 foreach (QMenu *menu, menus) { 295 foreach (QMenu *menu, menus) {
293 if (menu) finaliseMenu(menu); 296 if (menu) finaliseMenu(menu);
294 } 297 }
295 } 298 }
296 299
345 if (pm) { 348 if (pm) {
346 cerr << "(sub-menu of: " << pm << ", " << pm->title() << ")" << endl; 349 cerr << "(sub-menu of: " << pm << ", " << pm->title() << ")" << endl;
347 } 350 }
348 351
349 foreach (QAction *a, menu->actions()) { 352 foreach (QAction *a, menu->actions()) {
350 QWidgetList ww = a->associatedWidgets(); 353
351 bool hasButton = false; 354 if (a->isSeparator()) {
352 foreach (QWidget *w, ww) { 355 continue;
353 if (qobject_cast<QAbstractButton *>(w)) { 356 } else if (a->menu()) {
354 hasButton = true; 357 cerr << "recursing to menu: " << a->menu()->title() << endl;
355 break; 358 finaliseMenu(a->menu());
359 } else {
360
361 QWidgetList ww = a->associatedWidgets();
362 bool hasButton = false;
363 foreach (QWidget *w, ww) {
364 if (qobject_cast<QAbstractButton *>(w)) {
365 hasButton = true;
366 break;
367 }
356 } 368 }
357 } 369 if (hasButton) continue;
358 if (hasButton) continue; 370 QKeySequence sc = a->shortcut();
359 QKeySequence sc = a->shortcut(); 371 if (sc.count() == 1 && !(sc[0] & Qt::KeyboardModifierMask)) {
360 if (sc.count() == 1 && !(sc[0] & Qt::KeyboardModifierMask)) { 372 QShortcut *newSc = new QShortcut(sc, a->parentWidget());
361 QShortcut *newSc = new QShortcut(sc, a->parentWidget()); 373 QObject::connect(newSc, SIGNAL(activated()),
362 QObject::connect(newSc, SIGNAL(activated()), 374 m_menuShortcutMapper, SLOT(map()));
363 m_menuShortcutMapper, SLOT(map())); 375 cerr << "setting mapping for action " << a << ", name " << a->text() << " on mapper " << m_menuShortcutMapper << " through shortcut " << newSc << " with key " << newSc->key().toString() << endl;
364 cerr << "setting mapping for action " << a << ", name " << a->text() << " on mapper " << m_menuShortcutMapper << " through shortcut " << newSc << " with key " << newSc->key().toString() << endl; 376 m_menuShortcutMapper->setMapping(newSc, a);
365 m_menuShortcutMapper->setMapping(newSc, a); 377 m_appShortcuts.push_back(newSc);
366 m_appShortcuts.push_back(newSc); 378 }
367 } 379 }
368 } 380 }
381
382 cerr << "finished with menu " << menu << endl;
369 #endif 383 #endif
370 } 384 }
371 385
372 void 386 void
373 MainWindowBase::menuActionMapperInvoked(QObject *o) 387 MainWindowBase::menuActionMapperInvoked(QObject *o)