Skip to content

Commit

Permalink
Pref Effects: left/right key in effect lists trigger hide/unhide
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Jan 20, 2025
1 parent c327cf1 commit 9c0ba8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
20 changes: 14 additions & 6 deletions src/preferences/dialog/dlgprefeffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,20 +402,20 @@ void DlgPrefEffects::slotDeletePreset() {
}
}

bool DlgPrefEffects::eventFilter(QObject* object, QEvent* event) {
if (event->type() == QEvent::FocusIn) {
bool DlgPrefEffects::eventFilter(QObject* pObj, QEvent* pEvent) {
if (pEvent->type() == QEvent::FocusIn) {
// Allow selection only in either of the effects/chains lists at a time
// to clarify which effect/chain the info below refers to.
// The method to update the info box for the new selection is the same
// for both the Chains and Effects tab:
// * clear selection in adjacent view
// * restore previous selection (select first item if none was selected)
// which updates the info box via 'currentRowChanged' signals
auto* pChainList = qobject_cast<QListView*>(object);
auto* pEffectList = qobject_cast<QTableView*>(object);
auto* pChainList = qobject_cast<QListView*>(pObj);
auto* pEffectList = qobject_cast<QTableView*>(pObj);
// Restore previous selection only if focus was changed with keyboard.
// For mouse clicks, that procedure would select the wrong index.
QFocusEvent* focEv = static_cast<QFocusEvent*>(event);
QFocusEvent* focEv = static_cast<QFocusEvent*>(pEvent);
bool keyboardFocusIn = false;
if (focEv->reason() == Qt::TabFocusReason ||
focEv->reason() == Qt::BacktabFocusReason) {
Expand Down Expand Up @@ -447,8 +447,16 @@ bool DlgPrefEffects::eventFilter(QObject* object, QEvent* event) {
pEffectList->selectRow(currIndex.row());
}
}
} else if (pEvent->type() == QEvent::KeyPress &&
m_pFocusedEffectList &&
pObj == m_pFocusedEffectList) {
// Left/Right key in focused effect list trigger Hide/Unhide
QKeyEvent* pKE = static_cast<QKeyEvent*>(pEvent);
if (pKE->key() == Qt::Key_Left || pKE->key() == Qt::Key_Right) {
slotHideUnhideEffect();
}
}
return DlgPreferencePage::eventFilter(object, event);
return DlgPreferencePage::eventFilter(pObj, pEvent);
}

QListView* DlgPrefEffects::unfocusedChainList() {
Expand Down
3 changes: 2 additions & 1 deletion src/preferences/dialog/dlgprefeffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class DlgPrefEffects : public DlgPreferencePage, public Ui::DlgPrefEffectsDlg {
void loadChainPresetLists();
void saveChainPresetLists();

bool eventFilter(QObject* pChainList, QEvent* event) override;
/// Handles FocusIn and KeyPress events in chain preset lists
bool eventFilter(QObject* pObj, QEvent* pEvent) override;
QListView* m_pFocusedChainList;
QListView* unfocusedChainList();
QTableView* m_pFocusedEffectList;
Expand Down

0 comments on commit 9c0ba8b

Please sign in to comment.