diff options
author | Daniel Schürmann <daschuer@mixxx.org> | 2022-01-16 01:18:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-16 01:18:21 +0100 |
commit | 68978853a3ade2b8cdd39ac5555760f5b73b5689 (patch) | |
tree | 72e6799fa67489381678097271c6db9b7b0ad596 | |
parent | 418a7e362abac709e753589c2201504b98191f20 (diff) | |
parent | 47713241ebf5bac9a2cc9b2fc91b5ebd9870832d (diff) |
Merge pull request #4617 from ronso0/beat-library-focus
WBeatSpinBox/AutoDJ spinbox: Enter & Esc also move focus to library
-rw-r--r-- | src/library/autodj/dlgautodj.cpp | 22 | ||||
-rw-r--r-- | src/library/autodj/dlgautodj.h | 1 | ||||
-rw-r--r-- | src/widget/wbeatspinbox.cpp | 13 |
3 files changed, 23 insertions, 13 deletions
diff --git a/src/library/autodj/dlgautodj.cpp b/src/library/autodj/dlgautodj.cpp index adfe89852a..4cc452a87e 100644 --- a/src/library/autodj/dlgautodj.cpp +++ b/src/library/autodj/dlgautodj.cpp @@ -79,8 +79,6 @@ DlgAutoDJ::DlgAutoDJ(WLibrary* parent, m_pAutoDJTableModel = m_pAutoDJProcessor->getTableModel(); m_pTrackTableView->loadTrackModel(m_pAutoDJTableModel); - // Override some playlist-view properties: - // Do not set this because it disables auto-scrolling //m_pTrackTableView->setDragDropMode(QAbstractItemView::InternalMove); @@ -163,12 +161,8 @@ DlgAutoDJ::DlgAutoDJ(WLibrary* parent, // work around QLineEdit being protected QLineEdit* lineEditTransition(spinBoxTransition->findChild<QLineEdit*>()); lineEditTransition->setFocusPolicy(Qt::ClickFocus); - // Catch any Return keypress to pass focus to tracks table - connect(lineEditTransition, - &QLineEdit::returnPressed, - this, - // Move focus to tracks table to immediately allow keyboard shortcuts again. - &DlgAutoDJ::setFocus); + // Needed to catch Enter, Return and Escape keypresses + lineEditTransition->installEventFilter(this); connect(spinBoxTransition, QOverload<int>::of(&QSpinBox::valueChanged), @@ -386,6 +380,18 @@ void DlgAutoDJ::setFocus() { m_pTrackTableView->setFocus(); } +void DlgAutoDJ::keyPressEvent(QKeyEvent* pEvent) { + // Return, Enter and Escape key move focus to the AutoDJ queue to immediately + // allow keyboard shortcuts again. + if (pEvent->key() == Qt::Key_Return || + pEvent->key() == Qt::Key_Enter || + pEvent->key() == Qt::Key_Escape) { + setFocus(); + return; + } + return QWidget::keyPressEvent(pEvent); +} + void DlgAutoDJ::saveCurrentViewState() { m_pTrackTableView->saveCurrentViewState(); } diff --git a/src/library/autodj/dlgautodj.h b/src/library/autodj/dlgautodj.h index d0976f2d3c..163146e6bc 100644 --- a/src/library/autodj/dlgautodj.h +++ b/src/library/autodj/dlgautodj.h @@ -59,6 +59,7 @@ class DlgAutoDJ : public QWidget, public Ui::DlgAutoDJ, public LibraryView { void setupActionButton(QPushButton* pButton, void (DlgAutoDJ::*pSlot)(bool), const QString& fallbackText); + void keyPressEvent(QKeyEvent* pEvent) override; const UserSettingsPointer m_pConfig; diff --git a/src/widget/wbeatspinbox.cpp b/src/widget/wbeatspinbox.cpp index ded403b4a5..81e16d7084 100644 --- a/src/widget/wbeatspinbox.cpp +++ b/src/widget/wbeatspinbox.cpp @@ -297,12 +297,15 @@ bool WBeatSpinBox::event(QEvent* pEvent) { } void WBeatSpinBox::keyPressEvent(QKeyEvent* pEvent) { - // Return key applies current value and sends a Shift+Tab event in order - // to focus a library widget. In official skins this would be the tracks table. - if (pEvent->key() == Qt::Key_Return) { + // Return & Enter keys apply current value. + // Return, Enter and Escape send a Shift+Tab event in order to move focus + // to a library widget. In official skins this would be the tracks table. + if (pEvent->key() == Qt::Key_Return || + pEvent->key() == Qt::Key_Enter || + pEvent->key() == Qt::Key_Escape) { QDoubleSpinBox::keyPressEvent(pEvent); - QKeyEvent returnKeyEvent = QKeyEvent{QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier}; - QApplication::sendEvent(this, &returnKeyEvent); + QKeyEvent shiftTabKeyEvent = QKeyEvent{QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier}; + QApplication::sendEvent(this, &shiftTabKeyEvent); return; } return QDoubleSpinBox::keyPressEvent(pEvent); |