Mercurial > hg > svapp
comparison framework/MainWindowBase.cpp @ 396:2f54917f1599
Comments and tidy
author | Chris Cannam |
---|---|
date | Wed, 13 Aug 2014 16:44:44 +0100 |
parents | 71b21d6e66be |
children | 81e41a430b58 |
comparison
equal
deleted
inserted
replaced
395:ad168a6510f0 | 396:2f54917f1599 |
---|---|
275 } | 275 } |
276 | 276 |
277 void | 277 void |
278 MainWindowBase::finaliseMenus() | 278 MainWindowBase::finaliseMenus() |
279 { | 279 { |
280 cerr << "deleting mapper " << m_menuShortcutMapper << endl; | |
281 delete m_menuShortcutMapper; | 280 delete m_menuShortcutMapper; |
282 m_menuShortcutMapper = 0; | 281 m_menuShortcutMapper = 0; |
283 | 282 |
284 foreach (QShortcut *sc, m_appShortcuts) { | 283 foreach (QShortcut *sc, m_appShortcuts) { |
285 cerr << "deleting shortcut " << sc << endl; | |
286 delete sc; | 284 delete sc; |
287 } | 285 } |
288 m_appShortcuts.clear(); | 286 m_appShortcuts.clear(); |
289 | 287 |
290 QMenuBar *mb = menuBar(); | 288 QMenuBar *mb = menuBar(); |
289 | |
290 // This used to find all children of QMenu type, and call | |
291 // finaliseMenu on those. But it seems we are getting hold of some | |
292 // menus that way that are not actually active in the menu bar and | |
293 // are not returned in their parent menu's actions() list, and if | |
294 // we finalise those, we end up with duplicate shortcuts in the | |
295 // app shortcut mapper. So we should do this by descending the | |
296 // menu tree through only those menus accessible via actions() | |
297 // from their parents instead. | |
291 | 298 |
292 QList<QMenu *> menus = mb->findChildren<QMenu *> | 299 QList<QMenu *> menus = mb->findChildren<QMenu *> |
293 (QString(), Qt::FindDirectChildrenOnly); | 300 (QString(), Qt::FindDirectChildrenOnly); |
294 | 301 |
295 foreach (QMenu *menu, menus) { | 302 foreach (QMenu *menu, menus) { |
341 m_menuShortcutMapper = new QSignalMapper(this); | 348 m_menuShortcutMapper = new QSignalMapper(this); |
342 connect(m_menuShortcutMapper, SIGNAL(mapped(QObject *)), | 349 connect(m_menuShortcutMapper, SIGNAL(mapped(QObject *)), |
343 this, SLOT(menuActionMapperInvoked(QObject *))); | 350 this, SLOT(menuActionMapperInvoked(QObject *))); |
344 } | 351 } |
345 | 352 |
346 cerr << "examining menu: " << menu << ", " << menu->title() << endl; | |
347 QMenu *pm = qobject_cast<QMenu *>(menu->parent()); | |
348 if (pm) { | |
349 cerr << "(sub-menu of: " << pm << ", " << pm->title() << ")" << endl; | |
350 } | |
351 | |
352 foreach (QAction *a, menu->actions()) { | 353 foreach (QAction *a, menu->actions()) { |
353 | 354 |
354 if (a->isSeparator()) { | 355 if (a->isSeparator()) { |
355 continue; | 356 continue; |
356 } else if (a->menu()) { | 357 } else if (a->menu()) { |
357 cerr << "recursing to menu: " << a->menu()->title() << endl; | |
358 finaliseMenu(a->menu()); | 358 finaliseMenu(a->menu()); |
359 } else { | 359 } else { |
360 | 360 |
361 QWidgetList ww = a->associatedWidgets(); | 361 QWidgetList ww = a->associatedWidgets(); |
362 bool hasButton = false; | 362 bool hasButton = false; |
370 QKeySequence sc = a->shortcut(); | 370 QKeySequence sc = a->shortcut(); |
371 if (sc.count() == 1 && !(sc[0] & Qt::KeyboardModifierMask)) { | 371 if (sc.count() == 1 && !(sc[0] & Qt::KeyboardModifierMask)) { |
372 QShortcut *newSc = new QShortcut(sc, a->parentWidget()); | 372 QShortcut *newSc = new QShortcut(sc, a->parentWidget()); |
373 QObject::connect(newSc, SIGNAL(activated()), | 373 QObject::connect(newSc, SIGNAL(activated()), |
374 m_menuShortcutMapper, SLOT(map())); | 374 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; | |
376 m_menuShortcutMapper->setMapping(newSc, a); | 375 m_menuShortcutMapper->setMapping(newSc, a); |
377 m_appShortcuts.push_back(newSc); | 376 m_appShortcuts.push_back(newSc); |
378 } | 377 } |
379 } | 378 } |
380 } | 379 } |
381 | |
382 cerr << "finished with menu " << menu << endl; | |
383 #endif | 380 #endif |
384 } | 381 } |
385 | 382 |
386 void | 383 void |
387 MainWindowBase::menuActionMapperInvoked(QObject *o) | 384 MainWindowBase::menuActionMapperInvoked(QObject *o) |
388 { | 385 { |
389 cerr << "menuActionMapperInvoked from mapper " << sender() << endl; | |
390 QAction *a = qobject_cast<QAction *>(o); | 386 QAction *a = qobject_cast<QAction *>(o); |
391 if (a && a->isEnabled()) { | 387 if (a && a->isEnabled()) { |
392 cerr << "about to call trigger on action " << a << ", name " << a->text() << endl; | |
393 a->trigger(); | 388 a->trigger(); |
394 } | 389 } |
395 } | 390 } |
396 | 391 |
397 void | 392 void |