Skip to content

Commit

Permalink
Merge pull request #4617 from ronso0/beat-library-focus
Browse files Browse the repository at this point in the history
WBeatSpinBox/AutoDJ spinbox: Enter & Esc also move focus to library
  • Loading branch information
daschuer authored Jan 16, 2022
2 parents 418a7e3 + 4771324 commit 6897885
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
22 changes: 14 additions & 8 deletions src/library/autodj/dlgautodj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions src/library/autodj/dlgautodj.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 8 additions & 5 deletions src/widget/wbeatspinbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6897885

Please sign in to comment.