Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WBeatSpinBox/AutoDJ spinbox: Enter & Esc also move focus to library #4617

Merged
merged 1 commit into from
Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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