Skip to content

Commit

Permalink
Merge pull request #4360 from ronso0/lineedit-focus
Browse files Browse the repository at this point in the history
pass focus to library after effect, beat size or Auto DJ transition configuration
  • Loading branch information
daschuer authored Oct 7, 2021
2 parents bc3d041 + 2802f82 commit 7618abf
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
28 changes: 23 additions & 5 deletions src/library/autodj/dlgautodj.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "library/autodj/dlgautodj.h"

#include <QApplication>
#include <QMessageBox>

#include "library/playlisttablemodel.h"
Expand Down Expand Up @@ -160,7 +161,13 @@ DlgAutoDJ::DlgAutoDJ(WLibrary* parent,
fadeModeCombobox->setFocusPolicy(Qt::ClickFocus);
spinBoxTransition->setFocusPolicy(Qt::ClickFocus);
// work around QLineEdit being protected
spinBoxTransition->findChild<QLineEdit*>()->setFocusPolicy(Qt::ClickFocus);
QLineEdit* lineEditTransition(spinBoxTransition->findChild<QLineEdit*>());
lineEditTransition->setFocusPolicy(Qt::ClickFocus);
// Catch any Return keypress to pass focus to tracks table
connect(lineEditTransition,
&QLineEdit::returnPressed,
this,
&DlgAutoDJ::shiftTabKeypress);

connect(spinBoxTransition,
QOverload<int>::of(&QSpinBox::valueChanged),
Expand All @@ -178,7 +185,7 @@ DlgAutoDJ::DlgAutoDJ(WLibrary* parent,
fadeModeCombobox->setCurrentIndex(
fadeModeCombobox->findData(static_cast<int>(m_pAutoDJProcessor->getTransitionMode())));
connect(fadeModeCombobox,
QOverload<int>::of(&QComboBox::currentIndexChanged),
QOverload<int>::of(&QComboBox::activated),
this,
&DlgAutoDJ::slotTransitionModeChanged);

Expand Down Expand Up @@ -330,9 +337,11 @@ void DlgAutoDJ::autoDJStateChanged(AutoDJProcessor::AutoDJState state) {
}
}

void DlgAutoDJ::slotTransitionModeChanged(int comboboxIndex) {
m_pAutoDJProcessor->setTransitionMode(static_cast<AutoDJProcessor::TransitionMode>(
fadeModeCombobox->itemData(comboboxIndex).toInt()));
void DlgAutoDJ::slotTransitionModeChanged(int newIndex) {
m_pAutoDJProcessor->setTransitionMode(
static_cast<AutoDJProcessor::TransitionMode>(
fadeModeCombobox->itemData(newIndex).toInt()));
shiftTabKeypress();
}

void DlgAutoDJ::slotRepeatPlaylistChanged(int checkState) {
Expand Down Expand Up @@ -370,3 +379,12 @@ void DlgAutoDJ::updateSelectionInfo() {
bool DlgAutoDJ::hasFocus() const {
return m_pTrackTableView->hasFocus();
}

void DlgAutoDJ::shiftTabKeypress() {
// After selecting a mode or editing the transition time, send Shift+Tab
// to move focus to the next keyboard-focusable widget (tracks table in
// official skins) in order to immediately allow keyboard shortcuts again.
QKeyEvent backwardFocusKeyEvent =
QKeyEvent{QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier};
QApplication::sendEvent(this, &backwardFocusKeyEvent);
}
1 change: 1 addition & 0 deletions src/library/autodj/dlgautodj.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class DlgAutoDJ : public QWidget, public Ui::DlgAutoDJ, public LibraryView {
void setupActionButton(QPushButton* pButton,
void (DlgAutoDJ::*pSlot)(bool),
const QString& fallbackText);
void shiftTabKeypress();

const UserSettingsPointer m_pConfig;

Expand Down
13 changes: 13 additions & 0 deletions src/widget/wbeatspinbox.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "widget/wbeatspinbox.h"

#include <QApplication>
#include <QLineEdit>
#include <QRegularExpression>

Expand Down Expand Up @@ -295,6 +296,18 @@ bool WBeatSpinBox::event(QEvent* pEvent) {
return QDoubleSpinBox::event(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) {
QDoubleSpinBox::keyPressEvent(pEvent);
QKeyEvent returnKeyEvent = QKeyEvent{QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier};
QApplication::sendEvent(this, &returnKeyEvent);
return;
}
return QDoubleSpinBox::keyPressEvent(pEvent);
}

bool WBeatLineEdit::event(QEvent* pEvent) {
if (pEvent->type() == QEvent::FontChange) {
const QFont& fonti = font();
Expand Down
1 change: 1 addition & 0 deletions src/widget/wbeatspinbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class WBeatSpinBox : public QDoubleSpinBox, public WBaseWidget {

// for font scaling
bool event(QEvent* pEvent) override;
void keyPressEvent(QKeyEvent* pEvent) override;
double m_scaleFactor;
};

Expand Down
17 changes: 13 additions & 4 deletions src/widget/weffectselector.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "widget/weffectselector.h"

#include <QApplication>
#include <QtDebug>

#include "effects/effectsmanager.h"
Expand All @@ -11,9 +12,11 @@ WEffectSelector::WEffectSelector(QWidget* pParent, EffectsManager* pEffectsManag
WBaseWidget(this),
m_pEffectsManager(pEffectsManager),
m_scaleFactor(1.0) {
// Prevent this widget from getting focused to avoid
// interfering with using the library via keyboard.
setFocusPolicy(Qt::NoFocus);
// Prevent this widget from getting focused by Tab/Shift+Tab
// to avoid interfering with using the library via keyboard.
// Allow click focus though so the list can always be opened by mouse,
// see https://bugs.launchpad.net/mixxx/+bug/1902125
setFocusPolicy(Qt::ClickFocus);
}

void WEffectSelector::setup(const QDomNode& node, const SkinContext& context) {
Expand All @@ -37,7 +40,7 @@ void WEffectSelector::setup(const QDomNode& node, const SkinContext& context) {
this,
&WEffectSelector::slotEffectUpdated);
connect(this,
QOverload<int>::of(&WEffectSelector::currentIndexChanged),
QOverload<int>::of(&WEffectSelector::activated),
this,
&WEffectSelector::slotEffectSelected);
} else {
Expand Down Expand Up @@ -91,6 +94,12 @@ void WEffectSelector::slotEffectSelected(int newIndex) {
id);

setBaseTooltip(itemData(newIndex, Qt::ToolTipRole).toString());
// After selecting an effect send Shift+Tab to move focus to the next
// keyboard-focusable widget (tracks table in official skins) in order
// to immediately allow keyboard shortcuts again.
QKeyEvent backwardFocusKeyEvent =
QKeyEvent{QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier};
QApplication::sendEvent(this, &backwardFocusKeyEvent);
}

void WEffectSelector::slotEffectUpdated() {
Expand Down

0 comments on commit 7618abf

Please sign in to comment.