Qt: Fix events in fullscreen
Vicki Pfau vi@endrift.com
Sun, 12 May 2019 16:05:21 -0700
3 files changed,
15 insertions(+),
9 deletions(-)
M
src/platform/qt/ActionMapper.cpp
→
src/platform/qt/ActionMapper.cpp
@@ -30,8 +30,11 @@ m_menus[name].clear();
emit menuCleared(name); } -void ActionMapper::rebuildMenu(QMenuBar* menubar, const ShortcutController& shortcuts) { +void ActionMapper::rebuildMenu(QMenuBar* menubar, QWidget* context, const ShortcutController& shortcuts) { menubar->clear(); + for (QAction* action : context->actions()) { + context->removeAction(action); + } for (const QString& m : m_menus[{}]) { if (m_hiddenActions.contains(m)) { continue;@@ -39,11 +42,11 @@ }
QString menu = m.mid(1); QMenu* qmenu = menubar->addMenu(m_menuNames[menu]); - rebuildMenu(menu, qmenu, shortcuts); + rebuildMenu(menu, qmenu, context, shortcuts); } } -void ActionMapper::rebuildMenu(const QString& menu, QMenu* qmenu, const ShortcutController& shortcuts) { +void ActionMapper::rebuildMenu(const QString& menu, QMenu* qmenu, QWidget* context, const ShortcutController& shortcuts) { for (const QString& actionName : m_menus[menu]) { if (actionName.isNull()) { qmenu->addSeparator();@@ -55,12 +58,13 @@ }
if (actionName[0] == '.') { QString name = actionName.mid(1); QMenu* newMenu = qmenu->addMenu(m_menuNames[name]); - rebuildMenu(name, newMenu, shortcuts); + rebuildMenu(name, newMenu, context, shortcuts); continue; } Action* action = &m_actions[actionName]; QAction* qaction = qmenu->addAction(action->visibleName()); qaction->setEnabled(action->isEnabled()); + qaction->setShortcutContext(Qt::WidgetShortcut); if (action->isExclusive() || action->booleanAction()) { qaction->setCheckable(true); }@@ -88,6 +92,7 @@ QObject::connect(shortcut, &Shortcut::shortcutChanged, qaction, [qaction](int shortcut) {
qaction->setShortcut(QKeySequence(shortcut)); }); } + context->addAction(qaction); } }
M
src/platform/qt/ActionMapper.h
→
src/platform/qt/ActionMapper.h
@@ -29,7 +29,7 @@ public:
void addMenu(const QString& visibleName, const QString& name, const QString& parent = {}); void addHiddenMenu(const QString& visibleName, const QString& name, const QString& parent = {}); void clearMenu(const QString& name); - void rebuildMenu(QMenuBar*, const ShortcutController&); + void rebuildMenu(QMenuBar*, QWidget* context, const ShortcutController&); void addSeparator(const QString& menu);@@ -59,7 +59,7 @@ void actionAdded(const QString& name);
void menuCleared(const QString& name); private: - void rebuildMenu(const QString& menu, QMenu* qmenu, const ShortcutController&); + void rebuildMenu(const QString& menu, QMenu* qmenu, QWidget* context, const ShortcutController&); Action* addAction(const Action& act, const QString& name, const QString& menu, const QKeySequence& shortcut); QHash<QString, Action> m_actions;
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -617,6 +617,7 @@ enterFullScreen();
m_fullscreenOnStart = false; } reloadDisplayDriver(); + setFocus(); } void Window::closeEvent(QCloseEvent* event) {@@ -768,7 +769,7 @@ }, "audioChannels");
action->setActive(true); } } - m_actions.rebuildMenu(menuBar(), *m_shortcutController); + m_actions.rebuildMenu(menuBar(), this, *m_shortcutController); #ifdef USE_DISCORD_RPC@@ -1603,7 +1604,7 @@ action->setEnabled(false);
} m_shortcutController->rebuildItems(); - m_actions.rebuildMenu(menubar, *m_shortcutController); + m_actions.rebuildMenu(menuBar(), this, *m_shortcutController); } void Window::attachWidget(QWidget* widget) {@@ -1640,7 +1641,7 @@ ++i;
} m_config->setMRU(m_mruFiles); m_config->write(); - m_actions.rebuildMenu(menuBar(), *m_shortcutController); + m_actions.rebuildMenu(menuBar(), this, *m_shortcutController); } Action* Window::addGameAction(const QString& visibleName, const QString& name, Action::Function function, const QString& menu, const QKeySequence& shortcut) {