Skip to content

Commit

Permalink
Keyboard: update menubar shortcuts when keyboard mapping is reloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Apr 15, 2024
1 parent d1c3e76 commit 428caf9
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 70 deletions.
22 changes: 22 additions & 0 deletions src/controllers/keyboard/keyboardeventfilter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "controllers/keyboard/keyboardeventfilter.h"

#include <QAction>
#include <QEvent>
#include <QKeyEvent>
#include <QtDebug>
Expand Down Expand Up @@ -240,9 +241,30 @@ const QString KeyboardEventFilter::buildShortcutString(
return shortcutTooltip;
}

const QString KeyboardEventFilter::registerMenuBarActionGetKeySeqString(QAction* pAction,
const ConfigKey& command,
const QString& defaultShortcut) {
VERIFY_OR_DEBUG_ASSERT(treu /* reminder */) {

Check failure on line 247 in src/controllers/keyboard/keyboardeventfilter.cpp

View workflow job for this annotation

GitHub Actions / clazy

use of undeclared identifier 'treu'

Check failure on line 247 in src/controllers/keyboard/keyboardeventfilter.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04

‘treu’ was not declared in this scope; did you mean ‘tr’?

Check failure on line 247 in src/controllers/keyboard/keyboardeventfilter.cpp

View workflow job for this annotation

GitHub Actions / macOS 11 x64

use of undeclared identifier 'treu'

Check failure on line 247 in src/controllers/keyboard/keyboardeventfilter.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy

use of undeclared identifier 'treu' [clang-diagnostic-error]

Check failure on line 247 in src/controllers/keyboard/keyboardeventfilter.cpp

View workflow job for this annotation

GitHub Actions / macOS 11 arm64

use of undeclared identifier 'treu'; did you mean 'free'?

Check failure on line 247 in src/controllers/keyboard/keyboardeventfilter.cpp

View workflow job for this annotation

GitHub Actions / coverage

‘treu’ was not declared in this scope; did you mean ‘tr’?

Check failure on line 247 in src/controllers/keyboard/keyboardeventfilter.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'treu': undeclared identifier
}
const auto cmdStr = std::make_pair(command, defaultShortcut);
m_menuBarActions.insert(pAction, cmdStr);
return m_pKbdConfig->getValue(command, defaultShortcut);
}

void KeyboardEventFilter::updateMenuBarActions() {
QHashIterator<QAction*, std::pair<ConfigKey, QString>> it(m_menuBarActions);
while (it.hasNext()) {
it.next();
const QString keyStr = m_pKbdConfig->getValue(it.value().first, it.value().second);
auto pAction = it.key();

Check warning on line 259 in src/controllers/keyboard/keyboardeventfilter.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy

'auto pAction' can be declared as 'auto *pAction' [readability-qualified-auto]
pAction->setShortcut(QKeySequence(keyStr));
}
}

void KeyboardEventFilter::reloadKeyboardConfig() {
createKeyboardConfig();
updateWidgets();
updateMenuBarActions();
}

void KeyboardEventFilter::createKeyboardConfig() {
Expand Down
10 changes: 10 additions & 0 deletions src/controllers/keyboard/keyboardeventfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class KeyboardEventFilter : public QObject {
void clearWidgets();
const QString buildShortcutString(const QString& shortcut, const QString& cmd) const;

const QString registerMenuBarActionGetKeySeqString(
QAction* pAction,
const ConfigKey& command,
const QString& defaultShortcut);
void updateMenuBarActions();

public slots:
void reloadKeyboardConfig();

Expand Down Expand Up @@ -87,6 +93,10 @@ class KeyboardEventFilter : public QObject {

QFileSystemWatcher m_fileWatcher;

// Actions in the menu bar
// Value pair is the ConfigKey and the default QKeySequence (as QString).
QHash<QAction*, std::pair<ConfigKey, QString>> m_menuBarActions;

// Widgets that have mappable connections, registered by LegacySkinParser
// during skin construction.
QList<WBaseWidget*> m_widgets;
Expand Down
4 changes: 2 additions & 2 deletions src/mixxxmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,9 @@ void MixxxMainWindow::slotUpdateWindowTitle(TrackPointer pTrack) {
void MixxxMainWindow::createMenuBar() {
qWarning() << " $ createMenuBar";
ScopedTimer t(u"MixxxMainWindow::createMenuBar");
DEBUG_ASSERT(m_pCoreServices->getKeyboardConfig());
DEBUG_ASSERT(m_pCoreServices->getKeyboardEventFilter());
m_pMenuBar = make_parented<WMainMenuBar>(
this, m_pCoreServices->getSettings(), m_pCoreServices->getKeyboardConfig().get());
this, m_pCoreServices->getSettings(), m_pCoreServices->getKeyboardEventFilter());
if (m_pCentralWidget) {
m_pMenuBar->setStyleSheet(m_pCentralWidget->styleSheet());
}
Expand Down
Loading

0 comments on commit 428caf9

Please sign in to comment.