comparison framework/MainWindowBase.cpp @ 390:3e5c8a03bcb7

Associate the mapper with the MainWindowBase object, and recreate it each time we scan all menus -- allowing us to call finaliseMenus more than once if menu actions have changed
author Chris Cannam
date Wed, 13 Aug 2014 09:52:46 +0100
parents 8cfc71c8ec4b
children 9e31759254fe
comparison
equal deleted inserted replaced
389:8cfc71c8ec4b 390:3e5c8a03bcb7
153 m_abandoning(false), 153 m_abandoning(false),
154 m_labeller(0), 154 m_labeller(0),
155 m_lastPlayStatusSec(0), 155 m_lastPlayStatusSec(0),
156 m_initialDarkBackground(false), 156 m_initialDarkBackground(false),
157 m_defaultFfwdRwdStep(2, 0), 157 m_defaultFfwdRwdStep(2, 0),
158 m_statusLabel(0) 158 m_statusLabel(0),
159 m_menuShortcutMapper(0)
159 { 160 {
160 Profiler profiler("MainWindowBase::MainWindowBase"); 161 Profiler profiler("MainWindowBase::MainWindowBase");
161 162
162 #ifdef Q_WS_X11 163 #ifdef Q_WS_X11
163 XSetErrorHandler(handle_x11_error); 164 XSetErrorHandler(handle_x11_error);
274 } 275 }
275 276
276 void 277 void
277 MainWindowBase::finaliseMenus() 278 MainWindowBase::finaliseMenus()
278 { 279 {
280 delete m_menuShortcutMapper;
281 m_menuShortcutMapper = 0;
282
279 QMenuBar *mb = menuBar(); 283 QMenuBar *mb = menuBar();
280 QList<QMenu *> menus = mb->findChildren<QMenu *>(); 284 QList<QMenu *> menus = mb->findChildren<QMenu *>();
281 foreach (QMenu *menu, menus) { 285 foreach (QMenu *menu, menus) {
282 if (menu) finaliseMenu(menu); 286 if (menu) finaliseMenu(menu);
283 } 287 }
321 // i.e. that will not otherwise work. The downside is that if this 325 // i.e. that will not otherwise work. The downside is that if this
322 // bug is fixed in a future Qt release, we will start getting 326 // bug is fixed in a future Qt release, we will start getting
323 // "ambiguous shortcut" errors from the menu entry actions and 327 // "ambiguous shortcut" errors from the menu entry actions and
324 // will need to update the code.) 328 // will need to update the code.)
325 329
326 QSignalMapper *mapper = new QSignalMapper(this); 330 if (!m_menuShortcutMapper) {
327 331 m_menuShortcutMapper = new QSignalMapper(this);
328 connect(mapper, SIGNAL(mapped(QObject *)), 332 }
333
334 connect(m_menuShortcutMapper, SIGNAL(mapped(QObject *)),
329 this, SLOT(menuActionMapperInvoked(QObject *))); 335 this, SLOT(menuActionMapperInvoked(QObject *)));
330 336
331 foreach (QAction *a, menu->actions()) { 337 foreach (QAction *a, menu->actions()) {
332 QWidgetList ww = a->associatedWidgets(); 338 QWidgetList ww = a->associatedWidgets();
333 bool hasButton = false; 339 bool hasButton = false;
339 } 345 }
340 if (hasButton) continue; 346 if (hasButton) continue;
341 QKeySequence sc = a->shortcut(); 347 QKeySequence sc = a->shortcut();
342 if (sc.count() == 1 && !(sc[0] & Qt::KeyboardModifierMask)) { 348 if (sc.count() == 1 && !(sc[0] & Qt::KeyboardModifierMask)) {
343 QShortcut *newSc = new QShortcut(sc, a->parentWidget()); 349 QShortcut *newSc = new QShortcut(sc, a->parentWidget());
344 QObject::connect(newSc, SIGNAL(activated()), mapper, SLOT(map())); 350 QObject::connect(newSc, SIGNAL(activated()),
351 m_menuShortcutMapper, SLOT(map()));
345 cerr << "setting mapping for action " << a << ", name " << a->text() << endl; 352 cerr << "setting mapping for action " << a << ", name " << a->text() << endl;
346 mapper->setMapping(newSc, a); 353 m_menuShortcutMapper->setMapping(newSc, a);
347 } 354 }
348 } 355 }
349 #endif 356 #endif
350 } 357 }
351 358