Skip to content

Commit

Permalink
Merge pull request #3171 from poelzi/searchbox-combo
Browse files Browse the repository at this point in the history
Use a combobox instead of a lineedit widget for library search history
  • Loading branch information
Be-ing authored Oct 29, 2020
2 parents 26d27fb + 9e29613 commit 524c41a
Show file tree
Hide file tree
Showing 7 changed files with 299 additions and 46 deletions.
2 changes: 1 addition & 1 deletion res/skins/LateNight/style.qss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ WTrackText,
WTrackProperty,
WBeatSpinBox,
QSpinBox,
QComboBox,
WLibrary QHeaderView,
WLibrary QHeaderView::item,
QToolTip,
Expand All @@ -27,6 +26,7 @@ WCoverArtMenu,
WTrackMenu,
WTrackMenu QMenu,
WOverview /* Hotcue labels in the overview */,
WBeatSpinBox, #spinBoxTransition,
WEffectSelector,
WEffectSelector QAbstractScrollArea,
#fadeModeCombobox,
Expand Down
24 changes: 24 additions & 0 deletions src/controllers/controlpickermenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,30 @@ ControlPickerMenu::ControlPickerMenu(QWidget* pParent)
tr("Replace Auto DJ Queue with selected tracks"),
libraryMenu, false, m_libraryStr);
libraryMenu->addSeparator();
addControl("[Library]",
"search_history_next",
tr("Select next search history"),
tr("Selects the next search history entry"),
libraryMenu,
false,
m_libraryStr);
addControl("[Library]",
"search_history_prev",
tr("Select previous search history"),
tr("Selects the previous search history entry"),
libraryMenu,
false,
m_libraryStr);
addControl("[Library]",
"search_history_selector",
tr("Move selected search entry"),
tr("Moves the selected search history item into given direction "
"and steps"),
libraryMenu,
false,
m_libraryStr);

libraryMenu->addSeparator();
addControl("[Recording]", "toggle_recording",
tr("Record Mix"),
tr("Toggle mix recording"),
Expand Down
57 changes: 55 additions & 2 deletions src/library/librarycontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,47 @@ LibraryControl::LibraryControl(Library* pLibrary)
this,
&LibraryControl::slotTrackColorNext);

// Control to navigate between widgets (tab/shit+tab button)
m_pSelectHistoryNext = std::make_unique<ControlPushButton>(
ConfigKey("[Library]", "search_history_next"));
m_pSelectHistoryPrev = std::make_unique<ControlPushButton>(
ConfigKey("[Library]", "search_history_prev"));
m_pSelectHistorySelect = std::make_unique<ControlEncoder>(
ConfigKey("[Library]", "search_history_selector"), false);
connect(m_pSelectHistoryNext.get(),
&ControlPushButton::valueChanged,
this,
[this](double value) {
VERIFY_OR_DEBUG_ASSERT(m_pSearchbox) {
return;
}
if (value >= 1.0) {
m_pSearchbox->slotMoveSelectedHistory(1);
}
});
connect(m_pSelectHistoryPrev.get(),
&ControlPushButton::valueChanged,
this,
[this](double value) {
VERIFY_OR_DEBUG_ASSERT(m_pSearchbox) {
return;
}
if (value >= 1.0) {
m_pSearchbox->slotMoveSelectedHistory(-1);
}
});
connect(m_pSelectHistorySelect.get(),
&ControlEncoder::valueChanged,
this,
[this](double steps) {
VERIFY_OR_DEBUG_ASSERT(m_pSearchbox) {
return;
}
if (steps >= 1.0 || steps <= -1.0) {
m_pSearchbox->slotMoveSelectedHistory(static_cast<int>(steps));
}
});

/// Deprecated controls
m_pSelectNextTrack = std::make_unique<ControlPushButton>(ConfigKey("[Playlist]", "SelectNextTrack"));
connect(m_pSelectNextTrack.get(),
Expand Down Expand Up @@ -537,19 +578,26 @@ void LibraryControl::emitKeyEvent(QKeyEvent&& event) {
VERIFY_OR_DEBUG_ASSERT(m_pLibraryWidget) {
return;
}
VERIFY_OR_DEBUG_ASSERT(m_pSearchbox) {
return;
}
if (!QApplication::focusWindow()) {
qDebug() << "Mixxx window is not focused, don't send key events";
return;
}

bool keyIsTab = event.key() == static_cast<int>(Qt::Key_Tab);
bool keyIsTab = event.key() == Qt::Key_Tab;
bool keyIsUpDown = event.key() == Qt::Key_Up || event.key() == Qt::Key_Down;

// If the main window has focus, any widget can receive Tab.
// Other keys should be sent to library widgets only to not
// accidentally alter spinboxes etc.
// If the searchbox has focus allow only Up/Down to select previous queries.
if (!keyIsTab && !m_pSidebarWidget->hasFocus()
&& !m_pLibraryWidget->getActiveView()->hasFocus()) {
setLibraryFocus();
if (keyIsUpDown && !m_pSearchbox->hasFocus()) {
setLibraryFocus();
}
}
if (keyIsTab && !QApplication::focusWidget()){
setLibraryFocus();
Expand Down Expand Up @@ -652,6 +700,11 @@ void LibraryControl::slotGoToItem(double v) {
return activeView->loadSelectedTrack();
}

// If searchbox has focus jump to the tracks table
if (m_pSearchbox->hasFocus()) {
return setLibraryFocus();
}

// Clear the search if the searchbox has focus
emit clearSearchIfClearButtonHasFocus();

Expand Down
5 changes: 5 additions & 0 deletions src/library/librarycontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ class LibraryControl : public QObject {
std::unique_ptr<ControlPushButton> m_pTrackColorPrev;
std::unique_ptr<ControlPushButton> m_pTrackColorNext;

// Controls to navigate search history
std::unique_ptr<ControlPushButton> m_pSelectHistoryNext;
std::unique_ptr<ControlPushButton> m_pSelectHistoryPrev;
std::unique_ptr<ControlEncoder> m_pSelectHistorySelect;

// Font sizes
std::unique_ptr<ControlPushButton> m_pFontSizeIncrement;
std::unique_ptr<ControlPushButton> m_pFontSizeDecrement;
Expand Down
2 changes: 2 additions & 0 deletions src/preferences/dialog/dlgpreflibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ void DlgPrefLibrary::slotRemoveDir() {
} else if (removeMsgBox.clickedButton() == deleteAllButton) {
removalType = Library::RemovalType::PurgeTracks;
} else {
// Only used in DEBUG_ASSERT
Q_UNUSED(leaveUnchangedButton);
DEBUG_ASSERT(removeMsgBox.clickedButton() == leaveUnchangedButton);
removalType = Library::RemovalType::KeepTracks;
}
Expand Down
Loading

0 comments on commit 524c41a

Please sign in to comment.